Ejemplo n.º 1
0
        private void SendPacket(Sensor sender, Packet pck)
        {
            if (pck.PacketType == PacketType.ReportSinkPosition)
            {
                // neext hope:
                Sensor Reciver;
                sender.SwichToActive(); // switch on me.
                if (sender.RingNeighborRule.isNeighbor)
                {
                    if (sender.RingNeighborRule.NearestRingNode != null)
                    {
                        RingNeighborSendPacket(sender, pck);
                        return;
                    }
                }


                Reciver = SelectNextHop(sender, pck);
                if (Reciver != null)
                {
                    counter.ComputeOverhead(pck, EnergyConsumption.Transmit, sender, Reciver);
                    counter.Animate(sender, Reciver, pck);
                    RecivePacket(Reciver, pck);
                }
                else
                {
                    // wait:
                    counter.SaveToQueue(sender, pck);
                }
            }
        }
Ejemplo n.º 2
0
        private void SendPacket(Sensor sender, Packet pck)
        {
            if (pck.PacketType == PacketType.ShareSinkPosition)
            {
                sender.SwichToActive();
                // neext hope:
                // note: here the Reciver is null for two reasons:
                //1- it is in sleep mode.
                //- the current sender has no more right or left diaogonal nodes.
                if (pck.PacketDirection == PacketDirection.Right)
                {
                    if (sender.RightVldNeighbor != null)
                    {
                        if (sender.RightVldNeighbor.CurrentSensorState == SensorState.Active)
                        {
                            counter.ComputeOverhead(pck, EnergyConsumption.Transmit, sender, sender.RightVldNeighbor);


                            counter.Animate(sender, sender.RightVldNeighbor, pck);

                            RecivePacket(sender.RightVldNeighbor, pck);
                        }
                        else
                        {
                            // wait:
                            counter.SaveToQueue(sender, pck);
                        }
                    }
                    else
                    {
                        pck.Destination = sender; // arrived to dest.
                        RecivePacket(null, pck);
                    }
                }
                else
                {
                    if (sender.LeftVldNeighbor != null)
                    {
                        if (sender.LeftVldNeighbor.CurrentSensorState == SensorState.Active)
                        {
                            counter.ComputeOverhead(pck, EnergyConsumption.Transmit, sender, sender.LeftVldNeighbor);

                            counter.Animate(sender, sender.LeftVldNeighbor, pck);

                            RecivePacket(sender.LeftVldNeighbor, pck);
                        }
                        else
                        {
                            // wait:
                            counter.SaveToQueue(sender, pck);
                        }
                    }
                    else
                    {
                        pck.Destination = sender; // arrived to dest.
                        RecivePacket(null, pck);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void SendPacket(Sensor sender, Packet pck)
        {
            if (pck.PacketType == PacketType.ShareSinkPosition)
            {
                Sensor destination;


                if (pck.PacketDirection == PacketDirection.Right)
                {
                    destination = sender.RingNodesRule.AntiClockWiseNeighbor;
                }
                else
                {
                    destination = sender.RingNodesRule.ClockWiseNeighbor;
                }

                if (destination != null)
                {
                    if (!Operations.isInMyComunicationRange(sender, destination))
                    {
                        pck.Destination = destination;
                        SendANPISWithRelay(sender, pck);
                        return;
                    }

                    if (destination.CurrentSensorState == SensorState.Active)
                    {
                        counter.ComputeOverhead(pck, EnergyConsumption.Transmit, sender, destination);
                        counter.Animate(sender, destination, pck);
                        RecivePacket(destination, pck);
                    }
                    else
                    {
                        // wait:
                        counter.SaveToQueue(sender, pck);
                    }
                }
                else
                {
                    //Drop the packet something went wrong
                    counter.DropPacket(pck, sender, PacketDropedReasons.RingNodesError);
                }
            }
        }
Ejemplo n.º 4
0
 private void SendPacket(Sensor sender, Packet pck)
 {
     if (pck.PacketType == PacketType.ObtainSinkPosition)
     {
         // neext hope:
         sender.SwichToActive();
         Sensor Reciver = SelectNextHop(sender, pck);
         if (Reciver != null)
         {
             // overhead:
             counter.ComputeOverhead(pck, EnergyConsumption.Transmit, sender, Reciver);
             counter.Animate(sender, Reciver, pck);
             RecivePacket(Reciver, pck);
         }
         else
         {
             counter.SaveToQueue(sender, pck);
         }
     }
 }
Ejemplo n.º 5
0
 public void SendPacket(Sensor sender, Packet pck)
 {
     if (pck.PacketType == PacketType.Data)
     {
         sender.SwichToActive();
         // neext hope:
         Sensor Reciver = SelectNextHop(sender, pck);
         if (Reciver != null)
         {
             // overhead:
             counter.ComputeOverhead(pck, EnergyConsumption.Transmit, sender, Reciver);
             counter.Animate(sender, Reciver, pck);
             RecivePacket(Reciver, pck);
         }
         else
         {
             counter.SaveToQueue(sender, pck); // save in the queue.
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// preAgent send an obtian packet to ask for the new agent of the sink.
        /// </summary>
        /// <param name="preAgent"></param>
        /// <param name="SinksIDsRequiredRecovery"></param>
        public RecoveryMessage(Sensor preAgent, Packet packet)
        {
            // preAgent: if it has no record, then we obtian the sink position first.
            // if the preAgent did not sent an obtian message to the hightier node
            if (preAgent.RecoveryRow == null)
            {
                // obtian the recovery. obtian the sink location.
                Console.WriteLine("RecoveryMessage. >>>>Trying to recover the packet. Source ID=" + packet.Source.ID + " PID=" + packet.PID + " Path " + packet.Path);
                new ObtainSinkFreshPositionMessage(preAgent, packet.SinkIDsNeedsRecovery);
            }
            else
            {
                // it has record. no need to resend an obtian: but you should wait.
                if (!preAgent.RecoveryRow.IsExpired)
                {
                    // not expired
                    List <Sensor> NewAents = new List <Sensor>(); // new agent for the recovery.
                    foreach (SinksAgentsRow newAgentRow in preAgent.RecoveryRow.RecoveryAgentList)
                    {
                        if (newAgentRow.AgentNode.ID != preAgent.ID)
                        {
                            bool isFound = Operations.FindInAlistbool(newAgentRow.AgentNode, NewAents);
                            if (!isFound)
                            {
                                packet.Destination = newAgentRow.AgentNode;
                                NewAents.Add(newAgentRow.AgentNode);
                            }
                        }
                    }

                    // if we found the new agent.
                    if (NewAents.Count > 0)
                    {
                        Console.WriteLine("RecoveryMessage. Source ID=" + packet.Source.ID + " PID=" + packet.PID + " Path " + packet.Path);
                        List <Branch> Branches = FindBranches.GetBranches(NewAents, preAgent.CenterLocation, PublicParamerters.MainWindow.Canvas_SensingFeild, Settings.Default.MaxClusteringThreshold);

                        packet.SinksAgentsList = preAgent.RecoveryRow.RecoveryAgentList;
                        new MergedPathsMessages(preAgent, Branches, packet);
                    }
                    else
                    {
                        if (preAgent.RecoveryRow.ObtainPacketsRetry >= 3)
                        {
                            // in case no new agent is found.
                            Console.WriteLine("RecoveryMessage. No agent is found during the recovery.Source ID = " + packet.Source.ID + " PID = " + packet.PID + " Path " + packet.Path);
                            NetworkOverheadCounter counter = new NetworkOverheadCounter();
                            // counter.DropPacket(packet, preAgent, PacketDropedReasons.RecoveryNoNewAgentFound);
                            counter.SaveToQueue(preAgent, packet);
                        }
                        else
                        {
                            Console.WriteLine("RecoveryMessage. Recovery period is expired. Old Agent is sending new obtain packet!" + " Path " + packet.Path);
                            new ObtainSinkFreshPositionMessage(preAgent, packet.SinkIDsNeedsRecovery); // obtain
                        }
                    }
                }
                else
                {
                    // resent the obtian packet. 2 times.
                    if (preAgent.RecoveryRow.ObtainPacketsRetry <= 3)
                    {
                        Console.WriteLine("RecoveryMessage. Recovery period is expired. Old Agent is sending new obtain packet!" + " Path " + packet.Path);
                        new ObtainSinkFreshPositionMessage(preAgent, packet.SinkIDsNeedsRecovery); // obtain
                    }
                    else
                    {
                        Console.WriteLine("RecoveryMessage. Recovery period is expired. we tryied to re-sent the obtian packet for three times and faild. The packet will be droped." + " Path " + packet.Path);
                        // drop the packet:
                        NetworkOverheadCounter counter = new NetworkOverheadCounter();
                        counter.DropPacket(packet, preAgent, PacketDropedReasons.RecoveryPeriodExpired);
                        preAgent.RecoveryRow = null;
                    }
                }
            }
        }