Esempio n. 1
0
        public void Start()
        {
            ReturnLog("Managment agent start working.");
            ConnectToManagementCenter();
            while (true)
            {
                try
                {
                    var message         = Receive(CSocket);
                    var splittedMessage = message.Split(' ');
                    ReturnLog($"Received message from Management Center: {message}");
                    switch (splittedMessage[0])
                    {
                    case "ADDRECORD":
                        MPLSFibTable.AddElement(new MPLSFibRecord(
                                                    splittedMessage[1] + " " + splittedMessage[2] + " " + splittedMessage[3] + " " + splittedMessage[4] + " " + splittedMessage[5]));
                        ReturnLog($"Number of MPLSFibTable elements: {MPLSFibTable.MplsFibTable.Count}");
                        break;

                    case "REMOVERECORD":
                        MPLSFibTable.RemoveElement(new MPLSFibRecord(
                                                       splittedMessage[1] + " " + splittedMessage[2] + " " + splittedMessage[3] + " " + splittedMessage[4] + " " + splittedMessage[5]));
                        ReturnLog($"Number of MPLSFibTable elements: {MPLSFibTable.MplsFibTable.Count}");
                        break;

                    default:
                        ReturnLog("Received unknown command from Management Center");
                        break;
                    }
                }
                catch (Exception e)
                {
                }
            }
        }
 public static void SwapLabels(int portNumber, MPLSPacket mplsp)
 {
     if (mplsp.TTL > 0)
     {
         mplsp.TTL -= 1;
         int LabelIndex = 1;
         while (true)
         {
             byte LastLabel     = mplsp.Labels[mplsp.Labels.Count() - 1];
             int  mplsListIndex = MPLSFibTable.ReturnIndex(portNumber, LastLabel, LabelIndex);
             if (mplsListIndex == -1)
             {
                 ManagementAgent.ReturnLog("Unable to forward packet.");
                 break;
             }
             else
             {
                 List <int> outputLabels = MPLSFibTable.MplsFibTable[mplsListIndex].OutputLabel;
                 if (outputLabels[0] == 0)
                 {
                     LabelIndex++;
                     mplsp.Labels.RemoveAt(mplsp.Labels.Count() - 1);
                     continue;
                 }
                 else
                 {
                     mplsp.Labels.RemoveAt(mplsp.Labels.Count() - 1);
                     foreach (int labels in outputLabels)
                     {
                         mplsp.Labels.Add(Convert.ToByte(labels));
                     }
                     IOPort exitPort = LabelSwitchingRouter.ReturnPort(MPLSFibTable.MplsFibTable[mplsListIndex].OutputPort);
                     if (exitPort != null)
                     {
                         exitPort.Send(mplsp);
                     }
                     else
                     {
                         ManagementAgent.ReturnLog("Unable to forward packet.");
                     }
                     break;
                 }
             }
         }
     }
     else
     {
         ManagementAgent.ReturnLog("TTL value equals 0. Packet disappeared.");
     }
 }