Skip to main content

Sensor Network Simulation using NS2 | NS2 Basics | Lecture 9

Introduction to Sensor Networks in NS2

In this post

The readers learn about 

  • Sensor networks in brief

  • Wireless Sensor flooding protocol

  • Creating a wireless sensor cluster for flat and hierarchical topology using Mannasim framework.

  • Creating a new scenario for generating a flat topology or a hierarchical topology


9.1 Introduction to Sensor Networks

A wireless sensor network consists of nodes with limited energy, memory, bandwidth, computing power and sensing capabilities. Sensor nodes consist of a small processor to handle the events, a group of sensors, a transmitter/receiver, and a small battery with limited energy and in some nodes, an operating system to handle the tasking. TinyOS is one of the common operating systems for miniature sensor networks.  Like ad hoc networks, sensor networks also have a set of protocols for low energy, clustering, MAC level, etc. Usually, most of the routing protocols of sensor networks are designed mainly to optimise the power in order to improve the battery life.


The routing of sensor nodes is to design a network that possesses many challenges like node deployment, energy consumption without losing accuracy, data reporting model, fault tolerance, scalability, node/link heterogeneity, network dynamics, transmission media, connectivity, coverage, data aggregation and quality of service. 


The routing protocols in wireless sensor networks based on network structure are classified into 

  • flat-based routing; 

  • hierarchical routing and 

  • location based routing. 

In flat based routing all the nodes have same functionality which collaborate to perform sensing task. In hierarchical based routing nodes have different levels of functionalities. In location based routing nodes are referred by their positions.


The routing protocols in wireless sensor networks can also be classified into the following categories based on the protocol operation. 

They are: 

  • multi-path based routing, 

  • query based routing, 

  • negotiation based routing, 

  • coherent based routing, 

  • QoS based routing. 

A sensor network normally constitutes a wireless ad-hoc network, meaning that each sensor supports a multi-hop routing algorithm (several nodes may forward data packets to the base station). Like any computer network, nodes in Wireless Sensor Networks (WSN) communicate with each other based on defined protocols. Applications are developed and executed on top of the protocols.


In general, the categorisation of sensor network protocols falls under various categories, as each component in the sensor nodes is participating in the routing and is dealing with a protocol. Here is the list of protocols that were supported in the OSI layers for Wireless Sensor Networks (This is only a list of protocols, there may be other lists of protocols too in these categories) [11]


9.2 Protocols under various OSI layers

Application Layer

Sensor Management Protocol (SMP)

  • SMP access nodes by using attribute based naming and location-based addressing

  • SMP provides the following tasks

    • Introducing rules related to data aggregation, attribute based naming

    • Exchanging data

    • Time synchronisation of the sensor nodes

    • Moving sensor nodes

    • Turning sensor nodes ON or OFF

    • Authentication, key and security

    • Reconfiguring the sensor networks


Task assignment and Data advertisement protocol (TADAP)

  • Interest dissemination

  • Users send their interest to a node or a network

  • The node advertises the available data to the users


Sensor Query and Data Dissemination Protocol (SQDDP)

The locations of the nodes that sense temperature higher than 70°F is attribute-based “Temperature read by the nodes in Region A” is location based naming.

Transport layer protocol

  • Bridge between the network layer and application layer (Demux/Mux)

  • Data delivery service between the source and sink with error control

  • To regulate the amount of traffic injected into the network via flow and congestion


Transport layer for WSN

  • Reliable Transport (Source to sink, Event detection, Event to sink)

  • Congestion control

  • Self configuration

  • Energy Awareness

  • Biased implementation

  • Constrained routing


Event to Sink Transport

  1. Sink is interested only in the collective information of sensor nodes within the event radius and not in their data

  2. The nodes within the event radius accumulate more packets to send to the sink ,that leads to congestion

  3. Hence, the transport layer is helpful to control the congestion in the forward path for efficient data delivery to the sink


Sink to Sensor Transport

  1. Sink to sensor data should be 100% efficient and lossless as this data contains application-specific data like OS binaries, Programming/retasking, Application specific Queries and commands

  2. 100% reliable delivery is required

  3. More energy is consumed because the sink is with a powerful antenna for 100% delivery

  4. multihop communication 

  5. Forward path congestion is more when compared with reverse path congestion


Network Layer principles

  1. Power efficiency

  2. Sensor networks are mostly data centric

  3. attribute based addressing and location awareness

  4. data aggregation

  5. The routing protocol is easily integrated with other networks


Network layers Protocols 

SMECN – Small Minimum Energy Communication Network

Create a subgraph of a Sensor node that contains a minimum energy Path

LEACH – Low Energy Adaptive Clustering Hierarchy

Form clusters to minimise energy dissipation

SAR – Sequential Assignment Routing – uses tree like structure

Flooding – broadcast to all neighbours regardless of their receive or not

Gossiping – sends data to one randomly selected neighbour

SPIN – Sends data to nodes only if they are interested based on ADV, REQ and DATA


The Data Link Layer provides 

Medium Access Control

  1. Establish communication links for data transfer to create basic network infrastructure

  2. Regulate access to the shared media such that communication resources are fairly and efficiently shared between the nodes


Error Control

  • Forward Error Correction

  • Automatic Repeat Request 

    • Retransmission of lost packets/frames

    • Overhead cost and retransmission cost


MAC of Bluetooth and Adhoc (TxPower = 20dBM) network is different from MAC of Sensor network, TxPower = 0 dBM

So MAC has built-in power conservation, mobility management, and failure recovery strategies

MAC protocols

Two types of MAC protocols are available 

  1. Scheduled based protocol

  2. Contention based protocol

The MAC protocol is mainly responsible for providing a mechanism that controls access to the shared communication medium

Requirements of MAC

  • Energy Efficiency

  • Scalability

  • Latency

  • Fairness

  • Bandwidth utilization


Scheduled based protocols

Uses TDMA (Time Division Multiple Access)

  • Collision free

  • Best for single hop

  • Latency increases with the number of nodes

  • Non-adaptive (new nodes added are not included)

  • Not scalable


Nodes know ahead of time, so the nodes know their inactive time and they can goto sleep mode

Contention based protocols

Uses CSMA (Carrier Sense Multiple Access)

  • it adaptive (can add new nodes)

  • Strict synchronisation is not required

  • scalable

  • multihop

Energy Wasted in CBP

  • Collisions

  • Overhearing (packet not intended for it, but it accepts it)

  • Control packet overhead

  • Idle listening


LEACH (Low Energy Adaptive Clustering Hierarchy)

  • Schedule based protocol

  • Two phases: Initialisation and steady state phase

  • Initialisation Phase

    • Clusters are formed, and a CH is elected

    • Cluster head is formed and energy is evenly distributed so that all the nodes randomly die at sthe ame rate

    • Cluster head coordinates the activity, establishes TDMA

Steady State phase

  • All nodes transmit their sensed data as per TDMA, and then it go to sleep state

  • Collision within a cluster is not possible, but between clusters it is possible

  • So CDMA code is allotted to each cluste,r which results in poor bandwidth utilisation


Contention Based Protocols

IEEE 802.11 DCF is used for single hop and which is not sutiable for synchronization. Hence IEEE802.11PS (Power save) is used for WSN.

SMAC (Sensor MAC)

  • periodic listening and sleeping

  • Synchronisation (SYNC packet with information: Time left to Sleep)

  • Collision and overhearing are avoided

  • Message passing

    • First RTS/CTS reserved medium for the second packet and so on.


Time out MAC (TMAC)

  • Mainly for energy saving 

  • The FRTS (Future Ready to Send ) packet is used. 

  • Ta = CW + TxRTS + T


Data gathering MAC (DMAC)

  • Adaptive and energy efficient

  • Low-latency MAC 

  • No RTS/CTS only ACK Packets 

  • Efficient in data gathering 

  • Parent nodes can extend the wakeup time for their child nodes

  • Child nodes can request parent nodes to extend their lifetime


Wise MAC (Wireless Sensor MAC)

  • All nodes wake up periodically to receive or transmit data over the medium. 


MS MAC (Mobile Sensor MAC)

  • Border nodes inform the respective clusters that a new node reaches their area. 

  • The mobile node quickly follows the schedule of a new cluster. 



9.3 Wireless Sensor Networks Flooding Routing Protocol (WFRP)

Adding a new protocol, we have already seen in the OLSR protocol for wireless Adhoc networks. This topic will introduce the WSN Flooding routing protocol (WFRP) for NS2. In this protocol, the sink nodes send a beacon message periodically for a duration of time and other nodes in the network form or construct a route towards the sink nodes; in this way, this concept is called flooding. Later, other nodes report to the sink node a certain period using the UDP protocol. WFRP is more or less closely related to the Direct Diffusion protocol in a simple way. Of course, the Directed diffusion protocol is really a complex routing, whereas the WFRP is a simple implementation. 


Installation of WFRP in NS2

The source of this code is represented in [12].  The readers can download the code from the CD attached herewith, or they can download it at https://dl.dropboxusercontent.com/u/24623828/wfrp.zip


Files to be modified

  • ~ns-2.35/Makefile.in

  • ~ns-2.35/queue/priqueue.cc

  • ~ns-2.35/common/packet.h

  • ~ns-2.35/trace/cmu-trace.h

  • ~ns-2.35/trace/cmu-trace.cc

  • ~ns-2.35/tcl/lib/ns-packet.tcl

  • ~ns-2.35/tcl/lib/ns-lib.tcl

  • ~ns-2.35/tcl/lib/ns-agent.tcl

  • ~ns-2.35/tcl/lib/ns-mobilenode.tcl

Here are the following changes in ~ns-2.35/queue/priqueue.cc  (as given in the Fig 9.1)


wfrp1

Fig 9.1 – WFRP Change in priqueue.cc

Three changes in the ~ns-2.35/common/packet.h file, 

Change number 1

A new packet value has to be added

static const packet_t PT_WFRP = 73; 


Change number 2

name_PT_WFRP[“WFRP”]=”wfrp”;


Change number 3

Protocols have to be verified for type checking as shown in Fig. 9.3

wfrp2Fig 9.2 – WFRP Change in packet.h


wfrp3 Fig 9.3 – WFRP Change in packet.h
wfrp4 Fig 9.4 – WFRP Change in packet.h


There is a change in the ~ns-2.35/trace/cmu-trace.cc file, that includes the tracing information to the cmu-trace.cc to get the wfrp packets in the trace file. This is shown in Fig. 9.5


Defining the function void format_wfrp(Packet *p, int offset) in ~ns-2.35/trace/cmu-trace.h. This is shown in Fig 9.6 


Addition of the new packet type WFRP in the ~ns-2.35/tcl/lib/ns-packet.tcl. This is shown in Figure 9.7


There are two changes in the ~ns-2.35/tcl/lib/ns-lib.tcl that indicate what has to be done by the agent and how to create and start the transmission by the agent. This is shown in Fig. 9.8 and Fig. 9.9.



There is a change in ~ns-2.35/tcl/lib/ns-mobile.tcl file to tell the special processing for the WFRP protocol. This is shown in Fig. 9.10

Finally, the source files' location has to be added to the Makefile as given below. 

OBJ_CC =

wfrp/wfrp.o \


Next, the code has to be compiled using the command 

./configure && make clean && make 

 wfrp5

Fig 9.5 –WFRP Change in cmu-trace.cc file



wfrp6

Fig 9.6 – WFRP Change in cmu-trace.h


wfrp7

Fig 9.7 – WFRP change in ns-packet.tcl

wfrp9Fig 9.8 WFRP Change in ns-lib.tcl


wfrp10Fig 9.9 – WFRP Change in ns-lib.tcl
wfrp11Fig 9.10 – WFRP Change in ns-mobile.tcl

To test the WFRP protocol here is the listing for Tcl file that indicates the WFRP protocol in simulation.


Listing 9.1 – Testing WFRP protocol 

# Generated by Topology Generator for Network Simulator (c) Elmurod Talipov

set val(chan)          Channel/WirelessChannel      ;# channel type

set val(prop)          Propagation/TwoRayGround     ;# radio-propagation model

set val(netif)         Phy/WirelessPhy/802_15_4     ;# network interface type

set val(mac)           Mac/802_15_4                 ;# MAC type

set val(ifq)           Queue/DropTail/PriQueue      ;# interface queue type

set val(ll)            LL                           ;# link layer type

set val(ant)           Antenna/OmniAntenna          ;# antenna model

set val(ifqlen)        100             ;# max packet in ifq

set val(nn)            100     ;# number of mobilenodes

set val(rp)            WFRP     ;# protocol type

set val(x)             120     ;# X dimension of topography

set val(y)             120     ;# Y dimension of topography

set val(stop)          500     ;# simulation period 

set val(energymodel)   EnergyModel     ;# Energy Model

set val(initialenergy) 100     ;# value


#create the simulator object

set ns        [new Simulator]

set tracefd       [open wfrp.tr w]

set namtrace      [open wfrp.nam w]


#create the tracing and namtrace

$ns trace-all $tracefd

$ns namtrace-all-wireless $namtrace $val(x) $val(y)


#Radio details

set dist(5m)  7.69113e-06

set dist(9m)  2.37381e-06

set dist(10m) 1.92278e-06

set dist(11m) 1.58908e-06

set dist(12m) 1.33527e-06

set dist(13m) 1.13774e-06

set dist(14m) 9.81011e-07

set dist(15m) 8.54570e-07

set dist(16m) 7.51087e-07

set dist(20m) 4.80696e-07

set dist(25m) 3.07645e-07

set dist(30m) 2.13643e-07

set dist(35m) 1.56962e-07

set dist(40m) 1.20174e-07

Phy/WirelessPhy set CSThresh_ $dist(20m)

Phy/WirelessPhy set RXThresh_ $dist(20m)



# set up topography object

set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)


create-god $val(nn)


# configure the 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) \

             -channel [new $val(chan)] \

             -topoInstance $topo \

             -agentTrace ON \

             -routerTrace ON \

             -macTrace  OFF \

             -movementTrace OFF \

             -energyModel $val(energymodel) \

             -initialEnergy $val(initialenergy) \

             -rxPower 35.28e-3 \

             -txPower 31.32e-3 \

    -idlePower 712e-6 \

    -sleepPower 144e-9 

                           

             #-IncomingErrProc MultistateErrorProc \

             #-OutgoingErrProc MultistateErrorProc

             

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

        set mnode_($i) [$ns node]

}


#specify random location for the nodes

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

$mnode_($i) set X_ [ expr {$val(x) * rand()} ]

$mnode_($i) set Y_ [ expr {$val(y) * rand()} ]

$mnode_($i) set Z_ 0

}


# Position of Sink

$mnode_(0) set X_ [ expr {$val(x)/2} ]

$mnode_(0) set Y_ [ expr {$val(y)/2} ]

$mnode_(0) set Z_ 0.0

$mnode_(0) label "Sink"


#start sending beacon message

$ns at 1.0 "[$mnode_(0) set ragent_] sink"


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

$ns initial_node_pos $mnode_($i) 3

}


#Setup a UDP connection

set udp [new Agent/UDP]

$ns attach-agent $mnode_(10) $udp


set sink [new Agent/Null]

$ns attach-agent $mnode_(0) $sink


$ns connect $udp $sink

$udp set fid_ 2


#Setup a CBR over UDP connection

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set type_ CBR

$cbr set packet_size_ 50

$cbr set rate_ 0.1Mb

$cbr set interval_ 2

#$cbr set random_ false


$ns at 5.0 "$cbr start"

$ns at [expr $val(stop) - 5] "$cbr stop"


# Telling nodes when the simulation ends

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

    $ns at $val(stop) "$mnode_($i) reset;"

}


# ending nam and the simulation

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"

$ns at $val(stop) "stop"

$ns at [expr $val(stop) + 0.01] "puts \"end simulation\"; $ns halt"

proc stop {} {

    global ns tracefd namtrace

    $ns flush-trace

    close $tracefd

    close $namtrace

}


$ns run


Here is the sample trace file that indicates the presence of wfrp packets. 


9.4 – Mannasim Framework for Wireless Sensor Networks

Mannasim is a detailed framework for simulation of sensor networks as a valid test bed for wireless sensor networks. There are numerous simulators, emulators or test beds were available for sensor networks, but most of them are either proprietary or very difficult. Mannasim really does a difficult work to simple and elaborative simulation and it is free and open source built over the NS2 (Network Simulator 2).


9.4.1 Simple Example

Steps involved in creating a sensor network simulation using Mannasim framework is 

Step 1 – creating simulator object and create files for tracing and animation

set ns [new Simulator]                 ;# simulation object

set tracef [open mannasim.tr w]         ;# trace file

$ns_ trace-all $tracef               ;# attach trace to simulation

#$ns_ use-newtrace                       ;# use new trace format

set topo [new Topography]               ;# simulation topology

$topo load_flatgrid $val(x) $val(y)     ;# flat topology

create-god $val(nn)                     ;# god

Step 2: Define the antenna and physical layer details, though they are already defined as a default value in the ns-default.tcl file, still these values can be overridden in the Tcl file.

# 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

Phy/WirelessPhy set Pt_ 0.2818

Phy/WirelessPhy set freq_ 914e+6

Phy/WirelessPhy set L_ 1.0

Step 3: Create the configuration parameters with the default values for wireless channel, mac, number of nodes, protocol, link layer, energy details etc as given below

set val(chan) Channel/WirelessChannel  ;# channel type

set val(prop) Propagation/TwoRayGround ;# radio-propagation model 

set val(netif) Phy/WirelessPhy          ;# network interface type

set val(mac) Mac/802_11               ;# MAC type

set val(ifq) Queue/DropTail/PriQueue  ;# interface queye type

set val(ll) LL                       ;# link layer type

set val(ant) Antenna/OmniAntenna      ;# antenna model

set val(ifqlen) 200                      ;# max packet in ifq

set val(rp)      AODV                   ;# routing protocol 

set val(x)       30.0                     ;# scenario X dimension  

set val(y)       30.0                     ;# scenario Y dimension 

set val(start)   5.0                      ;# simulation start time

set val(stop) 3605.0                   ;# simulation stop time

set val(energy)  10.0                     ;# initial energy (joules)

set val(rx)      0.024                    ;# reception energy

set val(tx)      0.045                    ;# transmission energy

set val(idle)    0.000                    ;# idle energy

set val(nn)      22                       ;# total number of nodes



Step 4: Step to create the common sesnsor node, cluster heads and access point nodes which is the real work done by the Mannasim Team.  These details are shown shortly in the next topic. Set the node configuration for sensor nodes, the very first line being sensorNode ON which indicates the usage of sensor nodes in the node configuration.

$ns_ node-config -sensorNode ON

                 -adhocRouting $val(rp)

-adhocRouting $val(rp)

-llType $val(ll)

-macType $val(mac)

-ifqType $val(ifq)

-ifqLen $val(ifqlen)

-antType $val(ant)

  -propType $val(prop)

  -energyModel $val(en)



Step 5:  The access point nodes does not need any sensing or processing, so it is the simplest node configuration which is given below

This class is derived as AccessPointApp which will be accessed using the UDP protocol

set node_($counter) [$ns_ node]

set udp_($counter) [new Agent/UDP]

set app_($counter) [new Application/SensorBaseApp/AccessPointApp]


Step 6: The transport protocol should be attached to the application and applications sent message destination address must be set.

$app_($counter) set destination_id_ 0;

$app_($counter) attach-agent $udp_($counter)

Configuring the sensor node requires the adjustment of nodes position, motion characteristics (in the box example, 0 means that the sensor node is static) and the transport protocol

$node_($counter) random-motion 0

$node_($counter) set X_ 5.0

$node_($counter) set Y_ 5.0

$node_($counter) set Z_ 0.0

$node_($counter) attach $udp_($counter) $val(port)


Stop time is mentioned to finish the AP (Access Point) Simulation.

$ns_ at 1200.0 "$app_($counter) stop"

Step 7: On demand networks require that the AP or other outsider send requests messages to the WSN. These messages specifies the situation when the network should provide data to the requester.

To create a request message to be send by the AP the following parameters should be set:

  • When requested data should be sent back to AP (for example, send data when temperature exceeds 25 celcius degrees).

  • request type - two values are possible: REAL (0) when sensor node drops all data all data from its buffer, gather new one, process and deliver it to the disseminating module. BUFFER (1) when sensor node process data from its buffer and give the results to the disseminating module.

  • The sample code provided below defines the request time, schedules when data structure that encapulates request data is created and when request message will be sent.

$app_($counter) set request_type_ 25 0

$ns_ at 120.0 "$app_($counter) add_temp_data_param 25 0"

$ns_ at 120.5 "$app_ send_request"


Step 8: Cluster head configuration. It is similar to the AP nodes but they sense and process the data, so the configuration should be according to its use. To create a sensor node just put in the tradicional node-config structure the -sensorNode ON command.  So, for this cluster head, a sensor node application (as expected a ClusterHeadApp) and an instance of a processing module.

set node_($counter) [$ns_ node]

set udp_($counter) [new Agent/UDP]

set app_($counter) [new Application/SensorBaseApp/ClusterHeadApp]

set processing_($counter) [new Processing/AggregateProcessing]

Step 9:  Common node configuration. Common Nodes are added to the cluster head node for data processing and sensing. Cluster head application adjustments includes, besides transport protocol settings, sent messages destination address, dissemination interval and type (PERIODIC - 0, CONTINUOUS - 1, ON_DEMAND - 2 and EVENT_DRIVEN - 3). The wireless sensor node object, the transport protocol and the processing module just created are attached to the application also.

$app_($counter) node $node_($counter);

$app_($counter) set destination_id_ 0;

$app_($counter) set dissemination_type 0;

$app_($counter) set dissemination_interval 30.0;

$app_($counter) attach-agent $udp_($counter)

$app_($counter) attach-processing $processing_($counter)    

Concerning sensor node configuration the user should set it´s position, motion type (in the box example 0 means a static node), energy spent in processing tasks and node´s processor instruction per second rate. Cluster head application and transport protocol should be attached to sensor node. 

$node_($counter) random-motion 0

$node_($counter) set X_ 5.0

$node_($counter) set Y_ 5.0

$node_($counter) set Z_ 0.0

$node_($counter) add-app $app_($counter)

$node_($counter) attach $udp_($counter) $val(port)

Node/MobileNode/SensorNode set processingPower_ 0.024

Node/MobileNode/SensorNode set instructionsPerSecond_ 8000000

To complete node configuration, attach the sensor node to the processing module and schedule application start and stop times.

$processing_($counter) node $node_($counter)

$ns_ at 1.0 "$app_($counter) start"

$ns_ at 1200.0 "$app_($counter) stop"


The above Tcl can be run using the command ns filename.tcl to see the tracing and the energy occupation and data processing. 


9.4.2 Mannasim Implementation

Mannasim uses two modules, 

  • Mannasim Framework simulation

  • Script generation tool


Mannasim Framework

Mannasim uses a large number of classes for various data generators, sensors, nodes, etc.  Some of these classes, along with their usage, is listed below. However, the readers are asked to see the source code in the DVD provided for more information of refer to [13].


The order of class description is defined as follows:

  • Sensor Node

    • sensorNode.h and sensorNode.cc

    • extends the MobileNode Class

    • methods 

      • void sensorNode::selfTest()

      • void sensorNode::sleep()

      • void sensorNode::wakeUp()

      • double sensorNode::sensingPower()

      • double sensorNode::processingPower()

      • int sensorNode::instructionsPerSecond()

  • DataGenerator

    • dataGenerator.h and dataGenerator.cc

    • extends the TclObject class

  • TemperatureDataGenerator

    • temperatureDataGenerator.h and temperatureDataGenerator.cc

    • extends the DataGenerator class

  • TemperatureAppData

    • temperatureAppData.h and temperatureAppData.cc

    • extends AppData class

  • Processing

    • processing.h and processing.cc

    • extends TclObject Class

  • SensedData

    • sensedData.h and sensedData.cc

    • extends AppData class

  • OnDemandData

    • onDemandData.h and onDemandData.cc

    • extends SensedData class

  • OnDemandParameter

    • onDemandParameter.h and onDemandParameter.cc

    • extends AppData class

  • SensorBaseApp

    • sensorBaseApp.h and sensorBaseApp.cc

    • extends Application class of NS2

  • CommonNodeApp

    • commonNodeApp.h and commonNodeApp.cc

    • extends SensorBaseApp class

  • ClusterHeadApp

    • ClusterHeadApp.h and ClusterHeadApp.cc

    • extends SensorBaseApp class

This entire arrangement is for sensing – processing - dissemination


Mannasim Installation

  • Copy the Mannasim.tar.gz file from the CD provided along with this book

  • Untar it in the folder ~ns-2.35/ using the command 

    • tar zxvf Mannasim.tar.gz

    • Copy the files from the ~ns-2.35/Mannasim/ns-modified-files/ to these locations

    • ~ns-2.35/apps/udp.cc 

    • ~ns-2.35/common/ns-process.h

    • ~ns-2.35/common/packet.cc

    • ~ns-2.35/common/packet.h

    • ~ns-2.35/Makefile.in

    • ~ns-2.35/tcl/lib/ns-default.tcl

    • ~ns-2.35/tcl/lib/ns-lib.tcl

Once everything is done, go to the terminal and type the commands one by one

Prompt]./configure
Prompt] make

If there are any errors, correct them. Once the simulation is done, test the sensors using the following files
https://dl.dropboxusercontent.com/u/24623828/mannasim/mannasim-rede-plana.tcl
https://dl.dropboxusercontent.com/u/24623828/mannasim/mannasim-rede-hierarquica.tcl
Run these files using 

Here is the Listing for Hierarchical Simulation 

Listing 9.3 – Hierarchical simulation of Mannasim

# =============================================

# Procedure to create a common node application

# =============================================

proc create_common_app {destination_id disseminating_type disseminating_interval} {

set app_ [new Application/SensorBaseApp/CommonNodeApp]

$app_ set destination_id_ $destination_id

$app_ set disseminating_type_ $disseminating_type

$app_ set disseminating_interval_ $disseminating_interval

return $app_

}


# ===================================================

# Procedure to create a cluster head node application

# ===================================================

proc create_cluster_head_app {destination_id disseminating_type disseminating_interval} {

set app_ [new Application/SensorBaseApp/ClusterHeadApp]

$app_ set destination_id_ $destination_id

$app_ set disseminating_type_ $disseminating_type

$app_ set disseminating_interval_ $disseminating_interval

return $app_

}


# ====================================================

# Procedure to create a access point node application. 

# ====================================================

proc create_access_point_app {destination_id} {

set app_ [new Application/AccessPointApp]

$app_ set destination_id_ $destination_id

return $app_

}


# ================================================

# Procedure to create a Temperature Data Generator

# ================================================

proc create_temp_data_generator {sensing_interval sensing_type avg_measure std_deviation} {

set temp_gen_ [new DataGenerator/TemperatureDataGenerator]

$temp_gen_ set sensing_interval_ $sensing_interval

$temp_gen_ set sensing_type_ $sensing_type

$temp_gen_ set avg_measure $avg_measure

$temp_gen_ set std_deviation $std_deviation

return $temp_gen_

}


# ====================================================

# Procedure to create a Carbon Monoxide Data Generator

# ====================================================

proc create_carbon_data_generator {sensing_interval sensing_type avg_measure std_deviation} {

set carbon_gen_ [new DataGenerator/CarbonMonoxideDataGenerator]

$carbon_gen_ set sensing_interval_ $sensing_interval

$carbon_gen_ set sensing_type_ $sensing_type

$carbon_gen_ set avg_measure $avg_measure

$carbon_gen_ set std_deviation $std_deviation

return $carbon_gen_

}


# =================================

# Antenna Settings

# =================================

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


# =================================

# Wireless Phy Settings

# =================================

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

Phy/WirelessPhy set Pt_ 0.2818

Phy/WirelessPhy set freq_ 914e+6

Phy/WirelessPhy set L_ 1.0


set contador_nodos 0


# ==================================

# Simulation parameters

# ==================================

set val(pt_common) 8.564879510890936E-4

set val(pt_cluster_head) 0.2817901234567901


set val(chan) Channel/WirelessChannel ; # channel

set val(prop) Propagation/TwoRayGround ; # propagation 

set val(netif) Phy/WirelessPhy ; # phy

set val(mac) Mac/802_11 ; # mac

set val(ifq) Queue/DropTail/PriQueue ; # queue

set val(ll) LL ; # link layer

set val(ant) Antenna/OmniAntenna ; # antenna 

set val(ifqlen) 200 ; # queue length

set val(rp) DumbAgent ; # routing protocol

set val(en) EnergyModel/Battery ; # energy model

set val(nn) 14 ; # number of nodes

set val(n_pas) 1 ; # number os access points

set val(n_sinks) 1 ; # number of sink

set val(n_cluster) 2 ; # number of cluster heads

set val(n_common) 10 ; # number of common nodes

set val(x) 30.0 ; # x lenght of scenario

set val(y) 30.0 ; # y lenght of scenario


set val(disseminating_type) 0 ; # common node disseminating type

set val(ch_disseminating_type) 0 ; # cluster heard disseminating type

set val(disseminating_interval) 5.0 ; # common node disseminating interval

set val(cluster_head_disseminating_interval) 7.0 ; # cluster head disseminating interval


set val(start) 5.0 ; # simulation start time

set val(stop) 15.0 ; # simulation stop time


set val(father_addr) 1 ; # sink address

set val(port) 2020 ; # default port


# =======================================

# Global variables

# =======================================

set ns_ [new Simulator]

set traceFile [open mannasim-rede-hierarquica.tr w]

$ns_ trace-all $traceFile

$ns_ use-newtrace

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

set rng [new RNG]

$rng seed 0



# =================================

# Procedure to create a common node 

# =================================

proc create_common_node {} {

global val ns_ node_ topo udp_ app_ gen_ contador_nodos rng


Phy/WirelessPhy set Pt_ $val(pt_common)

$ns_ node-config -sensorNode ON \

-adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-energyModel $val(en) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-rxPower 0.024 \

-txPower 0.036 \

-initialEnergy 10.0 \

-movementTrace OFF

set node_($contador_nodos) [$ns_ node]

$node_($contador_nodos) random-motion 0

set x [$rng uniform 0.0 $val(x)]

set y [$rng uniform 0.0 $val(y)]

$node_($contador_nodos) set X_ $x

$node_($contador_nodos) set Y_ $y

$node_($contador_nodos) set Z_ 0.0

set interval [$rng uniform 0.0 1.0]


Node/MobileNode/SensorNode set sensingPower_ 0.015

Node/MobileNode/SensorNode set processingPower 0.024

Node/MobileNode/SensorNode set instructionsPerSecond_ 8000000

Phy/WirelessPhy set  bandwidth_ 288000.0


set udp_($contador_nodos) [new Agent/UDP]


set distance 10000000

set initial [expr $val(n_pas) + $val(n_sinks)]


for {set j $initial} {$j < [expr $initial + $val(n_cluster)]} {incr j} {

set x_father [$node_($j) set X_]

set y_father [$node_($j) set Y_]

set x_son [$node_($contador_nodos) set X_]

set y_son [$node_($contador_nodos) set Y_]

set x_temp [expr pow([expr $x_father-$x_son],2)]

set y_temp [expr pow([expr $y_father-$y_son],2)]

set temp_distance [expr sqrt([expr $x_temp + $y_temp])]

if {$temp_distance < $distance} {

set distance $temp_distance

set val(father_addr) [$node_($j) node-addr]

}

}


set app_($contador_nodos) [create_common_app $val(father_addr) $val(disseminating_type) $val(disseminating_interval)]

$node_($contador_nodos) attach $udp_($contador_nodos) $val(port)

$node_($contador_nodos) add-app $app_($contador_nodos)


set processing_($contador_nodos) [new Processing/AggregateProcessing]


$app_($contador_nodos) node $node_($contador_nodos)

$app_($contador_nodos) attach-agent $udp_($contador_nodos)


$app_($contador_nodos) attach-processing $processing_($contador_nodos)

$processing_($contador_nodos) node $node_($contador_nodos)


$ns_ at [expr $val(start) + 1 + $interval] "$app_($contador_nodos) start"

$ns_ at $val(stop) "$app_($contador_nodos) stop"


set gen_($contador_nodos) [create_temp_data_generator 3.0 0 25.0 1.0]

$app_($contador_nodos) attach_data_generator $gen_($contador_nodos)


incr contador_nodos


}


# ========================================

# Procedure to create a cluster head node 

# ========================================

proc create_cluster_head_node {} {


global val ns_ node_ topo contador_nodos rng


Phy/WirelessPhy set Pt_ $val(pt_cluster_head)

$ns_ node-config -sensorNode ON \

-adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-energyModel $val(en) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-rxPower 0.3 \

-txPower 0.6 \

-initialEnergy 100.0 \

-movementTrace OFF

set node_($contador_nodos) [$ns_ node]

$node_($contador_nodos) random-motion 0

set x [$rng uniform 0.0 $val(x)]

set y [$rng uniform 0.0 $val(y)]

$node_($contador_nodos) set X_ $x

$node_($contador_nodos) set Y_ $y

$node_($contador_nodos) set Z_ 0.0

set interval [$rng uniform 0.0 1.0]

Node/MobileNode/SensorNode set processingPower 0.36

Node/MobileNode/SensorNode set instructionsPerSecond_ 150000000

Phy/WirelessPhy set  bandwidth_ 1000000.0


set udp_($contador_nodos) [new Agent/UDP]


set app_($contador_nodos) [create_cluster_head_app [$node_(1) node-addr] $val(disseminating_type) $val(cluster_head_disseminating_interval)]

$node_($contador_nodos) attach $udp_($contador_nodos) $val(port)

$node_($contador_nodos) add-app $app_($contador_nodos)

set processing_($contador_nodos) [new Processing/AggregateProcessing]


$app_($contador_nodos) node $node_($contador_nodos)

$app_($contador_nodos) attach-agent $udp_($contador_nodos)


$app_($contador_nodos) attach-processing $processing_($contador_nodos)

$processing_($contador_nodos) node $node_($contador_nodos)


$ns_ at [expr $val(start) + 1 + $interval] "$app_($contador_nodos) start"

$ns_ at $val(stop) "$app_($contador_nodos) stop"


incr contador_nodos


}


# ===================================

# Procedure to create a sink node 

# ===================================

proc create_sink {} {

global ns_ val node_ sink_ contador_nodos topo


Phy/WirelessPhy set Pt_ 0.2818


$ns_ node-config -sensorNode ON \

-adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-energyModel $val(en) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-rxPower 0.5 \

-txPower 0.5 \

-initialEnergy 100.0 \

-movementTrace OFF


set node_($contador_nodos) [$ns_ node]

$node_($contador_nodos) random-motion 0


set sink_(0) [new Agent/LossMonitor]

$node_($contador_nodos) attach $sink_(0) $val(port)


$node_($contador_nodos) set X_ 0.0

$node_($contador_nodos) set Y_ 0.0

$node_($contador_nodos) set Z_ 0.0


incr contador_nodos


}


# ========================================

# Procedure to create a access point node 

# ========================================

proc create_access_point {} {

global ns_ val node_ app_ udp_ contador_nodos topo

Phy/WirelessPhy set Pt_ 0.2818

$ns_ node-config -sensorNode ON \

-adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-energyModel $val(en) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-rxPower 0.5 \

-txPower 0.5 \

-initialEnergy 100.0 \

-movementTrace OFF

set node_($contador_nodos) [$ns_ node]

$node_($contador_nodos) random-motion 0

set  udp_($contador_nodos) [new Agent/UDP]

set app_($contador_nodos) [create_access_point_app [$node_(0) node-addr]]

$node_($contador_nodos) attach $udp_($contador_nodos) $val(port)

$app_($contador_nodos) attach-agent $udp_($contador_nodos)

$node_($contador_nodos) set X_ 5.0

$node_($contador_nodos) set Y_ 5.0

$node_($contador_nodos) set Z_ 0.0

$ns_ at [expr $val(stop)+1] "$app_($contador_nodos) stop"

incr contador_nodos


}


# =================================================================

# Procedures to control common node and cluster head node creation

# =================================================================

create_sink

create_access_point


for {set j 0} {$j < $val(n_cluster)} {incr j} {

create_cluster_head_node

}


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

create_common_node

}


# =========================

# Simulation

# =========================

$ns_ at [expr $val(stop)+2.0] "finish"


$ns_ at [expr $val(stop)+2.0] "puts \"NS EXITING...\" ; $ns_ halt"


$ns_ at [expr $val(stop)+2.0] "$ns_ nam-end-wireless $val(stop)"


proc finish {} {

global ns_ traceFile

$ns_ flush-trace

close $traceFile


}


puts "Starting Simulation..."

$ns_ run



Here is another listing for Planar Configuration

Listing 9.4 – Planar or Flat Simulation

# =============================================

# Procedure to create a common node application

# =============================================

proc create_common_app {destination_id disseminating_type disseminating_interval} {

set app_ [new Application/SensorBaseApp/CommonNodeApp]

$app_ set destination_id_ $destination_id

$app_ set disseminating_type_ $disseminating_type

$app_ set disseminating_interval_ $disseminating_interval

return $app_

}


# ===================================================

# Procedure to create a cluster head node application

# ===================================================

proc create_cluster_head_app {destination_id disseminating_type disseminating_interval} {

set app_ [new Application/SensorBaseApp/ClusterHeadApp]

$app_ set destination_id_ $destination_id

$app_ set disseminating_type_ $disseminating_type

$app_ set disseminating_interval_ $disseminating_interval

return $app_

}


# ====================================================

# Procedure to create a access point node application. 

# ====================================================

proc create_access_point_app {destination_id} {

set app_ [new Application/AccessPointApp]

$app_ set destination_id_ $destination_id

return $app_

}


# ================================================

# Procedure to create a Temperature Data Generator

# ================================================

proc create_temp_data_generator {sensing_interval sensing_type avg_measure std_deviation} {

set temp_gen_ [new DataGenerator/TemperatureDataGenerator]

$temp_gen_ set sensing_interval_ $sensing_interval

$temp_gen_ set sensing_type_ $sensing_type

$temp_gen_ set avg_measure $avg_measure

$temp_gen_ set std_deviation $std_deviation

return $temp_gen_

}


# ====================================================

# Procedure to create a Carbon Monoxide Data Generator

# ====================================================

proc create_carbon_data_generator {sensing_interval sensing_type avg_measure std_deviation} {

set carbon_gen_ [new DataGenerator/CarbonMonoxideDataGenerator]

$carbon_gen_ set sensing_interval_ $sensing_interval

$carbon_gen_ set sensing_type_ $sensing_type

$carbon_gen_ set avg_measure $avg_measure

$carbon_gen_ set std_deviation $std_deviation

return $carbon_gen_

}


# =================================

# Antenna Settings

# =================================

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


# =================================

# Wireless Phy Settings

# =================================

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

Phy/WirelessPhy set Pt_ 0.2818

Phy/WirelessPhy set freq_ 914e+6

Phy/WirelessPhy set L_ 1.0


set contador_nodos 0


# ==================================

# Simulation parameters

# ==================================

set val(pt_common) 8.564879510890936E-4

set val(pt_cluster_head) 0.0


set val(chan) Channel/WirelessChannel ; # channel

set val(prop) Propagation/TwoRayGround ; # propagation 

set val(netif) Phy/WirelessPhy ; # phy

set val(mac) Mac/802_11 ; # mac

set val(ifq) Queue/DropTail/PriQueue ; # queue

set val(ll) LL ; # link layer

set val(ant) Antenna/OmniAntenna ; # antenna 

set val(ifqlen) 200 ; # queue length

set val(rp) DumbAgent ; # routing protocol

set val(en) EnergyModel/Battery ; # energy model

set val(nn) 12 ; # number of nodes

set val(n_pas) 1 ; # number os access points

set val(n_sinks) 1 ; # number of sink

set val(n_cluster) 0 ; # number of cluster heads

set val(n_common) 10 ; # number of common nodes

set val(x) 30.0 ; # x lenght of scenario

set val(y) 30.0 ; # y lenght of scenario


set val(disseminating_type) 0 ; # common node disseminating type

set val(ch_disseminating_type) 0 ; # cluster heard disseminating type

set val(disseminating_interval) 5.0 ; # common node disseminating interval

set val(cluster_head_disseminating_interval) 0.0 ; # cluster head disseminating interval


set val(start) 5.0 ; # simulation start time

set val(stop) 15.0 ; # simulation stop time


set val(father_addr) 1 ; # sink address

set val(port) 2020 ; # default port


# =======================================

# Global variables

# =======================================

set ns_ [new Simulator]

set traceFile [open mannasim-rede-plana.tr w]

$ns_ trace-all $traceFile

$ns_ use-newtrace

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

set rng [new RNG]

$rng seed 0


# =================================

# Procedure to create a common node 

# =================================

proc create_common_node {} {

global val ns_ node_ topo udp_ app_ gen_ contador_nodos rng


Phy/WirelessPhy set Pt_ $val(pt_common)

$ns_ node-config -sensorNode ON \

-adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-energyModel $val(en) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-rxPower 0.024 \

-txPower 0.036 \

-initialEnergy 10.0 \

-movementTrace OFF

set node_($contador_nodos) [$ns_ node]

$node_($contador_nodos) random-motion 0

set x [$rng uniform 0.0 $val(x)]

set y [$rng uniform 0.0 $val(y)]

$node_($contador_nodos) set X_ $x

$node_($contador_nodos) set Y_ $y

$node_($contador_nodos) set Z_ 0.0

set interval [$rng uniform 0.0 1.0]


Node/MobileNode/SensorNode set sensingPower_ 0.015

Node/MobileNode/SensorNode set processingPower 0.024

Node/MobileNode/SensorNode set instructionsPerSecond_ 8000000

Phy/WirelessPhy set  bandwidth_ 288000.0


set udp_($contador_nodos) [new Agent/UDP]


set distance 10000000

set initial [expr $val(n_pas) + $val(n_sinks)]


for {set j $initial} {$j < [expr $initial + $val(n_cluster)]} {incr j} {

set x_father [$node_($j) set X_]

set y_father [$node_($j) set Y_]

set x_son [$node_($contador_nodos) set X_]

set y_son [$node_($contador_nodos) set Y_]

set x_temp [expr pow([expr $x_father-$x_son],2)]

set y_temp [expr pow([expr $y_father-$y_son],2)]

set temp_distance [expr sqrt([expr $x_temp + $y_temp])]

if {$temp_distance < $distance} {

set distance $temp_distance

set val(father_addr) [$node_($j) node-addr]

}

}


set app_($contador_nodos) [create_common_app $val(father_addr) $val(disseminating_type) $val(disseminating_interval)]

$node_($contador_nodos) attach $udp_($contador_nodos) $val(port)

$node_($contador_nodos) add-app $app_($contador_nodos)


set processing_($contador_nodos) [new Processing/AggregateProcessing]


$app_($contador_nodos) node $node_($contador_nodos)

$app_($contador_nodos) attach-agent $udp_($contador_nodos)


$app_($contador_nodos) attach-processing $processing_($contador_nodos)

$processing_($contador_nodos) node $node_($contador_nodos)


$ns_ at [expr $val(start) + 1 + $interval] "$app_($contador_nodos) start"

$ns_ at $val(stop) "$app_($contador_nodos) stop"


set gen_($contador_nodos) [create_temp_data_generator 3.0 0 25.0 1.0]

$app_($contador_nodos) attach_data_generator $gen_($contador_nodos)


incr contador_nodos


}


# ========================================

# Procedure to create a cluster head node 

# ========================================

proc create_cluster_head_node {} {


global val ns_ node_ topo contador_nodos rng


Phy/WirelessPhy set Pt_ $val(pt_cluster_head)

$ns_ node-config -sensorNode ON \

-adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-energyModel $val(en) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-rxPower 0.0 \

-txPower 0.0 \

-initialEnergy 0.0 \

-movementTrace OFF

set node_($contador_nodos) [$ns_ node]

$node_($contador_nodos) random-motion 0

set x [$rng uniform 0.0 $val(x)]

set y [$rng uniform 0.0 $val(y)]

$node_($contador_nodos) set X_ $x

$node_($contador_nodos) set Y_ $y

$node_($contador_nodos) set Z_ 0.0

set interval [$rng uniform 0.0 1.0]

Node/MobileNode/SensorNode set processingPower 0.0

Node/MobileNode/SensorNode set instructionsPerSecond_ 0

Phy/WirelessPhy set  bandwidth_ 0.0


set udp_($contador_nodos) [new Agent/UDP]


set app_($contador_nodos) [create_cluster_head_app [$node_(1) node-addr] $val(disseminating_type) $val(cluster_head_disseminating_interval)]

$node_($contador_nodos) attach $udp_($contador_nodos) $val(port)

$node_($contador_nodos) add-app $app_($contador_nodos)

set processing_($contador_nodos) [new ]


$app_($contador_nodos) node $node_($contador_nodos)

$app_($contador_nodos) attach-agent $udp_($contador_nodos)


$app_($contador_nodos) attach-processing $processing_($contador_nodos)

$processing_($contador_nodos) node $node_($contador_nodos)


$ns_ at [expr $val(start) + 1 + $interval] "$app_($contador_nodos) start"

$ns_ at $val(stop) "$app_($contador_nodos) stop"


incr contador_nodos


}


# ===================================

# Procedure to create a sink node 

# ===================================

proc create_sink {} {

global ns_ val node_ sink_ contador_nodos topo


Phy/WirelessPhy set Pt_ 0.2818


$ns_ node-config -sensorNode ON \

-adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-energyModel $val(en) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-rxPower 0.5 \

-txPower 0.5 \

-initialEnergy 100.0 \

-movementTrace OFF


set node_($contador_nodos) [$ns_ node]

$node_($contador_nodos) random-motion 0


set sink_(0) [new Agent/LossMonitor]

$node_($contador_nodos) attach $sink_(0) $val(port)


$node_($contador_nodos) set X_ 0.0

$node_($contador_nodos) set Y_ 0.0

$node_($contador_nodos) set Z_ 0.0


incr contador_nodos


}


# ========================================

# Procedure to create a access point node 

# ========================================

proc create_access_point {} {

global ns_ val node_ app_ udp_ contador_nodos topo

Phy/WirelessPhy set Pt_ 0.2818

$ns_ node-config -sensorNode ON \

-adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-energyModel $val(en) \

-phyType $val(netif) \

-channelType $val(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-rxPower 0.5 \

-txPower 0.5 \

-initialEnergy 100.0 \

-movementTrace OFF

set node_($contador_nodos) [$ns_ node]

$node_($contador_nodos) random-motion 0

set  udp_($contador_nodos) [new Agent/UDP]

set app_($contador_nodos) [create_access_point_app [$node_(0) node-addr]]

$node_($contador_nodos) attach $udp_($contador_nodos) $val(port)

$app_($contador_nodos) attach-agent $udp_($contador_nodos)

$node_($contador_nodos) set X_ 5.0

$node_($contador_nodos) set Y_ 5.0

$node_($contador_nodos) set Z_ 0.0

$ns_ at [expr $val(stop)+1] "$app_($contador_nodos) stop"

incr contador_nodos


}


# =================================================================

# Procedures to control common node and cluster head node creation

# =================================================================

create_sink

create_access_point


for {set j 0} {$j < $val(n_cluster)} {incr j} {

create_cluster_head_node

}


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

create_common_node

}


# =========================

# Simulation

# =========================

$ns_ at [expr $val(stop)+2.0] "finish"


$ns_ at [expr $val(stop)+2.0] "puts \"NS EXITING...\" ; $ns_ halt"


$ns_ at [expr $val(stop)+2.0] "$ns_ nam-end-wireless $val(stop)"


proc finish {} {

global ns_ traceFile

$ns_ flush-trace

close $traceFile


}


puts "Starting Simulation..."

$ns_ run



Prompt] ns mannasim-rede-plana.tcl

Here is the output screenshot of the above command

Fig 9.11 – Planar Simulation

Prompt] ns mannasim-rede-hierarquica.tcl

Here is the output screenshot for the above command 

Fig 9.12 – hierarchical Simulation using Mannasim

Script Generation Tool

The script generation tool comes with a Java-based software that generates the above or below given Tcl code using its easier interface. Here are the sample screenshots that were used to create the Tcl script for running the Mannasim simulation. 

Listing 9.3 deals with the hierarchical simulation of sensor networks, and listing 9.4 shows the planar or flat simulation of sensor networks using the script generation tool. These two listings are easy to understand as it is self-explanatory. The script, once generated, has the option to save it as an .xml file for future use without altering the parameters. 

The script generation tool can be run using the ~ns-2.35/Mannasim/scriptgeneratorTool/msg-linux.sh file 

Prompt] ./msg-linux.sh 

Or

Prompt] bash msg-linux.sh 


Screenshot for Script generation

Fig 9.13 – Basic Configuration


Fig 9.14 - Access point Configuration



Fig 9.15 - Cluster Head Selection



Fig 9.16 - Common Node Configuration

Using these script generations, the Tcl script can be triggered and using the trace files, the results can be determined. In Mannasim, there are two data generators were introduced: carbon monoxide data and temperature data. The readers can generate data of their choice depending on their application.



Conclusion:

This chapter briefs and implements the wireless sensor flooding routing protocol (WFRP), and it also implements a third-party framework called the Mannasim framework that does the simulation for carbon monoxide and temperature sensors. This chapter also shows the way to create a script to generate a wireless sensor network. 


Comments

Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libc...

Simulation of URDF, Gazebo and Rviz | ROS Noetic Tutorial 8

Design a User-defined robot of your choice (or you can use the URDF file) and enable the LIDAR Scanner so that any obstacle placed on the path of the light scan will cut the light rays. Visualize the robot in the Gazebo workspace, and also show the demonstration in RViz.   (NB: Gain knowledge on wiring URDF file and .launch file for enabling any user-defined robot to get launched in the gazebo platform.) SLAM : One of the most popular applications of ROS is SLAM(Simultaneous Localization and Mapping). The objective of the SLAM in mobile robotics is to construct and update the map of an unexplored environment with the help of the available sensors attached to the robot which will be used for exploring. URDF: Unified Robotics Description Format, URDF, is an XML specification used in academia and industry to model multibody systems such as robotic manipulator arms for manufacturing assembly lines and animatronic robots for amusement parks. URDF is especially popular with users of the ...

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04 This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System Since ns-2.35 is too old, it needs the following packages gcc-4.8 g++-4.8 gawk and some more libraries Follow the video for more instructions So, here are the steps to install this software: To download and extract the ns2 software Download the software from the following link http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder) $ tar zxvf ns-allinone-2.35.tar.gz or Right click over the file and click extract here and select the home folder. $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev gawk To install gcc-4.8 and g++-4.8 $ sudo gedit /etc/apt/sources.list make an entry in the above file deb http://in.archive.ubuntu.com/ubuntu/ bionic main universe $ sudo apt update Since, it...