Beispiel #1
0
        /// <summary>
        /// Gets the routing table.
        /// </summary>
        /// <returns>Routing table based on the mapped network.</returns>
        public List <RoutingTableEntry> GetRoutingTable()
        {
            List <RoutingTableEntry> routingTable = new List <RoutingTableEntry>();

            for (int i = 1; i < rank; i++)
            {
                RoutingTableEntry entry = new RoutingTableEntry();
                entry.Node     = allNodes[i];
                entry.Distance = distances[i];

                if (entry.Distance == -1)
                {
                    continue;
                }

                int currentNode = i;

                while (previousNodes[currentNode] != 0)
                {
                    currentNode = previousNodes[currentNode];
                }

                entry.NextHop = allNodes[currentNode];

                routingTable.Add(entry);
            }

            return(routingTable);
        }
        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");
        }