with various data-link layer, network layer, routing and transport
layer networking protocols. It has been specifically developed for
TEXT ="black" LINK="blue" VLINK="purple">
Events occur when a node reboots, the Application Layer has a message for delivery, the Physical Layer receives a frame on a link, a timer event expires, a debugging button (under Tcl/Tk) is selected, and a node is (politely) shutdown. No event is delivered if a node pauses, crashes or suffers a hardware failure. These last few events only occur in simulations designed to address the higher layers of the OSI model (say, the Session Layer).
NOTE: cnet employs an event-driven style of programming, not an interrupt-driven style. In particular, while an event handler is executing it will not be interrupted by the arrival of another event. In support of this, there are no facilities to specify non-interruptable, high-priority handlers nor to ``wrap'' data structures in semaphores or monitors (you won't need them!).
Event-handling functions must first be registered to receive incoming events with a call to CNET_set_handler. Event-handling functions will be later called by cnet with three parameters. The first is the type of event (the reason the handler is being called), one of the CnetEvent enumerated values. The second parameter is a unique timer (described later) and the third, some user-specified data.
Each node is initially rebooted by calling its reboot_node function. This is the only function that you must provide and is assumed to have the name reboot_node() unless overridden with either the -R option or the rebootnode node attribute. The purpose of calling reboot_node is to give protocols a chance to allocate any necessary dynamic memory, initialize variables, inform cnet in which events protocols are interested, and which handlers that cnet should call when these events occur.
A user-defined data value must be initially provided as the third parameter to CNET_set_handler. When the handler's event eventually occurs, the same value is passed as the third parameter to the handler. Within more complex protocols, you will typically want to pass an integer or, with care, a pointer, via this third parameter. The user-defined data value for timeout handlers (for EV_TIMER1..EV_TIMER10) must also be provided as the third parameter to CNET_start_timer.
timer1 = CNET_start_timer(EV_TIMER1, 5000, 0);
The timer has significance for functions handling timer events; all other handlers will simply receive the special NULLTIMER. Notice that timers do not reflect the current time; they specify which timer has expired. When a timer expires, the event-handler for the corresponding event is invoked with the event and the unique timer as parameters. Timers may be cancelled prematurely with CNET_stop_timer to prevent them expiring, for example:
though they are automatically cancelled as a result of their handler being invoked.