Exemplo n.º 1
0
        public Server(string config)
        {
            centerIP = Dns.GetHostEntry(ip).AddressList[0];
            server   = new TcpListener(centerIP, centerPort);


            try {
                ConfigLoader.LoadConfig(config);

                GUIWindow.PrintLog("Management center is waiting for connections...");
            } catch (Exception ex) {
                Console.WriteLine(ex);
                GUIWindow.PrintLog(ex.ToString());
            } finally {
                server.Start();
            }

            new Thread(StartListening).Start();
        }
Exemplo n.º 2
0
        public void HandleClient(TcpClient client)
        {
            TcpClient     MyClient = client;
            NetworkStream stream   = MyClient.GetStream();
            StreamReader  reader   = new StreamReader(stream);
            StreamWriter  writer   = new StreamWriter(stream);

            try {
                string   request = reader.ReadLine();
                string[] cut     = request.Split(':');

                if (cut[0].Equals("REGISTRATION") && cut[1].Equals("HOST"))
                {
                    numOfHosts++;

                    foreach (Host h in ConfigLoader.GetHosts())
                    {
                        if (h.getIP() == cut[2])
                        {
                            lock (hostConnections) {
                                hostConnections.AddLast(new HostConnection(h, client, Convert.ToInt32(cut[3]), this));
                            }
                            writer.WriteLine("REGISTRATION:OK");
                            writer.Flush();
                            GUIWindow.PrintLog("Host #" + cut[3] + "|" + cut[2] + "| has been registered");
                            break;
                        }
                    }
                }
                else if (cut[0].Equals("REGISTRATION") && cut[1].Equals("ROUTER"))
                {
                    numOfRouters++;

                    foreach (Router r in ConfigLoader.GetRouters())
                    {
                        if (r.getIP() == cut[2])
                        {
                            lock (routerConnections) {
                                routerConnections.AddLast(new RouterConnection(r, client, Convert.ToInt32(cut[3])));
                            }
                            writer.WriteLine("REGISTRATION:OK");
                            writer.Flush();

                            GUIWindow.PrintLog("Router #" + cut[3] + "|" + cut[2] + "| has been registered");

                            //LinkedList<string[]> rows = new LinkedList<string[]>();
                            //foreach (var tuple in ConfigLoader.routerMPLSTables) {
                            //    if (tuple.Item1 == Convert.ToInt32(cut[3])) {
                            //        var vals = tuple.Item2;
                            //        string[] row = { vals.Item1.ToString(), vals.Item2.ToString(), vals.Item3.ToString(), vals.Item4,
                            //                         vals.Item5.ToString(), vals.Item6.ToString(), vals.Item7.ToString(), vals.Rest.Item1.ToString() };
                            //        rows.AddLast(row);
                            //    }
                            //}
                            //byte[] bytes = SerializeObject(rows);
                            //stream.Write(bytes, 0, bytes.Length);
                            //GUIWindow.PrintLog("Sending MPLS table to Router #" + cut[3]);

                            break;
                        }
                    }
                }
            } catch (IOException ex) {
                GUIWindow.PrintLog("One of the network nodes has been disconected");
            }
        }
Exemplo n.º 3
0
 public void RemoveHostConnection(HostConnection hostConnection)
 {
     GUIWindow.PrintLog("Host #" + hostConnection.GetID() + " has disconnected");
     hostConnections.Remove(hostConnection);
 }
Exemplo n.º 4
0
 public GUIWindow()
 {
     InitializeComponent();
     instance = this;
 }