/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="Reciver"></param> /// <param name="packt"></param> public void SendPacekt(Packet packt) { if (packt.PacketType == PacketType.Data) { lock (MiniFlowTable) { MiniFlowTable.Sort(new MiniFlowTableSorterUpLinkPriority()); MiniFlowTableEntry flowEntry = MatchFlow(packt); if (flowEntry != null) { Sensor Reciver = flowEntry.NeighborEntry.NeiNode; // sender swich on the redio: // SwichToActive(); ComputeOverhead(packt, EnergyConsumption.Transmit, Reciver); Console.WriteLine("sucess:" + ID + "->" + Reciver.ID + ". PID: " + packt.PID); flowEntry.UpLinkStatistics += 1; // Reciver.SwichToActive(); Reciver.ReceivePacket(packt); // SwichToSleep();// . } else { // no available node right now. // add the packt to the wait list. Console.WriteLine("NID:" + ID + " Faild to sent PID:" + packt.PID); WaitingPacketsQueue.Enqueue(packt); QueuTimer.Start(); Console.WriteLine("NID:" + ID + ". Queu Timer is started."); // SwichToSleep();// this. if (Settings.Default.ShowRadar) { Myradar.StartRadio(); } PublicParamerters.MainWindow.Dispatcher.Invoke(() => Ellipse_indicator.Fill = Brushes.DeepSkyBlue); PublicParamerters.MainWindow.Dispatcher.Invoke(() => Ellipse_indicator.Visibility = Visibility.Visible); } } } else if (packt.PacketType == PacketType.Control) { lock (MiniFlowTable) { DownLinkRouting.GetD_Distribution(this, packt.Destination); MiniFlowTableEntry FlowEntry = MatchFlow(packt); if (FlowEntry != null) { Sensor Reciver = FlowEntry.NeighborEntry.NeiNode; // sender swich on the redio: // SwichToActive(); // this. ComputeOverhead(packt, EnergyConsumption.Transmit, Reciver); FlowEntry.DownLinkStatistics += 1; // Reciver.SwichToActive(); Reciver.ReceivePacket(packt); // SwichToSleep();// this. } else { // no available node right now. // add the packt to the wait list. Console.WriteLine("NID:" + this.ID + " Faild to sent PID:" + packt.PID); WaitingPacketsQueue.Enqueue(packt); QueuTimer.Start(); Console.WriteLine("NID:" + this.ID + ". Queu Timer is started."); // SwichToSleep();// sleep. if (Settings.Default.ShowRadar) { Myradar.StartRadio(); } PublicParamerters.MainWindow.Dispatcher.Invoke(() => Ellipse_indicator.Fill = Brushes.DeepSkyBlue); PublicParamerters.MainWindow.Dispatcher.Invoke(() => Ellipse_indicator.Visibility = Visibility.Visible); } } } }
/// <summary> /// /// </summary> /// <param name="packt"></param> /// <param name="enCon"></param> /// <param name="Reciver"></param> public void ComputeOverhead(Packet packt, EnergyConsumption enCon, Sensor Reciver) { if (enCon == EnergyConsumption.Transmit) { if (ID != PublicParamerters.SinkNode.ID) { // calculate the energy double Distance_M = Operations.DistanceBetweenTwoSensors(this, Reciver); double UsedEnergy_Nanojoule = EnergyModel.Transmit(packt.PacketLength, Distance_M); double UsedEnergy_joule = ConvertToJoule(UsedEnergy_Nanojoule); ResidualEnergy = this.ResidualEnergy - UsedEnergy_joule; PublicParamerters.TotalEnergyConsumptionJoule += UsedEnergy_joule; packt.UsedEnergy_Joule += UsedEnergy_joule; packt.RoutingDistance += Distance_M; packt.Hops += 1; double delay = DelayModel.DelayModel.Delay(this, Reciver); packt.Delay += delay; PublicParamerters.TotalDelayMs += delay; if (Settings.Default.SaveRoutingLog) { RoutingLog log = new RoutingLog(); log.PacketType = PacketType.Data; log.IsSend = true; log.NodeID = this.ID; log.Operation = "To:" + Reciver.ID; log.Time = DateTime.Now; log.Distance_M = Distance_M; log.UsedEnergy_Nanojoule = UsedEnergy_Nanojoule; log.RemaimBatteryEnergy_Joule = ResidualEnergy; log.PID = packt.PID; this.Logs.Add(log); } // for control packet. if (packt.PacketType == PacketType.Control) { // just to remember how much energy is consumed here. PublicParamerters.EnergyComsumedForControlPackets += UsedEnergy_joule; } } if (Settings.Default.ShowRoutingPaths) { OpenChanel(Reciver.ID, packt.PID); } } else if (enCon == EnergyConsumption.Recive) { double UsedEnergy_Nanojoule = EnergyModel.Receive(packt.PacketLength); double UsedEnergy_joule = ConvertToJoule(UsedEnergy_Nanojoule); ResidualEnergy = ResidualEnergy - UsedEnergy_joule; packt.UsedEnergy_Joule += UsedEnergy_joule; PublicParamerters.TotalEnergyConsumptionJoule += UsedEnergy_joule; if (packt.PacketType == PacketType.Control) { // just to remember how much energy is consumed here. PublicParamerters.EnergyComsumedForControlPackets += UsedEnergy_joule; } } }
public int ComputeMaxHopsDownlink(Sensor endNode) { double DIS = Operations.DistanceBetweenTwoSensors(PublicParamerters.SinkNode, endNode); return(Convert.ToInt16(Math.Ceiling((Math.Sqrt(PublicParamerters.Density) * (DIS / ComunicationRangeRadius))))); }