Esempio n. 1
0
 public void ReciveBeaconPacket(BeaconPacket beaconPacket)
 {
     if (IsDead)
     {
         return;
     }
     consumeEnergy(EnergyConsumtionType.Reception);
     RecivedBeaconPackets.Add(beaconPacket);
     Simulation.RecivedBeaconsCount++;
 }
Esempio n. 2
0
        public void Iterate()
        {
            float t = Simulation.SimulationTime;

            //move around
            Move();
            if (IsDead)
            {
                return;
            }

            //remove outdated BeaconPackets
            RecivedBeaconPackets.RemoveAll(bp => t - bp.SentTime > BeaconInterval * 4.5);
            //Remove older  packets from same sender

            //update neighbors lists
            var tempNeighbors = RecivedBeaconPackets.Select(bp => bp.Sender).ToList();

            Neighbors = tempNeighbors.GroupBy(n => n.Id).Select(g => g.First()).ToList();
            consumeEnergy(EnergyConsumtionType.Idle);
            foreach (Node n in Neighbors)
            {
                var rb = RecivedBeaconPackets.Where(bp => bp.Sender.Id == n.Id).OrderByDescending(bp => bp.SentTime).Skip(1).ToList();
                foreach (var item in rb)
                {
                    RecivedBeaconPackets.Remove(item);
                }
            }
            UpdateRNGNeighbors();
            UpdateGGNeighbors();

            //if Beacon Interval passed
            if (t - LastBeaconSendTime >= BeaconInterval)
            {
                //Broadcast a beacon;
                BroadcastLocation();
                LastBeaconSendTime = t;
            }

            //see if i want to sent packets;
            bool sendAPacket = Simulation.Random.NextDouble() < 0.1;

            if (sendAPacket)
            {
                var p = Packet.CreateRandomPacket(this.Id);
                Simulation.Packets.Add(p);

                GpsrForward(p, null);
            }
        }