Esempio n. 1
0
        /// <summary>
        /// Inicjalizacja działania sieci
        /// </summary>
        public void Init()
        {
            Dictionary <int, string> nodeFiles = parser.ReadXml("config.xml");

            foreach (KeyValuePair <int, string> ipAddress in networkNodeIPAddresses)
            {
                SendData(ipAddress.Value, nodeFiles[ipAddress.Key]);
                CLI.PrintSentXML(nodeFiles[ipAddress.Key], ipAddress.Key);
                Listen();
            }

            SendData("127.0.0.1", nodeFiles[0]);
            Listen();
            CLI.PrintConfigFilesSent();
        }
Esempio n. 2
0
        /// <summary>
        /// Wysyła strumień bitów
        /// </summary>
        /// <param name="receiver">adres na który wysłane będą dane</param>
        /// <param name="data">dane do wysłania</param>
        public void SendData(string receiver, string data)
        {
            try
            {
                CreateSocket();

                socket.Connect(receiver, port);
                socket.Send(ASCIIEncoding.ASCII.GetBytes(data));
                Console.WriteLine("SENDING");

                Close();
            }
            catch (Exception e)
            {
                CLI.PrintError();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// konfiguracja sieci w mpls
        /// </summary>
        public static void Configure(int nodeAmount, List <Manager> manager, int clientAmount, List <Manager> managerClient, Manager managerCloud)
        {
            CLI.RequestXML();
            string name;

            do
            {
                name = Console.ReadLine();

                if (name == "esc")
                {
                    break;
                }
                XML.SetName(name);
            } while (XML.Test() != true);
            if (name != "esc")
            {
                for (int i = 1; i <= nodeAmount; i++)
                {
                    try
                    {
                        manager[i - 1].Send(XML.StringNode(i));
                    }
                    catch (Exception ex)
                    {
                    }
                }

                for (int i = 1; i <= clientAmount; i++)
                {
                    try
                    {
                        managerClient[i - 1].Send(XML.StringClients());
                    }
                    catch (Exception ex)
                    {
                    }
                }
                managerCloud.Send(XML.StringCableLinks(name));
                CLI.PrintConfigFilesSent();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Nasłuchuje czy przychodzą dane
        /// </summary>
        public void Listen()
        {
            try
            {
                socket = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.IP);
                socket.Bind(ipEndPoint);

                socket.Listen(1);
                Console.WriteLine("LISTENING");

                Socket handler = socket.Accept();
                response = ReceiveData(handler);
                CLI.PrintReceivedMessage(response);

                socket.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 5
0
        public static void ConfigureSubnetworks()
        {
            CLI.RequestXML();
            string name;

            do
            {
                name = Console.ReadLine();

                if (name == "esc")
                {
                    break;
                }
                XML.SetName(name);
            } while (XML.Test() != true);
            if (name != "esc")
            {
                Program.managerCloud.Send("clean_dictionary");
                XMLeonSubnetwork file = new XMLeonSubnetwork(name);


                CLI.PrintConfigFilesSent();

                lock (Program.subnetworksList)
                {
                    Program.subnetworksList = file.GetSubnetworks();
                    foreach (Subnetwork sub in Program.subnetworksList)
                    {
                        lock (Program.subnetworkManager)
                        {
                            try
                            {
                                Program.subnetworkManager.Find(x => x.number == sub.id).Send(sub.myContent);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Nie udała się konfiguracja podsieci, ex:" + ex.ToString());
                            }
                        }
                    }
                }
                string client;
                client = file.GetClientFile();

                List <int> portOut = XMLeon.GetClientPortOut(client);
                for (int i = 0; i < Program.amountOfclients; i++)
                {
                    try
                    {
                        Program.managerClient[i].Send("port_out:" + portOut[i]);
                        Console.WriteLine("Wysyłam info o porcie: " + portOut[i]);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Błąd wysyłania informacji o porcie");
                    }
                }
                string    linksFile = file.GetLinkFile();
                XMLParser xml       = new XMLParser(linksFile);
                Program.links = xml.GetLinks();
                lock (Program.managerCloud)
                {
                    Program.managerCloud.Send(XML.StringCableLinks(linksFile));
                    //Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaa");
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Main
        /// </summary>
        /// <param name="args">Nieużywane</param>
        static void Main(string[] args)
        {
            //w tescie sie tworzy te sieci i inne xml, wiec raz odpalic
            //a potem zakomentowac
            //i znowu skompilowac

            //Tests.TestXML();

            /*    bool[] a = new[] { true, false };
             *
             *  MemoryStream stream = new MemoryStream();
             *  IFormatter formatter = new BinaryFormatter();
             *  formatter.Serialize(stream, a);
             *
             *  IFormatter formatter1= new BinaryFormatter();
             *  stream.Seek(0, SeekOrigin.Begin);
             *  var b = formatter1.Deserialize(stream);
             *
             *  Console.WriteLine(b);*/


            Console.WriteLine("MANAGER:" + args[0]);
            subnetworkManager = new List <Manager>();

            //ustalenie wartosci ile mamy czego
            amountOfnodes       = Int32.Parse(args[1]);
            amountOfclients     = Int32.Parse(args[2]);
            amountOfSubnetworks = Int32.Parse(args[3]);



            //laczenie sie z chmura
            managerCloud = new Manager();
            managerCloud.CreateSocket("127.0.31." + args[0], 11001);


            //sie tu czasem wywalalo, to pomaga
            //laczenie sie z chmura
            while (true)
            {
                try
                {
                    managerCloud.Connect("127.0.30." + args[0], 11001);
                    break;
                }
                catch { }
            }


            Agent agent;

            if (args[0] == "1")
            {
                Console.WriteLine("Centralny Manager");
                isTheTopSub = true;

                for (int i = 2; i <= amountOfSubnetworks; i++)
                {
                    isTheBottonSub = true;
                    subnetworkManager.Add(new Manager(i));
                    subnetworkManager[i - 2].CreateSocket("127.0.21." + i, 11001);
                    subnetworkManager[i - 2].Connect("127.0.20." + i, 11001);
                }
                //laczenie sie z klientami
                for (int i = 1; i <= amountOfclients; i++)
                {
                    managerClient.Add(new Manager());
                    Console.WriteLine("Robię managera dla clienta " + "127.0.12." + i.ToString());

                    managerClient[i - 1].CreateSocket("127.0.13." + i.ToString(), 11001);
                    managerClient[i - 1].Connect("127.0.12." + i.ToString(), 11001);
                }
            }
            //jezeli nie jest to glowny manager to tworzymy agenta
            //polaczenia z nodami sa po tym jak agent dostanie info ktory plik koniguracyjny ma brac;
            else
            {
                agent = new Agent();

                agent.CreateSocket("127.0.20." + args[0].ToString(), 11001);
                Thread thread = new Thread(new ThreadStart(agent.Connect));
                thread.Start();
                Thread threadComputing = new Thread(new ThreadStart(agent.ComputingThread));
                threadComputing.Start();
            }


            //string do ktorego wczytujemy polecenie odbiorcy
            string choose;

            while (true)
            {
                //wypisanie polecen
                CLI.Prompt();

                choose = Console.ReadLine();
                if (choose == "1")
                {
                    if (Program.isTheTopSub)
                    {
                        CLI.ConfigureSubnetworks();
                    }
                }
                else if (choose == "2")
                {
                    if (Program.isTheBottonSub)
                    {
                        CLI.GetNodeFromNode(managerNodes);
                    }
                }
                else if (choose == "3")
                {
                    if (isTheBottonSub)
                    {
                        CLI.GetMatrixFromNode(managerNodes);
                    }
                }
                else if (choose == "4")
                {
                    Console.Clear();
                }
                else
                {
                    Console.WriteLine("Nie ma takiej komendy");
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// odpowiada za polaczenie sie z tymi wszystkimi wezlami na samy dole
        /// gdy juz wiemy ze nasz manger jest tym najnizszym managerem
        ///
        /// </summary>
        /// <param name="message"></param>
        static void ConnectSubnetwork(string message)
        {
            // Console.Write(DateTime.Now.ToString("HH:mm:ss") + " : ");
            Console.WriteLine(" Zadanie konfiguracji podsieci");
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Niepoprawny format wiadomości, ex:" + ex.ToString());
            }
            XMLeonSubnetwork eonXml   = new XMLeonSubnetwork(xmlDoc);
            string           linkFile = eonXml.GetLinkFile();
            XMLParser        xml      = new XMLParser(linkFile);

            Program.links = xml.GetLinks();
            lock (Program.managerCloud)
            {
                Program.managerCloud.Send(XML.StringCableLinks(linkFile));
            }
            CLI.PrintConfigFilesSent();

            //laczenie sie z wezlami w podsieci
            lock (Program.managerNodes)
            {
                //i jest do indeksacji Program.managerNodes
                int i = 0;
                foreach (Node node in Program.nodes)
                {
                    Program.managerNodes.Add(new Manager(node.number));
                    Program.managerNodes[i].CreateSocket("127.0.4." + node.number, 11001);
                    while (true)
                    {
                        try
                        {
                            Program.managerNodes[i].Connect("127.0.3." + node.number, 11001);
                            break;
                        }
                        catch
                        {
                        }
                    }

                    //uruchuchomienie thread pingow do wezlow
                    try
                    {
                        Thread threadPing = new Thread(new ThreadStart(Program.managerNodes[i].PingThread));
                        threadPing.Start();
                    }
                    catch
                    {
                        Console.WriteLine("Nie udało się włączyć pinga");
                    }

                    i++;
                }
            }
        }