Example #1
0
 public NetworkNode()
 {
     this.commutationTable           = new CommutationTable();
     this.borderNodeCommutationTable = new BorderNodeCommutationTable();
     this.eonTable         = new EONTable();
     this.commutationField = new CommutationField(ref borderNodeCommutationTable, ref commutationTable, ref eonTable, 1);
 }
        public void testAddBorderNodeCommutationTableRow()
        {
            IPAddress IP_IN                 = IPAddress.Parse("123.123.123.123");
            short     port_in               = 1;
            short     band                  = 2;
            short     frequency             = 3;
            short     modulationPerformance = 4;
            short     bitRate               = 5;
            IPAddress IPSocketOut           = IPAddress.Parse("234.234.234.234");
            short     socketPort            = 6;
            short     hopsNumber            = 7;

            //stworzenie nowego rzedu tablicy komutacji routera brzegowego
            BorderNodeCommutationTableRow row = new BorderNodeCommutationTableRow(IP_IN.ToString(), port_in, band, frequency,
                                                                                  modulationPerformance, bitRate, IPSocketOut.ToString(), socketPort, hopsNumber);

            //nowa tabela komutacji wezla brzegowego
            BorderNodeCommutationTable table = new BorderNodeCommutationTable();

            //Dodanie wiersza do tabeli komutacji wezla brzegowego
            table.Table.Add(row);

            //Powinny byc takie same
            Assert.AreEqual(row, table.Table[0]);
        }
 /// <summary>
 /// Konstruktor z referencjami na tablice i liczba wyjsciowych buforow
 /// </summary>
 /// <param name="borderNodeCommutationTable"></param>
 /// <param name="commutationTable"></param>
 /// <param name="EonTable"></param>
 public CommutationField(ref BorderNodeCommutationTable borderNodeCommutationTable,
     ref CommutationTable commutationTable, ref EONTable EonTable, int buffersOutCount) : this()
 {
     //bufferIn = new Buffer();
     // BuffersOut = new List<Buffer>(buffersOutCount);
     this.borderNodeCommutationTable = borderNodeCommutationTable;
     this.EonTable = EonTable;
     this.commutationTable = commutationTable;
 }
        public void testDetermineModulationPerformance()
        {
            for (int i = 1; i < 9; i++)
            {
                //i - ilosc hopow
                //9-i - wartosc wydajnosci modulacji
                Assert.AreEqual(9 - i, BorderNodeCommutationTable.determineModulationPerformance((short)i));
            }

            //W przeciwnych przypadkach powinno zwrocic 1
            Assert.AreEqual(1, BorderNodeCommutationTable.determineModulationPerformance(9));
            Assert.AreEqual(1, BorderNodeCommutationTable.determineModulationPerformance(19));
            Assert.AreEqual(1, BorderNodeCommutationTable.determineModulationPerformance(119));
            Assert.AreEqual(1, BorderNodeCommutationTable.determineModulationPerformance(0));
            Assert.AreEqual(1, BorderNodeCommutationTable.determineModulationPerformance(-1));
            Assert.AreEqual(1, BorderNodeCommutationTable.determineModulationPerformance(-100));
        }
        public void testFindRow1()
        {
            string IP   = "127.0.0.1";
            short  port = 2;

            //Nowa tabela
            BorderNodeCommutationTable table = new BorderNodeCommutationTable();

            //Nowy rząd
            BorderNodeCommutationTableRow row = new BorderNodeCommutationTableRow(IP, port, 0, 0, 0, 0, "0.0.0.0", 0, 0);

            //Dodanie rzedu do tabeli
            table.Table.Add(row);

            //    Assert.AreEqual(row, table.FindRow(IP, port));

            // Assert.AreEqual(0, table.FindIndex(IP, port));
        }
        public void testGenerateCharacteristicInfo()
        {
            IPAddress IP_IN                 = IPAddress.Parse("123.123.123.123");
            short     port_in               = 1;
            short     band                  = 2;
            short     frequency             = 3;
            short     modulationPerformance = 4;
            short     bitRate               = 5;
            IPAddress IPSocketOut           = IPAddress.Parse("234.234.234.234");
            short     socketPort            = 6;
            short     hopsNumber            = 7;

            //stworzenie nowego rzedu tablicy komutacji routera brzegowego
            BorderNodeCommutationTableRow row = new BorderNodeCommutationTableRow(IP_IN.ToString(), port_in, band, frequency,
                                                                                  modulationPerformance, bitRate, IPSocketOut.ToString(), socketPort, hopsNumber);

            //pozostale dane do pakietu, korzysta tez z danych od pakietu
            string    inscription      = "Mam malo wody";
            short     portNumber       = port_in;
            IPAddress IP_Source        = IP_IN;
            IPAddress IP_Destination   = IPSocketOut;
            short     packageNumber    = 5;
            short     usableInfoLength = (short)inscription.Length;
            short     ID = 17;
            short     howManyPackages = 1;

            //Stworzenie pakietu
            Package P = new Package(inscription, portNumber, IP_Destination.ToString(), IP_Source.ToString(), usableInfoLength, packageNumber, 0, 0, 0, 0, ID, howManyPackages);

            BorderNodeCommutationTable table = new BorderNodeCommutationTable();

            table.Table.Add(row);

            Package P2 = new Package(RouterClientPortIn.GenerateCharacteristicInfo(P.toBytes(), ref table));

            Assert.AreEqual(row.frequency, P2.frequency);
            Assert.AreEqual(row.band, P2.band);
            Assert.AreEqual(row.bitRate, P2.bitRate);
            Assert.AreEqual(row.modulationPerformance, P2.modulationPerformance);
        }
Example #7
0
        public void Run(string number, ref CommutationTable commutationTable,
                        ref BorderNodeCommutationTable borderNodeCommutationTable,
                        ref EONTable eonTable)
        {
            this.eonTable                   = eonTable;
            this.commutationTable           = commutationTable;
            this.borderNodeCommutationTable = borderNodeCommutationTable;
            //Zmienna do przechowywania klucza na adres wychodzacy powiazany z socketem sluchaczem
            string settingsString = "";


            //pobranie wlasnosci zapisanych w pliku konfiguracyjnym
            tmp = OperationConfiguration.ReadAllSettings(mySettings);


            //przeszukanie wszystkich kluczy w liscie


            //Uruchamiamy watek na kazdym z tworzonych sluchaczy


            //    CreateConnect("127.0.0.14","1NMS");
            CreateConnect(ConfigurationManager.AppSettings[number + "NMS"], number + "NMS");



            ConsoleKeyInfo cki;

            while (true)
            {
                cki = Console.ReadKey();
                if (cki.Key == ConsoleKey.Escape)
                {
                    break;
                }
            }
        }
        /// <summary>
        /// Funkcja wpisujaca do pakietu w postaci tablicy bajtow.
        /// </summary>
        /// <param name="packageBytes"></param>
        /// <param name="borderNodeCommutationTable"></param>
        /// <returns></returns>
        public static byte[] GenerateCharacteristicInfo(byte[] packageBytes, ref BorderNodeCommutationTable table)
        {
            try
            {
                //Wyjecie IP zrodla z pakietu
                string IP_in = Package.exctractSourceIP(packageBytes).ToString();

                //Numer portu, ktorym przyszedl pakiet od klienta
                short port_in = Package.extractPortNumber(packageBytes);

                //IP Destination, do ktorego klienta idzie
                string IPDestionation = Package.exctractDestinationIP(packageBytes).ToString();
                //Odnajduje okreslony rzad
                var row = table.FindRow(IP_in, port_in, IPDestionation);

                //Odtworzenie obiektu klasy pakiet
                Package P = new Package(packageBytes);

                //Zmiana parametrow
                P.changeBand(row.band);
                P.changeBitRate(row.bitRate);
                //TODO: Etap2 - niech samemu router ustala czestotliwosc na podstawie EONowej tablicy
                P.changeFrequency(row.frequency);
                P.changeModulationPerformance(row.modulationPerformance);

                //Zmiana numeru portu na socketowy
                P.changePort(row.Port);

                return(P.toBytes());
            }
            catch (Exception E)
            {
                Console.WriteLine("RouterClientPortIn.GenerateUsableInfo: " + E.Message);
                return(packageBytes);
            }
        }