CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

Rebooting each node

We next look at the mandatory reboot_node() function, and the simple handler of EV_DEBUG1 which simply prints the runtime state of the stopandwait protocol.

EVENT_HANDLER(showstate)
{
    printf("\tackexpected\t= %d\n\tnextdatatosend\t= %d\n\tdataexpected\t= %d\n",
		    ackexpected, nextdatatosend, dataexpected);

}

EVENT_HANDLER(reboot_node)
{
    if(OS->nodenumber > 1) {
	fprintf(stderr,"This is not a 2-node network!\n");
	exit(EXIT_FAILURE);
    }

    CHECK(CNET_set_handler( EV_APPLICATIONREADY, application_ready, 0));
    CHECK(CNET_set_handler( EV_PHYSICALREADY,    physical_ready, 0));
    CHECK(CNET_set_handler( EV_TIMER1,           timeouts, 0));
    CHECK(CNET_set_handler( EV_DEBUG1,           showstate, 0));

    CHECK(CNET_set_debug_string( EV_DEBUG1, "State"));

    if(OS->nodenumber == 1) {
	CNET_enable_application(ALLNODES);
    }
}

Two things of note:

  • Embedding a cnet function call in CHECK() provides a convenient way to check that the call succeeded.
  • The last 3 lines ensure that data traffic only flows one way, and its acknowledgments only flow the other
    (which is much easier to debug).



CITS3002 Computer Networks, Lecture 3, Data Link Layer protocols, p18, 13th March 2024.