PARSEC/Glomosim Tutorial
Vlasios Tsiatsis EE206 UCLA, 5/1/02
PARSEC Entities
Discrete-event simulation language Basically C with extensions
parallel executing ENTITIES
entity Sort (int n, int a[20]) { sorting(); finalize{ useful for statistics collection } }
entity body
//entity declaration, creation ename s1; entity handle ... sl = new Sort(20, a[20]); ...
May 1, 2002
2
Vlasios Tsiatsis
PARSEC Messages
Entities communicate via message passing Each entity has one built-in message queue time-stamped, typed, MESSAGES like C structs
message Request { int }; /* declaration - initialization*/ message Request myrequest; myrequest.units =20; myrequest.id = self; handle of current entity units; ename id;
May 1, 2002
3
Vlasios Tsiatsis
Entity Communication
Entities exchange messages using the send and receive primitives send – send a typed message to an entity
message Request myrequest; send Request{10, self} to E2; send oldrequest to E2; send oldrequest to E2 after 5;
This modifier changes the message timestamp
May 1, 2002
4
Vlasios Tsiatsis
Entity Communication (cont’d)
receive – process message from the internal queue (blocking call)
/* complex receive */ receive (Request r) { req = r; } or receive (Release r) { units = r.units; } or timeout in (5) { ... }
message Request req; int units; /* simple receive */ receive (Request r) { req = r; }
Two semantics: a) in – timeout has highest priority b) after – receive has highest priority
May 1, 2002 5
Vlasios Tsiatsis
Timing considerations
PARSEC keeps track of the simulation time by using an internal discrete simulation clock
Only a few statements can advance this clock:
send M1 to E1 after T with T>0 timeout with non-zero timeovalue hold(T) with T>0 (like a delay function) …so if you don’t have any of these statements in your code the simulation time is going to be zero!
send statements deposit the message asynchronously in the receiving entity queue time-stamping it with the current or modified time
6 Vlasios Tsiatsis
May 1, 2002
Timing considerations (cont’d)
receive statements take the earliest message from queue (according to timestamps) and if there are multiple messages with the same timestamp the order is NOT deterministic! The user can get the value of simulation clock by the simclock() function The user can set the maximum value of simulation clock by the setmaxclock() function
May 1, 2002
7
Vlasios Tsiatsis
Development Cycle
Your equivalent main() function is the entity driver() Use this entity to create all the other entities and setup the simulation environment Also use this entity to collect all the statistics from all other entities by sending them request messages If you need to connect entities together use messages with the entity reference (self) in the message If an entity A needs some information from another entity B create a dummy request message: send DummyReq to B; // no delay receive(DummyRep rep){ needed_info = rep.info
}
May 1, 2002 8 Vlasios Tsiatsis
Example
How would we simulate a wireless sensor network under PARSEC ? First thought- one entity per physical node What about node communication ? How do you model the wireless channel? The solution follows a layered approach
1
entity type for the channel 1 entity type for the physical layer 1 entity type for link layer and so on…
May 1, 2002 9 Vlasios Tsiatsis
Example – NESL Code Organization*
To keep things simple we only have 3 types of “networking” entity types:
Channel
(physical and MAC layer) Node (network and application layer)
Radio
And one entity responsible for setting up the simulation environment (driver entity) and gathering the simulation results
* The author of the first version of this code is Curt Schurgers
May 1, 2002
10
Vlasios Tsiatsis
Architecture
MAIN Node 1 Node N
Radio 1
Channel One physical sensor node
Radio N
Statistics messages Network messages
Each building block corresponds to 4 files
– Implementation .h – Declarations _functions.h – Functions _parameters.h – Parameters
.pc
May 1, 2002
11
Vlasios Tsiatsis
PARSEC Implementation
main.pc code
entity driver(int argc,char** argv) { ... // Topology (xcoord, ycoord) creation ... channel = (ename*)malloc(sizeof(ename)); channel = new Channel(self,num_nodes,BER); ... for (i=0;i