Vous êtes sur la page 1sur 43

CHAPTER 1

Networks

A network is a group of nodes that are connected to each other for the purpose of

communication.Networks may be classified according to a wide variety of characteristics.

TYPES OF NETWORKS

• WIRED NETWORKS

• WIRELESS NETWORKS

1.1 WIRED NETWORKS

Twisted-Pair Wire - This is the most widely used medium for telecommunication.

Twisted-pair wires are ordinary telephone wires which consist of two insulated

copper wires twisted into pairs and are used for both voice and data transmission.

The use of two wires twisted together helps to reduce crosstalk and electromagnetic

induction. The transmission speed range from 2 million bits per second to 100

million bits per second.

Coaxial Cable – These cables are widely used for cable television systems, office

buildings, and other worksites for local area networks. The cables consist of copper

or aluminum wire wrapped with insulating layer typically of a flexible material with

a high dielectric constant, all of which are surrounded by a conductive layer. The

layers of insulation help minimize interference and distortion. Transmission speed

range from 200 million to more than 500 million bits per second. One advantage of

coax over other types of transmission line is that in an ideal coaxial cable the

1
electromagnetic field carrying the signal exists only in the space between the inner

and outer conductors.

Fiber Optics – These cables consist of one or more thin filaments of glass fiber

wrapped in a protective layer. It transmits light which can travel over long distance

and higher bandwidths. Fiber-optic cables are not affected by electromagnetic

radiation. Transmission speed could go up to as high as trillions of bits per second.

The speed of fiber optics is hundreds of times faster than coaxial cables and

thousands of times faster than twisted-pair wire.

.
FIGURE-1.1

1.2 WIRELESS NETWORKS

Wireless communication is the transfer of information over a distance without the

use of electrical conductors or wires. The distances involved may be short (a few

2
meters as in television remote control) or long (thousands or millions of kilometers

for radio communications). When the context is clear, the term is often shortened to

wireless. Wireless communication is generally considered to be a branch of

telecommunications. Wireless operations permits services, such as long range

communications, that are impossible or impractical to implement with the use of

wires. The term is commonly used in the telecommunications industry to refer to

telecommunications systems (e.g. radio transmitters and receivers, remote controls,

computer networks, network terminals, etc.) which use some form of energy (e.g.

radio frequency (RF), infrared light, laser light, visible light, acoustic energy, etc.) to

transfer information without the use of wires.

FIGURE 1.2
1.3 TYPES OF WIRELESS NETWORKS

• CELLULAR NETWORKS

• AD HOC NETWORK

3
CHAPTER 2

Cellular Networks

A cellular network is a radio network made up of a number of radio cells (or just cells)

each served by at least one fixed-location transceiver known as a cell site or base station.

These cells cover different land areas to provide radio coverage over a wider area than

the area of one cell, so that a variable number of portable transceivers can be used in any

one cell and moved through more than one cell during transmission.The cellular network

has gone through three generations. The first generation of cellular networks is analog in

nature. To accommodate more cellular phone subscribers, digital TDMA (time division

multiple access) and CDMA (code division multiple access) technologies are used in the

second generation (2G) to increase the network capacity. With digital technologies,

digitized voice can be coded and encrypted. Therefore, the 2G cellular network is also

more secure. The third generation (3G) integrates cellular phones into the Internet world

by providing high speed packet-switching data transmission in addition to circuit-

switching voice transmission. The 3G cellular networks have been deployed in some

parts of Asia, Europe, and the United States since 2002 and will be widely deployed in

the coming years.

2.1 FIRST-GENERATION MOBILE SYSTEMS

The first generation of analog cellular systems included the Advanced Mobile Telephone

System (AMPS) which was made available in 1983. A total of 40MHz of spectrum was

allocated from the 800MHz band by the Federal Communications Commission (FCC) for

4
AMPS. It was first deployed in Chicago, with a service area of 2100 square miles. AMPS

offered 832 channels, with a data rate of 10 kbps. Although omni directional antennas

were used in the earlier AMPS implementation, it was realized that using directional

antennas would yield better cell reuse. In fact, the smallest reuse factor that would fulfill

the 18db signal-to-interference ratio (SIR) using 120-degree directional antennas was

found to be 7. Hence, a 7-cell reuse pattern was adopted for AMPS. Transmissions from

the base stations to mobiles occur over the forward channel using frequencies between

869-894 MHz. The reverse channel is used for transmissions from mobiles to base

station, using frequencies between 824-849 MHz

2.2 SECOND-GENERATION MOBILE SYSTEMS

Compared to first-generation systems, second-generation (2G) systems use digital

multiple access technology, such as TDMA (time division multiple access) and CDMA

(code division multiple access). Global System for Mobile Communications, or GSM,

uses TDMA technology to support multiple users. Examples of second-generation

systems are GSM, Cordless Telephone (CT2), Personal Access Communications Systems

(PACS), and Digital European Cordless Telephone (DECT). A new design was

introduced into the mobile switching center of second-generation systems. In particular,

the use of base station controllers (BSCs) lightens the load placed on the MSC (mobile

switching center) found in first-generation systems. This design allows the interface

between the MSC and BSC to be standardized. Hence, considerable attention was

devoted to interoperability and standardization in second-generation systems so that

carrier could employ different manufacturers for the MSC and BSCs. In addition to

5
enhancements in MSC design, the mobile-assisted handoff mechanism was introduced.

By sensing signals received from adjacent base stations, a mobile unit can trigger a

handoff by performing explicit signaling with the network.

2.3 2.5 GENERATION MOBILE SYSTEMS

The move into the 2.5G world will begin with General Packet Radio Service (GPRS).

GPRS is a radio technology for GSM networks that adds packet-switching protocols,

shorter setup time for ISP connections, and the possibility to charge by the amount of

data sent, rather than connection time. Packet switching is a technique whereby the

information (voice or data) to be sent is broken up into packets, of at most a few Kbytes

each, which are then routed by the network between different destinations based on

addressing data within each packet. Use of network resources is optimized as the

resources are needed only during the handling of each packet. The next generation of data

heading towards third generation and personal multimedia environments builds on GPRS

and is known as Enhanced Data rate for GSM Evolution (EDGE). EDGE will also be a

significant contributor in 2.5G. It will allow GSM operators to use existing GSM radio

bands to offer wireless multimedia IP-based services and applications at theoretical

maximum speeds of 384 kbps with a bit-rate of 48 kbps per timeslot and up to 69.2 kbps

per timeslot in good radio conditions. EDGE will let operators function without a 3G

license and compete with 3G networks offering similar data services. Implementing

EDGE will be relatively painless and will require relatively small changes to network

hardware and software as it uses the same TDMA (Time Division Multiple Access)

frame structure, logic channel and 200 kHz carrier bandwidth as today's GSM networks.

6
As EDGE progresses to coexistence with 3G WCDMA, data rates of up to ATM-like

speeds of 2 Mbps could be available. GPRS will support flexible data transmission rates

as well as continuous connection to the network. GPRS is the most significant step

towards 3G.

2.4 THIRD-GENERATION MOBILE SYSTEMS

Third-generation mobile systems are faced with several challenging technical issues, such

as the provision of seamless services across both wired and wireless networks and

universal mobility. In Europe, there are three evolving networks under investigation:

• UMTS (Universal Mobile Telecommunications Systems),

• MBS (Mobile Broadband Systems), and

• WLAN (Wireless Local Area Networks).

The use of hierarchical cell structures is proposed for IMT2000. The overlaying of cell

structures allows different rates of mobility to be serviced and handled by different cells.

Advanced multiple access techniques are also being investigated, and two promising

proposals have evolved, one based on wideband CDMA and another that uses a hybrid

TDMA/CDMA/FDMA approach.The International Telecommunication Union (ITU)

defined the third generation (3G) of mobile telephony standards IMT-2000 to facilitate

growth, increase bandwidth, and support more diverse applications.For example, GSM

(the current most popular cellular phone standard) could deliver not only voice, but also

circuit-switched data at download rates up to 14.4 kbps.

7
FIGURE 2.1

8
CHAPTER 3

Ad Hoc Networks
Ad hoc is a Latin phrase which means “for this purpose". It generally signifies a solution

designed for a specific problem or task, non-generalizable, and which cannot be adapted

to other purposes.A mobile ad hoc network (MANET), sometimes called a mobile mesh

network, is a self-configuring network of mobile devices connected by wireless links.

Each device in a MANET is free to move independently in any direction, and will

therefore change its links to other devices frequently. Each must forward traffic unrelated

to its own use, and therefore be a router. The primary challenge in building a MANET is

equipping each device to continuously maintain the information required to properly

route traffic.

FIGURE 3.1

9
Such networks may operate by themselves or may be connected to the larger Internet.

MANETs are a kind of wireless ad hoc networks that usually has a routeable networking

environment on top of a Link Layer ad hoc network. They are also a type of mesh

network, but many mesh networks are not mobile or not wireless. The growth of laptops

and 802.11/Wi-Fi wireless networking have made MANETs a popular research topic

since the mid- to late 1990s. Different protocols are then evaluated based on the packet

drop rate, the overhead introduced by the routing protocol, and other measures. A

wireless ad hoc network is a decentralized wireless network. The network is ad hoc

because it does not rely on a preexisting infrastructure, such as routers in wired networks

or access points in managed (infrastructure) wireless networks. Instead, each node

participates in routing by forwarding data for other nodes, and so the determination of

which nodes forward data is made dynamically based on the network connectivity.

The MANETs main characteristics are:-

• DYNAMIC TOPOLOGIES: - Nodes are free to move randomly and organize

themselves arbitrarily. Thus, the network topology, typically multihop, may

change rapidly and unpredictably. That leads towards the need of an effective

routing, a challenging problem to solve.

• BANDWIDTH-CONSTRAINED: - Variable capacity links Wireless links,

which can be either bidirectional or unidirectional, will continue to have

significantly lower capacity than wired ones. In addition, the actual throughput of

wireless communications after accounting for the effects of multiple access,

fading, noise, and interference conditions, etc.–is often much less than a radio’s

maximum transmission rate. One effect of the relatively low to moderate link

10
capacities is that congestion is typically the norm rather than the exception, so

demand from users will likely approach or exceed network capacity frequently.

As the mobile network is often simply an extension of the fixed network

infrastructure, mobile ad hoc users will demand similar services. These demands

will continue to increase as multimedia computing and collaborative networking

applications rise.

• ENERGY-CONSTRAINED: - Operation some or all of the nodes in a MANET

may rely on batteries or other exhaustible means for their energy. For these nodes,

the most important system design criteria for optimization may be energy

conservation. As a result, routing algorithms should be as simple as possible to

avoid intensive computations. For example, overhearing transmissions requires a

large amount of energy to receive and decode entire packets. Limited physical

security Mobile wireless networks are generally more prone to physical security

threats than wired nets. The increased possibility of eavesdropping, spoofing, and

denial-of-service attacks should be carefully considered. Existing link security

techniques are often applied within wireless networks to reduce security threats.

As a benefit, the decentralized nature of network control in MANETs provides

additional robustness against the single points of failure of more centralized

approaches.

• SCALABILITY: - Networks may be large, normally more than 10 nodes and

reaching 1000 nodes in a sensor network. Thus, routing protocols should be able

to scale to this amount.

11
CHAPTER 4

Power Management
Battery power is an important resource in ad hoc networks. It has been observed that in

ad hoc networks, energy consumption does not reflect the communication activities in the

network. Many existing energy conservation protocols based on electing a routing

backbone for global connectivity are oblivious to traffic characteristics. Nodes maintain

soft-state timers that determine power management transitions. By monitoring routing

control messages and data transmission, these timers are set and refreshed on-demand.

Nodes that are not involved in data delivery may go to sleep as supported by the MAC

protocol. This soft state is aggregated across multiple flows and its maintenance requires

no additional out-of-band messages. Wireless communication has the

advantage of allowing untethered communication, which implies

reliance on portable power sources such as batteries. However, due to

the slow advancement in battery technology, battery power continues

to be a constrained resource and so power management in wireless

networks remains to be an important issue. It has been observed that

in ad hoc networks, energy consumption does not always reflect active

communication in the network. Experimental results reveal that the

energy consumption of wireless devices in an idle state is only slightly

smaller than that in a transmitting or receiving state. Therefore, it is in

general desirable to turn the radio off when it is not in use. Motivated

by these observations, several energy conservation protocols have

been proposed to take advantage of route redundancy in dense ad hoc

12
networks by turning off devices that are not required for global

network connectivity. However, in these protocols, the decision about

which set of nodes to leave on is only based on

geographical/topological information thus is oblivious to the actual

traffic load in the network. Since many applications of ad hoc networks

are data-centric, maintenance of global connectivity is costly and

unnecessary when no traffic or only localized traffic is present in the

network. Various techniques, both in hardware and software, have

been proposed to reduce energy consumption for mobile computing

devices in wireless LANs In contrast, power management in ad hoc

networks is a more difficult problem for two reasons. First, in ad hoc

networks, a node can be both a data source/sink and a router that

forwards data for other nodes and participates in high-level routing and

control protocols. Additionally, the roles of a particular node may

change over time. Second, there is no centralized entity such as an

access point to control and maintain the power management mode of

each node in the network, buffer data and wake up sleeping nodes.

Therefore, power management in ad hoc networks must be done in a

distributed and cooperative fashion. A major challenge to the design of

a power management framework for ad hoc networks is that energy

conservation usually comes at the cost of degraded performance such

as lower throughput or longer delay. A naive solution that only

considers power savings at individual nodes may turn out to be

13
detrimental to the operation of the whole network. To achieve reduced

energy consumption while maintaining effective communication, our

framework integrates routing information from on-demand ad hoc

routing protocols and power management capabilities from the MAC

layer. Energy conservation is achieved by judiciously turning on and off

the radios of specific nodes in the network. The novelty of our

framework is that such power management decisions are driven by

active communications in the network. For the purpose of energy

conservation, connectivity is only maintained between pairs of senders

and receivers and along the route of data communication.

4.1 TYPES OF PROTOCOLS

• Destination-Sequenced Distance Vector (DSDV)

• Dynamic Source Routing (DSR)

• Ad hoc On-Demand Distance Vector (AODV)

4.2 Destination-Sequenced Distance Vector (DSDV)

DSDV is a hop-by-hop distance vector routing protocol. It is proactive and each node has

to periodically broadcast routing updates. The key advantage of DSDV over traditional

distance vector protocols is that it guarantees loop-freedom by using the concept of

sequence numbers. Each DSDV node maintains a routing table listing the “next hop” for

each reachable destination. DSDV tags each route with a sequence number and each node

in the network advertises an increasing even sequence number for itself. When a node

decides its route to a destination is broken, it advertises the route to infinite metric and a

sequence number one greater than its sequence number for the route that has broken

14
(making an odd sequence number). This causes any node routing packets through node to

incorporate the infinite-metric route into its routing table until node hears a route to node

with a higher sequence number. DSDV uses triggered route updates when the topology

changes. The transmission of updates is delayed to introduce a softening effect when the

topology is changing quickly. This gives an additional adaptation of DSDV to ad-hoc

networks.The main contribution of the algorithm was to solve the routing loop problem.

Each entry in the routing table contains a sequence number, the sequence numbers are

generally even if a link is present; else, an odd number is used.

4.3 Dynamic Source Routing (DSR)

DSR is a reactive protocol that uses source routing rather than hop-by-hop routing, with

each packet to be routed carrying in its header the complete, ordered list of nodes through

which the packet must pass. The key advantage of source routing is that intermediate

nodes do not need to maintain up-to-date routing information in order to route the packets

they forward, since the packets themselves already contain all the routing decisions. This

fact, coupled with the on-demand nature of the protocol, eliminates the need for the

periodic route advertisement and neighbor detection packets present in other protocols.

However, routing overhead is bigger. The DSR protocol consists of two mechanisms:

Route Discovery and Route Maintenance. Route Discovery is the mechanism by which a

node ns wanting to send a packet to a destination node obtains a path. To perform a Route

Discovery, the source node ns broadcasts a Route Request packet that is flooded through

the network in a controlled manner and is answered by a Route Reply packet from either

the destination node or another node that knows a route to the destination. To reduce the

cost of Route Discovery, each node maintains and actively uses a cache of source routes

15
it has learned or overheard. That way, the frequency and propagation of Route Requests

is limited. Route Maintenance is the mechanism by which a packet’s sender ns detects if

the network topology has changed such that it can no longer use its route to the

destination node because two nodes listed in the route have moved out of range of each

other. When Route Maintenance indicates a source route is broken, nodes are notified

with a Route Error packet. The sender ns can attempt to use any other route to node

already in its cache or can invoke Route Discovery again to find a new path. A DSR node

is able to learn routes by overhearing packets not addressed to it (the promiscuous mode).

However, this feature requires an active receiver in the nodes, which may be rather power

consuming and apparently does not improve performance.

4.4 Ad hoc On-Demand Distance Vector (AODV)

AODV is essentially a combination of both DSR and DSDV. It borrows the basic on

demand mechanism of Route Discovery and Route Maintenance from DSR, plus the use

of hop-by-hop routing, sequence numbers, and periodic beacons from DSDV. When a

node needs a route to some destination node, it broadcasts a Route Request message to its

neighbors, including the last known sequence number for that destination. The Route

Request is flooded until it reaches a node that knows a route to the destination. Each node

that forwards the Route Request creates a reverse route for itself back to node. When the

Route Request reaches a node with a route to node, that node generates a Route Reply

that contains the number of hops necessary to reach node and the sequence number for

node most recently seen by the node generating the Reply. Each node that participates in

forwarding this reply back toward the originator of the Route Request creates a forward

route to node. The state created in each node along the path is hop-by-hop state; that is,

16
each node remembers only the next hop and not the entire route, as would be done in

source routing. In order to maintain routes, AODV normally requires that each node

periodically transmit a HELLO message, with a default rate of once per second. Failure

to receive three consecutive HELLO messages from a neighbor is taken as an indication

that the link to the neighbor is down. Alternatively, the AODV specification briefly

suggests that a node may use physical layer or link layer methods to detect link breakages

to nodes that it considers neighbors When a link goes down, any upstream node that has

recently forwarded packets to a destination using that link.

CHAPTER 5

Network Simulator-2

Ns-2 is an object-oriented simulator developed as part of the VINT

project at the University of California in Berkeley. Ns-2 is extensively

used by the networking research community. It provides substantial

support for simulation of TCP, routing, multicast protocols over wired

and wireless (local and satellite) networks, etc. The simulator is event-

driven and runs in a non-real-time fashion. It consists of C++ core

methods and uses Tcl and Object Tcl shell as interface allowing the

input file (simulation script) to describe the model to simulate. Users

can define arbitrary network topologies composed of nodes, routers,

links and shared media. A rich set of protocol objects can then be

attached to nodes, usually as agents Ns-2 is a packet-level simulator which is

essentially a centralized discrete event scheduler to schedule the events such as packet

17
and timer expiration. The centralized event scheduler cannot accurately emulate “events

occurred at the same time”, instead, it can only handle events occurred one by one in

time. However, this is not a serious problem in most network simulations, because the

events here are often transitory. Besides, ns-2 implements a variety of network

components and protocols. Notably, the wireless extension, derived from two

assumptions simplifying the physical world:

• Nodes do not move significantly over the length of time they transmit or receive a

packet. This assumption holds only for mobile nodes of high-rate and low-speed.

Consider a node with the sending rate of 10Kbps and moving speed of 10m/s,

during its receiving a packet of 1500B, the node moves 12m. Thus, the

surrounding can change significantly and cause reception failure.

• Node velocity is insignificant compared to the speed of light. In particular, none

of the provided propagation models include Doppler effects, although they could.

5.1 Ns-2 Basics

• Ns-2 directory structure

The C++ classes of ns-2 network components and protocols are implemented in the

subdirectory “Ns-2” and the TCL library (corresponding to configurations of these C++

instances) in the subdirectory of “tcl”.

• Network Components

Network components are Node, Link, Queue, etc. Some of them are simple components,

that is, they corresponds to a single C++ object; The others are compound components,

that is, they combine multiple simple components, e.g. a Link component is composed of

a Delay component (emulating propagation delay) and a Queue component. In general,

18
all network components are created, plugged and configured by some TCL scripts (./ns-

allinone-2.*/tcl/) when ns-2 is initialized.

FIGURE-5.1

19
CHAPTER 6
Output
• OUTPUT OF AODV

20
• OUTPUT OF DSDV

21
Summary and Conclusion

22
We present a power management framework that reduces energy

consumption in ad hoc networks while maintaining effective

throughput. It explores the design space between proactive and

reactive power management approaches by adapting to the traffic load

in ad hoc networks. In our framework, transitions between power

management modes of a node are triggered by packet arrivals and the

expiration of a soft state timer called the keep-alive timer. Various

messages can serve to set up and refresh the keep-alive timer on

demand when mobility is high, intermediate nodes may remain in

active mode longer than necessary, which will result in reduced energy

savings. In addition, frequent broadcast messages for route discovery

may hurt overall performance since broadcast messages cause all

nodes to stay awake during a beacon interval. Techniques such as

mobility prediction or proactive handoffs may be used to reduce the

number of unnecessarily nodes that remain on despite route changes.

For on-demand routing protocols such as DSR that maintain routing

caches, we are investigating the integration of power management

with the caching strategy to better handle mobility.

23
References

[1] Rong Zheng and Robin Kravets, “On-demand Power Management for
Ad Hoc
Networks,”in Proc. of IEEE INFOCOM, 2003.

[2] Samyak Shah, Amit Khandre, Mahesh Shirole and Girish Bhole, “Performance Evaluation
of
Ad Hoc Routing Protocols Using NS2 Simulation”in CoMPC,2008.

[3] David Cordes And Jingyuan Zhang,”Power-Aware routing protocols in


ad hoc wireless networks “,IEEE INFOCOM, 2005.

[4] C.-K. Toh,”Maximum Battery Life Routing to Support Ubiquitous Mobile Computing
in Wireless Ad Hoc Networks”, IEEE Communication Magazine, June 2001.

[5] L. M. Feeney and M. Nilsson, “Investigating the energy consumption of a wireless


network interface in an ad hoc networking environment,” in Proc. of IEEE
INFOCOM, April 2001.

[6] R. Kravets and P. Krishnan, “Application-driven power management for mobile


communication,” Wireless Networks, vol. 6, no. 4, 2000.

[7] D. B. Johnson and D. A. Maltz, “Dynamic source routing in ad hoc


wireless
networks.” draft-ietf-manet-dsr-04.txt, 2001.

[8] C. E. Perkins, E. M. Royer, and S. Das, “Ad hoc on demand distance


vector
(AODV) routing.” draft-ietf-manet-aodv-07.txt, 2000.

24
Appendix A: Source Code

# AODV PROGRAM CODE

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(nn) 6 ;# number of mobilenodes

set val(rp) AODV ;# routing protocol

set val(x) 800

set val(y) 800

set ns [new Simulator]

#ns-random 0

25
set f [open 1_out.tr w]

$ns trace-all $f

set namtrace [open 1_out.nam w]

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

set f0 [open packets_received.tr w]

set f1 [open packets_lost.tr w]

set f2 [open proj_out2.tr w]

set f3 [open proj_out3.tr w]

set topo [new Topography]

$topo load_flatgrid 800 800

create-god $val(nn)

set chan_1 [new $val(chan)]

set chan_2 [new $val(chan)]

set chan_3 [new $val(chan)]

set chan_4 [new $val(chan)]

set chan_5 [new $val(chan)]

set chan_6 [new $val(chan)]

# CONFIGURE AND CREATE NODES

$ns node-config -adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

26
-antType $val(ant) \

-propType $val(prop) \

-phyType $val(netif) \

#-channelType $val(chan) \

-topoInstance $topo \

-agentTrace OFF \

-routerTrace ON \

-macTrace ON \

-movementTrace OFF \

-channel $chan_1 # \

#-channel $chan_2 \

#-channel $chan_3 \

#-channel $chan_4 \

#-channel $chan_5 \

#-channel $chan_6

proc finish {} {

global ns f f0 f1 f2 f3 namtrace

$ns flush-trace

close $namtrace

close $f0

close $f1

close $f2

close $f3

27
exec xgraph packets_received.tr packets_lost.tr

# proj_out2.tr proj_out3.tr

exec nam -r 5m 1_out.nam &

exit 0

proc record {} {

global sink0 sink1 sink2 sink3 sink4 sink5 f0 f1 f2 f3

#Get An Instance Of The Simulator

set ns [Simulator instance]

#Set The Time After Which The Procedure Should Be Called Again

set time 0.05

#How Many Bytes Have Been Received By The Traffic Sinks?

set bw0 [$sink5 set npkts_]

set bw1 [$sink5 set nlost_]

#set bw2 [$sink2 set npkts_]

#set bw3 [$sink3 set npkts_]

#Get The Current Time

set now [$ns now]

#Save Data To The Files

puts $f0 "$now [expr $bw0]"

puts $f1 "$now [expr $bw1]"

#puts $f2 "$now [expr $bw2]"

#puts $f3 "$now [expr $bw3]"

28
#Re-Schedule The Procedure

$ns at [expr $now+$time] "record"

# define color index

$ns color 0 blue

$ns color 1 red

$ns color 2 chocolate

$ns color 3 red

$ns color 4 brown

$ns color 5 tan

$ns color 6 gold

$ns color 7 black

set n(0) [$ns node]

#$ns at 0.0 "$n(0) color red"

$n(0) color "0"

$n(0) shape "circle"

set n(1) [$ns node]

$n(1) color "blue"

$n(1) shape "circle"

set n(2) [$ns node]

$n(2) color "tan"

$n(2) shape "circle"

set n(3) [$ns node]

29
$n(3) color "red"

$n(3) shape "circle"

set n(4) [$ns node]

$n(4) color "tan"

$n(4) shape "circle"

set n(5) [$ns node]

$n(5) color "red"

$n(5) shape "circle"

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

$ns initial_node_pos $n($i) 30+i*100

$n(0) set X_ 0.0

$n(0) set Y_ 0.0

$n(0) set Z_ 0.0

$n(1) set X_ 0.0

$n(1) set Y_ 0.0

$n(1) set Z_ 0.0

$n(2) set X_ 0.0

$n(2) set Y_ 0.0

$n(2) set Z_ 0.0

$n(3) set X_ 0.0

$n(3) set Y_ 0.0

$n(3) set Z_ 0.0

30
$n(4) set X_ 0.0

$n(4) set Y_ 0.0

$n(4) set Z_ 0.0

$n(5) set X_ 0.0

$n(5) set Y_ 0.0

$n(5) set Z_ 0.0

$ns at 0.0 "$n(0) setdest 100.0 100.0 3000.0"

$ns at 0.0 "$n(1) setdest 200.0 200.0 3000.0"

$ns at 0.0 "$n(2) setdest 300.0 200.0 3000.0"

$ns at 0.0 "$n(3) setdest 400.0 300.0 3000.0"

$ns at 0.0 "$n(4) setdest 500.0 300.0 3000.0"

$ns at 0.0 "$n(5) setdest 600.0 400.0 3000.0"

$ns at 2.0 "$n(5) setdest 100.0 400.0 500.0"

#$ns at 1.5 "$n(3) setdest 450.0 150.0 500.0"

# CONFIGURE AND SET UP A FLOW

set sink0 [new Agent/LossMonitor]

set sink1 [new Agent/LossMonitor]

set sink2 [new Agent/LossMonitor]

set sink3 [new Agent/LossMonitor]

set sink4 [new Agent/LossMonitor]

set sink5 [new Agent/LossMonitor]

$ns attach-agent $n(0) $sink0

$ns attach-agent $n(1) $sink1

31
$ns attach-agent $n(2) $sink2

$ns attach-agent $n(3) $sink3

$ns attach-agent $n(4) $sink4

$ns attach-agent $n(5) $sink5

#$ns attach-agent $sink2 $sink3

set tcp0 [new Agent/TCP]

$ns attach-agent $n(0) $tcp0

set tcp1 [new Agent/TCP]

$ns attach-agent $n(1) $tcp1

set tcp2 [new Agent/TCP]

$ns attach-agent $n(2) $tcp2

set tcp3 [new Agent/TCP]

$ns attach-agent $n(3) $tcp3

set tcp4 [new Agent/TCP]

$ns attach-agent $n(4) $tcp4

set tcp5 [new Agent/TCP]

$ns attach-agent $n(5) $tcp5

proc attach-CBR-traffic { node sink size interval } {

#Get an instance of the simulator

set ns [Simulator instance]

#Create a CBR agent and attach it to the node

set cbr [new Agent/CBR]

$ns attach-agent $node $cbr

32
$cbr set packetSize_ $size

$cbr set interval_ $interval

#Attach CBR source to sink;

$ns connect $cbr $sink

return $cbr

set cbr0 [attach-CBR-traffic $n(0) $sink5 1000 .015]

#set cbr1 [attach-CBR-traffic $n(1) $sink2 1000 .015]

#set cbr2 [attach-CBR-traffic $n(2) $sink3 1000 .015]

#set cbr3 [attach-CBR-traffic $n(3) $sink0 1000 .015]

#set cbr4 [attach-CBR-traffic $n(4) $sink3 1000 .015]

#set cbr5 [attach-CBR-traffic $n(5) $sink0 1000 .015]

$ns at 0.0 "record"

#$ns at 0.5 "$cbr0 start"

#$ns at 0.5 "$cbr2 start"

#$ns at 2.0 "$cbr0 stop"

#$ns at 2.0 "$cbr2 stop"

$ns at 1.0 "$cbr0 start"

#$ns at 4.0 "$cbr3 stop"

$ns at 10.0 "finish"

puts "Start of simulation.."

$ns run

33
# DSDV PROGRAM CODE
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(nn) 6 ;# number of mobilenodes

set val(rp) DSDV ;# routing protocol

set val(x) 800

set val(y) 800

set ns [new Simulator]

#ns-random 0

set f [open 1_out.tr w]

$ns trace-all $f

set namtrace [open 1_out.nam w]

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

set f0 [open proj_out0.tr w]

set f1 [open proj_out1.tr w]

set f2 [open proj_out2.tr w]

set f3 [open proj_out3.tr w]

set topo [new Topography]

34
$topo load_flatgrid 800 800

create-god $val(nn)

set chan_1 [new $val(chan)]

set chan_2 [new $val(chan)]

set chan_3 [new $val(chan)]

set chan_4 [new $val(chan)]

set chan_5 [new $val(chan)]

set chan_6 [new $val(chan)]

# CONFIGURE AND CREATE 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) \

#-channelType $val(chan) \

-topoInstance $topo \

-agentTrace OFF \

-routerTrace ON \

-macTrace ON \

35
-movementTrace OFF \

-channel $chan_1 # \

#-channel $chan_2 \

#-channel $chan_3 \

#-channel $chan_4 \

#-channel $chan_5 \

#-channel $chan_6

proc finish {} {

global ns f f0 f1 f2 f3 namtrace

$ns flush-trace

close $namtrace

close $f0

close $f1

close $f2

close $f3

# exec xgraph proj_out0.tr proj_out1.tr

# proj_out2.tr proj_out3.tr

exec nam -r 5m 1_out.nam &

exit 0

proc record {} {

global sink0 sink1 sink2 sink3 sink4 sink5 f0 f1 f2 f3

#Get An Instance Of The Simulator

36
set ns [Simulator instance]

#Set The Time After Which The Procedure Should Be Called Again

set time 0.05

#How Many Bytes Have Been Received By The Traffic Sinks?

set bw0 [$sink5 set npkts_]

set bw1 [$sink5 set nlost_]

#set bw2 [$sink2 set npkts_]

#set bw3 [$sink3 set npkts_]

#Get The Current Time

set now [$ns now]

#Save Data To The Files

puts $f0 "$now [expr $bw0]"

puts $f1 "$now [expr $bw1]"

#puts $f2 "$now [expr $bw2]"

#puts $f3 "$now [expr $bw3]"

#Re-Schedule The Procedure

$ns at [expr $now+$time] "record"

# define color index

$ns color 0 blue

$ns color 1 red

$ns color 2 chocolate

$ns color 3 red

37
$ns color 4 brown

$ns color 5 tan

$ns color 6 gold

$ns color 7 black

set n(0) [$ns node]

#$ns at 0.0 "$n(0) color red"

$n(0) color "0"

$n(0) shape "circle"

set n(1) [$ns node]

$n(1) color "blue"

$n(1) shape "circle"

set n(2) [$ns node]

$n(2) color "tan"

$n(2) shape "circle"

set n(3) [$ns node]

$n(3) color "red"

$n(3) shape "circle"

set n(4) [$ns node]

$n(4) color "tan"

$n(4) shape "circle"

set n(5) [$ns node]

$n(5) color "red"

$n(5) shape "circle"

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

$ns initial_node_pos $n($i) 30+i*100

$n(0) set X_ 0.0

$n(0) set Y_ 0.0

$n(0) set Z_ 0.0

$n(1) set X_ 0.0

$n(1) set Y_ 0.0

$n(1) set Z_ 0.0

$n(2) set X_ 0.0

$n(2) set Y_ 0.0

$n(2) set Z_ 0.0

$n(3) set X_ 0.0

$n(3) set Y_ 0.0

$n(3) set Z_ 0.0

$n(4) set X_ 0.0

$n(4) set Y_ 0.0

$n(4) set Z_ 0.0

$n(5) set X_ 0.0

$n(5) set Y_ 0.0

$n(5) set Z_ 0.0

$ns at 0.0 "$n(0) setdest 100.0 100.0 3000.0"

$ns at 0.0 "$n(1) setdest 200.0 200.0 3000.0"

39
$ns at 0.0 "$n(2) setdest 300.0 200.0 3000.0"

$ns at 0.0 "$n(3) setdest 400.0 300.0 3000.0"

$ns at 0.0 "$n(4) setdest 500.0 300.0 3000.0"

$ns at 0.0 "$n(5) setdest 600.0 400.0 3000.0"

$ns at 2.0 "$n(5) setdest 100.0 400.0 500.0"

#$ns at 1.5 "$n(3) setdest 450.0 150.0 500.0"

# CONFIGURE AND SET UP A FLOW

set sink0 [new Agent/LossMonitor]

set sink1 [new Agent/LossMonitor]

set sink2 [new Agent/LossMonitor]

set sink3 [new Agent/LossMonitor]

set sink4 [new Agent/LossMonitor]

set sink5 [new Agent/LossMonitor]

$ns attach-agent $n(0) $sink0

$ns attach-agent $n(1) $sink1

$ns attach-agent $n(2) $sink2

$ns attach-agent $n(3) $sink3

$ns attach-agent $n(4) $sink4

$ns attach-agent $n(5) $sink5

#$ns attach-agent $sink2 $sink3

set tcp0 [new Agent/TCP]

$ns attach-agent $n(0) $tcp0

set tcp1 [new Agent/TCP]

40
$ns attach-agent $n(1) $tcp1

set tcp2 [new Agent/TCP]

$ns attach-agent $n(2) $tcp2

set tcp3 [new Agent/TCP]

$ns attach-agent $n(3) $tcp3

set tcp4 [new Agent/TCP]

$ns attach-agent $n(4) $tcp4

set tcp5 [new Agent/TCP]

$ns attach-agent $n(5) $tcp5

proc attach-CBR-traffic { node sink size interval } {

#Get an instance of the simulator

set ns [Simulator instance]

#Create a CBR agent and attach it to the node

set cbr [new Agent/CBR]

$ns attach-agent $node $cbr

$cbr set packetSize_ $size

$cbr set interval_ $interval

#Attach CBR source to sink;

$ns connect $cbr $sink

return $cbr

set cbr0 [attach-CBR-traffic $n(0) $sink5 1000 .015]

#set cbr1 [attach-CBR-traffic $n(1) $sink2 1000 .015]

41
#set cbr2 [attach-CBR-traffic $n(2) $sink3 1000 .015]

#set cbr3 [attach-CBR-traffic $n(3) $sink0 1000 .015]

#set cbr4 [attach-CBR-traffic $n(4) $sink3 1000 .015]

#set cbr5 [attach-CBR-traffic $n(5) $sink0 1000 .015]

$ns at 0.0 "record"

#$ns at 0.5 "$cbr0 start"

#$ns at 0.5 "$cbr2 start"

#$ns at 2.0 "$cbr0 stop"

#$ns at 2.0 "$cbr2 stop"

$ns at 1.0 "$cbr0 start"

#$ns at 4.0 "$cbr3 stop"

$ns at 10.0 "finish"

puts "Start of simulation.."

$ns run

42
43

Vous aimerez peut-être aussi