// Place global declarations here.
const int HOSTS = 2;
// TIMEOUT Bounds
const int UBOUND = 600;
const int LBOUND = 10;
const int TTL = 600;
// sequence bounds
const int MAX_SEQ = 3;
typedef int[0,MAX_SEQ] SEQ;
chan Packet[HOSTS+1];
int target_address; //Global variable to pass the target address to the network
typedef struct {
bool syn;
bool ack;
SEQ seqNr;
SEQ ackNr;
} TCP_segment;
void initialize(TCP_segment& p)
{
p.seqNr := 0;
p.ackNr := 0;
p.syn := false;
p.ack := false;
}
meta TCP_segment to_network;
meta TCP_segment from_network;Networkconst int networkint target; // the target for the current network packet
meta TCP_segment transfer;
clock c;
int packets_lost := 0; // Max packets a network can lose.
void set_target() {
target = target_address;
}
void receive_packet(){
transfer := to_network;
initialize(to_network);
}
void send_packet(){
from_network := transfer;
}
PacketLostPacketInTransitReadyToReceiveHostconst int local, const int remote, const int networkclock c;
SEQ snd_nxt = 0;
SEQ snd_ack = 0;
SEQ rcv_nxt = 0;
const int seg_len = 0;
TCP_segment retrans;
TCP_segment received;
bool receive_packet(){
if (from_network.syn) {
rcv_nxt = from_network.seqNr;
}
if (rcv_nxt == from_network.seqNr) {
received := from_network;
if(received.ack){
snd_nxt = received.ackNr;
}
snd_ack = (received.seqNr + 1 + seg_len)%MAX_SEQ;
rcv_nxt = snd_ack;
initialize(from_network);
return true;
}
return false;
}
void send(bool syn, bool ack) {
target_address = remote;
retrans.syn := syn;
retrans.ack := ack;
retrans.seqNr := snd_nxt;
retrans.ackNr := snd_ack;
to_network := retrans;
}
void retransmit() {
target_address = remote;
to_network := retrans;
}EstablishedSynRcvdSynSentListenClosedNetwork1 = Network(0);
Network2 = Network(0);
Network3 = Network(0);
Network4 = Network(0);
Host1 = Host(1,2,0);
Host2 = Host(2,1,0);
system Network1, Network2, Network3, Host1,Host2;