示例#1
0
        /// <summary>
        /// Funkcja odpowiedzialna za znalezienie wiersza w tablicy komutacji
        /// </summary>
        /// <param name="frequency_in">Częstotliwość wejściowa</param>
        /// <param name="port_in">Port wejsciowy</param>
        /// <returns>Wiersz tablicy komutacji</returns>
        public CommutationTableRow FindRow(short frequency_in, short port_in)
        {
            //Jeden rzad tablicy komutacji
            CommutationTableRow commutationRow = null;

            try
            {
                //Wyszukiwanie takiego rzedu, ktory ma podane IP_IN i port_in
                commutationRow = this.Table.Find(row => (row.frequency_in == frequency_in) && (row.port_in == port_in));

                return(commutationRow);
            }
            catch (Exception E)
            {
                return(commutationRow);
            }
        }
示例#2
0
        public void testFindCloudSocketAndPort1()
        {
            //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;

            //adres socketa z chmury
            short     cloudSocketPort      = 1;
            IPAddress cloudSocketIPAddress = IPAddress.Parse("127.0.10.12");

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

            //Nowy wpis do tablicy komutacji pakietow, zawierajacy czestotliwosc z powyzszego pakietu
            CommutationTableRow row = new CommutationTableRow(frequency, cloudSocketPort, frequency, portNumber);

            Assert.IsNotNull(row);

            NetworkNode node = new NetworkNode();

            Assert.IsNotNull(node.borderNodeCommutationTable);
            Assert.IsNotNull(node.commutationTable);
            Assert.IsNotNull(node.eonTable);

            //dodanie do tablicy komutacji pakietow wezla sieciowego nowego rzedu
            node.commutationTable.Table.Add(row);

            //wyodrebnienie adresu IP socketa chmury i portu tego socketa
            var tuple = node.determineFrequencyAndPort(P.toBytes());

            //sprawdzenie, czy sie zgadzaja
            Assert.AreEqual(tuple.Item1, frequency);
            Assert.AreEqual(tuple.Item2, portNumber);
        }
示例#3
0
        public void testAddCommutationTableRow()
        {
            short frequency_in  = 2;
            short port_in       = 3;
            short frequency_out = 4;
            short port_out      = 5;

            //stworzenie nowego rzedu
            CommutationTableRow row = new CommutationTableRow(frequency_in, port_in, frequency_out, port_out);

            //stworzenie nowej tablicy komutacji
            CommutationTable table = new CommutationTable();

            //dodanie nowegor rzedu do tablicy komutacji
            table.Table.Add(row);

            //Powinny byc takie same
            Assert.AreEqual(table.Table[0].frequency_out, frequency_out);
            Assert.AreEqual(table.Table[0].port_out, port_out);
            Assert.AreEqual(table.Table[0].frequency_in, frequency_in);
            Assert.AreEqual(table.Table[0].port_in, port_in);
        }
示例#4
0
        /// <summary>
        /// Funkcja służąca do zamiany nagłówka
        /// </summary>
        /// <param name="message">Wiadomość odebrana w postaci tablicy bajtów</param>
        /// <returns></returns>
        public byte[] changePackageHeader(byte[] message)
        {
            byte[] msg = new byte[64];
            msg = message;
            Package p = new Package(msg);

            CommutationTableRow row = new CommutationTableRow();

            row = this.FindRow(p.frequency, p.portNumber);

            p.changePort(row.port_out);
            if (row.frequency_out == -1)
            {
                p.changeFrequency(row.frequency_out);
                p.changeBand(-1);
                p.changeModulationPerformance(-1);
                p.changeBitRate(-1);
            }

            msg = p.toBytes();

            return(msg);
        }
        private void setRouting(string [] message)
        {
            string address = message[0];

            if (message[1] == MessageNames.CONNECTION_TEARDOWN)
            {
                if (message[3] == "CC")
                {
                    short frequency = Int16.Parse(message[10]);
                    short port_In   = Int16.Parse(message[5]);
                    short port_Out  = Int16.Parse(message[7]);



                    CommutationTableRow rowToDelete = new CommutationTableRow();
                    rowToDelete = commutationTable.FindRow(Convert.ToInt16(message[10]), Convert.ToInt16(message[5]));
                    commutationTable.Table.Remove(rowToDelete);

                    string responseMessage = System.Configuration.ConfigurationManager.AppSettings["UDP" + numberOfRouter] + "#" + MessageNames.CONNECTION_TEARDOWN + "#OK" + "#" + "CC#";
                    SendingMessageCC(address, responseMessage);
                    Console.WriteLine("[" + Timestamp.generateTimestampRCC() + "] Message  delete from table  {0} frequency {1} port_in {2} port_out {3}", "COMUTATION", frequency, port_In, port_Out);
                }
                else if (message[3] == "BORDERTABLE")
                {
                    string responseMessage = System.Configuration.ConfigurationManager.AppSettings["UDP" + numberOfRouter] + "#" + MessageNames.CONNECTION_TEARDOWN + "#OK" + "#" + "CC#";


                    BorderNodeCommutationTableRow newRow = new BorderNodeCommutationTableRow();
                    //IP source--IP destination--czestotliwosc
                    newRow = borderNodeCommutationTable.FindRow(message[4], message[6], Int16.Parse(message[7]));
                    borderNodeCommutationTable.Table.Remove(newRow);
                    // SendingMessageCC(address, responseMessage);

                    Console.WriteLine("[" + Timestamp.generateTimestampRCC() + "] Message  delete from table  {0} frequency {1} address source: {2} address destination {3}", "BORDER_NODE_COMUTATION", message[7], message[4], message[6]);
                }
            }
            else if (message[1] == MessageNames.CONNECTION_REQUEST)
            {
                if (message[3] == "CC")
                {
                    Console.WriteLine("[" + Timestamp.generateTimestampRCC() + "] Received message filling Commutation Table  from CC " + message[0]);

                    short frequency = Int16.Parse(message[10]);
                    short port_In   = Int16.Parse(message[5]);
                    short port_Out  = Int16.Parse(message[7]);



                    CommutationTableRow commuteRow = new CommutationTableRow(frequency, port_In, frequency, port_Out);
                    commutationTable.Table.Add(commuteRow);

                    string responseMessage = System.Configuration.ConfigurationManager.AppSettings["UDP" + numberOfRouter] + "#" + MessageNames.CONNECTION_REQUEST + "#OK" + "#" + "CC#";
                    SendingMessageCC(address, responseMessage);
                    Console.WriteLine("[" + Timestamp.generateTimestampRCC() + "] Message  new registry to table  {0} ", "COMUTATION_TABLE" +
                                      " Frequency: " + message[10] + " port_in: " + message[5] + " port_out: " + message[7]);
                }
                else if (message[3] == "BORDERTABLE")
                {
                    Console.WriteLine("[" + Timestamp.generateTimestampRCC() + "] Received message filling BorderNodeCommutationTable  from CC " + message[0]);
                    string responseMessage = System.Configuration.ConfigurationManager.AppSettings["UDP" + numberOfRouter] + "#" + MessageNames.CONNECTION_REQUEST + "#OK" + "#" + "CC#";


                    BorderNodeCommutationTableRow newRow = new BorderNodeCommutationTableRow(
                        message[4], Convert.ToInt16(message[5]), Convert.ToInt16(1), Convert.ToInt16(message[7]), Convert.ToInt16(7),
                        Convert.ToInt16(1), message[6], Convert.ToInt16(2), Convert.ToInt16(1));
                    borderNodeCommutationTable.Table.Add(newRow);
                    // SendingMessageCC(address, responseMessage);
                    Console.WriteLine("[" + Timestamp.generateTimestampRCC() + "] Message  new registry to table  {0} ", "BORDER_NODE_COMUTATION " +
                                      "Frequency: " + message[7] + " port_in " + message[5]);
                }
            }
        }
示例#6
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();
        }
示例#7
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();
        }