You are on page 1of 9

Term Project 2: Using NS2 to implement LEACH

22082228

1. Aims
The aim of this assignment is to understand the characteristics of LEACH and experience
wireless sensor network simulators.
2. Introduction of LEACH
LEACH is a cluster-based protocol, which includes distributed cluster formation. LEACH
randomly selects a few sensor nodes as cluster heads (CHs) and rotates this role to evenly
distribute the energy load among the sensors in the network.
The operation of LEACH is separated into two phases, the setup phase and the steady state
phase. In the setup phase, the clusters are organized and CHs are selected. In the steady
state phase, the actual data transfer to the base station takes place.
In setup phase, each node chooses a random number between 0 and 1. If the number is less
than the threshold, the node is the cluster head. It will broadcast news to other nodes, and
each node decides to join which cluster node according to signal strength.
In steady state phase, cluster nodes will process data which is sent from nodes such as data
fusion and aggregation, and transmit it to sink.
3. Implement
NS2 which is an network simulator is used to simulate the network. LEACH protocol source
code provided by mit is loaded on NS2 to implement LEACH protocol.

4. Experiments result
My experiments are based on the default leach test set by MIT. First experiment uses the
default config file. Then I changed two parameters of default config file and got other two
different results. The following are the main files of each experiment.

1> Using default config file


LEACH_test file: the default parameters are defined in this file.

alg=leach

#This is the algorithm that we are going to run.

dirname="mit/leach_sims"

# The directory and filename that we want our output to be written.

filename=$alg
topology_file="mit/uAMPS/sims/100nodes.txt"
num_clusters=5

#This file is the scenario that we are going to run.

#number of clusters we want. It is recommended to use 5% of the total

eq_energy=1

# energy values. How much energy does each node have initially

init_energy=2
stop=3600

# stop is the time to stop the simulation if it is still running

x=1000

# x,y is the size of the field

y=1000
bs_x=50

# bs_x, bs_y is the location of the base station in the field.

bs_y=175
nn=101

# Number of nodes. This should be 1 higher than the number of nodes generated in the scenario

Condition.txt file
USING LEACH: DISTRIBUTED CLUSTER FORMATION
Simulation will stop after 3600 seconds.
Base station at (50, 175)
Each node starting with 2 Joules of energy.
Energy Model:
RXThresh = 6e-9
CSThresh = 1e-9
Rb = 1e6
Excvr = 50e-9
Efriss_amp = 9.6741659015025702e-12
Etwo_ray_amp = 1.3037037037037037e-15
Ebf = 5e-9
Pidle = 0
Psleep = 0
Thresholds chosen using original probs.
Desired number of clusters = 5
Spreading factor = 8
Changing clusters every 20 seconds

Leach.energy file (partly):

10 0 0.020595866298143972
10 1 0.020796805544838353
10 2 0.0076756180100429105
10 3 0.0080182483101283227

378.70000000001761 96 2.7319517057416345
378.70000000001761 97 2.0016787300175682
378.70000000001761 98 2.6527214788314222
378.70000000001761 99 3.076902775055153

Leach.alive file (partly):


10 0 1
10 1 1
10 2 1
10 3 1

378.70000000001761 96 0
378.70000000001761 97 0
378.70000000001761 98 0
378.70000000001761 99 0

TDMAschedule.20.txt file:
5

64 16 40 27 1 39 65 62 88 0 56

79 37 30 28 74 98 84 57 73 2 10 96 78 69

26

44 85 80 13 15 53 4 76 21 99 41 67 72 92 46 87 17 32 45

50

54 61 24 93 89 91 48 52 59 75 95 47 55 66 63 97 36 58 12 42

77

33 94 8 49 7 29 51 70 23 38 90 81

82

14 43 83 35 31 18 71 68 25 60 86 20 19 34 22 11 6 3

Leach.out file (partly):

num_nodes is set 101


Creating sensor nodes...
0 1 2 3 4 5 6 7 8 96 97 98 99 (100 == BS)
Loading scenario file...
Node 0: (65.745973803916002,92.581722416254564)
Node 1: (21.008649990432268,92.380389195112684)

Node 98: (2.466682112993059,57.526273074339272)


Node 99: (44.071560420129238,10.71598111219517)
Max Distance for this Simulation is 139.0
..
12: Is a cluster head at time 0
THRESH = 0.050000000000000003
13: *******************************************
THRESH = 0.050000000000000003

0: Current cluster-head is 16, code is 1, dist is 16


1: Current cluster-head is 16, code is 1, dist is 30
2: Current cluster-head is 12, code is 2, dist is 11
3: Current cluster-head is 12, code is 2, dist is 32

BS Received data 16 , 1.6109241256129656 from 16 at time 1.6448144862873331


This represents data from nodes: 35 19 64 0 65 20 22 1 68 71 88 83 5 27 60 62 14 59 16
BS Received data 42 , 1.6446520723570157 from 42 at time 1.6808430401062162
This represents data from nodes: 54 9 69 10 89 93 47 79 98 55 56 66 61 74 97 40 96 39 52 42

BS Received data 66 , 375.45310002073012 from 66 at time 375.48845295493089


This represents data from nodes: 59 79 24 46 95 45
Node 59 is DEAD!!!!
Node 79 is DEAD!!!!
At 378.70000000001761:
Total Energy = 302.16176076282812
Total Data = 37025
Total Alive = 4
Simulation complete.

2> Change one of the parameters:


In this experiment, I changed the number of clusters from 5 to 10.

LEACH_test file (partly):

num_clusters=5

Condition.txt file

#number of clusters we want. It is recommended to use 5% of the total

USING LEACH: DISTRIBUTED CLUSTER FORMATION


Simulation will stop after 3600 seconds.
Base station at (50, 175)
Each node starting with 2 Joules of energy.
Energy Model:
RXThresh = 6e-9
CSThresh = 1e-9
Rb = 1e6
Excvr = 50e-9
Efriss_amp = 9.6741659015025702e-12
Etwo_ray_amp = 1.3037037037037037e-15
Ebf = 5e-9
Pidle = 0
Psleep = 0
Thresholds chosen using original probs.
Desired number of clusters = 10
Spreading factor = 16
Changing clusters every 20 seconds

Leach.energy file (partly):


10 0 0.026361880504513487
10 1 0.014724424002492074
10 2 0.039149063425240681
10 3 0.46643024857508131

381.60000000001827 96 2.5149526692928803
381.60000000001827 97 3.4356600175697785
381.60000000001827 98 2.5193031335323699
381.60000000001827 99 2.5649926069643216

Leach.alive file (partly):


10 0 1
10 1 1
10 2 1
10 3 1

381.60000000001827 96 0
381.60000000001827 97 0
381.60000000001827 98 0
381.60000000001827 99 0

TDMAschedule.60.txt file:

62 20 18

40

27 64

77

23 33

79

17 30

91

25

98

Leach.out file (partly):


num_nodes is set 101
Creating sensor nodes...
0 1 2 3 4 5 6 7 8 96 97 98 99 (100 == BS)
Loading scenario file...
Node 0: (65.745973803916002,92.581722416254564)
Node 1: (21.008649990432268,92.380389195112684)

Node 98: (2.466682112993059,57.526273074339272)


Node 99: (44.071560420129238,10.71598111219517)
Max Distance for this Simulation is 139.0
..
3: Is a cluster head at time 0
THRESH = 0.10000000000000001
4: *******************************************
4: Is a cluster head at time 0
THRESH = 0.10000000000000001

0: Current cluster-head is 60, code is 6, dist is 30


1: Current cluster-head is 61, code is 4, dist is 25
2: Current cluster-head is 15, code is 5, dist is 24
3: Current cluster-head is 3, code is 3, dist is 139.0

BS Received data 72 , 1.2768120961991267 from 72 at time 1.3434019292829624


This represents data from nodes: 99 41 26 80 72
BS Received data 15 , 1.4117241543869543 from 15 at time 1.4795935390814605
This represents data from nodes: 32 53 91 92 85 2 15

BS Received data 30 , 381.00951199999997 from 30 at time 381.5976036960775


This represents data from nodes:
Node 18 is DEAD!!!!
At 381.60000000001827:
Total Energy = 298.27335652355163
Total Data = 5918
Total Alive = 9
Simulation complete.

3> Change one of the parameters:


In this experiment, I changed the location of BS from (50,175) to (20,50).

LEACH_test file (partly):


bs_x=50

# bs_x, bs_y is the location of the base station in the field.

bs_y=175

Condition.txt file
USING LEACH: DISTRIBUTED CLUSTER FORMATION
Simulation will stop after 3600 seconds.
Base station at (20, 50)
Each node starting with 2 Joules of energy.
Energy Model:
RXThresh = 6e-9
CSThresh = 1e-9
Rb = 1e6
Excvr = 50e-9
Efriss_amp = 9.6741659015025702e-12
Etwo_ray_amp = 1.3037037037037037e-15
Ebf = 5e-9
Pidle = 0
Psleep = 0
Thresholds chosen using original probs.
Desired number of clusters = 5
Spreading factor = 8
Changing clusters every 20 seconds

Leach.energy file (partly):


10 0 0.049169176892845723
10 1 0.44229645292517672
10 2 0.024756148577518327
10 3 0.028866643813124405

565.20000000005996 96 3.9511984004717937
565.20000000005996 97 2.1832415749427532
565.20000000005996 98 2.0021766326620138
565.20000000005996 99 6.2290362802848112

Leach.alive file (partly):


10 0 1
10 1 1
10 2 1
10 3 1

565.20000000005996 96 0
565.20000000005996 97 0
565.20000000005996 98 0
565.20000000005996 99 0

TDMAschedule.120.txt file:
4

67 45 15 87 99 46 41 72 26 76 78 30

21

34 95 3 11 81 43 18 82 83 94 19 31 49 35 6 63 71 22 60 58 20 86 25

47

97 27 14 62 50 56 54 42 12 59 48 93 24 16 61 10 68 0 40 89 88 75 1 65 39 64 5 52 55 66

74

79 69 57 91 36 73 9 28 98 2 96

84

13 44 37 17

85

90 53 29 8 92 38 32 70 80 77 33 51 7 23

Leach.out file (partly):


num_nodes is set 101
Creating sensor nodes...
0 1 2 3 4 5 6 7 8 96 97 98 99 (100 == BS)
Loading scenario file...
Node 0: (65.745973803916002,92.581722416254564)
Node 1: (21.008649990432268,92.380389195112684)

Node 98: (2.466682112993059,57.526273074339272)


Node 99: (44.071560420129238,10.71598111219517)
Max Distance for this Simulation is 139.0
..
1: *******************************************
1: Is a cluster head at time 0
THRESH = 0.050000000000000003

15: Is a cluster head at time 0


THRESH = 0.050000000000000003

0: Current cluster-head is 68, code is 7, dist is 19


1: Current cluster-head is 1, code is 2, dist is 139.0
2: Current cluster-head is 92, code is 5, dist is 19
3: Current cluster-head is 82, code is 1, dist is 16

BS Received data 35 , 1.1387320751706003 from 35 at time 1.1713648770937442


This represents data from nodes: 83 20 71 60 35
BS Received data 68 , 1.1387321208710139 from 68 at time 1.2118104283328113
This represents data from nodes: 62 22 14 0 68

BS Received data 58 , 564.86846018738038 from 58 at time 564.90285041584775


This represents data from nodes: 18 11 31 34 82
Node 82 is DEAD!!!!
At 565.20000000005996:
Total Energy = 351.31012201960863
Total Data = 56741
Total Alive = 4
Simulation complete.
Simulation complete.

5. Conclusion
In the three experiments, after adding the number of cluster header, the number of alive
nodes is increased and the number of transmitted data is decreased. After moving the BS
from inside to the border of field, the number of alive nodes is decreased and much more
data need to be transmitted.

6. References
[1] W. Heinzelman, A. Chandrakasan, and H. Balakrishnan, "Energy-efficient communication
protocol for wireless sensor networks," in the Proceeding of the Hawaii International
Conference System Sciences, Hawaii, January 2000.
*2+ MIT AMPS project ns2 code extensions.
http://www-mtl.mit.edu/research/icsystems/uamps/research/leach/leach_code.shtml
[3] Marc Greis' Tutorial for the UCB/LBNL/VINT Network Simulator "ns"
http://www.isi.edu/nsnam/ns/tutorial/

You might also like