Esempio 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;
                }
            }
        }
Esempio n. 2
0
        // Method invoked in a separate thread, sets up a UDP listener
        // that listens for anything on a management port, then detemines
        // what kind of message it is (with what information) and handles
        // the response.
        void ReceiveManagementMsg()
        {
            UdpClient  listener = new UdpClient(mgmtLocalPort);
            IPEndPoint groupEP  = new IPEndPoint(IPAddress.Parse("127.0.0.1"), mgmtLocalPort);

            try
            {
                while (true)
                {
                    byte[] bytes = listener.Receive(ref groupEP);

                    Communications.Message msg = Communications.Serialization.Deserialize(bytes);

                    switch (msg.messageType)
                    {
                    case "NHLF.AddUpdateRequest":
                        Log.WriteLine("[MGMT CCI] {1}, port {2}: {0})", msg.messageType, msg.senderID, msg.senderPort);
                        AddUpdateRequest addUpdateReq = (AddUpdateRequest)msg;
                        transportFunction.UpdateRoutingTable(addUpdateReq.entry, true);
                        // !!! IT CAN GO TERRIBLY WRONG HERE !!!
                        SendManagementMsg(
                            (ushort)addUpdateReq.senderPort,
                            new AddUpdateResponse(id, mgmtLocalPort, addUpdateReq.seq, true)
                            );
                        Log.WriteLine("[MGMT CCI] Add/update forward: conn {2}, iface {0}, label {1}", addUpdateReq.entry.interface_in, addUpdateReq.entry.label_in, addUpdateReq.entry.connectionID);
                        break;

                    case "NHLF.RemoveRequest":
                        Log.WriteLine("[MGMT CCI] {1}, port {2}: {0})", msg.messageType, msg.senderID, msg.senderPort);
                        RemoveRequest removeReq = (RemoveRequest)msg;
                        bool          status    = transportFunction.RemoveFromRoutingTable(removeReq.connectionID);
                        SendManagementMsg(
                            (ushort)removeReq.senderPort,
                            new RemoveResponse(id, mgmtLocalPort, removeReq.seq, status)
                            );
                        Log.WriteLine("[MGMT CCI] {0} entries for connection {1}", status ? "Removed" : "Could not remove", removeReq.connectionID);
                        break;

                    case "AllocateRequest":
                        Log.WriteLine("[MGMT LRM] {1}, port {2}: {0})", msg.messageType, msg.senderID, msg.senderPort);
                        AllocateRequest allocateReq = (AllocateRequest)msg;
                        uint            label       = LRM.AssignBandwidthOnInterface(allocateReq.interfaceID, (uint)allocateReq.bitrate, allocateReq.connectionID);
                        SendManagementMsg(
                            (ushort)allocateReq.senderPort,
                            new AllocateResponse(
                                id,
                                mgmtLocalPort,
                                (int)label,
                                allocateReq.seq
                                )
                            );
                        if (label != 0)
                        {
                            Log.WriteLine("[MGMT LRM] Allocate {0} Mb/s on iface {1} for connection {2})", allocateReq.bitrate, allocateReq.interfaceID, allocateReq.connectionID);
                        }
                        else
                        {
                            Log.WriteLine("[MGMT LRM] Could not allocate {0} Mb/s on iface {1} for connection {2})", allocateReq.bitrate, allocateReq.interfaceID, allocateReq.connectionID);
                        }
                        break;

                    case "DeallocateRequest":
                        Log.WriteLine("[MGMT LRM] {1}, port {2}: {0})", msg.messageType, msg.senderID, msg.senderPort);
                        DeallocateRequest deallocateReq = (DeallocateRequest)msg;
                        LRM.ReleaseAsignedBandwidth(deallocateReq.connectionID);
                        SendManagementMsg(
                            (ushort)deallocateReq.senderPort,
                            new DeallocateResponse(
                                id,
                                mgmtLocalPort,
                                deallocateReq.seq
                                )
                            );
                        Log.WriteLine("[MGMT LRM] Deallocate resources for connection {0})", deallocateReq.connectionID);
                        break;

#if DEBUG
                    case "NHLF.AddUpdateResponse":
                        AddUpdateResponse addUpdateResponse = (AddUpdateResponse)msg;
                        Log.WriteLine("[CCI] AddUpdateRequest for {0} {1}.", addUpdateResponse.senderID, addUpdateResponse.status ? "successful" : "failed");
                        break;

                    case "NHLF.RemoveResponse":
                        RemoveResponse removeResp = (RemoveResponse)msg;
                        Log.WriteLine("[CCI] Remove {0}", removeResp.status ? "some" : "none");
                        break;

                    case "LRMRC.LinkStateUpdate":
                        LinkStateUpdate linkStateUpdate = (LinkStateUpdate)msg;
                        Log.WriteLine("[RC] {0} --{2}-> {1}", linkStateUpdate.beginNode.id, linkStateUpdate.endNode.id, linkStateUpdate.capacity);
                        break;
#endif
                    default:
                        break;
                    }

                    // NHLFMgmtMessage mgmtMessage = NHLFSerialization.Deserialize(bytes);

                    //NHLFEntry newEntry = mgmtMessage.entry;

                    //string result = transportFunction.UpdateRoutingTable(newEntry, mgmtMessage.addOrSwap);
                }
            }
            catch (Exception e)
            {
                Log.WriteLine(e.ToString());
            }
            finally
            {
                listener.Close();
            }
        }