My Project | Low Rate Wireless Personal Area Networks in NS2

My Final Year Project... Thought of Sharing with others..!

Recent Posts

Useful Links

Internet Marketing
LinkAlizer makes it easy and fast for you to to find link exchange partners and increase traffic.
Free Website Directory

INTRODUCTION

           The IEEE 802.15.4 has recently been adopted as a communication standard for low data rate, low power consumption and low cost Wireless Personal Area Networks. This protocol is quite flexible for a wide range of applications if appropriate tuning of its parameters is carried out. Importantly, the protocol also provides real-time guarantees by using the Guaranteed Time Slot (GTS) mechanism. Indeed, the GTS mechanism is quite attractive for time-sensitive Wireless Sensor Network (WSN) applications, particularly when supported by cluster-tree network topologies, such as defined in the ZigBee standard... Continue Reading


MOTIVATION

The wireless market has been traditionally dominated by high end technologies, but so far Wireless Personal Area Networking products have not been able to make a significant impact on the market. While some technologies like the Bluetooth have been quite a success story, in the areas like computer peripherals, mobile devices, etc, they couldn’t be expanded to the automation arena. This led to the invention of the wireless low data rate personal area networking technology, Zigbee (IEEE 802.15.4),... Continue Reading


Evolution of zigbee

During the last decade there has been an explosion of devices using sensor technologies for control and monitoring purposes. Wired Sensors are now intended to be replaced with wireless technologies. Corporates have been envisioning of a digital home where every device is connected, and remotely controlled and monitored. Even though a perfect digital home is yet a mirage, we are now able to apply several technologies to suite our home and industrial networking needs. However, this concept of a digitally connected home has received a luke warm response due to lack of viable solutions... Continue Reading


Overview of our project 

The objective of our project is to build a simulation model of LR-WPAN and simulated the model using the Network simulator NS2. The WPAN Low Rate Task Group (TG4) is chartered to investigate a low data rate solution with multi-month to multi-year battery life and very low complexity.  This standard specifies two physical layers: an 868 MHz/915 MHz direct sequence spread spectrum PHY and a 2.4 GHz direct sequence spread spectrum PHY.  The 2.4 GHz PHY supports an over air data rate of 250 kb/s and the 868 MHz/915 MHz PHY supports over the air data rates of 20 kb/s and 40 kb/s.... Continue Reading

 

Applications

There has been tremendous excitement on part of the corporates, the market and the consumers alike because of the wide spectrum of applications that zigbee has to other. It is a revolutionary new technology built to compliment or replace existing not so successful technologies. Automation is the buzz word for zigbee. It stands to automate our household, corporate buildings and industries.... Continue Reading

AN OVERVIEW OF IEEE 802.15.4

Compared with wired networks, wireless networks provide advantages in deployment, cost, size, and distributed intelligence. Wireless technology not only enables users to set up a network quickly, but also enables them to set up a network where it is in-convenient or impossible to wire cables. The “care free” feature and convenience of deployment make a wireless network more cost-efficient than a wired network in general... Continue Reading


Network Topologies

A Low rate WPAN supports three different types of topologies.

  •         Star Topology
  •         Peer-to-Peer Topology
  •         Cluster Tree/Mesh Topology... Continue Reading

Network Formation

Network formation is part of the network layer functionalities. An example run of the various steps involved for a network formation is presented:

Star-Topology

  •          Assume a full function device is switched ON for the first time.
  •         It starts scanning its operating channels for possible beacon transmissions, from other PANs... Continue Reading

Architecture

The LR-WPAN architecture is defined in terms of a number of blocks in order to simplify the standard. These blocks are called layers. Each layer is responsible for one part of the standard and offers services to the higher layers. The layout of the blocks is similar to the structure of the OSI layered architecture. But the IEEE 802.15.4 standard only defines the PHY and the MAC layers. The upper layers of networking and application have been left for the application developers. An LR-WPAN device comprises a PHY, which contains the radio frequency (RF) transceiver along with its low-level control mechanism, and a MAC sub layer that provides access to the physical channel for all types of transfer. The figure 2.3 depicts the layered architecture of IEEE 802.15.4... Continue Reading


Functional Overview

The Superframe structure

The superframe structure (Fig: 2.4) is an optional part of a WPAN. It is the time duration between two consecutive beacons. The structure of the superframe is determined by the coordinator. The coordinator can also switch off the use of a superframe by not transmitting the beacons. The superframe duration is divided into 16 concurrent slots. The beacon is transmitted in the first slot. The remaining part of the superframe duration can be described by the terms, CAP, CFP and Inactive. The superframe is used to provide vital statistics like synchronization, identifying the PAN and the superframe structure, to the devices connected in a Wireless PAN. This information is critical for the operation of the PAN in a Beacon enabled network... Continue Reading


Data Transmission

There can be three different types of data transmission possible. They are

Ø Transmission from a device to the coordinator

Ø Transmission from the coordinator to the device

Ø Transmission between any two devices.

In a star topology only the first two transmission techniques are possible...

IEEE 802.15.4 Service Primitives

The new IEEE standard, 802.15.4, defines the physical layer (PHY) and medium access control sublayer (MAC) specifications for low data rate wireless connectivity among relatively simple devices that consume minimal power and typically operate in the Personal Operating Space (POS) of 10 meters or less. An 802.15.4 network can simply be a one-hop star, or, when lines of communication exceed 10 meters, a self-configuring, multi-hop network. A device in an 802.15.4 network can use either a 64-bit IEEE address or a 16-bit short address assigned during the association procedure, and a single 802.15.4 network can accommodate up to 64k (216 ) devices. Wireless links under 802.15.4 can operate in three license free industrial scientific medical (ISM) frequency bands. These accommodate over air data rates of 250 kb/sec (or expressed in symbols, 62.5 ksym/sec) in the 2.4 GHz band, 40 kb/sec (40 ksym/sec) in the 915 MHz band, and 20 kb/sec (20 ksym/sec) in the 868 MHz. Total 27 channels are allocated in 802.15.4, with 16 channels in the 2.4 GHz band, 10 channels in the 915 MHz band, and 1 channel in the 868 MHz band... Continue Reading


PHY Primitives

The primitives indicate the functions organized by each layer. The PHY layer is responsible for the following tasks:

Ø Activation and deactivation of the radio transceiver

Ø Energy Detection

Ø Link Quality Indication Measurement

Ø Clear Channel Assessment

Ø Data Transmission and Reception 

Data Transmission

When ever there is data to be transmitted, the MAC layer Management Entity calls upon the PHY layer with these primitives to transmit a data frame... Continue Reading


MAC Primitives

Data Transmission

The following primitives are used for data transmission from the next higher layer. The result is indicated with confirm primitive. These responses are prepared with respect to its own requests for data transmission to the PHY layer.

MCPS-DATA.request : Requests the transmission of a data unit from the local SSCS entity. It prepares the corresponding MPDU from the incoming SPDU and this is passed on to the PHY layer for transmission...

Continue Reading

NETWORK SIMULATOR

Purpose

NS (version 2) is an object-oriented, discrete event driven network simulator developed at UC Berkely written in C++ and OTcl. NS is primarily useful for simulating local and wide area networks. Although NS is fairly easy to use once you get to know the simulator, it is quite difficult for a first time user, because there are few user-friendly manuals. Even though there is a lot of documentation written by the developers which has in depth explanation of the simulator, it is written with the depth of a skilled NS user. The purpose of this project is to give a new user some basic idea of how the simulator works, how to setup simulation networks, where to look for further information about network components in simulator codes, how to create new network components, etc., mainly by giving simple examples and brief explanations based on our experiences. Although all the usage of the simulator or possible network simulation setups may not be covered in this project, the project should help a new user to get started quickly.

 

3.1.2 Overview

NS is an event driven network simulator developed at UC Berkeley that simulates variety of IP networks. It implements network protocols such as TCP and UPD, traffic source behavior such as... Continue Reading

 

Simple simulation

This section shows a simple NS simulation script and explains what each line does. An OTcl script that creates the simple network configuration and runs the simulation scenario is shown... Continue Reading


EXPLANATION FOR A SIMPLE PROGRAM

The following is the explanation of the script above. In general, an NS script starts with making a Simulator object instance.

set ns [new Simulator]: generates an NS simulator object instance, and assigns it to variable ns (italics is used for variables and values in this section).

What this line does is the following:

Initialize the packet format (ignore this for now)

Create a scheduler (default is calendar scheduler)

Select the default address format (ignore this for now)

 The "Simulator" object has member functions that do the following:

  Create compound objects such as nodes and links (described later)

Connect network component objects created (ex. attach-agent)

Set network component parameters (mostly for compound objects)

Create connections between agents (ex. make connection between a "tcp" and "sink")

Specify NAM display options

Etc... Continue Reading

 

The Network Animator

The network simulator (ns) comes along with an interesting tool, called the Network Animator (NAM). Nam is a Tcl/TK based animation tool for viewing network simulation traces and real world packet trace data. The design theory behind nam was to create an animator that is able to read large animation data sets and be extensible enough so that it could be used in different network visualization situations... Continue Reading

 SIMULATION SETUP

First the simulation model of star and peer-to-peer technology is designed. The following steps are done to simulate the model,

·        Generate the scripts for node arrangement

·        Creating TCL scripts for both the topologies

·        Running the simulation... Continue Reading


Model of Star topology

The node scenario generation is done using the star.scn file. The Start topology model has the following parameters simulated

  • Simulation Parameters

Simulation is a flexible means for assessment of the performance offered by a telecommunication system. However, identifying the correct simulation parameters is key for a successful and nearly realistic analysis


Model of Peer-to-peer topology

The simulation parameters for peer-to-peer topology are mostly simulated similar to that of star topology but for some parameters. The peer-to-peer topology has main advantage that the node can transmit data to different... Continue Reading

 

Simulation Results

The simulation process is carried out systematically as shown,

·        Running Ns2

·        Path setting for NS2

·        Opening Terminal window

·        Running Star.tcl an d Peer.tcl

·        NAM Analysis

Steps to Simulate our project

Ø Firstly the Terminal window in fedora is opened

Ø The path for the NS is loaded

Ø Run the command ns star.tcl or peer.tcl

Continue Reading


[1] IEEE 802.15.4 Standard-2003, “Part 15.4: Wireless Medium Access Control (MAC) and Physical Layer (PHY) Specifications for Low Rate Wireless Personal Area Networks (LR WPANs)”, IEEE SA Standards Board, 2003.

[2] slides by John Heidemann

[3] Retrieved from ns2 website: http://www.isi.edu/nsnam/ns on 12th of Jan 2008

[6] IEEE computer society, “Wireless MAC and PHY Specifications For LR-WPANS” IEEE,2003.

[7] Jianliang Zheng, and Myung J. Lee, “Will IEEE 802.15.4 Make Ubiquitous Networking a Reality?: A Discussion on a Potential Low Power Low Bit Rate Standard” IEEE Communications magazine, pp. 140-146, June 2004.


LR-WPAN is a promising new wireless short range communications technology. It may not have yet swept the short range communications market but it is surely making its presence felt. An alliance of companies called the Zibgbee alliance, have already joined hands to benefit from this new technology and share information and develop new applications. With its promises of short range communications with very low datarates and ultra low power consumption, it has created a market for itself.
A detailed study of the zigbee technology with its internal architecture, and the layered structure has been conducted. Followed by it is a similar study of the simulator environment (ns-2). A detailed study of the zigbee modules built under ns-2 with reference to its implementation in the standard also has been done. Later a well behaved and near realistic simulation scenario is built in TCL. The zigbee modules have been exclusively tested for the simulator environment and several loopholes have been identified. These loopholes are further investigated to replace them with working modules. Both Star and Peer-to-peer topologies have been studied and finalized that the star topology can be used effectively for short range application whereas the peer-to-peer can be used for large application which involves many number of devices.


The simulation process is carried out systematically as shown,
· Running Ns2
· Path setting for NS2
· Opening Terminal window
· Running Star.tcl an d Peer.tcl
· NAM Analysis
Steps to Simulate our project
Ø Firstly the Terminal window in fedora is opened
Ø The path for the NS is loaded
Ø Run the command ns star.tcl or peer.tcl

Fig. 4.2 Simulation terminal for star


The output terminal window appears as shown. In the terminal window the nodes synchronization is stated.
The output Nam appears after the project is executed.
The NAM window shows the animation of the entire process that takes the simulation to complete.

Fig. 4.3 NAM snapshot of Star topology


The peer-to-peer topology is simulated by typing the command
$ ns peer.tcl
The following window shows the simulation in terminal window
Fig. 4.4 simulation terminal for peer-to-peer topology


The following Output Nam will be automatically created and shown as







Fig. 4.5 NAM snapshot of peer-to-topology

Ø The trace files will be generated for both the files,
Ø Star.tr and peer.tr can be viewed for more analysis
Ø The trace files will give a complete scenario of what is been simulated for every micro seconds.

The simulation parameters for peer-to-peer topology are mostly simulated similar to that of star topology but for some parameters. The peer-to-peer topology has main advantage that the node can transmit data to different nodes, that is the communication is possible between the nodes.

Parameter
Value
Traffic Type
FTP
Number of nodes
11
Number of coordinator
1
Traffic direction
Node à node
Simulation time
100 seconds
Figure 4.2 Peer topology parameters

The node scenario generation is done using the star.scn file. The Start topology model has the following parameters simulated
4.1.1 Simulation Parameters
Simulation is a flexible means for assessment of the performance offered by a telecommunication system. However, identifying the correct simulation parameters is key for a successful and nearly realistic analysis
of any study. The following discussion focuses on the task of identifying the correct parameters to generate a realistic network scenario, while explaining their meaning and their reason of choice (if any) in detail. General parameters for basic simulations are described here. However, the parameters that impact the network performance are discussed in the next chapter where we introduce the performance analysis of the system.


Traffic Parameters
Traffic Type
This project report is based on results simulated with a FTP application, based on the internet protocol, UDP (User Datagram Protocol). Its primary features are:
. Single Way Transmission (No Acknowledgements)
. Defined Packet size
. Defined Packet Interval
. Unreliable Data Transmission
FTP traffic with a TCP connection is done due to its advanced features like congestion control, requiring dynamic adjustment of the transmission rate based on the traffic conditions; it is hard to implement simplistic and power efficient devices, for menial applications.
Packet Size
The packet size is assumed be to 70bytes. This is exclusive of the RTR, MAC and PHY layer headers.
Traffic Direction
The traffic flows are all one way, with the communication directed to the coordinator. The study is being investigated with particular focus on low datarate wireless sensors communicating with a central node updating it with the application information.
Number of Nodes
The simulation is carried out with 7 active nodes. One of them being the coordinator.
Coordinators
Since a simple star network topology is being simulated, only a single coordinator is present.
Node Movement
The nodes remain stationary.
Node Position
The nodes are placed along an imaginary circle around the coordinator, with radius equal to the personal operating space of the nodes.
The trace and node parameters are summarized in the following table.



Figure 4.1 Star topology parameters

scen_gen
. Parameters: It accepts the following command line parameters
– scen_gen [number-of-nodes] [X-Pos-of-coord] [Y-Pos-of-coord] [Personal-Operating-Space]
Number-of-nodes: Number of nodes to be placed around the coordinator.
X-Pos-of-coord: X position of the coordinator, with respect to the area of the network dimensions.
Y-Pos-of-coord: Y position of the coordinator, with respect to the area of operation of the network.
Personal-Operating-Space: The operating space or the reachabilitiy of the coordinator. The nodes are required to be placed equidistantly around the coordinator, for the test scenarios in this report, within the operating space of the coordinator, this parameter is utilized to arrange the nodes along an imaginary circle drawn around the coordinator with this value
as radius.
Example: scen gen 11 25 25 10
. Functionality: This utility would automatically generate the coordinates of the nodes to place them around the coordinator, along an imaginary circle drawn with a radius equal to the Personal Operating Space. The node position file, holding the positions of all the nodes around the coordinator is generated from star.scn. Currently this file is being generated with the utility, scen gen. However, it is a simple text file, which can be easily edited to place the nodes at desired positions. Note that the positions of the nodes should respect the boundaries of the network mentioned in the source file, star.tcl
Working: Running the utility would create a file, star.scn, to be used by the source scenario file, star.tcl.
The scn file for star.tcl
$node_(0) set X_ 25
$node_(0) set Y_ 25
$node_(0) set Z_ 0
$node_(1) set X_ 20
$node_(1) set Y_ 16.34
$node_(1) set Z_ 0
$node_(2) set X_ 15
$node_(2) set Y_ 25
$node_(2) set Z_ 0
$node_(3) set X_ 20
$node_(3) set Y_ 33.66
$node_(3) set Z_ 0
$node_(4) set X_ 30
$node_(4) set Y_ 33.66
$node_(4) set Z_ 0
$node_(5) set X_ 35
$node_(5) set Y_ 25
$node_(5) set Z_ 0
$node_(6) set X_ 30
$node_(6) set Y_ 16.34
$node_(6) set Z_ 0

The resultant position file for the nodes would like some think like this:
Figure 4.1 Node arrangement

SIMULATION MODEL
First the simulation model of star and peer-to-peer technology is designed. The following steps are done to simulate the model,
· Generate the scripts for node arrangement
· Creating TCL scripts for both the topologies
· Running the simulation in network simulator
· Analyzing using network simulator
System Requirements
· Operating system – Linux fedora 7
· Package – Ns allinone 2.30
· Scripts – TCL, C++


The network simulator (ns) comes along with an interesting tool, called the Network Animator (NAM). Nam is a Tcl/TK based animation tool for viewing network simulation traces and real world packet trace data. The design theory behind nam was to create an animator that is able to read large animation data sets and be extensible enough so that it could be used in different network visualization situations.Under this constraint nam was designed to read simple animation event commands from a large trace file. In order to handle large animation data sets a minimum amount of information is kept in memory. Event commands are kept in the file and are read from the file whenever necessary. A snapshot of NAM in action is presented
These are the features that can be done using NS-2
• Simulate different scenarios with existing protocols (TCP/UDP)
• Wired Routing protocols - Distance Vector and Link State (with the link state patch)
• Ad-Hoc Routing protocols - DSR, AODV, TORA
• MAC protocols - 802.3, 802.11 (Wireless MAC)
• Scheduling disciplines - DropTail, RED, WFQ, DRR, LQD etc.
• Different traffic characterizations - Poisson, Exponential, Pareto etc.
• Modify NS-2 to implement your own versions of the above protocols or even code totally new protocols
• Measurement of Statistics:
• Throughput, Delay, Jitter etc.
• Queue Monitoring, Drops at Queues.
• Literally all that you will need to know with your simulations.
Graphic visualization - using “nam” (Network Animator)

The following is the explanation of the script above. In general, an NS script starts with making a Simulator object instance.
set ns [new Simulator]: generates an NS simulator object instance, and assigns it to variable ns (italics is used for variables and values in this section).
What this line does is the following:
Initialize the packet format (ignore this for now)
Create a scheduler (default is calendar scheduler)
Select the default address format (ignore this for now)
The "Simulator" object has member functions that do the following:
Create compound objects such as nodes and links (described later)
Connect network component objects created (ex. attach-agent)
Set network component parameters (mostly for compound objects)
Create connections between agents (ex. make connection between a "tcp" and "sink")
Specify NAM display options
Etc.
Most of member functions are for simulation setup (referred to as plumbing functions in the Overview section) and scheduling, however some of them are for the NAM display. The "Simulator" object member function implementations are located in the "ns-2/tcl/lib/ns-lib.tcl" file.
$ns color fid color: is to set color of the packets for a flow specified by the flow id (fid). This member function of "Simulator" object is for the NAM display, and has no effect on the actual simulation.

$ns namtrace-all file-descriptor: This member function tells the simulator to record simulation traces in NAM input format. It also gives the file name that the trace will be written to later by the command $ns flush-trace. Similarly, the member function trace-all is for recording the simulation trace in a general format.
proc finish {}: is called after this simulation is over by the command $ns at 5.0 "finish". In this function, post-simulation processes are specified.
set n0 [$ns node]: The member function node creates a node. A node in NS is compound object made of address and port classifiers (described in a later section). Users can create a node by separately creating an address and a port classifier objects and connecting them together. However, this member function of Simulator object makes the job easier.
$ns duplex-link node1 node2 bandwidth delay queue-type: creates two simplex links of specified bandwidth and delay, and connects the two specified nodes. In NS, the output queue of a node is implemented as a part of a link, therefore users should specify the queue-type when creating links. In the above simulation script, DropTail queue is used. If the reader wants to use a RED queue, simply replace the word DropTail with RED. The NS implementation of a link is shown in a later section. Like a node, a link is a compound object, and users can create its sub-objects and connect them and the nodes.
$ns queue-limit node1 node2 number: This line sets the queue limit of the two simplex links that connect node1 and node2 to the number specified. At this point, the authors do not know how many of these kinds of member functions of Simulator objects are available and what they are.



$ns duplex-link-op node1 node2 : The next couple of lines are used for the NAM display. To see the effects of these lines, users can comment these lines out and try the simulation.
Now that the basic network setup is done, the next thing to do is to setup traffic agents such as TCP and UDP, traffic sources such as FTP and CBR, and attach them to nodes and agents respectively.
set tcp [new Agent/TCP]: This line shows how to create a TCP agent. But in general, users can create any agent or traffic sources in this way. Agents and traffic sources are in fact basic objects (not compound objects), mostly implemented in C++ and linked to OTcl. Therefore, there are no specific Simulator object member functions that create these object instances. To create agents or traffic sources, a user should know the class names these objects (Agent/TCP, Agnet/TCPSink, Application/FTP and so on). This information can be found in the NS documentation or partly in this documentation. But one shortcut is to look at the "ns-2/tcl/libs/ns-default.tcl" file. This file contains the default configurable parameter value settings for available network objects. Therefore, it works as a good indicator of what kind of network objects is available in NS and what are the configurable parameters.
$ns attach-agent node agent: The attach-agent member function attaches an agent object created to a node object. Actually, what this function does is call the attach member function of specified node, which attaches the given agent to itself. Therefore, a user can do the same thing by, for example, $n0 attach $tcp. Similarly, each agent object has a member function attach-agent that attaches a traffic source object to itself.

$ns connect agent1 agent2: After two agents that will communicate with each other are created, the next thing is to establish a logical network connection between them. This line establishes a network connection by setting the destination address to each others' network and port address pair.
Assuming that all the network configuration is done, the next thing to do is write a simulation scenario (i.e. simulation scheduling). The Simulator object has many scheduling member functions. However, the one that is mostly used is the following:
$ns at time "string": This member function of a Simulator object makes the scheduler (scheduler_ is the variable that points the scheduler object created by [new Scheduler] command at the beginning of the script) to schedule the execution of the specified string at given simulation time. For example, $ns at 0.1 "$cbr start" will make the scheduler call a start member function of the CBR traffic source object, which starts the CBR to transmit data. In NS, usually a traffic source does not transmit actual data, but it notifies the underlying agent that it has some amount of data to transmit, and the agent, just knowing how much of the data to transfer, creates packets and sends them.
After all network configurations, scheduling and post-simulation procedure specifications are done, the only thing left is to run the simulation. This is done by $ns run.

This section shows a simple NS simulation script and explains what each line does. An OTcl script that creates the simple network configuration and runs the simulation scenario is shown.

A Simple Network Topology and Simulation Scenario

This network consists of 4 nodes (n0, n1, n2, n3) as shown in above figure. The duplex links between n0 and n2, and n1 and n2 have 2 Mbps of bandwidth and 10 ms of delay. The duplex link between n2 and n3 has 1.7 Mbps of bandwidth and 20 ms of delay. Each node uses a DropTail queue, of which the maximum size is 10. A "tcp" agent is attached to n0, and a connection is established to a tcp "sink" agent attached to n3. As default, the maximum size of a packet that a "tcp" agent can generate is 1KByte. A tcp "sink" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. A "udp" agent that is attached to n1 is connected to a "null" agent attached to n3. A "null" agent just frees the packets received. A "ftp" and a "cbr" traffic generator are attached to "tcp" and "udp" agents respectively, and the "cbr" is configured to generate 1 KByte packets at the rate of 1 Mbps. The "cbr" is set to start at 0.1 sec and stop at 4.5 sec, and "ftp" is set to start at 1.0 sec and stop at 4.0 sec.
A Simple NS Simulation Script is shown below
set ns [new Simulator]
$ns color 0 blue
$ns color 1 red
$ns color 2 white

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

set f [open out.tr w]
$ns trace-all $f
set nf [open out.nam w]
$ns namtrace-all $nf

$ns duplex-link $n0 $n2 5Mb 2ms DropTail
$ns duplex-link $n1 $n2 5Mb 2ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail

$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
set udp1 [new Agent/UDP]
$ns attach-agent $n3 $udp1
$udp1 set class_ 1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
Set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
set null1 [new Agent/Null]
$ns attach-agent $n1 $null1
$ns connect $udp0 $null0
$ns connect $udp1 $null1
$ns at 1.0 "$cbr0 start"
$ns at 1.1 "$cbr1 start"
set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $n0 $tcp
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 1.2 "$ftp start"
$ns at 1.35 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
puts [$cbr0 set packetSize_]
puts [$cbr0 set interval_]
$ns at 3.0 "finish"
proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf
puts "running nam..."
exec nam out.nam &
exit 0
}
$ns run

Purpose
NS (version 2) is an object-oriented, discrete event driven network simulator developed at UC Berkely written in C++ and OTcl. NS is primarily useful for simulating local and wide area networks. Although NS is fairly easy to use once you get to know the simulator, it is quite difficult for a first time user, because there are few user-friendly manuals. Even though there is a lot of documentation written by the developers which has in depth explanation of the simulator, it is written with the depth of a skilled NS user. The purpose of this project is to give a new user some basic idea of how the simulator works, how to setup simulation networks, where to look for further information about network components in simulator codes, how to create new network components, etc., mainly by giving simple examples and brief explanations based on our experiences. Although all the usage of the simulator or possible network simulation setups may not be covered in this project, the project should help a new user to get started quickly.

3.1.2 Overview
NS is an event driven network simulator developed at UC Berkeley that simulates variety of IP networks. It implements network protocols such as TCP and UPD, traffic source behavior such as FTP, Telnet, Web, CBR and VBR, router queue management mechanism such as Drop Tail, RED and CBQ, routing algorithms such as Dijkstra, and more. NS also implements multicasting and some of the MAC layer protocols for LAN simulations. The NS project is now a part of the VINT project that develops tools for simulation results display, analysis and converters that convert network topologies generated by well-known generators to NS formats. Currently, NS (version 2) written in C++ and OTcl (Tcl script language with Object-oriented extensions developed at MIT) is available. This document talks briefly about the basic structure of NS, and explains in detail how to use NS mostly by giving examples. Most of the figures that are used in describing the NS basic structure and network components are from the 5th VINT/NS Simulator Tutorial/Workshop slides and the NS Manual (formerly called "NS Notes and Documentation"), modified little bit as needed. For more information about NS and the related tools, visit the VINT project home page.

Figure 3.1. Simplified User's View of NS

As shown in Figure 3.1, in a simplified user's view, NS is Object-oriented Tcl (OTcl) script interpreter that has a simulation event scheduler and network component object libraries, and network setup (plumbing) module libraries (actually, plumbing modules are implemented as member functions of the base simulator object). In other words, to use NS, you program in OTcl script language. To setup and run a simulation network, a user should write an OTcl script that initiates an event scheduler, sets up the network topology using the network objects and the plumbing functions in the library, and tells traffic sources when to start and stop transmitting packets through the event scheduler. The term "plumbing" is used for a network setup, because setting up a network is plumbing possible data paths among network objects by setting the "neighbor" pointer of an object to the address of an appropriate object. When a user wants to make a new network object, he or she can easily make an object either by writing a new object or by making a compound object from the object library, and plumb the data path through the object. This may sound like complicated job, but the plumbing OTcl modules actually make the job very easy. The power of NS comes from this plumbing.
NS is written not only in OTcl but in C++ also. For efficiency reason, NS separates the data path implementation from control path implementations. In order to reduce packet and event processing time (not simulation time), the event scheduler and the basic network component objects in the data path are written and compiled using C++. These compiled objects are made available to the OTcl interpreter through an OTcl linkage that creates a matching OTcl object for each of the C++ objects and makes the control functions and the configurable variables specified by the C++ object act as member functions and member variables of the corresponding OTcl object. In this way, the controls of the C++ objects are given to OTcl. It is also possible to add member functions and variables to a C++ linked OTcl object. The objects in C++ that do not need to be controlled in a simulation or internally used by another object do not need to be linked to OTcl. Likewise, an object (not in the data path) can be entirely implemented in OTcl. Figure 3.2 shows an object hierarchy example in C++ and OTcl. One thing to note in the figure is that for C++ objects that have an OTcl linkage forming a hierarchy, there is a matching OTcl object hierarchy very similar to that of C++.
Figure 3.2. C++ and OTcl: The Duality

Data Transmission
The following primitives are used for data transmission from the next higher layer. The result is indicated with confirm primitive. These responses are prepared with respect to its own requests for data transmission to the PHY layer.
MCPS-DATA.request : Requests the transmission of a data unit from the local SSCS entity. It prepares the corresponding MPDU from the incoming SPDU and this is passed on to the PHY layer for transmission.
MCPS-DATA.confirm : Reports the result of the request for the transmission of an SPDU over to a single peer SSCS entity.
2.6.2.2 Data Reception
The following primitives are used for data reception from the next lower layer(PHY). The PHY layer upon receiving a data packet informs the upper layer, with an indication about the received packet. And the MAC layer, after analyzing the indication primitive fields, informs the local SSCS entity of an incoming packet data frame, unless it is intended for itself.
MCPS-DATA.indication : The MCPS-DATA.indication primitive indicates the transfer of a data SPDU (i.e., MSDU) from the MAC sublayer to the local SSCS entity. This indicates the arrival of data from the peer SSCS to the local SSCS entity.
2.6.2.3 Association
The primitives that are used to associate a network node or to provide association services, as applicable to a coordinator, are presented here.
MLME-ASSOCIATE.request: The MLME-ASSOCIATE.request primitive allows a device to request an association with a coordinator. The association request is generated at the next higher layer, (generally the routing layer), however it is not part of this study. The conditions that determine the invoking of the association phase is not defined.
MLME-ASSOCIATE.indication: Indicates the reception of an association request command.
MLME-ASSOCIATE.response : This primitive is used to initiate a response to an MLMEASSOCIATE.indication primitive.
MLME-ASSOCIATE.confirm: The MLME-ASSOCIATE.confirm primitive is used to inform the next higher layer of the initiating device whether its request to associate was successful or unsuccessful.
2.6.2.4 Disassociation
Similar to the primitives described for the association phase, the following primitives are used for the disassociation. Their functionality is exactly inverse to that of their counterparts for the association.
MLME-DISASSOCIATE.request
MLME-DISASSOCIATE.indication
MLME-DISASSOCIATE.response
MLME-DISASSOCIATE.confirm


2.6.2.5 PAN Information Management
The following primitives are used to request and to reply back with information about a particular MAC PIB Value.
MLME-GET.request: The next higher layer issues this primitive to the MAC layer to request information about a particular, MAC PIB.
MLME-GET.confirm: This primitive is used by the MAC layer to reply back to the MLMEGET.request primitive received to it by the next higher layer.
MLME-SET.request: Request to set the indicated MAC PIB with the passed value.
MLME-SET.confirm: Returns the result of an attempt to set the indicated PIB value.
2.6.2.6 Orphaning
MLME-ORPHAN.indication: A primitive to indicate to the next higher layer of the presence of an orphan device in the network.
MLME-ORPHAN.response: It helps the next higher layer to respond to the MLMEORPHAN.indication message by the MAC layer. It indicates if the node in question is associated to the network.

2.6.2.7 Receiver Maintainence
The following primitives are used to maintain the receiver enable time.
MLME-RX-ENABLE.request : The next higher layer requests the MAC for the Receiver to be enabled for a finite amount of time.
MLME-RX-ENABLE.confirm : It reports the result of an attempt to enable the receiver.


2.6.2.8 Channel Scanning
These primitives are used to scan the communication channels to determine the presence or absence of PANs.

MLME-SCAN.request: The MLME-SCAN.request primitive is used to initiate a channel scan over a given list of channels. A device can use a channel scan to measure the energy on the channel, search for the coordinator with which it is associated, or search for all coordinators transmitting beacon frames within the POS of the scanning device.
MLME-SCAN.confirm: It reports back to the next higher channel of the result of the channel scan.

Primitives are functions offered by each layer. The four generic types of a primitive are Request, Indication, Response, and Confirm. The PHY layer is responsible for tasks like activating/deactivating the transceiver, CCA, ED, LQI management, Data transmission and reception. The primitives responsible for each of the above described mechanisms are presented and are explained in brief. The PHY primitives are followed by the MAC primitives.

The primitives indicate the functions organized by each layer. The PHY layer is responsible for the following tasks:
Ø Activation and deactivation of the radio transceiver
Ø Energy Detection
Ø Link Quality Indication Measurement
Ø Clear Channel Assessment
Ø Data Transmission and Reception

2.6.1.1 Data Transmission
When ever there is data to be transmitted, the MAC layer Management Entity calls upon the PHY layer with these primitives to transmit a data frame.
PD-DATA.request: The PD-DATA.request primitive is generated by a local MAC sublayer entity and issued to its PHY entity to request the transmission of an MPDU. Upon receiving the PDDATA.request primitive, the PHY first constructs a PPDU with the supplied PSDU.
PD-DATA.confirm : The PD-DATA.confirm primitive is generated by the PHY entity and issued to its MAC sublayer entity in response to a PD-DATA.request primitive. The PD-DATA.confirm primitive will return a status of either SUCCESS, indicating that the request to transmit was successful, or an error code of RX ON or TRX OFF, indicating that the transceiver is working in the Receiver mode or the transceiver is switched off.
2.6.1.2 Data Reception
This primitive is used by the PHY layer to notify the MAC layer of the reception of a data packet.


PD-DATA.indication : The PD-DATA.indication primitive is generated by the PHY entity and issued to its MAC sublayer entity to transfer a received PSDU. This primitive will not be generated if the received PSDU Length field is zero or greater than aMaxPHYPacketSize.
2.6.1.3 Clear Channel Assessment
The following primitives implement the Clear Channel Assessment logic. When ever there is data to be transmitted and the node need to compete with its peers using CSMA-CA, it must go through the CCA phase to ascertain if the channel is free/busy. This function is called upon by the MAC Layer Management Entity.
PLME-CCA.request : The PLME-CCA.request primitive is generated by the MLME and issued to its PLME whenever the CSMA-CA algorithm requires an assessment of the channel.
PLME-CCA.confirm : The PLME-CCA.confirm primitive reports the results of a CCA analysis.
2.6.1.4 Energy Detection
The following primitives are responsible for implementing energy detection of the channel. The MAC layer request for such a service and the PHY layer performs the Energy Detection and replies back with the result of the operation.
PLME-ED.request : The PLME-ED.request primitive requests that the PLME perform an ED(Energy Detection) measurement.
PLME-ED.confirm : The PLME-ED.confirm primitive reports back the results of the ED measurement to the MLME.



2.6.1.5 PAN Information Management
The following primitives are subsequently used by the MAC and the PHY layer entities to access a particular PIB value, or either to set a value for a PIB property.
PLME-GET.request: The PLME-GET.request primitive requests information about a given PHY PIB attribute.
PLME-GET.confirm : The PLME-GET.confirm primitive reports the results of an information request from the PHY PIB.
PLME-SET.request : The PLME-SET.request primitive attempts to set the indicated PHY PIB attribute to the given value.
PLME-SET.confirm : The PLME-SET.confirm primitive reports the results of the attempt to set a PIB attribute.

2.6.1.6 Activate/Deactivate Radio Transceiver
The following two primitives are responsible for implementing the function of activating and deactivatingthe transceiver.
PLME-SET-TRX-STATE.request: The PLME-SET-TRX-STATE.request primitive requests that the PHY entity change the internal operating state of the transceiver. The transceiver will have three main states:
Ø Transceiver disabled (TRX OFF)
Ø Transmitter enabled (TX ON)
Ø Receiver enabled (RX ON)

PLME-SET-TRX-STATE.confirm:
The PLME-SET-TRX-STATE.confirm primitive reports the result
of a request to change the internal operating state of the transceiver.

Not all blocks in Figure 2. Logical blocks in the transceiver PHY layer are required to implement a communications system. However, if the functionality is used (even optionally) in the specification, then the cost for implementing the functionality must be included in the cost estimate. The blocks may occur in different orders in the chain, for example, the frequency spreading may be a part of the modulate/demodulate portion or the encryption may precede the source encoding and the decryption follow the source decoding.












Figure 2.11 Logical blocks in the transceiver PHY layer

· Source Encode/Decode – packet formation including headers, data interleaving, error correction/detection (FEC, CRC, etc), compression/decompression. This function is optional, include if it applies to the proposed system.
· Encrypt/Decrypt – bit level operations to protect data. This function is optional, include if it applies to the proposed system.
· Channel encode/decode – bias suppression, symbol spreading/de-spreading (e.g. DSSS), data whitening/de-whitening (or scrambling). This function is optional, include if it applies to the proposed system.
· Modulate/Demodulate – convert digital data to analog format, can include symbol filtering, frequency conversion, frequency filtering.
· Frequency Spreading/De-spreading – can include frequency hopping or other techniques to decrease or increase, respectively, the bits/Hz of the analog signal in the channel. This function is optional, include if it applies to the proposed system.
· Transmit/Receive – transition the signal to/from the channel.