160 likes | 356 Views
Data Communication and Networks. Introduction to cnet Simulator September 25, 2003 Joseph Conron Computer Science Department New York University jconron@cs.nyu.edu. What is cnet Simulator?. Program that simulates a network environment Provides simulated application and physical layers.
E N D
Data Communication and Networks Introduction to cnet Simulator September 25, 2003 Joseph Conron Computer Science Department New York University jconron@cs.nyu.edu
What is cnet Simulator? • Program that simulates a network environment • Provides simulated application and physical layers. • You provide the middle layers • Written in C and requires that you write your protocols in C • Runs on many Unix systems. We will give you a running version for Solaris. • If you want run it on another Unix, get the package and compile/install/test yourself. • you’re on your own – no help from me
Overview of cnet • Organized around layered model • cnet application layer generates message intended for other nodes • Calls a function you write to send message • You use functions in cnet physical layer to send • cnet physical layer is designed to corrupt and lose frames. • Your job is to write protocols that provide for reliable, ordered message delivery …
cnet Event Interface • Communications between layers is accomplished through event handlers • cnet generates events when something important happens: • reboot (EV_REBOOT) • application message available to send (EV_APPLICATIONREADY) • physical layer data available to read (EV_PHYSICALREADY) • timer expired (EV_TIMER)
cnet Event Handlers • How does cnet know which function to call when one of these events occur? • You write C functions and tell cnet which of these to call when a given event occurs (CNET_set_handler()) • cnet requires that each handler function provides a pre-defined signature. • Your code implements whatever is appropriate for the event and protocol
Basic Steps to Implement a Protocol • Describe the network with a “topology file” • Indentifies nodes and links between them • Write reboot_node() function to handle event EV_REBOOT_NODE • Write the event handlers • Run cnet using your topology file as input
What cnet does (1) • Your topology file includes the name of your source file(s) • Cnet compiles the named files • If compilation is OK, cnet begins the simulation • Cnet generates events • EV_REBOOT_NODE for each node in network • EV_APPLICATION_READY for nodes enabled to send messages • EV_PHYSICAL_READY for received frames • EV_TIMERn for timer events.
What cnet does (2) • If you specified it in your topolgy file cnet will generate errors at the physical layer • Simulation will run for as long as you’ve specified • By wall-clock time • By simulated time • By number of generated events • cnet collects spastics during the run – these are important because they allow you to evaluate the protocol’s performance.
“Hello World” A topology file A protocol source file Compile = “hello.c” Host NewYork { link to Boston south of Boston } Host Boston { } #include <cnet.h> Void reboot_node(CnetEvent event, CnetTimer timer, CnetData data) { printf(“Hello from node %s.\n”, nodeinfo.nodename); }
cnet Reboot Event • Every node must handle a reboot event (EV_REBOOT) • Handler signature is: void reboot_node(CnetEvent event, CnetTimer timer, CnetData data) Event will be “EV_REBOOT”, timer and data can be ignored • No need to tell cnet about your reboot_node function – cnet assumes you have one. • Your reboot handler does system initialization for your node. • You should be asking the question by now: “how do I know which node my handler is being called for?”
cnet Global Information • Cnet defines some global data for you: The variable nodeinfo contains a CnetNodeInfo structure (see cnet.h) • The data in nodeinfo is read-only – you should not try to change it. • Example: to get your node name, use nodeinfo.nodename.
Running the simulation • Cnet –W –E 2 –o hello HELLO • This command tells cnet to compile and run your simulation. • -W says to run in console (not GUI) mode • -E 2 says run for 2 events • -o hello says create output files for each node named “hello.<node>” • Simulation with no options will run for 3 minutes of wall-clock time.
cnet Timers • cnet provides 10 timers (named EV_TIMER1 – EVTIMER10) • You can start as many timers as you wish using just one of cnet’s timers. • So why does cnet have 10 timers? • Allows layers to use independent timers • Convenience • myTimer = CNET_start_timer(EV_TIMER1, 3000, 0) • Starts a 3 second timer. The ID of this timer is saved in “myTimer”.
Adding a timer to HELLO #include <cnet.h> void myTimerHndlr(CnetEvent event, CnetTimer timer, CnetData data) { printf(“Hello from timer handler in node %s\n”, nodeinfo.nodename); CNET_Start_Timer(EV_TIMER1, 3000, 0); } void reboot_node(CnetEvent event, CnetTimer timer, CnetData data) { printf(“Hello from node %s.\n”, nodeinfo.nodename); CNET_set_handler(EV_TIMER1, myTimerHndlr, 0); CNET_Start_Timer(EV_TIMER1, 3000, 0); }
cnet GUI • Cnet provides a graphical interface via tcl/tk • (but you don’t really need it!) • You need a Unix X windows environment to use it. • If you are running an XServer from home, you can connect to the NYU Solaris systems using ssh and start an xterm window: ssh –X –l <your-id> <fqdn> • If you are running NT or W2K, get cygwin. Here are instructions I put together to help.
Excercises • Take the HELLO example and change it to print the seconds value of cnet’s wall-clock time (it’s in nodeinfo) at each timer event. • Add node number to the print message in reboot handler. • Add code to send messages from NewYork to Boston (Use CNET_write_physical_reliable())