Upload
allen-campbell
View
213
Download
0
Embed Size (px)
Citation preview
2008.03.18(Tue)2008.03.18(Tue) 11
Network Simulator 2Network Simulator 2
- Introduction for Beginners -- Introduction for Beginners -
2008. 03. 182008. 03. 18
CNLABCNLAB
nsns--22 seminar seminar
2008.03.18(Tue)2008.03.18(Tue) 22
Scope
Basic Requirements for Using ns-2
1) C++
2) Tcl & OTcl
3) Object Orientation concepts
4) ns-2 Mechanisms (ns-2 Core & Utilities)
5) Application-specific Implementation Architectures
. Wired ~ to Wireless world
. Lower Layer ~ to Higher Layer
. Variety of architectural specifics
2008.03.18(Tue)2008.03.18(Tue) 33
Scope
Introduction
Some Basic Concepts - Architectural Views- Plumbing & Duality
- Tcl basics
OTcl Linkage Architecture
Object Orientation in OTcl
Elemental Procedures in ns-2 programming- Network creation- Agents & others
2008.03.18(Tue)2008.03.18(Tue) 44
Introduction
Ns has began as a variant of the REAL network simulator in 1989, and has evolved substantially in the past few years.
In 1995 ns development was supported by DARPA through the VINT project at LBL, Xerox PARC, UCB, and USC/ISI.
- VINT : Virtual InterNet Testbed
http://www.isi.edu/nsnam/ns/
The latest version : ns-2.32 [2007] : hundreds * 1000 LOC
2008.03.18(Tue)2008.03.18(Tue) 55
Introduction
RRelated Research area - functionality & application
- Network Layer . Routing : unicast, multicast, MPLS . QoS : IntServ / DiffServ . Queuing Disciplines
- Transport . TCP . Reliable multicast . Congestion control
- Application . Web Caching . Multimedia . Traffic Sources
- Wireless world . Mobile IP . Ad hoc routing . Sensor MAC
2008.03.18(Tue)2008.03.18(Tue) 66
Introduction
TK8.x OTcl tclclTcl8.x ns-2 nam-1
tcl
ex test lib
. . .
..
.examples validation tests
C++ code
OTcl code
ns-allinone
mcast
NS-2 Directory
2008.03.18(Tue)2008.03.18(Tue) 77
Introduction
What is NS-2 ? - Discrete Event Simulator
- Packet-level
- Link layer and up
- Wired and Wireless worlds
Languages
- Tcl (Tool Command Language)
- OTcl (MIT Object-oriented Tcl)
- C++
- Some others
2008.03.18(Tue)2008.03.18(Tue) 88
Introduction
Tcl Interpreter with Extents - OTcl : Object-oriented support, extending Tcl/Tk
- TclCL : C++ and OTcl Linkage (interface)
- Discrete Event Scheduler (ordered list of events)
- Data Network (the Internet) Components
tcl8.x
Otcl
tclcl
ns-2EventScheduler
Netw
orkC
omp
onen
t
Users
2008.03.18(Tue)2008.03.18(Tue) 99
Basic Concepts – Architectural View
Object-oriented (C++, OTcl) - Reusability
- Maintenance
Scalability + Extensibility- Control / ““Data” separation
. OTcl for control (scenarios)
. C++ for “data”
- Split OTcl / C++ objects Duality Needs Linkage
Modular approach - Fine-grained Object composition
2008.03.18(Tue)2008.03.18(Tue) 1010
Basic Concepts – Architectural View
OTcl Script
Analysis
NetworkAnimator
NS Simulator Library
. Event Scheduler Objects. Network Component Objects
. Network Setup Help Modules(Plumbing Modules)
OTcl : Tcl Interpreterwith OO extensions
NAM
..................
..................
SimulationProgram
SimulationResults
Simplified User’s View of NS - NS-2 is basically the Tcl & OTcl Interpreter with network simulation object libraries.
2008.03.18(Tue)2008.03.18(Tue) 1111
Basic Concepts – Architectural View
Layered View of the NS [an example]
- OTcl : Application, Scenario, or Upper Layer - C++ : Lower Layer or Protocol/Packet Layer
Ingress NodeSource Node Egress Node
TransportC++ Layer
OTcl Lib
TransportC++ Layer
Core Node
ApplicationProcedure
TransportC++ Layer
OTcl Lib
TransportC++ Layer
OTcl Lib
2008.03.18(Tue)2008.03.18(Tue) 1212
Basic Concepts – Architectural View
Components domain Relationship View of the NS
- NS-2 is written in C++ with OTcl Interpreter as the Front-End.
- Simulator objects are implemented in the Compiled hierarchy (C++ domain), but instantiated through the Interpreter.
2008.03.18(Tue)2008.03.18(Tue) 1313
Basic Concepts - Architecture
Nodes
Node
Link
Nodeentry
entry_
LinkLink
PortClassifier
AddrClassifier
classifier_
dmux_
Agent
Agent
Agent
App
2008.03.18(Tue)2008.03.18(Tue) 1414
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
Node entry
Unicast Node
Multicast Classifier
classifier_
dmux_
entry_
Node entry
Multicast Node
multiclassifier_
Classifier : Address, Multicast, Multipath
Nodes
Basic Concepts - Architecture
2008.03.18(Tue)2008.03.18(Tue) 1515
Basic Concepts - Architecture
Links
n0 n1
enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_
n1 entry_
head_
tracing simplex link
duplex link
2008.03.18(Tue)2008.03.18(Tue) 1616
Basic Concepts - Architecture
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
Node entry
0
1 enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_n1 entry_head_
Nodes & Links
2008.03.18(Tue)2008.03.18(Tue) 1717
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0
1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
Basic Concepts - Architecture
Routing
2008.03.18(Tue)2008.03.18(Tue) 1818
0
1
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0 Agent/TCP
agents_
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSinkagents_
dst_=1.0 dst_=0.0
Basic Concepts - Architecture
Transport
2008.03.18(Tue)2008.03.18(Tue) 1919
0
1
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0 Agent/TCP
agents_
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSink
agents_
dst_=1.0 dst_=0.0Application/FTP
Application : Traffic Generator
Basic Concepts - Architecture
2008.03.18(Tue)2008.03.18(Tue) 2020
Basic Concepts - Architecture
TclObject
NsObject
Connector Classifier
Delay AddrClassifierAgent McastClasifierQueue Trace
DropTail RED TCP Enq Deq Drop
Reno SACK ...
Object Hierarchy
other objects
2008.03.18(Tue)2008.03.18(Tue) 2121
Basic Concepts - Architecture
Some differences between NS-2 & Real network
- Node : no queue, above network layer, no lower layer on the basic Node (not in mobile node)
- Link : Compound object with Queues
- No physical media, but simulated environment
- No real data or payload transmissions, except in special applications (web), which uses special transport.
- Normally, the ultimate Packet Transmissions are done by calling the next object’s method (recv( )).
2008.03.18(Tue)2008.03.18(Tue) 2222
Basic Concepts - Plumbing
Network Topology Setup using- Network Objects : Nodes & Links *cf) NsObject
- Plumbing Library functions
Plumbing : for Network Setup
- Plumbing Data Paths among the Network Objects by setting the “Neighbor” pointers of an Object to the Address of an appropriate object.
- Plumbing modules are implemented as member functions of the base Simulator object.
- neighbor_, target_ variables are key to plumbing transmission : target_recv( )
2008.03.18(Tue)2008.03.18(Tue) 2323
Basic Concepts - Duality
C++ OTcl
Pure C++objects
Pure OTclobjects
C++ / OTcl split objects
ns
TclCL linkage
OTcl & C++ Share Class Hierarchy
2008.03.18(Tue)2008.03.18(Tue) 2424
Basic Concepts - Duality
C++ / OTcl Separation - C++ for “Data” . Per Packet action : Packet Headers accessed
- OTcl for Control
. Periodic or Triggered action (~ Scenario scheduling)
. Network(Topology) Creation : Application procedure
- Tradeoff between Composability and Speed (+)
- Learning/debugging are more difficult (-)
Separation on Dual planes need Linkage to compose
2008.03.18(Tue)2008.03.18(Tue) 2525
Basic Concepts - Duality
OTcl : Interpreted hierarchy - Create Network
- Create Connection (wired)
- Create Traffic
C++ : Compiled hierarchy - Packet processing methods
- OTcl command Interpreter
. object::command( ) method : one of the linkage
2008.03.18(Tue)2008.03.18(Tue) 2626
Basic Concepts - Duality
Otcl domainset tcp [new Agent/TCP]
$tcp advance 10
C++ domainint TcpAgent::command(int argc, const char*const* argv)
{if (argc == 3) {
if (strcmp(argv[1], “advance”) == 0) { int newseq = atoi(argv[2]);
…… return(TCL_OK);
}}
return (Agent::command(argc, argv);}
2008.03.18(Tue)2008.03.18(Tue) 2727
Basic Concepts – Tcl/OTcl
Tcl / OTcl Basics - proc command : define a global procedure . proc create_topology {
- set command : assign a value to a variable . set count 10 . $self set count 10
- Substitutions
. Command substitution : brackets as command - set cnt [ $self set count ] cnt = 10
- set cnt [ expr $cnt + $cnt ] set cnt to 20
. Variable substitution : ex) $count 10
$ns at [ $ns now ] “$self send $class $rate"
2008.03.18(Tue)2008.03.18(Tue) 2828
C++ / OTcl Linkage - snapshot view
Export C++ class to Otcl [Create C++ object from OTcl] • Creating a new network object class in C++, & also an instance of this object in Otcl, needs a Linkage object derived from the TclClass (C++ domain).
Export C++ class variables to OTcl • The new network object class in C++ may have some parameter variables, also to be configured from Otcl.
Export C++ Object Control Commands to OTcl • Giving the control of new C++ object to Otcl, via the Otcl command interpreter: command() function.
Execute an OTcl command from C++
• Execute an OTcl command from the new C++ object.
2008.03.18(Tue)2008.03.18(Tue) 2929
C++ / OTcl Linkage
Root Class of ns-2 object hierarchy
bind(): Link variable values between C++ and OTcl TclObject
command() : Link OTcl methods to C++ implementations
TclClass Create and initialize TclObject’s
Tcl C++ methods to access Tcl interpreter
TclCommand Standalone global commands
EmbeddedTcl ns script initialization
2008.03.18(Tue)2008.03.18(Tue) 3030
C++ / OTcl Linkage - TclObject
TclObject : base class - Basic hierarchy in ns-2 for split objects
- Mirrored in both C++ & OTcl
- NsObject : the superclass of all network component objects that handle packets
Connector, Classifier subclasses
- Connector : having only one output data path
- Classifier : having multiple output data path (Router)
- Node : Compound object ~ Node Entry, Classifier objects
- Link : ’’ ~ Queue, Delay, TTL objects..
2008.03.18(Tue)2008.03.18(Tue) 3131
C++ / OTcl Linkage - TclObject
TclObject
Agent
Agent/TCP
Agent/TCP OTcl shadow object
_o123
Agent/TCP C++ object
*tcp
TclObject
Agent
TcpAgent
OTcl classhierarchy
C++ classhierarchy
TclObject : Hierarchy and Shadowing
static TcpClass : public TclClass {public: TcpClass():TclClass(“Agent/Tcp"){} TclObject* create(int,const char*const*) { return (new TcpAgent());}};
2008.03.18(Tue)2008.03.18(Tue) 3232
C++/OTcl Linkage - TclObject
TclObject Creation & Deletion
- Global Procedures : new{ }, delete{ }
- Example :
set tcp [ set tcp [ newnew Agent/TCP ] Agent/TCP ] … …
deletedelete $tcp $tcp
2008.03.18(Tue)2008.03.18(Tue) 3333
C++ / OTcl Linkage – TclObject
C++
OTcl
invoke parentconstructor
Agent/TCPconstructor
parentconstructor
invoke parentconstructor
TclObjectconstructor
create C++object
AgentTCPconstructor
invoke parentconstructor
invoke parentconstructor
parent (Agent)constructor
do nothing,return
TclObject (C++)constructor
bind variablesand return
bind variablesand return
create OTclshadow object
complete initialization
complete initialization
which C++ objto create? – TclClass
set tcp [ new Agent/TCP ]
2008.03.18(Tue)2008.03.18(Tue) 3434
C++/OTcl Linkage - TclObject::bind()
Linking C++ member variable to OTcl object variable • Bound variables can be configured from Both C++/OTcl.
C++ domainTcpAgent::TcpAgent( ) { // Constructor
bind(“window_”, &wnd);… …
} // other type : bind_time(), bind_bool(), bind_bw()
OTcl domain set tcp [new Agent/TCP]set tcp [new Agent/TCP]
$tcp set $tcp set window_window_ 200 200
2008.03.18(Tue)2008.03.18(Tue) 3535
C++ / OTcl Linkage - TclObject::command()
Export C++ Object Control Commands to OTcl
int MyAgent::command(int argc, const char*const* argv ) { if (argc == 2) {
if (strcmp(argv[1], “call-my-func”) == 0) {MyPrivFunc( ));
return (TCL_OK);}
}return (Agent::command(argc, argv));
}
- Effect : Implement OTcl methods in C++
- Trap point : OTcl method cmd{ }
2008.03.18(Tue)2008.03.18(Tue) 3636
C++ / OTcl Linkage - TclObject::command()
$tcp send TclObject::unknown{} $tcp cmd sendno suchprocedure
TcpAgent::command()
match “send”?
Invoke parent: return Agent::command()
process and return
Yes No
OTcl space
C++ space
2008.03.18(Tue)2008.03.18(Tue) 3737
C++ / OTcl Linkage – TclClass
TclObject
Agent
Agent/TCP
TclObject
Agent
TcpAgent
NsObject ??
OTclC++ mirroringStatic class TcpClass : public TclClass {public:
TcpClass() : TclClass(“Agent/TCP”) { }
TclObject* create(int, const char*const*) {return (new TcpAgent( ) );
}} class_tcp;
Static class TcpClass : public TclClass {public:
TcpClass() : TclClass(“Agent/TCP”) { }
TclObject* create(int, const char*const*) {return (new TcpAgent( ) );
}} class_tcp;
2008.03.18(Tue)2008.03.18(Tue) 3838
C++ / OTcl Linkage – TclClass
Class TclClass ( in C++ )
- This compiled class is pure virtual class : only 2 functions
• Construct the interpreted class hierarchy to mirror the compiled class hierarchy.
• Method to Create instances of the associated TclObject.
- For the static variable class_tcp, ns-2 will execute the constructor of TcpClass. The constructor specifies the interpreted class explicitly as “Agent/TCP”.
- This sets up the related methods and the interpreted class hierarchy in the Otcl space. Next slide
- This class is associated with the class TcpAgent, and when the user issues “new …”, TcpClass::create( ) is invoked. TcpAgent is created.
2008.03.18(Tue)2008.03.18(Tue) 3939
C++ / OTcl Linkage – TclClass
Interpreted Class Hierarchy construction (more)
- When the object constructor is executed, the TclClass constructor stores the name of the class, and inserts this object into Linked List of TclClass objects.
- During initialization, TclClass::bind() is invoked.
- For each object in the List, bind() invokes register{… } with the class name as its argument.
- register{ } establishes the class hierarchy, creating the class required.
class TcpAgent : public Agent { public: TcpAgent( ); // Constructor protected: int command(int argc, const char* const* argv); int xxx_;};
2008.03.18(Tue)2008.03.18(Tue) 4040
C++ / OTcl Linkage – Tcl
Singleton class with a handle to Tcl interpreter
Usage - Invoke OTcl procedure from C++ : 4 methods
- Obtain OTcl evaluation results : tcl.result( )
- Pass a result string to OTcl : tcl.result(*s), tcl.resultf(*s)
2008.03.18(Tue)2008.03.18(Tue) 4141
C++ / OTcl Linkage – Tcl
Execute an OTcl command from C++
Tcl& tcl = Tcl::instance();
tcl.eval (“puts \ “Message from MyPrivFunc\””);
or char wrk[128]; sprintf(wrk, “$s recv %d”, name(), result); tcl.eval (wrk);
tcl.evalc (“puts \ “Message from MyPrivFunc\””);
tcl.evalf (“puts \ “ my_var1 = %d\””, my_var1);
tcl.evalf (“puts \ “ my_var2 = %d\””, my_var2);
2008.03.18(Tue)2008.03.18(Tue) 4242
C++ / OTcl Linkage - summary
TclObject
- Unifies Interpreted (OTcl) and Compiled (C++) class hierarchies
- Seamless access (Method call and Variable access) between OTcl and C++
TclClass
- The mechanism that makes TclObject work
- Interpreted hierarchy & shadowing methods
Tcl
- Primitives ( in C++ ) to access Tcl interpreter
2008.03.18(Tue)2008.03.18(Tue) 4343
Object Orientation in OTcl
Some Differences between C++ & OTcl
- OTcl Class vs. C++ Class architecture
. OTcl attaches methods to Object or Class (evolving)
. C++ has single Class Declaration
- C++/OTcl Split Objects
. Implement methods in either language
. Define instance variables in either C++ or Otcl
Through in different Syntax & Forms
2008.03.18(Tue)2008.03.18(Tue) 4444
Object Orientation in OTcl
class PingAgent : public Agent { public: PingAgent( ); int command(int argc, const char* const* argv); void recv (Packet*, Handler*); protected: int off_ping_;};
Class Link
Link instproc init { src dst } { $self next $self instvar fromNode_ toNode_ … set fromNode_ $src set toNode_ $dst …………}
Link instproc head { } { $self instvar head_ return $head_}
Class structures comparison
2008.03.18(Tue)2008.03.18(Tue) 4545
Object Orientation in OTcl
Some Differences between C++ / OTcl
- instvar : to define/access member variable
- instproc : to define member function (procedure)
- OTcl init{ } vs. C++ Constructor( )
- $self this
- Syntax checking in Tcl/OTcl
. No new line from “{” + body, but only after “{”
. if {, } elseif {, …
2008.03.18(Tue)2008.03.18(Tue) 4646
OTcl Basics
Class Mom
Mom instproc greet {} {
$self instvar age_
puts “$age_ years old mom: How are you doing?”
}
Class Kid -superclass Mom
Kid instproc greet {} {
$self instvar age_
puts “$age_ years old kid: What’s up, dude?”
}
set mom [new Mom]$mom set age_ 45
set kid [new Kid]$kid set age_ 15
$mom greet
$kid greet
45 years old mom: How are you doing?
15 years old kid: What's up, dude?
2008.03.18(Tue)2008.03.18(Tue) 4747
Elemental Tcl Procedures in ns-2 programming
- Creating the Event Scheduler
- [Turn on tracing]
- Creating network
- Setup routing
- Insert errors
- Creating connection(Agents)
- Creating traffic
- Configuring Algorithmic Scenario specific to this App ….
- Start ns simulation
2008.03.18(Tue)2008.03.18(Tue) 4848
Example Procedures
# Application code Tcl/OTcl Script.
set end 200.0set warmup 20.0 # For Stable data timingset linkrate 5Mb # May be Adjusted.
set ns [new Simulator] # ns Created : First line of App
create_topology # Creating topology...
create_agents # Creating agents...
create_sources # Creating traffic sources...
create_conditioners # Creating conditioners...
configure_scheduler # Configuring Queue Scheduler...
$ns at $end "end"
$ns run # Starting simulation...
2008.03.18(Tue)2008.03.18(Tue) 4949
Creating Event Scheduler
Create event scheduler
set ns [new Simulator]
Scheduling Events$ns at <time> “<event>”
<event> : any legitimate ns/tcl commands
Start scheduler
$ns run
2008.03.18(Tue)2008.03.18(Tue) 5050
Event Scheduling
Scheduler
Event QueueTarget objectEvent (Packet)Time
Object BObject A
Deque
Dispatch Dispatch
Register Event
2008.03.18(Tue)2008.03.18(Tue) 5151
Creating Network
Nodes
set n0 [$ns node]
set n1 [$ns node]
. . .
NodeAgent
Link
Node entry
entry_
Agent
Agent
LinkLink
PortClassifier
AddrClassifier
classifier_
dmux_
2008.03.18(Tue)2008.03.18(Tue) 5252
Creating Network
Links and Queuing
$ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type>
<queue_type> : DropTail, RED, CBQ, FQ, SFQ, DRR, WRR
n0 n1
enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_n1 entry_head_
tracing simplex link
duplex link
2008.03.18(Tue)2008.03.18(Tue) 5353
Creating Network
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
Node entry
0
1 enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_n1 entry_head_
Nodes & Links
2008.03.18(Tue)2008.03.18(Tue) 5454
Packet Format
header
data
ip header
tcp header
rtp header
trace header
cmn header
...
ts_
ptype_
uid_
size_
iface_
Packet Format
2008.03.18(Tue)2008.03.18(Tue) 5555
Packet Format
Packet- Fundamental unit of exchange between objects
- Contain packet headers
Packet Header- Per-protocol information
- New protocols may define their own header or may extend existing headers
New Type Packet added in the Application ?
- “ns-allinone2.xx/ns-2.xx/packet.h”
Add “PT_xxx” Type
2008.03.18(Tue)2008.03.18(Tue) 5656
Agents
Agents - UDP TCP/Reno, TCP/NewReno,
- TCP TCP/Sack, TCP/Fack,
- RTP TCP/FullTcp, TCP/Vegas,
- RTCP TCP/Asym, TCP/Reno/Asym,
- SRM TCPSink, TCPSink/….
- SRM/Adaptive
- CtrMcast/Encap, CtrMcast/Decap
- Message, Message/Prune
- Null
: Endpoint where network-layer packets are constructed or consumed, for protocol implementation at various layers.
2008.03.18(Tue)2008.03.18(Tue) 5757
Agents
Agents
- Normally Transport, Routing Entities . End-to-End pair : not Hop-by-Hop . Hop-by-Hop : Routing Agent
- Implemented partly in C++, and partly in OTcl : ~ns-2.x/common/agent.cc, ~ns-2.x/tcl/lib/ns-agent.tcl
- Basic Member functions . Packet* allocpkt() : not over-ridden . void recv(Packet*, Handler) : main entry point
- OTcl Linkage . Agents are created within OTcl code space . set newtcp [new Agent/TCP]
2008.03.18(Tue)2008.03.18(Tue) 5858
Agents
Creation & Attach-Agent{ } set tcp1 [ new Agent/TCP ] set tcp2 [ new Agent/TCPSink ]
$ns attach-agent $node1 $tcp1 $ns attach-agent $node2 $tcp2 $ns connect tcp1 tcp2
# Internally Calls attach{ } method of Node in ns-node.tcl. Simulator instproc attach-agent { node agent } {
$node attach $agent # Compare with below command}
2008.03.18(Tue)2008.03.18(Tue) 5959
Agents
# Attach an Agent to a Node. Pick a Port and Bind the Agent to the Port number. Simulator's attach-agent{ } internally calls this method : $node attach $agent
Node instproc attach { agent { port "" } } { $self instvar agents_ address_ dmux_ classifier_ $self instvar classifiers_ lappend agents_ $agent # agents_ = port list ??
# Attach Agents to this Node (i.e., the Classifier inside). We call the Entry method on ourself to find the front door. Also, stash the node in the Agent and set the local addr of this Agent.
$agent set node_ $self # $self = Node
if [Simulator set EnableHierRt_] { $agent set agent_addr_ [AddrParams set-hieraddr $address_] } else { $agent set agent_addr_ [expr ($address_ & [AddrParams set NodeMask_(1)]) \ << [AddrParams set NodeShift_(1) ] ] } . . .
2008.03.18(Tue)2008.03.18(Tue) 6060
Agents
# If a Port Demuxer doesn't exist, Create it.
if { $dmux_ == "" } { set dmux_ [new Classifier/Port]
# Point the Node's Routing entry to itself at the Port Demuxer if {[Simulator set EnableHierRt_]} { $self add-hroute $address_ $dmux_ } else { $self add-route $address_ $dmux_ ;# install addr in classifier, } ;# classifier target = dmux } if {$port == ""} { set ns_ [Simulator instance] $ns_ instvar nullAgent_ set port [$self alloc-port $nullAgent_] } $agent set agent_port_ $port $self add-target $agent $port ;# send / recv targets of age
nt}
2008.03.18(Tue)2008.03.18(Tue) 6161
Agents
attach-agent (another for comparison) # In contrast, $App attach-agent $agent is used to attach Application to the Agent in C++ level.
int Application::command(int argc, const char*const* argv) { if (strcmp(argv[1], "attach-agent") == 0) // OTcl command { agent_ = (Agent*) TclObject::lookup(argv[2]); if (agent_ == 0) { tcl.resultf("no such agent %s", argv[2]); return(TCL_ERROR); } agent_->attachApp(this); // agent.cc; this = App return(TCL_OK); } ……..
2008.03.18(Tue)2008.03.18(Tue) 6262
End-to-End Transport with Plumbing
0
1
n0 n1
Addr Classifier
Port Classifier
entry_
0 Agent/TCP Addr Classifier
Port Classifier
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSink
dst_=1.0 dst_=0.0Application/FTP
2008.03.18(Tue)2008.03.18(Tue) 6363
Creating Connection
Connect : Transport level
- $ns connect tcp1 tcp2
- UDP
. set udp [new Agent/UDP]
. set null [new Agent/Null]
. $ns attach-agent $n0 $udp
. $ns attach-agent $n1 $null
. $ns connect $udp $null
2008.03.18(Tue)2008.03.18(Tue) 6464
Creating Connection
# Need to check that Agents are already Attached to Nodes : ns-lib.tcl
# This is an Agent-level Connect.
Simulator instproc connect { src dst } {
$self simplex-connect $src $dst # One-way connection
$self simplex-connect $dst $src # The other way return $src}
Simulator instproc simplex-connect { src dst } {
$src set dst_addr_ [$dst set agent_addr_] # Get agent_addr $src set dst_port_ [$dst set agent_port_] # Get agent_port return $src}
2008.03.18(Tue)2008.03.18(Tue) 6565
Creating Connection
Connect : Application level $UA connect $DM : Application-to-Application connection
Http instproc connect { server } {
Http instvar TRANSPORT_
$self instvar ns_ slist_ node_ fid_ id_
lappend slist_ $server # Client side Server List
set tcp [new Agent/TCP/$TRANSPORT_] # Transport_ = FullTcp
$tcp set fid_ [$self getfid]
$ns_ attach-agent $node_ $tcp # $node attach $tcp
# Make a Wrapper in Server, and associate it with Client.
# Client calls <connect>, meanwhile Server calls <alloc-connection>.
set ret [$server alloc-connection $self $fid_] # Server = Manager
set snk [$ret agent] # ret = server wrapper
$ns_ connect $tcp $snk # $ns connect{} : 2 agents
# $tcp set dst_addr_ [$snk set addr_] See $ns connect{}
$tcp set window_ 100
2008.03.18(Tue)2008.03.18(Tue) 6666
Creating Connection
Connect : Application level
# Use a Wrapper(in Client) to implement Application Data Transfer
set wrapper [new Application/TcpApp $tcp] # Agent Wrapper
$self cmd connect $server $wrapper # HttpApp::command( )
# Application(Server) is associated with Client TcpApp Agent wrapper
# TcpApp->target( ) = (Process*) this; tagret( ) : return target_
$wrapper connect $ret # TcpApp connect : private
# dst_ = peer object, with each other
#puts "HttpApp $id_ connected to server [$server id]"
2008.03.18(Tue)2008.03.18(Tue) 6767
Configuring Algorithm/Scenario
Algorithm/Scenario : specific to the Application
- Queue Scheduling/Management parameter configuration
. DropTail, CBQ, FQ, SFQ, DRR, WRR
. RED, MRED
- Network Measurement parameter configuration . Admission Control (QoS)
. Network Measurement & Monitoring
……..
- uncountable examples
2008.03.18(Tue)2008.03.18(Tue) 6868
Drawing Outputs
Xgraph : exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 &
2008.03.18(Tue)2008.03.18(Tue) 6969
Compilation after New Components
xxx.cc : C++ Code Added - “ns-allinone2.xx/ns-2.xx/Makefile.in”
Add “OBJ_CC = xxx.o”
xxx.h : Header Added - Declare New Packet type Data Structure in the header
xxx.tcl : OTcl Library Added - “ns-allinone2.xx/ns-2.xx/Makefile.in”
Add “NS_TCL_LIB=xxx.tcl”
at ns-2.32/: $ make