예제 #1
0
 public SNandRC(string rc_ip, string snpp_ip)
 {
     try
     {
         RC_IP = IPAddress.Parse(rc_ip);
         snpp  = new SubNetworkPointPool(new SubNetworkPoint(IPAddress.Parse(snpp_ip)));
     }
     catch (Exception E)
     {
         Console.WriteLine("SNandRC(): " + E.Message);
     }
 }
예제 #2
0
        public bool resolveSNPPS(ref NetworkPath networkPath, short band, short frequency)
        {
            //topology.getNetworkPath();
            foreach (var snpp in networkPath.snpps)
            {
                //if (canIGoOnAtThisFrequency)
                //{
                SNandRC sNandRc = SN_RCs.Find(x => x.snpp.snps[0].ipaddress.ToString() == snpp.snps[0].ipaddress.ToString());

                if (sNandRc != null)
                {
                    //IP węzła modelującego podsieć
                    string oldNodeIP = sNandRc.snpp.snps[0].ipaddress.ToString();

                    //Łącze dochodzące do węzła modelującego podsieć
                    int previousLink = networkPath.path.KrawedzieSciezki.FindIndex(x =>
                                                                                   x.Wezel2.ip == oldNodeIP);

                    //Łącze wychodzące z węzła modelującego podsieć
                    int nextLink = networkPath.path.KrawedzieSciezki.FindIndex(x =>
                                                                               x.Wezel1.ip == oldNodeIP);

                    Wezel w1 = networkPath.path.zwroc_ListaKrawedziSciezki[previousLink].Wezel1;
                    Wezel w2 = networkPath.path.zwroc_ListaKrawedziSciezki[nextLink].Wezel2;

                    SubNetworkPointPool SNPPFrom = new SubNetworkPointPool(new SubNetworkPoint(IPAddress.Parse(w1.ip)));
                    SubNetworkPointPool SNPPTo   = new SubNetworkPointPool(new SubNetworkPoint(IPAddress.Parse(w2.ip)));

                    // writeLog("Resolving path from " + SNPPFrom.snps[0].ipaddress + " to " + SNPPTo.snps[0].ipaddress);

                    //Czesciowa sciezka, którą trzeba dodać do nadścieżki
                    var partOfThePath = this.getPathFromRC(sNandRc.RC_IP.ToString(), SNPPFrom, SNPPTo, band,
                                                           frequency);

                    //Sciezka jest pusta
                    if (partOfThePath == null || partOfThePath.snpps.Count == 0)
                    {
                        //canIGoOnAtThisFrequency = false;
                        return(false);
                    }
                    //Ścieżka jest niepusta
                    else
                    {
                        //insertSubPath(ref networkPath, partOfThePath, previousLink, nextLink);
                        return(true);
                    }
                }
            }
            //}

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Generuje sciezke od jednego RC do drugiego RC
        /// </summary>
        /// <param name="rc_ip"></param>
        /// <param name="Source"></param>
        /// <param name="Destnation"></param>
        /// <param name="band"></param>
        /// <param name="frequency"></param>
        /// <returns></returns>
        public NetworkPath NetworkTopologyRequest(string rc_ip, SubNetworkPointPool Source,
                                                  SubNetworkPointPool Destnation, short band, short frequency)
        {
            try
            {
                //Generowanie wiadomosci
                string message = generateNetworkTopologyMessage(Source, Destnation, band, frequency);

                //Zamiana jej na tablice bajtow
                byte[] data = Encoding.ASCII.GetBytes(message);

                //Tworzenie IPEndPointa z rc, do którego wysyłamy prośbę o wyznaczenie ścieżki. Nasluchiwanie na porcie 11001
                IPEndPoint rcEndPoint = new IPEndPoint(this.ip, 11002);
                IPEndPoint myEndpoint = new IPEndPoint(IPAddress.Any, 0);

                UdpClient client = new UdpClient(rcEndPoint);
                //Polaczenie z endpointem
                //if (!this.sender.IsBound)
                //this.sender.Bind(rcEndPoint);

                //Wyslanie zapytania do RC o IP okreslonym przez rc_ip
                SendMessage(rc_ip, message);

                //alokacja bajtow do odbierania
                byte[] receivedBytes = new byte[0];

                receivedBytes = client.Receive(ref myEndpoint);

                client.Close();

                //Zmiana jej na stringa
                string receivedMesage = Encoding.ASCII.GetString(receivedBytes);

                //Tworzenie obiektu klasy NetworkPath ze sciezka wpisana
                NetworkPath networkPath = readNetworkTopologyResponse(receivedMesage, rc_ip);

                //Przypisanie wartosci pasma i czestotliwosci do sciezki
                networkPath.path.band      = band;
                networkPath.path.frequency = frequency;

                return(networkPath);
            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
                return(null);
            }

            return(null);
        }
예제 #4
0
        /// <summary>
        /// Aktualizuje wartości SNPPów po zmianie w krawędziach ścieżki.
        /// </summary>
        public void actualizeSNPPs()
        {
            snpps = new List <SubNetworkPointPool>();
            foreach (Wezel w in path.WezlySciezki)
            {
                SubNetworkPoint snp = new SubNetworkPoint(IPAddress.Parse(w.ip));

                SubNetworkPointPool snpp = new SubNetworkPointPool();

                snpp.Add(snp);

                snpps.Add(snpp);
            }
        }
예제 #5
0
        public void testSNPPsConstructors()
        {
            setUpValues1();

            SubNetworkPoint     SNP1  = new SubNetworkPoint(IPAddress.Parse(nodes[0].ip));
            SubNetworkPointPool SNPP1 = new SubNetworkPointPool(SNP1);
            SubNetworkPoint     SNP2  = new SubNetworkPoint(IPAddress.Parse(nodes[6].ip));
            SubNetworkPointPool SNPP2 = new SubNetworkPointPool(SNP2);

            Assert.AreNotEqual("", SNP1.ipaddress);
            Assert.AreNotEqual("", SNP2.ipaddress);

            Assert.AreEqual(SNP1, SNPP1.snps[0]);
            Assert.AreEqual(SNP2, SNPP2.snps[0]);
        }
예제 #6
0
        public List <SubNetworkPointPool> getPathOfSNPPs(SubNetworkPointPool beginningNetworkPointPool,
                                                         SubNetworkPointPool endNetworkPointPool, short band, Siec network)
        {
            //Zamiana adresow IP na inty
            int beginID = ipToInt(beginningNetworkPointPool.snps[0].ipaddress);
            int endID   = ipToInt(endNetworkPointPool.snps[0].ipaddress);

            //Tworzenie wezlow
            Wezel beginNode = new Wezel(beginID, beginID, beginID, beginningNetworkPointPool.snps[0].ipaddress.ToString());
            Wezel endNode   = new Wezel(endID, endID, endID, endNetworkPointPool.snps[0].ipaddress.ToString());

            //Wyszukiwanie sciezki
            Sciezka path = new Sciezka();

            path.wyznaczSciezke(beginNode, endNode, network.zwrocTabliceKierowaniaLaczami,
                                network.zwrocTabliceKierowaniaWezlami, ref network.wezly, band, network.Koszty);

            if (path.KrawedzieSciezki.Count != 0)
            {
                network.sciezki.Add(path);
            }

            //network.zwroc_sciezki.Find((x) => x.Wezel1 == beginNode && x.Wezel2 == endNode));network.zwroc_sciezki.Find((x) => x.Wezel1 == beginNode && x.Wezel2 == endNode);

            //Gdy sciezki w networki nie ma, to nie da sie ustanowic polaczenia
            if (path == null)
            {
                return(null);
            }
            else
            {
                List <SubNetworkPointPool> SNPPs = new List <SubNetworkPointPool>();
                foreach (Wezel w in path.WezlySciezki)
                {
                    SubNetworkPoint snp = new SubNetworkPoint(IPAddress.Parse(w.ip));

                    SubNetworkPointPool snpp = new SubNetworkPointPool();

                    snpp.Add(snp);

                    SNPPs.Add(snpp);
                }

                //Zwracanie listy SNPPów, gdzie kazdy z nich zawiera po jednym SNP.
                return(SNPPs);
            }
        }
예제 #7
0
        public NetworkPath getNetworkPath(SubNetworkPointPool beginningNetworkPointPool,
                                          SubNetworkPointPool endNetworkPointPool, short band, Siec network, short frequency)
        {
            //Zamiana adresow IP na inty
            int beginID = ipToInt(beginningNetworkPointPool.snps[0].ipaddress);
            int endID   = ipToInt(endNetworkPointPool.snps[0].ipaddress);

            //Tworzenie wezlow
            Wezel beginNode = this.network.wezly.Find(x => x.SNPP == beginningNetworkPointPool); // new Wezel(beginID, beginID, beginID, beginningNetworkPointPool.snps[0].ipaddress.ToString());
            Wezel endNode   = this.network.wezly.Find(x => x.SNPP == endNetworkPointPool);       //new Wezel(endID, endID, endID, endNetworkPointPool.snps[0].ipaddress.ToString());

            //Wyszukiwanie sciezki
            Sciezka path = new Sciezka();

            //path.wyznaczSciezke(beginNode, endNode, network.zwrocTabliceKierowaniaLaczami,
            //network.zwrocTabliceKierowaniaWezlami, ref network.wezly, band, network.Koszty, frequency);

            path.wyznaczSciezke(beginNode, endNode, band, frequency, network);

            //Gdy sciezki w networki nie ma, to nie da sie ustanowic polaczenia
            if (path.KrawedzieSciezki.Count != 0)
            {
                //Nowy obiekt klasy NetworkPath ze ścieżką "path"
                NetworkPath networkPath = new NetworkPath(path);

                //Dodawanie do dodanych sciezek
                this.pathsCopy.Add(networkPath);

                network.sciezki.Add(path);

                return(networkPath);
            }
            //Sciezka jest pusta
            else
            {
                return(null);
            }
            //network.zwroc_sciezki.Find((x) => x.Wezel1 == beginNode && x.Wezel2 == endNode));network.zwroc_sciezki.Find((x) => x.Wezel1 == beginNode && x.Wezel2 == endNode);
        }
예제 #8
0
 /// <summary>
 /// Generuje zapytanie do innego RC o wyznaczenie sciezki od Source do Destination przy dostepnym pasmie band
 /// </summary>
 /// <param name="Source"></param>
 /// <param name="Destination"></param>
 /// <param name="band"></param>
 /// <param name="frequency"></param>
 /// <returns></returns>
 public string generateGetPathFromRCMessage(SubNetworkPointPool Source, SubNetworkPointPool Destination, short band, short frequency)
 {
     return(this.ip + "#" + MessageNames.ROUTE_PATH + "#" + Source.snps[0].ipaddress + "#" +
            Destination.snps[0].ipaddress + "#" + band + "#" + frequency);
 }
예제 #9
0
        /// <summary>
        /// Wyznacza ścieżkę i wolną częstotliwość w ścieżce. W razie niepowodzenia zwraca pustą ścieżkę.
        /// </summary>
        /// <param name="rc_ip">IP RC, do którego RC zwraca się o wyznaczenie ścieżki.</param>
        /// <param name="Source">Węzeł przed węzłem modelującym podsieć.</param>
        /// <param name="Destnation">Węzeł po węźle modelującym podsieć.</param>
        /// <param name="band">Ilość szczelin.</param>
        /// <returns></returns>

        /*[Obsolete]
         * public NetworkPath TryGetPathFromSNMPAtFrequencies(string rc_ip, Wezel nodeFrom,
         *  Wezel nodeTo, short band, ref NetworkPath upperNetworkPath)
         * {
         *  SubNetworkPointPool SNPPFrom = new SubNetworkPointPool(new SubNetworkPoint(IPAddress.Parse(nodeFrom.ip)));
         *  SubNetworkPointPool SNPPTo = new SubNetworkPointPool(new SubNetworkPoint(IPAddress.Parse(nodeTo.ip)));
         *
         *  //RC po kolei próbuje otrzymać jakaś ścieżkę
         *  for (short i = 0; i < EONTable.capacity; i++)
         *  {
         *      if (nodeFrom.eonTable.OutFrequencies[i] == -1 && nodeTo.eonTable.InFrequencies[i] == -1)
         *      {
         *          upperNetworkPath = this.topology.getNetworkPath(SNPPFrom, SNPPTo, band, this.topology.network, i);
         *
         *          if (upperNetworkPath != null || upperNetworkPath.snpps.Count != 0)
         *          {
         *              //Próba wyznaczenia i-tej ścieżki
         *              var path = this.getPathFromRC(rc_ip, SNPPFrom, SNPPTo, band, i);
         *
         *              if (path != null || path.snpps.Count != 0)
         *                  return path;
         *          }
         *      }
         *      else
         *      {
         *          continue;
         *      }
         *  }
         *  //Zwracanie pustej sciezki
         *  return new NetworkPath();
         *
         * }*/

        /// <summary>
        /// Generuje sciezke od jednego RC do drugiego RC
        /// </summary>
        /// <param name="rc_ip"></param>
        /// <param name="Source"></param>
        /// <param name="Destnation"></param>
        /// <param name="band"></param>
        /// <param name="frequency"></param>
        /// <returns></returns>
        public NetworkPath getPathFromRC(string rc_ip, SubNetworkPointPool Source,
                                         SubNetworkPointPool Destnation, short band, short frequency)
        {
            try
            {
                //Generowanie wiadomosci
                string message = generateGetPathFromRCMessage(Source, Destnation, band, frequency);

                //Zamiana jej na tablice bajtow
                byte[] data = Encoding.ASCII.GetBytes(message);

                //Tworzenie IPEndPointa z rc, do którego wysyłamy prośbę o wyznaczenie ścieżki. Nasluchiwanie na porcie 11001
                IPEndPoint rcEndPoint = new IPEndPoint(this.ip, 11001);
                IPEndPoint myEndpoint = new IPEndPoint(IPAddress.Any, 0);

                UdpClient client = new UdpClient(rcEndPoint);
                //Polaczenie z endpointem
                //if (!this.sender.IsBound)
                //this.sender.Bind(rcEndPoint);

                //TODO: Wyskakuje blad, ze tylko jedno uzycie gniazda sieciowego jest dozwolone

                //Wyslanie zapytania do RC o IP okreslonym przez rc_ip
                SendMessage(rc_ip, message);
                //this.sender.SendTo(data, rcEndPoint);

                //alokacja bajtow do odbierania
                byte[] receivedBytes = new byte[0];

                //if (!this.receiver.IsBound)
                //this.receiver.Bind(rcEndPoint);


                receivedBytes = client.Receive(ref myEndpoint);

                client.Close();


                //Odebranie wiadomości od tamtego RC
                // UdpClient udpClient = new UdpClient(rcEndPoint);
                //receivedBytes = udpClient.Receive(ref rcEndPoint);
                //this.receiver.ReceiveFrom(receivedBytes, SocketFlags.None, ref rcendPoint);

                //this.receiver.ReceiveFrom(receivedBytes, ref rcEndPoint);

                //Zmiana jej na stringa
                string receivedMesage = Encoding.ASCII.GetString(receivedBytes);

                //Tworzenie obiektu klasy NetworkPath ze sciezka wpisana
                NetworkPath networkPath = readGetPathFromRCResponse(receivedMesage, rc_ip);

                //Przypisanie wartosci pasma i czestotliwosci do sciezki
                networkPath.path.band      = band;
                networkPath.path.frequency = frequency;

                return(networkPath);
            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
                return(null);
            }

            return(null);
        }
예제 #10
0
 /// <summary>
 /// Tworzy zapytanie Network Topology.
 /// </summary>
 /// <param name="Source"></param>
 /// <param name="Destination">IP klienta końcowego.</param>
 /// <param name="band"></param>
 /// <param name="frequency"></param>
 /// <returns></returns>
 public string generateNetworkTopologyMessage(SubNetworkPointPool Source, SubNetworkPointPool Destination, short band, short frequency)
 {
     return(this.ip + "#" + MessageNames.NETWORK_TOPOLOGY + "#" + Source.snps[0].ipaddress + "#" +
            Destination.snps[0].ipaddress + "#" + band + "#" + frequency);
 }
예제 #11
0
 public SNandRC()
 {
     snpp = new SubNetworkPointPool();
 }
예제 #12
0
 /// <summary>
 /// Wyznacza ścieżkę między dwoma SNPPami, korzystając z istniejących łączy.
 /// </summary>
 /// <param name="beginningNetworkPoint"></param>
 /// <param name="endNetworkPoint"></param>
 /// <returns></returns>
 public List <SubNetworkPointPool> getPathOfSNPPs(SubNetworkPointPool beginningNetworkPointPool,
                                                  SubNetworkPointPool endNetworkPointPool, short band)
 {
     return(getPathOfSNPPs(beginningNetworkPointPool, endNetworkPointPool, band, this.network));
 }
예제 #13
0
        public List <SubNetworkPointPool> routePath(SubNetworkPointPool beginningNetworkPointPool,
                                                    SubNetworkPointPool endNetworkPointPool, short band)
        {
            var path = getPathOfSNPPs(beginningNetworkPointPool, endNetworkPointPool, band);

            //0 w ścieżce oznacza, że nie da się zestawić połączenia
            if (path.Count == 0)
            {
                //Skopiowanie sieci
                var newNetwork = new Siec(network);

                newNetwork.krawedzie = newNetwork.krawedzie.OrderByDescending(o => o.Waga).ToList();

                for (int i = 0; i < newNetwork.krawedzie.Count; i++)
                {
                    Wezel W1 = new Wezel(newNetwork.krawedzie[i].Wezel1.idWezla, newNetwork.krawedzie[i].Wezel1.idWezla,
                                         newNetwork.krawedzie[i].Wezel1.idWezla, newNetwork.krawedzie[i].Wezel1.ip);
                    Wezel W2 = new Wezel(newNetwork.krawedzie[i].Wezel2.idWezla, newNetwork.krawedzie[i].Wezel2.idWezla,
                                         newNetwork.krawedzie[i].Wezel2.idWezla, newNetwork.krawedzie[i].Wezel2.ip);

                    Lacze potentialLink = potentialLinks.Find(x => x.Wezel1.idWezla == W1.idWezla && x.Wezel2.idWezla == W2.idWezla &&
                                                              x.Wezel1.ip == W1.ip && x.Wezel2.ip == W2.ip);

                    //udalo sie znalezc lacze
                    if (potentialLink != null)
                    {
                        //Wstawiamy nowe łącze na koniec listy
                        potentialLink.idKrawedzi = newNetwork.krawedzie.Count;
                        newNetwork.krawedzie.Add(potentialLink);
                        newNetwork.aktualizujLiczniki();

                        //Po wstawieniu nowego łącza do eksperymentalnej sieci, zapuszaczamy algorytm Floyda
                        newNetwork.algorytmFloyda();

                        path = getPathOfSNPPs(beginningNetworkPointPool, endNetworkPointPool, band);

                        //nie udało się
                        if (path.Count == 0)
                        {
                            continue;
                        }
                        //udało się, dzięki wstawieniu krawędzi z potencjalnej udało się stworzyć ścieżkę
                        else
                        {
                            //Pierwszy wezel sciezki
                            Wezel beginNode = newNetwork.wezly.Find(x => x.ip == path[0].snps[0].ipaddress.ToString());
                            //Ostatni wezel sciezki
                            Wezel endNode = newNetwork.wezly.Find(x => x.ip == path[path.Count - 1].snps[0].ipaddress.ToString());

                            //Wyznaczamy sciezke jeszcze raz, by uzyskac liste laczy
                            var links = new Sciezka().wyznaczSciezke(beginNode, endNode, newNetwork.zwrocTabliceKierowaniaLaczami,
                                                                     newNetwork.zwrocTabliceKierowaniaWezlami, ref newNetwork.wezly, band, newNetwork.Koszty);

                            foreach (Lacze link in links)
                            {
                                //Jeżeli danej krawędzi z wyznaczonej ścieżki nie ma w wyjściowej topologii, trzeba ją dodać do tej topologii
                                if (!network.zwroc_lacza.Contains(link))
                                {
                                    network.krawedzie.Add(link);
                                    //jeszcze zmiana id krawedzi na jej indeks
                                    link.idKrawedzi = network.krawedzie.Count - 1;
                                    //Lacze juz nie jest potencjalne, lecz rzeczywiste
                                    this.potentialLinks.Remove(link);
                                }
                            }

                            return(path);
                        }
                    }
                }

                //Zwrocenie pustej listy, gdy nic sie nie udalo zrobic
                return(new List <SubNetworkPointPool>());
            }
            //A jak Count != 0, to mozna zwrocic sceizke
            else
            {
                return(path);
            }
            return(null);
        }