public void listener() { Task.Run(async() => { using (var updClient = udp) { while (true) { var result = await updClient.ReceiveAsync(); Package package = Package.fromBytes(result.Buffer); if (package.isMPLS()) { MPLSPackage MPLSpackage = Package.ReceiveMPLSPackage(package); Logs.LogsCableCloudReceivePackage(MPLSpackage); var InPort = MPLSpackage.GetPort(); var cable = ConnectedCableList[InPort]; if (ConnectedCableList[InPort].isAvailable == false) { Logs.LogsCableCloudSendingError(ConnectedCableList[InPort].OutNodeName, ConnectedCableList[ConnectedCableList[InPort].OutPort].OutNodeName); } else { MPLSpackage.swapPort(cable.OutPort); var outNodeName = cable.OutNodeName; var outIPEndPoint = IPlist[outNodeName]; IPEndPoint destination = outIPEndPoint; Package package1 = Package.MPLSPackage_(MPLSpackage); Logs.LogsCableCloudSendPackage(MPLSpackage); udp.Send(package1.toBytes(), package1.toBytes().Length, destination); package1 = null; MPLSpackage = null; } } else if (package.isTerminateOrder()) { Environment.Exit(0); } package = null; } } }); }
public void listener() { Task.Run(async() => { using (var updClient = udp) { while (true) { var result = await updClient.ReceiveAsync(); Package package = Package.fromBytes(result.Buffer); if (package.isRoutingCommunication() && nhfletable_set == false) { ManagementAnswer answer1 = Package.ReceiveRoutingTables(package); ComutationList = NHLFE.setRoutingTables(answer1); nhfletable_set = true; Logs.LogsReceiveRoutingTable(Name); } if (package.isMPLS()) { if (nhfletable_set) { MPLSPackage MPLSpackage = Package.ReceiveMPLSPackage(package); Console.WriteLine($"otrzymany TTL: {MPLSpackage.GetTTL()}"); MPLSpackage.decrementTTL(); if (MPLSpackage.GetTTL() > 0) { Logs.LogsRouterReceivePackage(MPLSpackage, Name); var InPort = MPLSpackage.GetPort(); int label = MPLSpackage.GetLastLabel(); int row_id = get_nhfle_row_id(InPort, label); if (row_id > -1) { switch (ComutationList[row_id].method) { case "swap": MPLSpackage.swap(ComutationList[row_id].label_out, ComutationList[row_id].port_out); break; case "push": push(ComutationList[row_id], MPLSpackage); break; case "pop": pop(ComutationList[row_id], MPLSpackage); break; } Console.WriteLine($"wysyłany TTL: {MPLSpackage.GetTTL()}"); Package package1 = Package.MPLSPackage_(MPLSpackage); Logs.LogsRouterSendPackage(MPLSpackage, Name); udp.Send(package1.toBytes(), package1.toBytes().Length, CableCloudEndPoint); } else { Console.WriteLine("Podana etykieta jest niepoprawna"); } //Thread.Sleep(1000); } } } else if (package.isTerminateOrder()) { Environment.Exit(0); } } } }); }