public void Transmit(Packet p, Socket self) { if (p == null) { Console.WriteLine(GetTime() + " | No Packet"); } else { //Console.WriteLine(GetTime() + " | packet recv, from " + p.src + " to " + p.dest + " ack?: " + p.ack + " seq " + p.seq + " "); if (rand.NextDouble() > lossRate) { Console.WriteLine(GetTime() + " | packet recv, from " + p.src + " to " + p.dest + " ack?: " + p.ack + " seq " + p.seq + " "); //Console.WriteLine("Success"); foreach (Socket s in sockets) { if (s != self) s.Recieve(p); } } else { //Console.WriteLine("Loss"); } } }
public void Recieve(Packet p) { //We Only Listen to stuff adressed to us. if (p.dest == id) { if (p.ack) { if (p.seq == lastRecv) { //Enter Recovery Mode error = true; } else { } while(transWindow > 0 && transmissionWindow[transHead].seq < p.seq ) { transWindow--; transHead = (ushort)((transHead + 1) % 8); lastRecv = p.seq; } } else { if (p.seq == (lastRecv)) { //Things are in order. Increment lastRecv++; _TrueRecv(p); if (window != head) { int i = 0; int j = head; while ((j + i) % 8 != window) { if (networkWindow[(j + i) % 8].seq == (lastRecv)) { _TrueRecv(networkWindow[(j + i) % 8]); head = (ushort)(( head + 1) % 8); window--; lastRecv++; } i++; } } } else { if (window > 8) { window++; networkWindow[(window + head - 1) % 8] = p; } } Packet ack = new Packet(); ack.ack = true; ack.dest = p.src; ack.src = p.dest; ack.seq = (ushort)(lastRecv); SendP(ack); } } }
private void _TrueRecv(Packet p) { Console.WriteLine(network.GetTime() + " | SOCKET " + id + " recieved packet # " + p.seq + " from " + p.src + " sent: " + p.timeStamp); }
public void Transmit(Packet p) { network.Transmit(p, this); }
public void SendP(Packet p) { transmissionQueue.AddLast(p); hasMessages = true; }
public void Send() { Packet p = new Packet(); p.dest = dst; p.src = id; p.seq = lastSeq; lastSeq++; transmissionQueue.AddLast(p); hasMessages = true; }
public TransitPacket(Packet p,int time,Socket s) { this.p = p; this.transitTime = time; this.source = s; }