Beispiel #1
0
        /// <summary>
        /// Dodanie rzędu do tablicy EON, wraz z aktualizacją tablic zajętości z częstotliwościami OUT.
        /// </summary>
        /// <param name="row"></param>
        public bool addRow(EONTableRowOut row)
        {
            try
            {
                //sprawdzenie, czy wpis nie bedzie kolidowal
                if (CheckAvailability(row.busyFrequency, row.busyBandOUT, "out") && row.busyFrequency >= 0 &&
                    row.busyFrequency <= EONTable.capacity && row.busyBandOUT > 0)
                {
                    //dodanie do tabeli
                    this.TableOut.Add(row);

                    //Ustawienie wartosci zajetych pol w tabeli
                    for (int i = row.busyFrequency; i < row.busyFrequency + row.busyBandOUT; i++)
                    {
                        this.OutFrequencies[i] = row.busyFrequency;
                    }

                    return(true);
                }
                else
                {
                    throw new Exception("EONTable.addRow(out): failed to add a row! bandOut=" + row.busyBandOUT + " frequency=" + row.busyFrequency);
                }
            }
            catch (Exception E)
            {
                if (row.busyBandOUT != 0)
                {
                    Console.WriteLine(E.Message);
                }
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Funkcja, ktora usuwa wpis z wyjsciowej tablicy EONowej i zwalnia zajete pasma
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool deleteRow(EONTableRowOut row)
        {
            int indexToRemove =
                TableOut.FindIndex(x => x.busyBandOUT == row.busyBandOUT && x.busyFrequency == row.busyFrequency);

            //Czy taki wpis jest w tabeli?
            if (indexToRemove != -1)
            {
                //zwolnienie wszystkich szczelin zwiazanych z danym wierszem
                for (int i = row.busyFrequency; i < row.busyBandOUT + row.busyFrequency; i++)
                {
                    OutFrequencies[i] = -1;
                }

                //wyrzucenie z tabeli wiersza
                TableOut.RemoveAt(indexToRemove);

                return(true);
            }
            else
            {
                //Nie ma takiego wpisu w tabeli, wiec sie go nie da usunac
                return(false);
            }
        }
        public void testDeleteEONRow()
        {
            short frequency = 2;
            short band      = 3;

            //stworzenie nowej tabeli
            EONTable table = new EONTable();

            //stworzenie nowych rzedow
            EONTableRowIN  rowIn  = new EONTableRowIN(frequency, band);
            EONTableRowOut rowOut = new EONTableRowOut(frequency, band);

            //Dodanie rzedow
            table.addRow(rowIn);
            table.addRow(rowOut);

            //usuniecie rzedow
            table.deleteRow(rowIn);
            table.deleteRow(rowOut);

            Assert.IsTrue(table.CheckAvailability(rowIn));
            Assert.IsTrue(table.CheckAvailability(rowOut));

            //Kazdy wpis w tabeli po wyczyszczeniu powinien byc rowny -1
            foreach (short f in table.InFrequencies)
            {
                Assert.AreEqual(-1, f);
            }

            //Nie powinno byc rzedu w tablicy
            Assert.IsFalse(table.TableIN.Contains(rowIn));

            //Kazdy wpis w tabeli po wyczyszczeniu powinien byc rowny -1
            foreach (short f in table.OutFrequencies)
            {
                Assert.AreEqual(-1, f);
            }

            //Nie powinno byc rzedu w tablicy
            Assert.IsFalse(table.TableOut.Contains(rowOut));
        }
Beispiel #4
0
        /// <summary>
        /// Funkcja, ktora usuwa wpis z wyjsciowej tablicy EONowej i zwalnia zajete pasma
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool deleteRow(EONTableRowOut row)
        {
            //Czy taki wpis jest w tabeli?
            if (TableOut.Contains(row))
            {
                //zwolnienie wszystkich szczelin zwiazanych z danym wierszem
                for (int i = row.busyFrequency; i < row.busyBandOUT + row.busyFrequency; i++)
                {
                    OutFrequencies[i] = -1;
                }

                //wyrzucenie z tabeli wiersza
                TableOut.Remove(row);

                return(true);
            }
            else
            {
                //Nie ma takiego wpisu w tabeli, wiec sie go nie da usunac
                return(false);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Dodanie rzędu do tablicy EON, wraz z aktualizacją tablic zajętości z częstotliwościami OUT.
        /// </summary>
        /// <param name="row"></param>
        public bool addRow(EONTableRowOut row)
        {
            //sprawdzenie, czy wpis nie bedzie kolidowal
            if (CheckAvailability(row.busyFrequency, row.busyBandOUT, "out"))
            {
                //dodanie do tabeli
                this.TableOut.Add(row);

                //Ustawienie wartosci zajetych pol w tabeli
                for (int i = row.busyFrequency; i < row.busyFrequency + row.busyBandOUT; i++)
                {
                    this.OutFrequencies[i] = row.busyFrequency;
                }

                return(true);
            }
            else
            {
                throw new Exception("EONTable.addRow(in): failed to add a row!");
            }

            return(false);
        }
        public void testAddEONRow()
        {
            short frequency = 2;
            short band      = 3;

            //stworzenie nowej tabeli
            EONTable table = new EONTable();

            //stworzenie nowych rzedow
            EONTableRowIN  rowIn  = new EONTableRowIN(frequency, band);
            EONTableRowOut rowOut = new EONTableRowOut(frequency, band);

            //Dodanie rzedow
            table.addRow(rowIn);
            table.addRow(rowOut);

            //Sprawdzenie, czy wybrane czestotliwosci sa zajete
            for (int i = frequency; i < frequency + band; i++)
            {
                Assert.IsTrue(table.InFrequencies[i] == frequency);
                Assert.IsTrue(table.OutFrequencies[i] == frequency);
            }

            //Sprawdzenie wolnych czestotliwosci
            for (int i = 0; i < frequency; i++)
            {
                Assert.IsTrue(table.InFrequencies[i] == -1);
                Assert.IsTrue(table.OutFrequencies[i] == -1);
            }

            for (int i = frequency + band; i < EONTable.capacity; i++)
            {
                Assert.IsTrue(table.InFrequencies[i] == -1);
                Assert.IsTrue(table.OutFrequencies[i] == -1);
            }
        }
Beispiel #7
0
        public void fillingTable(string line, Socket socketsending, string key)
        {
            //Znaki oddzielające poszczególne części żądania klienta.
            char[] delimiterChars = { '#' };
            //Podzielenie żądania na tablicę stringów.
            string[] words;


            words = line.Split(delimiterChars);
            switch (words[0])
            {
            case "ADD":
                switch (Int32.Parse(words[1]))
                {
                //Dodawanie wpisu do BorderComutationTable
                case 1:
                    BorderNodeCommutationTableRow newRow = new BorderNodeCommutationTableRow(
                        words[2], Convert.ToInt16(words[3]), Convert.ToInt16(words[4]), Convert.ToInt16(words[5]), Convert.ToInt16(words[6]),
                        Convert.ToInt16(words[7]), words[8], Convert.ToInt16(words[9]), Convert.ToInt16(words[10]));
                    borderNodeCommutationTable.Table.Add(newRow);
                    stateReceivedMessageFromNMS("BorderNodeCommutationTable", "ADD");
                    break;

                //Dodanie wpisu do EONTable
                case 2:
                    EONTableRowIN  eonIN      = new EONTableRowIN(Convert.ToInt16(words[2]), Convert.ToInt16(words[3]));
                    EONTableRowOut eonOut     = new EONTableRowOut(Convert.ToInt16(words[4]), Convert.ToInt16(words[5]));
                    bool           eoninbool  = eonTable.addRow(eonIN);
                    bool           eonoutbool = eonTable.addRow(eonOut);
                    if (eoninbool == false || eonoutbool == false)
                    {
                        sendingMessageCommunication(OperationConfiguration.getSetting(key, mySettings), "ERROR", socketsending);
                    }
                    else
                    {
                        stateReceivedMessageFromNMS("EONTable", "ADD");
                    }

                    break;

                //Dodanie wpisu do CommutationTable
                case 3:
                    CommutationTableRow commuteRow = new CommutationTableRow(Convert.ToInt16(words[2]),
                                                                             Convert.ToInt16(words[3]), Convert.ToInt16(words[4]), Convert.ToInt16(words[5]));
                    commutationTable.Table.Add(commuteRow);

                    stateReceivedMessageFromNMS("CommutationTable", "ADD");
                    break;

                default:
                    break;
                }
                break;

            case "DELETE":
                switch (Int32.Parse(words[1]))
                {
                //Dodawanie wpisu do BorderComutationTable
                case 1:
                    BorderNodeCommutationTableRow newRow = new BorderNodeCommutationTableRow();
                    newRow = borderNodeCommutationTable.FindRow(words[2], Convert.ToInt16(words[3]), words[4]);
                    borderNodeCommutationTable.Table.Remove(newRow);
                    stateReceivedMessageFromNMS("BorderNodeCommutationTable", "DELETE");
                    break;

                //Dodanie wpisu do EONTable
                case 2:
                    EONTableRowIN  eonIN      = new EONTableRowIN(Convert.ToInt16(words[2]), Convert.ToInt16(words[3]));
                    EONTableRowOut eonOut     = new EONTableRowOut(Convert.ToInt16(words[4]), Convert.ToInt16(words[5]));
                    bool           eoninbool  = eonTable.deleteRow(eonIN);
                    bool           eonoutbool = eonTable.deleteRow(eonOut);

                    if (eoninbool == false || eonoutbool == false)
                    {
                        sendingMessageCommunication(OperationConfiguration.getSetting(key, mySettings), "ERROR", socketsending);
                    }
                    else
                    {
                        stateReceivedMessageFromNMS("EONTable", "DELETE");
                    }

                    break;

                //Dodanie wpisu do CommutationTable
                case 3:
                    CommutationTableRow rowToDelete = new CommutationTableRow();
                    rowToDelete = commutationTable.FindRow(Convert.ToInt16(words[2]), Convert.ToInt16(words[3]));
                    commutationTable.Table.Remove(rowToDelete);
                    stateReceivedMessageFromNMS("CommutationTable", "DELETE");
                    break;

                default:
                    break;
                }
                break;

            case "TOPOLOGY":
                switch (Int32.Parse(words[1]))
                {
                case 1:
                    //Dodawanie wpisu do BorderComutationTable
                    for (int i = 0; i < borderNodeCommutationTable.Table.Count; i++)
                    {
                        byte[] table_in_bytes = null;
                        string builder        = string.Empty;
                        string port_in        = string.Empty;
                        string port_out       = string.Empty;
                        string Hops           = string.Empty;
                        string command        = string.Empty;
                        string band_out       = string.Empty;
                        string destination_IP = string.Empty;
                        string Modulation     = string.Empty;
                        string BitRate        = string.Empty;
                        string IP_IN          = string.Empty;
                        string Frequency_out  = string.Empty;
                        command        = "TOPOLOGY";
                        IP_IN          = borderNodeCommutationTable.Table[i].IP_IN.ToString();
                        port_in        = borderNodeCommutationTable.Table[i].port_in.ToString();
                        band_out       = borderNodeCommutationTable.Table[i].band.ToString();
                        Frequency_out  = borderNodeCommutationTable.Table[i].frequency.ToString();
                        Modulation     = borderNodeCommutationTable.Table[i].modulationPerformance.ToString();
                        BitRate        = borderNodeCommutationTable.Table[i].bitRate.ToString();
                        destination_IP = borderNodeCommutationTable.Table[i].IP_Destination.ToString();
                        port_out       = borderNodeCommutationTable.Table[i].Port.ToString();
                        Hops           = borderNodeCommutationTable.Table[i].hopsNumber.ToString();

                        builder = command + "#" + "1" + "#" + IP_IN + "#" + port_in + "#" + band_out + "#" + Frequency_out + "#" +
                                  Modulation + "#" + BitRate + "#" + destination_IP + "#" + port_out + "#" + Hops;

                        sendingMessageCommunication(OperationConfiguration.getSetting(key, mySettings), builder, socketsending);
                    }
                    break;

                //Dodanie wpisu do EONTable
                case 2:
                    for (int i = 0; i < eonTable.TableIN.Count; i++)
                    {
                        byte[] table_in_bytes = null;
                        string builder        = string.Empty;
                        ;
                        string command       = string.Empty;
                        string band_in       = string.Empty;
                        string frequency_out = string.Empty;
                        string band_out      = string.Empty;
                        string frequency_in  = string.Empty;
                        command = "TOPOLOGY";

                        frequency_in  = eonTable.TableIN[i].busyFrequency.ToString();
                        band_in       = eonTable.TableIN[i].busyBandIN.ToString();
                        frequency_out = eonTable.TableOut[i].busyFrequency.ToString();
                        band_out      = eonTable.TableOut[i].busyBandOUT.ToString();


                        builder = command + "#" + "2" + "#" + frequency_in + "#" + band_in + "#" + frequency_out + "#" + band_out;
                        sendingMessageCommunication(OperationConfiguration.getSetting(key, mySettings), builder, socketsending);
                    }

                    break;

                //Dodanie wpisu do CommutationTable
                case 3:
                    for (int i = 0; i < commutationTable.Table.Count; i++)
                    {
                        byte[] table_in_bytes = null;
                        string command        = string.Empty;
                        string builder        = string.Empty;
                        string port_in        = string.Empty;
                        string port_out       = string.Empty;
                        string Frequency_in   = string.Empty;
                        string frequency_out  = string.Empty;
                        command = "TOPOLOGY";
                        port_in = commutationTable.Table[i].port_in.ToString();

                        frequency_out = commutationTable.Table[i].frequency_out.ToString();
                        Frequency_in  = commutationTable.Table[i].frequency_in.ToString();
                        port_out      = commutationTable.Table[i].port_out.ToString();


                        builder = command + "#" + "3" + "#" + Frequency_in + "#" + port_in + "#" + frequency_out + "#" + port_out;

                        sendingMessageCommunication(OperationConfiguration.getSetting(key, mySettings), builder, socketsending);
                    }



                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }



            // Console.ReadKey();
        }
Beispiel #8
0
 /// <summary>
 /// prawdza, czy pasmo na zadanej częstotliwości jest wolne w tym routerze.
 /// </summary>
 /// <param name="row"></param>
 /// <returns></returns>
 public bool CheckAvailability(EONTableRowOut row)
 {
     return(CheckAvailability(row.busyFrequency, row.busyBandOUT, "in"));
 }
Beispiel #9
0
        public void fillingTable(string line)
        {
            //Znaki oddzielające poszczególne części żądania klienta.
            char[] delimiterChars = { '#' };
            //Podzielenie żądania na tablicę stringów.
            string[] words;


            words = line.Split(delimiterChars);
            switch (words[0])
            {
            case "ADD":
                switch (Int32.Parse(words[1]))
                {
                //Dodawanie wpisu do BorderComutationTable
                case 1:
                    BorderNodeCommutationTableRow newRow = new BorderNodeCommutationTableRow(
                        words[2], Convert.ToInt16(words[3]), Convert.ToInt16(words[4]), Convert.ToInt16(words[5]), Convert.ToInt16(words[6]),
                        Convert.ToInt16(words[7]), words[8], Convert.ToInt16(words[9]), Convert.ToInt16(words[10]));
                    borderNodeCommutationTable.Table.Add(newRow);
                    stateReceivedMessageFromNMS("BorderNodeCommutationTable", "ADD");
                    break;

                //Dodanie wpisu do EONTable
                case 2:
                    EONTableRowIN  eonIN  = new EONTableRowIN(Convert.ToInt16(words[2]), Convert.ToInt16(words[3]));
                    EONTableRowOut eonOut = new EONTableRowOut(Convert.ToInt16(words[4]), Convert.ToInt16(words[5]));
                    eonTable.addRow(eonIN);
                    eonTable.addRow(eonOut);
                    stateReceivedMessageFromNMS("EONTable", "ADD");
                    break;

                //Dodanie wpisu do CommutationTable
                case 3:
                    CommutationTableRow commuteRow = new CommutationTableRow(Convert.ToInt16(words[2]),
                                                                             Convert.ToInt16(words[3]), Convert.ToInt16(words[4]), Convert.ToInt16(words[5]));
                    commutationTable.Table.Add(commuteRow);
                    stateReceivedMessageFromNMS("CommutationTable", "ADD");
                    break;

                default:
                    break;
                }
                break;

            case "DELETE":
                switch (Int32.Parse(words[1]))
                {
                //Dodawanie wpisu do BorderComutationTable
                case 1:
                    BorderNodeCommutationTableRow newRow = new BorderNodeCommutationTableRow();
                    newRow = borderNodeCommutationTable.FindRow(words[2], Convert.ToInt16(words[3]), words[4]);
                    borderNodeCommutationTable.Table.Remove(newRow);
                    stateReceivedMessageFromNMS("BorderNodeCommutationTable", "DELETE");
                    break;

                //Dodanie wpisu do EONTable
                case 2:
                    EONTableRowIN  eonIN  = new EONTableRowIN(Convert.ToInt16(words[2]), Convert.ToInt16(words[3]));
                    EONTableRowOut eonOut = new EONTableRowOut(Convert.ToInt16(words[4]), Convert.ToInt16(words[5]));
                    eonTable.deleteRow(eonIN);
                    eonTable.deleteRow(eonOut);
                    stateReceivedMessageFromNMS("EONTable", "DELETE");
                    break;

                //Dodanie wpisu do CommutationTable
                case 3:
                    CommutationTableRow rowToDelete = new CommutationTableRow();
                    rowToDelete = commutationTable.FindRow(Convert.ToInt16(words[2]), Convert.ToInt16(words[3]));
                    commutationTable.Table.Remove(rowToDelete);
                    stateReceivedMessageFromNMS("CommutationTable", "DELETE");
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }



            // Console.ReadKey();
        }
        public void testCheckAvailability()
        {
            //Jakies dane do pakietu
            string    inscription      = "Mam malo wody";
            short     portNumber       = 2;
            IPAddress IP_Source        = IPAddress.Parse("192.168.0.1");
            IPAddress IP_Destination   = IPAddress.Parse("192.168.0.10");
            short     packageNumber    = 5;
            short     frequency        = 2;
            short     band             = 4;
            short     usableInfoLength = (short)inscription.Length;

            //stworzenie nowego pakietu
            Package P = new Package(inscription, portNumber, IP_Destination.ToString(), IP_Source.ToString(),
                                    usableInfoLength, packageNumber, frequency, band);

            //nowy rzad wejsciowy tablicy
            EONTableRowIN rowIn = new EONTableRowIN(frequency, band);

            NetworkNode node = new NetworkNode();

            //Wpisanie w tablice EONową węzła
            node.eonTable.addRow(rowIn);

            //Wartosci powinny byc te same
            Assert.AreEqual(node.eonTable.TableIN[0].busyFrequency, frequency);
            Assert.AreEqual(node.eonTable.TableIN[0].busyBandIN, band);

            //Powinno byc zajete
            Assert.IsFalse(node.eonTable.CheckAvailability(frequency, band, "in"));

            //Powinno byc zajete
            Assert.IsFalse(node.eonTable.CheckAvailability(rowIn));

            //Powinno byc wolne
            Assert.IsTrue(node.eonTable.CheckAvailability(frequency, band, "out"));

            //Powinno sie zazebic troche i zgrzytnac
            Assert.IsFalse(node.eonTable.CheckAvailability(1, 3, "in"));

            //Nie powinny sie pokrywac
            Assert.IsTrue(node.eonTable.CheckAvailability(0, 2, "in"));

            //====================================================================================
            //nowy rzad wyjsciowy tablicy
            EONTableRowOut rowOut = new EONTableRowOut(frequency, band);

            //dodanie rzedu do tablicy
            node.eonTable.addRow(rowOut);

            //Wartosci powinny byc te same
            Assert.AreEqual(node.eonTable.TableOut[0].busyFrequency, rowOut.busyFrequency);
            Assert.AreEqual(node.eonTable.TableOut[0].busyBandOUT, rowOut.busyBandOUT);

            //powinno byc zajete
            Assert.IsFalse(node.eonTable.CheckAvailability(rowOut));

            //Powinno byc zajete
            Assert.IsFalse(node.eonTable.CheckAvailability(frequency, band, "out"));

            //Powinno sie zazebic troche i zgrzytnac
            Assert.IsFalse(node.eonTable.CheckAvailability(1, 3, "out"));

            //Nie powinny sie pokrywac
            Assert.IsTrue(node.eonTable.CheckAvailability(0, 2, "out"));
        }