public void send(int reqid, string address)
        {
            ManagmentProtocol protocol = new ManagmentProtocol();

            protocol.State = ManagmentProtocol.SOFTPERNAMENT;
            string id = reqid.ToString();

            protocol.Name    = id;
            protocol.NodeEnd = address;
            String send_object = JSON.Serialize(JSON.FromValue(protocol));

            writer.Write(send_object);
        }
Beispiel #2
0
        private static void ListenThread(Object threadPasser)
        {
            ThreadPasser tp        = (ThreadPasser)threadPasser;
            TcpClient    clienttmp = tp.client;
            BinaryWriter writer    = new BinaryWriter(clienttmp.GetStream());

            ManagmentProtocol toSend = new ManagmentProtocol();

            toSend.State = ManagmentProtocol.WHOIS;
            string data = JSON.Serialize(JSON.FromValue(toSend));

            writer.Write(data);

            BinaryReader      reader            = new BinaryReader(clienttmp.GetStream());
            string            received_data     = reader.ReadString();
            JSON              received_object   = JSON.Deserialize(received_data);
            ManagmentProtocol received_Protocol = received_object.Value.ToObject <ManagmentProtocol>();
            String            nodeName          = received_Protocol.Name;

            tp.control.allocateNode(nodeName, clienttmp, Thread.CurrentThread, writer);
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        public void sendOutInformation(bool clearAutoTrails = true)
        {
            if (clearAutoTrails)
            {
                List <Trail> copyTrailList = new List <Trail>(trailList);
                foreach (Trail trail in copyTrailList)
                {
                    if (!trail.isCreadetByUser())
                    {
                        trail.clearTrail(trail);
                        trailList.Remove(trail);
                    }
                }
            }

            Dictionary <Dictionary <String, int>, String> possibleDestinations = new Dictionary <Dictionary <string, int>, String>();
            Dictionary <Dictionary <string, int>, string> listDestinations     = new Dictionary <Dictionary <string, int>, string>();

            foreach (Trail trail in trailList)
            {
                if (trail.From != null && trail.To != null)
                {
                    Dictionary <string, int> temp = new Dictionary <string, int>();
                    temp.Add(trail.To.Name, trail.StartingSlot);
                    listDestinations.Add(temp, (trail.From.Name));
                }
            }

            foreach (Trail trail in trailList)
            {
                if (trail.From == null)
                {
                    continue;
                }
                BinaryWriter      writer   = new BinaryWriter(trail.From.TcpClient.GetStream());
                ManagmentProtocol protocol = new ManagmentProtocol();
                protocol.State = ManagmentProtocol.POSSIBLEDESITATIONS;
                protocol.possibleDestinations = new Dictionary <string, int>();

                foreach (var dest in listDestinations)
                {
                    if (dest.Value == trail.From.Name)
                    {
                        foreach (var temp in dest.Key)
                        {
                            protocol.possibleDestinations.Add(temp.Key, temp.Value);
                        }
                    }
                }

                //protocol.possibleDestinations.Add(trail.To.Name, trail.StartingSlot);
                protocol.Port = trail.PortFrom;
                mainWindow.errorMessage(trail.From.Name + "<->" + protocol.Port);
                String send_object = JSON.Serialize(JSON.FromValue(protocol));
                writer.Write(send_object);

                foreach (KeyValuePair <Node, FIB> fib in trail.ComponentFIBs)
                {
                    //continue;
                    writer         = fib.Key.SocketWriter;//new BinaryWriter(fib.Key.TcpClient.GetStream());
                    protocol       = new ManagmentProtocol();
                    protocol.State = ManagmentProtocol.ROUTINGENTRY;
                    Console.WriteLine("routingentry");
                    protocol.RoutingEntry = fib.Value;

                    send_object = JSON.Serialize(JSON.FromValue(protocol));
                    writer.Write(send_object);
                }
            }
        }