Example #1
0
        public IOTReader(int id, int org)
            : base(id, org)
        {
            this.global = (IOTGlobal)Global.getInstance();
            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();
        }
Example #2
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);
            }
        }
Example #3
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);
        }
Example #4
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;
        }
Example #5
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);
            }
        }