Пример #1
0
        public override void Execute()
        {
            try
            {
                // basic test, interrogate router for Routing Table, check the Port IDs

                BACnetUtil.SendInitRoutingTable(_apm, _bnm, new DADR(devicTreeNode.device.adr));

                BACnetPacket incomingPkt = waitForPacket(5000, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE_ACK);

                foreach (RoutingTableEntry rte in incomingPkt.routerTableList)
                {
                    if (rte.portID == 0)
                    {
                        // fails
                        //Console.WriteLine("Illegal Port ID " + rte.ToString());
                        // Need to mark diagnostic as failed, with a comment
                        MarkDiagnosticFailed("Port ID found to be out of range: " + rte.ToString());
                        return;
                    }
                }
            }
            catch (TimeoutException)
            {
                // todo-put a wrapper around execute and catch all executions in a common area..
                MarkDiagnosticFailed("Timeout");
                return;
            }
            MarkDiagnosticSuccess();
        }
Пример #2
0
        public override void Execute()
        {
            BACnetPacket incomingPkt;

            //if (!(deviceNode.device.GetType() == typeof(Router)))
            //{
            //    MarkDiagnosticWithNote("Device is not a router, cannot run this test");
            //    return;
            //}

            // todo, block this queue unless a diagnostic is running
            // clear the queue
            ClearIncomingPacketQueue();

            try
            {
                BACnetUtil.SendInitRoutingTable(_apm, _bnm, new DADR(devicTreeNode.device.adr));
                incomingPkt = waitForPacket(5000, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE_ACK);  // todo, add fromaddress...
                // got it.
                foreach (RoutingTableEntry rte in incomingPkt.routerTableList)
                {
                    Console.WriteLine(rte.ToString());
                }

                // record the number of entries, and record the last item
                int entrycount = incomingPkt.routerTableList.Count;
                if (entrycount < 1 || entrycount > 255)
                {
                    Console.WriteLine("Failed this time around");
                    // test fails, impossible count
                    return;
                    //throw new Exception("m0525-Totally bogus router table entry count");
                }

                RoutingTableEntry rtDupe = incomingPkt.routerTableList[entrycount - 1];

                // now write the last entry again.
                BACnetPacket outgoingPkt = new BACnetPacket(_apm, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE);
                outgoingPkt.SetDestination(new DADR(incomingPkt.srcDevice.adr));
                outgoingPkt.routerTableList = new List <RoutingTableEntry>();
                outgoingPkt.routerTableList.Add(rtDupe);
                outgoingPkt.EncodeBACnet();
                _bnm.insideSocket.OurSendTo(outgoingPkt.buffer, outgoingPkt.optr, incomingPkt.srcDevice.adr.ResolvedIPEP());

                // wait for the ack
                incomingPkt = waitForPacket(5000, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE_ACK);

                // drop the packet

                // re-read the routing table
                BACnetUtil.SendInitRoutingTable(_apm, _bnm, new DADR(devicTreeNode.device.adr));
                incomingPkt = waitForPacket(5000, BACnetEnums.BACNET_NETWORK_MESSAGE_TYPE.NETWORK_MESSAGE_INIT_RT_TABLE_ACK);

                foreach (RoutingTableEntry rte in incomingPkt.routerTableList)
                {
                    Console.WriteLine(rte.ToString());
                }

                // record the number of entries, and record the last item
                if (incomingPkt.routerTableList.Count != entrycount)
                {
                    Console.WriteLine("m0165-Failed entrycount");
                    // Todo, check if this _IS_ OK.
                    MarkDiagnosticFailed("The entrycount did not remain the same, i.e. The router allowed the addition of a duplicate Network Number");
                    return;
                }
            }
            catch (TimeoutException)
            {
                // todo-put a wrapper around execute and catch all executions in a common area..
                MarkDiagnosticFailed("Timeout");
                return;
            }
            catch (Exception ex)
            {
                // other types of exception...
                throw ex;
                //BACnetLibrary.Panic(ex.ToString());
                //return;
            }

            MarkDiagnosticSuccess();
            Console.WriteLine("Diag done");
        }