예제 #1
0
        /// <summary>
        ///
        /// </summary>
        public void GeneratePacketAndSent()
        {
            List <RoutingMetric> Forwarders = MyForwardersShortedList;

            if (Forwarders != null)
            {
                ForwardersCoordination coordDinator = new ForwardersCoordination();
                RoutingMetric          nextHop      = coordDinator.SelectedForwarder(this, this);
                if (nextHop != null)
                {
                    NumberofPacketsGeneratedByMe++;
                    PublicParamerters.NumberofGeneratedPackets++;// public
                    Datapacket datap = new Datapacket(this, nextHop.PotentialForwarder);
                    datap.SourceNode               = this;
                    datap.SourceNodeID             = ID;
                    datap.Path                     = this.ID.ToString();
                    datap.DistanceFromSourceToSink = Operations.DistanceBetweenTwoSensors(PublicParamerters.SinkNode, this);
                    datap.PacektSequentID          = PublicParamerters.NumberofGeneratedPackets;
                    datap.MaxHops                  = ComputeMaxHops;
                    this.SwichToActive();
                    SendData(this, nextHop.PotentialForwarder, datap);// send the data:
                    this.lbl_Sensing_ID.Foreground = Brushes.Red;

                    if (Settings.Default.KeepLogs)
                    {
                        // HistoricalRelativityRows.AddRange(Forwarders);
                    }
                    else
                    {
                        Dispose();
                    }
                }
                else
                {
                    // has no forwarders then let him try:
                    PublicParamerters.NumberofGeneratedPackets++; // public
                    NumberofPacketsGeneratedByMe++;
                    Datapacket datap = new Datapacket();          // packet with no sender.
                    datap.SourceNode               = this;
                    datap.MaxHops                  = ComputeMaxHops;
                    datap.SourceNodeID             = ID;
                    datap.Path                     = this.ID.ToString();
                    datap.DistanceFromSourceToSink = Operations.DistanceBetweenTwoSensors(PublicParamerters.SinkNode, this);
                    datap.PacektSequentID          = PublicParamerters.NumberofGeneratedPackets;
                    SwichToActive();
                    this.lbl_Sensing_ID.Foreground = Brushes.Red;
                    RelayThePacket(this, datap);
                }
            }
            else
            {
                if (ID != PublicParamerters.SinkNode.ID)
                {
                    MessageBox.Show("Node:" + ID + "Has No Forwarders");
                }
            }
        }
예제 #2
0
        public void RelayThePacket(Sensor RelayNode, Datapacket datap)
        {
            List <RoutingMetric>   GetMyForw   = MyForwardersShortedList;
            ForwardersCoordination coordinator = new ForwardersCoordination();
            RoutingMetric          nextHop     = coordinator.SelectedForwarder(RelayNode, datap.SourceNode);

            if (nextHop != null) // not the sink
            {
                // no loop:
                Datapacket forwardPacket;
                forwardPacket                          = new Datapacket(RelayNode, nextHop.PotentialForwarder);
                forwardPacket.MaxHops                  = datap.MaxHops;
                forwardPacket.PacketWaitingTimes       = datap.PacketWaitingTimes;
                forwardPacket.SourceNodeID             = datap.SourceNodeID;
                forwardPacket.DistanceFromSourceToSink = datap.DistanceFromSourceToSink;
                forwardPacket.RoutingDistance          = datap.RoutingDistance;
                forwardPacket.Path                     = datap.Path;
                forwardPacket.Hops                     = datap.Hops;
                forwardPacket.UsedEnergy_Joule         = datap.UsedEnergy_Joule;
                forwardPacket.Delay                    = datap.Delay;
                forwardPacket.SourceNode               = datap.SourceNode;
                forwardPacket.PacektSequentID          = datap.PacektSequentID;

                if (IsThisPacketInTheWaitingList(RelayNode, datap))
                {
                    WaitingList.Remove(datap);
                }
                RelayNode.SendData(RelayNode, nextHop.PotentialForwarder, forwardPacket);
            }
            else
            {
                // wait:
                // waiting time.
                // the either all the nodes are sleep
                if (GetMyForw.Count > 0)
                {
                    datap.PacketWaitingTimes = datap.PacketWaitingTimes + 1;
                    if (!IsThisPacketInTheWaitingList(RelayNode, datap))
                    {
                        WaitingList.Add(datap);
                    }
                    RelayNode.DeliveerPacketsInQueuTimer.Start();
                }
                else
                {
                    // MessageBox.Show("This Node has no forwarders!");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 3d
        /// </summary>
        /// <param name="N"></param>
        /// <returns></returns>
        public double[,,] GetMatrix(List <Sensor> N)
        {
            int n = N.Count;

            double[,,] M = new double[Parameters.PublicParamerters.NumberofGeneratedPackets, n, n];
            List <RoutingMetric> L = new List <RoutingMetric>();

            foreach (Sensor s in N)
            {
                L.AddRange(s.MyForwardersShortedList);
            }

            for (int x = 0; x < L.Count; x++)
            {
                RoutingMetric row = L[x];
                int           k   = System.Convert.ToInt32(row.PID) - 1; // the path is starting from the 1.
                int           i   = row.SenderID;
                int           j   = row.ForwarderID;
                M[k, i, j] = row.LinkEstimationNormalized;
            }

            return(M);
        }