Example #1
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);
            }
        }
Example #2
0
        /// <summary>
        /// find x in inlist
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="inlist"></param>
        /// <returns></returns>
        private bool StillWithinMyRange(SinksAgentsRow x, List <SinksAgentsRow> inlist)
        {
            foreach (SinksAgentsRow rec in inlist)
            {
                if (rec.Sink.ID == x.Sink.ID)
                {
                    return(true);
                }
            }

            return(false);
        }
        private Packet GeneragtePacket(Sensor highTierGateWay, SinksAgentsRow reportSinkPositionRow)
        {
            PublicParamerters.NumberofGeneratedPackets += 1;
            Packet pck = new Packet();

            pck.Source             = highTierGateWay;
            pck.ReportSinkPosition = reportSinkPositionRow;
            pck.Path        = "" + highTierGateWay.ID;
            pck.Destination = null; // has no destination.
            pck.PacketType  = PacketType.ShareSinkPosition;
            pck.PID         = PublicParamerters.NumberofGeneratedPackets;
            counter.IncreasePacketsCounter(highTierGateWay, PacketType.ShareSinkPosition);
            return(pck);
        }
Example #4
0
        private Packet GeneragtePacket(SinksAgentsRow reportSinkPosition)
        {
            PublicParamerters.NumberofGeneratedPackets += 1;
            Packet pck = new Packet();

            pck.Source             = reportSinkPosition.AgentNode;
            pck.Path               = "" + reportSinkPosition.AgentNode.ID;
            pck.Destination        = null; // has no destination.
            pck.PacketType         = PacketType.ReportSinkPosition;
            pck.PID                = PublicParamerters.NumberofGeneratedPackets;
            pck.ReportSinkPosition = reportSinkPosition;
            pck.TimeToLive         = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(reportSinkPosition.AgentNode.CenterLocation, reportSinkPosition.ClosestPointOnTheDiagonal) / (PublicParamerters.CommunicationRangeRadius / Settings.Default.ComunTTL)));
            counter.IncreasePacketsCounter(reportSinkPosition.AgentNode, PacketType.ReportSinkPosition);
            return(pck);
        }
        public ShareSinkPositionIntheHighTier(Sensor highTierGateWay, SinksAgentsRow reportSinkPositionRow)
        {
            if (highTierGateWay.IsHightierNode)
            {
                counter = new NetworkOverheadCounter();
                Packet leftpacket = GeneragtePacket(highTierGateWay, reportSinkPositionRow);
                leftpacket.PacketDirection = PacketDirection.Left;
                Packet righttpacket = GeneragtePacket(highTierGateWay, reportSinkPositionRow);
                righttpacket.PacketDirection = PacketDirection.Right;
                SendPacket(highTierGateWay, leftpacket);
                SendPacket(highTierGateWay, righttpacket);


                //: SAVE Sink positions.// this is not agent record. becarful here
                highTierGateWay.AddSinkRecordInHighTierNode(reportSinkPositionRow);
            }
        }
Example #6
0
        public ReportSinkPositionMessage(SinksAgentsRow reportSinkPosition)
        {
            // node should not be a hightier
            if (!reportSinkPosition.AgentNode.IsHightierNode)
            {
                counter = new NetworkOverheadCounter();
                double x = (reportSinkPosition.AgentNode.CenterLocation.X + reportSinkPosition.AgentNode.CenterLocation.Y) / 2;
                reportSinkPosition.ClosestPointOnTheDiagonal = new Point(x, x);
                Packet packet = GeneragtePacket(reportSinkPosition);

                SendPacket(reportSinkPosition.AgentNode, packet);
                // check if the node isself is hightier node. here no need to generate ReportSinkPosition.
            }
            else
            {
                // node just generate sharesinkposition packet.
                // no need to report.
                ShareSinkPositionIntheHighTier xma = new ShareSinkPositionIntheHighTier(reportSinkPosition.AgentNode, reportSinkPosition);
            }
        }