Ejemplo n.º 1
0
        public void GiveConnectionWithHost(RestOfHosts destination)
        {
            byte[] buffer = new byte[16];
            // Dispatcher.Invoke(() => ListBox12.Items.Add("Selected speed " + selectedSpeed));
            client.socketToDomain.Send(Encoding.ASCII.GetBytes("NCC-GET " + client.clientName + " " + destination.Name + " " + selectedSpeed)); //callRequest(adres A, adres B, speed)
            //probnie 10Gbps ale chyba zrobimy mozliwosc wyboru tej szybkosci bitowej, wysyła to callRequest że chce taką przepustowość do takiego hosta
            client.socketToDomain.Receive(buffer);                                                                                              // odpowiedź od Domaina

            if (Encoding.ASCII.GetString(buffer.ToList().GetRange(0, 3).ToArray()).Equals("ACK"))                                               // jeśli okej to wyśle ACK
            {
                //destination.modulation = BitConverter.ToInt32(buffer, 4); // dla danego sąsiada na podstawie zwróconej długości ścieżki w Routing Controller w Domainze
                // Domain zadecyduje jakiej modulacji użyć
                Console.WriteLine("I caught conf");
                // Dispatcher.Invoke(() => ListBox12.Items.Add("Selected speed " + client.clientName));
                destination.firstFrequencySlot = BitConverter.ToInt32(buffer, 3); // używane szczeliny do danego sąsiada
                destination.lastFrequencySlot  = BitConverter.ToInt32(buffer, 7);
                ushort port = BitConverter.ToUInt16(buffer, 11);
                foreach (var linkR in client.linkResources)
                {
                    if (port == linkR.port)
                    {
                        for (int i = destination.firstFrequencySlot; i <= destination.lastFrequencySlot; i++)
                        {
                            linkR.slots[i] = false;
                        }
                        break;
                    }
                }
                Console.WriteLine("Changed state");

                ListBox12.Items.Add("I've got path to " + destination.Name + ". You can start sending messages to this destination.");
                //comboBox1.Items.Add(destination); // dodajemy do możliwych adresatów wiadomości danego sąsiada
            }
            // WaitForData(); // po uzyskaniu wszystkich informacji przechodzimy w stan taki jak w 1 etapie
        }
Ejemplo n.º 2
0
        public static Client createHost(string ConFile)
        {
            Client       host = new Client();
            string       line;
            StreamReader streamReader = new StreamReader(ConFile);

            line            = streamReader.ReadLine();
            host.clientName = line.Split(' ')[1];

            line          = streamReader.ReadLine();
            host.clientIP = IPAddress.Parse(line.Split(' ')[1]);

            line         = streamReader.ReadLine();
            host.portOut = ushort.Parse(line.Split(' ')[1]);

            line         = streamReader.ReadLine();
            host.cloudIP = IPAddress.Parse(line.Split(' ')[1]);

            line           = streamReader.ReadLine();
            host.cloudPort = ushort.Parse(line.Split(' ')[1]);

            /*line = streamReader.ReadLine();
             * host.managementIP = IPAddress.Parse(line.Split(' ')[1]);*/

            line            = streamReader.ReadLine();
            host.domainPort = ushort.Parse(line.Split(' ')[1]);
            RestOfHosts neighbour;

            while ((line = streamReader.ReadLine()) != null)
            {
                string    Name = line.Split(' ')[0];
                IPAddress ip   = IPAddress.Parse(line.Split(' ')[1]);


                neighbour = new RestOfHosts(line);
                host.Neighbours.Add(neighbour);
            }
            Console.WriteLine("Host has been created");
            return(host);
        }