<?xml version="1.0" encoding="utf-8"?><!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_1.dtd'><nta><declaration>// Place global declarations here.
const int N=5+1; //Number of nodes +1
const int M=15+1; //Maximum sequence number +1
const int QLength=40;
const int time_between_hello=1500; //Hello  interval
const int time_between_tc=4500; //TC interval
const int time_sending=500;
const int time_spread=500;
const int TTL=N;
const int id_1=1; // is used for adding or droping a link between node 1 and 3
const int id_2=2;
const int id_3=3;

typedef int[0,N-1] IP; //Set of all ip numbers
typedef int[0,M-1] SQN;// Set of all sequence numbers
typedef int[0,3] MSGTYPE;//Set of all types of messages


int[0,QLength-1] nodebuffersize[N];

//for test_case generate. 
// send packet from oip1 to dip1
const int OIP1=1;
const int DIP1=3;
const int DIP2=2;

// type of messages
const MSGTYPE NONE=0;
const MSGTYPE PACKET=1;
const MSGTYPE HELLO=2;
const MSGTYPE TC=3;

bool idle[N]={1,1,1,1,1,1};

meta bool topology[N][N]={

{0,0,0,0,0,0},
{0,0,1,0,0,1},
{0,1,0,1,1,0},
{0,0,1,0,0,0},
{0,0,1,0,0,1},
{0,1,0,0,1,0}



};


bool isconnected(IP i, IP j){
  return(topology[i][j]==1);
}

bool emptybuffers(){
  for(i: int[1,N-1]){
    if(nodebuffersize[i]&gt;0||!idle[i]){
      return false;
    }
  }
  return true;
}

//channels
broadcast chan htc[N],urg[N], hur[N];
urgent chan imsg[N];
chan pkt[N][N];
chan packet[N][N]; /// get rid of this, replace by pkt/
urgent broadcast chan tau[N];
chan priority  urg[5] &lt; hur[5]&lt; tau[5] &lt; imsg[5] &lt; htc[5] &lt; urg[4] &lt; hur[4] &lt; tau[4] &lt; imsg[4] &lt; htc[4] &lt;  urg[3]&lt; hur[3] &lt; tau[3] &lt; imsg[3] &lt; htc[3] &lt;  urg[2]&lt; hur[2] &lt; tau[2] &lt; imsg[2] &lt; htc[2] &lt; urg[1]&lt; hur[1] &lt; tau[1] &lt; imsg[1] &lt; htc[1];


typedef struct { //HELLO and TC messages
  MSGTYPE msgtype;    //type of message (packet, Hello, TC)
  IP oip;    //originator address or ip
  IP dip;     
  bool onehop[N];
  int ttltc;  
  int hops;   //hops from originator
  IP sip; //Sender IP
  SQN osn;    //message(TC) sequence number
  bool mpr[N]; //used for mprs in Hello messages and mprselectors in TC messages
} MSG;

MSG msgglobal;

typedef struct { //Routing table entry
  IP dip;
  int hops; //Number of hops to destination
  IP nhopip; // Next hop ip
  SQN dsn;  // Sequence number of originator of TC	;
} rtentry;

</declaration><template><name>Tester</name><declaration>clock clk;

void drop (IP i,IP j){
    topology[i][j]=0;
    topology[j][i]=0;
}
</declaration><location id="id0" x="-392" y="8"><name x="-402" y="-22">drop_link</name><label kind="invariant" x="-520" y="32">clk&lt;=3*(time_between_tc + time_sending)</label></location><location id="id1" x="-744" y="8"><label kind="invariant" x="-928" y="24">clk&lt;=3*(time_between_tc )</label></location><location id="id2" x="624" y="8"><name x="614" y="-22">delivery</name></location><location id="id3" x="304" y="8"><name x="312" y="-16">test2</name><label kind="invariant" x="232" y="32">clk&lt;=7*(time_between_tc+time_sending)</label></location><init ref="id0"/><transition><source ref="id0"/><target ref="id3"/><label kind="guard" x="-352" y="-32">clk&gt;=3*(time_between_tc + time_sending)</label><label kind="assignment" x="-224" y="16">drop(id_1, id_2)</label></transition><transition><source ref="id1"/><target ref="id0"/><label kind="guard" x="-712" y="-24">clk&gt;=3*(time_between_tc )</label><label kind="synchronisation" x="-704" y="16">packet[OIP1][DIP1]!</label></transition><transition><source ref="id3"/><target ref="id2"/><label kind="guard" x="328" y="-40">clk&gt;=7*(time_between_tc+time_sending)</label><label kind="synchronisation" x="404" y="-7">packet[OIP1][DIP1]!</label></transition></template><template><name x="5" y="5">OLSR</name><parameter>const IP ip</parameter><declaration>// Place local declarations here.

rtentry rt[N]; //routing table of node ip
SQN sn=1;      // local sequence number
MSG msglocal;  //message currently handled
int delivered=0; // indicates that a packet has been deliered at this node
bool isMPR;     // node is classified as MPR
bool mprselector[N]; //is used in TC msgs and helps those nodes which do not transmit TC to find the route to other nodes.
//bool flag_hello=0; // this flag is used when overlapping TC and Hello. For instance when t_hello=1500 and t_tc=4500
bool flag_fwd=0; // if a TC is recieved from the queue and at the same time, hello or tc must be sent, this flag is set to 1 which shows the tc to be forwarded is not still forwarded.
bool flag_pkt=0;
int a;
bool flag_reset[N];
bool flag_sn=0;
//////////////////
//timers
//////////////////
clock t_send;  //time for sending a message
clock t_hello; //time passed since the last hello message
               //also used for init
clock t_tc;  //time passed since the last hello message
clock t_reset_rt [N];
clock t_reset_rt_topo[N];
//////////////////
//functions
//////////////////

//delete local message - happens whenever a messages has been handled successfully
void deletemsg(){
    msglocal.msgtype=NONE;
}


// HELLO messages 
//////////////////

//create new Hello message
void createhello(){
  MSG msg;
  msg.msgtype= HELLO;
  msg.oip= ip;

  for(i:int[1,N-1]){
    if (rt[i].hops==1){
      msg.onehop[i] = 1;

    }     
    else {
      msg.onehop[i]= 0;

      if (rt[i].hops==2){
        msg.mpr[rt[i].nhopip]=1;
      }
    }
  }
  msgglobal= msg;
}


//update data as consequence of a received hello message
void updatehello(){
  rt[msglocal.oip].dip=msglocal.oip;
  rt[msglocal.oip].hops= 1; 
  rt[msglocal.oip].nhopip=msglocal.oip;
  rt[msglocal.oip].dsn=rt[msglocal.oip].dsn;
}


//////////////////
// TC messages
//////////////////

//create new TC message
void createtc(IP oip, SQN osn, int ttltc, int hops, IP sip, bool mprselector[N]){
    MSG msg;
    msg.msgtype= TC;
    msg.oip= oip;
    msg.osn= osn;  // originator of TC SQN
    msg.ttltc= ttltc;
    msg.hops= hops;     
    msg.sip= sip;   
    msg.mpr = mprselector; 
    msgglobal= msg;
}


//update routing table when receiving a TC msg
void updatetc(){
if(rt[msglocal.oip].hops==1|| rt[msglocal.oip].hops==2){
    rt[msglocal.oip].dsn=msglocal.osn; 
    } 
else{
	if(rt[msglocal.oip].hops!=1&amp;&amp; rt[msglocal.oip].hops!=2){
    rt[msglocal.oip].dip=msglocal.oip;
    rt[msglocal.oip].hops= msglocal.hops+1; 
    rt[msglocal.oip].nhopip= msglocal.sip;
    rt[msglocal.oip].dsn=msglocal.osn; 
		}
	}
} 



//////////////////
///functions below to be sorted and annotated
void updatetwohop(){  //When receiving a Hello msg, every node updates its rounting table for onehop neighbors of the originator
// (twohop neighbors)
  for(i:int[1,N-1]){
    if(msglocal.onehop[i]==1 &amp;&amp; i!=ip &amp;&amp; rt[i].hops!=1){
      rt[i].dip=i;
      rt[i].hops= 2; 
      rt[i].nhopip= msglocal.oip;
    }
  }
}

void setmpr(){ // Allows MPR nodes to know that they are MPRs and shows which nodes have selected this node as MPR.
  if (msglocal.mpr[ip] == 1){
//    isMPR=1;
    mprselector[msglocal.oip]=1;
  }

 else{
	if(msglocal.mpr[ip] == 0){
    mprselector[msglocal.oip]=0;
}
	}
}

void reset_mpr(){ // removing the node from MPR status
for(i:int[1,N-1]){
   if (mprselector[i]==1){
isMPR=1;
		}
	}
}

void updatemprselector(){ // When a node is not a MPR, it does not broadcast TC msgs. So, other nodes will not be aware of that
// node. Using this funcion allows nodes to know about the mprselector of MPRs.

  for(i:int[1,N-1]){
    if (msglocal.mpr[i]==1 &amp;&amp; rt[i].hops!=1 &amp;&amp; rt[i].hops!=2 &amp;&amp; i!=ip){
      rt[i].dip=i;
      rt[i].hops=msglocal.hops+2;
      rt[i].nhopip=msglocal.sip;
         rt[i].dsn=rt[i].dsn;
    }
  }
}

/*void reset_rt_hello() { // assignes 0 to all variables in rt (shows expiration)
 for(i:int[1,N-1]){
 for(j:int[1,N-1]){

   if (flag_reset[i]==1 &amp;&amp; rt[j].nhopip==i){
      rt[j].dip=0;
      rt[j].hops=0;
      rt[j].nhopip=0;
      rt[j].dsn=0;
mprselector[i]=0;
flag_reset[i]=0;
   }}
  }
}
*/
void reset_rt(){
for(i:int[1,N-1]){
if (flag_reset[i]==1){
      rt[i].dip=0;
      rt[i].hops=0;
      rt[i].nhopip=0;
//     rt[i].dsn=0;
      flag_reset[i]=0;
}
     }
	}



void reset_clock_two_hop(){ 
 for(i:int[1,N-1]){
    if (msglocal.onehop[i]==1 &amp;&amp; i!=ip &amp;&amp; rt[i].hops!=1 &amp;&amp; rt[i].nhopip==msglocal.oip){
t_reset_rt[i]=0;
    }}
}

void reset_clock_mprselectors(){ 

  for(i:int[1,N-1]){
    if (msglocal.mpr[i]==1 &amp;&amp; i!=ip ){
t_reset_rt_topo[i]=0;
    }
  }
}

void reset_flag_sn(){ 

  for(i:int[1,N-1]){
    if (rt[i].dsn==M-1){
flag_sn=1;
    }
  }
}

</declaration><location id="id4" x="-392" y="352"><committed/></location><location id="id5" x="-392" y="184"><committed/></location><location id="id6" x="544" y="440"><name x="534" y="410">Forward_PACKET</name><label kind="invariant" x="424" y="448">t_send&lt;=time_sending</label></location><location id="id7" x="640" y="232"><committed/></location><location id="id8" x="-504" y="-8"><committed/></location><location id="id9" x="520" y="-128"><name x="488" y="-112">send_HELLO</name><label kind="invariant" x="440" y="-160">t_send&lt;=time_sending</label></location><location id="id10" x="712" y="-128"><committed/></location><location id="id11" x="-728" y="-8"><label kind="invariant" x="-776" y="-40">t_send&lt;=time_sending</label></location><location id="id12" x="-1080" y="440"><committed/></location><location id="id13" x="-1080" y="240"><committed/></location><location id="id14" x="-144" y="-344"><label kind="invariant" x="-200" y="-384">t_hello&lt;time_between_hello</label></location><location id="id15" x="-736" y="440"><name x="-784" y="456">forward_TC</name><label kind="invariant" x="-712" y="416">t_send&lt;=time_sending</label></location><location id="id16" x="-944" y="240"><committed/></location><location id="id17" x="-144" y="-232"><label kind="invariant" x="-120" y="-280">t_hello &lt;= time_between_hello</label></location><init ref="id14"/><transition><source ref="id11"/><target ref="id11"/><label kind="guard" x="-1216" y="-120">t_send&gt;=time_sending&amp;&amp;
flag_pkt==1&amp;&amp;
!isconnected(ip, rt[msglocal.dip].nhopip)</label><label kind="assignment" x="-1128" y="-64">deletemsg(),
idle[ip]=1,
flag_pkt=0</label><nail x="-1032" y="-8"/><nail x="-1032" y="-120"/><nail x="-728" y="-120"/></transition><transition><source ref="id9"/><target ref="id9"/><label kind="guard" x="288" y="-112">t_send&gt;=time_sending&amp;&amp;
flag_pkt==1&amp;&amp;
!isconnected(ip, rt[msglocal.dip].nhopip)</label><label kind="assignment" x="192" y="-112">deletemsg(),
idle[ip]=1,
flag_pkt=0</label><nail x="520" y="-56"/><nail x="280" y="-56"/><nail x="280" y="-128"/></transition><transition><source ref="id17"/><target ref="id4"/><label kind="select" x="-64" y="488">i:IP</label><label kind="guard" x="-344" y="512">t_reset_rt_topo[i]&gt;=
3* (time_between_tc+time_sending) &amp;&amp;
(rt[i].hops!=1 &amp;&amp; rt[i].hops!=2 &amp;&amp; rt[i].hops!=0&amp;&amp; rt[i].dsn&lt;M &amp;&amp; flag_sn==0)</label><label kind="synchronisation" x="72" y="488">hur[ip]!</label><label kind="assignment" x="16" y="560">flag_reset[i]=1,
t_reset_rt_topo[i]=0</label><nail x="168" y="184"/><nail x="168" y="512"/><nail x="-392" y="512"/></transition><transition><source ref="id4"/><target ref="id17"/><label kind="assignment" x="-392" y="264">reset_rt()</label><nail x="-408" y="352"/><nail x="-408" y="184"/></transition><transition><source ref="id17"/><target ref="id4"/><label kind="select" x="-64" y="328">i:IP</label><label kind="guard" x="-288" y="360">t_reset_rt[i]&gt;=
3* (time_between_hello+time_sending) &amp;&amp;
(rt[i].hops==2 )</label><label kind="synchronisation" x="56" y="328">hur[ip]!</label><label kind="assignment" x="24" y="368">flag_reset[i]=1,
t_reset_rt[i]=0</label><nail x="168" y="184"/><nail x="168" y="352"/></transition><transition><source ref="id5"/><target ref="id17"/><label kind="assignment" x="-336" y="88">reset_rt(),
isMPR=0,
reset_mpr()</label><nail x="-408" y="184"/></transition><transition><source ref="id17"/><target ref="id5"/><label kind="select" x="-32" y="160">i:IP</label><label kind="guard" x="-128" y="192">t_reset_rt[i]&gt;=
3* (time_between_hello+time_sending) &amp;&amp;
(rt[i].hops==1)</label><label kind="synchronisation" x="72" y="152">hur[ip]!</label><label kind="assignment" x="32" y="232">flag_reset[i]=1,
t_reset_rt[i]=0,
mprselector[i]=0</label><nail x="168" y="184"/></transition><transition><source ref="id7"/><target ref="id17"/><label kind="guard" x="248" y="328">msglocal.dip!=ip&amp;&amp;
(rt[msglocal.dip].nhopip==0 ||
!isconnected(ip, rt[msglocal.dip].nhopip))</label><label kind="assignment" x="536" y="336">deletemsg(),
idle[ip]=1</label><nail x="640" y="376"/><nail x="224" y="376"/><nail x="224" y="232"/></transition><transition><source ref="id10"/><target ref="id9"/><label kind="guard" x="640" y="0">t_tc&gt;=time_between_tc&amp;&amp;
!isMPR&amp;&amp;
flag_pkt==1</label><label kind="assignment" x="744" y="24">t_tc=0,
t_send=0</label><nail x="808" y="-128"/><nail x="808" y="0"/><nail x="520" y="0"/></transition><transition><source ref="id11"/><target ref="id11"/><label kind="guard" x="-952" y="-208">t_send&gt;=time_sending&amp;&amp;
flag_pkt==1&amp;&amp;
isconnected(ip, rt[msglocal.dip].nhopip)</label><label kind="synchronisation" x="-1008" y="-152">pkt[ip][rt[msglocal.dip].nhopip]!</label><label kind="assignment" x="-896" y="-120">msgglobal=msglocal,
deletemsg(),
idle[ip]=1,
flag_pkt=0,
a++</label><nail x="-728" y="-120"/><nail x="-920" y="-120"/><nail x="-920" y="-8"/></transition><transition><source ref="id9"/><target ref="id9"/><label kind="guard" x="288" y="-232">t_send&gt;=time_sending&amp;&amp;
flag_pkt==1&amp;&amp;
isconnected(ip, rt[msglocal.dip].nhopip)</label><label kind="synchronisation" x="392" y="-184">pkt[ip][rt[msglocal.dip].nhopip]!</label><label kind="assignment" x="296" y="-192">msgglobal=msglocal,
deletemsg(),
idle[ip]=1,
flag_pkt=0,
a++</label><nail x="520" y="-200"/><nail x="280" y="-200"/><nail x="280" y="-128"/><nail x="448" y="-128"/></transition><transition><source ref="id7"/><target ref="id17"/><label kind="guard" x="280" y="536">msglocal.dip!=ip&amp;&amp;
rt[msglocal.dip].nhopip!=0&amp;&amp;
t_hello&gt;time_between_hello-time_sending&amp;&amp;
isconnected(ip, rt[msglocal.dip].nhopip)</label><label kind="assignment" x="544" y="536">flag_pkt=1</label><nail x="640" y="528"/><nail x="224" y="528"/><nail x="224" y="232"/></transition><transition><source ref="id6"/><target ref="id17"/><label kind="guard" x="256" y="392">t_send&gt;=time_sending</label><label kind="synchronisation" x="248" y="424">pkt[ip][rt[msglocal.dip].nhopip]!</label><label kind="assignment" x="256" y="440">msgglobal=msglocal,
deletemsg(),
idle[ip]=1,
a++</label><nail x="224" y="440"/><nail x="224" y="232"/></transition><transition><source ref="id7"/><target ref="id6"/><label kind="guard" x="648" y="360">msglocal.dip!=ip&amp;&amp;
rt[msglocal.dip].nhopip!=0&amp;&amp;
t_hello&lt;=time_between_hello-time_sending&amp;&amp;
isconnected(ip, rt[msglocal.dip].nhopip)</label><label kind="assignment" x="568" y="440">t_send=0</label><nail x="640" y="248"/><nail x="640" y="440"/></transition><transition><source ref="id9"/><target ref="id9"/><label kind="guard" x="296" y="-40">t_send&gt;=time_sending&amp;&amp;
flag_fwd==1</label><label kind="synchronisation" x="408" y="-24">htc[ip]!</label><label kind="assignment" x="248" y="16">createtc(msglocal.oip, msglocal.osn, msglocal.ttltc-1,
              msglocal.hops+1,  ip, msglocal.mpr),
deletemsg(),
idle[ip]=1,
flag_fwd=0</label><nail x="520" y="0"/><nail x="280" y="0"/><nail x="280" y="-128"/></transition><transition><source ref="id7"/><target ref="id17"/><label kind="guard" x="280" y="272">msglocal.dip==ip</label><label kind="assignment" x="496" y="248">deletemsg(),
idle[ip]=1,
delivered++</label><nail x="640" y="296"/><nail x="440" y="296"/><nail x="224" y="296"/><nail x="224" y="232"/><nail x="-128" y="-208"/></transition><transition><source ref="id17"/><target ref="id7"/><label kind="guard" x="272" y="200">msglocal.msgtype==PACKET&amp;&amp;
flag_pkt==0</label><label kind="synchronisation" x="504" y="208">tau[ip]!</label><nail x="224" y="232"/><nail x="224" y="232"/></transition><transition><source ref="id10"/><target ref="id9"/><label kind="guard" x="544" y="-72">t_tc&gt;=time_between_tc&amp;&amp;
!isMPR</label><label kind="assignment" x="640" y="-48">t_tc=0,
t_send=0</label><nail x="712" y="-72"/><nail x="520" y="-72"/></transition><transition><source ref="id11"/><target ref="id8"/><label kind="guard" x="-720" y="0">t_send&gt;=time_sending&amp;&amp;
flag_fwd==0&amp;&amp;
flag_pkt==0</label><label kind="synchronisation" x="-664" y="48">htc[ip]!</label><label kind="assignment" x="-680" y="64">createhello()</label></transition><transition><source ref="id11"/><target ref="id11"/><label kind="guard" x="-1024" y="8">t_send&gt;=time_sending&amp;&amp;
flag_fwd==1</label><label kind="synchronisation" x="-888" y="32">htc[ip]!</label><label kind="assignment" x="-1096" y="80">createtc(msglocal.oip, msglocal.osn, msglocal.ttltc-1,
              msglocal.hops+1,  ip, msglocal.mpr),
deletemsg(),
idle[ip]=1,
flag_fwd=0</label><nail x="-920" y="-8"/><nail x="-920" y="144"/><nail x="-792" y="144"/><nail x="-792" y="-8"/></transition><transition><source ref="id10"/><target ref="id9"/><label kind="guard" x="552" y="-144">t_tc&lt;time_between_tc</label><label kind="assignment" x="616" y="-128">t_send=0</label></transition><transition><source ref="id10"/><target ref="id11"/><label kind="guard" x="408" y="-392">t_tc&gt;=time_between_tc&amp;&amp;
isMPR</label><label kind="assignment" x="608" y="-392">t_tc=0,
t_send=0</label><nail x="712" y="-360"/><nail x="-728" y="-368"/></transition><transition><source ref="id9"/><target ref="id17"/><label kind="guard" x="88" y="-184">t_send&gt;=time_sending&amp;&amp;
flag_fwd==0&amp;&amp;
flag_pkt==0</label><label kind="synchronisation" x="192" y="-152">htc[ip]!</label><label kind="assignment" x="80" y="-128">createhello()</label><nail x="512" y="-128"/><nail x="488" y="-128"/><nail x="56" y="-128"/><nail x="56" y="-192"/><nail x="0" y="-200"/></transition><transition><source ref="id17"/><target ref="id10"/><label kind="guard" x="264" y="-256">t_hello&gt;=time_between_hello</label><label kind="synchronisation" x="488" y="-256">urg[ip]!</label><label kind="assignment" x="632" y="-224">t_hello=0</label><nail x="712" y="-232"/></transition><transition><source ref="id8"/><target ref="id17"/><label kind="synchronisation" x="-448" y="-24">htc[ip]!</label><label kind="assignment" x="-512" y="-176">(sn&lt;M-1)?sn=sn+1:(sn=1),
createtc(ip,sn,TTL,0,ip,mprselector)</label><nail x="-368" y="-8"/><nail x="-368" y="-16"/><nail x="-368" y="-200"/><nail x="-216" y="-200"/></transition><transition><source ref="id12"/><target ref="id17"/><label kind="guard" x="-1056" y="544">t_hello&gt;time_between_hello-time_sending</label><label kind="assignment" x="-720" y="576">flag_fwd=1</label><nail x="-1080" y="576"/><nail x="-416" y="576"/><nail x="-416" y="304"/><nail x="-488" y="232"/></transition><transition><source ref="id12"/><target ref="id15"/><label kind="guard" x="-1056" y="416">t_hello&lt;=time_between_hello-time_sending</label><label kind="assignment" x="-1016" y="440">t_send=0</label></transition><transition><source ref="id13"/><target ref="id12"/><label kind="guard" x="-1200" y="376">isMPR &amp;&amp;
msglocal.ttltc&gt;1</label><nail x="-1080" y="408"/></transition><transition><source ref="id13"/><target ref="id17"/><label kind="guard" x="-1000" y="336">!isMPR||
msglocal.ttltc&lt;=1</label><label kind="assignment" x="-768" y="336">deletemsg(),
idle[ip]=1</label><nail x="-1080" y="376"/><nail x="-416" y="376"/><nail x="-416" y="304"/><nail x="-488" y="232"/></transition><transition><source ref="id16"/><target ref="id13"/><label kind="guard" x="-1088" y="192">msglocal.oip!=ip &amp;&amp;
(msglocal.osn&gt;rt[msglocal.oip].dsn)</label><label kind="assignment" x="-1224" y="256">updatetc(),
updatemprselector()</label></transition><transition><source ref="id14"/><target ref="id17"/><label kind="synchronisation" x="-144" y="-312">urg[ip]!</label><label kind="assignment" x="-88" y="-360">t_hello=0,
t_tc=0,
t_send=0</label></transition><transition><source ref="id17"/><target ref="id17"/><label kind="guard" x="280" y="152">msglocal.msgtype==HELLO</label><label kind="synchronisation" x="480" y="144">tau[ip]!</label><label kind="assignment" x="632" y="88">updatehello(),
updatetwohop(),
setmpr(),
isMPR=0,
reset_mpr(),
deletemsg(),
idle[ip]=1,
t_reset_rt [msglocal.oip]=0,
reset_clock_two_hop()</label><nail x="224" y="144"/><nail x="616" y="144"/><nail x="616" y="200"/><nail x="224" y="200"/></transition><transition><source ref="id15"/><target ref="id17"/><label kind="guard" x="-696" y="440">t_send&gt;=time_sending</label><label kind="synchronisation" x="-496" y="456">htc[ip]!</label><label kind="assignment" x="-792" y="472">createtc(msglocal.oip, msglocal.osn, msglocal.ttltc-1,
              msglocal.hops+1,  ip, msglocal.mpr),
deletemsg(),
idle[ip]=1</label><nail x="-416" y="440"/><nail x="-416" y="304"/><nail x="-488" y="232"/><nail x="-152" y="-216"/></transition><transition><source ref="id16"/><target ref="id17"/><label kind="guard" x="-912" y="264">msglocal.oip==ip ||
(msglocal.osn&lt;=rt[msglocal.oip].dsn)</label><label kind="assignment" x="-600" y="272">deletemsg(),
idle[ip]=1</label><nail x="-944" y="312"/><nail x="-416" y="312"/><nail x="-416" y="304"/><nail x="-488" y="232"/></transition><transition><source ref="id17"/><target ref="id16"/><label kind="guard" x="-656" y="160">msglocal.msgtype==TC&amp;&amp;
flag_fwd==0</label><label kind="synchronisation" x="-584" y="208">tau[ip]!</label><label kind="assignment" x="-816" y="192">t_reset_rt_topo[msglocal.oip]=0,
reset_clock_mprselectors(),
reset_flag_sn()</label><nail x="-528" y="240"/></transition><transition><source ref="id17"/><target ref="id17"/><label kind="guard" x="-352" y="-352">msglocal.msgtype==NONE</label><label kind="synchronisation" x="-256" y="-288">imsg[ip]?</label><label kind="assignment" x="-296" y="-320">msglocal=msgglobal,
idle[ip]=0</label><nail x="-144" y="-328"/><nail x="-304" y="-328"/><nail x="-304" y="-296"/><nail x="-304" y="-240"/><nail x="-160" y="-240"/></transition></template><template><name>Queue</name><parameter>const IP ip</parameter><declaration>MSG msglocal[QLength]; //last local copies of incoming messages 

void addmsg(MSG msg){
//if(nodebuffersize[ip]&lt;=QLength-1){
  msglocal[nodebuffersize[ip]]=msg;
  nodebuffersize[ip]++;
}
//else{msg.msgtype=NONE;}

//}

void deletemsg(){
  MSG empty_msg;
  for(i: int[1,QLength-1]){
    msglocal[i-1]=msglocal[i];
  }
  msglocal[QLength-1]=empty_msg;
  nodebuffersize[ip]--;
}

MSGTYPE nextmsg(){
  return msglocal[0].msgtype;
}

void create_add_packet(IP oip, IP dip){
  MSG msg;
  msg.msgtype= PACKET;
  msg.oip=oip;
  msg.dip=dip;
  addmsg(msg);
}
</declaration><location id="id18" x="0" y="0"></location><init ref="id18"/><transition><source ref="id18"/><target ref="id18"/><label kind="select" x="-24" y="128">dip:IP</label><label kind="synchronisation" x="-48" y="152">packet[ip][dip]?</label><label kind="assignment" x="-72" y="176">create_add_packet(ip,dip)</label><nail x="80" y="128"/><nail x="-88" y="128"/></transition><transition><source ref="id18"/><target ref="id18"/><label kind="select" x="-40" y="-208">sip:IP</label><label kind="guard" x="-80" y="-192">isconnected(sip,ip)</label><label kind="synchronisation" x="-64" y="-176">pkt[sip][ip]?</label><label kind="assignment" x="-88" y="-152">addmsg(msgglobal)</label><nail x="-88" y="-128"/><nail x="64" y="-128"/></transition><transition><source ref="id18"/><target ref="id18"/><label kind="select" x="-240" y="-48">sip:IP</label><label kind="guard" x="-312" y="-24">isconnected(sip,ip)</label><label kind="synchronisation" x="-240" y="8">htc[sip]?</label><label kind="assignment" x="-312" y="32">addmsg(msgglobal)</label><nail x="-144" y="-72"/><nail x="-144" y="64"/></transition><transition><source ref="id18"/><target ref="id18"/><label kind="guard" x="136" y="-40">(nextmsg()!=NONE)&amp;&amp;
idle[ip]</label><label kind="synchronisation" x="136" y="-8">imsg[ip]!</label><label kind="assignment" x="136" y="16">msgglobal=msglocal[0],
deletemsg()</label><nail x="128" y="-80"/><nail x="128" y="80"/></transition></template><system>// Place template instantiations here.
a1=OLSR(1);
a2=OLSR(2);
a3=OLSR(3);
a4=OLSR(4);
a5=OLSR(5);
//a6=OLSR(6);
//a7=OLSR(7);

a1q=Queue(1);
a2q=Queue(2);
a3q=Queue(3);
a4q=Queue(4);
a5q=Queue(5);
//a6q=Queue(6);
//a7q=Queue(7);

// List one or more processes to be composed into a system.
system 
a1,a1q,
a2,a2q,
a3,a3q,
a4,a4q,
a5,a5q,
//a6,a6q,
//a7,a7q, 

Tester;


//a1q,a2q,a3q,a4q, Tester &lt; ,a2,a3,a4;

//Tester &lt; a5,a5q &lt; a4,a4q &lt; a3, a3q &lt; a2,a2q &lt; a1,a1q;</system></nta>