Download presentation
Presentation is loading. Please wait.
1
Performing RWA Simulation With NS An introduction to NS & RWA simulation constructs
2
Optical Networking Research Group Information Network Lab, USTC2 Outline Part I: NS Programming Basics Object oriented mechanisms Overview of NS Simulator The Lamp Example Packet Handling in NS—from a transport protocol’s perspective Part II: Build in NS a platform for RWA Simulation Network Model Architectural Overview Internals…
3
Optical Networking Research Group Information Network Lab, USTC3 What’s Object Oriented… Object An object is a software bundle of variables and related methods. [java.sun.com] Variable => State Methods => Behavior OOP. A software design method that models the characteristics of abstract or real objects using classes. [java.sun.com]
4
Optical Networking Research Group Information Network Lab, USTC4 Why Object Oriented… Modularity Easy for maintenance Easy for code Reuse Information hiding Transparency Security Inheritance Structuring and Organizing Software
5
Optical Networking Research Group Information Network Lab, USTC5 Object Oriented Programming struct a Class a member v1; member v2; method m1; method m2; … member v1; member v2; method m1; method m2; … variable v1; variable v2; … variable v1; variable v2; … procedure p Some operation on instances of struct a Class b base class a member v2b; method m2b; … member v2b; method m2b; …
6
Optical Networking Research Group Information Network Lab, USTC6 NS – A Schematic Overview C++ Compiled Hierarchy OTcl Interpreted Hierarchy
7
Optical Networking Research Group Information Network Lab, USTC7 NS – A Schematic Overview C++ /OTcl Implementation C++ and OTcl Interaction OTcl Object Implementation Simulation Scripts What to do? For ordinary users For Advanced users
8
Optical Networking Research Group Information Network Lab, USTC8 An Example -- Lamp May change ON/OFF Status May change brightness Status and Brightness may be monitored
9
Optical Networking Research Group Information Network Lab, USTC9 From this example, You will know how to… Implement a class in C++ Implement a class in OTcl Combine OTcl and C++ codes Write simple simulation scripts
10
Optical Networking Research Group Information Network Lab, USTC10 An Example: Lamp Interfaces: switch: switch the ON/OFF status of the lamp object show_status: Show the current ON/OFF status of the lamp object brighten: make the lamp object brighter darken: make the lamp object darker Member variables status: current status of the lamp object, {ON, OFF} brightness: current brightness of the lamp object in integer voltage, current, resistance: electro. character. of the lamp object OTcl C++ OTcl C++
11
Optical Networking Research Group Information Network Lab, USTC11 Lamp Implementation in C++ class Lamp_C: public TclObject { private: real resistance, current, voltage; int brightness; public: Lamp_C(real r) {resistance = r;} void brighten(int step); void darken(int step); } void Lamp_C::brighten(int step) { resistance -= log(step); //need check here!!! current = voltage/resistance; brightness = C*pow (current, 2); } void Lamp_C::darken(int step) { resistance +=log(step); //need check here!!! current = voltage/resistance; brightness = C*pow (current, 2); } class Lamp_C: public TclObject { private: real resistance, current, voltage; int brightness; public: Lamp_C(real r) {resistance = r;} void brighten(int step); void darken(int step); } void Lamp_C::brighten(int step) { resistance -= log(step); //need check here!!! current = voltage/resistance; brightness = C*pow (current, 2); } void Lamp_C::darken(int step) { resistance +=log(step); //need check here!!! current = voltage/resistance; brightness = C*pow (current, 2); } … Lamp_C mylamp = new Lamp_C(50.0); mylamp.brighten(10); mylamp.darken(30); … Lamp_C mylamp = new Lamp_C(50.0); mylamp.brighten(10); mylamp.darken(30); …
12
Optical Networking Research Group Information Network Lab, USTC12 Lamp Implementation in OTcl Class Lamp_TCL Lamp_TCL set status OFF Lamp_TCL set brightness 0 Lamp_TCL instproc switch { state } { $self instvar status if {$state != “”} { set status $state } return $status } Lamp_TCL instproc show_status { } { $self instvar status puts “Current status is :$status” puts “Current brightness is :$brightness” } Class Lamp_TCL Lamp_TCL set status OFF Lamp_TCL set brightness 0 Lamp_TCL instproc switch { state } { $self instvar status if {$state != “”} { set status $state } return $status } Lamp_TCL instproc show_status { } { $self instvar status puts “Current status is :$status” puts “Current brightness is :$brightness” } C:\ns-2.1b8win\ns ↲ % % set mylamp [new Lamp_TCL] % $mylamp show_status % $mylamp switch ON % $mylamp show_status Result: Current status is :OFF Current brightness is : 0 Current status is :ON Current brightness is : 0 C:\ns-2.1b8win\ns ↲ % % set mylamp [new Lamp_TCL] % $mylamp show_status % $mylamp switch ON % $mylamp show_status Result: Current status is :OFF Current brightness is : 0 Current status is :ON Current brightness is : 0
13
Optical Networking Research Group Information Network Lab, USTC13 Comparing C++ and OTcl class Lamp_C: public TclObject { private: real resistance, current, voltage; int brightness; public: Lamp_C(real r) {resistance = r;} void brighten(int step); void darken(int step); } void Lamp_C::brighten(int step) { // … } void Lamp_C::darken(int step) { //… } class Lamp_C: public TclObject { private: real resistance, current, voltage; int brightness; public: Lamp_C(real r) {resistance = r;} void brighten(int step); void darken(int step); } void Lamp_C::brighten(int step) { // … } void Lamp_C::darken(int step) { //… } Class Lamp_TCL Lamp_TCL set status OFF Lamp_TCL set brightness 0 Lamp_TCL instproc switch { state } { #... } Lamp_TCL instproc show_status { } { #... } Class Lamp_TCL Lamp_TCL set status OFF Lamp_TCL set brightness 0 Lamp_TCL instproc switch { state } { #... } Lamp_TCL instproc show_status { } { #... }
14
Optical Networking Research Group Information Network Lab, USTC14 NS: OTcl and C++ Combined Static class LampClass:public TclClass { public: LampClass::TclClass(“Lamp_TCL”) {} TclObject * create(int, const char * const *) { return (new Lamp_C( )); } }class_Lamp; Int Lamp_C::init( ){ … bind(“brightness”,&brightness); … } Static class LampClass:public TclClass { public: LampClass::TclClass(“Lamp_TCL”) {} TclObject * create(int, const char * const *) { return (new Lamp_C( )); } }class_Lamp; Int Lamp_C::init( ){ … bind(“brightness”,&brightness); … } int Lamp_C::command(int ac, const char*const* av){ if (strcmp(av[1], “brighten") == 0){ int step = atoi(av[2]); brighten(step); return TCL_OK; } if (strcmp(av[1], “darken”) == 0) { int step = atoi(av[2]); darken(step); return TCL_OK; } return TclObject::command(ac,av); } int Lamp_C::command(int ac, const char*const* av){ if (strcmp(av[1], “brighten") == 0){ int step = atoi(av[2]); brighten(step); return TCL_OK; } if (strcmp(av[1], “darken”) == 0) { int step = atoi(av[2]); darken(step); return TCL_OK; } return TclObject::command(ac,av); }
15
Optical Networking Research Group Information Network Lab, USTC15 NS: OTcl and C++ Combined if (strcmp(av[1], “darken”) == 0) { int step = atoi(av[2]); Tcl & tcl = Tcl::instance(); char cmd[50],ret[10]; sprintf(cmd, “%s switch”, name()); tcl.eval(cmd); if(strcmp(tcl.result(), “OFF”)){ return TCL_OK; } darken(step); return TCL_OK; } if (strcmp(av[1], “darken”) == 0) { int step = atoi(av[2]); Tcl & tcl = Tcl::instance(); char cmd[50],ret[10]; sprintf(cmd, “%s switch”, name()); tcl.eval(cmd); if(strcmp(tcl.result(), “OFF”)){ return TCL_OK; } darken(step); return TCL_OK; }
16
Optical Networking Research Group Information Network Lab, USTC16 NS: OTcl and C++ Combined C:\NetSim\ns-2.1b8a-win\ns ↲ % %set mylamp [new Lamp_TCL] % $mylamp show_status % $mylamp switch ON % $mylamp brighten 100 % $mylamp show_status % Result: Current status is :OFF Current brightness is : 0 Current status is :ON Current brightness is : 32 C:\NetSim\ns-2.1b8a-win\ns ↲ % %set mylamp [new Lamp_TCL] % $mylamp show_status % $mylamp switch ON % $mylamp brighten 100 % $mylamp show_status % Result: Current status is :OFF Current brightness is : 0 Current status is :ON Current brightness is : 32 Use OTcl –magic of manipulating: Configuration, setup and one-time stuff Manipulating existing C++ objects Use C++ –power of Computing: Packet processing Computational complex jobs Anything you like !
17
Optical Networking Research Group Information Network Lab, USTC17 Lamp Conclusion Interfaces: switch, show_status, brighten, darken brighten, darken Member variables status brightness, voltage, current, resistance Implementation C++/OTcl OTcl Invocation in C++ : tcl.eval(...), tcl.result(...); C++ Invocation in OTcl : Lamp::command(...); Variable binding: bind(...);
18
Optical Networking Research Group Information Network Lab, USTC18 Packet Handling in NS: From A Protocol’s Perspective int RWAAgent::command(int argc, const char * const * argv){ … if (strcmp(argv[1],”get-connect-request”) = = 0){ Packet *pkt = allocpkt(); hdr_rwa *hdrrwa = hdr_rwa::access(pkt); hdrrwa->msg_type = CONNECTION_REQUEST; … send(pkt,0); } … } int RWAAgent::command(int argc, const char * const * argv){ … if (strcmp(argv[1],”get-connect-request”) = = 0){ Packet *pkt = allocpkt(); hdr_rwa *hdrrwa = hdr_rwa::access(pkt); hdrrwa->msg_type = CONNECTION_REQUEST; … send(pkt,0); } … } >>>
19
Optical Networking Research Group Information Network Lab, USTC19 Packet Handling in NS: From A Protocol’s Perspective void RWAAgent::recv(Packet* pkt, Handler*){ hdr_rwa *hdrrwa = hdr_rwa::access(pkt); int msgtype = hdrrwa->msg_type; … switch (msgtype){ case CONNECTION_REQUEST: //process this packet … break; … } Packet::free(pkt); } void RWAAgent::recv(Packet* pkt, Handler*){ hdr_rwa *hdrrwa = hdr_rwa::access(pkt); int msgtype = hdrrwa->msg_type; … switch (msgtype){ case CONNECTION_REQUEST: //process this packet … break; … } Packet::free(pkt); }
20
Optical Networking Research Group Information Network Lab, USTC20 Build in NS a platform for RWA Simulation Extensions to Class Simulator Extensions to Class Node RWA Agents new! Connection Request Generator new!
21
Optical Networking Research Group Information Network Lab, USTC21 Network Model
22
Optical Networking Research Group Information Network Lab, USTC22 Components DWDM Node Interfaces, Fibers, Wavelengths Wavelength Converter RWA Agent Simple Signaling(Connection Setup/Teardown) Routing (Fixed, Explicit Routing) Connection Request Generator Arrival Rate Hold Time
23
Optical Networking Research Group Information Network Lab, USTC23 Architectural Overview Linked_DWDM_nodes_ Linked_interfaces_ Linked_RWA_Agents_
24
Optical Networking Research Group Information Network Lab, USTC24 Architectural Overview RWA Agent DWDM Node Edge Node Transit Node Connect Request Generator RWA Peer
25
Optical Networking Research Group Information Network Lab, USTC25 Internals of Connection Request Generator Descriptions Base Class: TrafficGenerator Functionality: generating connection request Hold time … Destination node… Wavelength change allowed ? “$agent get-connect-request $ht $dst $change_allow”get-connect-request Configurable Parameters: Mean arrival rate Mean hold time
26
Optical Networking Research Group Information Network Lab, USTC26 Internals of RWA Agent Descriptions: Base Class: Agent Functionality: Packet processing Connection request/setup/release Route lookups Change node status A list of timers Connection timeouts …
27
Optical Networking Research Group Information Network Lab, USTC27 Internals of RWA Agent OTcl part Route lookups Interfacing with Node C++ Part Receiving/processing/sending packets Connection timeouts
28
Optical Networking Research Group Information Network Lab, USTC28 Structure of A RWA Packet struct hdr_rwa{ int src, dst; int sid; int msg_type; int fid, lambda; char er [MAX_HOPS*5] ; int rtptr; … } struct hdr_rwa{ int src, dst; int sid; int msg_type; int fid, lambda; char er [MAX_HOPS*5] ; int rtptr; … } Message Types: CONNECTION_REQUEST_MSG CONNECTION_RELEASE_MSG CONNECTION_CONFIRM_MSG CONNECTION_BLOCKED_MSG EXPLICIT_ROUTE_MSG Global Session ID: NODEID * CONST + local_sid …
29
Message Processing In RWA Agents
30
Optical Networking Research Group Information Network Lab, USTC30 Finding RWA Peers Node/DWDM instproc get-rwa-agent {peer_node} { $self instvar linked_rwa_agents_ set na [llength $linked_rwa_agents_] for {set i 0} {$i < $na } {incr i} { set rwa_agent [lindex $linked_rwa_agents_ $i] if {[$rwa_agent set peer_node_] == $peer_node} { return $rwa_agent } return -1 } Node/DWDM instproc get-rwa-agent {peer_node} { $self instvar linked_rwa_agents_ set na [llength $linked_rwa_agents_] for {set i 0} {$i < $na } {incr i} { set rwa_agent [lindex $linked_rwa_agents_ $i] if {[$rwa_agent set peer_node_] == $peer_node} { return $rwa_agent } return -1 }
31
Optical Networking Research Group Information Network Lab, USTC31 Internals of DWDM Node Descriptions Base class: Node Functionality Management of physical resources Data structures Lambda_table Converter_table ER_routing_table Connection_table
32
Optical Networking Research Group Information Network Lab, USTC32 Internals of DWDM Node OTcl part Attaching RWA agents/Traffic generator Interfacing with RWA Physical interface mapping (object index) C++ Part A Lambda table /converter table /connection table Connection query interface Nodal statistics Static Routes
33
Optical Networking Research Group Information Network Lab, USTC33 Connection Table Structure struct connect_struct{ short src, dst; int global_sid_; short in_lambda, out_lambda; short in_inf, out_inf; short in_fid, out_fid; short prevhop; intholdtime; inter_entry; entry_statusstatus; }; struct connect_struct{ short src, dst; int global_sid_; short in_lambda, out_lambda; short in_inf, out_inf; short in_fid, out_fid; short prevhop; intholdtime; inter_entry; entry_statusstatus; }; sid = NODEID * CONST + local_sid [Prefix] [local] [Globally Unique] sid = NODEID * CONST + local_sid [Prefix] [local] [Globally Unique]
34
Connection Initiation and confirmation on Nodes
35
Connection Request Processing on Nodes
36
Optical Networking Research Group Information Network Lab, USTC36 To Start Simulation… Create Network Topology Create DWDM Nodes Build Links between Nodes Configure RWA Agents on every node Install Traffic Generator on Edge Nodes Configure Traffic Generators Install Static Routes On Edge Nodes Start Traffic and do an “$ns run”
37
Optical Networking Research Group Information Network Lab, USTC37 Thank You ! Questions are welcome…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.