private void RecivePacket(Sensor Reciver, Packet packt)
        {
            if (Reciver == null) // packet is recived.
            {
                counter.SuccessedDeliverdPacket(packt);
                counter.DisplayRefreshAtReceivingPacket(packt.Source);
            }
            else
            {
                packt.Path += ">" + Reciver.ID;
                packt.ReTransmissionTry = 0;
                counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                Reciver.AddSinkRecordInHighTierNode(packt.ReportSinkPosition); // keep track of the sink position


                if (packt.Hops <= packt.TimeToLive)
                {
                    if (packt.PacketDirection == PacketDirection.Up)
                    {
                        Packet upPlacket = GeneragtePacket(Reciver, packt.ReportSinkPosition, PacketDirection.Up);
                        SendPacket(Reciver, upPlacket);
                    }
                    else
                    {
                        // down:
                        Packet downPlacket = GeneragtePacket(Reciver, packt.ReportSinkPosition, PacketDirection.Down);
                        SendPacket(Reciver, downPlacket);
                    }
                }
            }
        }
Example #2
0
        private void RecivePacket(Sensor Reciver, Packet packt)
        {
            packt.Path += ">" + Reciver.ID;
            if (loopMechan.isLoop(packt))
            {
                counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
            }
            else
            {
                packt.ReTransmissionTry = 0;
                if (Reciver.RingNodesRule.isRingNode) // packet is recived.
                {
                    packt.Destination = Reciver;

                    counter.SuccessedDeliverdPacket(packt);
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    counter.DisplayRefreshAtReceivingPacket(Reciver);
                    // share:

                    ShareSinkPositionIntheHighTier xma = new ShareSinkPositionIntheHighTier(Reciver, packt.ReportSinkPosition);
                }
                else
                {
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    if (packt.Hops <= packt.TimeToLive)
                    {
                        SendPacket(Reciver, packt);
                    }
                    else
                    {
                        counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
                    }
                }
            }
        }
Example #3
0
        private void RecivePacket(Sensor Reciver, Packet packt)
        {
            packt.Path += ">" + Reciver.ID;

            if (loopMechan.isLoop(packt))
            {
                counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
            }
            else
            {
                packt.ReTransmissionTry = 0;
                if (Reciver == packt.Destination)
                {
                    counter.SuccessedDeliverdPacket(packt);
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    Reciver.Ellipse_nodeTypeIndicator.Fill = Brushes.LightSlateGray; // mark
                    Reciver.IsHightierNode = true;

                    counter.DisplayRefreshAtReceivingPacket(Reciver);
                }
                else
                {
                    if (packt.Hops <= packt.TimeToLive)
                    {
                        // compute the overhead:
                        counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                        SendPacket(Reciver, packt);
                    }
                    else
                    {
                        counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
                    }
                }
            }
        }
Example #4
0
        private void RecivePacket(Sensor Reciver, Packet packt)
        {
            packt.Path += ">" + Reciver.ID;
            packt.ReTransmissionTry = 0;

            if (Reciver.ID == packt.Destination.ID) // packet is recived.
            {
                counter.SuccessedDeliverdPacket(packt);
                counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                counter.DisplayRefreshAtReceivingPacket(Reciver);
            }
            else
            {
                // compute the overhead:
                counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                if (packt.Hops <= packt.TimeToLive)
                {
                    SendPacket(Reciver, packt);
                }
                else
                {
                    counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
                }
            }
        }
Example #5
0
        /// <summary>
        /// hand the packet to my sink.
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="packt"></param>
        public void HandOffToTheSinkOrRecovry(Sensor agent, Packet packt)
        {
            // check how many sinks are there in my record
            if (agent != null)
            {
                if (packt.SinksAgentsList != null)
                {
                    // my sinks recored in the packet:
                    List <SinksAgentsRow> MysinksInPpaket          = GetMySinksFromPacket(agent.ID, packt.SinksAgentsList); // my sinks in the packet.
                    List <SinksAgentsRow> MyCurrentSinks           = agent.GetSinksAgentsList;                              //my sinks that currently within my range.
                    List <int>            SinksIDsRequiredRecovery = new List <int>();                                      //  sinks that required recovery. those sinks which are in the packet but not within my range anymore.

                    for (int i = 0; i < MysinksInPpaket.Count; i++)
                    {
                        SinksAgentsRow sinkInPacket = MysinksInPpaket[i];
                        // check if sink still within the range of the agent
                        bool stillWithinMyRange = StillWithinMyRange(sinkInPacket, MyCurrentSinks); // check if sink x  still within my range
                        if (stillWithinMyRange)
                        {
                            // I am an agent for more than one sink
                            // here we should increase the PID, otherwise the number of delivered packets will be more than the generated packets.
                            Packet pck  = Duplicate(packt, agent, true); // duplicate and increase the PID
                            Sink   sink = sinkInPacket.Sink;
                            pck.Path += "> Sink: " + sink.ID;
                            counter.SuccessedDeliverdPacket(pck);
                            counter.DisplayRefreshAtReceivingPacket(agent);
                        }
                        else
                        {
                            // sinkInPacket.Sink is out of agent range.
                            SinksIDsRequiredRecovery.Add(sinkInPacket.Sink.ID);
                        }
                    }

                    // recovery: SinksIDsRequiredRecovery
                    if (SinksIDsRequiredRecovery.Count > 0)
                    {
                        packt.SinkIDsNeedsRecovery = SinksIDsRequiredRecovery;
                        new RecoveryMessage(agent, packt);
                    }
                }
                else
                {
                    // drop the packet.
                    // i dont know when it should be null.
                    Console.Write(">>>>No agents. MergedPathsMessages->HandOffToTheSinkOrRecovry->packt.SinksAgentsList==null");
                    counter.DropPacket(packt, agent, PacketDropedReasons.Unknow);
                }
            }
            else
            {
                // drop the packet
                Console.Write(">>>>HandOffToTheSinkOrRecovry->agent = null");
                counter.DropPacket(packt, agent, PacketDropedReasons.Unknow);
            }
        }
        private void RecivePacket(Sensor Reciver, Packet packt)
        {
            packt.Path += ">" + Reciver.ID;
            if (loopMechan.isLoop(packt))
            {
                counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
            }
            else
            {
                packt.ReTransmissionTry = 0;
                if (Reciver.IsHightierNode) // packet is recived.
                {
                    packt.Destination = Reciver;
                    counter.SuccessedDeliverdPacket(packt);
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    counter.DisplayRefreshAtReceivingPacket(Reciver);
                    // response to the source:
                    if (packt.SinkIDsNeedsRecovery == null) // nomal
                    {
                        new ResonseSinkPositionMessage(Reciver, packt.Source);
                    }
                    else
                    {
                        // recovery packet.
                        new ResonseSinkPositionMessage(Reciver, packt.Source, packt.SinkIDsNeedsRecovery);
                    }

                    if (Reciver.ReachedBatterThresh)
                    {
                        RingNodeChange rch = new RingNodeChange();
                        rch.ChangeRingNode(Reciver.RingNodesRule);
                    }
                }
                else
                {
                    // compute the overhead:
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    if (packt.Hops <= packt.TimeToLive)
                    {
                        SendPacket(Reciver, packt);
                    }
                    else
                    {
                        counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
                    }
                }
            }
        }
 private void RecivePacket(Sensor Reciver, Packet packt)
 {
     if (Reciver == null) // packet is recived.
     {
         counter.SuccessedDeliverdPacket(packt);
         counter.DisplayRefreshAtReceivingPacket(packt.Source);
     }
     else
     {
         packt.Path += ">" + Reciver.ID;
         packt.ReTransmissionTry = 0;
         counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
         Reciver.AddSinkRecordInHighTierNode(packt.ReportSinkPosition); // keep track of the sink position
         SendPacket(Reciver, packt);
     }
 }
Example #8
0
        /// <summary>
        /// hand the packet to my sink.
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="packt"></param>
        private void HandOffToTheSinkOrRecovry(Sensor agent, Packet packt)
        {
            // check how many sinks are there in my record
            if (agent != null)
            {
                if (packt.SinksAgentsList != null)
                {
                    // the sinks in the packet:
                    List <SinksAgentsRow> MyinpacketSinks = GetMySinksFromPacket(agent, packt); // The sinks the agent has record of
                    // the sinks within my range.
                    List <SinksAgentsRow> inAgentList = agent.GetSinksAgentsList;
                    List <int>            SinksIDsRequiredRecovery = new List <int>(); // the sinks that required recovery.

                    foreach (SinksAgentsRow rowInpacket in MyinpacketSinks)
                    {
                        // check if sink still within the range of the agent
                        bool isFound = Find(rowInpacket, inAgentList);
                        if (isFound)
                        {
                            //
                            Sink sink = rowInpacket.Sink;
                            packt.Path += "> Sink: " + sink.ID;
                            counter.SuccessedDeliverdPacket(packt);
                        }
                        else
                        {    // the sinks is not within my range:
                            // change packet destination:
                            // keep this for recovery.
                            SinksIDsRequiredRecovery.Add(rowInpacket.Sink.ID);
                        }
                    }

                    // recovery: SinksIDsRequiredRecovery
                    if (SinksIDsRequiredRecovery.Count > 0)
                    {
                        packt.SinkIDsNeedsRecovery = SinksIDsRequiredRecovery;
                        new RecoveryMessage(agent, packt);
                    }
                }
                else
                {
                    // i dont know when it should be null.
                    counter.DropPacket(packt, agent, PacketDropedReasons.InformationError);
                    Console.Write("MergedPathsMessages->HandOffToTheSinkOrRecovry->packt.SinksAgentsList==null");
                }
            }
        }
 /// <summary>
 ///  the hightierNode should response to the lowtiernode.
 ///  here the respnse should contain all sinks.
 /// </summary>
 /// <param name="hightierNode"></param>
 /// <param name="sourceNode"></param>
 public ResonseSinkPositionMessage(Sensor hightierNode, Sensor sourceNode)
 {
     counter = new NetworkOverheadCounter();
     // the hightierNode=lowtiernode --> means that the high tier node itself has data to send.
     if (hightierNode.ID == sourceNode.ID)
     {
         // here high tier has data to send.
         Packet responspacket = GeneragtePacket(hightierNode, hightierNode, null, true); // fack.
         counter.SuccessedDeliverdPacket(responspacket);                                 // count it as delivered
         PreparDataTransmission(hightierNode, responspacket);
     }
     else
     {
         Packet responspacket = GeneragtePacket(hightierNode, sourceNode, null, true);
         SendPacket(hightierNode, responspacket);
     }
 }
        private void RecivePacket(Sensor Reciver, Packet packt)
        {
            packt.Path += ">" + Reciver.ID;
            if (new LoopMechanizimAvoidance(packt).isLoop)
            {
                // drop the packet:
                counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
            }
            else
            {
                packt.ReTransmissionTry = 0;
                if (Reciver.IsHightierNode) // packet is recived.
                {
                    packt.Destination = Reciver;
                    counter.SuccessedDeliverdPacket(packt);
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    counter.DisplayRefreshAtReceivingPacket(Reciver);

                    // response to the source:
                    if (packt.SinkIDsNeedsRecovery == null) // nomal
                    {
                        new ResonseSinkPositionMessage(Reciver, packt.Source);
                    }
                    else
                    {
                        // recovery packet.
                        // we can also save the record
                        new ResonseSinkPositionMessage(Reciver, packt.Source, packt.SinkIDsNeedsRecovery);
                    }
                }
                else
                {
                    // compute the overhead:
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    if (packt.Hops <= packt.TimeToLive)
                    {
                        SendPacket(Reciver, packt);
                    }
                    else
                    {
                        counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// obtian location for the sinks with IDs listed in SinkIDs.
        /// this is used in the recovery mechansim.
        /// when the agent node did not found its sinks.
        /// </summary>
        /// <param name="AgentNode"> the node that make the request.</param>
        /// <param name="SinkIDs"></param>
        public ObtainSinkFreshPositionMessage(Sensor AgentNode, List <int> SinkIDs)
        {
            counter = new NetworkOverheadCounter();

            // the high tier node has data.
            if (AgentNode.IsHightierNode)
            {
                Packet pack = GeneragtePacket(AgentNode, true);                // fack packet.
                pack.SinkIDsNeedsRecovery = SinkIDs;                           // not all sinks. this is for data recovery only.
                counter.SuccessedDeliverdPacket(pack);                         // count it as delivered
                new ResonseSinkPositionMessage(AgentNode, AgentNode, SinkIDs); // recovery.
            }
            else
            {
                AgentNode.Ellipse_nodeTypeIndicator.Fill = Brushes.Yellow;
                Packet ObtainSinkPositionPacket = GeneragtePacket(AgentNode, true);
                ObtainSinkPositionPacket.SinkIDsNeedsRecovery = SinkIDs; // not all sinks. this is for data recovery only.
                SendPacket(AgentNode, ObtainSinkPositionPacket);
            }
        }
Example #12
0
        /// <summary>
        /// obtian the position for all sinks.
        /// </summary>
        /// <param name="sensor"></param>
        public ObtainSinkFreshPositionMessage(Sensor sensor)
        {
            counter = new NetworkOverheadCounter();

            // the high tier node has data.
            if (sensor.IsHightierNode)
            {
                Packet pack = GeneragtePacket(sensor, true);
                pack.SinkIDsNeedsRecovery = null;
                counter.SuccessedDeliverdPacket(pack); // count it as delivered
                new ResonseSinkPositionMessage(sensor, sensor);
            }
            else
            {
                sensor.Ellipse_nodeTypeIndicator.Fill = Brushes.Yellow;
                Packet ObtainSinkPositionPacket = GeneragtePacket(sensor, true);
                ObtainSinkPositionPacket.SinkIDsNeedsRecovery = null;
                SendPacket(sensor, ObtainSinkPositionPacket);
            }
        }
        private void RecivePacket(Sensor Reciver, Packet packt)
        {
            packt.Path += ">" + Reciver.ID;
            if (LoopMechan.isLoop(packt))
            {
                // drop the packet:
                counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
            }
            else
            {
                packt.ReTransmissionTry = 0;

                if (Reciver.CenterLocation == packt.Destination) // packet is recived.
                {
                    if (packt.SinksAgentsList.Count == 0)
                    {
                        Console.WriteLine("SinksAgentsList.Count == 0 " + "Source " + packt.Source.ID);
                    }

                    counter.SuccessedDeliverdPacket(packt);
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    counter.DisplayRefreshAtReceivingPacket(Reciver);
                    Reciver.Ellipse_nodeTypeIndicator.Fill = Brushes.Transparent;
                    PreparDataTransmission(Reciver, packt); // the merge path
                }
                else
                {
                    // compute the overhead:
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    if (packt.Hops <= packt.TimeToLive)
                    {
                        SendPacket(Reciver, packt);
                    }
                    else
                    {
                        counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
                    }
                }
            }
        }
 private void RecivePacket(Sensor Reciver, Packet packt)
 {
     packt.Path += ">" + Reciver.ID;
     if (loopMechan.isLoop(packt))
     {
         counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
     }
     else
     {
         packt.ReTransmissionTry = 0;
         if (Reciver.IsHightierNode)
         {
             if (Reciver.AlreadyRecievedAgentInfo(packt.ReportSinkPosition)) // packet is recived.
             {
                 // Console.WriteLine("****Success ANPIS : " + Reciver.ID);
                 counter.SuccessedDeliverdPacket(packt);
                 counter.DisplayRefreshAtReceivingPacket(packt.Source);
             }
             else
             {
                 Reciver.AddSinkRecordInHighTierNode(packt.ReportSinkPosition); // keep track of the sink position
                 counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                 SendPacket(Reciver, packt);
             }
         }
         else
         {
             if (packt.Hops <= packt.TimeToLive)
             {
                 SendPacket(Reciver, packt);
             }
             else
             {
                 counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
             }
         }
     }
 }
        /// <summary>
        /// obtian the position for all sinks.
        /// </summary>
        /// <param name="sourceNode"></param>
        public ObtainSinkFreshPositionMessage(Sensor sourceNode)
        {
            counter = new NetworkOverheadCounter();

            // the high tier node has data.
            if (sourceNode.RingNodesRule.isRingNode)
            {
                //Directly send data to the access nodes that u have
                //No need to send a query request and wait for response
                Packet pack = GeneratePacket(sourceNode, true);
                pack.SinkIDsNeedsRecovery = null;
                counter.SuccessedDeliverdPacket(pack); // considere the obtian packet as delivred.
                new ResonseSinkPositionMessage(sourceNode, sourceNode);
            }
            else
            {
                //Regular sensor node disseminating data start with QReq
                sourceNode.Ellipse_nodeTypeIndicator.Fill = Brushes.Yellow;
                Packet QReq = GeneratePacket(sourceNode, true);
                QReq.SinkIDsNeedsRecovery = null;
                SendPacket(sourceNode, QReq);
            }
        }
Example #16
0
        private void RecivePacket(Sensor Reciver, Packet packt)
        {
            packt.Path += ">" + Reciver.ID;
            if (new LoopMechanizimAvoidance(packt).isLoop)
            {
                // drop the packet:
                counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
            }
            else
            {
                packt.ReTransmissionTry = 0;

                if (Reciver.ID == packt.Destination.ID) // packet is recived.
                {
                    counter.SuccessedDeliverdPacket(packt);
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    counter.DisplayRefreshAtReceivingPacket(Reciver);
                    Reciver.Ellipse_nodeTypeIndicator.Fill = Brushes.Transparent;


                    PreparDataTransmission(Reciver, packt); // the merge path
                }
                else
                {
                    // compute the overhead:
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    if (packt.Hops <= packt.TimeToLive)
                    {
                        SendPacket(Reciver, packt);
                    }
                    else
                    {
                        counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
                    }
                }
            }
        }