Пример #1
0
 public void pop(NHLFE.NHFLERow entry, MPLSPackage MPLSpackage)
 {
     MPLSpackage.ChangeLabel("pop");
     NHLFE.NHFLERow nextentry = ComutationList[entry.next_id];
     if (nextentry.method == "swap")
     {
         MPLSpackage.swap(nextentry.label_out, nextentry.port_out);
         return;
     }
     while (nextentry.method != "swap")
     {
         MPLSpackage.ChangeLabel("pop");
         nextentry = ComutationList[nextentry.next_id];
     }
     MPLSpackage.swap(nextentry.label_out, nextentry.port_out);
 }
Пример #2
0
        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);
                        }
                    }
                }
            });
        }