Beruflich Dokumente
Kultur Dokumente
Simulation in MATLAB
Stuart Miller
Department of Electrical and
Computer Engineering
Missouri University of Science & Technology
Rolla, Missouri 65409
Email: mailto:sm67c@mst.edu
Web: http://web.mst.edu/∼sm67c
Fig. 7. Route request and reply from intermediate nodes, route messages RREQ, RREPL, and data
Fig. 8. Route request and reply from intermediate nodes, node route tables
Fig. 9. Link breakage, route messages RREQ, RREPL, and data
can’t reach E. This message propagates back up to D and both Because AODV provides no method of maintaining a node’s
nodes cancel out their routes to G. D must once again flood past activity, it must attempt sending again, receive an error
by sending out RREQ packets. C replies that it knows a route again, flood again, attempt to send again, etc. It can only
(the one established in example 2) and D then proceeds to cancel out one intermediate node’s route destination entry at
send to G via C. a time, potentially causing enormous overhead. Although not
The subsequent routing table is shown in figure 10. The reproduced here, this can be seen in the simulator in real time
sequence number have increased several times. Each time by mnually moving all the nodes in the network once valid
the nodes notice a change in their local network topology routing paths have been established.
the increase their sequence numbers. All nodes connected or
disconnected from E have been incremented to 2. V. A NALYSIS
While this is an exceptional method of handling a single To investigate the problem of quantifying exactly how
link failure or small change in topology, it starts to become much overhead various network topologies generate, statistics
rather burdensome when multiple route failures occur. One from several repeated transmissions were aggregated. In each
can imagine a contrived highly scenario where the topology simulation, the network had it’s nodes reset to an established
changes in such a way as to allow every intermediate node starting position and the route tables for all nodes were cleared.
to obtain a false route entry for the desired destination. In Nodes were set in motion and updated their position regularly.
such a case, the source node must first attempt to send and Each node had a pre-established step size and direction. Nodes
receive a reply. It then floods but receives multiple replies. reflected off the boundaries of the simulation area in order to
ensure that they stayed relatively close to each other and did
not go out of bounds. Random traffic was generated and sent
through the network. The random number generator used a
static seed to ensure that all variables were consistent from
experiment to experiment.
To begin with, traffic was evaluated on a static network
(figure 11). Here, the number of RREQ messages steadily
increases until around the 50th packet, at which time nodes
have most of the possible connections mapped out. The data
rate climbs steadily since no transmissions fail and the RERR
rate is accordingly zero.
Fig. 13. Network overhead with nodes moving every 10 packets sent
% Check a r g s
i f ( n a r g i n <= 2)
quickMode = f a l s e ;
end
i f ( nargin > 3 || s r c == d e s t )
return
end
% Bring g l o b a l s i n t o scope
global nodes c o l o r s r o u t e L i f e t i m e ;
% Persistant variables
requestDepth = 0;
depth = 0;
% Get s e q u e n c e number
i d x = f i n d ( n o d e s ( s r c ) . r o u t e T a b l e . d e s t == d e s t ) ’ ;
i f ( isempty ( idx ) )
seqNum = 0 ;
else
seqNum = n o d e s ( s r c ) . r o u t e T a b l e . seqNum ( i d x ) ;
end
% I f t h i s node h a s a r o u t e e n t r y f o r o u r d e s t , t r y s e n d i n g n o r m a l l y
tryAgain = f a l s e ;
i f ( any ( i d x ) )
i f ( ˜ send ( src , dest , c o l o r s . Data ) )
tryAgain = true ;
flood ( src , dest ) ;
end
else
tryAgain = true ;
flood ( src , dest )
end
i f ( quickMode )
quickUpdate ( ) ;
else
% Make a t i m e r t o i t e r a t i v e l y l i g h t up p a t h s
c o l o r T i m e r = t i m e r ( ’Name ’ , ’ c o l o r T i m e r ’ , . . .
’ ExecutionMode ’ , ’ f i x e d D e l a y ’ , . . .
’ Period ’ , 0 . 5 , . . .
’ TimerFcn ’ , @ s e t C o l o r ) ;
depth = 0;
s t a r t ( colorTimer )
end
% Remove r o u t e w i t h e x p i r e d l i f e t i m e s
f o r i = 1 : numel ( n o d e s )
for j = 1 : s i z e ( nodes ( i ) . routeTable , 1 )
e x p i r e d = find ( nodes ( i ) . r o u t e T a b l e . l i f e T i m e > r o u t e L i f e t i m e ) ;
nodes ( i ) . r o u t e T a b l e ( expired , : ) = [ ] ;
end
end
B. send()
function [ s u c c e s s ] = send ( sendSrc , sendDest , c o l o r )
success = false ;
% Check i f we a l r e a d y h a v e a r o u t e e n t r y f o r t h i s
currentNode = sendSrc ;
visitedNodes = [ ] ;
while t r u e
depth = depth + 1;
% Look i n c u r r e n t N o d e ’ s r o u t e T a b l e f o r t h e n e x t H o p node
n e x t N o d e = f i n d ( n o d e s ( c u r r e n t N o d e ) . r o u t e T a b l e . d e s t == s e n d D e s t ) ;
% E x i t i f no node was f o u n d
i f ( ˜ any ( n e x t N o d e ) )
% I f we were e x p e c t i n g t o h a v e a v a l i d p a t h , s e n d a RERR
i f ( c o l o r == c o l o r s . Data )
r e p l y T a b l e = f l o o d R e p l y ( s e n d S r c , c u r r e n t N o d e , c o l o r s . Data , c o l o r s . RERR) ;
myTable = [ myTable ; r e p l y T a b l e ] ;
success = true ;
tryAgain = true ;
return
end
break ;
end
% Update l i f e t i m e f i e l d now t h a t we ’ v e u s e d t h i s r o u t e
n o d e s ( c u r r e n t N o d e ) . r o u t e T a b l e ( nextNode , : ) . l i f e T i m e = . . .
n o d e s ( c u r r e n t N o d e ) . r o u t e T a b l e ( nextNode , : ) . l i f e T i m e + 1 ;
% C o n v e r t f r o m i n d e x i n r o u t e T a b l e t o a c t u a l node i n d e x
nextNode = nextNode ( 1 ) ;
n e x t N o d e = n o d e s ( c u r r e n t N o d e ) . r o u t e T a b l e ( nextNode , : ) . nextHop ;
% E x i t i f t h i s nextNode i s unreachable
% Send a RERR b a c k t o s o u r c e
i f ( ˜ any ( f i n d ( n o d e s ( c u r r e n t N o d e ) . c o n n e c t e d N o d e s == n e x t N o d e ) ) )
% myTable = [ myTable ;{ d e p t h , d e p t h , c u r r e n t N o d e , c u r r e n t N o d e , c o l o r s . RERR } ] ;
% s e n d ( c u r r e n t N o d e , s e n d S r c , c o l o r s . RERR ) ;
% myTable = [ myTable ;{ d e p t h , d e p t h , s e n d S r c , s e n d S r c , c o l o r s . RERR } ] ;
i f ( currentNode == sendSrc )
myTable = [ myTable ; { d e p t h , d e p t h , s e n d S r c , s e n d S r c , c o l o r s . RERR } ] ;
else
r e p l y T a b l e = f l o o d R e p l y ( s e n d S r c , c u r r e n t N o d e , c o l o r s . Data , c o l o r s . RERR) ;
myTable = [ myTable ; r e p l y T a b l e ] ;
end
tryAgain = true ;
success = true ;
return
end
% E x i t i f we ’ r e i n a l o o p
i f ( any ( f i n d ( v i s i t e d N o d e s == c u r r e n t N o d e ) ) )
r e p l y T a b l e = f l o o d R e p l y ( s e n d S r c , c u r r e n t N o d e , c o l o r s . Data , c o l o r s . RERR) ;
myTable = [ myTable ; r e p l y T a b l e ] ;
tryAgain = true ;
success = true ;
return
end
visitedNodes = [ visitedNodes , currentNode ] ;
% Update o u r p a t h t a b l e
myTable = [ myTable ; { d e p t h , d e p t h , nextNode , c u r r e n t N o d e , c o l o r } ] ;
c u r r e n t N o d e = nextNode ;
% E x i t when we ’ v e r e a c h e d t h e d e s t i n a t i o n
% Set success to true
i f ( currentNode == sendDest )
success = true ;
break
end
end
end
C. flood()
function [ ] = flood ( floodSrc , floodDest )
% Get c o n n e c t e d n o d e s h e r e
c u r r e n t N o d e = myTable . Node ( i ) ;
connectedNodes = nodes ( currentNode ) . connectedNodes ;
d e p t h = myTable . Depth ( i ) + 1 ;
% Remove d u p l i c a t e s when we ’ v e f i n i s h e d a t t h i s d e p t h
i f ( d e p t h > myTable . Depth ( end ) )
% For e a c h d u p l i c a t e d v a l u e i n myTable . Node
f o r j = f i n d ( h i s t ( myTable . Node , u n i q u e ( myTable . Node ) ) >1)
% F i n d t h e d i s t a n c e b e t w e e n Node and From f o r a l l
% o c c u r r a n c e s o f t h i s d u p l i c a t e d node
dist = [];
d u p l i c a t e s = f i n d ( myTable . Node== j & myTable . C o l o r = = c o l o r s . RREQ) ’ ;
for k = d u p l i c a t e s
d i s t = [ d i s t , s q r t ( ( n o d e s ( myTable . Node ( k ) ) . x − n o d e s ( myTable . From ( k ) ) . x ) ˆ 2 . . .
+ ( n o d e s ( myTable . Node ( k ) ) . y − n o d e s ( myTable . From ( k ) ) . y ) ˆ 2 ) ] ;
end
% Remove o c c u r r a n c e s b u t t h e one w i t h t h e min d i s t a n c e
[ ˜ , i d x ] = min ( d i s t ) ;
d u p l i c a t e s ( idx ) = [ ] ;
myTable ( d u p l i c a t e s , : ) = [ ] ;
i = i − numel ( f i n d ( d u p l i c a t e s <=i ) ) ;
end
end
% I f t h i s node h a p p e n s t o h a v e a v a l i d e n t r y on t h e r o u t e
% t a b l e , go ahead and s e n d n o r m a l l y f r o m h e r e o u t
i f ( any ( f i n d ( n o d e s ( c u r r e n t N o d e ) . r o u t e T a b l e . d e s t == f l o o d D e s t ) ) | | c u r r e n t N o d e = = f l o o d D e s t )
replyNodes = [ replyNodes ; currentNode ] ;
success = true ;
else
% Add e a c h o f t h i s node ’ s c o n n e c t e d n o d e s u n l e s s i t s a l r e a d y
% on t h e t a b l e b e f o r e t h i s d e p t h
for connectedNode = connectedNodes
i f ( currentNode ˜= floodDest )
i f ( ˜ any ( f i n d ( myTable . Node== c o n n e c t e d N o d e & myTable . Depth < d e p t h ) ) )
myTable = [ myTable ; { d e p t h , d e p t h , c o n n e c t e d N o d e , c u r r e n t N o d e , c o l o r s . RREQ} ] ;
end
else
success = true ;
end
end
end
% Check f o r t e r m i n a t i o n
i f ( i >= s i z e ( myTable , 1 ) )
i f ( isempty ( replyNodes ) )
tryAgain = f a l s e ;
end
break
end
end
r e q u e s t D e p t h = d e p t h −1;
i f ( success )
tempDepth = d e p t h ;
for r e p l y = replyNodes ’
d e p t h = tempDepth ;
r e p l y T a b l e = f l o o d R e p l y ( f l o o d S r c , r e p l y , c o l o r s . RREQ, c o l o r s . RREPL ) ;
myTable = [ myTable ; r e p l y T a b l e ] ;
end
end
end