Example #1
0
        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");
                }
            }
        }
Example #2
0
        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);
                }
            }
        }
Example #3
0
 private void _TrueRecv(Packet p)
 {
     Console.WriteLine(network.GetTime() + " | SOCKET " + id + " recieved packet # " + p.seq + " from " + p.src + " sent: " + p.timeStamp);
 }
Example #4
0
 public void Transmit(Packet p)
 {
     network.Transmit(p, this);
 }
Example #5
0
 public void SendP(Packet p)
 {
     transmissionQueue.AddLast(p);
     hasMessages = true;
 }
Example #6
0
 public void Send()
 {
     Packet p = new Packet();
     p.dest = dst;
     p.src = id;
     p.seq = lastSeq;
     lastSeq++;
     transmissionQueue.AddLast(p);
     hasMessages = true;
 }
Example #7
0
 public TransitPacket(Packet p,int time,Socket s)
 {
     this.p = p;
     this.transitTime = time;
     this.source = s;
 }