140 likes | 240 Views
This document outlines an engineering approach to computer networking fundamentals using the REAL simulation framework. It covers multi-threading concepts in UNIX, emphasizing the mechanism of sharing a single address space among threads while maintaining isolation of thread stacks. Learn how to implement communication between threads through packet exchange without memory leaks and acquire practical insights into controlling packet flow. The document also highlights practical file modifications for extending functionality and debugging tips to streamline your simulation experience.
E N D
REAL An Engineering Approach to Computer Networking
Basics • REAL: globals and simulation engine thread UNIX
Threads • Thread = infinite loop • for (;;) • Share a single address space • can read and write all globals • but not another thread’s stack • Communication is through sendm(dest, key, packet) and recvm(&dest, &key, &pkt) • Only pointers to packets are exchanged • sender must not free a packet - receivers do this
REAL functions • sendm(dest, key, pkt) • recvm(&dest, &key, &pkt) • blocking • get_node_id() • runtime() • struct timeval { long tv_sec, long tv_usec} • abs_advance() • make_pkt() • pkt type is DATA • make_float() • pr_error()
A simple node function #include "../kernel/real.h" ecn_dummy() { PKT_PTR pkt; int node, num_pkts_sent = 0; ident destn, sender, sink; long key; timev now; int seq_no = 0; node = get_node_id(); /* find out local id */ sink = assigned_sink[node]; /* find out sink (from .l file ) */ abs_advance(node_start_time[node]); /* advance time to start time */ now = runtime();
Contd. /* send the request packet */ if(node is 1) { make_pkt(pkt); pkt->dest = sink; /* use num_pkts field to store command (0 or 1) */ pkt->data[0] = num_pkts[node]; sendm(sink, 0, pkt); printf("Node 1 sent request packet\n"); }
Contd. for (ever) { sender = recvm(&destn, &key, &pkt); now = runtime(); switch (pkt->type){ case ACK: /* just free acks for now */ free(pkt); break; case INT: /* when the line goes free */ free(pkt); break; case DATA: /* convert the request packet to reply packet and send * it right back */ pkt->type = ACK; pkt->dest = pkt->source; pkt->source= node; sendm(pkt->dest, 0, pkt); break;
How it works • Simulator simulates a topology given to it in an input file • described in NetLanguage • parameters, nodes, edges • defaults • node function = C function implementing a thread is part of node description • Simulator parses the file and starts the threads • Same C function may run at multiple nodes • At each instant, run the thread which has the earliest packet to serve • Preemption only during recvm() • Details in sim/src
Things to watch out for • Globals can be modified by any thread • need to synchronize access • For non-shared global, index by node ID (from get_node_id()) • Debugging: can land up at the same statement many times! • Threads are serial, but programming abstraction is that they run in parallel • I/O by a thread blocks all others • Nodes exchange pointers to packets
Adding a new function • Write the function • Modify sim/sources/makefile and sim/makefile
Adding a new parameter • Change lang/lang.lex to add the name • Change lang/lang.yacc to read the value into a variable • Change kernel/parameters.h to make it a global • Recompile
Useful files • sim/kernel/types.h • the packet type • sim/ kernel/config.h • configuration parameters • sim/ kernel/parameters.h • globals • sim/ lang/lang.lex; sim/ lang/lang.yacc • NetLanguage scanner and parser • src/defs.h • additions to C syntax • src/nest.a • simulation engine
RealEdit • Java based GUI for creating input files and simulating them on a server • http://real.cs.cornell.edu:80
More information • http://www.cs.cornell.edu/home/skeshav/real/overview.html • Also contains online manual pages • Searchable archive of REAL mailing list is at http://minnie.cs.odfa.oz.au/cgi-bin/real.cgi