private void ConsoleInterface() { log("NetNode " + this.virtualIp + " " + this.managementAgent.port + " " + this.controlAgent.port + " " + this.physicalPort, ConsoleColor.Yellow); Boolean quit = false; while (!quit) { Console.WriteLine("\n MENU: "); Console.WriteLine("\n 1) Manually insert entry in connection table"); Console.WriteLine("\n 2) Show connection table"); Console.WriteLine("\n 3) Clear connection table"); Console.WriteLine("\n 4) Show node connections"); Console.WriteLine("\n 5) Show node resource status"); Console.WriteLine("\n"); int choice; bool res = int.TryParse(Console.ReadLine(), out choice); if (res) { switch (choice) { case 1: insertFib(); break; case 2: SwitchingField.printFibTable(); break; case 3: SwitchingField.clearFibTable(); break; case 4: LRM.printConn(); break; case 5: LRM.printResources(); break; default: log("\n Wrong option", ConsoleColor.Red); break; } } else { log("Wrong format", ConsoleColor.Red); ConsoleInterface(); } } }
private void insertFib() { FIB fib = new FIB(0, 0, 0, 0); Console.WriteLine("Insert input port:"); Int32.TryParse(Console.ReadLine(), out fib.iport); Console.WriteLine("Insert input container position:"); Int32.TryParse(Console.ReadLine(), out fib.in_cont); Console.WriteLine("Insert output port:"); Int32.TryParse(Console.ReadLine(), out fib.oport); Console.WriteLine("Insert output container position:"); Int32.TryParse(Console.ReadLine(), out fib.out_cont); SwitchingField.addToSwitch(fib); //adding fib for two-way communication SwitchingField.addToSwitch(new FIB(fib.oport, fib.out_cont, fib.iport, fib.in_cont)); }
private void Listen() { TcpClient clienttmp = new TcpClient("127.0.0.1", this.port); BinaryReader reader = new BinaryReader(clienttmp.GetStream()); BinaryWriter writer = new BinaryWriter(clienttmp.GetStream()); try { while (true) { string received_data = reader.ReadString(); JSON received_object = JSON.Deserialize(received_data); ManagmentProtocol received_Protocol = received_object.Value.ToObject <ManagmentProtocol>(); if (received_Protocol.State == ManagmentProtocol.WHOIS) { NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: receivedWhoIs", ConsoleColor.Blue); //send name to management ManagmentProtocol protocol = new ManagmentProtocol(); protocol.Name = this.virtualIp; String send_object = JMessage.Serialize(JMessage.FromValue(protocol)); writer.Write(send_object); NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " sending: " + protocol.Name, ConsoleColor.Blue); } else if (received_Protocol.State == ManagmentProtocol.ROUTINGTABLES) { NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: receivedroutingtable", ConsoleColor.Blue); //receiving fibs if (received_Protocol.RoutingTable != null) { foreach (var fib in received_Protocol.RoutingTable) { SwitchingField.addToSwitch(fib); //adding fib for two-way communication SwitchingField.addToSwitch(new FIB(fib.oport, fib.out_cont, fib.iport, fib.in_cont)); } } } else if (received_Protocol.State == ManagmentProtocol.ROUTINGENTRY) { NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: receivedroutingentry", ConsoleColor.Blue); //receiving fibs if (received_Protocol.RoutingEntry != null) { SwitchingField.addToSwitch(received_Protocol.RoutingEntry); //adding fib for two-way communication SwitchingField.addToSwitch(new FIB(received_Protocol.RoutingEntry.oport, received_Protocol.RoutingEntry.out_cont, received_Protocol.RoutingEntry.iport, received_Protocol.RoutingEntry.in_cont)); } } else if (received_Protocol.State == ManagmentProtocol.INTERFACEINFORMATION) { NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: iterfaceinformation", ConsoleColor.Blue); //send dictionary from LRM to management ManagmentProtocol protocol = new ManagmentProtocol(); protocol.State = ManagmentProtocol.INTERFACEINFORMATION; protocol.Interfaces = LRM.getConn(); String send_object = JMessage.Serialize(JMessage.FromValue(protocol)); writer.Write(send_object); } else if (received_Protocol.State == ManagmentProtocol.GETTABLE) { NetNode.log(DateTime.Now.ToLongTimeString() + " [Management]" + " receiving: getTable", ConsoleColor.Blue); //send dictionary from LRM to management ManagmentProtocol protocol = new ManagmentProtocol(); protocol.State = ManagmentProtocol.GETTABLE; protocol.RoutingTable = SwitchingField.fib; String send_object = JMessage.Serialize(JMessage.FromValue(protocol)); writer.Write(send_object); } else { NetNode.log("[Management] undefined protocol", ConsoleColor.Red); } } } catch (Exception e) { NetNode.log("\nError sending signal: " + e.Message, ConsoleColor.Red); Thread.Sleep(2000); Environment.Exit(1); } }
private void Listen() { TcpClient clienttmp = new TcpClient("127.0.0.1", this.port); reader = new BinaryReader(clienttmp.GetStream()); writer = new BinaryWriter(clienttmp.GetStream()); try { while (true) { string received_data = reader.ReadString(); JSON received_object = JSON.Deserialize(received_data); CCtoCCSignallingMessage received_Protocol = received_object.Value.ToObject <CCtoCCSignallingMessage>(); if (received_Protocol.State == CCtoCCSignallingMessage.CC_UP_FIB_CHANGE) { //insert FIB NetNode.log(DateTime.Now.ToLongTimeString() + " [CC -> node] insertFib", ConsoleColor.Yellow); List <FIB> rec = received_Protocol.Fib_table; //TODO allocate resources foreach (var row in rec) { if (LRM.allocateResource(row.iport, row.in_cont)) { NetNode.log(DateTime.Now.ToLongTimeString() + " [CC -> node] allocate: " + row.iport + " " + row.in_cont, ConsoleColor.Yellow); if (LRM.allocateResource(row.oport, row.out_cont)) { NetNode.log(DateTime.Now.ToLongTimeString() + " [CC -> node] allocate: " + row.oport + " " + row.out_cont, ConsoleColor.Yellow); sendTopologyAllocated(row.iport, row.in_cont); sendTopologyAllocated(row.oport, row.out_cont); SwitchingField.addToSwitch(row); SwitchingField.addToSwitch(new FIB(row.oport, row.out_cont, row.iport, row.in_cont)); sendConfirmation(row.iport, row.in_cont, true); } else { LRM.deallocateResource(row.iport, row.in_cont); sendConfirmation(row.iport, row.in_cont, false); } } else { sendConfirmation(row.iport, row.in_cont, false); } } } else if (received_Protocol.State == CCtoCCSignallingMessage.REALEASE_TOP_BOTTOM) { foreach (var fib in received_Protocol.Fib_table) { NetNode.log(DateTime.Now.ToLongTimeString() + " [CC -> LRM]" + " deallocate" + fib.toString(), ConsoleColor.Green); if (LRM.deallocateResource(fib.iport, fib.in_cont)) { sendTopologyDeallocated(fib.iport, fib.in_cont); } if (LRM.deallocateResource(fib.oport, fib.out_cont)) { sendTopologyDeallocated(fib.oport, fib.out_cont); } SwitchingField.clearFib(fib); SwitchingField.clearFib(new FIB(fib.oport, fib.out_cont, fib.iport, fib.in_cont)); } } else { NetNode.log("undefined protocol", ConsoleColor.Red); } } } catch (Exception e) { NetNode.log("\nError sending signal: " + e.Message, ConsoleColor.Red); Thread.Sleep(2000); Environment.Exit(1); } }