Exemple #1
0
        public void FindPath(NetworkPackage networkPackage)
        {
            //TimeStamp.WriteLine("{0} >> Received ROUTE TABLE QUERY REQUEST from {1}", RC_Name, networkPackage.sendingClientId);
            connectionMessage = networkPackage.message;

            /*
             * Big brain time - Wielkie sprawdzanie jak dojść do takiego klienta. Na razie oba są w domenie wiec do RC_A_1 i RC_A_2
             * Zapisać LRM połączenia między podsieciami
             */
            try
            {
                RCContact contact1 = contacts.Find(x => String.Equals(x.contactName, networkPackage.message.Split(' ')[0]));
                RCContact contact2 = contacts.Find(x => String.Equals(x.contactName, networkPackage.message.Split(' ')[1]));

                RCPath path = new RCPath();
                path.from           = contact1.subjectToAsk;
                path.to             = contact2.subjectToAsk;
                path.CCConnectionId = Int32.Parse(networkPackage.message.Split(' ')[4]);
                //Console.WriteLine(networkPackage.message);


                graph.Dijkstra(path.from, path.to, path);

                if (path.status == ConnectionStatus.InProgress)
                {
                    paths.Add(path);
                    Console.WriteLine("{0} {1} :: found path between {2} and {3}, length: {4}", TimeStamp.TAB, RC_Name, path.from, path.to, path.length);
                }
                else
                {
                    Console.WriteLine("{0} {1} did not found path between {2} and {3}", TimeStamp.TAB, RC_Name, path.from, path.to);
                }

                foundPathMessage = contact1.contactName + " " + contact2.subjectToAsk + " " + contact2.contactName + " " + contact1.subjectToAsk + " " + path.length;

                NetworkPackage response = new NetworkPackage(
                    "CC_" + domain.emulationNodeId,
                    "LRMs",
                    Command.Used_Slots_Request,
                    String.Join(" ", path.LRMids)
                    );

                domain.Send(response);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #2
0
        public void UsedCracksResponse(NetworkPackage networkPackage)
        {
            //TimeStamp.WriteLine("{0} >> Received USED SLOTS RESPONSE from {1}", RC_Name, networkPackage.sendingClientId);

            RCPath         path     = paths.Find(x => x.status == ConnectionStatus.InProgress);
            NetworkPackage response = new NetworkPackage(
                RC_Name,
                domain.domainCC.CC_Name,
                Command.Path_Found,
                foundPathMessage + ":" + networkPackage.message// klient_1 podsieć_klienta_2 klient_2 podsieć_klienta_1
                );

            TimeStamp.WriteLine("{0} >> ROUTE TABLE QUERY RESPONSE sent to {1}", RC_Name, "CC_" + networkPackage.receivingClientId);
            TimeStamp.WriteLine("{0} >> USED SLOTS REQUEST sent to {1}", "CC_" + domain.emulationNodeId, "LRMs");

            domain.domainCC.PathFound(response);
        }
Exemple #3
0
        public void LinkConnectionResponse(NetworkPackage networkPackage)
        {
            //TimeStamp.WriteLine("{0} >> Received L CON RES from {1}", CC_Name, networkPackage.sendingClientId);
            RCPath currentPath = domain.domainRC.paths.Find(x => x.status == ConnectionStatus.InProgress);

            foreach (Subnetwork subnetwork in domain.subnetworks)
            {
                NetworkPackage message = new NetworkPackage(
                    CC_Name,
                    subnetwork.cc.CC_Name,
                    Command.Link_Connection_Request,
                    connections.Find(x => x.status == ConnectionStatus.InProgress).id + ":" + currentPath.startCrack + " " + currentPath.endCrack
                    );
                TimeStamp.WriteLine("{0} >> LINK CONNECTION REQUEST sent to {1}", CC_Name, message.receivingClientId);
                subnetwork.cc.LinkConnection(message);
            }
        }
Exemple #4
0
        public void FindParams(NetworkPackage networkPackage)
        {
            //TimeStamp.WriteLine("{0} >> Received FIND PATH PARAMS from {1}", RC_Name, networkPackage.sendingClientId);

            /*
             * Big brain time liczenie parametrów ścieżki
             */
            string[] split = networkPackage.message.Split(' ');

            RCPath path         = paths.Find(x => x.status == ConnectionStatus.InProgress);
            string signalParams = SignalParamFinder.FindParams(Int32.Parse(split[1]), Int32.Parse(split[0]), new List <int>());

            string[] splittedSignalParams = signalParams.Split(' ');
            slotsToAllocate = splittedSignalParams[1] + " " + splittedSignalParams[2];
            path.startCrack = splittedSignalParams[1];
            path.endCrack   = splittedSignalParams[2];

            foreach (Subnetwork subnetwork in domain.subnetworks)
            {
                if (subnetwork.rc.paths.Find(x => x.CCConnectionId == path.CCConnectionId) != null)
                {
                    subnetwork.rc.paths.Find(x => x.CCConnectionId == path.CCConnectionId).startCrack = path.startCrack;
                    subnetwork.rc.paths.Find(x => x.CCConnectionId == path.CCConnectionId).endCrack   = path.endCrack;
                    //Console.WriteLine("Path {0} updated", path.CCConnectionId);
                }
                else
                {
                    Console.WriteLine("Not found {0} {1}", path.CCConnectionId, subnetwork.rc.paths.First().CCConnectionId);
                }
            }

            NetworkPackage response = new NetworkPackage(
                RC_Name,
                domain.domainCC.CC_Name,
                Command.Path_Params_Found,
                signalParams
                );

            TimeStamp.WriteLine("{0} >> CALCULATE PARAMS RESPONSE sent to {1}", RC_Name, response.receivingClientId);
            domain.domainCC.ParamsFound(response);
        }
Exemple #5
0
        public void FindPath(NetworkPackage networkPackage)
        {
            RCPath path = new RCPath();

            path.from           = networkPackage.message.Split(' ')[0];
            path.to             = networkPackage.message.Split(' ')[1];
            path.CCConnectionId = Int32.Parse(networkPackage.message.Split(' ')[2]);
            //Console.WriteLine(networkPackage.message);


            graph.Dijkstra(networkPackage.message.Split(' ')[0], networkPackage.message.Split(' ')[1], path);

            if (path.status == ConnectionStatus.InProgress)
            {
                paths.Add(path);
                Console.WriteLine("{0} {1} :: found path between {2} and {3}, length: {4}", TimeStamp.TAB, RC_Name, path.from, path.to, path.length);
            }
            else
            {
                Console.WriteLine("{0} {1} did not found path between {2} and {3}", TimeStamp.TAB, RC_Name, path.from, path.to);
            }


            TimeStamp.WriteLine("{0} >> ROUTE TABLE QUERY RESPONSE sent to {1}", RC_Name, networkPackage.sendingClientId);
            networkPackage.receivingClientId = networkPackage.sendingClientId;
            networkPackage.sendingClientId   = RC_Name;

            /*
             * Dodać zajęte szczeliny
             */
            TimeStamp.WriteLine("{0} >> USED SLOTS REQUEST sent to {1}", "CC_" + subnetwork.emulationNodeId, "LRMs");
            NetworkPackage response = new NetworkPackage(
                "CC_" + subnetwork.emulationNodeId,
                "LRMs",
                Command.Used_Slots_Request,
                String.Join(" ", path.LRMids)
                );

            subnetwork.domain.Send(response);
        }
Exemple #6
0
        public void RestorePath(NetworkPackage networkPackage)
        {
            RCPath path = paths.Find(x => x.CCConnectionId == Int32.Parse(networkPackage.message));

            path.LRMids.Clear();
            path.nodes.Clear();

            graph.Dijkstra(path.from, path.to, path);

            if (path.status == ConnectionStatus.InProgress)
            {
                paths.Add(path);
                Console.WriteLine("{0} {1} :: found path between {2} and {3}, length: {4}", TimeStamp.TAB, RC_Name, path.from, path.to, path.length);
            }
            else
            {
                Console.WriteLine("{0} {1} :: did not found path between {2} and {3}", TimeStamp.TAB, RC_Name, path.from, path.to);
            }


            TimeStamp.WriteLine("{0} >> RESTORE PATH RESPONSE sent to {1}", RC_Name, networkPackage.sendingClientId);
            networkPackage.receivingClientId = networkPackage.sendingClientId;
            networkPackage.sendingClientId   = RC_Name;

            messagesToSend.Clear();
            connectionMessage = networkPackage.message;
            string lambda = path.lambda;

            for (int i = 1; i < path.LRMids.Count; i++)
            {
                if (path.nodes[i].Contains("OXC"))
                {
                    string portConfig = GetPorts(path.LRMids[i - 1], path.nodes[i], path.LRMids[i]);
                    if (portConfig.Length > 0)
                    {
                        messagesToSend.Push(new NetworkPackage(
                                                RC_Name,
                                                path.nodes[i],
                                                Command.Set_OXC,
                                                portConfig + " " + lambda + " " + "d"
                                                ));
                        subnetwork.domain.Send(messagesToSend.Pop());
                        Thread.Sleep(10);
                    }
                    else
                    {
                        Console.WriteLine("PORT CONFIG ERROR");
                    }
                }
            }


            TimeStamp.WriteLine("{0} >> LINK CONNECTION REQUEST sent to {1}", "CC_" + subnetwork.emulationNodeId, "LRMs");
            NetworkPackage response = new NetworkPackage(
                "CC_" + subnetwork.emulationNodeId,
                "LRMs",
                Command.Link_Connection_Request,
                String.Join(" ", path.LRMids) + ":" + path.startCrack + " " + path.endCrack + ":false"
                );

            subnetwork.domain.Send(response);
        }