![]() |
![]() |
cnet's datatypes, event types, and error typescnet's provides a number of datatypes, necessary to identify node types, link types, events, and errors. Each datatype is defined in the <cnet.h> header file. The datatypes are:
The CnetNodeType enumerated typeEach node is either a host (such as a workstation), a router, a mobile node (such as a wireless PDA), or a wireless accesspoint. The type of a node may be determined by examining its value of nodeinfo.nodetype. For example:if(nodeinfo.nodetype == NT_HOST) CNET_set_handler(EV_APPLICATIONREADY, appl_ready, 0);
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 type NT_HOST or NT_MOBILE. Calls to the functions
CNET_set_position, and CNET_set_battery are only valid if called from a node of type NT_MOBILE. The CnetLinkType enumerated typeEach node's links provide either a loopback service, wide-area-networking, local-area-networking, or wireless-local-area-networking. The type of a link may be determined by examining the value of linkinfo[link].linktype. For example:
Calls to the function
CNET_set_nicaddr may only be made for links of type LT_LAN or LT_WLAN. The CnetColour typeColours are employed for some simple activities when cnet's execution is displayed via its GUI. Colours are simple C strings, such as "red" or "blue", hexadecimal RGB-triples such as "#ffaa00", or the special value CNET_LED_OFF.When drawing datalink frames, protocol code may specify the colour to be used to highlight each field in each frame. When wishing to present a quick indication of a node's status, the function CNET_set_LED may be called with the desired colour (string). When drawing the wireless transmissions of wireless LANs, the function CNET_set_wlancolour may be called to request how each transmission is drawn. The CnetError enumerated typeMost cnet API functions return the integer 0 on success and the integer -1 on failure. The most recent error status is stored in the global variable cnet_errno. All values of cnet_errno will be instances of the enumerated type CnetError. Functions do not set the value of cnet_errno to ER_OK if their execution was successful.Errors may be reported to stderr with CNET_perror() and their error message string accessed from cnet_errstr[(int)cnet_errno]. For example:
The CnetEvent enumerated typeAll events in cnet are of type CnetEvent. Events are raised when a number of important things occur that (possibly) require action from your protocols. Interest may be registered in each event by calling the function CNET_set_handler and passing to it a function, an event handler, to be called when the event is raised. By default, no events are of interest (all are ignored).When an event of interest is raised, its event handler is called, with the event (an instance of CnetEvent) passed as the first parameter.
The CnetNICaddr datatypeEach Physical Layer link of type LT_WAN, LT_LAN, or LT_WLAN has a specific Network Interface Card (NIC) address. cnet provides the CnetNICaddr datatype to represent the addresses of its NICs, as an array of LEN_NICADDR (=6) unsigned characters. Although cnet does not require it, it is anticipated that frames will carry the address of their source and destination Network Interface Cards (NIC) near the beginning of the frame.cnet provides the functions CNET_parse_nicaddr and CNET_format_nicaddr to convert between character strings and the CnetNICaddr datatype. The CnetTime datatypeAll times and periods in cnet are stored as an integral number of microsconds. This requires a sufficiently long integer representation to avoid values "wrapping around" in most simulations. cnet employs ISO-C99's standard int64_t datatype to represent time:
typedef int64_t CnetTime; and all function arguments and structure fields requiring a number of microseconds, employ the CnetTime type. Standard integer arithmetic, such as addition and subtraction, and comparisons may be performed on CnetTime values, and they may be conveniently formatted with CNET_format64. The WLANRESULT enumerated typeA simulation needing to define its own WLAN signal propagation model, will call CNET_set_wlan_model to register a function that determines the extent and success of wireless signal propagation. This function must return one of the values of WLANRESULT:
|
cnet v3.3.4, written by Chris.McDonald@uwa.edu.au
Last modified: Tue Mar 1 7:43AM 2016