public void RecievePacket(Packet packet) { Dispatcher.Invoke((Action) delegate { if (this == packet.DestinationVehicle) { packet.isDelivered = true; // PublicStatistics.SumCommunicationOverhead += packet.CommunicationOverhead; PublicStatistics.SumPropagationAndTransmissionDelay += packet.PropagationAndTransmissionDelay; PublicStatistics.QueueDelaySumInSeconds += packet.QueuingDelayInSecond; // PublicStatistics.HopsSum += packet.HopsVehicles; PublicStatistics.SumRoutingDistance += packet.RoutingDistance; PublicStatistics.WaitingTimesSum += packet.PathWaitingTimes; PublicStatistics.DeleiverdPacketsList.Add(packet); // Console.WriteLine("-------------------- Packert " + packet.PID + " is sucessfully recived-------------------"); packet.SourceVehicle.SetNotationSign(NotationsSign.Default); WaitingPacketsIDsList.Remove(packet.PID); SetNotationSign(NotationsSign.Default); packet.DestinationVehicle.SetNotationSign(NotationsSign.Default); PublicStatistics.InstanceDisplay(); // display. } else { // forward the packet. //check if this is the destination segment. then you should no select any PacketQueue.Enqueue(packet); // put the packet in the queue. PacketQueueTimer.Start(); // run the transmitter. PacketQueueTimer.Interval = TimeSpan.FromSeconds(PublicParamerters.PacketQueueTimerInterval); // retry after... } }); }
public void DropPacket(Packet packet) { Dispatcher.Invoke((Action) delegate { // drop the packet: packet.PathWaitingTimes += packet.HopWaitingTimes; // save the path waiting time and clear the hop. packet.isDelivered = false; // PublicStatistics.DropedPacketsList.Add(packet); packet.SourceVehicle.SetNotationSign(NotationsSign.Default); packet.DestinationVehicle.WaitingPacketsIDsList.Remove(packet.PID); SetNotationSign(NotationsSign.Default); packet.DestinationVehicle.SetNotationSign(NotationsSign.Default); PublicStatistics.InstanceDisplay(); // display. }); }