real
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
REAL
An Engineering Approach to Computer NetworkingAn Engineering Approach to Computer Networking
Basics
UNIX
REAL: globals and simulation engineREAL: globals and simulation engine
thread
Threads
Thread = infinite loopThread = infinite loop for (;;)for (;;)
Share a single address spaceShare a single address space can read and write all globalscan read and write all globals but not another thread’s stackbut not another thread’s stack
Communication is through sendm(dest, key, packet) and Communication is through sendm(dest, key, packet) and recvm(&dest, &key, &pkt)recvm(&dest, &key, &pkt)
Only pointers to packets are exchangedOnly pointers to packets are exchanged sender sender must notmust not free a packet - receivers do this free a packet - receivers do this
REAL functions
sendm(dest, key, pkt)sendm(dest, key, pkt) recvm(&dest, &key, &pkt)recvm(&dest, &key, &pkt)
blockingblocking get_node_id()get_node_id() runtime()runtime()
struct timeval { long tv_sec, long tv_usec}struct timeval { long tv_sec, long tv_usec} abs_advance()abs_advance() make_pkt()make_pkt()
pkt type is DATApkt type is DATA make_float()make_float() pr_error()pr_error()
A simple node function
#include "../kernel/real.h"#include "../kernel/real.h"
ecn_dummy()ecn_dummy()
{{
PKT_PTR pkt;PKT_PTR pkt;
int node, num_pkts_sent = 0; int node, num_pkts_sent = 0;
ident destn, sender, sink;ident destn, sender, sink;
long key;long key;
timev now;timev now;
int seq_no = 0;int seq_no = 0;
node = get_node_id(); /* find out local id */ node = get_node_id(); /* find out local id */
sink = assigned_sink[node]; /* find out sink (from .l file ) */sink = assigned_sink[node]; /* find out sink (from .l file ) */
abs_advance(node_start_time[node]); /* advance time to start time */abs_advance(node_start_time[node]); /* advance time to start time */
now = runtime();now = runtime();
Contd.
/* send the request packet *//* send the request packet */
if(node is 1) {if(node is 1) {
make_pkt(pkt);make_pkt(pkt);
pkt->dest = sink;pkt->dest = sink;
/* use num_pkts field to store command (0 or 1) *//* use num_pkts field to store command (0 or 1) */
pkt->data[0] = num_pkts[node];pkt->data[0] = num_pkts[node];
sendm(sink, 0, pkt);sendm(sink, 0, pkt);
printf("Node 1 sent request packet\n");printf("Node 1 sent request packet\n");
}}
Contd.
for (ever) {for (ever) {
sender = recvm(&destn, &key, &pkt);sender = recvm(&destn, &key, &pkt);
now = runtime();now = runtime();
switch (pkt->type){switch (pkt->type){
case ACK: /* just free acks for now */case ACK: /* just free acks for now */
free(pkt);free(pkt);
break;break;
case INT: /* when the line goes free */case INT: /* when the line goes free */
free(pkt);free(pkt);
break;break;
case DATA: /* convert the request packet to reply packet and sendcase DATA: /* convert the request packet to reply packet and send
* it right back */* it right back */
pkt->type = ACK;pkt->type = ACK;
pkt->dest = pkt->source;pkt->dest = pkt->source;
pkt->source= node;pkt->source= node;
sendm(pkt->dest, 0, pkt);sendm(pkt->dest, 0, pkt);
break;break;
How it works
Simulator simulates a Simulator simulates a topologytopology given to it in an input file given to it in an input file described in NetLanguagedescribed in NetLanguage parameters, nodes, edgesparameters, nodes, edges defaultsdefaults node function = C function implementing a thread is part of node function = C function implementing a thread is part of
node descriptionnode description Simulator parses the file and starts the threadsSimulator parses the file and starts the threads Same C function may run at multiple nodesSame C function may run at multiple nodes At each instant, run the thread which has the earliest packet to At each instant, run the thread which has the earliest packet to
serveserve Preemption only during recvm()Preemption only during recvm() Details in sim/srcDetails in sim/src
Things to watch out for
Globals can be modified by any threadGlobals can be modified by any thread need to synchronize accessneed to synchronize access For non-shared global, index by node ID (from For non-shared global, index by node ID (from
get_node_id())get_node_id()) Debugging: can land up at the same statement many times!Debugging: can land up at the same statement many times! Threads are serial, but programming abstraction is that they run Threads are serial, but programming abstraction is that they run
in parallelin parallel I/O by a thread blocks all othersI/O by a thread blocks all others
Nodes exchange Nodes exchange pointerspointers to packets to packets
Adding a new function
Write the functionWrite the function Modify sim/sources/makefile and sim/makefileModify sim/sources/makefile and sim/makefile
Adding a new parameter
Change lang/lang.lex to add the nameChange lang/lang.lex to add the name Change lang/lang.yacc to read the value into a variableChange lang/lang.yacc to read the value into a variable Change kernel/parameters.h to make it a globalChange kernel/parameters.h to make it a global RecompileRecompile
Useful files
sim/kernel/types.hsim/kernel/types.h the packet typethe packet type
sim/ kernel/config.hsim/ kernel/config.h configuration parametersconfiguration parameters
sim/ kernel/parameters.hsim/ kernel/parameters.h globalsglobals
sim/ lang/lang.lex; sim/ lang/lang.yaccsim/ lang/lang.lex; sim/ lang/lang.yacc NetLanguage scanner and parserNetLanguage scanner and parser
src/defs.hsrc/defs.h additions to C syntaxadditions to C syntax
src/nest.asrc/nest.a simulation enginesimulation engine
RealEdit
Java based GUI for creating input files and simulating them on a Java based GUI for creating input files and simulating them on a server server
http://real.cs.cornell.edu:80http://real.cs.cornell.edu:80
More information
http://www.cs.cornell.edu/home/skeshav/real/overview.htmlhttp://www.cs.cornell.edu/home/skeshav/real/overview.html Also contains online manual pagesAlso contains online manual pages Searchable archive of REAL mailing list is atSearchable archive of REAL mailing list is at
http://minnie.cs.odfa.oz.au/cgi-bin/real.cgihttp://minnie.cs.odfa.oz.au/cgi-bin/real.cgi