Beispiel #1
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);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
Beispiel #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 (packt.Destination.ID == Reciver.ID)
                {
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    counter.DisplayRefreshAtReceivingPacket(Reciver);
                    HandOffToTheSinkOrRecovry(Reciver, packt);
                }
                else
                {
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    counter.DisplayRefreshAtReceivingPacket(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) // 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)
        {
            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);
                    }
                }
            }
        }
        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);
                }
            }
        }
Beispiel #7
0
 public void SendPacket(Sensor sender, Packet pck)
 {
     if (pck.PacketType == PacketType.Data)
     {
         // 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.DropPacket(pck, sender, PacketDropedReasons.Loop);
         }
     }
 }
        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);
                    }
                }
            }
        }
Beispiel #9
0
        // try.
        private void DeliveerPacketsInQueuTimer_Tick(object sender, EventArgs e)
        {
            Packet waitingpacket = WaitingPacketsQueue.Dequeue();

            waitingpacket.ReTransmissionTry++;
            if (waitingpacket.ReTransmissionTry <= Settings.Default.ReTransmissionAttemps)
            {
                // Console.WriteLine(waitingpacket.PID + ">>>" + waitingpacket.ReTransmissionTry);
                switch (waitingpacket.PacketType)
                {
                case PacketType.ReportSinkPosition:
                    new ReportSinkPositionMessage().HandelInQueuPacket(this, waitingpacket);
                    break;

                case PacketType.ShareSinkPosition:
                    new ShareSinkPositionIntheHighTier().HandelInQueuPacket(this, waitingpacket);
                    break;

                case PacketType.ObtainSinkPosition:
                    new ObtainSinkFreshPositionMessage().HandelInQueuPacket(this, waitingpacket);
                    break;

                case PacketType.ResponseSinkPosition:
                    new ResonseSinkPositionMessage().HandelInQueuPacket(this, waitingpacket);
                    break;

                case PacketType.Data:
                    new MergedPathsMessages().HandelInQueuPacket(this, waitingpacket);
                    break;
                }
            }
            else
            {
                // the packet should be droped here:
                counter.DropPacket(waitingpacket, this, PacketDropedReasons.WaitingTime);
            }


            if (WaitingPacketsQueue.Count == 0)
            {
                if (Settings.Default.ShowRadar)
                {
                    Myradar.StopRadio();
                }
                QueuTimer.Stop();
                MainWindow.Dispatcher.Invoke(() => Ellipse_indicator.Fill       = Brushes.Transparent);
                MainWindow.Dispatcher.Invoke(() => Ellipse_indicator.Visibility = Visibility.Hidden);

                // dont have data any mode than sleep:
                SwichToSleep();
            }
        }
        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);
                    }
                }
            }
        }
Beispiel #11
0
 private void RecivePacket(Sensor Reciver, Packet packt)
 {
     if (LoopMechan.isLoop(packt))
     {
         counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
     }
     else
     {
         // flooooding.
         if (Reciver.IsHightierNode == false)
         {
             // Recivece the packe and send it.
             counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
             Reciver.IsHightierNode = true; // let each node send once.
             counter.DisplayRefreshAtReceivingPacket(Reciver);
             SendPacket(Reciver, packt);
         }
     }
 }
Beispiel #12
0
        private void RecivePacket(Sensor Reciver, Packet packt)
        {
            // string cluster = packt.Branch.Cluster.MembersString;
            packt.Path += ">" + Reciver.ID;

            // if Reciver is an agent, then reciev the packet and remove the Reciver from the cluster
            // reFindBranches if the cluster still have more members.
            if (new LoopMechanizimAvoidance(packt).isLoop)
            {
                // drop the packet:
                packt.IsLooped = true;
                counter.DropPacket(packt, Reciver, PacketDropedReasons.Loop);
            }
            else
            {
                // not loop:
                packt.ReTransmissionTry = 0;
                if (Operations.FindInAlist(Reciver, packt.Branch.Cluster.Members) != null)
                {
                    // Reciver is an agent:
                    counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                    counter.DisplayRefreshAtReceivingPacket(Reciver);
                    // when the packet arrived to Reciver and holds more clustreds. this case reclustring process should be performed.
                    if (packt.Branch.Cluster.Members.Count > 0)
                    {
                        packt.Branch.Cluster.Members.Remove(Reciver);
                        List <Branch> Branches = FindBranches.GetBranches(packt.Branch.Cluster.Members, Reciver.CenterLocation, PublicParamerters.MainWindow.Canvas_SensingFeild, Settings.Default.MaxClusteringThreshold);
                        if (Branches.Count > 0)
                        {
                            MergedPathsMessages merged = new MergedPathsMessages(Reciver, Branches, packt);
                        }
                    }

                    HandOffToTheSinkOrRecovry(Reciver, packt);
                }
                else
                {
                    double dis1    = Operations.DistanceBetweenTwoPoints(Reciver.CenterLocation, packt.Branch.EndPoint);
                    double dis2    = Operations.DistanceBetweenTwoPoints(Reciver.CenterLocation, packt.Branch.Cluster.Centeriod);
                    double disThre = PublicParamerters.CommunicationRangeRadius;
                    if ((dis1 < disThre) && (packt.Branch.Cluster.Members.Count > 1))
                    {
                        double clusteringThreshould = 0;
                        if (dis2 <= disThre)
                        {
                            clusteringThreshould = Settings.Default.MinClusteringThreshold;
                        }
                        else
                        {
                            clusteringThreshould = Settings.Default.MaxClusteringThreshold;
                        }
                        counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                        List <Branch> Branches = FindBranches.GetBranches(packt.Branch.Cluster.Members, Reciver.CenterLocation, PublicParamerters.MainWindow.Canvas_SensingFeild, clusteringThreshould);
                        if (Branches.Count > 1)
                        {
                            MergedPathsMessages merged = new MergedPathsMessages(Reciver, Branches, packt);
                        }
                        else
                        {
                            counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                            packt.Branch = Branches[0]; // the branch is not changed. only the end coordinat of the branch is changed.
                            SendPacket(Reciver, packt);
                        }
                    }
                    else
                    {
                        counter.ComputeOverhead(packt, EnergyConsumption.Recive, null, Reciver);
                        if (packt.Hops <= packt.TimeToLive)
                        {
                            SendPacket(Reciver, packt);
                        }
                        else
                        {
                            counter.DropPacket(packt, Reciver, PacketDropedReasons.TimeToLive);
                            // since we did not count PID during the generation, thuse we should add here:
                            PublicParamerters.NumberofGeneratedPackets += 1;
                            packt.PID = PublicParamerters.NumberofGeneratedPackets;
                            counter.IncreasePacketsCounter(Reciver, PacketType.Data); //
                        }
                    }
                }
            }
        }
Beispiel #13
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;
                    }
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// preAgent: the packet will arrived to this  agent. This agent did not know the location of the new agent for the SinksIDsRequiredRecovery.
        /// </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.
                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 row in preAgent.RecoveryRow.RecoveryAgentList)      // get the agents
                    {
                        if (row.AgentNode.ID != preAgent.ID)                                    // no the same agent. the new one should had diffrent ID
                        {
                            bool isFound = Operations.FindInAlistbool(row.AgentNode, NewAents); // no repeatation
                            if (!isFound)
                            {
                                packet.Destination = row.AgentNode; // update the packet destination.
                                NewAents.Add(row.AgentNode);
                            }
                        }
                    }

                    if (NewAents.Count > 0)
                    {
                        Console.WriteLine("RecoveryMessage. Source ID=" + packet.Source.ID + " PID=" + packet.PID + " Path " + packet.Path);
                        packet.SinksAgentsList = preAgent.RecoveryRow.RecoveryAgentList;
                        if (packet.Hops <= packet.TimeToLive)
                        {
                            new DataPacketMessages(preAgent, packet);
                        }
                        else
                        {
                            NetworkOverheadCounter counter = new NetworkOverheadCounter();
                            counter.DropPacket(packet, preAgent, PacketDropedReasons.Loop);
                        }
                    }
                    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);
                        }
                        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;
                    }
                }
            }
        }