private static void startReadingCommands(NetworkNode node) { while (true) { Console.WriteLine("Oczekiwanie na polecenie"); Console.WriteLine("R - kanał rozmówny rsoh"); Console.WriteLine("M - kanał rozmówny msoh"); string command = Console.ReadLine(); if (command.Equals("R")) { string args = takeArgs(); node.AddRsohContent(args); } else if (command.Equals("M")) { string args = takeArgs(); node.AddMsohContent(args); } else { Console.WriteLine("Nie odnaleziono polecenia"); continue; } } }
private static void startReadingCommands(NetworkNode node) { while (true) { Console.WriteLine("Oczekiwanie na polecenie"); Console.WriteLine("R - kanał rozmówny rsoh"); Console.WriteLine("M - kanał rozmówny msoh"); string command = Console.ReadLine(); if (command.Equals("R")) { string args = takeArgs(); node.AddRsohContent(args); } else if (command.Equals("M")) { string args = takeArgs(); node.AddMsohContent(args); } else { Console.WriteLine("Nie odnaleziono polecenia"); continue; } } }
public NetworkNode configureNode() { List <NodeInput> ports = new List <NodeInput>(); string nodeName = null; string nodeType = null; ManagementPort managementPort = null; NetworkNodeSender sender = null; while (configReader.Read()) { if (configReader.IsStartElement()) { if (configReader.NodeType == XmlNodeType.Element) { if (configReader.Name == "port") { int portNumber = int.Parse(configReader.GetAttribute("local")); int tcp = int.Parse(configReader.GetAttribute("tcp")); string stm = configReader.GetAttribute("stm"); ports.Add(new NodeInput(tcp, portNumber, StmLevelExt.GetContainer(stm))); } else if (configReader.Name == "cloud-server") { int tcp = int.Parse(configReader.GetAttribute("tcp")); sender = new NetworkNodeSender(tcp); } else if (configReader.Name == "managment-port") { int portNumber = int.Parse(configReader.GetAttribute("number")); managementPort = new ManagementPort(portNumber); } else if (configReader.Name == "node" && configReader.IsStartElement()) { nodeName = configReader.GetAttribute("name"); nodeType = configReader.GetAttribute("type"); } } } } SynchronousPhysicalInterface spi = new SynchronousPhysicalInterface(ports, sender, nodeName); TransportTerminalFunction ttf = new TransportTerminalFunction(spi, getMode(nodeType)); HigherOrderPathConnection hpc = new HigherOrderPathConnection(ttf); NetworkNode node = new NetworkNode(hpc, ttf, nodeName); ManagementCenter managementCenter = new ManagementCenter(managementPort, node); managementPort.SetManagementCenter(managementCenter); managementPort.StartListening(); foreach (NodeInput input in ports) { input.SetUpServer(10000, 10); input.StartListening(); } return(node); }
public NetworkNode configureNode() { List<NodeInput> ports = new List<NodeInput>(); string nodeName = null; string nodeType = null; ManagementPort managementPort = null; NetworkNodeSender sender = null; while (configReader.Read()) { if (configReader.IsStartElement()) { if (configReader.NodeType == XmlNodeType.Element) { if (configReader.Name == "port") { int portNumber = int.Parse(configReader.GetAttribute("local")); int tcp = int.Parse(configReader.GetAttribute("tcp")); string stm = configReader.GetAttribute("stm"); ports.Add(new NodeInput(tcp, portNumber, StmLevelExt.GetContainer(stm))); } else if (configReader.Name == "cloud-server") { int tcp = int.Parse(configReader.GetAttribute("tcp")); sender = new NetworkNodeSender(tcp); } else if (configReader.Name == "managment-port") { int portNumber = int.Parse(configReader.GetAttribute("number")); managementPort = new ManagementPort(portNumber); } else if (configReader.Name == "node" && configReader.IsStartElement()) { nodeName = configReader.GetAttribute("name"); nodeType = configReader.GetAttribute("type"); } } } } SynchronousPhysicalInterface spi = new SynchronousPhysicalInterface(ports, sender, nodeName); TransportTerminalFunction ttf = new TransportTerminalFunction(spi, getMode(nodeType)); HigherOrderPathConnection hpc = new HigherOrderPathConnection(ttf); NetworkNode node = new NetworkNode(hpc, ttf, nodeName); ManagementCenter managementCenter = new ManagementCenter(managementPort,node); managementPort.SetManagementCenter(managementCenter); managementPort.StartListening(); foreach (NodeInput input in ports) { input.SetUpServer(10000, 10); input.StartListening(); } return node; }
static void Main(string[] args) { String id = args[0]; NetworkNodeSetupProcess setUpProcess = new NetworkNodeSetupProcess("..\\..\\..\\Configs\\NetworkNode\\nodeConfig" + id + ".xml"); NetworkNode node = setUpProcess.startNodeProcess(); Console.WriteLine("Start emulation"); startReadingCommands(node); }
public void StartConnections(NetworkNode networkNode) { commutation_field = new ComutationField(port_maps); management_agent = new ManagementAgent(networkNode); main_socket.Connect(new IPEndPoint(cloud_addr, cloud_port)); int[] arr = { 0 }; NetworkMessage init = new NetworkMessage(0, IPAddress.Loopback, 123, IPAddress.Loopback, 123, arr, 80, node_name); Send(main_socket, init.GetBytes()); ListenForMessages(); }
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); }
/// <summary> /// Start function creating new NetworkNode object and then return it to Main. /// </summary> /// <param name="FilePath"></param> /// <returns>NetworkNode</returns> public NetworkNode Start(string FilePath) { NetworkNode nn = new NetworkNode(); ViewOnScreen("Node is running!"); try { config = NetworkNodeConfiguration.ParseConfiguration(FilePath); Console.Title = config.NodeName; nn.node_name = config.NodeName; nn.management_port = config.ManagementPort; nn.management_addr = config.ManagementAddress; nn.cloud_addr = config.CloudAddress; nn.cloud_port = config.CloudPort; nn.port_maps = config.port_maps; } catch (FileNotFoundException e) { ViewOnScreen(e.Message); } return(nn); }
public async static Task Main(string[] args) { //Create networknode object and read its parameters. NetworkNode networkNode = new NetworkNode(); #region Start by .bat try { await Task.Run(() => networkNode = networkNode.Start(args[0])); //await Task.Run(() => networkNode = networkNode.Start($"..\\..\\..\\..\\Configs\\NetworkConfig1.txt")); } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } Task.Run(() => networkNode.ReconfigMpls()); await Task.Run(() => networkNode.StartConnections(networkNode)); Console.ReadLine(); #endregion }
public NetworkMessage HandleMessage(NetworkMessage message) { if (message.labels.Count == 0) { int temp_label = mpls.mplsBorderList.Find(x => x.dst.Equals(message.dst) & x.transport_layer_port == message.transport_layer_port).label; if (temp_label == 0) { NetworkNode.ViewOnScreen("There is no MPLS tunnel to IP: " + message.dst.ToString()); message.labels.Add(temp_label); return(message); } else { message.labels.Add(temp_label); NetworkNode.ViewOnScreen("GAVE MPLS LABEL: " + message.labels[0]); } } while (true) { //ViewOnScreen("Message: " + message.GetDiagnosticString()); MplsForwardEntry mpls_entry = mpls.mplsForwardList.Find(x => x.label == message.labels[message.labels.Count - 1] & x.inc_port == message.dst_port & x.last_idx == message.last_idx); switch (mpls_entry.op) { case operation.ADD: message.labels.Add(mpls_entry.out_label); message.src_port = mpls_entry.out_port; message.dst_port = port_maps.Find(x => x.src == message.src_port).dst; NetworkNode.ViewOnScreen("LABEL ADDED: " + mpls_entry.out_label); message.last_idx = mpls_entry.idx; //NetworkNode.ViewOnScreen("ACTUAL LABELS: " + string.Join(" ", message.labels)); return(message); case operation.SWAP: message.src_port = mpls_entry.out_port; NetworkNode.ViewOnScreen("LABEL SWAP: " + message.labels[message.labels.Count - 1] + " -> " + mpls_entry.out_label); //NetworkNode.ViewOnScreen("ACTUAL LABELS: " + string.Join(" ", message.labels)); message.labels[message.labels.Count - 1] = mpls_entry.out_label; message.last_idx = mpls_entry.idx; if (message.src_port != 0) { message.dst_port = port_maps.Find(x => x.src == message.src_port).dst; return(message); } else { break; } case operation.POP: NetworkNode.ViewOnScreen("LABBEL POPPED: " + message.labels[message.labels.Count - 1]); //NetworkNode.ViewOnScreen("ACTUAL LABELS: " + string.Join(" ", message.labels)); message.labels.RemoveAt(message.labels.Count - 1); message.src_port = mpls_entry.out_port; message.last_idx = mpls_entry.idx; if (message.labels.Count == 0) { MplsBorderEntry mpls_border_entry = mpls.mplsBorderList.Find(x => x.dst.Equals(message.dst)); message.src_port = mpls_border_entry.out_port; message.dst_port = port_maps.Find(x => x.src == message.src_port).dst; return(message); } break; } } }
public void CreateConnect(string addressConnectIP, string key, CancellationToken cancellationToken = default(CancellationToken)) { Socket socket = null; Socket listenerAgent = null; Socket agentSending = null; try { byte[] bytes = new Byte[128]; string numberOfRouter = key.Substring(0, 1); //Sklejenie czesci wspolnej klucza dla socketu OUT oraz indeksu string settingsString = numberOfRouter + "Agent"; IPAddress ipAddress = ipAddress = IPAddress.Parse(OperationConfiguration.getSetting(settingsString, mySettings)); IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000); // Create a TCP/IP socket. listenerAgent = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (!listenerAgent.IsBound) { //zabindowanie na sokecie punktu koncowego listenerAgent.Bind(localEndPoint); listenerAgent.Listen(100); } int milliseconds = 100; //Nasluchujemy bez przerwy while (Last) { if (Listening) { //Dodanie socketu do listy socketow OUT agentSending = sS.ConnectToEndPoint(addressConnectIP); Thread.Sleep(milliseconds); SendingNodeIsUpMessage(agentSending, OperationConfiguration.getSetting(settingsString, mySettings), Int16.Parse(numberOfRouter)); //oczekiwanie na polaczenie socket = listenerAgent.Accept(); SendingKeepAliveMessage(OperationConfiguration.getSetting(settingsString, mySettings), agentSending); Listening = false; /* LingerOption myOpts = new LingerOption(true, 1); * socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, myOpts); * socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, false); * socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);*/ Console.WriteLine("Connect on port " + NetworkNode.takingAddresListenerSocket(socket)); byte[] msg; if (socket.Connected) { //Oczekiwanie w petli na przyjscie danych while (true) { string from = string.Empty; //Odebranie tablicy bajtow na obslugiwanym w watku sluchaczu msg = sl.ProcessRecivedBytes3(socket); NMSPackage package = new NMSPackage(); string usableMessage = NMSPackage.extractUsableMessage(msg, NMSPackage.extractUsableInfoLength(msg)); Console.WriteLine(usableMessage); fillingTable(usableMessage, agentSending, settingsString); // Package.extractHowManyPackages(msg); // listByte.Add(msg); //Wykonuje jezeli nadal zestawione jest polaczenie if (msg == null) { //Rozpoczynamy proces nowego polaczenia break; } } } } ConsoleKeyInfo cki; while (true) { cki = Console.ReadKey(); if (cki.Key == ConsoleKey.Escape) { break; } } } } catch (SocketException se) { Console.WriteLine($"Socket Exception: {se}"); } finally { // StopListening(); } if (socket == null) { } }
public ManagementAgent(NetworkNode _networkNode) { network_node = _networkNode; ConnectManagementSystem(); }
public static void Main(string[] args) { NetworkNode nd = new NetworkNode(); nd.Run(); }
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")); }