Example #1
0
        public void testWyznaczSciezke()
        {
            Siec  network = new Siec();
            Wezel w1      = new Wezel(1, "127.0.0.1");
            Wezel w2      = new Wezel(2, "127.0.0.2");
            Wezel w3      = new Wezel(3, "127.0.0.3");

            network.wezly.Add(w1);
            network.wezly.Add(w2);
            network.wezly.Add(w3);
            network.krawedzie.Add(new Lacze(12, w1, w2));
            network.krawedzie.Add(new Lacze(23, w2, w3));
            short   band      = 5;
            short   frequency = 6;
            Sciezka path      = new Sciezka(w1, w3);

            network.algorytmFloyda();
            path.wyznaczSciezke(w1, w2, band, frequency, network);

            Assert.AreNotEqual(0, path.WezlySciezki.Count);
            Assert.AreNotEqual(0, path.KrawedzieSciezki.Count);
            Assert.AreEqual(w1.ip, path.WezlySciezki[0].ip);
            Assert.AreEqual(w2.ip, path.WezlySciezki[1].ip);
            Assert.AreEqual(w3.ip, path.WezlySciezki[2].ip);
        }
Example #2
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);
            }
        }
Example #3
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);
        }
Example #4
0
        public void testRoutePathsInNetwork()
        {
            Siec network = new Siec();

            List <Wezel>     nodes = new List <Wezel>();
            List <IPAddress> ips   = new List <IPAddress>();
            List <Lacze>     links = new List <Lacze>();

            ips.Add(IPAddress.Parse("127.0.0.2"));
            ips.Add(IPAddress.Parse("127.0.0.31"));
            ips.Add(IPAddress.Parse("127.0.0.17"));
            ips.Add(IPAddress.Parse("127.0.0.4"));
            ips.Add(IPAddress.Parse("127.0.0.33"));
            ips.Add(IPAddress.Parse("127.0.0.15"));
            ips.Add(IPAddress.Parse("127.0.0.6"));

            nodes.Add(new Wezel(2, "127.0.0.2"));
            nodes.Add(new Wezel(31, "127.0.0.31"));
            nodes.Add(new Wezel(17, "127.0.0.17"));
            nodes.Add(new Wezel(4, "127.0.0.4"));
            nodes.Add(new Wezel(33, "127.0.0.33"));
            nodes.Add(new Wezel(15, "127.0.0.15"));
            nodes.Add(new Wezel(6, "127.0.0.6"));

            //Dodawanie krawedzi
            links.Add(new Lacze(0, nodes[0], nodes[1], 1, 0));  //2-31
            links.Add(new Lacze(1, nodes[1], nodes[2], 1, 0));  //31-17
            links.Add(new Lacze(2, nodes[2], nodes[3], 1, 0));  //17-4
            links.Add(new Lacze(3, nodes[2], nodes[4], 1, 0));  //17-33
            links.Add(new Lacze(4, nodes[2], nodes[5], 1, 0));  //17-15
            links.Add(new Lacze(5, nodes[4], nodes[5], 1, 0));  //33-15
            links.Add(new Lacze(6, nodes[5], nodes[6], 1, 0));  //15-6

            links.Add(new Lacze(7, nodes[1], nodes[0], 1, 0));  //31-2
            links.Add(new Lacze(8, nodes[2], nodes[1], 1, 0));  //17-31
            links.Add(new Lacze(9, nodes[3], nodes[2], 1, 0));  //4-17
            links.Add(new Lacze(10, nodes[4], nodes[2], 1, 0)); //33-17
            links.Add(new Lacze(11, nodes[5], nodes[2], 1, 0)); //15-17
            links.Add(new Lacze(12, nodes[5], nodes[4], 1, 0)); //15-33
            links.Add(new Lacze(13, nodes[6], nodes[5], 1, 0)); //6-15

            //DOdanie wszystkich krawedzi do sieci
            network.krawedzie.AddRange(links);

            //Dodanie wszystkich wezlow do sieci
            network.wezly.AddRange(nodes);

            //zapuszczenie algorytmu floyda
            network.algorytmFloyda();

            //elementy sieci nie powinny byc zerowe
            Assert.IsFalse(network.Koszty.Length == 0);
            Assert.IsFalse(network.wezly.Count == 0);
            Assert.AreEqual(network.wezly.Count * network.wezly.Count, network.Koszty.Length);
            Assert.IsFalse(network.krawedzie.Count == 0);
            Assert.IsTrue(network.sprawdzSpojnosc());

            Sciezka path2_6 = new Sciezka(nodes[0], nodes[6]);

            path2_6.wyznaczSciezke(path2_6.Wezel1, path2_6.Wezel2, network.zwrocTabliceKierowaniaLaczami,
                                   network.zwrocTabliceKierowaniaWezlami, ref network.wezly, 1, network.Koszty, 1);

            path2_6.wyznaczWezly(path2_6.Wezel1);

            path2_6.pokazSciezke();

            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[0]));
            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[1]));
            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[2]));
            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[5]));
            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[6]));

            //Wyswietlenie tablic Floydowych
            //network.tabliceFloyd(network.zwrocTabliceKierowaniaLaczami, network.zwrocTabliceKierowaniaWezlami, network.Koszty);
        }
Example #5
0
        public void testTables1()
        {
            Siec network = new Siec();

            List <Wezel>     nodes = new List <Wezel>();
            List <IPAddress> ips   = new List <IPAddress>();
            List <Lacze>     links = new List <Lacze>();

            ips.Add(IPAddress.Parse("127.0.0.1"));
            ips.Add(IPAddress.Parse("127.0.0.2"));
            ips.Add(IPAddress.Parse("127.0.0.3"));
            ips.Add(IPAddress.Parse("127.0.0.4"));
            ips.Add(IPAddress.Parse("127.0.0.5"));
            ips.Add(IPAddress.Parse("127.0.0.6"));
            ips.Add(IPAddress.Parse("127.0.0.7"));

            //Tworzenie wezlow o id odpowiadajacych adresom IP z listy
            for (int i = 0; i < ips.Count; i++)
            {
                nodes.Add(new Wezel(i + 1, ips[i].ToString()));
            }

            //Dodawanie krawedzi
            links.Add(new Lacze(0, nodes[0], nodes[3], 1));
            links.Add(new Lacze(1, nodes[3], nodes[6], 1));
            links.Add(new Lacze(2, nodes[6], nodes[2], 1));
            links.Add(new Lacze(3, nodes[2], nodes[1], 1));
            links.Add(new Lacze(4, nodes[3], nodes[4], 1));
            links.Add(new Lacze(5, nodes[4], nodes[5], 1));
            links.Add(new Lacze(6, nodes[5], nodes[3], 1));
            links.Add(new Lacze(7, nodes[3], nodes[0], 1));
            links.Add(new Lacze(8, nodes[1], nodes[3], 1));

            //DOdanie wszystkich krawedzi do sieci
            network.krawedzie.AddRange(links);

            //Dodanie wszystkich wezlow do sieci
            network.wezly.AddRange(nodes);

            //zapuszczenie algorytmu floyda
            network.algorytmFloyda();

            //elementy sieci nie powinny byc zerowe
            Assert.IsFalse(network.Koszty.Length == 0);
            Assert.IsFalse(network.wezly.Count == 0);
            Assert.AreEqual(network.wezly.Count * network.wezly.Count, network.Koszty.Length);
            Assert.IsFalse(network.krawedzie.Count == 0);
            Assert.IsTrue(network.sprawdzSpojnosc());

            /*
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 3].idWezla);
             * Assert.AreEqual(7, network.zwrocTabliceKierowaniaWezlami[3, 2].idWezla);
             * Assert.AreEqual(7, network.zwrocTabliceKierowaniaWezlami[3, 1].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 6].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 2].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 1].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 4].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 5].idWezla);
             * Assert.AreEqual(5, network.zwrocTabliceKierowaniaWezlami[3, 5].idWezla);
             * Assert.AreEqual(6, network.zwrocTabliceKierowaniaWezlami[4, 5].idWezla); */

            Sciezka path1_2 = new Sciezka(nodes[0], nodes[1]);

            path1_2.KrawedzieSciezki = path1_2.wyznaczSciezke(path1_2.Wezel1, path1_2.Wezel2, network.zwrocTabliceKierowaniaLaczami,
                                                              network.zwrocTabliceKierowaniaWezlami, ref network.wezly, 1, network.Koszty, 10);

            path1_2.wyznaczWezly(path1_2.Wezel1);

            path1_2.pokazSciezke();

            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[0]));
            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[3]));
            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[6]));
            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[2]));
            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[1]));

            //Wyswietlenie tablic Floydowych
            //network.tabliceFloyd(network.zwrocTabliceKierowaniaLaczami, network.zwrocTabliceKierowaniaWezlami, network.Koszty);
        }