Exemplo n.º 1
0
        public void Listen()
        {
            inputSocket.Listen(0);
            Thread t;

            t = new Thread(() =>
            {
                foreignSocket = inputSocket.Accept();
                while (true)
                {
                    byte[] bytes = Receive(foreignSocket);
                    inCommand    = GetDeserializedCommand(bytes);
                    if (inCommand.agentId == "Fib")
                    {
                        foreach (FIB.Entry entry in fib.routingTable)
                        {
                            Command kom = new Command("Fib", Config.getIntegerProperty("NMSListenPort"), entry.InPort, entry.InLabel, entry.OutPort, entry.OutLabel, entry.NewLabel, entry.RemoveLabel, entry.IPAddress);
                            SendFib(kom);
                        }
                    }
                    else if (inCommand.agentId == "Add")
                    {
                        fib.AddEntry(inCommand.inPort, inCommand.inLabel, inCommand.outPort, inCommand.outLabel, inCommand.newLabel, inCommand.removeLabel, inCommand.ipAdress);
                        fib.UpdatePortsRoutingTables(inPorts);
                    }
                    else
                    {
                        // fib.RemoveEntry(inCommand.inPort, inCommand.inLabel);
                        fib.UpdatePortsRoutingTables(inPorts);
                    }
                }
            }
                           );
            t.Start();

            /*Thread tr;
             * tr = new Thread(() =>
             * {
             *  while (true)
             *  {
             *      Thread.Sleep(3000);
             *      SendKeepAliveMessage("KeepAlive");
             *  }
             * }
             * );
             * tr.Start();
             */
        }
Exemplo n.º 2
0
        public bool ConnectionRequestIn(SNP firstSNP, SNP secondSNP)
        {
            int inputPort = 0, outputPort = 0;

            //LogClass.WhiteLog("Przyszły takie snp: " + firstSNP.Address + "  " + firstSNP.Label + " i " + secondSNP.Address + "  " + secondSNP.Label);
            foreach (string[] translation in addressTranslation)
            {
                if (translation[0] == firstSNP.Address)
                {
                    inputPort = Int32.Parse(translation[1]);
                }
                else if (translation[0] == secondSNP.Address)
                {
                    outputPort = Int32.Parse(translation[1]);
                }
            }

            if (firstSNP.Label == 0)
            {
                foreach (string[] translation in addressTranslation)
                {
                    if (translation[0] == firstSNP.PathBegin)
                    {
                        if (firstSNP.Deleting)
                        {
                            fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label);
                            fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label);
                            fib.UpdatePortsRoutingTables(inPorts);
                        }
                        else
                        {
                            fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, firstSNP.PathEnd);
                            fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0");
                            fib.UpdatePortsRoutingTables(inPorts);
                        }
                    }
                    else if (translation[0] == firstSNP.PathEnd)
                    {
                        if (firstSNP.Deleting)
                        {
                            fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label);
                            fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label);
                            fib.UpdatePortsRoutingTables(inPorts);
                        }
                        else
                        {
                            fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, firstSNP.PathBegin);
                            fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0");
                            fib.UpdatePortsRoutingTables(inPorts);
                        }
                    }
                }
            }
            else if (secondSNP.Label == 0)
            {
                foreach (string[] translation in addressTranslation)
                {
                    if (translation[0] == secondSNP.PathBegin)
                    {
                        if (secondSNP.Deleting)
                        {
                            fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label);
                            fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label);
                            fib.UpdatePortsRoutingTables(inPorts);
                        }
                        else
                        {
                            fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, secondSNP.PathEnd);
                            fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0");
                            fib.UpdatePortsRoutingTables(inPorts);
                        }
                    }
                    else if (translation[0] == secondSNP.PathEnd)
                    {
                        if (secondSNP.Deleting)
                        {
                            fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label);
                            fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label);
                            fib.UpdatePortsRoutingTables(inPorts);
                        }
                        else
                        {
                            fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, secondSNP.PathBegin);
                            fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0");
                            fib.UpdatePortsRoutingTables(inPorts);
                        }
                    }
                }
            }
            else
            {
                if (firstSNP.Deleting)
                {
                    fib.RemoveEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label);
                    fib.RemoveEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label);
                    fib.UpdatePortsRoutingTables(inPorts);
                }
                else
                {
                    fib.AddEntry(inputPort, firstSNP.Label, outputPort, secondSNP.Label, 0, 0, "0");
                    fib.AddEntry(outputPort, secondSNP.Label, inputPort, firstSNP.Label, 0, 0, "0");
                    fib.UpdatePortsRoutingTables(inPorts);
                }
            }
            return(true);
        }