Saturday 28 January 2017

NS2 PROGRAM TUTORIAL FOR WIRELESS TOPOLOGY

In this section, you are going to learn to use the mobile wireless simulation model available in ns. The section consists of two parts. In the first subsection, we discuss how to create and run a simple 2-node wireless network simulation. In second subsection, we will extend our program to create a relatively more complex wireless scenario.

1. Creating a simple wireless scenario 

We are going to simulate a very simple 2-node wireless scenario. The topology consists of two mobile nodes, node_(0) and node_(1). The mobile nodes move about within an area whose boundary is defined in this example as 500m X 500m. The nodes start out initially at two opposite ends of the boundary. Then they move towards each other in the first half of the simulation and again move away for the second half. A TCP connection is setup between the two mobile nodes. Packets are exchanged between the nodes as they come within hearing range of one another. As they move away, packets start getting dropped.
Just as with any other ns simulation, we begin by creating a tcl script for the wireless simulation. We will call this file simple-wireless.tcl.
If you want to download a copy of simple-wireless.tcl click here.

A mobile node consists of network components like Link Layer (LL), Interface Queue (IfQ), MAC layer, the wireless channel nodes transmit and receive signals from etc. 

At the beginning of a wireless simulation, we need to define the type for each of these network components. Additionally, we need to define other parameters like the type of antenna, the radio-propagation model, the type of ad-hoc routing protocol used by mobilenodes etc. See comments in the code below for a brief description of each variable defined. The array used to define these variables, val() is not global as it used to be in the earlier wireless scripts.We begin our script simple-wireless.tcl with a list of these different parameters described above, as follows:

# ======================================================================
# Define options
# ======================================================================
set val(chan)         Channel/WirelessChannel  ;# channel type
set val(prop)         Propagation/TwoRayGround ;# radio-propagation model
set val(ant)          Antenna/OmniAntenna      ;# Antenna type
set val(ll)           LL                       ;# Link layer type
set val(ifq)          Queue/DropTail/PriQueue  ;# Interface queue type
set val(ifqlen)       50                       ;# max packet in ifq
set val(netif)        Phy/WirelessPhy          ;# network interface type
set val(mac)          Mac/802_11               ;# MAC type
set val(rp)           DSDV                     ;# ad-hoc routing protocol 
set val(nn)           2                        ;# number of mobilenodes

Next we go to the main part of the program and start by creating an instance of the simulator,
set ns_ [new Simulator]

Then setup trace support by opening file simple.tr and call the procedure trace-all {} as follows:
set tracefd [open simple.tr w]
$ns_ trace-all $tracefd           

Next create a topology object that keeps track of movements of mobilenodes within the topological boundary.
set topo [new Topography]

We had earlier mentioned that mobile nodes move within a topology of 500m X 500m. We provide the topography object with x and y co-ordinates of the boundary, (x=500, y=500) :
$topo load_flatgrid 500 500

The topography is broken up into grids and the default value of grid resolution is 1. A diferent value can be passed as a third parameter to load_flatgrid {} above.

Next we create the object God, as follows:
create-god $val(nn)

Quoted from CMU document on god, "God (General Operations Director) is the object that is used to store global information about the state of the environment, network or nodes that an omniscent observer would have, but that should not be made known to any participant in the simulation." Currently, God object stores the total number of mobile nodes and a table of shortest number of hops required to reach from one node to another. The next hop information is normally loaded into god object from movement pattern files, before simulation begins, since calculating this on the fly during simulation runs can be quite time consuming. However, in order to keep this example simple we avoid using movement pattern files and thus do not provide God with next hop information. The usage of movement pattern files and feeding of next hop info to God shall be shown in the example in the next sub-section.
     
The procedure create-god is defined in ~ns/tcl/mobility/com.tcl, which allows only a single global instance of the God object to be created during a simulation. In addition to the evaluation functionalities, the God object is called internally by MAC objects in mobile nodes. So even though we may not utilize God for evaluation purposes,(as in this example) we still need to create God.

Next, we create mobile nodes. The node creation APIs have been revised and here we shall be using the new APIs to create mobile nodes. 

IMPORTANT NOTE: The new APIs are not available with ns2.1b5 release. Download the daily snapshot version if the next release (2.1b6 upwards) is not as yet available.

First, we need to configure nodes before we can create them. Node configuration API may consist of defining the type of addressing (flat/hierarchical etc), the type of adhoc routing protocol, Link Layer, MAC layer, IfQ etc. The configuration API can be defined as follows:


                                   (parameter examples)
# $ns_ node-config -addressingType flat or hierarchical or expanded
#                  -adhocRouting   DSDV or DSR or TORA
#                  -llType    LL
#                  -macType    Mac/802_11
#                  -propType    "Propagation/TwoRayGround"
#                  -ifqType    "Queue/DropTail/PriQueue"
#                  -ifqLen    50
#                  -phyType    "Phy/WirelessPhy"
#                  -antType    "Antenna/OmniAntenna"
#                  -channelType    "Channel/WirelessChannel"
#                  -topoInstance   $topo
#                  -energyModel    "EnergyModel"
#                  -initialEnergy  (in Joules)
#                  -rxPower        (in W)
#                  -txPower        (in W)
#                  -agentTrace     ON or OFF
#                  -routerTrace    ON or OFF
#                  -macTrace       ON or OFF
#                  -movementTrace  ON or OFF

All default values for these options are NULL except: addressingType: flat

We are going to use the default value of flat addressing; Also lets turn on only AgentTrace and RouterTrace; You can experiment with the traces by turning all of them on. AgentTraces are marked with AGT, RouterTrace with RTR and MacTrace with MAC in their 5th fields. MovementTrace, when turned on, shows the movement of the mobilenodes and the trace is marked with M in their 2nd field.

The configuration API for creating mobilenodes looks as follows:

# Configure nodes
        $ns_ node-config -adhocRouting $val(rp) \
                         -llType $val(ll) \
                         -macType $val(mac) \
                         -ifqType $val(ifq) \
                         -ifqLen $val(ifqlen) \
                         -antType $val(ant) \
                         -propType $val(prop) \
                         -phyType $val(netif) \
                         -topoInstance $topo \
                         -channelType $val(chan) \
                         -agentTrace ON \
                         -routerTrace ON \
                         -macTrace OFF \
                         -movementTrace OFF

Next we create the 2 mobilenodes as follows:

        for {set i 0} {$i < $val(nn) } {incr i} {
                set node_($i) [$ns_ node ]
                $node_($i) random-motion 0       ;# disable random motion
        }    

The random-motion for nodes is disabled here, as we are going to provide node position and movement(speed & direction) directives next.

Now that we have created mobilenodes, we need to give them a position to start with,

#
# Provide initial (X,Y, for now Z=0) co-ordinates for node_(0) and node_(1)
#
$node_(0) set X_ 5.0
$node_(0) set Y_ 2.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
$node_(1) set Z_ 0.0

Node0 has a starting position of (5,2) while Node1 starts off at location (390,385).

Next produce some node movements,

#
# Node_(1) starts to move towards node_(0)
#
$ns_ at 50.0 "$node_(1) setdest 25.0 20.0 15.0"
$ns_ at 10.0 "$node_(0) setdest 20.0 18.0 1.0"

# Node_(1) then starts to move away from node_(0)
$ns_ at 100.0 "$node_(1) setdest 490.0 480.0 15.0" 

$ns_ at 50.0 "$node_(1) setdest 25.0 20.0 15.0" means at time 50.0s, node1 starts to move towards the destination (x=25,y=20) at a speed of 15m/s. This API is used to change direction and speed of movement of the mobilenodes.

Next setup traffic flow between the two nodes as follows:
# TCP connections between node_(0) and node_(1)

set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp
$ns_ attach-agent $node_(1) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at 10.0 "$ftp start" 

This sets up a TCP connection betwen the two nodes with a TCP source on node0.

Then we need to define stop time when the simulation ends and tell mobilenodes to reset which actually resets thier internal network components,

#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 150.0 "$node_($i) reset";
}
$ns_ at 150.0001 "stop"
$ns_ at 150.0002 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
    close $tracefd
}

At time 150.0s, the simulation shall stop. The nodes are reset at that time and the "$ns_ halt" is called at 150.0002s, a little later after resetting the nodes. The procedure stop{} is called to flush out traces and close the trace file. And finally the command to start the simulation,
puts "Starting Simulation..."
$ns_ run

Save the file simple-wireless.tcl. In order to download a copy of the file click here. Next run the simulation in the usual way (type at prompt: "ns simple-wireless.tcl" )

At the end of the simulation run, trace-output file simple.tr is created. As we have turned on the AgentTrace and RouterTrace we see DSDV routing messages and TCP pkts being received and sent by Router and Agent objects in node _0_ and _1_. Note that all wireless traces starts with WL in their first field. See Chapter 15 of ns documentation for details on wireless trace. We see TCP flow starting at 10.0s from node0. Initially both the nodes are far apart and thus TCP pkts are dropped by node0 as it cannot hear from node1. Around 81.0s the routing info begins to be exchanged between both the nodes and around 100.0s we see the first TCP pkt being received by the Agent at node1 which then sends an ACK back to node0 and the TCP connection is setup. However as node1 starts to move away from node0, the connection breaks down again around time 116.0s. Pkts start getting dropped as the nodes move away from one another.
2. Using node-movement/traffic-pattern files and other features in wireless simulations 

As an extension to the previous sub-section, we are going to simulate a simple multi hop wireless scenario consisting of 3 mobile nodes here. As before, the mobile nodes move within the boundaries of a defined topology. However the node movements for this example shall be read from a node-movement file called scen-3-test. scen-3-test defines random node movements for the 3 mobile nodes within a topology of 670mX670m. This file is available as a part of the ns distribution and can be found, along with other node-movement files, under directory ~ns/tcl/mobility/scene. Random node movement files like scen-3-test can be generated using CMU's node-movement generator "setdest". Details on generation of node movement files are covered in Generating traffic-connection and node-movement files for large wireless scenarios section of this tutorial.

In addition to node-movements, traffic flows that are setup between the mobile nodes, are also read from a traffic-pattern file called cbr-3-test. cbr-3-test is also available under ~ns/tcl/mobility/scene. Random CBR and TCP flows are setup between the 3 mobile nodes and data packets are sent, forwarded or received by nodes within hearing range of one another. See cbr-3-test to find out more about the traffic flows that are setup. These traffic-pattern files can also be generated using CMU's TCP/CBR traffic generator script. More about this is discussed in Generating traffic-connection and node-movement files for large wireless scenarios section of this tutorial.

We shall make changes to the script, simple-wireless.tcl, we had created in above section. and shall call the resulting file wireless1.tcl. For a copy of wireless1.tcl download from here. In addition to the variables (LL, MAC, antenna etc) that were declared at the beginning of the script, we now define some more parameters like the connection-pattern and node-movement file, x and y values for the topology boundary, a seed value for the random-number generator, time for the simulation to stop, for convenience. They are listed as follows:
set val(chan) Channel/WirelessChannel
set val(prop)       Propagation/TwoRayGround
set val(netif)      Phy/WirelessPhy
set val(mac)        Mac/802_11
set val(ifq)        Queue/DropTail/PriQueue
set val(ll)         LL
set val(ant)        Antenna/OmniAntenna
set val(x)              670   ;# X dimension of the topography
set val(y)              670   ;# Y dimension of the topography
set val(ifqlen)         50            ;# max packet in ifq
set val(seed)           0.0
set val(adhocRouting)   DSR
set val(nn)             3             ;# how many nodes are simulated
set val(cp)             "../mobility/scene/cbr-3-test" 
set val(sc)             "../mobility/scene/scen-3-test" 
set val(stop)           2000.0           ;# simulation time

Number of mobile nodes is changed to 3; Also we use DSR (dynamic source routing) as the adhoc routing protocol inplace of DSDV (Destination sequence distance vector);

After creation of ns_, the simulator instance, open a file (wireless1-out.tr) for wireless traces. Also we are going to set up nam traces.
set tracefd [open wireless1-out.tr w] ;# for wireless traces
$ns_ trace-all $tracefd

set namtrace [open wireless1-out.nam w]           ;# for nam tracing
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

Next (after creation of mobile nodes) source node-movement and connection pattern files that were defined earlier as val(sc) and val(cp) respectively.

# Define node movement model
#
puts "Loading connection pattern..."
source $val(cp)

# 
# Define traffic model
#
puts "Loading scenario file..."
source $val(sc)

In node-movement file scen-3-test, we see node-movement commands like
$ns_ at 50.000000000000 "$node_(2) setdest 369.463244915743 \
170.519203111152 3.371785899154"

This, as described in earlier sub-section, means at time 50s, node 2 starts to move towards destination (368.4,170.5) at a speed of 3.37m/s. We also see other lines like
$god_ set-dist 1 2 2

These are command lines used to load the god object with the shortest hop information. It means the shortest path between node 1 and 2 is 2 hops. By providing this information, the calculation of shortest distance between nodes by the god object during simulation runs, which can be quite time-consuming, is prevented.

The setdest program (see Generating traffic-connection and node-movement files for large wireless scenarios) generates movement pattern files using the random waypoint algorithm. The node-movement files generated using setdest (like scen-3-test) already include lines like above to load the god object with the appropriate information at the appropriate time.
A program called calcdest (~ns/indep-utilities/cmu-scen-gen/setdest/calcdest) can be used to annotate movement pattern files generated by other means with the lines of god information. calcdest makes several assumptions about the format of the lines in the input movement pattern file which will cause it to fail if the file is not formatted properly. If calcdest rejects a movement pattern file you have created, the easiest way to format it properly is often to load it into ad-hockey and then save it out again. If ad-hockey can read your input correctly, its output will be properly formatted for calcdest.

Both setdest and calcdest calculate the shortest number of hops between nodes based on the nominal radio range, ignoring any effects that might be introduced by the propagation model in an actual simulation. The nominal range is either provided as an argument to the programs, or extracted from the header in node-movement pattern files.

The path length information provided to god was used by CMU's Monarch Project to analyze the path length optimality of ad hoc network routing protocols, and so was printed out as part of the CMUTrace output for each packet.

Other uses that CMU has found for the information are:
  • Characterizing the rate of topology change in a movement pattern.
  • Identifying the frequency and size of partitions.
  • Experimenting with the behavior of the routing protocols if the god information is used to provide           them with ``perfect'' neighbor information at zero cost.


Next add the following lines for providing initial position of nodes in nam. However note that only node movements can currently be seen in nam . Dumping of traffic data and thus visualization of data pkt movements in nam for wireless scenarios is still not supported (future work).
# Define node initial position in nam

for {set i 0} {$i < $val(nn)} {incr i} {

        # 20 defines the node size in nam, must adjust it according to your
        # scenario size.
        # The function must be called after mobility model is defined
        $ns_ initial_node_pos $node_($i) 20
}  
Next add informative headers for the CMUTrace file, just before the line "ns_ run" :
puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"
puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"
The rest of the script remains unchanged.

Save the file wireless1.tcl. Make sure the connection-pattern and node-movement files exist under the directories as declared above. 
Run the script by typing at the prompt:

ns wireless1.tcl
On completion of the run, CMUTrace output file "wireless1-out.tr" and nam output file "wireless1-out.nam" are created. Running wireless1-out.nam we see the three mobile nodes moving in nam window. However as mentioned earlier no traffic flow can be seen (not supported as yet). For a variety of coarse and fine grained trace outputs turn on/off AgentTrace, RouteTrace, MacTrace and movementTrace as shown earlier in the script. From the CMUTrace output we find nodes 0 and 2 are out of range and so cannot hear one another. Node1 is in range with nodes 0 and 2 and can communicate with both of them. Thus all pkts destined for nodes 0 and 2 are routed through node 1.

3. Creating random traffic-pattern for wireless scenarios.

Random traffic connections of TCP and CBR can be setup between mobile nodes using a traffic-scenario generator script. This traffic generator script is available under ~ns/indep-utils/cmu-scen-gen and is called cbrgen.tcl. It can be used to create CBR and TCP traffics connections between wireless mobile nodes. In order to create a traffic-connection file, we need to define the type of traffic connection (CBR or TCP), the number of nodes and maximum number of connections to be setup between them, a random seed and in case of CBR connections, a rate whose inverse value is used to compute the interval time between the CBR pkts. So the command line looks like the following

ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections]
[-rate rate]

The start times for the TCP/CBR connections are randomly generated with a maximum value set at 180.0s. Go through the tcl script cbrgen.tcl for the details of the traffic-generator implementation.
For example, let us try to create a CBR connection file between 10 nodes, having maximum of 8 connections, with a seed value of 1.0 and a rate of 4.0. So at the prompt type:

ns cbrgen.tcl -type cbr -nn 10 -seed 1.0 -mc 8 -rate 4.0 > cbr-10-test

From cbr-10-test file (into which the output of the generator is redirected) thus created, one of the cbr connections looks like the following:

#
# 2 connecting to 3 at time 82.557023746220864
#
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(2) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(3) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 0.25
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 10000
$cbr_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at 82.557023746220864 "$cbr_(0) start"

Thus a UDP connection is setup between node 2 and 3. Total UDP sources (chosen between nodes 0-10) and total number of connections setup is indicated as 5 and 8 respectively, at the end of the file cbr-10-test.

Similarly TCP connection files can be created using "type" as tcp. An example would be:

ns cbrgen.tcl -type tcp -nn 25 -seed 0.0 -mc 8 > tcp-25-test

A typical connection from tcp-25-test looks like the following:

#
# 5 connecting to 7 at time 163.0399642433226
#
set tcp_(1) [$ns_ create-connection  TCP $node_(5) TCPSink $node_(7) 0]
$tcp_(1) set window_ 32
$tcp_(1) set packetSize_ 512
set ftp_(1) [$tcp_(1) attach-source FTP]
$ns_ at 163.0399642433226 "$ftp_(1) start"

4. Creating node-movements for wireless scenarios 

The node-movement generator is available under ~ns/indep-utils/cmu-scen-gen/setdest directory and consists of setdest{.cc,.h} and Makefile. CMU's version of setdest used system dependent /dev/random and made calls to library functions initstate() for generating random numbers. That was replaced with a more portable random number generator (class RNG) available in ns. In order to compile the revised setdest.cc do the following:
1. Go to ns directory and run "configure" (you probably have done that already while building ns). This creates a makefile for setdest.
2.Go to indep-utils/cmu-scen-gen/setdest. Run "make" , which first creates a stand-alone object file for ~ns/rng.cc (the stand-alone version doesnot use Tclcl libs) and then creates the executable setdest. 

3. Run setdest with arguments as shown below:


./setdest [-n num_of_nodes] [-p pausetime] [-s maxspeed] [-t simtime] \
      [-x maxx] [-y maxy] > [outdir/movement-file]

Lets say we want to create a node-movement scenario consisting of 20 nodes moving with maximum speed of 10.0m/s with an average pause between movement being 2s. We want the simulation to stop after 200s and the topology boundary is defined as 500 X 500. So our command line will look like:

./setdest -n 20 -p 2.0 -s 10.0 -t 200 -x 500 -y 500 > scen-20-test

The output is written to stdout by default. We redirect the output to file scen-20-test. The file begins with the initial position of the nodes and goes on to define the node movements.

$ns_ at 2.000000000000 "$node_(0) setdest 90.441179033457 44.896095544010
1.373556960010"

This line from scen-20-test defines that node_(0) at time 2.0s starts to move toward destination (90.44, 44.89) at a speed of 1.37m/s. These command lines can be used to change direction and speed of movement of mobile nodes.

Directives for GOD are present as well in node-movement file. The General Operations Director (GOD) object is used to store global information about the state of the environment, network, or nodes that an omniscent observer would have, but that should not be made known to any participant in the simulation.

Currently, the god object is used only to store an array of the shortest number of hops required to reach from one node to an other. The god object does not calculate this on the fly during simulation runs, since it can be quite time consuming. The information is loaded into the god object from the movement pattern file where lines of the form

$ns_ at 899.642 "$god_ set-dist 23 46 2"

are used to load the god object with the knowledge that the shortest path between node 23 and node 46 changed to 2 hops at time 899.642.

The setdest program generates node-movement files using the random waypoint algorithm. These files already include the lines to load the god object with the appropriate information at the appropriate time.

Another program calcdest (also available in ~ns/indep-utils/cmu-scen-gen/setdest) can be used to annotate movement pattern files generated by other means with the lines of god information. calcdest makes several assumptions about the format of the lines in the input movement pattern file which will cause it to fail if the file is not formatted properly. If calcdest rejects a movement pattern file you have created, the easiest way to format it properly is often to load it into ad-hockey and then save it out again. If ad-hockey can read your input correctly, its output will be properly formatted for calcdest.
Both calcdest and setdest calculate the shortest number of hops between nodes based on the nominal radio range, ignoring any effects that might be introduced by the propagation model in an actual simulation. The nominal range is either provided as an argument to the programs, or extracted from the header on the movement pattern file.

The path length information was used by the Monarch Project to analyze the path length optimality of ad hoc network routing protocols, and so was printed out as part of the CMUTrace output for each packet.
  • Other uses that CMU found for the information:
  • Characterizing the rate of topology change in a movement pattern.
  • Identifying the frequency and size of partitions.
  • Experimenting with the behavior of the routing protocols if the god information is used to provide them with perfect'' neighbor information at zero cost.
Thus at the end of the node-movement file are listed information like number of destination unreachable, total number of route and connectivity changes for mobile nodes and the same info for each mobile node.

The revised (more portable) version of setdest ( files revised are: setdest{.cc,.h}, ~ns/rng{.cc,.h}, ~ns/Makefile.in ) should be available from the latest ns distribution.

 

Performance of Swarm Routing Protocol Under MANET

Caution :

If you try to use SWARM routing under highly mobile and try to send much data which will consume much bandwidth, then the performance of the SWARM routing will become very worst. Some of the papers that you see in literature may try to hide this fact.
Further, this evaluation is an elementary evaluation which considered only “time vs performance” as a metric. So any serious research on this routing protocol will need a lot of iterative simulations and more advanced analysis.

Important Sections of the Simulation Script

Some of the important parameters

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(ant) Antenna/OmniAntenna ;# Antenna type
set val(ll) LL ;# Link layer type
set val(ifq) Queue/DropTail/PriQueue ;# Interface queue type
set val(ifqlen) 50 ;# max packet in ifq
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(rp) [lindex $argv 0] ;# Change it as SWARM or AODV or DSR
set val(TotalNodes) 10
set val(xdim) 1000
set val(ydim) 500
set val(speed) 20 ;# Change it as SWARM or AODV or DSR
set val(StartTime) 0.00
set val(SimTime) 50.00
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.5
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ 3.652e-10
Phy/WirelessPhy set Rb_ 2*1e6
#inital transmission power of all the nodes
Phy/WirelessPhy set Pt_ 0.2819;# Change it if required
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0

Setting Node Configuration


01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
#-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-channel $chan_1

Creating Nodes and Settingup Some mobility


01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
for {set i 0} {$i < [expr $val(TotalNodes) ] } {incr i} {
set node($i) [$ns node ]
$node($i) random-motion 1 ;# disable random motion
set tx [$rng integer [expr $val(xdim)-100]]
set ty [$rng integer [expr $val(ydim)-100]]
set tx [expr $tx + 50 ]
set ty [expr $ty + 50 ]
$node($i) set X_ $tx
$node($i) set Y_ $ty
$node($i) set Z_ 0.0
$node($i) color "black"
$ns initial_node_pos $node($i) 10
}
# set the position of the sender and reciever at two extreem ends
set x 100
set y [expr $val(ydim) - 100 ]
$node(0) set X_ $x
$node(0) set Y_ $y
$node(0) set Z_ 0.0
$ns initial_node_pos $node(0) 20
$ns at 0.0 "$node(0) setdest $x $y 20000.0"
$ns at 0.0 "$node(0) label Sender"
$ns at 0.0 "$node(0) color blue"
set x [expr $val(xdim) - 100 ]
set y 100
set n [expr $val(TotalNodes) -1 ]
$node($n) set X_ $x
$node($n) set Y_ $y
$node($n) set Z_ 0.0
$ns initial_node_pos $node($n) 20
$ns at 0.0 "$node($n) setdest $x $y 20000.0"
$ns at 0.0 "$node($n) label Reciever"
$ns at 0.0 "$node($n) color blue"
if {$val(speed) > 0 } {
for {set i 0} {$i < [expr $val(TotalNodes) ]} {incr i} {
set tx [$rng integer [expr $val(xdim)-100]]
set ty [$rng integer [expr $val(ydim)-100]]
set tx [expr $tx + 50 ]
set ty [expr $ty + 50 ]
$node($i) random-motion 1
$ns at 0.0 "$node($i) setdest $tx $ty $val(speed)"
}
}


Setting up some traffic

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Setup traffic flow between nodes
# CBR connections between node(0) and node(1)
set udp [new Agent/UDP]
$udp set class_ 2
set sink [new Agent/LossMonitor]
$ns attach-agent $node(0) $udp
$ns attach-agent $node([expr $val(TotalNodes) -1 ]) $sink
$ns connect $udp $sink
set cbr [new Application/Traffic/CBR]
$cbr set class_ 2
$cbr set packetSize_ 1024
$cbr set interval_ 0.05
$cbr attach-agent $udp
$ns at 0.002 "$cbr start"
$ns at $val(StartTime) "$cbr stop"
$ns at $val(SimTime).01 "stop"

Record Some Events for Performance Analysis

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
proc record {} {
global sink fpRecieved fpDropped fdTput fdLrate
#Get An Instance Of The Simulator
set ns [Simulator instance]
#Set The Time After Which The Procedure Should Be Called Again
set time 2.0
#How Many Bytes Have Been Received By The Traffic Sinks?
set npkts [$sink set npkts_]
set nbytes [$sink set bytes_]
set nlost [$sink set nlost_]
#Get The Current Time
set now [$ns now]
#Save Data To The Files
puts $fpRecieved "$now [expr $nbytes]"
puts $fdTput "$now [expr $nbytes/$time*8/1000000]"
if {$npkts> 0.0 } {
set lossrate1 [expr $nlost / $npkts ]
puts $fdLrate "$now $lossrate1"
} else {
puts $fdLrate "$now 0"
}
$sink set bytes_ 0
#Re-Schedule The Procedure
$ns at [expr $now+$time] "record"
}

The Nam Outputs



Overall Results without Mobility

Average Received Packets over time

Average Loss Rate Over Time


Average Throughput Over Time

Without mobility, SWARM routing gave very good throughput

Loss rate is very very low in the case of SWARM and AODV while comparing it with DSR
Without mobility, the received bytes is high. The Graph is almost similar to throughput graph, but the x axis is showing total received bytes.

Overall results with Mobility 20m/sec

Average Received Packets over time


Average Received Packets over time

Average Throughput Over Time

With mobility, the received bytes is almost equal in all the three protocols
With mobility, the Packet loss rate is low in the case of SWARM and AODV

Conclusion :

Without mobility and low rate of traffic (as in this experiment), SWARM routing performed good. But, with mobility, all the three protocols gave almost equal throughput. As I mentioned in the very first paragraph, if you try to use SWARM routing under highly mobile and try to send much data which will consume much bandwidth, then the performance of the SWARM routing will become very worst. Some of the papers that you see in literature may try to hide this fact.
So, if we use SWAM in a network without mobility (such as sensor network) and with suitably less traffic condition, then SWAM may compete some of the existing MANET routing protocols

 

What is background traffic in a network simulation?

A background traffic is nothing but another traffic which is used simultaneously along with the primary traffic of interest.
For example, if you need to evaluate the performance of your custom voice over IP (VoIP) application, then it may use tcp or sctp  to transport your voice. But in ideal network condition, you will have all the necessary network resources and bandwidth so that you can not prove that your VoIP application will work better even in worst network condition. So, for that, you have to simulate the worst network condition with some “bottle necks” and “traffic overheads”.  For that purpose, another traffic is needed – Such background traffic may use any kind of transport agent (tcp, udp, etc.,) and may use any kind of application (cbr, vbr, telnet, ftp, etc.,)
So, for example, if you need to evaluate the performance of your VoIP application protocol with respect to different network load condition, you may do it in different ways.0
(1) Run the simulation with different background traffic conditions (against 5, 10, 20, background cbr flows) and how your fixed number of VoIP flows getting affected by such background traffic condition.
(2) Or, without any such background traffic, simply you may run the simulation with different number of VoIP flows (5, 10, 20, .. VoIP flows) and evaluate its performance
Generally, researchers prefer combining (1) and (2) to do a good evaluation while evaluating their new protocol.

Sunday 25 December 2016

DBMS :

Normalization

What is Normalization?
Normalization is the process of efficiently organizing
data in a database. There are two goals of the
normalization process: eliminating redundant data
(for example, storing the same data in more than one
table) and ensuring data dependencies make sense
(only storing related data in a table). Both of these
are worthy goals as they reduce the amount of space
a database consumes and ensure that data is
logically stored.

The Normal Forms:
The database community has developed a series of
guidelines for ensuring that databases are
normalized. These are referred to as normal forms
and are numbered from one (the lowest form of
normalization, referred to as first normal form or 1NF)
through five (fifth normal form or 5NF). In practical
applications, you'll often see 1NF, 2NF, and 3NF along with the occasional 4NF. Fifth normal form
is very rarely seen and won't be discussed in this article.
Before we begin our discussion of the normal forms, it's important to point out that they are
guidelines and guidelines only. Occasionally, it becomes necessary to stray from them to meet
practical business requirements. However, when variations take place, it's extremely important
to evaluate any possible ramifications they could have on your system and account for possible
inconsistencies. That said, let's explore the normal forms.

First Normal Form (1NF)
First normal form (1NF) sets the very basic rules for an organized database:
For more details, read Put t ing your Dat abase in First Normal Form

Second Normal Form (2NF)
Second normal form (2NF) further addresses the
concept of removing duplicative data:
Eliminate duplicative columns from the same table.
Create separate tables for each group of related data and identify each row with a unique
column or set of columns (the primary key).
of a table and place them in separate tables.
Create relationships between these new tables and
their predecessors through the use of foreign keys.

Third Normal Form (3NF)
Third normal form (3NF) goes one large step further:
Meet all the requirements of the second normal form.
Remove columns that are not dependent upon the primary key.

Boyce-Codd Normal Form (BCNF or 3.5NF)
The Boyce-Codd Normal Form, also referred to as the "third and half (3.5) normal form", adds
one more requirement:
Meet all the requirements of the third normal form.
Every determinant must be a candidate key.

Fourth Normal Form (4 NF)
Finally, fourth normal form (4NF) has one additional requirement:
Meet all the requirements of the third normal form.
A relation is in 4NF if it has no multi-valued dependencies.

Remember, these normalization guidelines are cumulative. For a database to be in 2NF, it must
first fulfill all the criteria of a 1NF database.

Meet all the requirements of the first normal form.
Remove subsets of data that apply to multiple rows

Data Communication & Networks:

Notes on Data Communication & Networks :Part II

Hello Friends!


Data Communication & Networks is one of the important subjects in UGC NET exam on which lots of questions are asked. So, prepare this subject well. The syllabus of the subject is vast, but is one of the easiest subjects to prepare. 

Please read the post and then post your comments/suggestions:

ETHERNET: Ethernet frames must carry a minimum payload of 46 bytes, which ensures that a valid Ethernet frame is 512-bits long (considering bits of header section also). The shortest Ethernet frame is 64 bytes in length, which carry Control messages.

Ethernet frames don't have a way to indicate end-of-frame, but an inter-frame gap (of time required to send 96 bit of data, i.e. 9.6 micro sec.) is used.

Horn antennas are very popular at UHF (300 MHz-3 GHz) and higher frequencies. They have a wide impedance bandwidth, implying that the input impedance is slowly varying over a wide frequency range.
S-parameters describe the input-output relationship between ports (or terminals) in an electrical system. A port can be defined as any place where we can deliver voltage and current.
Waveforms are not made up of a discrete number of frequencies, but rather a continuous range of frequencies (sum of frequencies).
Through modulation the waveforms can be relocated to separate frequency bands. Television is broadcast primarily at 54-216 MHz. FM radio operates between 87.5-108 MHz.
Frequency Band Name
Frequency Range
Wavelength (Meters)
Application
Extremely Low Frequency (ELF)
3-30 Hz
10,000-100,000 km
Underwater Communication
Super Low Frequency (SLF)
30-300 Hz
1,000-10,000 km
AC Power (though not a transmitted wave)
Ultra Low Frequency (ULF)
300-3000 Hz
100-1,000 km
Earth Mode Communications*
Very Low Frequency (VLF)
3-30 kHz
10-100 km
Navigational Beacons
Low Frequency (LF)
30-300 kHz
1-10 km
AM Radio
Medium Frequency (MF)
300-3000 kHz
100-1,000 m
Aviation and AM Radio
High Frequency (HF)
3-30 MHz
10-100 m
Shortwave Radio
Very High Frequency (VHF)
30-300 MHz
1-10 m
FM Radio
Ultra High Frequency (UHF)
300-3000 MHz
10-100 cm
Television, Mobile Phones, GPS
Super High Frequency (SHF)
3-30 GHz
1-10 cm
Satellite Links, Wireless Communication
Extremely High Frequency (EHF)
30-300 GHz
1-10 mm
Astronomy, Remote Sensing
Visible Spectrum
400-790 THz (4*10^14-7.9*10^14)
380-750 nm (nanometers)
Human Eye
* Communications through the ground using conduction fields e.g. military communications.

Slot Time: It is twice the time it takes for an electronic pulse to travel the maximum distance between two nodes. Thus Propagation delay takes half of the time of slot time since it is only the measure of the time required for signal to reach from node A to B. Slot time is used for half-duplex Ethernet network operation. It is 512 bit times for Ethernet networks operating below 1 Gbit/s, and 4096 bit times for Gigabit Ethernet. To reliably detect collisions, the minimum transmission time for a complete frame must be at least one slot time, whereas the round-trip propagation delay must be less than a slot time (half of slot time).

Back-off Algorithm: Once a collision is detected by simultaneous transmitters, they will follow a backoff algorithm, which requires each transmitter to wait an integral number of slot times (51.2 µs) before attempting a new transmission sequence. The integer is determined by the equation:
0<=r<2 power k where k = min (n, 10)
The variable k is actually the number of collisions capped at a maximum of 10. Therefore, r can range from 0 to 1023. The actual value for r is determined by a random process within each Ethernet node. As the number of consecutive collisions increases, the range of possible backoff times increases exponentially. The number of possible retries is max. 16.
There are no collisions with a full-duplex link, where each node is paired with a port on the hub.

Collision Domain - a section of a network where data packets can collide with one another when being sent on a shared medium or through repeaters, in particular.

The 5-4-3 rule: A system can have up to five segments in series, with up to four repeaters and no more than three mixing segments (a segment that may be connected to more than two transceivers).

The FCS field in Ethernet frame provides only bit-level error detection, no error recovery.

UDP is also known as laissez-faire protocol

TCP is used for unicast addresses only, so multicast applications must use the UDP transport protocol.

In asynchronous transmission, the Start bit always has a value of 0 (a Space). The Stop Bit always has a value of 1 (a Mark). This means that there will always be a Mark (1) to Space (0) transition on the line at the start of every word.

Application layer is free to send any size of data, there is no upper limit defined by standards. The lower layers divides the data if needed.
A channel with x bps may not necessarily transmit data at x rate, since protocols, encryption, and other factors can add may overheads.

The asymptotic bandwidth (formally asymptotic throughput) for a network is the measure of maximum throughput for a greedy source (a traffic generator that generates data at the maximum rate possible and at the earliest opportunity possible).

CIDR: Classless Inter-Domain Routing, known as supernetting, is a solution to limited address space problem in a network. It allocates address space to ISPs and end users on any address bit boundary, instead of on 8-bit segments (which is class based addressing). It appends to the IP address a slash character and the decimal number as routing prefix, e.g., "192.168.2.0/24" for IPv4, and 2001:db8::/32 for IPv6. The value after / indicates how many bits are used for the network prefix, leaving the remaining bits to identify the specific host.

CIDR currently uses prefixes anywhere from 13 to 27 bits. This solution fits an organization's specific needs. It helps in reducing number of entries in global routing tables. It is the concept of subnetting within the internet itself.

The industrial, scientific and medical (ISM) radio bands are radio bands (portions of the radio spectrum) reserved internationally for industrial, scientific and medical purposes other than communications. These are for unlicensed operations. Cordless phones, Bluetooth devices, near field communication (NFC) devices, and wireless computer networks all use frequencies allocated to low power communications as well as ISM.
Hartley's law- "The maximum data rate of a physical communication link is proportional to its bandwidth in hertz, which is sometimes called frequency bandwidth, spectral bandwidth, RF bandwidth, signal bandwidth or analog bandwidth."
A Baud Rate represents the number of bits that are actually being sent over the media, not the amount of data that is actually moved from one DTE device to the other. That means, baud rate decides the actual bit rate. For example, the bit rate is 9600
The Intelligent Network (IN) is the standard network architecture which allows telecom operators to differentiate themselves by providing value-added services in addition to the standard telecom services. The intelligence is provided by network nodes on the service layer (a conceptual layer within a network service provider architecture. It aims at providing middleware that serves third-party value-added services and applications at a higher application layer.)

The Internet protocol suite ( TCP/IP Model), occasionally known as the DoD model due to the foundational influence of the ARPANET. The TCP/IP model and related protocols are maintained by the Internet Engineering Task Force (IETF).

PORT: Each process that wants to communicate with another process identifies itself to the TCP/IP protocol suite by one or more ports. Application Layer talks with Transport layer through ports. A port number helps the transport layer protocols (like TCP) to know the type of content residing inside the packet.
A port is a 16-bit number, used by the host-to-host protocol to identify to which higher level protocol or application program (process) it must deliver incoming messages. There are two types of ports. Well-known port numbers(0-1023) are typically odd, because early systems using the port concept required an odd/even pair of ports for duplex operations.
The well-known ports are controlled and assigned by the Internet Assigned Number Authority (IANA) and on most systems can only be used by system processes or by programs executed by privileged users. Ephemeral ports are opposite to well-known ports. Such port number are used by clients and are contained in the UDP datagrams sent to the server.

Normally, a server will use either TCP or UDP, but there are exceptions. For example, domain name servers use both UDP port 53 and TCP port 53.

SOCKET: A socket is a special type of file handle, which is used by a process to request network services from the operating system. A socket address is the triple: <protocol, local-address, local-process>. For example, in the TCP/IP suite:
<tcp, 193.44.234.3, 12345>
An association is the 5-tuple that completely specifies the two processes that comprise a connection:
<protocol, local-address, local-process, foreign-address, foreign-process>. In the TCP/IP suite, the following could be a valid association:
<tcp, 193.44.234.3, 1500, 193.44.234.5, 21>
Two processes communicate via TCP sockets. The socket model provides a process with a full-duplex byte stream connection to another process.

UDP: UDP is basically an application interface to IP. It adds no reliability, flow-control, or error recovery to IP. It simply serves as a multiplexer/demultiplexer for sending and receiving datagrams, using ports to direct the datagrams. It requires the application to take responsibility for error recovery and so on.
Slow-start is one of the algorithms that TCP uses to control congestion inside the network. It is also known as the exponential growth phase.
Broadband means "having instantaneous bandwidths greater than 1 MHz and supporting data rates greater than about 1.5 Mbit/s." In telecommunication, Broadband refers to a communication bandwidth of at least 256 kbit/s. Each channel is 6 MHz wide.
The additive-increase/multiplicative-decrease (AIMD) algorithm is a feedback control algorithm used by  TCP for Congestion Avoidance. The approach taken is to increase the transmission rate (window size), probing for usable bandwidth, until loss occurs.
IP address classes:
Class
Leftmost bits
Start address
Finish address
A
0xxx
0.0.0.0
127.255.255.255
B
10xx
128.0.0.0
191.255.255.255
C
110x
192.0.0.0
223.255.255.255
D
1110
224.0.0.0
239.255.255.255
E
1111
240.0.0.0
255.255.255.255

IP address range for Intranets (Private Networks):

Class
Private start address
Private finish address
A
10.0.0.0
10.255.255.255
B
172.16.0.0
172.31.255.255
C
192.168.0.0
192.168.255.255

IP packets addressed by them cannot be transmitted onto the public Internet. If such a private network needs to connect to the Internet, it must use either a network address translator (NAT) gateway, or a proxy server.In IPV6, The address block fc00::/7 has been reserved for private networks.
IP officially reserves the entire range from 127.0.0.0 through 127.255.255.255 for loopback purposes.
IPv6 does not use classes. IPv6 supports the following three IP address types: unicast, multicast and anycast. IPv6 does not support broadcast. Multicast addresses in IPv6 start with 'FF' (255) just like IPv4 addresses. Unicast addresses have 3 defined scopes, including link-local, site-local and global; and multicast addresses have 14 scopes.
The number of IPv6 addresses is 1028. There is no ARP in V6. Currently, DHCP, FTP, PPP, RIP, SNMP, VPN, L2TP and Telnet do not support IPv6.
IPv6 does not require NAT. NAT, too, doesn't support V6. Currently, IPv6 packets are not forwarded.
IPv6 reserves just two special addresses: 0:0:0:0:0:0:0:0 and 0:0:0:0:0:0:0:1. IPv6 uses 0:0:0:0:0:0:0:0 internal to the protocol implementation, so nodes cannot use it for their own communication purposes. IPv6 uses 0:0:0:0:0:0:0:1 as its loopback address, equivalent to 127.0.0.1 in IPv4. The minimum size of an IP datagram is 28 bytes, including 20 bytes of header.
BIND and NSD are the most widely used DNS software on the Internet
Anycast is a network addressing and routing methodology in which datagrams from a single sender are routed to the topologically nearest node in a group of potential receivers, though it may be sent to several nodes, all identified by the same destination address. On the Internet, anycast is usually implemented by using BGP.
In denial-of-service attacks, a rogue network host may advertise itself as an anycast server for a vital network service, to provide false information or simply block service.
"6 to 4" is an Internet transition mechanism for migrating from IPv4 to IPv6, a system that allows IPv6 packets to be transmitted over an IPv4 network. 6to4 does not facilitate interoperation between IPv4-only hosts and IPv6-only hosts, but simply a transparent mechanism used as a transport layer between IPv6 nodes.
The network requests supporting DNS lookups run over TCP and UDP, port 53 by default.