You are on page 1of 150

.....................

6
...........................................................................................................................................................6
1.1 NS-2.....................................................................................................................................................6
1.2 OPNET................................................................................................................................................6
1.3 SensorSim...........................................................................................................................................6
1.4 EmStar................................................................................................................................................7
1.5 GloMoSim...........................................................................................................................................7
1.6 TOSSIM..............................................................................................................................................7
1.7 PowerTOSSIM...................................................................................................................................7

OMNET........................8
...........................................................................................................................................................8
2.1 OMNeT++..................................................................................................................................8
2.1.1 OMNeT++............................................................................................................................8
2.1.2 OMNeT++............................................................................................................................9
2.2 OMNeT++............................................................................................................................10
2.3 OMNeT++.................................................................................................................................11
2.3.1 NED ...................................................................................................................................11
2.3.1.1 NED ........................................................................................................................11
2.3.1.2 Ned ..................................................................................................................11
2.3.1.3 .....................................................................................................................................13
2.3.2 ....................................................................................................................................14
2.3.2.1 OMNET...................................................................................................14
2.3.2.2 .........................................................................................................................14
2.3.2.3 .....................................................................................................................15
2.3.2.4 .............................................................................................16
2.3.3 ............................................................................................................................................17
2.3.3.1 cMessage .....................................................................................................................17
2.3.3.2 .............................................................................................................................17

2.3.3.3 .........................................................................................................................17
2.3.4 ....................................................................................................18
2.3.4.1 .................................................................................................................18
2.3.4.2 .................................................................................................................19
2.3.4.3 .....................................................................................................................20
2.3.3.4 .........................................................................................................................20
2.4 ...........................................................................................................................................21
2.5 omnetpp.ini.....................................................................................................................22
2.6 ..................................................................................................................................22
2.6.1 Plove..............................................................................................................22
2.6.2 Scalar.....................................................................................................................22
2.7............................................................................................................................................23

...................24
3.1 UWB ............................................................................................................................24
3.1.1 UWB ..............................................................................................................24
3.1.2 UWB ......................................................................................................................24
3.1.3 UWB (,)......................................................................25
3.1.4 UWB ......................................................................................................................25
3.1.5 ................................................................27
3.2 OMNeT++ UWB ....................................................................................................28
3.2.1 ........................................................................................................................28
3.2.2 ........................................................................................................................30
3.2.3 ........................................................................................................................31
3.2.4 ............................................................................................................................43
3.2.5 ....................................................................................................................................43
.................................................................................................................................................44

MAC ............................44
.........................................................................................................................................................44
4.1 MAC ..........................................................................................45
4.1.1 ............................................................................................................................45
4.1.2 MAC ..................................................................................................................45
4.1.3 MAC ..................................................................................45

4.2 MAC ...........................................................................................................46


4.2.1 S-MAC [12]...........................................................................................................................46
4.2.2 T-MAC ...............................................................................................................................47
4.2.3 AC-MAC ............................................................................................................................48
4.3 MAC ...........................................................................................................48
4.3.1 D-MAC ..............................................................................................................................48
4.3.2 TRAMA .............................................................................................................................49
4.3.3 AI-LMAC ...........................................................................................................................49
4.4 MAC ...................................................................................................................49
4.4.1 SMACS/EAR .....................................................................................................................49
4.4.2 CDMA MAC ................................................................................................50
4.4.3 DCC-MAC..................................................................................................................................50
4.5 OMNeT++ MAC ...........................................................................................51
4.5.1 S-MAC ...................................................................................................................51
4.5.2 S-MAC ...................................................................................................................52
4.5.3 S-MAC ...................................................................................................................53
4.6 ...................................................................................................................................................63
.................................................................................................................................................63

..............................64
.........................................................................................................................................................64
5.1 .....................................................................................................65
5.1.1 ........................................................................................................65
5.1.2 ....................................................................................................66
5.1.3 ................................................................................................67
5.1.4 OMNET ........................................................................................................69
5.2 ................................................................................76
5.3 OMNET++........................................................................77
5.3.1 OMNET++[19].....................................................77
5.3.1.1 .....................................................................................................77
5.3.1.1.1 ..................................................................................................77
5.3.1.1.2 ..........................................................................78
5.3.2 ........................................................................................79
5.3.2.1 [28].................................................................................................................79
5.3.2.1.1 ..........................................................................................................................79

5.3.2.1.2 ..........................................................................................................................79
5.3.2.1.3 ..........................................................................................................................79
5.3.2.2 [29].........................................................................................................80
5.3.3 OMNET++.............................................................................................81
5.4 .....................................................................................................81
5.4.1 (Flooding)[32]...................................................................................................................82
5.4.2 (Directed DiffusionDD)[33]......................................................................................82
5.4.3 LEACH( Energy Adaptive Clustering Hierarchy)[34]..................................................................83
5.5. OMNET++......................................................................................................................84
5.5.1 ........................................................................................................................................84
5.5.2 gossiping ............................................................................................................................88
5.6 ...........................................................................................................................................90
.................................................................................................................................................90

..............................92
6.1 ..............................................................................................................92
6.1.1 ................................................................................................................92
6.1.1.1 .................................................................................................................92
6.1.1.2 .............................................................................................................93
6.1.2 ........................................................................................................................93
6.1.2.1 .............................................................................................................................93
6.1.2.2 .....................................................................................................................94
6.1.2.3 .............................................................................................................94
6.1.2.3.1 ..................................................................................................................94
6.1.2.3.2 ..............................................................................................................95
6.1.2.3.3 ......................................................................................................................95
6.1.2.3.4 ..........................................................................................................96
6.1.2.4 [37]......................................................................................................96
6.1.3 OMNET++ DVHop ...........................................................................97
6.1.3.1 DVHop ........................................................................................97
6.1.3.2 DVHop ....................................................................................................98
6.2 .........................................................................................................................................105
6.2.1 ..........................................................................................................................................105
6.2.1.1 wsn ............................................................................................106
6.2.1.2 wsn ................................................................................................106
6.2.1.3 wsn ........................................................................................107
6.2.2 wsn ...................................................................................................................108
6.2.2.1 ...................................................................................................................108
4

6.2.2.1.1 SenOs[5].....................................................................................................................108
6.2.2.2 ...................................................................................................................109
6.2.2.2.1 TopDisc .............................................................................................................109
6.2.2.3 .......................................................................................110
6.2.2.2.1 sympathy [42].....................................................................................................111
6.2.2.2.2 Agilla [7].............................................................................................................111
6.2.3 Omnet ..........................................................................................112
6.2.3.1 Wsn ..............................................................112
6.2.4 ..........................................................................................................................................116
6.3 OMNeT++....................................................................................116
6.3.1 ..........................................................................................................................116
6.3.1.1 ...................................................................116
6.3.1.2 ...........................................................................................116
6.3.1.3 ...............................................................................117
6.3.1.4 ...........................................................................117
6.3.1.5 ...............................................................119
6.3.1.6 ...........................................................................................................121
6.3.1.6.1 [20, 23, 24, 25]...................................................................................121
6.3.1.6.2 ............................................................................................................121
6.3.2 OMNeT++ ..........................................................................................................122
6.3.3 ..........................................................................................................................................128
...............................................................................................................................................129


............................................................................... 133
.......................................................................................................................................................133
7.1 ........................................................................................................................134
7.1.1 ..........................................................................................................134
7.1.1.1 Active Badge .............................................................................................................134
7.1.1.2 RADAR ....................................................................................................................134
7.1.1.3 Cricket ......................................................................................................................134
7.1.2 ..........................................................................................................135
7.1.2.1 .......................................................................................135
7.1.2.2 ...............................................................................................................135
7.2 OMNeT++................................................................................................136
7.2.1 MCLMonte Carlo Localization................................................................136
7.2.2 MCLMonte Carlo Localization OMNeT++.........................................................138
7.2.2.1 ...................................................................................................................138

7.2.2.2 ...........................................................................................................................141
7.3.............................................................................................................................145
...............................................................................................................................................145

()
(
) NS-2, OPNET, SensorSim, EmStar, OMNet++, G1oMoSim,
TOSSIM, PowerTOSSIM

1.1 NS-2
NS-2 (Network Simulator-2)
TCP
NS-2 OSI NS-2
C Network Animator (NAM)
NS-2 NS-2

NS-2

1.2 OPNET
OPNET OPNET


OPNET TCP/IP, 802.1 1 , 3G OPNET
TinyOS NesC
OPNET QoS

1.3 SensorSim
SensorSim NS-2 DSR 802.11 SensorSim
WINS SensorWare Tel SensorSim
WINS Mote
SensorSim

1.4 EmStar
EmStar iPAQ Liunx

EmSta: Linux
EmTOS EmStar TinyOS
EmStar

1.5 GloMoSim
GloMoSim (Global Mobile Information Systems Simulation Library )
OSI

APIs GIoMoSim Parsec


G1oMoSim

1.6 TOSSIM
TOSSIM (TinyOS mote simulator) TinyOS Motes bit
TOSSIM TinyOS NesC PC
Mote TOSSIM
TinyViz.TOSSIM

1.7 PowerTOSSIM
PowerTOSSIM TOSSIM MICA2
PowerTOSSIM

Omnet

Ethernet IEEE 802.11


TCP

ns-2
OMNeT++ ( Objective Modular Network Testbed in C++)

OMNeT++ Objective Modular Network TestBed in C++

OMNeT++
NS2OPNET JavaSim OMNeT++
OMNeT++
OMNeT3.3p1

2.1 OMNeT++
2.1.1 OMNeT++
OMNeT++ simulation kernel library,
Simnetwork description compiler, nedc
graphical network description editor,GNED
TkenvCmdenvPlove Scalar Sim
Sim Sim OMNeT++

(1)NED
NED
NED
GNED NED

(2)
OMNeT++OMNeT++
OMNeT++

OMNeT++ Tkenv Cmdenv


Tkenv Tkenv Tkenv
Tkenv
Tkenv

Cmdenv Cmdenv Cmdenv


Cmdenv

2.1.2 OMNeT++
(1) OMNeT++ 1 OMNeT++

1 5 5
(1) Sim
Sim main
Sim
(2)Sim

Sim
(3) Envirev Envir
ev
(4)Sim Envir Envir Envir
Envir

(5)Envir TkenvCmdenvEnvir TOmnetApp Tkenv

Cmdenv TOmnetApp main() Envir


Sim ev
TOmnetApp Envir TOmnetApp Tkenv Cmdenv

2.2 OMNeT++
OMNeT++:
a)
Linux
Unix
b)
c)
Win32 (NT4.0, Window 2000,XP)
windows
2.2 windows Visual C++ 7.0 Service Pack 6
Visual Studio 6.0

(1)www.omnetpp.org omnetpp-3.3-win32.exe
(2) vc vc8.0vc.7.0vc6.0
vc6.0 release gswin32c ghostscript
ps pdf
(3) vc6.0 bin
VCVARS32.BAT cmd

10

2.3 OMNeT++
OMNET++ ,
OMNET++ , OMNET++
ned(Network Discription,) C++OMNET++
NED,:
NED NED
C++ OMNET++ NEDC
.NED .cpp , C++

2.3.1 NED
2.3.1.1 NED
NED
/
.Ned .Ned
Ned C++NED
GNED

2.3.1.2 Ned
NED
(1)

D NED NED
NED
NED <path>

import "ethernet"; // imports ethernet.ned


(2)
delayerrordatarate

channel LeasedLine
delay 0.0018 // sec
error 1e-8
datarate 128000 // bit/sec
endchannel

11

(3)

simple SimpleModuleName
parameters:
//...
gates:
//...
endsimple

module CompoundModule
parameters:
//...
gates:
//...
submodules:
//...
connections:
//...
endmodule

(4)

NEDNED

network wirelessLAN: WirelessLAN


parameters:
numUsers=10,
httpTraffic=true,
ftpTraffic=true,
distanceFromHub=truncnormal(100,60);
endnetwork
wirelessLAN
wirelessHostwirelessHub

12

2OMNeT

2.3.1.3
NED
(1)C<math.h>exp( ),log( ),cos( ),floor( ),ceil( )
(2)uniform, exponential, normal
const
const
genertor0

13

(3)
C++ 0 1 2 3 4
double double C++
Define_Functionmacro

#include <omnetpp.h>
double average(double a, double b)
{
return (a+b)/2;
}
Define_Function(average, 2);
2average()2average()NED
module Compound
parameter: a,b;
submodules:
proc: Processor
parameters: av = average(a,b);
endmodule
double#include
Define OMNeT++ NED

2.3.2
2.3.2.1 OMNET




OMNET
cpu cpu
OMNETcMessage

OMNET++Csimtime_t

14

2.3.2.2
(1)

propagation delay (sec)


bit error rate (errors/bit)
data rate (bits/sec)

N
Pnobiterror = (1 ber)length

bits/second
3

3
Token Ring FDDI

2.3.2.3
(1) CSimpleModule
(2) define_Module() define_Module_Like()
a) simple module NED
NED SimpleModule NED
SimpleModule
b) SimpleModule CompondMoudule OMNeT
15


(3)

#include <omnetpp.h>
// module class declaration:
class SlidingWindow : public cSimpleModule
{
Module_Class_Members(SlidingWindow,cSimpleModule,8192)
//
virtual void activity();
};
// module type registration:
Define_Module( SlidingWindow );
// implementation of the module class:
void SlidingWindow::activity()
{
int windowSize = par("windowSize");
...
}
NED
// file: swp.ned
simple SlidingWindow
parameters:
windowSize: numeric const;
gates:
in: fromNet, fromUser;
out: toNet, toUser;
endsimple
(4)
Module_Class_Members(classname, baseclass, stacksize);
activity()
0 handleMessage()

2.3.2.4
(1) activity()

16k

(2)handleMessage()
16

a) message / event handleMessage()


b) initialize() wait()
receive()

c)SimpleModule stacksize 0

sendscheduleAtcancelEvent
scheduleAt
(3)Initialize()
FES(Future Event Set)

(4)Finish()
(FES )
initialize()

2.3.3
2.3.3.1 cMessage
cMessageOMNETCMessage
cMessage

a) string(const char *)Tkenv


:
cObject
b) 0OMNET

c)
d) 1(1ber)length
ber
e) FES

2.3.3.2
mypacket.msg

message MyPacket
{
fields:
int srcAddress;
int destAddress;
17

int hops = 32;


};
C Tkenv
reflection
mypacket.msg,
mypacket_m.hmypacket_m.ccmypacket_m.hMypacket C
field
(1) bool, char, short, int, long, unsigned short, unsigned int,
unsigned
long, double, stringstringcontst char *
(2) cObjectC

2.3.3.3
OMNeTmessage
(1)
send(cMessage *msg, const char *gateName, int index=0);
send(cMessage *msg, int gateId);
isBusy(); transmissionFinishes()
(2)
send()message
Why

(3)
a)Wait();send(msg,outgate);
b)sendDelayed(cMessage *msg, double delay, const char *gate_name, int
index);
c)sendDelayed(cMessage *msg, double delay, int gate_id);
d)
E.gsendDelayed(msg, 0.005, "outGate");
(4)
job

a)scheduleAt()
scheduleAt(absoluteTime, msg);
scheduleAt(simtime()+delta, msg);
b)
c)isSelfMessage()
timer
cMessage *timeoutEvent = new cMessage("timeout");
scheduleAt(simTime()+10.0, timeoutEvent);
18

//...
cMessage *msg = receive();
if (msg == timeoutEvent)
{
// timeout expired
}
else
{
// other message has arrived, timer can be cancelled now:
delete cancelEvent(timeoutEvent);// FES
}

2.3.4
2.3.4.1
cModule par()
cPar& delayPar = par("delay");
cPar
int numTasks = par("numTasks");
double processingDelay = par("processingDelay");

cPar& waitTime = par("waitTime");


for(;;)
{
//...
wait( (simtime_t)waitTime );
}
NED source ini wait_time

par("waitTime") = 0.12;
Or:
cPar& waitTime = par("waitTime");
waitTime = 0.12;

2.3.4.2
1
OMNET++
19


gates [ ] 0

simple NetworkInterface
parameters: //...
gates:
in: fromPort, fromHigherLayer;
out: toPort, toHigherLayer;
endsimple
simple RoutingUnit
parameters: //...
gates:
in: output[];
out: input[];
endsimple
(2)

for

node1.outGate --> node2.inGate;


NED
node1.outGate --> error 1e-9 delay 0.001 --> node2.inGate;

for

for i=0..4 do
node1.outGate[i] --> node2[i].inGate
endfor;
4

4
20

2.3.4.3
isBusy()
transmissionFinishes()
cMessage *packet = new cMessage("DATA");
packet->setByteLength(1024); // 1K
if (gate("TxGate")->isBusy()) // if gate is busy, wait until it
{ // becomes free
wait( gate("TxGate")->transmissionFinishes() - simTime());
}
send( packet, "TxGate");

if (gate("mygate")->toGate()->isBusy())

2.3.3.4
isConnected()toGate()
fromGate()
cGate *gate = gate("somegate");
if (gate->isConnected())
{
cGate *othergate = (gate->type()==O) ?gate->toGate() : gate>fromGate();
ev << "gate is connected to: " << othergate->fullPath() << endl;
}
else
{
ev << "gate not connected" << endl;
}

cGate *gate = gate("out");


while (gate->toGate()!=NULL)
{
gate = gate->toGate();
}
cModule *destmod = gate->ownerModule();
sourceGate() and destination-Gate()

21

2.4
OMNET++
omnetpp.ini

vector scalar
OMNET Plove GUI vector
OMNET Matlab
Octave OpenOffice CalcGnumeric MS Excel

nedtool *.ned ned _n.cc

opp_msgc *.msg*.msg _m.h _m.cc

opp_nmakemake -f -e cccpp cccpp


cc cpp
Makefile.vc

nmake -f Makefile.vc

2.5 omnetpp.ini

General
, Run 2.
Run 1

22

CmdenvCmdenv
TkenvTkenv
parametersNED
OutVectors

2.6
2.6.1 Plove
Plove
PloveOMNET++

windows
,
Plove.ploverc

Plove
(.vev)
PLOT
windowsshift+ctrl+/

Options

(Plove)

2.6.2 Scalar

recordScalar()finish()

void EtherMAC::finish()
{
double t = simTime();
if (t==0) return;
recordScalar("simulated time", t);
.
}

23

(,omnetpp.sca)
run 1 "lan"
scalar "lan.hostA.mac" "simulated time" 120.249243
scalar ..

run 2 "lan"
scalar "lan.hostA.mac" "simulated time" 235.678665
[...]
recordScalar()scalar
----x-y

2.7
OMNeT++
OMNeT++
OMNeT++

OMNeT++
OMNeT++
OMNeT++
OMNeT++
OMNeT++/

C++ omnetpp.ini

OMNeT++ 802.11 MAC Directed Diffusion


3.1 UWB
3.1.1 UWB

24

FCC UWB UWB

UWB

3.1.2 UWB
500MHz 25
125 1
UWB

fH fL

fH fL
2

fH fL
f fL
( H
)
2

0.200.25
""""
RF

IR 10 0 1
0.1 1.5 Hz
GHz 10GHz

UWB

UWB
0 1
25

1/100UWB

IEEE802.11a
Bluetooth
UWB
54Mbps

1Mbps

500Mbps

10m-100m

10m

1 -100

10m
1

3.1.3 UWB (,)


UWB
f (t )

1
2 2

t2
2 2

[10],[11]

3.1.4 UWB
A UWB DSUWB
B THUWB
C
[1] TH-PPM
TH-PAM +
PPM
PPM [10][11]).
TH+PAM

26

T f N h
N h =7 Tc T f = Tc N h
N s N s =4
A T f
A TH {0 1 5 3} A
0 PAM
-1 1
5 3 +1+1 -1
A {-1 +1 +1 -1}
N i
[1]

Pi g ii
Ri ( i 2T f

P g

j 1, j i

ij

1.1

N .
T f
Ri i
g ij j i .
i i .
2 UWB
N s T f
Tb = T f N s ,

27

Ri =

. Pi

1
Tb

1.2

E m ,i
E m ,i
E E frame

t
T frame
Tf
Tf

1.3

E frame i E m ,i i
i T f
. T f N h Tc

3.1.5
MEI
ad-hoc .

UWB UWB

FCC
(MEI)
QoS
. i i
T

1.1 MEI

iT

Pi g ii
Ri ( i 2T f

P g

j 1, j i

ij

2T f M i )

1.4

i , Ri
T

M i
N ,
M i
( N+1 )
M i 1 i N . N+1 N 1
T

R N 1 ,

28

NT 1

PN 1 g N 1, N 1
R N 1 ( N 1 2T f

P g
j 1

N 1, j

1.5

Ri ,

NT 1 R N 1 ( N 1 2T f
PN 1

P g
j

j 1

N 1, j

1.6

g N 1, N 1

, N
, N+1 ,
N+1
min{

Mi
} 1 i N
g i , N 1

FCC N+1
Pmax min{PFCC , min{

Mi
}}
g i , N 1

1 i N

PN 1 Pmax
PN 1 Pmax

time out N+1


,
PN 1 = Pmax N+1 Pmax
PN 1 < Pmax Popt { PN 1 , Pmax } Popt
[1] MEI
Popt

PN 1 Pmax
.
2

3.2 OMNeT++ UWB


3.2.1
OMNeT
doc/ usman
UWB UWB

29

1
message
powerMsg

30

3.2.2

1. RX
2.
Pmax
3. RX Pmin 4
4. PminPmax
5 1

5. Popt RX
6.

1. TX
2 1
2. Pmin
TX
3. TX 4 1
4.

31

TX

RX

TX

Yes

Yes
RX

Pmin
TX
Pmax

Time out

RX
Pmin

TX

Yes

Time out

Yes

PminPmax
Yes

Popt RX

3.2.3
UWB

message powerMsg

powerMsg
32


message powerMsg
{
fields:
double txPower;
double rxWantMinpower;
double MEI;
int sourceNodeIndex;
int destintNodeIndex; // -1 .
int x; // x,y
int y;
bool wantCommWithYou=false;
bool linkSucessToCreat=false; // link true
}
msg powerMsg_m.h
powerMsg_m.cc

#include <omnetpp.h>
#include "powerMsg_m.h"
class Physic :public cSimpleModule
{
private:
double initxPower;
double commonPower; //
double deviceMaxpower;
double myMEI;
double mySIR;
double myLinkGain;
double requireRate;
double totoalInterferenc;
double backnoise;
double shapingFactor;
double tagetSIR;
double Tf;
int posX, posY;
int targetNodeIndex;
int sourceNodeIndex;
bool isBusy;
cArray txpmsgArray;
cArray rxpmsgArray;
public:
33

double getDistance(powerMsg * pmsg);


double getGain(powerMsg *pmsg);
double getInterference();
double getSIR();
double getmyMEI(double tSIR);
void sendmyMEI();
void sendIniPmsg(int targetNodeIndex);
double maxPower();
double minPower();
double resetPower();
virtual void initialize();
virtual void handleMessage(cMessage * msg);
virtual void finish();
};

#include "Physic.h"
Define_Module(Physic);
void Physic::initialize()
{
//( node x,y )
posX=(int)parentModule()->par("x");
posY=(int)parentModule()->par("y");
txpmsgArray.setName("txpmsgList");
rxpmsgArray.setName("rxpmsgList");
isBusy=false;
myLinkGain=0.0;
initxPower=0.0;
//
commonPower=1.0;
deviceMaxpower=2.0;
requireRate=1.4e6;
backnoise=4.0e-18;
shapingFactor=1.99e-3;
tagetSIR=10.0;
Tf=1.0e-7;
ev<<"the node's Physic layer... is initializing....the node is "<<parentModule()>index()<<endl;
ev<<"send a msg to MAC"<<endl;
// Msg MAC
cMessage *toMacmsg=new cMessage("toMAC");
send(toMacmsg,"toMAC");
34

//
if(((parentModule()->index())%2)==0)
{
ev<<"the node "<< parentModule()->index()<<" is initializing.... and want to
send a selfMsg..."<<endl;
simtime_t waittime=(simtime_t)uniform(0.10,3.0);
cMessage *smsg=new cMessage("selfMsg");
scheduleAt(simTime()+waittime,smsg);
ev<<"self msg had send..."<<endl;
isBusy=true;
}
}

// cMessage
void Physic:: handleMessage(cMessage * msg)
{
if (msg->isSelfMessage())
{
// selfMsg
delete msg;
int a=genk_intrand(0,11);
while((a%2)==0)
{
a=genk_intrand(0,11);
}
bool aIsBusy=false;
for (int i=0;i<rxpmsgArray.items();i++)
{
powerMsg *pmsgs=(powerMsg *)rxpmsgArray[i];
if(pmsgs->getSourceNodeIndex()==a)
{
aIsBusy=true;
ev<<" the node a is now receiving ,choose a new one "<<endl;
break;
}
}
if(aIsBusy)
{
ev<<"the node "<< parentModule()->index()<<" is initializing.... and want
to send a selfMsg..."<<endl;
ev<<"but the destination node is busy...choosing aother one ....."<<endl;
35

cMessage *smsg=new cMessage("selfMsg");


scheduleAt(simTime(),smsg);
ev<<"self msg had send..."<<endl;
isBusy=true;
}
else
{
ev<<"I am the node "<<parentModule()->index()<<" the self msg had
arrived...."<<endl;
ev<<" and i want to comunicate with the node "<<a<<" and send a msg
to him...... "<<endl;
sendIniPmsg(a);
isBusy=true;
}
}
else if (strcmp(msg->name(),"txpowerMsg")==0)
{
powerMsg *pmsg=(powerMsg *)msg;
ev<<" a txpowerMsg is arriving from the node
"<<pmsg>getSourceNodeIndex()<<endl;
ev<<"convert to pMsg.....I am the node "<<parentModule()->index()<<endl;
if
((pmsg->getWantCommWithYou())&&((pmsg>getDestintNodeIndex())==(parentModule()->index())))
{
if (!isBusy) {
if(pmsg->getLinkSucessToCreat())
//
{
ev<<"I am the node "<<parentModule()->index()<<" an the
link is sucess to creat.."<<endl;
powerMsg *minpmsg=new powerMsg("rxpowerMsg");
minpmsg->setSourceNodeIndex(parentModule()->index());
minpmsg->setDestintNodeIndex(-1); // MEI
minpmsg->setWantCommWithYou(false);
myLinkGain=getGain(pmsg);
initxPower=pmsg->getTxPower();
myMEI=getmyMEI(tagetSIR);
minpmsg->setMEI(myMEI);
minpmsg->setLinkSucessToCreat(true);
minpmsg->setX(posX);
minpmsg->setY(posY);
isBusy=true;
36

for(int i=0;i<11;i++)
{
powerMsg *copypmsg= (powerMsg *)minpmsg->dup();
send(copypmsg,"toOutside",i);
}
bubble("I have broadcasted my MEI...");
ev<<"I am the node .."<<parentModule()->index()<<"I have
broadcasted my MEI..."<<endl;
if(isBusy)
{
// link MEI
myMEI=getmyMEI(tagetSIR);
ev<<" In my life
I am Broadcasting........my MEI
is :"<<myMEI<<endl;
powerMsg *minpmsg=new powerMsg("rxpowerMsg");
minpmsg->setSourceNodeIndex(parentModule()->index());
minpmsg->setDestintNodeIndex(-1); // MEI
minpmsg->setWantCommWithYou(false);
minpmsg->setMEI(myMEI);
minpmsg->setLinkSucessToCreat(true);
minpmsg->setX(posX);
minpmsg->setY(posY);
for(int i=0;i<11;i++)
{
powerMsg *copypmsg= (powerMsg *)minpmsg->dup();
send(copypmsg,"toOutside",i);
}
}
}
else
{
myLinkGain=getGain(pmsg);
double minipower=minPower();
ev<<"I am the node "<<parentModule()->index()<<" computing the
min power is OK!!"<<endl;
ev<<"the min power is .."<<minipower<<endl;
powerMsg *minpmsg=new powerMsg("rxpowerMsg");
minpmsg->setSourceNodeIndex(parentModule()->index());
minpmsg->setRxWantMinpower(minipower);
minpmsg->setDestintNodeIndex(pmsg->getSourceNodeIndex());
minpmsg->setWantCommWithYou(true);
minpmsg->setX(posX);
minpmsg->setY(posY);
37

for(int i=0;i<10;i++)
{
powerMsg *copypmsg= (powerMsg *)minpmsg->dup();
send(copypmsg,"toOutside",i);
}
send(minpmsg,"toOutside",10); //
}
}
}
else
if(
((pmsg->getDestintNodeIndex())!=(parentModule()>index()))&&(pmsg->getLinkSucessToCreat()))
{
bool haveOldmsg;
haveOldmsg=false;
for (int i=0;i<txpmsgArray.items();i++)
{
powerMsg *pmsgs=(powerMsg *)txpmsgArray[i];
if(pmsgs->getSourceNodeIndex()==pmsg->getSourceNodeIndex())
{
haveOldmsg=true;
delete txpmsgArray.remove(i);
int index =txpmsgArray.add(pmsg);
break;
}
}
if(!haveOldmsg)
int indexs=txpmsgArray.add(pmsg);
}
}
else
{
delete pmsg;
ev<<"I am the node "<<parentModule()->index()<<"I receive a
msg which is usefulless ....deleting it"<<endl;
}
}
else if (strcmp(msg->name(),"rxpowerMsg")==0)
{
powerMsg *pmsg=(powerMsg *)msg;
ev<<"convert to pMsg....."<<endl;
38

if
((pmsg->getWantCommWithYou())&&((pmsg>getDestintNodeIndex())==(parentModule()->index())))
{
// rx , power.
double rxminpower=pmsg->getRxWantMinpower();
ev<<"my min power is :"<<rxminpower<<endl;
double txmaxpower=maxPower();
if (rxminpower>txmaxpower)
{
isBusy=false;
while(!isBusy)
{
ev<<"the node "<< parentModule()->index()<<" re transmiting is
want to send a selfMsg..."<<endl;
simtime_t waittime=(simtime_t)uniform(0.10,3.0);
cMessage *smsg=new cMessage("selfMsg");
scheduleAt(simTime()+waittime,smsg);
ev<<"self msg had send..."<<endl;
}
}
else
{
initxPower=(txmaxpower+rxminpower)/2;
isBusy=true;
powerMsg *txpmsg=new powerMsg("txpowerMsg");
ev<<"I am the node "<<parentModule()->index()<<"sucees to
contruct a new link ..."<<endl;
ev<<"the link is :"<<parentModule()->index()<<"--->>"<<pmsg>getSourceNodeIndex()<<endl;
txpmsg->setTxPower(initxPower);
txpmsg->setSourceNodeIndex(parentModule()->index());
txpmsg->setDestintNodeIndex(pmsg->getSourceNodeIndex());
txpmsg->setX(posX);
txpmsg->setY(posY);
txpmsg->setWantCommWithYou(true);
txpmsg->setLinkSucessToCreat(true);
for(int i=0;i<10;i++)
{
powerMsg *copypmsg= (powerMsg *)txpmsg->dup();
send(copypmsg,"toOutside",i);
}
39

send(txpmsg,"toOutside",10);
bubble("I have broadcasted my ini power...");
while(isBusy)
{
powerMsg *txpmsg=new powerMsg("txpowerMsg");
txpmsg->setTxPower(initxPower);
txpmsg->setSourceNodeIndex(parentModule()->index());
txpmsg->setDestintNodeIndex(pmsg->getSourceNodeIndex());
txpmsg->setX(posX);
txpmsg->setY(posY);
txpmsg->setWantCommWithYou(true);
txpmsg->setLinkSucessToCreat(true);
for(int i=0;i<10;i++)
{
powerMsg *copypmsg= (powerMsg *)txpmsg->dup();
send(copypmsg,"toOutside",i);
}
send(txpmsg,"toOutside",10);
}
}
}
else
if((pmsg->getDestintNodeIndex()==-1)&&(pmsg>getLinkSucessToCreat()))
{
bool haveOldmsg;
haveOldmsg=false;
for (int i=0;i<rxpmsgArray.items();i++)
{
powerMsg *pmsgs=(powerMsg *)rxpmsgArray[i];
if(pmsgs->getSourceNodeIndex()==pmsg->getSourceNodeIndex())
//, msg
{
haveOldmsg=true;
delete rxpmsgArray.remove(i);
int index =rxpmsgArray.add(pmsg);
ev<<" there is an old one in the rxArray....delete it and add the new
one"<<endl;
//ev<<"the
old
one
is
from....node
..."<<pmsgs>getSourceNodeIndex();
break;
}
}
40

if(!haveOldmsg)
int index=rxpmsgArray.add(pmsg);
}
else
{
ev<<"I am the node "<<parentModule()->index()<<"I receive a msg which
is usefulless ....deleting it"<<endl;
delete pmsg;
}
}
else
{
// msg
send(msg,"toMAC");
}
}

// Msg
void Physic::sendIniPmsg(int targetindex)
{
powerMsg *pmsg=new powerMsg("txpowerMsg");
pmsg->setTxPower(commonPower);
pmsg->setX(posX);
pmsg->setY(posY);
pmsg->setWantCommWithYou(true);
pmsg->setSourceNodeIndex( parentModule()->index() );
pmsg->setDestintNodeIndex(targetindex);
for(int i=0;i<10;i++)
{
powerMsg *copypmsg= (powerMsg *)pmsg->dup();
send(copypmsg,"toOutside",i);
ev<<"broakcasting the initial msg to other node from the gate
toOuside["<<i<<"]"<<endl;
}
send(pmsg,"toOutside",10);
}
//
double Physic::getDistance(powerMsg * pmsg)
{
double distant=sqrt((posX-pmsg->getX())*(posX-pmsg->getX())+(posY-pmsg>getY())*(posY-pmsg->getY()));
41

return distant;
}
//
double Physic::getGain(powerMsg *pmsg)
{
double gain;
double dist=getDistance(pmsg);
if(dist<35)
{
gain=1;
}
gain=1225/(dist*dist);
return gain;
}
//
double Physic::getInterference()
{
double totleNiose=0.0;
for (int i=0;i<txpmsgArray.items();i++) {
powerMsg *pmsg=(powerMsg *)txpmsgArray[i];
if ((pmsg->getSourceNodeIndex() )!=(parentModule()->index()))
{
double gains=getGain(pmsg);
totleNiose+=(pmsg->getTxPower())*gains;
}
}
return totleNiose;
}
double Physic::getSIR()
{
double mylinkgain, sourcepower;
for (int i=0;i<txpmsgArray.items();i++)
{
powerMsg *apmsg=(powerMsg *)txpmsgArray[i];
if ((apmsg->getSourceNodeIndex() )==(parentModule()->index()))
{
mylinkgain=getGain(apmsg);
sourcepower=apmsg->getTxPower();
break;
}
42

}
// SIR
double interfere=getInterference();
double
theSIR=(mylinkgain*sourcepower)/
(requireRate*(backnoise+shapingFactor*Tf*interfere));
return theSIR;
}
// MEI
double Physic::getmyMEI(double tSIR)
{
double interfere=getInterference();
double xixi=tSIR*requireRate*shapingFactor*Tf;
double
myMei=(initxPower*myLinkGain-tSIR*requireRate*backnoisexixi*interfere)/(xixi);
return myMei;
}

//
double Physic::maxPower()
{
double thetxPower;
double maxpower=1000.0;
for (int i=0;i<rxpmsgArray.items();i++)
{
powerMsg *pmsgs=(powerMsg *)rxpmsgArray[i];
double gain=getGain(pmsgs);
if (((pmsgs->getMEI())/gain)<maxpower)
maxpower=(pmsgs->getMEI())/gain;
}
if(maxpower>(deviceMaxpower))
maxpower= deviceMaxpower;
return maxpower;
}
//
double Physic::minPower()
{
double intf=getInterference();
double
minpowers=(tagetSIR*requireRate*(shapingFactor*intf*Tf+backnoise))/
myLinkGain;
43

return minpowers;
}
void Physic::finish()
{
ev<<"finish..."<<endl;
}

3.2.4
UWB
UWB

UWB

3.2.5
UWB
Gbps UWB 3
480Mbps 5 80Mbps 2007
UWB

UWB
UWB

PDA

UWB

[1] Francesca Cuomo, Cristina Martello. Ultra Wide Band WLANS:A SelfConfiguring Resource Control Scheme for Accessing UWB Hot-Spots with QoS
Guarantees
[2] Michael I. Brownfield, Kaveh Mehrjoo, Almohonad S. Fayez, and Nathaniel J.
Davis IV, Wireless Sensor Network Energy-Adaptive MAC Protocol
[3] Jerey P. Monks, Vaduvur Bharghavan, and Wen-mei W. Hwu, A Power
Controlled Multiple Access Protocol for Wireless Packet Networks
[4] F. Cuomo, C. Martello, A. Baiocchi, and F. Capriotti, Radio Resource
Sharing for Ad Hoc Networking with UWB, IEEE Journal on Selected Areas in
44

Communications, Vol. 20, No. 9,pp. 17221732, December 2002.


[5] MARIA-GABRIELLA DI BENEDETTO, LUCA DE NARDIS, MATTHIAS JUNK and GUERINO
GIANCOLAUWB2: Uncoordinated, Wireless, Baseborn Medium Access for UWB
Communication Network
[6] Jean-Yves Le Boudec, Ruben Merz, Boidar Radunovi c, Jrg Widmer ,DCC-MAC
A Decentralized MAC Protocol for 802.15.4a-like UWB Mobile Ad-Hoc Networks
Based on Dynamic Channel Coding
[7] Tomaso Erseghe, Nicola Laurenti, Pietro Nicoletti, and Andrea Sivier, An
Algorithm for Radio Resource Management in UWB Ad Hoc Networks with Concurrent
Guaranteed QoS and Best Effort Trafc
[8] Vipin Mehta, Magda El Zarki, An Ultra Wide Band (UWB) based Sensor Network
for Civil Infrastructure Health Monitoring
[9] N.Boubaker , K.B.Letaidf, Performance Analysis of DS-UWB Multiple Access
Under Imperfect Power Control
[10]Maria-Gabriella, Di Benedetto, Guerino Giancola , .
. : , 2005.
[11] ,..2005.8

MAC

(medium access control)MAC

MAC
Ad Hoc MAC
GSM CDMA QoS
Ad Hoc
QoS
MAC MAC
MAC

4.1 MAC
4.1.1
,,
1aA
BB
CAB

45

AB

1bABC
CBA
CBABC

4.1.2 MAC
MAC ,,
,,MAC
,MAC
,
,,
,
,
,,
,,
,,
,,,
,,

4.1.3 MAC
MAC

3MAC

MACMAC

46

4.2 MAC
4.2.1 S-MAC [12]
S-MAC [1] 802.11MAC
MAC
S-MAC /

S-MAC
1

/
SYNC

S-MAC

2
S-MAC

RTS
RTS

3
S-MAC 802.11MAC
RTS/CTS SMAC
RTS/CTS/DATA/ACK

47

4
S-MAC RTS/CTS
S-MAC

IEEE802.11MAC S-MAC RTS/CTS

IEEE802.11MAC
RTS/CTS

S-MAC /
RTS/CTS
S-MAC

4.2.2 T-MAC
T-MACTimeout MAC[2]S-MAC S-MAC
/

T-MAC
T-MAC
S-MAC
T-MAC RTS/CTS/DATA/ACK
TA
;;RSSI ;
RTS/CTS
T-MAC

48

4.2.3 AC-MAC
AC-MAC [3] MAC T-MAC
AC-MAC S-MAC
S-MAC
AC-MAC MAC
S-MAC
AC-MAC
MAC i Ni RifNi
Ri f
'
'
T frame
TRTS / CTS Tsleep

TRTS / CTS Tsleep


Ri

S-MAC R RTS/CTS
R .
AC-MAC S-MC S-MAC

T-MAC

4.3 MAC
4.3.1 D-MAC
S-MAC T-MAC /

DMAC[4]

S-MAC D-MAC RTS/CTS


(BP)
(SP) ACK
= BP+CW+DATA+SP+ACK
D-MAC slot-by-slot
MAC D-MAC
DMAC more-to-send
D-MAC S-MAC

49

4.3.2 TRAMA
TRAMA[5]

TRAMA
TDMA
MAC TRAMA

4.3.3 AI-LMAC
AI-LMAC(adaptive,information centric and lightweightMAC)TDMA
MAC [6]AI-LMAC
(sink )

( time slot)
)(bit )

(controlmessageCM)(data messageDM)CM DM

AI-LMAC
/DDT (data
distribution table)
AI-LMAC

4.4 MAC
4.4.1 SMACS/EAR
SMACS/EARSelf-organizing Medium Access Control/Eavesdrop And Register
MAC

SMACSEAR
SMACS/EAR

[7]

50

4.4.2 CDMA MAC


CDMA CDMA
CDMA
[8]CDMA
MAC

//
/
/
/
CDMA MAC
CDMA

4.4.3 DCC-MAC
DCC-MAC [9]
CDMA DCC-MAC[4] PPM-TH-UWB [10]TH
MAC
IEEE 802.15.4a[11]PRP

THS UWB
MACPrivate MAC
public THS
private THS S
D D D THS S
D D THS REQ
REQ RN D
RESP, RN. S RESP
THS 2DCC-MAC
THS

2 DCC-MAC

51

4.5 OMNeT++ MAC


MAC Simulator TU Delft Consensus
MAC OMNeT++ version 0.2.2
OMNeT++http://www.omnetpp.org/article.php?story=200510251304406
MAC Simulator TU Delft Consensus

MAC
Simulator
http://www.consensus.tudelft.nl/software.html
MAC Simulator Linux Windows
Windows OMNeT++
MAC Simulator S-MACT-MACTMACpL-MACCSMACSMAACK MAC
MAC
S-MAC

4.5.1 S-MAC
Windows MAC Simulator
nedtool *.ned opp_msgc *.msg opp_nmakemake f e cc nmake f
Makefile.vc S-MAC
3

52

3 S-MAC

4.5.2 S-MAC
S-MAC 4

53

4 S-MAC

4.5.3 S-MAC
S-MAC BasicMac BasicMac cSimpleModule
S-MAC S-MAC
class SMac: public BasicMac
{
//
Module_Class_Members(SMac, BasicMac, 0);
protected:
unsigned int listen_time;

54

unsigned int sleep_time;


unsigned int frame_time;
ushort sched_table[10]; //
int sched_count;
SchedStates sched_state;
ushort time_last_sched; //
ProtoState proto_state;
ProtoState proto_next_state;
int nav_state;
ushort nav_end_time;
int must_send_sync;
int resync_counter;
Packet * tx_msg;
int rts_contend_time;
int cts_to;
ushort cts_nav_end;
ushort cts_nav_rcv;
ushort cts_nav_t;
int ack_to;
int ack_serial;
int my_serial;
void setMySchedule(ushort time); //
void evalState(); //
void startContending(int time); //
void sendSync(); //
void sendRts();
void sendCts();
void sendData();
void sendAck();
void receiveSync(Packet * msg);
//
void receiveRts(Packet * msg);
void receiveCts(Packet * msg);
void receiveData(Packet * msg);
void receiveAck(Packet * msg);
void adoptSchedule(int offset); //
void calcSchedState();
//
55

void setIdle();
void protocolTimeout();
void navTimeout();
void schedTimeout();
void setProtocolTimeout(int t);
void setNavTimeout(int t);
void setSchedTimeout(int t);
void updateNav(ushort nav);
void txDone();
virtual void endForce();
int isSameSchedule(int time1, int time2);
virtual int mustUseCA(Packet * msg);
//virtual void incBackoff();
virtual void decBackoff();
virtual void init();
virtual void timeout(int which);
virtual void txPacket(Packet * msg);
virtual void rxFrame(Packet * msg);
virtual void transmitDone();
virtual void rxFailed();
virtual void rxStarted();
virtual int headerLength();
};
S-MAC

void SMac::setMySchedule(ushort time)


{
// <time>, <time>-<frame_time>
assert(time < frame_time);
time_last_sched = currentTime() + time - frame_time; //
must_send_sync = 1;
resync_counter = NEW_RESYNC_COUNTER;
printf(PRINT_MAC, "schedule: %d", time_last_sched % frame_time);
calcSchedState();
}

56

void SMac::evalState()
{
if (proto_state == PROTO_STATE_IDLE && !isReceiving())
{
//
if (nav_state == NAV_STATE_CLEAR && sched_state !=CHED_STATE_SLEEP)
{
// /
if (must_send_sync)
{
printf(PRINT_MAC, "preparing to send SYNC %s",tx_msg?"(data
pending)":"");
//
proto_next_state = PROTO_STATE_SEND_SYNC;
startContending(SYNC_CONTEND_TIME);
return;
}
if (tx_msg && sched_state == SCHED_STATE_OWN)
{
if (mustUseCA(tx_msg)) //
{
printf(PRINT_MAC, "preparing to send RTS");
//
proto_next_state = PROTO_STATE_SEND_RTS;
startContending(rts_contend_time);
}
else
{
printf(PRINT_MAC, "preparing to send data");
proto_next_state = PROTO_STATE_SEND_DATA;
startContending(RTS_CONTEND_TIME);
}
return;
}
//
printf(PRINT_MAC, "idle listening");
setRadioListen();
}
else
{
//
printf(PRINT_MAC, "idle sleeping");
if (getForce() != FORCE_NOSLEEP)
57

setRadioSleep();
}
}
}

void SMac::startContending(int time)


{
assert(proto_next_state >= 0);
assert(time >= 5);
if (nav_state == NAV_STATE_BUSY)
{
printf(PRINT_MAC, "contend: skipping because nav is busy");
proto_next_state = PROTO_STATE_INVALID;
setIdle();
}
else
{
proto_state = PROTO_STATE_CONTEND;
int ctime = (int) intuniform(5, time);
printf(PRINT_MAC, "starting contention, will fire in %d", ctime);
setRadioListen();
setProtocolTimeout(ctime);
}
}

void SMac::rxFrame(Packet * msg)


{
assert(msg);
if (sched_state == SCHED_STATE_SLEEP && getForce()!=FORCE_NOSLEEP)
return; //
if (proto_state == PROTO_STATE_WFCTS && (PKT_KIND(msg) != KIND_CTS ||
msg->local_to != nodeId()))
{
printf(PRINT_MAC, "received packet, but not cts we want");
cancelTimeout(TIMER_PROTOCOL);
proto_state = PROTO_STATE_IDLE;
}
if (proto_state == PROTO_STATE_WFACK && (PKT_KIND(msg) != KIND_ACK ||
msg->local_to != nodeId() || PKT_SERIAL(msg) != my_serial))
{
58

printf(PRINT_MAC, "received packet, but not ack we want");


cancelTimeout(TIMER_PROTOCOL);
proto_state = PROTO_STATE_IDLE;
}
assert(sched_state != SCHED_STATE_SLEEP || getForce() == FORCE_NOSLEEP);
switch (PKT_KIND(msg))
{
case KIND_SYNC:
receiveSync(msg);
break;
case KIND_RTS:
receiveRts(msg);
break;
case KIND_CTS:
receiveCts(msg);
break;
case KIND_DATA:
receiveData(msg);
break;
case KIND_ACK:
receiveAck(msg);
break;
default:
assert(false);
}
evalState();
}

void SMac::protocolTimeout()
{
int next_state;
switch (proto_state)
{
case PROTO_STATE_CONTEND:
assert(proto_next_state >= 0);
assert(!isReceiving());
assert(nav_state == NAV_STATE_CLEAR);
// RSSI
setRadioListen(); //
if(getRssi()>0.5) { //
printf(PRINT_MAC,
59

"sensed communication, cancelling");


setIdle();
return;
}
//
next_state = proto_next_state;
proto_next_state = PROTO_STATE_INVALID;
switch (next_state)
{
case PROTO_STATE_SEND_SYNC:
sendSync();
break;
case PROTO_STATE_SEND_RTS:
sendRts();
break;
case PROTO_STATE_SEND_CTS:
sendCts();
break;
case PROTO_STATE_SEND_DATA:
sendData();
break;
case PROTO_STATE_SEND_ACK:
sendAck();
break;
default:
assert(false);
}
break;
case PROTO_STATE_WFCTS:
printf(PRINT_MAC, "wait-for-cts timeout");
setIdle();
break;
case PROTO_STATE_WFDATA:
printf(PRINT_MAC, "wait-for-data timeout");
setIdle();
break;
case PROTO_STATE_WFACK:
printf(PRINT_MAC, "wait-for-ack timeout");
setIdle();
break;
default:
assert(false);
60

}
}

void SMac::sendSync()
{
printf(PRINT_MAC, "sending sync");
must_send_sync = 0;
proto_state = PROTO_STATE_SEND_SYNC;
Packet *msg = new Packet("sync");
msg->local_from = nodeId();
msg->local_to = -1; //-1
PKT_KIND(msg) = KIND_SYNC;
ushort now = currentTime();
unsigned long est = EST_SYNC_TIME;
assert(time_last_sched+(int)frame_time > now+EST_SYNC_TIME);
unsigned long stime = time_last_sched + frame_time //
- now
//
- est;
//
//- EST_SYNC_TIME;
//
//assert(now>900);
assert(stime>0);
stime &= 0xFFFF;
assert(stime < frame_time);
PKT_SYNC(msg) = stime;
msg->setLength(SYNC_SIZE);
setRadioTransmit();
reg_tx_overhead(msg);
startTransmit(msg);
}

void SMac::receiveSync(Packet * msg)


{
assert(msg);
reg_rx_overhead(msg);
ushort stime = (ushort) PKT_SYNC(msg);
delete msg;
if (sched_state == SCHED_STATE_STARTUP)
{
cancelTimeout(TIMER_SCHED);
61

printf(PRINT_MAC, "received SYNC, following");


setMySchedule(stime);
return;
}
//
int ftime = (int)currentTime() + stime; //
if (isSameSchedule(ftime, time_last_sched))
{
printf(PRINT_MAC, "received SYNC, my own schedule");
return;
}
//
int i;
for (i = 0; i < sched_count; i++)
{
if (isSameSchedule(ftime, time_last_sched + sched_table[i]))
{
printf(PRINT_MAC, "received SYNC, known schedule");
return;
}
}
//
printf(PRINT_MAC, "adopting foreign schedule");
int offset = ftime - time_last_sched;
if (offset < 0)
offset += 65536;
offset %= frame_time;
assert(offset > 0);
//assert(offset < (int)frame_time);
adoptSchedule(offset);
}

void SMac::calcSchedState()
{
ushort t = currentTime();
unsigned in_f = (ushort) (t - time_last_sched);
assert(listen_time>0);
//
if ( /*in_f >=0 && */ in_f < listen_time)
{
sched_state = SCHED_STATE_OWN;
ushort left = listen_time + 5 - in_f;
62

assert(left <= listen_time + 5);


printf(PRINT_MAC, "calc_sched: in own frame, left = %u", (unsigned) left);
setSchedTimeout(left);
return;
}
//
if (in_f > frame_time - 5 && in_f < frame_time + listen_time)
{
time_last_sched += frame_time;
in_f -= frame_time;
if (in_f == 0) { //
resync_counter--;
if (resync_counter <= 0) {
must_send_sync = 1;
resync_counter = NEW_RESYNC_COUNTER;
}
}
sched_state = SCHED_STATE_OWN;
ushort left = listen_time + 5 - in_f;
assert(left <= listen_time + 10);
printf(PRINT_MAC, "calc_sched: in next frame, left = %u", (unsigned) left);
setSchedTimeout(left);
return;
}
//
assert(in_f < frame_time);
int i;
for (i = 0; i < sched_count; i++)
{
if (in_f > (unsigned) sched_table[i] - 5 && in_f < sched_table[i] + listen_time)
{
//
sched_state = SCHED_STATE_OTHER;
unsigned end_in_f = sched_table[i] + listen_time;
if (end_in_f > frame_time)
{
//
end_in_f = frame_time;
}
ushort left = end_in_f - in_f + 5;
assert(left <= listen_time + 10);
printf(PRINT_MAC, "calc_sched: in foreign frame %d, left = %u", i,
(unsigned) left);
63

setSchedTimeout(left);
return;
}
}
// .
sched_state = SCHED_STATE_SLEEP;
unsigned wake_at = frame_time;
//
for (i = 0; i < sched_count; i++)
{
if (sched_table[i] > in_f && sched_table[i] < wake_at)
wake_at = sched_table[i];
}
ushort left = wake_at - in_f;
assert(left <= sleep_time);
printf(PRINT_MAC, "calc_sched: in no frame, left = %u", (unsigned) left);
setSchedTimeout(left);
if (getForce() != FORCE_NOSLEEP)
setRadioSleep();
return;
}

4.6
MAC MAC
MAC OMNeT++ S-MAC

MAC

[1] Ye W, Heidemann J, Estrin D. An energy-efficient MAC protocol for wireless sensor


networks[C]. In: Proc 21st Intl Annual Joint Conf IEEE Computer and Communications
Societies (INFOCOM 2002), New York, NY, June 2002.
[2] Langendoen K, Van Dam T. An adaptive energy-efficient MAC protocol for wireless sensor
networks.[C] In: Proc 1st Intl Annual Joint Conf on Embedded Networked Sensor Systems
(SenSys), Nov. 5-7,2003, Los Angeles, CA. 2003
[3] J. Ai, J. Kong, D. Turgut, An adaptive coordinated medium access control for wireless sensor

64

networks, in: Proceedings of the International Symposium on Computers and


Communications, Vol. 1, 2004, pp. 214219.
[4] Lu G, Krishnamachari B, Raghavendra C. An adaptive energy-efficient and low-latency MAC
for data gathering in wireless sensor networks.[C] In: Proc 18th Intl Parallel and Distributed
Processing Symp (IPDPS04), April 26-30, 2004, Santa Fe, New Mexico. 224~230
[5] Rajendran V, Obracazka K, Garcia-Luna-Aceves J J. Energy-efficient, collision-free medium
access control for
wireless sensor networks[A]. Proc 1st Intl Annual Joint Conf on Embedded Networked Sensor
Systems (SenSys)[C], Nov. 5-7,2003, Los Angeles, CA. 181~192
[6] Chatterjea S, van Hoesel L FW, Havinga P J M. AI-LMAC: An Adaptive, information-centric
and lightweight MAC protocol for wireless sensor network[C]. IEEE ISSNIP, 2004.381-388.
[7] Sohrabi K, Gao J, Ailawadhi V, Pottie G J. Protocol for self-organization of a wireless sensor
network.[M] IEEE Personal Communications Magazine, 2000, 7(5): 16~27
[8] Guo C, Zhong L, Rabaey J M. Low-power distributed MAC for ad hoc sensor radio networks.
[C] In: Proc Internet Performance Symp (Globecom01), San Antonio, TX, Nov. 2001.
2944~2948
[9] Le Boudec, J.-Y. Merz, R.Radunovic, B.Widmer, J. DCC-MAC: a decentralized MAC
protocol for 802.15.4a-like UWB mobile ad-hoc networks based on dynamic channel coding.
Broadband Networks, 2004. BroadNets 2004. Proceedings. First International Conference on

[10] M.Z.Win and R.A.Scholtz. Ultra-wide bandwidth time-hopping


spread-spectrum impulse radio for wireless multiple-access
communication. IEEE Transaction on Communication, 48(4):679691,April 2000.
[11] IEEE 802.15.4a approved technical requirements document,
may 04 - 04/198r2, available at
http://www.ieee.org.
[12] , , , . . : , 2005.

65

QOS [1]
(1)

(2)

(3)

5.1
5.1.1
WSNs sink WSNs

[2-4].
(1)

(2) ,

(3)
,
;
(4)
. WSNs
GPS

(5)
WSNs

(6)

66

WSNs

(7) QoS , QoS QoS


QoS QoS
QoS
(8)
,
(9)

(10)

5.1.2
1 hop

1Flooding[5] Source
,
, Sink
2Gossiping[5]Gossiping Flooding

3SARSequential Assignment Routing


Sink
QoS

4SPIN ( Sensor Protocol for Information via Negotiation)[6]/


Source ADV
ADV REQ
DATA Sink
, Flooding
,
, (
)
5Directed Diffusion, DD[7] Estrin
Sink (
) ,
CACHE

67

, Source Sink
Source ,

DD

, 5.1

B. C.
5.1 DD
[8]
6Rumor sink Directed Diffusion
Rumor
Agent

Agent Agent
Agent sink
sink flooding sink
Rumor
Agent 3 Rumor Agent Agent
.

5.1.3
clusterclusterheadcluster-member

1LEACHLow-Energy Adaptive Clustering Hierarchy[9] Heinzelman


round
0 1 q q T(n)
nG T(n) =1/{1-P[r mod (1/p)]} T(n) = 0 p
r G

68


Sink

2TEENThreshold Sensitive Energy Efficient Sensornetwork Protocol[11]TEEN


LEACH TEEN

3 PEGASIS Power-Efficient Gathering in Sensor Information Systems [10]


PEGASIS LEACH

Sink PEGASIS
,

(4) TTDD [12] sink sink

(grid)

sink
flooding
sink Sink
(Agent) Directed Diffusion
sink
8 TTDD
5Estrin

()
6Younis LEACH
ID

69

5.1.4 OMNET

5.2 OMNET
OMNET 5.2
sm_application sm_cordinator
sm_layer0 sm_energy

5.3

70

1 Leach
A Leach 5.2.3
B

Sink

C
#include "application.h"
#include <math.h>
//
//
#define SELF_INITIALIZE {
71

cMessage *msg = new cMessage("SET_UP");


msg->setKind(M_SELF);
scheduleAt(0.1,msg);
if(OCCUPATION != 5)
SEND_DECREASE_ENERGY(3);
}
//
#define SET_UP_PHASE {
cMessage *msg = new cMessage("SET_UP");
msg->setKind(M_SELF);
scheduleAt(simTime()+ 9000,msg);
if(OCCUPATION != 5)
SEND_DECREASE_ENERGY(3);
}
//
#define WAITING_INVITATION_TIMER {
cMessage *msg = new cMessage("WAIT_INVITATION_TIME_OUT");
msg->setKind(M_SELF);
scheduleAt(simTime()+ 10,msg);
if(OCCUPATION != 5)
SEND_DECREASE_ENERGY(3);
}
//
#define SEND_DECREASE_ENERGY(QUANTITY){
cMessage *msg = new cMessage("DECREASE_ENERGY");
msg->addPar("quantity") = (int)QUANTITY;
send(msg,"cordinator_out");
}
//
#define SEND_INVITATION {
cMessage *msg = new cMessage("INVITATION");
msg->setKind(M_HIGHLOW);
msg->addPar("group_id") = ID;
send(msg,"lowergate_out");
if(OCCUPATION != 5)
SEND_DECREASE_ENERGY(29);
}
//
#define SEND_SENSED_INFO {
cMessage *msg = new cMessage("SENSING_DATA");
msg->setKind(M_HIGHLOW);
msg->addPar("time") = simTime();
msg->addPar("source") = ID;
72

msg->addPar("destination") = FATHER;
msg->addPar("X") = PX;
msg->addPar("Y") = PY;
send(msg,"lowergate_out");
if(OCCUPATION != 5)
SEND_DECREASE_ENERGY(820);
}
//,IDfalse
void application::initialize()
{
group_flag = false;
SELF_INITIALIZE;
WAITING_INVITATION_TIMER;
}
void application::finish()
{
}
void application::handleMessage(cMessage *msg)
{
switch(msg->kind())
{
case M_SELF:
{
if (strcmp(msg->name(),"SET_UP")==0)
{
//
//clean up the marked connection
if(OCCUPATION == 2)
{
UPDATECOLOR("white");
if (ev.isGUI())
parentModule()->gate("out",FATHER)>setDisplayString("m=m;o=lightgrey,0;");
}
//Delete father
this->parentModule()->par("FATHER")= 0;
if(OCCUPATION == 1)
{
73

//
this->parentModule()->par("OCCUPATION") = 2;
//
this->parentModule()->gate("out",MAXCONN -1)->disconnect();
this->parentModule()->gate("in",MAXCONN -1)->fromGate()->disconnect();
UPDATECOLOR("white");
}
if(OCCUPATION != 5)//Not the base
{
//
int cluster_head = rand()% (HEAD_DISTRIBUTION);
//if cluster_head = HEAD_DISTRIBUTION --> head cadidate
if(cluster_head == HEAD_DISTRIBUTION - 1)
{
//
this->parentModule()->par("OCCUPATION")= 1;
group_flag =true;
SEND_INVITATION;
//
if (ev.isGUI())
UPDATECOLOR("blue");
}
}
delete msg;
break;
}
else if(strcmp(msg->name(),"WAIT_INVITATION_TIME_OUT")==0)
{
if(group_flag == false)//
delete msg;
break;
}
else
{
ev << "unknown message received from another node.\n";
endSimulation();
}
}
case M_LOWHIGH:
{
if (strcmp(msg->name(),"SENSING_DATA")==0)
74

{
SEND_DECREASE_ENERGY(100);
forward(msg);
delete msg;
break;
}
else if (strcmp(msg->name(),"INVITATION")==0)
{
SEND_DECREASE_ENERGY(3);
//
if(FATHER == 0 && OCCUPATION == 2) //occupation = 2 means not a
cluster head or base
{
//ID,
parentModule()->par("FATHER") = msg->par("group_id");
group_flag =true; //ID
if (ev.isGUI())

parentModule()-

>gate("out",FATHER)->setDisplayString("m=a;o=blue,0;");
}
delete msg;
break;
}
else if (strcmp(msg->name(),"SENSOR_INFO")==0)
{
if(SENSOR_SWITCH)

SEND_DECREASE_ENERGY(100);
parentModule()->bubble("DETECTED")

SEND_SENSED_INFO;
}
delete msg;
break;
}
else
{
ev << "unknown message received from another node.\n";
endSimulation();
}
}
default:
75

{
ev << "unknown message received\n";
endSimulation();
}
}
}
void application::forward(cMessage *msg)
{
if((int)msg->par("destination") == ID)
{
if(OCCUPATION == 1) //
{
//Sink
cMessage *tmpmsg = new cMessage("SENSING_DATA");
tmpmsg->setKind(M_HIGHLOW);
tmpmsg->addPar("time") = msg->par("time");
tmpmsg->addPar("source") = ID; //message from cluster head
tmpmsg->addPar("destination") = FATHER;
tmpmsg->addPar("X") = msg->par("X");
tmpmsg->addPar("Y") = msg->par("Y");
send(tmpmsg,"lowergate_out");
if(DISTANCE > CRADIUS)
{
SEND_DECREASE_ENERGY(200+ 0.1*DISTANCE*DISTANCE);

else
{
SEND_DECREASE_ENERGY(920);//100 for creating + 820 for sending
}
parentModule()->bubble("FWD");
}
else if(OCCUPATION == 5) //
{
sprintf(str,"%d,%d",(int)msg->par("X"),(int)msg->par("Y"));
parentModule()->bubble(str);
}
}
}

76

5.4 Leach
Sink

Sink

5.2
WSNs

sink

,
WSNs
(1) WSNs

sink
(2)

77


(3) WSNs

(4) WSNs
.

(5) WSNs WSNs

5.3 OMNET++
5.3.1 OMNET++ [19]
[20]

[21]
[22]Ad Hoc(M0bile Ad
hoe NetworksMANET)
(1)MANET
MANET
(2)MANET

5.3.1.1
5.3.1.1.1
GPS()
()6[23-27]

SinkSink1

78

5.3.1.1.2

2
(Multi-hops)Sink
SinkSink

(
R)

RSink
kSink

79

5.3.2
5.3.2.1 [28]
()

5.3.2.1.1
Sink Sink
10 Sink
10 Sink

Sink

Sink

Sink Sink
Sink

5.3.2.1.2
Sink

Sink Sink

Sink

80

5.3.2.1.3
Sink
Sink
Sink

QOS

QOS

5.3.2.2 [29]

(
)
(proactive)(reactive)

81

5.3.3 OMNET++
OMNET++

GUI GUI
OPNET NS2 NS2
NED( NS2 TCL)
C++OMNET++
windows
Liunx OPNET OMENT++
[30]






OMNET++
OOP
1simple
simple
parameters: //.cc
gates:
//
endsimple
2
module
parameters: //
gates: //
submodules: //
connections: //gates
endmodule
3
network : //gates
parameters: //
endnetwork
4import

82

5.4
(
tabledriven)()
[31]

5.4.1 (Flooding) [32]


3SD

83

5.4.2 (Directed DiffusionDD) [33]


DD

4Sink(interest
)
(interest entry)(
)

Sink

5.4.3 LEACH( Energy Adaptive Clustering Hierarchy) [34]


LEACHLEACH
(ready phase)(setup
phase)
LEACH
Sink
0l
T(n)
T(n)

84

nPr
Gr

TDMA

15

LEACH

5.5. OMNET++
5.5.1

FAMflooding algorithm message


FAMFAM
6[35]MAC
2FAFAMFAMAC2
FAFAMFAFAM,

85

FAMMACMACFAMFA

iFA(AP)
initiate(i)
send() FAMFAMAC
deliver() FAMFAAP
FAFAM(FA)
if(receive()== true) FAM
{
deliver()FAMFAAP
send() FAMFAMAC
}
else discard()FAM
OMNET7

Node

Application
Manager
Layer0

7
3applicationlayer0managerapplication
86

layer0FAmanager

NED
//----------------------------------------------// default components:
//----------------------------------------------simple application
gates:
in: lowergate_in;
in: uppergate_in;
in: blackboard_in;
out: lowergate_out;
out: uppergate_out;
endsimple
simple layer0
gates:
in: lowergate_in[];
in: uppergate_in;
in: blackboard_in;
out: lowergate_out[];
out: uppergate_out;
endsimple
//----------------------------------------------// sensor node definition:
//----------------------------------------------module sensornode
parameters:
CNNCTVTY: numeric,
KIND: numeric,
COLOR: numeric,
PX: numeric,
PY: numeric;
gates:
in: in[];
out: out[];
submodules:
sm_layer0: layer0;
gatesizes:
lowergate_in[CNNCTVTY],
87

lowergate_out[CNNCTVTY];
display: "p=158,258;i=layer0";
sm_application: application;
display: "p=158,86;i=application";
connections nocheck:
for i=0..CNNCTVTY-1 do
in[i] --> sm_layer0.lowergate_in[i];
out[i] <-- sm_layer0.lowergate_out[i];
endfor;
sm_application.lowergate_in <-- sm_layer0.uppergate_out;
sm_application.lowergate_out --> sm_layer0.uppergate_in;
display: "b=290,485,rect;o=white";
endmodule
// the central manager
simple manager
parameters:
P_FMAP: numeric,
N_FMAP: numeric;
gates:
in: in;
out: out;
endsimple
//------------------------------------------------// the parent module
//------------------------------------------------module test
parameters:
MAXCONN: numeric,
NNODES: numeric,
SSTRENGTH: numeric;
submodules:
snode: sensornode[NNODES];
parameters:
CNNCTVTY = MAXCONN,
KIND = 2,
COLOR = 2,
PX = 0,
PY = 0;
gatesizes:
in[MAXCONN],
88

out[MAXCONN];
man: manager;
parameters:
P_FMAP = 0,
N_FMAP = 0;
connections nocheck:
display: "p=0,0;b=860,560,rect;o=white";
endmodule
//------------------------------------------------// the network
//------------------------------------------------network thetest : test
endnetwork
102

89

5.5.2 gossiping
GossipingFlooding

floodingNED
Gossiping
NEDFlooding
940

90

10
10

5.6

QoS
sensor

1
[1] Akyildiz IF, Su W, Sankarasubramaniam Y, Cayirci E. A survey on sensor
networks. IEEE Communications Magazine, 2002,40(8)
[2] Akyildiz IF, Su W, Sankarasubramaniam Y, Cayirci E. Wireless sensor
networks: A survey. Computer Networks, 2002,38
[3] Cui L, Ju HL, Miao Y, Li TP, Liu W, Zhao Z. Overview of wireless sensor
networks. Journal of Computer Research and Development, 2005,42

91

[4] Niculescu D, Americ NL. Communication paradigms for sensor networks. IEEE
Communications Magazine 2005,43(3):
[5] Haas ZJ, Halpern JY, Li L. Gossip-Based ad hoc routing. In: Proc. of the
IEEE INFOCOM. New York: IEEE Communications Society, 2002.
[6] Kulik J, Heinzelman WR, Balakrishnan H. Negotiation based protocols for
disseminating information in wireless sensor networks. Wireless Networks,
2002,8(2-3)
[7] Intanagonwiwat C, Govindan R, Estrin D, Heidemann J. Directed diffusion for
wireless sensor networking. IEEE/ACM Trans. on Networking, 2003,11(1)
[8] Braginsky D, Estrin D. Rumor routing algorithm for sensor networks. In:
Proc. of the 1st workshop on sensor networks and applications. Atlanta: ACM
Press, 2002.
[9] Heinzelman W, Chandrakasan A, Balakrishnan H. Energy-efficient
communication protocol for wireless microsensor networks. In: Proc. of the 33rd
Annual Hawaii Intl Conf. on System Sciences. Maui: IEEE Computer Society,
2000.
[10] Lindsey S, Raghavendra CS. PEGASIS: Power-efficient gathering in sensor
information systems. In: Proc. of the IEEE Aerospace Conf. Montana: IEEE
Aerospace and Electronic Systems Society, 2002.
[11] Manjeshwar A, Agrawal DP. TEEN: A protocol for enhanced efficiency in
wireless sensor networks. In: Intl Proc. of the 15th Parallel and Distributed
Processing Symp. San Francisco: IEEE Computer Society, 2001.
[12] Ye F, Luo H, Cheng J, Lu S, Zhang L. A two-tier data dissemination model
for large-scale wireless sensor networks. In: Proc. of the 8th Annual Intl
Conf. on Mobile Computing and Networking. Atlanta: ACM Press, 2002.
[13] Sohrabi K, Gao J, Ailawadhi V, Pottie GJ. Protocols for self-organization
of a wireless sensor network. IEEE Personal Communications, 2000,7(5):
[14] Chang JH, Tassiulas L. Maximum lifetime routing in wireless sensor
networks. IEEE/ACM Trans. on Networking, 2004,12(4)
[15] Karlof C, Wagner D. Secure routing in sensor networks: attacks and
countermeasures. Ad Hoc Networks, 2003,1(1)
[16] Ye F, Chen A, Lu S, Zhang L. A scalable solution to minimum cost
forwarding in large sensor networks. In: Proc. of the 10th Intl Conf. on
Computer Communications and Networks. Arizona: IEEE Communications Society,
2001.
[17] Schurgers C, Srivastava MB. Energy efficient routing in wireless sensor
networks. In: Proc. of the MILCOM on Communications for Network-Centric
Operations: Creating the Information Force. Virginia: IEEE Communications
Society, 2001.
[18] Chu M, Haussecker H, Zhao F. Scalable information-driven sensor querying
and routing for ad hoc heterogeneous sensor networks. The Intl Journal of
High Performance Computing Applications, 2002,16
[19]..2005600
92

607
[20]J Agre JClare LAn integrated mehitecture for cooperative sensing
networks[J]Computer200033(5)106108
[21][J]
200542(1)163174
[22]Sehrabi KGao JAilawadhi Vet a1Protocols for self-organization of a
wireless sensor network[J]IEEE Personal Communications20007(5)1627
[23]Akyildiz I FSu WYet a1A Survey on Sensor Networks[J]IEEE
Communications Magazine2002lO2ll4
[24]Min RBhardwaj MCho s Het a1An Architecture for a Power-Aware
Distributed Micro sensor Node[A]IEEE Workshop on Signal Processing
Systems[C]New YorkIEEE345E47THST2000581590
[25]Shen CSrizathapornphat CJaikaeo CSensor Information Networking
Architecture and Applications[J]IEEE Personal Communication200l852
59
[26]Megnerdichien SKoushanfar FQu Get a1Exposure In Wireless AdHoc
Sensor Networks[A]ACMIEEE International Conference on Mobile Computing and
Networking[C]New YorkACM Press2001139150
[27]Li QAslam JRus DHierarchical Power-aware Routing in Sensor
Networks[EBOL]httpwwwCSwmedullqunpaper
dimacspdf20015
[28]http://blog.sina.com.cn/u/490620c3010005f9
[29]...2005
[30]http://blog.chinaunix.net/u/13991/showart.php?id=229797
[31Jamal NAhmed E.KamalRouting Techniques in Wireless Sensor NetworksA
SurveySan FranciscoIEEE Computer Society200216961705
[32]S. HedemiemiALiestmanA survey of gossiping and broadcasting
in communication networksNetworks198818(4)319349
[33]C. IntanagonwiwatRGovindanDEstrinDirected diffusionA scalable
and robust communication paradigm for sensor networks in the Proceeding s of
the 6th Annual ACMIEEE International Conference on Mobile Computing and
Networking ( MobiCom00)BostonMAAugust 2O00
[34]Heinzelman W ChandrakasanABalakrishnanHAn applicationspecific
protocol architecture for wireless micro sensor networks[J]IEEE Transactions
on Wireless Communications2002(1O)660670
[35].MANET..2003.

93


6.1
6.1.1

6.1.1.1
N
G
e=(ij)rijijdij
rijPi
eGPj-Pi=dij

1
1(a)1(b)1(c)

NP-hard
1(b)1(c)

(a)

(b)
1

(c)

94

6.1.1.2

(1)
(2)

6.1.2
6.1.2.1

(1)(RSSI)RSSIRF

RSSI50
(2)/(TOA/TDOA)TOA/TDOA

CPUSavvides[21]
TOA/TDOA
(3)(AOA)AOA
NiculescuAOA

6.1.2.2

95

(1)

AOA

(2)


(3)
Savvides
Nmin-max

6.1.2.3

6.1.2.3.1

(1)
ABCAFLABC
ABC
AFLCricket[5] [6]

-
AFL

(2)

TerrainABC

525ABC
60Savarese [19]Hop-

96

TerrainTerrainGPS-Free

(1)
(2)

6.1.2.3.2

Doherty
[10] [11]

MDS-MAP[25]
MDS-MAP3-4

ABCAOA

Yi ShangMDS-MAP
[27]

6.1.2.3.3

[8]APIT[23]DV-HOP[15]
APIT

DV-HOP

97

NiculescuAOA
[16]AOA

6.1.2.3.4

CPU

6.1.2.4 [37]

(1)

(2)

(3)

10%
10

(4)

(5)

(6)

98

(7)

6.1.3 OMNET++ DVHop


6.1.3.1 DVHop
DVHop

0 1

2 A
A

2 A
i

XiYiXjYj ij h(ij) i j
hdi i
hd hd
hd hd

99

hd hops i ,

di=hopshdi
3

6.1.3.2 DVHop
OMNET++ DVHop OMNET++

(1)
(2) 100
(3) 800500 30 3
27

DVHop

DVHop
.ned 3
.h .cc 4 nedtool *.ned
opp_nmakemake -f -e cc nmake -f Makefile.vc
100

DVHop.exe omnetpp.ini
DVHop.exe 10%
33%DVHop

DVHop

101

DVHop

OMNET++ DVHop

#include "application.h"
Define_Module( application );
void application::initialize()//
{
last_seen_id = -1;
// id -1
msgcount = 0;
// 0
TTL=0;
}
void application::finish()
{
int i;
double tmp;
ev<<"Node "<<ID<<" position, px="<<PX<<";
py="<<PY<<"\n";
for(i=0;i<NUM_ANC;i++)
{
ev<<"least hops to anchor["<<i<<"]is "<<hopto[i]<<"\n";
ev<<"len to anchor["<<i<<"] is "<<lento[i]<<"\n";
}
if(ID>=NUM_ANC)
{
commatrix();
tmp=sqrt((PX-rp.rx)*(PX-rp.rx)+(PY-rp.ry)*(PY-rp.ry));
102

ev<<"we get the position px="<<rp.rx<<", py="<<rp.ry<<"\n";


ev<<"cha="<<tmp<<"\n";
}
else
ev<<"we get the position px="<<PX<<",
ev<<"\n\n";

py="<<PY<<"\n";

}
void application::handleMessage(cMessage *msg)
{
switch(msg->kind())
{
case M_LOWHIGH:
{
if (strcmp(msg->name(),"FLOOD")==0)
{
processFlood(msg);
return;
}
if(strcmp(msg->name(),"GGHOPS")==0)
{
processHops(msg);
return;
}
ev << "unknown message received from another node.\n";
endSimulation();
}
case M_START:
{
cMessage *msgnew = new cMessage("FLOOD");
msgnew->setKind(M_HIGHLOW);
msgnew->addPar("flood_id") = ++last_seen_id;
msgnew->addPar("source")=ID;
//set source
for the message
msgnew->addPar("hops")=0;
msgnew->addPar("spx")=PX;
msgnew->addPar("spy")=PY;
send(msgnew,"lowergate_out");
UPDATECOLOR(msgcount+2);
msgcount++;
break;
}
case M_S2:
{
103

if(strcmp(msg->name(),"GGHOPS")==0)
{
double hopsize=comhopsize();
TTL=INTTL;
cMessage *hopsmsg=new cMessage("GGHOPS");
hopsmsg->setKind(M_HIGHLOW);
hopsmsg->addPar("source")=ID;
hopsmsg->addPar("hopsize")=hopsize;
hopsmsg->addPar("ttl")=INTTL;
sendDelayed(hopsmsg,RETRANSMITDELAY,"lowergate_out");
seens[ID]=true;
UPDATECOLOR(ID+2);
break;
}
}
default:
ev << "unknown message received\n";
endSimulation();
}
}
void application::processFlood(cMessage *msg)
{
int flood_id = (int)msg->par("flood_id");
if (flood_id <= last_seen_id)
{
delete msg;
return;
}
int source =msg->par("source");
int hop=msg->par("hops");
if(seen[source]==false)
{
seen[source]=true;
ancpos[source].x=msg->par("spx");
ancpos[source].y=msg->par("spy");
hopto[source]=hop+1;
msg->par("hops")=hopto[source];
msg->setKind(M_HIGHLOW);
sendDelayed(msg,RETRANSMITDELAY,"lowergate_out");
UPDATECOLOR(flood_id+2);
}
else if(seen[source]==true)
{
104

if(hopto[source]>hop+1)
{
hopto[source] = hop+1;
msg->par("hops")=hopto[source];
msg->setKind(M_HIGHLOW);
sendDelayed(msg,RETRANSMITDELAY,"lowergate_out");
}
else
delete msg;
return;
}
msgcount++;
last_seen_id = flood_id;
}
double application::comhopsize()//PXPY

{
double len=0.0,hs=0.0;
int hop=0,i;
for(i=0;i<NUM_ANC;i++)
{
len+=sqrt((PX-ancpos[i].x)*(PX-ancpos[i].x)+(PYancpos[i].y)*(PY-ancpos[i].y));
hop+=hopto[i];
}
hs=len/hop;
return hs;
}
void application::processHops(cMessage *msg)
{
int soc,ttl;
ttl=msg->par("ttl");
ttl--;
hopsize=msg->par("hopsize");
soc=msg->par("source");
if(seens[soc]==true||ttl<0)
{
delete msg;
return ;
}
if(seens[soc]==false)
105

{
seens[soc]=true;
if(TTL<ttl)
{
TTL=ttl;
msg->setKind(M_HIGHLOW);
msg->par("ttl")=ttl;
sendDelayed(msg,GENERATIONDELAY,"lowergate_out");
UPDATECOLOR(soc+2);
}
else
{
msg->setKind(M_HIGHLOW);
msg->par("ttl")=ttl;
sendDelayed(msg,GENERATIONDELAY,"lowergate_out");
}
lento[soc]=hopto[soc]*hopsize;
}
}
void application::commatrix()
{
int sel[NUM_ANC],i,j,t;
double dt,b11,b21,a11,a12,a21,a22,ap11,ap12,ap21,ap22;
ap11=ap12=ap21=ap22=0.0;
a11=a12=a21=a22=0.0;
b11=b21=0.0;
dt=0.0;
for(i=0;i<NUM_ANC;i++)
sel[i]=i;
for(i=0;i<NUM_ANC-1;i++)
for(j=i+1;j<NUM_ANC;j++)
{
if(hopto[j]<hopto[i])
{
t=hopto[j];
hopto[j]=hopto[i];
hopto[i]=t;
t=sel[j];
sel[j]=sel[i];
sel[i]=t;
}
106

}
ap11=(double)(2*(ancpos[sel[0]].x-ancpos[sel[2]].x));
ap12=(double)(2*(ancpos[sel[0]].y-ancpos[sel[2]].y));
ap21=(double)(2*(ancpos[sel[1]].x-ancpos[sel[2]].x));
ap22=(double)(2*(ancpos[sel[1]].y-ancpos[sel[2]].y));
b11=ancpos[sel[0]].x*ancpos[sel[0]].xancpos[sel[2]].x*ancpos[sel[2]].x+ancpos[sel[0]].y*ancpos[sel[0]].yancpos[sel[2]].y*ancpos[sel[2]].y+lento[sel[2]]*lento[sel[2]]lento[sel[0]]*lento[sel[0]]
b21=ancpos[sel[1]].x*ancpos[sel[1]].xancpos[sel[2]].x*ancpos[sel[2]].x+ancpos[sel[1]].y*ancpos[sel[1]].yancpos[sel[2]].y*ancpos[sel[2]].y+lento[sel[2]]*lento[sel[2]]lento[sel[1]]*lento[sel[1]];
double test[2][4]={ap11,ap12,1.0,0.0,ap21,ap22,0.0,1.0};
dt=test[0][0];
for(i=0;i<4;i++)
test[0][i]=test[0][i]/dt;
dt=test[1][0];
for(i=0;i<4;i++)
test[1][i]=test[1][i]-dt*test[0][i];
dt=test[0][1]/test[1][1];
for(i=0;i<4;i++)
test[0][i]=test[0][i]-test[1][i]*dt;
dt=1.0/test[1][1];
for(i=0;i<4;i++)
test[1][i]=test[1][i]*dt;
a11=test[0][2];
a12=test[0][3];
a21=test[1][2];
a22=test[1][3];
rp.rx=a11*b11+a12*b21;
rp.ry=a21*b11+a22*b21;
}

6.4

(1)
(2)
(3)

107

6.2
6.2.1

ISO(International Organization for Standardization)

1
2
3
4
5
IP

ISO
Internet IAB(Internet Architecture Board)
OSI
CMIS/CMIP(Common Management Information Services/Protocol) TCP/IP
SNMP(Simple Network Management Protocol)

WSN Internet
WSN

8.1 WSN
WSN
omnet WSN

6.2.1.1 wsn

[36]
Cisco

WSN

108

WSN performance and


accounting management.
WSN
WSN
WSN
wsn
WSn

bug
wSN
wsn

wsn
flat

6.2.1.2 wsn
Wsn
WSN
,[37]:
(1) post-man
(2)
(3)

(4)

, :
(1) ,
(2). ,

(3).
.

1
1

Two-Phase Monitoring System

2006

MOTE-VIEW

2005

SNMS

2005

109

AppSleep

2005

Agilla

2005

BOSS

2005

Agent-Based Power Management

2005

Agent-Based Policy Management

2005

Siphon

2005

Sympathy

2005

[18]

RRP

2004

STREAM

2004

MANNA

2003

N/A

N/A

Sectoral Sweeper

2003

Node-Level Management

2003

SenOS

2003

TinyDB

2002

TopDisc

2001

DSN Resource Management

2001

6.2.1.3 wsn
,
,
[37]:
(1)

(2)

(3) (
,)
(4) , WSN

(5) ,,,
wsn (), ,
(6)

6.2.2 wsn
WSN [38]
(1)
(2 /
(3) usage pattern

110

(4)Non-deterministic

(5)

6.2.2.1
,
,
, SPANGAFASCENTPEASNSSSCCP AppSleep SenOs
,
,[39]
SenOS

6.2.2.1.1 SenOs[5]
Sen OS
WSN

1 Sen OS
1Sen OS

ROM
SenOS

111

6.2.2.2
WSN
WSN
WSN
[6]
TopDisc[40]

6.2.2.2.1 TopDisc
TopDiscGuha
TopDisc
TopDisc

TopDisc

(1)
(2)

(3)

(4)
(5)

2TopDisc

112

TopDisc

6.2.2.3

,( tinyos)
,,
, ,
,
? ,

unreachablereachable
,
()
-
(
)
,, /
/mability"[41]

113

6.2.2.2.1 sympathy [42]


sympathy
Sympathy

Sympathyspatiotemporal context metrics

sympathy

6.2.2.2.2 Agilla [7]


tinyos Agilla

- -
-
--

114

6.2.3 Omnet
6.2.3.1 Wsn
omnet WSN ,
,(),
()

omnet wsn
1
(20 80)
ID ,,ID


(,)
MAC
2

115

,,
,:
, 3, n .
:
n-1 n-1
n n
n+1

3
:
,,
:,
,

3
,
,():


,
ID ,
-------
,
,,
,
,:

,( 3)
( n+1 )
:
116

void application::processTopologyRequest(cTopMessage *msg)


{
int source =(int)msg->par("sourceaddr"); //
int rehops = (int)msg->par("requirehops"); // hop
int realhops = (int)msg->par("hops"); // hop
realhops=realhops+1;
// hop 1
if (source==ID)
//
{

delete msg;
return ;

}
// meesage
if (IsMessageSeen[source])
// message
{
if(realhops-1>MinHops[ID])
{
if (msgtimerreply[source]!=NULL)
{
delete cancelEvent(msgtimerreply[source]); //
msgtimerreply[source] = NULL;
}
}
delete msg;
}
Else
// message
{
IsMessageSeen[source] = true;
MinHops[ID]=realhops;
if(PosOfAllNodes[ID].x==-1)
{
cModule *mod = this->parentModule();
PosOfAllNodes[ID].x=mod->par("PX");
PosOfAllNodes[ID].y=mod->par("PY");
}
if (realhops<rehops) // hop hop
{
SEND_TOPOLOGY_REQ(source,realhops);
SET_SELF_TIMER_REPLY(source);
delete msg;
}
if (realhops==rehops) // hop hop

{
ev <<"source:"<<source<< " ID"<<ID<<" rehops:"<<rehops <<"\n";
117

SEND_TOPOLOGY_REPLY_NEW(source,MinHops[ID],PosOfAllNodes[ID].x,PosOfAll
Nodes[ID].y);
delete msg;
}
if (realhops>rehops)
{
delete msg;
}
// setup timer for route reply
}
}
4

,() n ,
n+1
, n
,,
,,,,
,,,
,,
,
:
ID
ID

,
------
,,

118


0 : 1 3 15
1 : 3 15
2 : 4 13
3 : 6 7 15
4 : 5 9 11 13 18 19
5 : 8 9 11 13 18 19
6 : 7 12 15 17
7 : 8 17
8 : 9 10 17 18 19
9 : 17 18 19
10 : 17
11 : 14 18 19
12 : 16
13 : 18 19
18 : 19

6.2.4

SenOS TopDisc sympathy


Agilla omnet

119

6.3 OMNeT++
6.3.1
6.3.1.1

WSN
WSN
WSN
WSN
[45,46,47]

[49]

6.3.1.2
(1) MAC

(2)
WSN MAC
(3)

(4)
WSN

6.3.1.3
WSNsink.
WSN,,

(Proactive)(Reactive)
(Flooding)(Gossiping)[11]
(SAR)(Minimum Cost Field)
120

(SPIN)[12](DD)(LEACH)[8]
(TEEN)[10]PEGAGIS[9]
(GEAR)
(GPSR)[13]Ad Hoc
SPANGAF

6.3.1.4
(Relay)
(Sinkhole)(Sybil)(Wormhole)
HELLO(Acknowledgement Spoofing)[49, 50]
1

(1)

(Latency)
(2)
(Multihop)

(Black Hole)

(3)Sinkhole
Sinkhole

121

Wormhole

(4)Sybil[60]
SybilSybil

Sybil
(5)Wormhole[61]
Wormhole
Wormhole
Wormhole
SinkholeWormhole

1(a)WormholeSinkhole

1
(6)HELLO
HELLOHELLO

1(b)
(Advertisement)
HELO
(Overheard)

(7)

122

6.3.1.5
(1) (Directed Diffusion)
(Directed Difusion)Estrin
<>Sink
(interest)<>

sink
sink2

2 Directed Diffusion
Directed Difusion
sink sink sinkhole
Wormhole Svbil

(2) LEACH (Low Energy Adaptive Clustering Hierarchy)


LEACHMITChandrakasan
LEACH15
LEACH(round)

01
T(n)T(n)p
rG1/p

123

sink

HELLO
Flood

Svbil
(3) GEAR(Geographic and Energy Aware Routing)[62]
GEARDirected Difusion
(
)sink
GEAR
sybil

6.3.1.6

6.3.1.6.1 [20, 23, 24, 25]

Newsome J Sybil
[21]
Sybil

Needham-Schroeder

Wormhole

124

6.3.1.6.2

SinkholeWormholes
Brad KarpGPSR(Greedy Perimeter Stateless Routing)
[13]
Sinkhole
Wormhole
Yin Changqing
(Heuristic Secure
Routing on the DiameterSRD)[26]Ar
BB
DTokens

GPSRSRDINTRSNSLRSN

6.3.2 OMNeT++
(Directed Diffusion)
. diffusion
. node.ned node.msg
[node.msg]
message intMessage
{
fields:
int source;
int destination;
int hopCount = 0;
}
[node.ned]
simple Diffusion
gates:
in: in[];
out: out[];
endsimple

125

module Node
submodules:
node: Diffusion[7]; // we'll have 7 modules
display: "i=misc/node_s";
connections:
node[6].out++ --> delay 100ms --> node[5].in++;
node[6].in++ <-- delay 100ms <-- node[5].out++;
node[6].out++ --> delay 100ms --> node[4].in++;
node[6].in++ <-- delay 100ms <-- node[4].out++;
node[6].out++ --> delay 100ms --> node[3].in++;
node[6].in++ <-- delay 100ms <-- node[3].out++;
node[3].out++ --> delay 100ms --> node[4].in++;
node[3].in++ <-- delay 100ms <-- node[4].out++;
node[3].out++ --> delay 100ms --> node[5].in++;
node[3].in++ <-- delay 100ms <-- node[5].out++;
node[3].out++ --> delay 100ms --> node[2].in++;
node[3].in++ <-- delay 100ms <-- node[2].out++;
node[3].out++ --> delay 100ms --> node[1].in++;
node[3].in++ <-- delay 100ms <-- node[1].out++;
node[3].out++ --> delay 100ms --> node[0].in++;
node[3].in++ <-- delay 100ms <-- node[0].out++;
node[4].out++ --> delay 100ms --> node[2].in++;
node[4].in++ <-- delay 100ms <-- node[2].out++;
node[5].out++ --> delay 100ms --> node[1].in++;
node[5].in++ <-- delay 100ms <-- node[1].out++;
node[2].out++ --> delay 100ms --> node[0].in++;
node[2].in++ <-- delay 100ms <-- node[0].out++;
node[1].out++ --> delay 100ms --> node[0].in++;
node[1].in++ <-- delay 100ms <-- node[0].out++;
endmodule
network node : Node
endnetwork
. diffusion.cpp
[diffusion.cpp]
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include "node_m.h"
class Diffusion : public cSimpleModule {
protected:
126

virtual intMessage *genMessage();


virtual void forwardMessage(intMessage *msg);
virtual void updateDisplay();
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
Define_Module(Diffusion);

// OMNeT

void Diffusion::initialize()
{
// node[0], sink interest message
if (index() == 0)
{
// self-message
intMessage *msg = genMessage();
scheduleAt(0.0, msg);
}
}
void Diffusion::handleMessage(cMessage *msg)
{
if (simTime() < 0.3)
{
ev << simTime() << " ";
intMessage *intMsg = check_and_cast<intMessage *>(msg); //
forwardMessage(intMsg); //
}
else
{
//
cTopology topo;
topo.extractByModuleType("Diffusion",NULL);
for (int i=0; i<topo.nodes(); i++)
{
cTopology::Node *node = topo.node(i);
ev << "Node i=" << i<< " is " << node->module()->fullPath()<< endl;
ev<<"It has " << node->outLinks()<<" conns to other nodes\n";
ev<< "and " << node->inLinks()<<" conns from other nodes\n";
ev << "Connections to other modules are:\n";
127

for(int j=0;j<node->outLinks();j++)
{
cTopology::Node *neighbour = node->out(j)->remoteNode();
cGate *gate = node->out(j)->localGate();
ev << "
" << neighbour->module()->fullPath()
<< " through gate " << gate->fullName() << endl;
}
}
// node(6)
cTopology::Node *targetnode = topo.node(6);
topo.unweightedSingleShortestPathsTo(targetnode);
cTopology::Node *node = topo.node(0);
if (node == NULL)
{
ev << "We(" << fullPath() << ") are not included in the topology.\n";
}
else if (node->paths() == 0)
{
ev << "No path to destination.\n";
}
else
{
while (node != topo.targetNode())
{
ev << "We are in " << node->module()->fullPath() << endl;
ev << node->distanceToTarget() << " hops to go\n";
ev << "There are " << node->paths()
<< " equally good directions, taking the first one\n";
cTopology::LinkOut *path = node->path(0);
ev << "Taking gate" << path->localGate()->fullName()
<<" we arrive in" << path->remoteNode()->module()->fullPath()
<< " on its gate" << path->remoteGate()->fullName() << endl;
node = path->remoteNode();
}
}
if(index() == 6) updateDisplay();
if(index() == 3) updateDisplay();
if(index() == 0) updateDisplay();
128

}
}
//
intMessage* Diffusion::genMessage()
{
// .
int src = index(); // ID
int n = size();
//
int dest = intuniform(0,n-1);
char msgName[20];
// .
intMessage *msg = new intMessage(msgName);
msg->setSource(src);
msg->setDestination(dest);
return msg;
}
//
void Diffusion::forwardMessage(intMessage *msg)
{
int n = gate("out")->size();
if (index() != 6)
{
for( int i=0; i<n; i++)
{
ev << "Forwarding message " << "on port out[" << i << "]\n";
intMessage *copy=(intMessage*) msg->dup();
send(copy, "out", i);
}
}
}
//
void Diffusion::updateDisplay()
{
char buf[40];
sprintf(buf, "Best Path!");
displayString().setTagArg("t", 0, buf);
}
129

. :
nedtool node.ned;
opp_nmakemake -f -e cpp;
nmake -f Makefile.vc;
diffusion.exe

. [omnetpp.ini]

[omnetpp.ini]
# Lines beginning with `#' are comments
[General]
preload-ned-files=*.ned
network=node
. diffusion.exe

130

6.3.3

(1)

(2)SPINGPSR

SRDINTRSN
(3)

131

[1]Want R, Hopper A, Falcao V, Gibbons J. The active badge location system.


ACM Trans. on Information Systems, 1992,10(1): 91102.
[2]Harter A, Hopper A, Steggles P, Ward A, Webster P. The anatomy of a
context-aware application. In: Proc. of the 5th Annual ACM/IEEE Intl Conf. on
Mobile Computing and Networking. Seattle: ACM Press, 1999. 5968.
[3]Bahl P, Padmanabhan VN. RADAR: An in-building RF-based user location
and tracking system. In: Proc. of the IEEE INFOCOM 2000. Vol.2, Tel Aviv: IEEE
Computer and Communications Societies, 2000. 775784.
[4]Hightower J, Boriello G, Want R. SpotON: An indoor 3D location sensing
technology based on RF signal strength. Technical Report UW CSE 2000-02-02,
Seattle: Department of Computer Science and Engineering, University of
Washington, 2000.
[5]Priyantha NB, Chakraborty A, Balakrishnan H. The cricket location-support
system. In: Proc. of the 6th Annual Intl Conf. on Mobile Computing and
Networking. Boston: ACM Press, 2000. 3243
[6]Priyantha N B. The cricket indoor location system: [dissertation]
Massachusetts institute of
technology, 2005
[7]Lorincz K, Welsh M. Motetrack: a robust decentralized approach to RFbased location tracking. In: Proceedings of the International workshop on
location and context-awareness. Pervasive, 2005
[8]Bulusu N, Heidemann J, Estrin D. GPS-Less low cost outdoor localization for
very small devices. IEEE Personal Communications, 2000,7(5):2834.
[9]Bulusu B, Heidemann J, Estrin D. Density adaptive algorithms for beacon
placement in wireless sensor networks. In: IEEE ICDCS01,Phoenix, AZ. April
2001
[10]Doherty L, Pister KSJ, Ghaoui LE. Convex position estimation in wireless
sensor networks. In: Proc. of the IEEE INFOCOM 2001. Vol.3, Anchorage: IEEE
Computer and Communications Societies, 2001. 16551663.
[11]Doherty L. Algorithms for position and data recovery in wireless sensor
networks [MS. Thesis]. Berkeley: University of California, 2000.
[12]Capkun S, Hamdi M, Hubaux J-P. GPS-Free positioning in mobile ad-hoc
networks. Cluster Computing, 2002,5(2):157167
[13]Iyengar R, Sikdar B. Scalable and distributed GPS free positioning for
sensor networks. In: Proc. of IEEE Intl Conf. on Communications 2003. Vol.1,

132

Anchorage: IEEE Communications Society, 2003. 338342.


[14]Nicolescu D, Nath B. Ad-Hoc positioning systems (APS). In: Proc. of the
2001 IEEE Global Telecommunications Conf. Vol.5, San Antonio: IEEE
Communications Society, 2001. 29262931.
[15]Niculescu D, Nath B. DV based positioning in ad hoc networks. Journal of
Telecommunication Systems, 2003,22(1/4):267280.
[16]Niculescu D, Nath B. Ad hoc positioning system (APS) using AoA. In: Proc.
of the IEEE INFOCOM 2003. Vol.3, San Francisco: IEEE Computer and
Communications Societies, 2003. 17341743.
[17]Beutel J. Geolocation in a PicoRadio environment [MS. Thesis]. Berkeley:
UC Berkeley, 1999.
[18]Savarese C, Rabaey JM, Beutel J. Locationing in distributed ad-hoc wireless
sensor network. In: Proc. of the 2001 IEEE Intl Conf. on Acoustics, Speech, and
Signal. Vol.4, Salt Lake: IEEE Signal Processing Society, 2001. 20372040.
[19]Savarese C, Rabay J, Langendoen K. Robust positioning algorithms for
distributed ad-hoc wireless sensor networks. In: Ellis CS, ed. Proc. of the
USENIX Technical Annual Conf. Monterey: USENIX Press, 2002. 317327.
[20]Bergamo P, Mazzini G. Localization in sensor networks with fading and
mobility. In: Proc. of the 13th IEEE Intl Symp. on Personal, Indoor and Mobile
Radio Communications. Lisbon: IEEE Communications Society,
2002,2:750754.
[21]Savvides A, Han C-C, Srivastava MB. Dynamic fine-grained localization in
ad-hoc networks of sensors. In: Proc. of the 7th Annual Intl Conf. on Mobile
Computing and Networking. Rome: ACM Press, 2001. 166179.
[22]Avvides A, Park H, Srivastava MB. The bits and flops of the N-hop
multilateration primitive for node localization problems. In: Proc. of the 1st
ACM Intl Workshop on Wireless Sensor Networks and Applications. Atlanta:
ACM Press, 2002. 112121.
[23]He T, Huang C, Blum B M, Stankovic J A Abdelzaher T. Range-free
localization schemes for
large scale sensor networks. In: Proc 9th Annual Int1 Conf on Mobile
Computing and Networks, San Diego, CA.,2003
[24]Chong L,Kui W. Sensor localization with ring overlapping based on
comparion of received signal strength indicator.2004
[25]Borg I, Groener P. Modern multidimensional scaling, theory and applications. SpringerVerlag, New York, 1997
[26]Shang Y, Ruml W, Zhang Y, Fromherz MPJ. Localization from mere
connectivity. In: Proc. of the 4th ACM Intl Symp. on Mobile Ad Hoc Networking
& Computing. Annapolis: ACM Press, 2003.
[27]Shang Y, Ruml W, Zhang Y, Fromherz MPJ. Improved MDS-Based
Localization. In: Proc. of the IEEE InforCom, March 2004
[28]Ahmed A, Shang Y, Shi H. Variants of multidimensional scaling for node
localization. In: Proceedings of the 2005 11th International Conference on
133

Parallel and Distributed Systems,2005


[29]Ji X., Zha H. Robust Sensor localization in wireless ad hoc sensor networks.
In: Proc. of the IEEE InforCom 2003
[30]Ji X., Zha H. Sensor positioning in wireless ad-hoc sensor networks using
multidimensional scaling. In: Proc. of the IEEE InforCom March 2004
[31]Patwari N, Hero III A.O. Distributed Weighted-Multidimensional Scaling for
Node Localization in Sensor Networks. In: ACM Journal, June 2005
[32]Cheng K W, So H C, A multidimensional scaling framework for mobile
location using time-of-arrival measurements. In: IEEE transactions on signal
processing, vol,53,No 2, 2005,2
[33]Tao PRudys AI_add A MWallach D SWireless LAN LocationSensing
for Security Applications[A]Proceedings of the Second ACM Workshop on
Wireless Security (WiSe)[C]San DiegoCAUSA2003
[34]Lingxuan Hu, David Evans.Localization for Mobile Sensor Networks.In:
ACM MobiCom 2004
[35] http://www.omnetpp.org/index.php
[36]Athanassios Boulis, Sanjay Jha Network management in new realms:
wirelesssensor networks. INTERNATIONAL JOURNAL OF NETWORK MANAGEMENT2005;
154: 219221
[37]Winnie Louis Lee,_ Amitava Datta, Rachel Cardell-Oliver ,Network Management
in Wireless Sensor Networks,
[38]B. Deb, S. Bhatnagar, and B. Nath, Tech. Rep. A Topology Discovery
Algorithm for Sensor
Networks with Applications to Network Management. DCS-TR-441, Rutgers
University (2001).
[39] .
200627(6):291:293.
[40] S. Hong and T. Kim, SenOS: State-driven Operating System Architecture for
Dynamic Sensor Node Reconfigurability, International Conference on Ubiquitous
Computing
(2003).
[41] .
,2005,26(11):1203~1209.
[42]C.-L. Fok, G.-C. Roman, and C. Lu. Mobile agent middleware for sensor
networks: An application case study. In Proceedings of the 4th International
Conference on Information Processing in Sensor Networks (IPSN05), 2005.
[43] Athanassios Boulis, Models for Programmability in Sensor Networks,
in Handbook of Sensor Networks: Compact Wireless and Wired Sensing Systems,
M. Ilyas and I. Mahgoub, eds., Boca Raton, FL,pp. 1.11.14, CRC Press, 2004.
[44]N. Ramanathan, E. Kohler, and D. Estrin, Sympathy for the Sensor Network
Debugger International Journal for Network Management 15, 223 (2005).
[45] Akyildiz IF, Su W, Sankarasubramaniam Y, Cayirci E. A survey on Sensor
Networks. IEEE Communications Magazine, 2002,40(8): 102-114.
134

[46] Akyildiz IF, Su W, Sankarasubramaniam Y, Cayirci E.


Networks: A Survey. Computer Networks, 2002,38(4): 393-422.
[47] .

Wireless Sensor

[48] Kemal Akkava and Mohamed Younis. A Survey on Routing Protocols for
Wireless Sensor Networks. November 2003.
[49] GUO Zhi-yuan,HE Qi-yuan. Study on Security of Routing Protocol in
Wireless Sensor Network.
[50] Karlof C, Wagner D. Secure Routing in Sensor Networks: Attacks and
Countermeasures. Ad Hoc Networks, 2003,1(1):293-315.
[51] C Intanagonwiwat, R Govindan and D Estrin. Direeted Diffusion: A Scalable
and Robust Communication Paradigm for Sensor Networks[C]. in the Proceedings
of the 6th Annual ACM/IEEE International Conference on Mobile Computing and
Networking(MobiComO0),Boston, MA,August 2000.
[52] Heinzelman W, Chandrakasan A, Balakrishnan H. Energy-efficient
Communication Protocol for Wireless Microsensor Networks. In: Proc. of the 33rd
Annual Hawaii Intl Conf. on System Sciences. Maui: IEEE Computer Society,
2000. 3005-3014.
[53] Lindsey S, Raghavendra CS. PEGASIS: Power-efficient gathering in sensor
information systems. In: Proc. of the IEEE Aerospace Conf. Montana: IEEE
Aerospace and Electronic Systems Society, 2002. 1125-1130.
[54] Manjeshwar A, Agrawal DP. TEEN: A protocol for enhanced efficiency in
wireless sensor networks. In: Intl Proc. of the 15th Parallel and Distributed
Processing Symp. San Francisco: IEEE Computer Society, 2001. 2009-2015.
[55] Haas ZJ, Halpern JY, Li L. Gossip-Based ad hoc Routing. In: Proc. of the
IEEE INFOCOM. New York: IEEE Communications Society, 2002. 1707-1716.
[56] Kulik J, Heinzelman WR, Balakrishnan H. Negotiation based protocols for
disseminating information in wireless sensor networks . Wireless Networks,
2002,8(2-3):169-185.
[57] Karp B, Kung H. GPSR: Greedy perimeter stateless routing for wireless
networks. In: Proc. of the 6th Annual Intl Conf. on Mobile Computing and
Networking. Boston: ACM Press, 2000. 243-254.
[58] W. Heinzelman, A. Sinha, A. Wang, A. Chandrakasan.
Energy-scalable
algorithms and protocols for wireless microsensor networks. Proc. International
Conference on Acoustics, Speech, and Signal Processing (ICASSP '00), June 2000.
[59] W. Heinzelman, A. Chandrakasan, H. Balakrishnan. An application-specific
protocol architecture for wireless microsensor networks .
in press: IEEE
Transaction on Wireless Networking.
[60] I. R. Uouceur. The Sybil Attack. In: 1st lnremotionnl Workshop on
Peer-to-Peer Syslcmr (IPTPS '0202). March 2002.
[61] Y.-C. Hu, A. Perrig, and U. B. Johnson. Wormhole detection in wireless
ad hoc networks. Depmenent of Computer Science, Rice University. Tech. Rep.
TR01-384, June 2002.
[62] Y. Yu, R. Govindan, and U. Estrin. Geographical and energy awaremuting:
135

A recursive dam dissemination pmtocol for wireless sensornetworkss. University


of California at Los Angeles Computer Science Department. Tech. Rep. UCLAKSUTR-01-0023. May 2001.
[63] Wang Xiao-yun, Yang Li-zhen, Chen Ke-fei.
SLEACH: Secure Low-Energy
Adaptive Clustering Hierarchy Protocol for Wireless Sensor Networks . Wuhan
University Journal of Natural Science, Vol.10 No.1 2005. 127-131
[64] Haowen Chan Adrian Perrig Dawn Song.
Random Key Predistribution
Schemes for Sensor Networks
[65] Newsome J, Shi E, Song D, et a1The Sybil Attack in Sensor Networks:
Analysis&Defenses[C]In: Proceedings of the 3rd International Symposium oil
Information Processing in Sensor Networks (IPSN04), April 26-27, 2004. 259268
[66] Chan Haowen, Perrig A. Security and Privacy in Sensor networks[J].
Computer200336(10)103-105
[67] Haowen Chan, Adrian Perrig, Dawn Song.
Random Key Predistribution
Schemes for Sensor Networks.
[68] Laurent Eschenauer, Virgil D. Gligor
A Key-Management Scheme for
Distributed Sensor Networks.
[69] Seyit A.Camtepe, Bulent Yener Key Distribution Mechanisms for Wireless
Sensor Networks: a Survey.
[70] Yin Changqing, Huang Shaoyin, Su Pengcheng, et a1. Secure Routing for
Large-scale Wireless Sensor Networks[C] In: Proceedings of
ICCT2003.2003:1282-1286.
[71] .
[72] . Ad Hoc
[73] TANG Yong, HOU Ming-Tian, HANG Xin.
Overview of Routing Protocols in
Wireless Sensor Networks.
[74] .

[1]

[2][34]
[5] [6,7] [89]

136

[10] GPS
GPS

WSN

7.1

In-door(Outdoor)

7.1.1
Active Badge[11]RADAR[12]Cricket[13]

7.1.1.1 Active Badge


Active BadgeOlivetti1992

ID
()

7.1.1.2 RADAR
RADARMicrosoft2000

RADAR

137

7.1.1.3 Cricket
CricketMIT2000
Cricket

300000000m/s340m/s

7.1.2

7.1.2.1

DV-Hop[14]Amorphous[15]
DV-HopRutgers UniversityNiculescuDV
Hop 3
2

1
TTL
3
3

Amorphous[15]DV-Hop[14]

138

7.1.2.2
GPS
GPSGPSGPS
ZebraNet[16]GPSMCL(Monte Carlo
Localization)[17]GPSDL(directional localization)
[18]
2002Princeton UniversityPhilo JuangZebraNet,
GPS
3GPS

GPS
2004 Virginia Lingxuan Hu
MCL
Lingxuan Hu

N
V A
A V

50 50

2006Polytechnic UniversityAkcanDL

7.2 OMNeT++
OMNeT++
MCL OMNeT++

7.2.1 MCLMonte Carlo Localization


MCL 2004 Virginia Lingxuan Hu
MCL

MCL

139

t-1 lt 1 Vmax
t lt 1 Vmax 1

Vmax

lt 1
1
S

S
2

S T
filter (l ) s S , d (l , s ) r s r d (l , s ) r 2
50 50

// N

L0 {l01 , l0,2 ......l0N }


// t ot (1 2 )t-1 lt 1
i

p (lt | lt 1 ) t lt

Lt {}
Whilesize( Lt )<N do

R {lti | p(lt | lti1 ), lti1 Lt 1} //


R filtered {lti | lti R, p (ot | lti ) 0} //
Lt Lt R filtered

140

= +1

<N and
<20000

Coord getSample(Coord p, double radius)


// t-1 p
radius
= +1;

meetCondition(Coord
p)>=0
//

= +1

7.2.2 MCLMonte Carlo Localization OMNeT++

7.2.2.1
(.ned )
:mobility,bottomlayer,position
mobility bottomlayer position

141

mobileHost.ned
simple Mobility
parameters:
minSpeed:
numeric const,
maxSpeed:
numeric const,
movKind:
numeric const,
XRange:
numeric const,
YRange:
numeric const,
pauseTime: numeric const,
moveInterval:
numeric const,
gates:
out: out;
endsimple
simple bottomLayer
parameters:
seed_r: numeric const,
node_r: numeric const,
isSeed: numeric const;
gates:
in: fromMobility;
in: fromPosition;
out: toPosition;
endsimple

//
//
//
//
//
//
//

//
//
//

simple Positioning
parameters:
isSeed:
numeric const, //
announceInterval:
numeric const,
//
updateInterval:
numeric const, //
seed_r:
numeric const,
//
node_r:
numeric const, //
max_v:
numeric const, //
142

delta:
numeric const;
gates:
in: fromBottom;
out: toBottom;
endsimple

//

module MobileHost
parameters:
isSeed: numeric const, //
numHost: numeric const, //
x: numeric, // x
y: numeric,
// y
Xbound: numeric, //
Ybound: numeric, //
seed_r: numeric const, //
node_r: numeric const, //
mobilityModel: string, //
posAlgorithm: string; //
submodules:
mobility: mobilityModel like Mobility;
parameters:
XRange = Xbound,
YRange = Ybound;
display: "p=260,64;b=24,26";
bottomlayer: bottomLayer;
parameters:
isSeed = isSeed,
seed_r = seed_r,
node_r = node_r;
display: "p=148,62;b=104,10";
position: posAlgorithm like Positioning;
parameters:
isSeed = isSeed,
seed_r = seed_r,
node_r = node_r,
max_v = input,
delta = input,
announceInterval = input,
updateInterval = input;
display: "p=148,171;b=104,10";
connections:
mobility.out --> bottomlayer.fromMobility;
position.toBottom --> bottomlayer.fromPosition;
143

bottomlayer.toPosition --> position.fromBottom;


display: "p=10,10;b=287,250";
endmodule
seed node seed node
numHost anchorFraction

mcl.ned
import "mobileHost.ned";
module MobileSensorNet
parameters:
numHost: numeric const,
anchorFraction: numeric const,
playgroundSizeX: numeric const,
playgroundSizeY: numeric const;
submodules:
seed: MobileHost[numHost * anchorFraction];
parameters:
isSeed = 1,
numHost = numHost,
Xbound = playgroundSizeX,
Ybound = playgroundSizeY,
x = intuniform(0,playgroundSizeX),
y = intuniform(0,playgroundSizeY);
node: MobileHost[numHost - numHost * anchorFraction];
parameters:
isSeed = 0,
numHost = numHost,
Xbound = playgroundSizeX,
Ybound = playgroundSizeY,
x = intuniform(0,playgroundSizeX),
y = intuniform(0,playgroundSizeY);
endmodule
network mobilesensornet : MobileSensorNet
endnetwork

144

7.2.2.2
C++ simple
MobilitybottomLayer PositioningMobility bottomLayer
Positioning MCL MCL
MCL
cMessage *annouceMsg = new cMessage("Annouce");
annouceMsg->setKind(MCL_MSG_ANNOUNCE_LOCATION);
scheduleAt(simTime()+announceInterval, annouceMsg);

message LocAnnounce
{
fields:
double x=0;
double y=0;
int hops=0;
int
id;
};

cMessage *updateMsg = new cMessage("Update");


updateMsg->setKind(MCL_MSG_UPDATE_LOCATION);
scheduleAt(simTime()+updateInterval, updateMsg);
handlemessage() MCL_MSG_ANNOUNCE_LOCATION
MCL_MSG_SEED_LOCATION MCL_MSG_UPDATE_LOCATION
MCL_MSG_ANNOUNCE_LOCATION

if(msg->kind() == MCL_MSG_ANNOUNCE_LOCATION)
{
LocAnnounce *locmsg = new LocAnnounce();
int x,y;
bottomlayer->getPos (x,y);
locmsg->setX(x);
locmsg->setY (y);
locmsg->setHops (0);
locmsg->setId(parentModule()->id());
locmsg->setId (MCL_MSG_SEED_LOCATION);
send(locmsg,"toBottom");
scheduleAt(simTime()+announceInterval, msg);
}
MCL_MSG_SEED_LOCATION 1 2
if(msg->kind() == MCL_MSG_SEED_LOCATION)
{
145

LocAnnounce *locmsg = (LocAnnounce *)msg;


int hops = locmsg->getHops ()+1;
cNeighbourPos *npos = new cNeighbourPos();
npos->x = locmsg->getX ();
npos->y = locmsg->getY ();
npos->id = locmsg->getId ();
if(hops == 1)
nbs1hop.insert(npos);
// 1
else if(hops == 2)
nbs2hop.insert(npos);
// 2
if(hops < MCL_MAX_HOPS)
//
{
locmsg->setHops (hops);
send(locmsg,"toBottom");
}
else
delete locmsg;
}
MCL_MSG_UPDATE_LOCATION
getSample meetCondition
getSample p radius

Coord Algorithm_MCL::getSample(Coord p, double radius)


{
Coord sample_p;
for (; ;) {
sample_p.x = p.x - radius + uniform(0,2 * radius);
sample_p.y = p.y - radius + uniform(0,2 * radius);
if (sample_p.distance(p) < radius)
return sample_p;
}
}
meetCondition 1 2
int Algorithm_MCL::meetCondition(Coord p)
{
int ret = 1;
//
int ql1 = nbs1hop.length();
int ql2 = nbs2hop.length();
if(ql1==0 && ql2==0)
return -1;
//-1
while(ql1-- >0)
{
146

cNeighbourPos *np = (cNeighbourPos *)nbs1hop.pop();


Coord pt;
pt.x = np->x;
pt.y = np->y;
nbs1hop.insert(np);
if(pt.distance (p) >= seed_r + delta)
return(-1);
else if(pt.distance (p) >= seed_r)
ret = 0;
// 0
}
while(ql2-- >0)
{
cNeighbourPos *np = (cNeighbourPos *)nbs2hop.pop();
Coord pt;
pt.x = np->x;
pt.y = np->y;
nbs2hop.insert(np);
if ( (pt.distance(p) < seed_r - delta) || (pt.distance(p) >= seed_r
+ node_r + delta))
return(-1);
else if( (pt.distance (p)<seed_r) || (pt.distance(p) >= seed_r +
node_r) )
ret = 0;
}
return ret;
}

7.2.2.3
OMNeT++ MCL OMNeT++ 3

147

MCL 17 MCL
MCLCentroid Amorphous 4

4
4 r 1 10
r MCL 0.5r ,MCL
Centroid Amorphous

7.3.

148


OMNeT++ MCL
MCLDL

[1]Rabacy JJ, Ammer MJ, da Silva Jr. JL, Patel D, Roundy S. Picorodio supports
ad hoc ultra-low power wireless networking. Computer, 2000,33(7):4248

[2]Savarese C, Rabaey JM, Beutel J. Locationing in distributed ad-hoc wireless


sensor network. In: Proc. of the 2001 IEEE Intl Conf. on Acoustics, Speech,
and Signal. Vol.4, Salt Lake: IEEE Signal Processing Society, 2001. 20372040.

[3]Capkun S, Hamdi M, Hubaux J-P. GPS-Free positioning in mobile ad-hoc networks. Cluster
Computing, 2002,5(2):157167.
[4]Doherty L, Pister KSJ, Ghaoui LE. Convex position estimation in wireless
sensor networks. In: Proc. of the IEEE INFOCOM 2001. Vol.3, Anchorage: IEEE
Computer and Communications Societies, 2001. 16551663.

[5]Girod L, Estrin D. Robust range estimation using acoustic and multimodal


sensing. In: Proc. of the IEEE/RSJ Intl Conf. on Intelligent Robots and
Systems (IROS 01). Vol.3, Maui: IEEE Robotics and Automation Society, 2001.
13121320.

[6]Meguerdichian S, Koushanfar F, Potkonjak M, Srivastava MB. Coverage problems


in wireless ad-hoc sensor networks. In: Proc. of the IEEE INFOCOM 2001. Vol.3,
Anchorage: IEEE Computer and Communications Societies, 2001. 13801387.

[7]Bulusu N, Heidemann J, Estrin D. Adaptive beacon placement. In: Young DC,


ed. Proc. of the 21st Intl Conf. on Distributed Computing Systems. Mesa: IEEE
Computer Society, 2001. 489498.

[8]Chang J-H, Tassiulas L. Energy conserving routing in wireless ad-hoc


networking. In: Proc. of the IEEE INFOCOM 2000. Tel Aviv: IEEE Computer and
Communications Societies, 2000,1:2231.

[9]Xu Y, Heidemann J, Estrin D. Geography-Informed energy conservation for ad


hoc routing. In: Proc. of the 7th Annual Conf. on Mobile Computing and
Networking. Rome: ACM Press, 2001. 7084.

[10]Alberto Cerpa, Deborah Estrin. Ascent: Adaptive self-configuring sensor network topologies.
ACM SIGCOMM Computer Communication Review, 2002,32(1):6262.
[11]BAHL, P., AND PADMANABHAN, V. RADAR: An In-Building RF-based User Location
and Tracking System. InProc. IEEE INFOCOM (Tel-Aviv, Israel, Mar. 2000).
[12]WANT, R., HOPPER, A., FALCAO, V., AND GIBBONS, J.The Active Badge Location
System. ACM Transactions on Information Systems 10, 1 (January 1992), 91102.
[13]Priyantha NBChakraborty ABalakrishnan HThe cricket location-support
system In Proc of the 6th Annual Intl Conf on Mobile Computing and
149

NetworkingBostonACM Press20003243
[14]D. Niculescu and B. Nath, Ad hoc positioning system (APS), in GLOBECOM.
IEEE, November 2001.
[15]Radhika Nagpal, Howard Shrobe, and Jonathan Bachrach. Organizing a Global
Coordinate System from Local Information on an Ad Hoc Sensor Network. 2nd
International Workshop on Information Processing in Sensor Networks (IPSN).
April 2003.
[16]JUANG, P., OKI, H., WANG, Y., MARTONOSI, M., PEH, L. S., AND RUBENSTEIN, D.
Energy-efficient computing for wildlife tracking: design tradeoffs and early
experiences with zebranet. Proc. of ASPLOS '02 (October 2002), 96--107.
[17]L.Hu, D.Evans: Localization for Mobile Sensor Networks. Tenth Annual
International Conference on Mobile Computing and Networking (MobiCom 2004),
USA.2004.
[18]Hseyin Akcan,, Herv Brnnimann,Vassil Kriakov,Alex Delis, GPS Free Node
Localization in Mobile Wireless Sensor Networks. Proceedings of the 5th ACM
international workshop on Data engineering for wireless and mobile access,
USA,2006.

150

You might also like