Beispiel #1
0
        static List<IOTEventTrustResult> DeduceModifyPacketMaliciously(int selfId, HashSet<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            foreach (IOTPhenomemon p in observedPhenomemons)
            {
                double a1, a2, a3, a4, a6, a8_9;

                if(p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.RECV_PACKET)
                    continue;
                else if (p.pkg.Dst == p.nodeId)
                    continue;
                else if (selfId == p.nodeId)//自己不检查自己的可信度
                    continue;
                else if (global.readers[p.nodeId].IsGateway)
                    continue;
                else if (currentTime - p.start < global.checkPhenomemonTimeout)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a1 = p.likehood; //likehood of receiving a packet at time p.start
                a2 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_PACKET, node, p.start, p.start + global.sendPacketTimeout, p.pkg);
                a3 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.NOT_SEND_PACKET, node, p.start, Scheduler.getInstance().currentTime, p.pkg);
                a4 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.BANDWIDTH_BUSY, selfId, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime);
                a6 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, node, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime);
                a8_9 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SAME_PACKET_HEADER, selfId, p.start, p.start + global.sendPacketTimeout, p.pkg);

                double b4 = DSClass.AND(a1, a2) * CF[(int)IOTEventType.NotModifyPacket];
                double b5 = DSClass.AND(DSClass.AND(DSClass.AND(a1, a3), a8_9), a4) * CF[(int)IOTEventType.NotModifyPacketButNetworkFaulty];
                double b6 = DSClass.AND(DSClass.AND(a1, a3), a8_9) * CF[(int)IOTEventType.ModifyPacketDueToNodeFaulty];
                double b7 = DSClass.AND(DSClass.AND(a1, a3), a8_9) * CF[(int)IOTEventType.ModifyPacketMaliciously];

                DSClass ds = new DSClass(pow(IOTModifyPacketEventType.END));
                ds.SetM(pow(IOTModifyPacketEventType.NotModifyPacket), b4);
                ds.SetM(pow(IOTModifyPacketEventType.NotModifyPacketButNetworkFaulty), b5);
                ds.SetM(pow(IOTModifyPacketEventType.ModifyPacketDueToNodeFaulty), b6);
                ds.SetM(pow(IOTModifyPacketEventType.ModifyPacketMaliciously), b7);
                ds.SetM(pow(IOTModifyPacketEventType.END) - 1, 1 - b4 - b5 - b6 - b7);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTModifyPacketEventType.NotModifyPacket)] < global.NormalBelief
                    && ds.p[pow(IOTModifyPacketEventType.NotModifyPacket)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "->" + p.pkg.Next + "[" + p.pkg.PrevSenderSeq + "]";
                    IOTEventTrustResult r = new IOTEventTrustResult(node, selfId, pkgIdent, IOTEventCategoryType.ModifyPacket, ds);
                    r.totalEventCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                }

            }
            return list;
        }
Beispiel #2
0
        static List<IOTEventTrustResult> DeduceMakePacketMaliciously(int selfId, HashSet<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            foreach(IOTPhenomemon p in observedPhenomemons)
            {
                double a2, a24, a23, a22_10;

                if (p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.RECV_PACKET)
                    continue;
                else if (p.pkg.Dst == p.nodeId)
                    continue;
                else if (selfId == p.nodeId)//自己不检查自己的可信度
                    continue;
                else if (global.readers[p.nodeId].IsGateway)
                    continue;
                else if (currentTime - p.start < global.checkPhenomemonTimeout)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a2 = p.likehood; //likehood of receiving a packet at time p.start
                a24 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.RECV_PACKET, selfId, p.start - global.checkPhenomemonTimeout, p.start);
                a23 = Inverse(a24);
                a22_10 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SAME_PACKET_DATA, selfId, p.start, p.start + global.sendPacketTimeout, p.pkg);

                double b8 = DSClass.AND(a2, a24) * CF[(int)IOTEventType.NotMakePacket];
                double b9 =DSClass.AND(DSClass.OR(a23, a22_10), a2) * CF[(int)IOTEventType.MakePacketMaliciously];

                DSClass ds = new DSClass(pow(IOTMakePacketEventType.END));
                ds.SetM(pow(IOTMakePacketEventType.NotMakePacket), b8);
                ds.SetM(pow(IOTMakePacketEventType.MakePacketMaliciously), b9);
                ds.SetM(pow(IOTMakePacketEventType.END) - 1, 1 - b8 - b9);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTMakePacketEventType.NotMakePacket)] < global.NormalBelief
                    && ds.p[pow(IOTMakePacketEventType.NotMakePacket)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "->" + p.pkg.Next + "[" + p.pkg.PrevSenderSeq + "]";
                    IOTEventTrustResult r = new IOTEventTrustResult(node, selfId, pkgIdent, IOTEventCategoryType.MakePacket, ds);
                    r.totalEventCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                }

            }
            return list;
        }
Beispiel #3
0
        static List<IOTEventTrustResult> DeduceModifyCommandMaliciously(int selfId, HashSet<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            foreach (IOTPhenomemon p in observedPhenomemons)
            {
                double a15_16, a17_20, a21, a6, a7, a17;

                if (p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.RECV_PACKET)
                    continue;
                else if (p.pkg.Dst != p.nodeId || p.pkg.Type != PacketType.COMMAND)
                    continue;
                else if (selfId == p.nodeId)//自己不检查自己的可信度
                    continue;
                else if (currentTime - p.start < global.checkPhenomemonTimeout)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a15_16 = p.likehood; //likehood of receiving a packet at time p.start

                a6 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, node, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime);
                a7 = 0.9 - a6;

                a17_20 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_COMMAND,
                    node, p.start, p.start + global.sendPacketTimeout, p, ComparePhenomemonByExactTag);

                List<IOTPhenomemon> similiarList = new List<IOTPhenomemon>();
                a17 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_COMMAND,
                    node, p.start, p.start + global.sendPacketTimeout, p, similiarList, ComparePhenomemonBySimiliarTag);
                a21 = SimiliarCommand(p, similiarList);

                double b17 = DSClass.AND(a15_16, a17_20) * CF[(int)IOTEventType.NotModifyCommand];
                double b18 = DSClass.AND(DSClass.AND(a15_16, a17), a21) * CF[(int)IOTEventType.ModifyCommandDueToNodeFaulty];
                double b19 = DSClass.AND(DSClass.AND(a15_16, a17), a21) * CF[(int)IOTEventType.ModifyCommandMaliciously];

                DSClass ds = new DSClass(pow(IOTModifyCommandEventType.END));
                ds.SetM(pow(IOTModifyCommandEventType.NotModifyCommand), b17);
                ds.SetM(pow(IOTModifyCommandEventType.ModifyCommandDueToNodeFaulty), b18);
                ds.SetM(pow(IOTModifyCommandEventType.ModifyCommandDueToNodeFaulty), b19);
                ds.SetM(pow(IOTModifyCommandEventType.END) - 1, 1 - b17 - b18 - b19);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTModifyCommandEventType.NotModifyCommand)] < global.NormalBelief
                    && ds.p[pow(IOTModifyCommandEventType.NotModifyCommand)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "->" + p.pkg.Next + "[" + p.pkg.PrevSenderSeq + "]";
                    IOTEventTrustResult r = new IOTEventTrustResult(node, selfId, pkgIdent, IOTEventCategoryType.ModifyCommand, ds);
                    r.totalEventCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                }
            }
            return list;
        }
Beispiel #4
0
        static List<IOTEventTrustResult> DeduceDropPacketMaliciously(int selfId, HashSet<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            if(Global.getInstance().debug)
                Console.WriteLine("READER{0} Check DeduceDropPacketMaliciously", selfId);
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            IOTReader selfNode = (IOTReader)global.readers[selfId];
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            foreach (IOTPhenomemon p in observedPhenomemons)
            {
                double a1, a2, a3, a4, a5, a6, a7, a19, a27;

                if (p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.RECV_PACKET)
                    continue;
                else if (p.pkg.Dst == p.nodeId)
                    continue;
                else if (p.pkg.Type != PacketType.DATA && p.pkg.Type != PacketType.COMMAND)
                    continue;
                else if (selfId == p.nodeId)//自己不检查自己的可信度
                    continue;
                else if (global.readers[p.nodeId].IsGateway)
                    continue;
                else if (currentTime - p.start < global.checkPhenomemonTimeout)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a1 = p.likehood; //likehood of receiving a packet at time p.start
                a2 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_PACKET, node, p.start, p.start + global.sendPacketTimeout, p.pkg);
                a3 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.NOT_SEND_PACKET, node, p.start, Scheduler.getInstance().currentTime, p.pkg);
                a4 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.BANDWIDTH_BUSY, selfId, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime);
                //如果对带宽占用没有知识,则正反都设置为未知。
                a5 = 0.9 - a4;
                //这里是否可以用平均值Average?
                a6 = Utility.Max(new double[]{
                    ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, node, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime),
                    ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, p.pkg.Prev, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime),
                    ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, selfId, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime)
                });
                a7 = 0.9 - a6;
                //一个是观测节点和被观测节点的距离,看是否后者发送的消息能否被前者收到
                //另一个是,看源节点发送的数据是否能被被观测节点收到
                //a19 = Math.Max(FarDistanceLikehood(selfId, node, p.pkg.DstType==NodeType.OBJECT),
                //    FarDistanceLikehood(selfId, p.pkg.Prev, p.pkg.PrevType == NodeType.OBJECT));

                //TODO,这里是不是有问题,false和true,在md项目中已修正
                if(p.pkg.DstType == NodeType.OBJECT && selfNode.NearbyObjectCache.ContainsKey(p.pkg.Dst))
                    a19 = FarDistanceLikehood(selfId, node, false);
                else
                    a19 = FarDistanceLikehood(selfId, node, true);
                a27 = 0.9 - a19;

                //A1 AND A2 AND A7 AND A11 -> B1
                double b0 = DSClass.AND(a1, a2) * CF[(int)IOTEventType.NotDropPacket];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b1 = DSClass.AND(DSClass.AND(a1, a3), DSClass.OR(DSClass.OR(a4, a6), a19)) * CF[(int)IOTEventType.NotDropPacketButNotReceivePacket];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b2 = DSClass.AND(DSClass.AND(a1, a3), a4) * CF[(int)IOTEventType.DropPacketDueToBandwith];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b3 = DSClass.AND(DSClass.AND(DSClass.AND(DSClass.AND(a1, a3), a5), a7), a27) * CF[(int)IOTEventType.DropPacketMaliciously];

                if (global.debug)
                {
                    Console.WriteLine("{0}->{1}:{2}", selfId, node, p.pkg.SrcSenderSeq);
                    Console.WriteLine("a1:" + a1);
                    Console.WriteLine("a2:" + a2);
                    Console.WriteLine("a3:" + a3);
                    Console.WriteLine("a4:" + a4);
                    Console.WriteLine("a5:" + a5);
                    Console.WriteLine("a6:" + a6);
                    Console.WriteLine("a7:" + a7);
                    Console.WriteLine("a19:" + a19);
                    Console.WriteLine("a27:" + a27);
                    Console.WriteLine("b0:" + b0);
                    Console.WriteLine("b1:" + b1);
                    Console.WriteLine("b2:" + b2);
                    Console.WriteLine("b3:" + b3);
                }

                DSClass ds = new DSClass(pow(IOTDropPacketEventType.END));
                ds.SetM(pow(IOTDropPacketEventType.NotDropPacket), b0);
                ds.SetM(pow(IOTDropPacketEventType.NotDropPacketButNotReceivePacket), b1);
                ds.SetM(pow(IOTDropPacketEventType.DropPacketDueToBandwith), b2);
                ds.SetM(pow(IOTDropPacketEventType.DropPacketMaliciously), b3);
                ds.SetM(pow(IOTDropPacketEventType.END) - 1, 1 - b0 - b1 - b2 - b3);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTEventType.NotDropPacket) + pow(IOTEventType.NotDropPacketButNotReceivePacket)] < global.NormalBelief
                    && ds.p[pow(IOTEventType.NotDropPacket) + pow(IOTEventType.NotDropPacketButNotReceivePacket)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "->" + p.pkg.Next + "[" + p.pkg.PrevSenderSeq + "]";
                    IOTEventTrustResult r = new IOTEventTrustResult(node, selfId, pkgIdent, IOTEventCategoryType.DropPacket, ds);
                    r.totalEventCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                    Console.WriteLine("{0:F4} reader{1} think reader{2} is not normal.", currentTime, selfId, p.nodeId);
                    if (global.debug)
                    {
                        r.ds.Output();
                    }
                }
            }
            return list;
        }
Beispiel #5
0
        static List<IOTEventTrustResult> DeduceMakeCommandMaliciously(int selfId, HashSet<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            foreach (IOTPhenomemon p in observedPhenomemons)
            {
                double a20, a24, a5, a6, a7, a17, a23, a4;

                if (p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.SEND_COMMAND)
                    continue;
                else if (p.pkg.Dst != p.nodeId || p.pkg.Type != PacketType.COMMAND)
                    continue;
                else if (selfId == p.nodeId)//自己不检查自己的可信度
                    continue;
                else if (currentTime - p.start < global.checkPhenomemonTimeout)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a17 = p.likehood; //likehood of receiving a packet at time p.start

                a6 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, node, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime);
                //如果对带宽占用没有知识,则正反都设置为未知。
                a4 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.BANDWIDTH_BUSY, selfId, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime);
                a5 = 0.9 - a4;
                a7 = 0.9 - a6;

                List<IOTPhenomemon> similiarList = new List<IOTPhenomemon>();
                a24 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_COMMAND,
                    node, p.start - global.sendPacketTimeout, p.start, p, similiarList, ComparePhenomemonBySimiliarTag);
                a20 = SimiliarCommand(p, similiarList);

                if (Utility.DoubleEqual(a20, global.SmallValue) || Utility.DoubleEqual(a24, global.SmallValue))
                    a23 = 0.9 - global.SmallValue;
                else
                    a23 = Math.Max(a20, a24);

                double b20 = DSClass.AND(DSClass.AND(a17, a20), a24) * CF[(int)IOTEventType.NotMakeCommand];
                double b21 = DSClass.AND(DSClass.AND(DSClass.AND(17, a20), a23), a6) * CF[(int)IOTEventType.NotMakeCommandButMove];
                double b22 = DSClass.AND(DSClass.AND(DSClass.AND(17, a20), a23), a4) * CF[(int)IOTEventType.NotMakeCommandButNetworkDelay];
                double b23 = DSClass.AND(DSClass.AND(DSClass.AND(DSClass.AND(17, a20), a23), a5), a7) * CF[(int)IOTEventType.MakeCommandMaliciously];

                DSClass ds = new DSClass(pow(IOTMakeCommandEventType.END));
                ds.SetM(pow(IOTMakeCommandEventType.NotMakeCommand), b20);
                ds.SetM(pow(IOTMakeCommandEventType.NotMakeCommandButNetworkDelay), b21);
                ds.SetM(pow(IOTMakeCommandEventType.NotMakeCommandButNetworkDelay), b22);
                ds.SetM(pow(IOTMakeCommandEventType.MakeCommandMaliciously), b23);
                ds.SetM(pow(IOTMakeCommandEventType.END) - 1, 1 - b21 - b22 - b23);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTMakeCommandEventType.NotMakeCommand)] < global.NormalBelief
                    && ds.p[pow(IOTMakeCommandEventType.NotMakeCommand)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "->" + p.pkg.Next + "[" + p.pkg.PrevSenderSeq + "]";
                    IOTEventTrustResult r = new IOTEventTrustResult(node, selfId, pkgIdent, IOTEventCategoryType.MakeCommand, ds);
                    r.totalEventCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                }
            }
            return list;
        }
Beispiel #6
0
        static List<IOTEventTrustResult> DeduceDropCommandMaliciously(int selfId, HashSet<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            foreach (IOTPhenomemon p in observedPhenomemons)
            {
                double a15_16, a17_20, a18_20, a19, a6, a7;

                if (p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.RECV_PACKET)
                    continue;
                else if (p.pkg.Dst != p.nodeId ||p.pkg.Type != PacketType.COMMAND)
                    continue;
                else if (selfId == p.nodeId)//自己不检查自己的可信度
                    continue;
                else if (currentTime - p.start < global.checkPhenomemonTimeout)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a15_16 = p.likehood; //likehood of receiving a packet at time p.start

                a6 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, node, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().currentTime);
                a7 = 0.9 - a6;

                a17_20 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_COMMAND, node, p.start, p.start + global.sendPacketTimeout, p, ComparePhenomemonByExactTag);
                a18_20 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.NOT_SEND_COMMAND, node, p.start, Scheduler.getInstance().currentTime, p.pkg);
                //第三个参数是“数据包的目的地是否是标签”,由于命令的目的肯定是标签,所以永远为true
                a19 = FarDistanceLikehood(selfId, node, true);

                double b14 = DSClass.AND(a15_16, a17_20) * CF[(int)IOTEventType.NotDropCommand];
                double b15 = DSClass.AND(DSClass.AND(a15_16, a18_20), DSClass.OR(a6, a19)) * CF[(int)IOTEventType.NotDropCommandButNotDetected];
                double b16 = DSClass.AND(DSClass.AND(a15_16, a18_20), a7) * CF[(int)IOTEventType.DropCommandMaliciously];

                DSClass ds = new DSClass(pow(IOTDropCommandEventType.END));
                ds.SetM(pow(IOTDropCommandEventType.NotDropCommand), b14);
                ds.SetM(pow(IOTDropCommandEventType.NotDropCommandButNotDetected), b15);
                ds.SetM(pow(IOTDropCommandEventType.DropCommandMaliciously), b16);
                ds.SetM(pow(IOTDropCommandEventType.END) - 1, 1 - b14 - b15 - b16);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTDropCommandEventType.NotDropCommand)] < global.NormalBelief
                    && ds.p[pow(IOTDropCommandEventType.NotDropCommand)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "->" + p.pkg.Next + "[" + p.pkg.PrevSenderSeq + "]";
                    IOTEventTrustResult r = new IOTEventTrustResult(node, selfId, pkgIdent, IOTEventCategoryType.DropCommand, ds);
                    r.totalEventCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                }
            }
            return list;
        }
Beispiel #7
0
        /*
        //根据事件发生的频率调整该事件的可信度
        static void UpdateM(IOTEventTrustCategoryResult r, IOTEventCategoryType category)
        {
            int count = IOTEventTrustResult.GetCountByCategory(category);
            int start = IOTEventTrustResult.GetStartTypeByCategory(category);
            for (int i = 0; i < count; i++)
            {
                int t = i + start;
                IOTEventType type = (IOTEventType)t;
                double confirmRate = (double)r.confirmedEventNums[i] / r.totalEventCount;
                r.ds.m[DSClass.pow(i)] = r.ds.m[DSClass.pow(i)] * f(confirmRate, type);
            }
        }*/
        //将不同节点对同一个事件的报告正交化为一个事件的报告
        static IOTEventTrustResult CombineToEvent(int node, int selfId, string eventIdent, List<IOTEventTrustResult> events)
        {
            int len = events[0].ds.m.Length;
            DSClass ds = null;
            int totalCount = 0;
            IOTEventCategoryType category = events[0].category;
            for (int i = 0; i < events.Count; i++)
            {
                IOTEventTrustResult e0 = events[0];
                IOTEventTrustResult e = events[i];
                if (e.app != e0.app || e.node != e0.node || e.category != category)
                {
                    Console.WriteLine("Error: app and node not match: {0}-{1}->{2}-{3}", e0.app, e0.node, e.app, e.node);
                    Console.ReadLine();
                    return null;
                }
                if (totalCount < e.totalEventCount)
                    totalCount = e.totalEventCount;

                if (ds == null)
                    ds = e.ds;
                else
                    ds = DSClass.Combine(ds, e.ds);//进行正交运算
            }
            ds.Cal();
            IOTEventTrustResult r = new IOTEventTrustResult(node, selfId, node.ToString(), category, ds);
            r.totalEventCount = totalCount;
            r.nodeReportCount = events.Count;
            return r;
        }
Beispiel #8
0
        static List<IOTEventTrustResult> DeduceDropPacketMaliciously(int selfId, HashSet<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            foreach (IOTPhenomemon p in observedPhenomemons)
            {
                double a1, a2, a3, a4, a5, a6, a7, a19, a27;

                if (p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.RECV_PACKET)
                    continue;
                else if (p.pkg.Dst == p.nodeId)
                    continue;
                else if (selfId == p.nodeId)//自己不检查自己的可信度
                    continue;
                else if (global.readers[p.nodeId].IsGateway)
                    continue;
                else if (currentTime - p.start < global.checkPhenomemonTimeout)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a1 = p.likehood; //likehood of receiving a packet at time p.start
                a2 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_PACKET, node, p.start, p.start + global.sendPacketTimeout, p.pkg);
                a3 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.NOT_SEND_PACKET, node, p.start, Scheduler.getInstance().CurrentTime, p.pkg);
                a4 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.BANDWIDTH_BUSY, selfId, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().CurrentTime);
                //如果对带宽占用没有知识,则正反都设置为未知。
                a5 = 0.9 - a4;
                a6 = Utility.Max(new double[]{
                    ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, node, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().CurrentTime),
                    ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, p.pkg.Prev, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().CurrentTime),
                    ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, selfId, p.start - global.checkPhenomemonTimeout, Scheduler.getInstance().CurrentTime)
                });
                a7 = 0.9 - a6;
                a19 = Math.Max(FarDistanceLikehood(selfId, node, p.pkg.DstType==NodeType.OBJECT),
                    FarDistanceLikehood(selfId, p.pkg.Prev, false));
                a27 = 0.9 - a19;

                //A1 AND A2 AND A7 AND A11 -> B1
                double b0 = DSClass.AND(a1, a2) * CF[(int)IOTEventType.NotDropPacket];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b1 = DSClass.AND(DSClass.AND(a1, a3), DSClass.OR(DSClass.OR(a4, a6), a19)) * CF[(int)IOTEventType.NotDropPacketButNotReceivePacket];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b2 = DSClass.AND(DSClass.AND(a1, a3), a4) * CF[(int)IOTEventType.DropPacketDueToBandwith];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b3 = DSClass.AND(DSClass.AND(DSClass.AND(DSClass.AND(a1, a3), a5), a7), a27) * CF[(int)IOTEventType.DropPacketMaliciously];

                DSClass ds = new DSClass(pow(IOTDropPacketEventType.END));
                ds.SetM(pow(IOTDropPacketEventType.NotDropPacket), b0);
                ds.SetM(pow(IOTDropPacketEventType.NotDropPacketButNotReceivePacket), b1);
                ds.SetM(pow(IOTDropPacketEventType.DropPacketDueToBandwith), b2);
                ds.SetM(pow(IOTDropPacketEventType.DropPacketMaliciously), b3);
                ds.SetM(pow(IOTDropPacketEventType.END) - 1, 1 - b0 - b1 - b2 - b3);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTEventType.NotDropPacket) + pow(IOTEventType.NotDropPacketButNotReceivePacket)] < global.NormalBelief
                    && ds.p[pow(IOTEventType.NotDropPacket) + pow(IOTEventType.NotDropPacketButNotReceivePacket)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "->" + p.pkg.Next + "[" + p.pkg.SenderSeq + "]";
                    IOTEventTrustResult r = new IOTEventTrustResult(node, selfId, pkgIdent, IOTEventCategoryType.DropPacket, ds);
                    r.totalEventCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                    Console.WriteLine("{0:F4} reader{1} think reader{2} is not normal.", currentTime, selfId, p.nodeId);
                    //r.ds.Output();
                }
            }
            return list;
        }
        static List<IOTEventTrustResult> DeduceDropPacketMaliciously(int selfId, List<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            for (int i = 0; i < observedPhenomemons.Count; i++)
            {
                double a1, a2, a3, a4, a5, a6, a7;
                IOTPhenomemon p = observedPhenomemons[i];

                if (p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.RECV_PACKET)
                    continue;
                else if (p.pkg.Dst == p.nodeId)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a1 = p.likehood; //likehood of receiving a packet at time p.start
                a2 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_PACKET, node, p.start, p.start + global.sendPacketTimeout, p.pkg);
                a3 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.NOT_SEND_PACKET, node, p.start, p.start + global.sendPacketTimeout, p.pkg);
                a4 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.BANDWIDTH_BUSY, selfId, p.start - global.checkPhenomemonTimeout, p.start + global.checkPhenomemonTimeout);
                //如果对带宽占用没有知识,则正反都设置为未知。
                if (Utility.DoubleEqual(a4, global.SmallValue))
                    a5 = global.SmallValue;
                else
                    a5 = 0.9 - a4;
                a6 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST, node, p.start - global.checkPhenomemonTimeout, p.start + global.checkPhenomemonTimeout);
                if (Utility.DoubleEqual(a6, global.SmallValue))
                    a7 = global.SmallValue;
                else
                    a7 = 0.9 - a6;

                //A1 AND A2 AND A7 AND A11 -> B1
                double b0 = DSClass.AND(a1, a2) * CF[(int)IOTEventType.NotDropPacket];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b1 = DSClass.AND(DSClass.AND(a1, a3), DSClass.OR(a4, a5)) * CF[(int)IOTEventType.NotDropPacketButNotReceivePacket];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b2 = DSClass.AND(DSClass.AND(a1, a3), a4) * CF[(int)IOTEventType.DropPacketDueToBandwith];
                //A1 AND A2 AND A7 AND A11 -> B1
                double b3 = DSClass.AND(DSClass.AND(DSClass.AND(a1, a3), a5), a7) * CF[(int)IOTEventType.DropPacketMaliciously];

                DSClass ds = new DSClass(pow(IOTDropPacketEventType.END));
                ds.SetM(pow(IOTDropPacketEventType.NotDropPacket), b0);
                ds.SetM(pow(IOTDropPacketEventType.NotDropPacketButNotReceivePacket), b1);
                ds.SetM(pow(IOTDropPacketEventType.DropPacketDueToBandwith), b2);
                ds.SetM(pow(IOTDropPacketEventType.DropPacketMaliciously), b3);
                ds.SetM(pow(IOTDropPacketEventType.END) - 1, 1 - b0 - b1 - b2 - b3);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTEventType.NotDropPacket)] < global.NormalBelief
                    || ds.p[pow(IOTEventType.NotDropPacket)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "-" + p.pkg.Next + global.PacketSeq;
                    IOTEventTrustResult r = new IOTEventTrustResult(node, pkgIdent, IOTEventCategoryType.DropPacket, ds);
                    r.totalCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                }
            }
            return list;
        }
        static List<IOTEventTrustResult> DeduceDropCommandMaliciously(int selfId, List<IOTPhenomemon> observedPhenomemons, double currentTime)
        {
            IOTGlobal global = (IOTGlobal)Global.getInstance();
            //每个节点处理该类事件的次数
            int[] eventCount = new int[global.readerNum];
            List<IOTEventTrustResult> list = new List<IOTEventTrustResult>();
            for (int i = 0; i < observedPhenomemons.Count; i++)
            {
                double a15_16, a17_20, a18_20, a19, a6, a7;
                IOTPhenomemon p = observedPhenomemons[i];

                if (p.likehood <= global.SmallValue)
                    continue;
                if (p.type != IOTPhenomemonType.RECV_PACKET)
                    continue;
                else if (p.pkg.Dst != p.nodeId ||p.pkg.Type != PacketType.COMMAND)
                    continue;

                int node = p.nodeId;
                eventCount[node]++;

                a15_16 = p.likehood; //likehood of receiving a packet at time p.start

                a6 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.MOVE_FAST,
                    node, p.start - global.checkPhenomemonTimeout, p.start + global.checkPhenomemonTimeout);
                if (Utility.DoubleEqual(a6, global.SmallValue))
                    a7 = global.SmallValue;
                else
                    a7 = 0.9 - a6;

                a17_20 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.SEND_COMMAND,
                    node, p.start, p.start + global.sendPacketTimeout, p, ComparePhenomemonByExactTag);
                a18_20 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.NOT_SEND_COMMAND,
                    node, p.start, p.start + global.sendPacketTimeout, p.pkg);
                a19 = ConditionHappened(observedPhenomemons, IOTPhenomemonType.DIST_FAR,
                    node, p.start - global.checkPhenomemonTimeout, p.start + global.checkPhenomemonTimeout);

                double b14 = DSClass.AND(a15_16, a17_20) * CF[(int)IOTEventType.NotDropCommand];
                double b15 = DSClass.AND(DSClass.AND(a15_16, a18_20), DSClass.OR(a6, a19)) * CF[(int)IOTEventType.NotDropCommandButNotDetected];
                double b16 = DSClass.AND(DSClass.AND(a15_16, a18_20), a7) * CF[(int)IOTEventType.DropCommandMaliciously];

                DSClass ds = new DSClass(pow(IOTDropCommandEventType.END));
                ds.SetM(pow(IOTDropCommandEventType.NotDropCommand), b14);
                ds.SetM(pow(IOTDropCommandEventType.NotDropCommandButNotDetected), b15);
                ds.SetM(pow(IOTDropCommandEventType.DropCommandMaliciously), b16);
                ds.SetM(pow(IOTDropCommandEventType.END) - 1, 1 - b14 - b15 - b16);
                ds.Cal();
                //ds.Output();
                //此处,我们先过滤一些正常事件,否则事件太多了
                if (ds.b[pow(IOTDropCommandEventType.NotDropCommand)] < global.NormalBelief
                    || ds.p[pow(IOTDropCommandEventType.NotDropCommand)] < global.NormalPlausibility)//确实是攻击,恶意事件的信念大于正常事件,或恶意事件的信念大于某一个阈值
                {
                    string pkgIdent = p.pkg.Prev + "-" + p.pkg.Next + global.PacketSeq;
                    IOTEventTrustResult r = new IOTEventTrustResult(node, pkgIdent, IOTEventCategoryType.DropCommand, ds);
                    r.totalCount = eventCount[node];
                    r.app = p.pkg.AppId;
                    list.Add(r);
                }
            }
            return list;
        }