Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Transport

p Control Protocols and


UDP Agents

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1
A Two
T Node
N d Network
N k
Application
pp cat on

Source Agent Sink Agent

packet
n0 n1

Link:
Agent: Connecting
g Nodes
Packet Creation and Buffer Management
Destruction
Application: Node:
Demand Indication A computer host +
A router

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 2
O li
Outline
• Introduction
• NS2 Transport Layer Agents
• N
Networkk Configuration
C fi i
• UDP Agents
g
• Summary

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 3
Agent
• Creating/destroying packets
• Two main types
• 1 Routing
1. R i agents: RRouting
i packets
k
• 2. Transport
p layer
y agents:
g TCP/UDP
packets

Q: what is the main functionality of


a transport layer protocol?
( End-to-end Flow control and Error control )

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 4
R i
Review of
f the
h OSI M
Model
d l
• L1: Physical
y layer:
y Define max. speed
p of a medium.
• L2: Data link layer: Control speed/error between two
connecting nodes.
• L3
L3: Routing:
Routing Find the way to reach the destination node.
• L4: Transport Layer: Control speed/error AT the SOURCE
node.
L2:
L3: Speed between
L4:
Determine two nodes
Speed at the
TCP the routes
source node
TCPSink

L1: Max. speed


of the cable

destination
source T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Textbook: 5
T
Transport Layer
L Protocols
P l
• Encapsulate packets from layers 11, 2,
2 and 3
• End-to-end Flow control
– At the source node
– Control the sending rate
– Regardless
g of Route, Link-layer
y protocols,
p and
Physical medium
• End-to-end error control
– ACK/NACK
– Packet retransmission

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 6
O li
Outline
• Introduction
• NS2 Transport Layer Agents
• N
Networkk Configuration
C fi i
• UDP Agents
g
• Summary

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 7
T
Transport Layer
L Agents
A
• Application:
pp Create user demand to send data
• Simulator: Indicate the source and destination
• Sending Agent
– Input
• Src/Dst indicated by the Simulator
• User demand indicated by the Application
– Create packets
p
– Send out packets to lower layer network
– Control the rate at which the packets are sent.
• Receiving Agents
– Destroy packets
– Send out acknowledgement

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 8
C and
C++ d OTcl
OT l Implemenation
I l i
• C++ and OTcl class Agent
• C++ class Agent derives from class
Connector
• Base class for all Agent
– UdpAgent  Agent/UDP,
– TcpAgent  Agent/TCP

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 9
C and
C++ d OTcl
OT l Variables
V i bl
C++ Type C++ variable OTcl instvar Description
ns_addr_t here_

here_.addr_ agent_addr_ Address of the attached node


here_.port_ agent_port_ Port where the agent is attached
ns_addr_t dst_
Address off the node attaching
g to
dst_.addr_ dst_addr_ a peering agent
Port where the peering agent is
dst_.port_ dst_port_ attached
int size_ N/A Packet size
packet_t type_ N/A Packet type
int seqno
q _ N/A Current sequence
q number

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 10
C and
C++ d OTcl
OT l Variables
V i bl
C++ Type C++ variable OTcl instvar Description
int fid_ fid_ Flow ID
IPv6 priority field (e.g., 0 =
unspecified, 1 = background
int prio_ prio_ traffic)
int flags_ flags_ Flags
int defttl_ ttl_ Default time to live value
Application* app_ N/A A pointer to an application
Total number of packets
int uidcnt_ N/A generated by all agents

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 11
C Implementation
C++ I l i
Function Meaning g
recv(p,h) Receives a packet p.
send(p,h) Sends a packet p to the attached Application.
send(nbytes) Sends a message with nbytes bytes to the
attached Application.
sendmsg(nbytes) Sends a message with nbytes bytes to the
attached Application.
Application
timeout(tno) Actions to be performed at timeout
connect(dst) Connects to a dynamic destination dst .
close() Closes a connection-oriented
connection oriented session .
listen() Waits for a connection-oriented session .

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 12
C Implementation
C++ I l i
Function Meaning
attachApp(app) Stores app in variable app_.
ocp t() Creates a packet.
allocpkt()
a packet
initpkt(p) Initializes the input packet p.
recvBytes(bytes) Sends data of bytes bytes to the attached
application.
application
idle() Tells the application that the agent has nothing to
transmit.

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 13
C Implementation
C++ I l i
• Funct
Function
n sendmsg(nbytes)
g( y )
– Invoked by application to send a message
– Implemented in the derived class
• Function
F ti recv(p,h)
( h)
void Agent::recv(Packet* p, Handler*)
{
if (
(app_)
)
app_->recv(hdr_cmn::access(p)->size());
Packet::free(p);
}

• Function attachApp(app)
void Agent::attachApp(Application *app)
{
app_ = app;
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 14
C Implementation
C++ I l i
• Function allocpkt() • Function initpkt(p)
Packet* Agent::allocpkt() const void Agent::initpkt(Packet* p)
{ {
Packet* p = Packet::alloc();
() hdr_cmn* ch = hdr_cmn::access(p);
(p)
initpkt(p); ch->uid() = uidcnt_++;
return (p); ch->ptype() = type_;
} ...
hdr_ip* iph = hdr_ip::access(p);
iph >saddr() = here
iph->saddr() here_.addr_;
addr ;
iph->sport() = here_.port_;
iph->daddr() = dst_.addr_;
iph->dport() = dst_.port_;
...
}

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 15
A Guide for
f r Creatin
Creating a New A
Agent
ent
11. Define the hierarchy: Based/derived classes
2. Define C++ and OTcl class variables
3 Define the constructor in both the
3.
hierarchy (bind the C++/OTcl variables here)
4 Implement the following key functions
4.
sendmsg(nbyte), recv(p,h), timeout(tno)
5. Define OTcl commands
5
6. Define timer (if necessary)

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 16
O li
Outline
• Introduction
• NS2 Transport Layer Agents
• N
Networkk Configuration
C fi i
• UDP Agents
g
• Summary

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 17
N
Network
k Configuration
C fi i
• 4 Steps in an OTcl simulation script
1. Create a sending agent, a receiving agent,
and an application
2. Connect the agents to the applications
3 Connect the agents to the low
3. low-level
level
network
4. Associating sending and receiving agents

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 18
Applications, Agents,
and
d Low-level
L l l Networks
ork of NsObjectss
A Netwo
N k

What is the class of Link 2?


( SimpleLink )
What domain does it lie in ?
( OTcl
OT l )

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 19
OT l simulation
OTcl i l i script
i
set ns [new Simulator]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n1 $n2 5Mb 2ms DropTail
$ns duplex-link $n2 $n3 5Mb 2ms DropTail
$ns duplex-link $n1 $n3 5Mb 2ms DropTail
Focus here!!
#=== UDP-Null peering starts here ===
set udp [new Agent/UDP] Step1: The creation
set null [new Agent/Null]
set cbr [new Application/Traffic/CBR]
$cbr attach-agent
attach agent $udp Step2: Agent  Application
$ns attach-agent $n1 $udp
$ns attach-agent $n3 $null
$ns connect $udp $null Step3: Agent  Network

Step4: Sending  Receiving


Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 20
N
Network
k Configuration
C fi i
Step1:
p The Creation
• An Agent instance: new Agent/<type>
• An Application instance: new Application/<type>
Step2 Agent  Application
Step2:
• Use OTcl command of class Application

$app
pp attach-agent
g $agent
g

//~ns/apps/app.cc
int Application::command(int argc, const
char*const*
char const argv){
if (strcmp(argv[1], "attach-agent") == 0) {
agent_ = (Agent*) TclObject::lookup(argv[2]);
agent_->attachApp(this);
return(TCL_OK); //~ns/common/agent.cc
} void Agent::attachApp(Application *app)
app)
{
app_ = app;
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 21
N
Network
k Configuration
C fi i
Step3: Agent  Network
• Use OTcl command of class Simulator
(see Chapter 6: Node)

$ns attach-agent
attach agent $node $agent

1. $ns attach-agent $node $agent


2
2. $node attach $agent {port “”}
}
3. $node add-target $agent $port
4. $rm attach $agent $port
5
5. $agent target [[$self node] entry]
5. [[$self node] demux] install $port $agent

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 22
N
Network
k Configuration
C fi i
Step4 Sending
Step4: SendingReceiving
Receiving
• Use an OTcl command of class Simulator
$ns connect $s_agent $r_agent

//~/ns/tcl/lib/ns-lib.tcl
Simulator instproc connect {src dst} { When a packet is
... created ports and
$self simplex-connect $src $dst addresses of the
$self simplex-connect $dst $src source and
}
destination are
stored
d in the
h packet
k
Simulator instproc simplex-connect { src dst } {
...
$src set dst_addr_ [$dst set agent_addr_]
$
$src set
t d
dst_port_
t t [$d
[$dst
t set
t agent_port_]
t t ]
}

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 23
Applications, Agents,
and
d Low-level
L l l Networks
ork of NsObjectss
A Netwo
N k

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 24
O li
Outline
• Introduction
• NS2 Transport Layer Agents
• N
Networkk Configuration
C fi i
• UDP Agents
g
• Summary

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 25
U
User Datagram
D Protocol
P l
• Transport layer protocol
• Unreliable and connectionless
• RFC 1122
(http://www.networksorcery.com/enp/protocol/udp.htm)
• Main functionality
f y
– Mux/Demux data flows in source/destination
nodes
– Put the address/port of source/destination
node in packets, and
– Forward
F d to
t th
the packet
k t tto IP llayer.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 26
UDP: NS2 Implementation
l

• Two types of Agents


1 S
1. Sending
di A Agent
– OTcl: Agent/UDP  C++: UdpAgent
2. Receiving Agent
– OTcl: Agent/Null
g  C++: None
– See ~ns/tcl/lib/ns-agent.tcl

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 27
A Guide for Creating a New Agent
11. Define the hierarchy: Based/derived classes
2. Define C++ and OTcl class variables
3 Define the constructor in both the hierarchy
3.
(bind the C++/OTcl variables here)
4 Implement the following key functions
4.
sendmsg(nbyte), recv(p,h), timeout(tno)
5. Define OTcl commands
5
6. Define timer (if necessary)

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 28
UDP Sending
S di Agent
A
Step1: Define class inheritance
– C++: Agent  UdpAgent
– OTcl: Agent
g  Agent/UDP
g
– Binding C++ and OTcl classes
//~/ns/apps/udp.cc
static class UdpAgentClass : public TclClass {
public:
UdpAgentClass() : TclClass("Agent/UDP") {}
TclObject* create(int, const char*const*) {
return (new UdpAgent());
} What is the
} class_udp_agent; difference between

Step2: Define variables


Step2
UdpAgent::seqno_
and Packet::uid_?
Packet::uid ?
– C++: UdpAgent::seqno_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 29
UDP Sending
S di Agent
A
Step3: Define the constructors
– C++:
//~/ns/apps/udp.cc
UdpAgent::UdpAgent() : Agent(PT_UDP), seqno_(-1){
bind("packetSize_", &size_);
}
??
// / /
//~/ns/common/agent.cc
/ t
Agent::Agent(packet_t pkttype):
size_(0),type_(pkttype),app_(0){}

– OTcl: None

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 30
A Guide for Creating a New Agent
11. Define the hierarchy: Based/derived classes
2. Define C++ and OTcl class variables
3 Define the constructor in both the hierarchy
3.
(bind the C++/OTcl variables here)
4 Implement the following key functions
4.
sendmsg(nbyte), recv(p,h), timeout(tno)
5. Define OTcl commands
5
6. Define timer (if necessary)

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 31
UDP Sending
S di Agent
A
Step4 Define C++
Step4: C functions
– recv(p,h):
• Main packet reception function
• Invoked by: an underlying NsObject
• What it does:
1. Tell the application
pp of the amount of data received.
2. Destroy the packet

void Agent::recv(Packet
Agent::recv(Packet* p, Handler
Handler*)
)
{
if (app_)
app_->recv(hdr_cmn::access(p)->size());
Packet::free(p);
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 32
UDP Sending
S di Agent
A
– sendmsg(nbytes,data,flags):
g( y , , g )
• Send out nbytes bytes of data
• Invoked by: the attached application
• Wh t it does:
What d s: Create
C t andd ssend
d outt th
the packets
k ts
//~/ns/apps/udp.cc
virtual void sendmsg(int nbytes, const char *flags = 0){
sendmsg(nbytes, NULL, flags);
}
void UdpAgent::sendmsg(int nbytes,AppData* data,const char* flags)
{
p int n = nbytes
Packet *p; y / size_;
while (n-- > 0) {
p = allocpkt(); hdr_cmn::access(p)->size() = size_;...
target_->recv(p);
}
...
idle();
}
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 33
UDP Sending
S di Agent
A
Step5: Define OTcl commands and Instprocs
Step5

• Two key Otcl commands: send{nbytes,str},


sendmsg{nbytes,str,flags}
d { b fl }
• Send nbytes bytes of packets whose content is str
• Make use of
UdpAgent::sendmsg(nbytes,str,flag)
• y used
Not usually
• Usually: Application C++ object invokes
UdpAgent::sendmsg(nbytes)

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 34
UDP NS2 Implementation
UDP: I l i
• Two types of Agents
1. Sending Agent
– OTcl:
OT l Agent/UDP
/  C++:
C UdpAgent
d
2. Receiving Agent
– OTcl: Agent/Null  C++: None
– See ~ns/tcl/lib/ns-agent.tcl
• Associating Sending and Receiving
g
Agents

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 35
UDP Receiving
R i i Agent
A
Step1: Define class inheritance
Step1
– C++: None
– OTcl: Agent  Agent/Null
Step2:
St 2 Define
D fi variables:
i bl N
None
Step3: Define the constructor: None (use that of Agent)
Step4: Define key function: None (use that of Agent)
void Agent::recv(Packet* p, Handler*)
{
if (app_)
app_->recv(hdr_cmn::access(p)->size());
Packet::free(p);
}

Step5: Define OTcl commands and Instprocs: None


Step6: Define Timer: None
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 36
O li
Outline
• Introduction
• NS2 Transport Layer Agents
• N
Networkk Configuration
C fi i
• UDP Agents
g
• Summary

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 37
Summary
• Main functionality
y
– Application ( Model User Demand: How much? )
– Simulator ( Select Source/Destination: Where? )
– Agent
1) create/destroy packets,
2) control sending rate, and
3) acknowledging
• UDP agents
– S
Sender
d ( UdpAgent
Ud A t  Agent/UDP
A t/UDP )
– Receiver ( N/A  Agent/Null )

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 38

You might also like