background preloader

Lab

Facebook Twitter

The cnet network simulator - layers and functions - the API. Cnet's layers and functions - the API Descriptions of cnet's core functions are available from here.

The cnet network simulator - layers and functions - the API

In each section functions are presented as ANSI-C prototypes, often with an example of their use. Most library functions return the integer 0 on success and the integer -1 on failure. The most recent error status is reflected in the global variable cnet_errno. All values of cnet_errno will be instances of the enumerated type CnetError. Function restrictions Note that calls to the functions CNET_write_application, CNET_read_application, CNET_enable_application, CNET_disable_application and CNET_set_handler(EV_APPLICATIONLAYER,...) and CNET_set_handler(EV_KEYBOARDREADY,...) are only valid if called from a node of node type NT_HOST. Calls to the functions CNET_set_promiscuous, and CNET_set_nicaddr cannot set the attributes of link 0, the LOOPBACK link, nor set a NIC address to either the zero address, 00:00:00:00:00:00, or the broadcast address, ff:ff:ff:ff:ff:ff.

The cnet network simulator (v3.2.4) Topology files cnet accepts (many) command line options to control its execution.

The cnet network simulator (v3.2.4)

However, more important is cnet's use of a topology file to define the nodes, links, and attributes in each network simulation. If the name of the topology file is "-", then the topology will be read from standard input. Consider the following simple topology file which defines a 2-node network. An implementation of the stopandwait protocol is being developed over a single bidirectional WAN link which experiences dataframe corruption. cnet keywords are case-sensitive and are presented here in bold font. If necessary, the topology file is first preprocessed by the C-preprocessor, enabling the use of #include, #define and conditional "compilation" directives. Global attributes may be defined in each topology file and affect the execution of the whole simulation. Local attributes are defined within a new "block", by opening a curly bracket (as in C). Defining different node types Defining WAN links. The cnet network simulator (v3.2.4)

Protocol walkthroughs A good way to introduce protocol writing in cnet is to ''walkthrough'' some of the protocols provided in cnet's source distribution.

The cnet network simulator (v3.2.4)

Firstly, as seems mandatory when introducing new programming languages, let's look at the traditional ''Hello World'' example written as a cnet protocol. Although cnet protocols are written in ISO-C99, this example looks quite different: Things to first note are that the source code includes the standard cnet header file, as must all cnet protocol source files, and that there is no traditional main() function, nor a call to exit(), nor a return value. However, this ''protocol'' does run - each node implementing this protocol is rebooted when cnet invokes its event-handler for the EV_REBOOT event. In fact, the above protocol is so simple that it doesn't even need the usual cnet topology file. Cnet -C helloworld.c -r 2 We can even replace the 2, above, with 101 to run the protocol on a much larger, random, network. Introducing timer events. The cnet network simulator - layers and functions. Cnet's layers and functions Descriptions of cnet's core functions are available from here.

The cnet network simulator - layers and functions

In each section functions are presented as ANSI-C prototypes, often with an example of their use. Most library functions return the integer 0 on success and the integer -1 on failure. The most recent error status is reflected in the global variable cnet_errno. All values of cnet_errno will be instances of the enumerated type CnetError. Function restrictions Note that calls to the functions CNET_write_application, CNET_read_application, CNET_enable_application, CNET_disable_application and CNET_set_handler(EV_APPLICATIONLAYER,...) or CNET_set_handler(EV_KEYBOARDREADY,...) are only valid if called from a node of node type NT_HOST. Cnet was written and is maintained by Chris McDonald (chris@cs.uwa.edu.au)