Exemple #1
0
        public IOTReader(int id, int org)
            : base(id, org)
        {
            this.global = (IOTGlobal)Global.getInstance();
            this.orgMonitorMapping = new Dictionary<int, List<int>>();
            this.cachedMonitorNodes = new Dictionary<int, HashSet<int>>();
            this.readerType = ReaderType.NORMAL;
            this.observedPhenomemons = new HashSet<IOTPhenomemon>();
            this.neighborSpeedPhenomemons = new Dictionary<int, IOTPhenomemon>();

            IOTPhenomemon p = new IOTPhenomemon(IOTPhenomemonType.MOVE_FAST, id);
            this.neighborSpeedPhenomemons.Add(id, p);
            this.observedPhenomemons.Add(p);

            CheckRoutine();
        }
Exemple #2
0
        public IOTReader(int id, int org)
            : base(id, org)
        {
            this.ReaderCache = new Dictionary<int, RSUEntity>();
            this.wiredNodeCache = new List<int>();
            this.orgMonitorMapping = new Dictionary<int, List<int>>();
            this.cachedMonitorNodes = new Dictionary<int, HashSet<int>>();
            this.readerType = ReaderType.NORMAL;
            this.observedPhenomemons = new HashSet<IOTPhenomemon>();
            this.neighborSpeedPhenomemons = new Dictionary<int, IOTPhenomemon>();

            IOTPhenomemon p = new IOTPhenomemon(IOTPhenomemonType.MOVE_FAST, id);
            this.neighborSpeedPhenomemons.Add(id, p);
            this.observedPhenomemons.Add(p);

            CheckRoutine();
        }
Exemple #3
0
        void CheckTimeoutPhenomemons()
        {
            double sendTimeout = global.sendPacketTimeout;
            List<IOTPhenomemon> temp1 = new List<IOTPhenomemon>();
            List<IOTPhenomemon> temp2 = new List<IOTPhenomemon>();
            foreach (IOTPhenomemon p in this.observedPhenomemons)
            {
                if (p.type == IOTPhenomemonType.RECV_PACKET && scheduler.currentTime - p.start > sendTimeout)
                {
                    IOTPhenomemon foundSend = null, foundNotSend = null;
                    foreach (IOTPhenomemon p1 in this.observedPhenomemons)
                    {
                        if (p1.pkg == null)
                            continue;
                        //找到该节点对该数据包的操作
                        if (Packet.IsSamePacket(p1.pkg, p.pkg) &&
                            p1.nodeId == p.nodeId)
                        {
                            if (p1.type == IOTPhenomemonType.SEND_PACKET)
                            {
                                foundSend = p1;
                                continue;
                            }
                            else if (p1.type == IOTPhenomemonType.NOT_SEND_PACKET)
                            {
                                p1.end = scheduler.currentTime;
                                foundNotSend = p1;
                                continue;
                            }
                            else
                                continue;
                        }
                    }

                    if (foundSend != null && foundNotSend != null)
                    {
                        temp2.Add(foundNotSend);
                    }
                    else if (foundSend == null && foundNotSend == null)
                    {
                        IOTPhenomemon p2 = new IOTPhenomemon(IOTPhenomemonType.NOT_SEND_PACKET, p.nodeId, p.start, scheduler.currentTime, p.pkg);
                        p2.likehood = global.checkTimeoutPhenomemonLikehood;
                        temp1.Add(p2);
                    }
                }
            }
            foreach (IOTPhenomemon p in temp1)
            {
                this.observedPhenomemons.Add(p);
            }
            foreach (IOTPhenomemon p in temp2)
            {
                this.observedPhenomemons.Remove(p);
            }
        }
Exemple #4
0
        void CheckNodeSpeeds()
        {
            foreach (KeyValuePair<int, Neighbor> k in this.Neighbors)
            {
                int node = k.Key;
                Neighbor nb = k.Value;

                //节点无法测出邻居的距离,但是可以根据信号强弱估计出,为简化,此处直接给出两点距离。
                double speed = global.readers[node].GetCurrentSpeed();
                if (!this.neighborSpeedPhenomemons.ContainsKey(node))
                {
                    IOTPhenomemon p = new IOTPhenomemon(IOTPhenomemonType.MOVE_FAST, node);
                    p.start = 0;
                    this.neighborSpeedPhenomemons.Add(node, p);
                    this.observedPhenomemons.Add(p);
                }
                this.neighborSpeedPhenomemons[node].start = this.neighborSpeedPhenomemons[node].end;
                this.neighborSpeedPhenomemons[node].end = scheduler.currentTime;
                this.neighborSpeedPhenomemons[node].likehood = Math.Min(speed / global.nodeSpeedThreahold + global.SmallValue, 0.9);
            }
            this.neighborSpeedPhenomemons[Id].start = this.neighborSpeedPhenomemons[Id].end;
            this.neighborSpeedPhenomemons[Id].end = scheduler.currentTime;
            double s = GetCurrentSpeed();
            this.neighborSpeedPhenomemons[Id].likehood = Math.Min(s / global.nodeSpeedThreahold + global.SmallValue, 0.9);
        }
Exemple #5
0
        void CheckNetworkBandwidth()
        {
            if (this.bandwidthPhenomemon == null)
                this.bandwidthPhenomemon = new IOTPhenomemon(IOTPhenomemonType.BANDWIDTH_BUSY, this.Id);

            this.bandwidthPhenomemon.start = this.bandwidthPhenomemon.end;
            this.bandwidthPhenomemon.end = scheduler.currentTime;
            this.bandwidthPhenomemon.likehood = Math.Min(this.totalReceivedPackets / global.totalPacketThreahold + global.SmallValue, 0.9);
            if (!this.observedPhenomemons.Contains(this.bandwidthPhenomemon))
                this.observedPhenomemons.Add(this.bandwidthPhenomemon);
            this.totalReceivedPackets = 0;
        }
Exemple #6
0
        //将接收到的数据包添加到观察到的现象中
        public void AddReceivePacketPhenomemon(Packet pkg)
        {
            IOTPhenomemon p;
            this.totalReceivedPackets++;
            //忽略广播包(从实际来看,发送广播包的一般是节点本身的行为,不需要考虑其对数据包的恶意操作)
            if (pkg.Next == BroadcastNode.Node.Id)
                return;

            //记录发送现象
            if (pkg.Next != BroadcastNode.Node.Id)
            {
                p = new IOTPhenomemon(IOTPhenomemonType.SEND_PACKET, pkg.Prev, scheduler.currentTime, pkg);
                p.likehood = global.sendLikehood;
                this.observedPhenomemons.Add(p);
                if(global.debug)
                    Console.WriteLine("[Debug] reader{0} add a RECV phenomemon of reader{1}", Id, pkg.Next);
            }

            //数据包到达目的地,忽略

            //记录接收现象
            if (pkg.Next != pkg.Dst)
            {
                p = new IOTPhenomemon(IOTPhenomemonType.RECV_PACKET, pkg.Next, scheduler.currentTime, pkg);
                p.likehood = global.recvLikehood;
                this.observedPhenomemons.Add(p);
                if(global.debug)
                    Console.WriteLine("[Debug] reader{0} add a SEND phenomemon of reader{1}", Id, pkg.Prev);
            }
        }
 static double ConditionHappened(HashSet<IOTPhenomemon> observedPhenomemons, IOTPhenomemonType type, int node,
     double starttime, double endtime, IOTPhenomemon p1, ComparePhenomemon comparer)
 {
     foreach (IOTPhenomemon p in observedPhenomemons)
     {
         if (p.nodeId == node && p.type == type
             && p.start >= starttime && p.end <= endtime
             && comparer(p1, p))
         {
             return p.likehood;
         }
     }
     return global.SmallValue;
 }
 static double ConditionHappened(HashSet<IOTPhenomemon> observedPhenomemons, IOTPhenomemonType type, int node,
     double starttime, double endtime, IOTPhenomemon p1, List<IOTPhenomemon> list, ComparePhenomemon comparer)
 {
     double likehood = global.SmallValue;
     foreach (IOTPhenomemon p in observedPhenomemons)
     {
         if (p.nodeId == node && p.type == type
             && p.start >= starttime && p.end <= endtime
             && comparer(p1, p))
         {
             list.Add(p);
             likehood = Math.Max(p.likehood, likehood);
         }
     }
     return likehood;
 }
 public static double SimiliarCommand(IOTPhenomemon p, List<IOTPhenomemon> list)
 {
     double likehood = 0;
     foreach (IOTPhenomemon p1 in list)
     {
         likehood = Math.Max(likehood, 1 - global.SmallValue - Math.Abs(p1.pkg.SrcSenderSeq - p.pkg.SrcSenderSeq) / 100);
     }
     return likehood;
 }
 public static bool ComparePhenomemonBySimiliarTag(IOTPhenomemon p1, IOTPhenomemon p2)
 {
     if (p1.pkg == null || p1.pkg.Type != PacketType.COMMAND)
         return false;
     //使用PacketSeq判断两个数据包是否为同一个
     return (p1.pkg.Command.tag == p2.pkg.Dst);
 }
 public static bool ComparePhenomemonByExactTag(IOTPhenomemon p1, IOTPhenomemon p2)
 {
     if (p1.pkg == null || p1.pkg.Type != PacketType.COMMAND)
         return false;
     //使用PacketSeq判断两个数据包是否为同一个
     return (p1.pkg.Command.tag == p2.pkg.Dst && p1.pkg.SrcSenderSeq == p2.pkg.SrcSenderSeq);
 }
 static double ConditionHappened(List<IOTPhenomemon> observedPhenomemons, IOTPhenomemonType type, int node,
     double starttime, double endtime, IOTPhenomemon p, ComparePhenomemon comparer)
 {
     for (int i = 0; i < observedPhenomemons.Count; i++)
     {
         if (observedPhenomemons[i].nodeId == node && observedPhenomemons[i].type == type
             && observedPhenomemons[i].start >= starttime && observedPhenomemons[i].end <= endtime
             && comparer(p, observedPhenomemons[i]))
         {
             return observedPhenomemons[i].likehood;
         }
     }
     return global.SmallValue;
 }
 static double ConditionHappened(List<IOTPhenomemon> observedPhenomemons, IOTPhenomemonType type, int node,
     double starttime, double endtime, IOTPhenomemon p, List<IOTPhenomemon> list, ComparePhenomemon comparer)
 {
     double likehood = global.SmallValue;
     for (int i = 0; i < observedPhenomemons.Count; i++)
     {
         if (observedPhenomemons[i].nodeId == node && observedPhenomemons[i].type == type
             && observedPhenomemons[i].start >= starttime && observedPhenomemons[i].end <= endtime
             && comparer(p, observedPhenomemons[i]))
         {
             list.Add(observedPhenomemons[i]);
             likehood = Math.Max(observedPhenomemons[i].likehood, likehood);
         }
     }
     return likehood;
 }