예제 #1
0
        private void listenForNCC()
        {
            listenerNCC.Start();
            clientNCC = listenerNCC.AcceptTcpClient();
            writerNCC = new BinaryWriter(clientNCC.GetStream());
            readerNCC = new BinaryReader(clientNCC.GetStream());
            UserInterface.log("Connection successfully established with NCC.", ConsoleColor.Green);

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

                    if (received_Protocol.State == ManagmentProtocol.SOFTPERNAMENT)
                    {
                        Console.WriteLine("Received signal from NCC connection: " + received_Protocol.Name + " " + received_Protocol.NodeEnd);
                        ManagementPlane.conn.Add(received_Protocol.Name, received_Protocol.NodeEnd);
                    }
                    else
                    {
                        Console.WriteLine("Signal from management: undefined protocol", ConsoleColor.Red);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("\nError sending signal: " + e.Message, ConsoleColor.Red);
                Thread.Sleep(2000);
                Environment.Exit(1);
            }
        }
예제 #2
0
        public void sendInfoToOtherNcc(List <int> nccPorts)
        {
            ManagmentProtocol toSend = new ManagmentProtocol();

            toSend.State = ManagmentProtocol.TOOTHERNCC;
            toSend.ConnectionToOtherNcc = nccPorts;
            string data             = JSON.Serialize(JSON.FromValue(toSend));
            Thread threadManagement = new Thread(new ParameterizedThreadStart(tryToSendData));

            threadManagement.Start(data);
        }
예제 #3
0
        public void sendSoftPernament(String start, String end, int speed)
        {
            ManagmentProtocol toSend = new ManagmentProtocol();

            toSend.State     = ManagmentProtocol.SOFTPERNAMENT;
            toSend.NodeStart = start;
            toSend.NodeEnd   = end;
            toSend.Speed     = speed;
            string data = JSON.Serialize(JSON.FromValue(toSend));

            writerNCC.Write(data);
        }
예제 #4
0
        public void sendReleaseSoftPernament(String connection)
        {
            ManagmentProtocol toSend = new ManagmentProtocol();

            toSend.State = ManagmentProtocol.RELEASESOFTPERNAMENT;
            int i = 0;

            int.TryParse(connection, out i);
            toSend.Connection = i;
            string data = JSON.Serialize(JSON.FromValue(toSend));

            writerNCC.Write(data);
        }
예제 #5
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.management.allocateNode(nodeName, clienttmp, Thread.CurrentThread, writer);

            try
            {
                while (true)
                {
                    received_data     = reader.ReadString();
                    received_object   = JSON.Deserialize(received_data);
                    received_Protocol = received_object.Value.ToObject <ManagmentProtocol>();
                    if (received_Protocol.State == ManagmentProtocol.INTERFACEINFORMATION)
                    {
                        UserInterface.showInterfaces(received_Protocol.Interfaces);
                    }
                    if (received_Protocol.State == ManagmentProtocol.GETTABLE)
                    {
                        UserInterface.showTable(received_Protocol.RoutingTable);
                    }
                }
            }
            catch (SocketException e)
            {
                UserInterface.log("Error: " + e.Message, ConsoleColor.Red);
                tp.management.removeNode(nodeName);
            }
            catch (IOException e)
            {
                UserInterface.log("Error: " + e.Message, ConsoleColor.Red);
                tp.management.removeNode(nodeName);
            }
        }
        internal void sendAllClients(List <string> list)
        {
            Dictionary <string, int> allClients = new Dictionary <string, int>();
            int i = 0;

            foreach (String s in list)
            {
                allClients.Add(s, i++);
                log(s, ConsoleColor.Cyan);
            }
            foreach (Node n in nodeList)
            {
                Address a = new Address(n.Name);
                if (a.type.Equals(192))
                {
                    ManagmentProtocol toSend = new ManagmentProtocol();
                    toSend.State = ManagmentProtocol.POSSIBLEDESITATIONS;
                    toSend.PossibleDestinations = allClients;
                    string data = JSON.Serialize(JSON.FromValue(toSend));
                    n.SocketWriter.Write(data);
                }
            }
        }
        private void Listen()
        {
            try
            {
                client = new TcpClient("127.0.0.1", this.port);
                BinaryReader reader = new BinaryReader(client.GetStream());
                writer = new BinaryWriter(client.GetStream());
                while (true)
                {
                    string received_data   = reader.ReadString();
                    JSON   received_object = JSON.Deserialize(received_data);
                    Management.ManagmentProtocol received_Protocol = received_object.Value.ToObject <Management.ManagmentProtocol>();
                    if (received_object.Type == typeof(Management.ManagmentProtocol))
                    {
                        Management.ManagmentProtocol management_packet = received_object.Value.ToObject <Management.ManagmentProtocol>();
                        if (management_packet.State == Management.ManagmentProtocol.TOOTHERNCC)
                        {
                            foreach (int port in management_packet.ConnectionToOtherNcc)
                            {
                                TcpClient connection             = new TcpClient("127.0.0.1", port);
                                ControlConnectionService service = new ControlConnectionService(connection, control);
                                Thread.Sleep(500);
                                ControlPacket packetToNCC = new ControlPacket(ControlInterface.NETWORK_CALL_COORDINATION_IN, ControlPacket.IN_PROGRESS, 0, "", "", control.domainNumber);
                                service.send(packetToNCC);
                            }
                        }
                        else if (management_packet.State == Management.ManagmentProtocol.SOFTPERNAMENT)
                        {
                            control.consoleWriter("[NCC <- Management] Soft pernament from " + management_packet.NodeStart + " to " + management_packet.NodeEnd);
                            int     RequestID = control.generateRequestID();
                            Address address   = new Address(management_packet.NodeStart);
                            int     cpccID    = address.type + address.domain + address.subnet + address.space;
                            control.addCpccRequest(RequestID, cpccID);

                            ControlPacket packetToCPCC = new ControlPacket(ControlInterface.CALL_INDICATION_CPCC, ControlPacket.IN_PROGRESS, management_packet.Speed, management_packet.NodeEnd, management_packet.NodeStart, RequestID);
                            packetToCPCC.Vc11 = 1;
                            packetToCPCC.Vc12 = 1;
                            packetToCPCC.Vc13 = 1;
                            ControlConnectionService cpccService = control.getCpccServiceByAddr(management_packet.NodeEnd);
                            cpccService.send(packetToCPCC);
                            control.consoleWriter("[NCC -> CPCC] Send Call Indication");
                        }
                        else if (management_packet.State == Management.ManagmentProtocol.RELEASESOFTPERNAMENT)
                        {
                            int id = management_packet.Connection;
                            control.consoleWriter("[NCC <- CPCC] Call release id: " + id);

                            if (!control.checkIfInterdomainRequest(id))
                            {
                                control.consoleWriter("[NCC -> CC]Send connection release");
                                CCtoNCCSingallingMessage packetToCC = new CCtoNCCSingallingMessage();
                                packetToCC.State     = CCtoNCCSingallingMessage.NCC_RELEASE_WITH_ID;
                                packetToCC.RequestID = id;
                                ControlConnectionService CCService = control.getCCService();
                                CCService.sendCCRequest(packetToCC);
                            }
                            else
                            {
                                control.consoleWriter("[NCC -> CC]Send connection release");
                                CCtoNCCSingallingMessage packetToCC = new CCtoNCCSingallingMessage();
                                packetToCC.State     = CCtoNCCSingallingMessage.NCC_RELEASE_WITH_ID;
                                packetToCC.RequestID = id;
                                ControlConnectionService CCService = control.getCCService();
                                CCService.sendCCRequest(packetToCC);
                            }
                        }
                    }
                }
            }
            catch (SocketException e)
            {
            }
            catch (IOException e)
            {
                Thread.Sleep(1000);
                Environment.Exit(1);
            }
        }