Exemplo n.º 1
0
        // Keyboard input handling -each keypress can be interpreted as
        // a control command.
        void KeyboardControl()
        {
            while (true)
            {
                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.T:
                    transportFunction.PrintRouteTable();
                    break;

                case ConsoleKey.A:
                    LRM.PrintAssignments();
                    break;

                case ConsoleKey.P:
                    if (Log.IsPaused)
                    {
                        Log.Unpause();
                    }
                    else
                    {
                        Log.Pause();
                    }
                    break;

#if DEBUG
                case ConsoleKey.Enter:
                    MPLSPacket testPacket = new MPLSPacket(new int[] { 2137 }, "This is a test MPLSMessage.");
                    transportFunction.EnqueuePacketOnFirstQueue(testPacket);
                    break;

                case ConsoleKey.U:
                    NHLFEntry        entry         = new NHLFEntry(10, 1, 17, true, 2, new int[] { 35 });
                    AddUpdateRequest testUpdateReq = new AddUpdateRequest("Helo it me", mgmtLocalPort, 2137, entry);
                    SendManagementMsg(mgmtLocalPort, testUpdateReq);
                    break;

                case ConsoleKey.R:
                    RemoveRequest testRemoveReq = new RemoveRequest("Helo it me", mgmtLocalPort, 2137, 10);
                    SendManagementMsg(mgmtLocalPort, testRemoveReq);
                    break;

                case ConsoleKey.L:
                    AllocateRequest testAllocReq = new AllocateRequest(id, mgmtLocalPort, allocCounter++, 1, 30, 1);
                    SendManagementMsg(mgmtLocalPort, testAllocReq);
                    break;

                case ConsoleKey.D:
                    DeallocateRequest testDeallocReq = new DeallocateRequest(id, mgmtLocalPort, allocCounter--, 1);
                    SendManagementMsg(mgmtLocalPort, testDeallocReq);
                    break;
#endif
                default:
                    break;
                }
            }
        }
        public void SendPeerMessage(byte snppId, GenericMessage genmsg)
        {
            //Log.WriteLine("[TX] PeerMessage: {0}, SNPP {1}", genmsg.messageType, snppId);

            MPLSPacket packet = new MPLSPacket(new int[] { 0 }, "");

            packet.managementObject = genmsg;

            AggregatePacket aggregatePacket = new AggregatePacket(new MPLSPacket[] { packet });
            BinaryWrapper   wrappedPacket   = MPLSMethods.Serialize(aggregatePacket);

            MAC.SendData(wrappedPacket, snppId);
            //Log.WriteLine("[TX {0}] => {1}, iface {2}", snppId, genmsg.messageType, snppId);
        }
Exemplo n.º 3
0
 public void EnqueuePacket(MPLSPacket packet)
 {
     packetQueue.Enqueue(packet);
 }
 public void EnqueuePacketOnFirstQueue(MPLSPacket packet)
 {
     routerInterfaces[0].EnqueuePacket(packet);
 }
        /*
         * Takes a packet and places it in a corresponding queue for output.
         */
        void Route(MPLSPacket packet, byte iface, int connectionID = 0)
        {
            NHLFEntry routeEntry;
            int       topLabel = packet.labels.Pop();

            try
            {
                var queryResults = from entry in routingTable
                                   where entry.interface_in == iface && entry.label_in == topLabel && (connectionID == 0 || entry.connectionID == connectionID)
                                   select entry;
                // The query should always return a single entry (.Single() throws error if not single ;P)
                routeEntry = queryResults.Single();
            }
            catch (InvalidOperationException)
            {
                // If no routing information is found, abandon route method
                Log.WriteLine("[FWD] ({0}, {1}) ==> DROP", iface, topLabel);
                return;
            }

            if (routeEntry.is_swap_or_add) // If the label is to be swapped or added...
            {
                foreach (int label in routeEntry.labels_out)
                {
                    packet.labels.Push(label);
                }

                /*
                 * This mysterious construct does the following things:
                 *  1. Query the interface list in search of the one
                 *      that has an ID [i.InterfaceId] equal to the one
                 *      carried in the routing entry [routeEntry.interface_out]
                 *  2. Ensure that only single interface is received as
                 *      a result (there should not be multiple interfaces
                 *      with the same ID) and select it [.Single()]
                 *  3. Execute a method [.EnqueuePacket()] on that interface
                 *      to insert the packet in a correspoding output queue
                 *
                 *                                              Sincerely,
                 *                                                Waked
                 */
                try
                {
                    var queryResults = from i in routerInterfaces
                                       where i.Id == routeEntry.interface_out
                                       select i;
                    TELinkEnd outputIface = queryResults.Single();
                    outputIface.EnqueuePacket(packet);

                    Log.WriteLine("[FWD] ({0}, {1}) ==> ({2}, {3}))", iface, topLabel, routeEntry.interface_out, string.Join(";", routeEntry.labels_out));
                }
                catch (InvalidOperationException)
                {
                    // In case there is no such interface to output (the routing
                    // infromation is flawed), abandon routing.
                    Log.WriteLine("[FWD] ({0}, {1}) ==> DROP", iface, topLabel);
                }
            }
            else // ...otherwise, reroute the packet without the top-most label
            {
                Log.WriteLine("[FWD] ({0}, {1}) ==> Reforward({0}, {2})", iface, topLabel, packet.labels.Peek());
                // Reroute the packet with the connectionID of the previous entry
                Route(packet, iface, routeEntry.connectionID);
            }
        }