An Uppaal analysis of the connection setup of the TCP protocol.

Changed from packets to segments

+58 -47
+58 -47
Model/model.xml
··· 3 3 // TIMEOUT Bounds 4 4 const int UBOUND = 600; 5 5 const int LBOUND = 10; 6 + const int TTL = 600; 6 7 // sequence bounds 7 8 const int MAX_SEQ = 3; 8 9 ··· 11 12 int target_address; //Global variable to pass the target address to the network 12 13 13 14 typedef struct { 14 - int syn; 15 - int ack; 16 - } TCP_packet; 15 + bool syn; 16 + bool ack; 17 + int seqNr; 18 + int ackNr; 19 + } TCP_segment; 17 20 18 - void initialize(TCP_packet&amp; p) 21 + void initialize(TCP_segment&amp; p) 19 22 { 20 - p.syn := 0; 21 - p.ack := 0; 23 + p.seqNr := 0; 24 + p.ackNr := 0; 25 + p.syn := false; 26 + p.ack := false; 22 27 } 23 28 24 - TCP_packet to_network; 25 - TCP_packet from_network;</declaration><template><name>Network</name><parameter>const int network</parameter><declaration>int target; // the target for the current network packet 26 - TCP_packet transfer; 29 + TCP_segment to_network; 30 + TCP_segment from_network;</declaration><template><name>Network</name><parameter>const int network</parameter><declaration>int target; // the target for the current network packet 31 + TCP_segment transfer; 32 + clock c; 27 33 28 34 void set_target() { 29 35 target = target_address; ··· 37 43 void send_packet(){ 38 44 from_network := transfer; 39 45 } 40 - </declaration><location id="id0" x="-5312" y="-1536"><committed/></location><location id="id1" x="-5152" y="-1664"><name x="-5160" y="-1696">PacketLost</name><committed/></location><location id="id2" x="-5312" y="-1664"><name x="-5360" y="-1696">PacketInTransit</name></location><location id="id3" x="-5312" y="-1408"><name x="-5360" y="-1384">ReadyToReceive</name></location><init ref="id3"/><transition><source ref="id0"/><target ref="id2"/><label kind="assignment" x="-5296" y="-1560">initialize(from_network)</label><nail x="-5280" y="-1592"/></transition><transition><source ref="id0"/><target ref="id3"/><label kind="synchronisation" x="-5400" y="-1480">Packet[target]!</label></transition><transition><source ref="id2"/><target ref="id0"/><label kind="assignment" x="-5400" y="-1608">send_packet()</label></transition><transition><source ref="id2"/><target ref="id1"/></transition><transition><source ref="id1"/><target ref="id3"/><nail x="-5152" y="-1408"/></transition><transition><source ref="id3"/><target ref="id2"/><label kind="synchronisation" x="-5432" y="-1560">Packet[network]?</label><label kind="assignment" x="-5432" y="-1544">set_target(), 41 - receive_packet()</label><nail x="-5440" y="-1408"/><nail x="-5440" y="-1664"/></transition></template><template><name>Host_Handshake</name><parameter>const int local, const int remote, const int network</parameter><declaration>clock c; 42 - int last_syn = 0; 46 + </declaration><location id="id0" x="-5312" y="-1536"><committed/></location><location id="id1" x="-5152" y="-1664"><name x="-5160" y="-1696">PacketLost</name><committed/></location><location id="id2" x="-5312" y="-1664"><name x="-5360" y="-1696">PacketInTransit</name></location><location id="id3" x="-5312" y="-1408"><name x="-5360" y="-1384">ReadyToReceive</name></location><init ref="id3"/><transition><source ref="id0"/><target ref="id2"/><label kind="assignment" x="-5296" y="-1560">initialize(from_network)</label><nail x="-5280" y="-1592"/></transition><transition><source ref="id0"/><target ref="id3"/><label kind="synchronisation" x="-5304" y="-1488">Packet[target]!</label></transition><transition><source ref="id2"/><target ref="id0"/><label kind="guard" x="-5384" y="-1624">c &lt;= TTL</label><label kind="assignment" x="-5416" y="-1608">send_packet()</label></transition><transition><source ref="id2"/><target ref="id1"/></transition><transition><source ref="id1"/><target ref="id3"/><nail x="-5152" y="-1408"/></transition><transition><source ref="id3"/><target ref="id2"/><label kind="synchronisation" x="-5432" y="-1560">Packet[network]?</label><label kind="assignment" x="-5432" y="-1544">set_target(), 47 + receive_packet(), 48 + c:=0</label><nail x="-5440" y="-1408"/><nail x="-5440" y="-1664"/></transition></template><template><name>Host_Handshake</name><parameter>const int local, const int remote, const int network</parameter><declaration>clock c; 49 + int last_seq = 0; 43 50 int last_ack = 0; 44 - int retrans_syn; 45 - int retrans_ack; 46 - TCP_packet received; 47 - 48 - void set_target(int syn, int ack) { 49 - target_address = remote; 50 - to_network.syn = syn; 51 - to_network.ack = ack; 52 - } 51 + TCP_segment retrans; 52 + TCP_segment received; 53 53 54 54 void receive_packet(){ 55 - received = from_network; 55 + received := from_network; 56 56 initialize(from_network); 57 57 } 58 58 59 - int update_syn(){ 60 - last_syn = (last_syn % MAX_SEQ) +1; 61 - return last_syn; 59 + int update_seq(bool syn){ 60 + last_seq = (last_seq % MAX_SEQ) +1; 61 + return last_seq; 62 62 } 63 63 64 - int update_ack(){ 65 - last_ack = received.syn; 64 + int update_ack(bool ack){ 65 + if(!ack) 66 + return 0; 67 + last_ack = received.seqNr; 66 68 return last_ack; 67 69 } 68 70 69 - void initialize() 71 + void reset() 70 72 { 71 - last_syn := 0; 73 + last_seq := 0; 72 74 last_ack := 0; 75 + initialize(retrans); 76 + initialize(received); 73 77 } 74 78 75 - void set_retrans(int syn, int ack) { 76 - retrans_syn = syn; 77 - retrans_ack = ack; 78 - }</declaration><location id="id4" x="-448" y="-672"><committed/></location><location id="id5" x="-736" y="-768"><committed/></location><location id="id6" x="-992" y="-928"><committed/></location><location id="id7" x="-736" y="-672"><name x="-768" y="-656">Established</name></location><location id="id8" x="-992" y="-768"><name x="-984" y="-768">SynRcvd</name><label kind="invariant" x="-984" y="-752">c &lt;= UBOUND</label></location><location id="id9" x="-448" y="-768"><name x="-512" y="-768">SynSent</name><label kind="invariant" x="-552" y="-752">c &lt;= UBOUND</label></location><location id="id10" x="-736" y="-928"><name x="-752" y="-912">Listen</name></location><location id="id11" x="-736" y="-1120"><name x="-800" y="-1128">Closed</name></location><init ref="id11"/><transition><source ref="id5"/><target ref="id8"/><label kind="synchronisation" x="-920" y="-832">Packet[network]!</label><label kind="assignment" x="-920" y="-817">set_target(0, update_ack()), 79 - set_retrans(0, last_ack), 80 - c := 0</label></transition><transition><source ref="id7"/><target ref="id7"/><nail x="-704" y="-704"/><nail x="-776" y="-704"/></transition><transition><source ref="id8"/><target ref="id8"/><label kind="guard" x="-1232" y="-720">c &gt; LBOUND</label><label kind="synchronisation" x="-1232" y="-736">Packet[network]!</label><label kind="assignment" x="-1232" y="-704">set_target(retrans_syn, retrans_ack), 81 - c:=0</label><nail x="-1120" y="-768"/><nail x="-1120" y="-736"/></transition><transition><source ref="id9"/><target ref="id9"/><label kind="guard" x="-312" y="-776">c &gt; LBOUND</label><label kind="synchronisation" x="-312" y="-792">Packet[network]!</label><label kind="assignment" x="-312" y="-760">set_target(last_syn, 0), 82 - c := 0</label><nail x="-320" y="-736"/><nail x="-320" y="-768"/></transition><transition><source ref="id11"/><target ref="id11"/><label kind="synchronisation" x="-856" y="-1192">Packet[local]?</label><label kind="assignment" x="-856" y="-1176">receive_packet()</label><nail x="-720" y="-1192"/><nail x="-752" y="-1192"/></transition><transition><source ref="id4"/><target ref="id7"/><label kind="synchronisation" x="-664" y="-672">Packet[network]!</label><label kind="assignment" x="-664" y="-656">set_target(0, update_ack())</label></transition><transition><source ref="id6"/><target ref="id8"/><label kind="synchronisation" x="-1240" y="-888">Packet[network]!</label><label kind="assignment" x="-1240" y="-872">set_target(update_syn(), update_ack()), 83 - set_retrans(last_syn, last_ack), 84 - c := 0</label></transition><transition><source ref="id10"/><target ref="id6"/><label kind="guard" x="-944" y="-976">from_network.syn != 0 &amp;&amp; 85 - from_network.ack == 0</label><label kind="synchronisation" x="-944" y="-992">Packet[local]?</label><label kind="assignment" x="-944" y="-952">receive_packet()</label></transition><transition><source ref="id9"/><target ref="id4"/><label kind="guard" x="-432" y="-712">from_network.ack == last_syn &amp;&amp; 86 - from_network.syn != 0</label><label kind="synchronisation" x="-432" y="-728">Packet[local]?</label><label kind="assignment" x="-432" y="-680">receive_packet()</label></transition><transition><source ref="id9"/><target ref="id5"/><label kind="guard" x="-672" y="-816">from_network.syn != 0 &amp;&amp; 87 - from_network.ack == 0</label><label kind="synchronisation" x="-672" y="-832">Packet[local]?</label><label kind="assignment" x="-672" y="-792">receive_packet()</label></transition><transition><source ref="id10"/><target ref="id9"/><label kind="synchronisation" x="-664" y="-976">Packet[network]!</label><label kind="assignment" x="-664" y="-960">set_target(update_syn(), 0), 88 - c := 0</label><nail x="-480" y="-928"/><nail x="-480" y="-800"/></transition><transition><source ref="id8"/><target ref="id7"/><label kind="guard" x="-984" y="-656">from_network.ack == last_syn &amp;&amp; 89 - from_network.syn == 0</label><label kind="synchronisation" x="-984" y="-672">Packet[local]?</label><label kind="assignment" x="-984" y="-624">receive_packet()</label><nail x="-992" y="-672"/></transition><transition><source ref="id9"/><target ref="id11"/><nail x="-416" y="-800"/><nail x="-416" y="-1152"/><nail x="-704" y="-1152"/></transition><transition><source ref="id11"/><target ref="id9"/><label kind="synchronisation" x="-592" y="-1120">Packet[network]!</label><label kind="assignment" x="-592" y="-1104">initialize(), 90 - set_target(update_syn(), 0), 91 - c := 0</label><nail x="-448" y="-1120"/></transition><transition><source ref="id10"/><target ref="id11"/><nail x="-704" y="-960"/><nail x="-704" y="-1088"/></transition><transition><source ref="id11"/><target ref="id10"/><label kind="assignment" x="-840" y="-1032">initialize()</label><nail x="-768" y="-1088"/><nail x="-768" y="-960"/></transition></template><system>Network1 = Network(0); 79 + void send(bool syn, bool ack) { 80 + target_address = remote; 81 + retrans.syn := syn; 82 + retrans.ack := ack; 83 + retrans.seqNr := update_seq(syn); 84 + retrans.ackNr := update_ack(ack); 85 + to_network := retrans; 86 + } 87 + 88 + void retransmit() { 89 + target_address = remote; 90 + to_network := retrans; 91 + }</declaration><location id="id4" x="-448" y="-672"><committed/></location><location id="id5" x="-736" y="-768"><committed/></location><location id="id6" x="-992" y="-928"><committed/></location><location id="id7" x="-736" y="-672"><name x="-768" y="-656">Established</name></location><location id="id8" x="-992" y="-768"><name x="-984" y="-768">SynRcvd</name><label kind="invariant" x="-984" y="-752">c &lt;= UBOUND</label></location><location id="id9" x="-448" y="-768"><name x="-512" y="-768">SynSent</name><label kind="invariant" x="-552" y="-752">c &lt;= UBOUND</label></location><location id="id10" x="-736" y="-928"><name x="-752" y="-912">Listen</name></location><location id="id11" x="-736" y="-1120"><name x="-800" y="-1128">Closed</name></location><init ref="id11"/><transition><source ref="id5"/><target ref="id8"/><label kind="synchronisation" x="-920" y="-832">Packet[network]!</label><label kind="assignment" x="-920" y="-817">send(false, true), 92 + c := 0</label></transition><transition><source ref="id7"/><target ref="id7"/><nail x="-704" y="-704"/><nail x="-776" y="-704"/></transition><transition><source ref="id8"/><target ref="id8"/><label kind="guard" x="-1224" y="-768">c &gt; LBOUND</label><label kind="synchronisation" x="-1256" y="-784">Packet[network]!</label><label kind="assignment" x="-1224" y="-752">retransmit(), 93 + c:=0</label><nail x="-1120" y="-768"/><nail x="-1120" y="-744"/></transition><transition><source ref="id9"/><target ref="id9"/><label kind="guard" x="-312" y="-776">c &gt; LBOUND</label><label kind="synchronisation" x="-312" y="-792">Packet[network]!</label><label kind="assignment" x="-312" y="-760">retransmit(), 94 + c := 0</label><nail x="-320" y="-736"/><nail x="-320" y="-768"/></transition><transition><source ref="id11"/><target ref="id11"/><label kind="synchronisation" x="-872" y="-1192">Packet[local]?</label><label kind="assignment" x="-872" y="-1176">receive_packet()</label><nail x="-720" y="-1192"/><nail x="-752" y="-1192"/></transition><transition><source ref="id4"/><target ref="id7"/><label kind="synchronisation" x="-664" y="-672">Packet[network]!</label><label kind="assignment" x="-664" y="-656">send(false,true)</label></transition><transition><source ref="id6"/><target ref="id8"/><label kind="synchronisation" x="-1120" y="-872">Packet[network]!</label><label kind="assignment" x="-1120" y="-856">send(true,true), 95 + c := 0</label></transition><transition><source ref="id10"/><target ref="id6"/><label kind="guard" x="-944" y="-976">from_network.syn &amp;&amp; 96 + ! from_network.ack</label><label kind="synchronisation" x="-944" y="-992">Packet[local]?</label><label kind="assignment" x="-944" y="-952">receive_packet()</label></transition><transition><source ref="id9"/><target ref="id4"/><label kind="guard" x="-432" y="-712">from_network.ack &amp;&amp; 97 + from_network.syn</label><label kind="synchronisation" x="-432" y="-728">Packet[local]?</label><label kind="assignment" x="-432" y="-680">receive_packet()</label></transition><transition><source ref="id9"/><target ref="id5"/><label kind="guard" x="-672" y="-816">from_network.syn&amp;&amp; 98 + ! from_network.ack</label><label kind="synchronisation" x="-672" y="-832">Packet[local]?</label><label kind="assignment" x="-672" y="-792">receive_packet()</label></transition><transition><source ref="id10"/><target ref="id9"/><label kind="synchronisation" x="-664" y="-976">Packet[network]!</label><label kind="assignment" x="-664" y="-960">send(true, false), 99 + c := 0</label><nail x="-480" y="-928"/><nail x="-480" y="-800"/></transition><transition><source ref="id8"/><target ref="id7"/><label kind="guard" x="-984" y="-656">from_network.ack &amp;&amp; 100 + ! from_network.syn</label><label kind="synchronisation" x="-984" y="-672">Packet[local]?</label><label kind="assignment" x="-984" y="-624">receive_packet()</label><nail x="-992" y="-672"/></transition><transition><source ref="id9"/><target ref="id11"/><nail x="-416" y="-800"/><nail x="-416" y="-1152"/><nail x="-704" y="-1152"/></transition><transition><source ref="id11"/><target ref="id9"/><label kind="synchronisation" x="-592" y="-1120">Packet[network]!</label><label kind="assignment" x="-592" y="-1104">reset(), 101 + send(true,false), 102 + c := 0</label><nail x="-448" y="-1120"/></transition><transition><source ref="id10"/><target ref="id11"/><nail x="-704" y="-960"/><nail x="-704" y="-1088"/></transition><transition><source ref="id11"/><target ref="id10"/><label kind="assignment" x="-816" y="-1056">reset()</label><nail x="-768" y="-1088"/><nail x="-768" y="-960"/></transition></template><system>Network1 = Network(0); 92 103 Network2 = Network(0); 93 104 Network3 = Network(0); 94 105 Network4 = Network(0); 95 106 Host1Handshake = Host_Handshake(1,2,0); 96 107 Host2Handshake = Host_Handshake(2,1,0); 97 108 98 - system Network1, Network2, Network3, Network4, Host1Handshake,Host2Handshake; 109 + system Network1, Network2, Network3, Host1Handshake,Host2Handshake; 99 110 </system></nta>