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 Clear() { Dispatcher.Invoke((Action) delegate { foreach (RoadSegment s in MyRoadSegments) { s.stopGeneratingVehicles(); } Settings.Default.IsIntialized = false; // re-intialize canvas_vanet.Children.Clear(); MyJunctions.Clear(); MyRoadSegments.Clear(); MyVehicles.Clear(); PublicStatistics.Clear(); }); }
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. }); }
private void btn_show_results(object sender, RoutedEventArgs e) { try { // send packets options. MenuItem item = sender as MenuItem; string Header = item.Header.ToString(); if (Settings.Default.IsIntialized) { switch (Header) { case "_Show Results Details": // stop. { List <object> List = new List <object>(); List.AddRange(PublicStatistics.DeleiverdPacketsList); List.AddRange(PublicStatistics.DropedPacketsList); if (List.Count > 0) { UiShowResults sh = new UiShowResults(List); sh.Title = "Details Results"; sh.Show(); } else { MessageBox.Show("No Results Found!"); } break; } case "_Print Results": // stop. { List <object> List = new List <object>(); List.AddRange(PublicStatistics.PrintResults(this)); if (List.Count > 0) { UiShowResults sh = new UiShowResults(List); sh.Title = "Final Results"; sh.Show(); } else { MessageBox.Show("No Results Found!"); } break; } case "_Show Live Results": { try { PublicStatistics.LiveStatstics.Show(); } catch { PublicStatistics.LiveStatstics = new UiLiveStatstics(); PublicStatistics.LiveStatstics.Show(); } break; } } } } catch (Exception exp) { MessageBox.Show(exp.Message, "MianWindow-btn_show_results"); } }