static void Main(string[] args)
        {
            //string[] parameters = new string[] { args[0], args[1], args[2] };

            NetNode netnode = new NetNode(args);
        }
Example #2
0
        private void Listen()
        {
            TcpClient    clienttmp = new TcpClient("127.0.0.1", this.port);
            BinaryReader reader    = new BinaryReader(clienttmp.GetStream());
            BinaryWriter writer    = new BinaryWriter(clienttmp.GetStream());

            try
            {
                while (true)
                {
                    string            received_data     = reader.ReadString();
                    JSON              received_object   = JSON.Deserialize(received_data);
                    ManagmentProtocol received_Protocol = received_object.Value.ToObject <ManagmentProtocol>();

                    if (received_Protocol.State == ManagmentProtocol.WHOIS)
                    {
                        NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: receivedWhoIs", ConsoleColor.Blue);
                        //send name to management
                        ManagmentProtocol protocol = new ManagmentProtocol();
                        protocol.Name = this.virtualIp;
                        String send_object = JMessage.Serialize(JMessage.FromValue(protocol));
                        writer.Write(send_object);
                        NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " sending: " + protocol.Name, ConsoleColor.Blue);
                    }
                    else if (received_Protocol.State == ManagmentProtocol.ROUTINGTABLES)
                    {
                        NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: receivedroutingtable", ConsoleColor.Blue);
                        //receiving fibs
                        if (received_Protocol.RoutingTable != null)
                        {
                            foreach (var fib in received_Protocol.RoutingTable)
                            {
                                SwitchingField.addToSwitch(fib);
                                //adding fib for two-way communication
                                SwitchingField.addToSwitch(new FIB(fib.oport, fib.out_cont, fib.iport, fib.in_cont));
                            }
                        }
                    }
                    else if (received_Protocol.State == ManagmentProtocol.ROUTINGENTRY)
                    {
                        NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: receivedroutingentry", ConsoleColor.Blue);
                        //receiving fibs
                        if (received_Protocol.RoutingEntry != null)
                        {
                            SwitchingField.addToSwitch(received_Protocol.RoutingEntry);
                            //adding fib for two-way communication
                            SwitchingField.addToSwitch(new FIB(received_Protocol.RoutingEntry.oport, received_Protocol.RoutingEntry.out_cont,
                                                               received_Protocol.RoutingEntry.iport, received_Protocol.RoutingEntry.in_cont));
                        }
                    }
                    else if (received_Protocol.State == ManagmentProtocol.INTERFACEINFORMATION)
                    {
                        NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: iterfaceinformation", ConsoleColor.Blue);
                        //send dictionary from LRM to management
                        ManagmentProtocol protocol = new ManagmentProtocol();
                        protocol.State      = ManagmentProtocol.INTERFACEINFORMATION;
                        protocol.Interfaces = LRM.getConn();
                        String send_object = JMessage.Serialize(JMessage.FromValue(protocol));
                        writer.Write(send_object);
                    }
                    else if (received_Protocol.State == ManagmentProtocol.GETTABLE)
                    {
                        NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: getTable", ConsoleColor.Blue);
                        //send dictionary from LRM to management
                        ManagmentProtocol protocol = new ManagmentProtocol();
                        protocol.State        = ManagmentProtocol.GETTABLE;
                        protocol.RoutingTable = SwitchingField.fib;
                        String send_object = JMessage.Serialize(JMessage.FromValue(protocol));
                        writer.Write(send_object);
                    }
                    else
                    {
                        NetNode.log("[Management] undefined protocol", ConsoleColor.Red);
                    }
                }
            }
            catch (Exception e)
            {
                NetNode.log("\nError sending signal: " + e.Message, ConsoleColor.Red);
                Thread.Sleep(2000);
                Environment.Exit(1);
            }
        }
Example #3
0
        private void Listen()
        {
            TcpClient clienttmp = new TcpClient("127.0.0.1", this.port);

            reader = new BinaryReader(clienttmp.GetStream());
            writer = new BinaryWriter(clienttmp.GetStream());
            try
            {
                while (true)
                {
                    string received_data   = reader.ReadString();
                    JSON   received_object = JSON.Deserialize(received_data);
                    CCtoCCSignallingMessage received_Protocol = received_object.Value.ToObject <CCtoCCSignallingMessage>();

                    if (received_Protocol.State == CCtoCCSignallingMessage.CC_UP_FIB_CHANGE)
                    {
                        //insert FIB
                        NetNode.log(DateTime.Now.ToLongTimeString() + " [CC -> node] insertFib", ConsoleColor.Yellow);
                        List <FIB> rec = received_Protocol.Fib_table;

                        //TODO allocate resources
                        foreach (var row in rec)
                        {
                            if (LRM.allocateResource(row.iport, row.in_cont))
                            {
                                NetNode.log(DateTime.Now.ToLongTimeString() + " [CC -> node] allocate: " + row.iport + " " + row.in_cont, ConsoleColor.Yellow);
                                if (LRM.allocateResource(row.oport, row.out_cont))
                                {
                                    NetNode.log(DateTime.Now.ToLongTimeString() + " [CC -> node] allocate: " + row.oport + " " + row.out_cont, ConsoleColor.Yellow);
                                    sendTopologyAllocated(row.iport, row.in_cont);
                                    sendTopologyAllocated(row.oport, row.out_cont);
                                    SwitchingField.addToSwitch(row);
                                    SwitchingField.addToSwitch(new FIB(row.oport, row.out_cont, row.iport, row.in_cont));
                                    sendConfirmation(row.iport, row.in_cont, true);
                                }
                                else
                                {
                                    LRM.deallocateResource(row.iport, row.in_cont);
                                    sendConfirmation(row.iport, row.in_cont, false);
                                }
                            }
                            else
                            {
                                sendConfirmation(row.iport, row.in_cont, false);
                            }
                        }
                    }
                    else if (received_Protocol.State == CCtoCCSignallingMessage.REALEASE_TOP_BOTTOM)
                    {
                        foreach (var fib in received_Protocol.Fib_table)
                        {
                            NetNode.log(DateTime.Now.ToLongTimeString() + " [CC -> LRM]" + " deallocate" + fib.toString(), ConsoleColor.Green);
                            if (LRM.deallocateResource(fib.iport, fib.in_cont))
                            {
                                sendTopologyDeallocated(fib.iport, fib.in_cont);
                            }
                            if (LRM.deallocateResource(fib.oport, fib.out_cont))
                            {
                                sendTopologyDeallocated(fib.oport, fib.out_cont);
                            }
                            SwitchingField.clearFib(fib);
                            SwitchingField.clearFib(new FIB(fib.oport, fib.out_cont, fib.iport, fib.in_cont));
                        }
                    }
                    else
                    {
                        NetNode.log("undefined protocol", ConsoleColor.Red);
                    }
                }
            }
            catch (Exception e)
            {
                NetNode.log("\nError sending signal: " + e.Message, ConsoleColor.Red);
                Thread.Sleep(2000);
                Environment.Exit(1);
            }
        }