Ejemplo n.º 1
0
        public bool FastReroute(Call call, int connectionID)
        {
            GUIWindow.PrintLog("RC: Received RouteTableQuery(" + connectionID + ") from CC");

            Path        oldPath = call.GetPath();
            List <Path> paths   = null;

            try {
                paths = Algorithms.AllPaths(oldPath.endPoints.Item1, oldPath.endPoints.Item2);
            } catch (Exception e) {
                GUIWindow.PrintLog(e.Message);
                GUIWindow.PrintLog(e.StackTrace);
            }

            if (paths == null || paths.Count == 0)
            {
                //nie istnieje żadna ścieżka -> należy przejść wyżej lub rozłączyć jeśli jesteśmy już na górze
                return(false);
            }

            Path newPath = paths[0];

            NCC.callRegister[connectionID].path = newPath;

            string oldLCs = "";

            foreach (Connection connection in oldPath.edges)
            {
                if (ConfigLoader.myConnections.Values.Contains(connection))
                {
                    oldLCs += connection.GetID() + ", ";
                }
            }
            oldLCs = oldLCs.Remove(oldLCs.Length - 2, 2);

            string newLCs = "";

            foreach (Connection connection in newPath.edges)
            {
                if (ConfigLoader.myConnections.Values.Contains(connection))
                {
                    newLCs += connection.GetID() + ", ";
                }
            }
            newLCs = newLCs.Remove(newLCs.Length - 2, 2);

            GUIWindow.PrintLog("RC: Sent RouteTableQueryResponse(" + oldLCs + ";" + newLCs + ") to CC");       //tutaj dodać do argumentów id LC tylko z tej podsieci
            GUIWindow.PrintLog("CC: Received RouteTableQueryResponse(" + oldLCs + ";" + newLCs + ") from RC"); //tu też

            UpdateRoutingTables(oldPath, call.GetConnectionID(), false, true);
            UpdateRoutingTables(newPath, call.GetConnectionID(), false, false);
            UpdateRoutingTables(newPath, call.GetConnectionID(), true, false);

            foreach (Connection connection in oldPath.edges)
            {
                if (!ConfigLoader.myConnections.Values.Contains(connection))
                {
                    continue;
                }

                for (int i = 0; i < connection.slot.Length; i++)
                {
                    if (connection.slot[i] == connectionID)
                    {
                        connection.slot[i] = 0;
                    }
                }

                GUIWindow.PrintLog("CC: Sent LinkConnectionDeallocation(" + connection.GetID() + ") to internal LRM");
                GUIWindow.PrintLog("Internal LRM: Received LinkConnectionDeallocation(" + connection.GetID() + ") from CC");

                GUIWindow.PrintLog("Internal LRM: Sent LocalTopology(" + connection.GetID() + ": " + String.Join("", connection.slot) + ") to RC : DEALLOCATED");
                GUIWindow.PrintLog("RC: Received LocalTopology(" + connection.GetID() + ": " + String.Join("", connection.slot) + ") from Internal LRM : DEALLOCATED");
                GUIWindow.PrintLog("RC: Sent LocalTopologyResponse() to Internal LRM : OK");
                GUIWindow.PrintLog("Internal LRM: Received LocalTopologyResponse() from RC : OK");

                GUIWindow.PrintLog("Internal LRM: Sent LinkConnectionDeallocationResponse() to CC");
                GUIWindow.PrintLog("CC: Received LinkConnectionDeallocationResponse() from Internal LRM");
            }

            string[] range = oldPath.channelRange.Split('-');
            foreach (Connection connection in newPath.edges)
            {
                if (!ConfigLoader.myConnections.Values.Contains(connection))
                {
                    continue;
                }

                for (int i = Convert.ToInt32(range[0]); i <= Convert.ToInt32(range[1]); i++)
                {
                    connection.slot[i] = RC.currentConnectionID;
                }

                GUIWindow.PrintLog("CC: Sent LinkConnectionRequest(" + connection.GetID() + ", " + oldPath.channelRange + ") to internal LRM");
                GUIWindow.PrintLog("Internal LRM: Received LinkConnectionRequest(" + connection.GetID() + ", " + oldPath.channelRange + ") from CC");

                GUIWindow.PrintLog("Internal LRM: Sent LocalTopology(" + connection.GetID() + ": " + String.Join("", connection.slot) + ") to RC");
                GUIWindow.PrintLog("RC: Received LocalTopology(" + connection.GetID() + ": " + String.Join("", connection.slot) + ") from Internal LRM");
                GUIWindow.PrintLog("RC: Sent LocalTopologyResponse() to Internal LRM : OK");
                GUIWindow.PrintLog("Internal LRM: Received LocalTopologyResponse() from RC : OK");

                GUIWindow.PrintLog("Internal LRM: Sent LinkConnectionRequestResponse() to CC");
                GUIWindow.PrintLog("CC: Received LinkConnectionRequestResponse() from Internal LRM");
            }
            GUIWindow.UpdateChannelTable();

            //GUIWindow.PrintLog("Internal LRM: Sent ChannelReallocationResponse() to CC");
            //GUIWindow.PrintLog("CC: Received ChannelReallocationResponse() from Internal LRM");

            return(true);
        }
Ejemplo n.º 2
0
        private void CalculateAllPaths()
        {
            Node startingNode = ConfigLoader.GetNodeByIP(cachedData["routerX"]);
            Node endingNode   = ConfigLoader.GetNodeByIP(cachedData["routerY"]);
            int  speed        = Convert.ToInt32(cachedData["speed"]);
            Host startHost    = null;
            Host endingHost   = null;

            foreach (Host h in ConfigLoader.hosts)
            {
                if (startingNode == h.GetNeighborRouter())
                {
                    startHost = h;
                }
                if (endingNode == h.GetNeighborRouter())
                {
                    endingHost = h;
                }
            }

            List <Path> paths = Algorithms.AllPaths(startHost, endingHost);

            if (paths == null || paths.Count == 0)
            {
                //nie istnieje żadna ścieżka
                GUIWindow.PrintLog("RC: Sent RouteTableQueryResponse(null) to CC");
                Program.cc.HandleRequest(Util.DecodeRequest("component:CC;name:RouteTableQueryResponse;path:null"));
                return;
            }

            Path chosenPath = null;

            foreach (Path path in paths)
            {
                int[] pathsID = path.getEdges();
                int   n       = DetermineGapNo(speed, path.GetLength());
                //GUIWindow.PrintLog("Channel count: " + n);
                int[,] LRMarray = GetLRMarray(pathsID);
                int[] indexFromTo = EvaluatePath(n, LRMarray);
                if (indexFromTo[0] != -1 && indexFromTo[1] != -1)
                {
                    //GUIWindow.PrintLog("Test: n: " + n + " index from: " + indexFromTo[0] + " to " + indexFromTo[1]);
                    try {
                        cachedData.Add("channelRange", indexFromTo[0] + "-" + indexFromTo[1]);
                    } catch (Exception) {
                        cachedData["channelRange"] = indexFromTo[0] + "-" + indexFromTo[1];
                    }
                    chosenPath = path;
                    chosenPath.channelRange = indexFromTo[0] + "-" + indexFromTo[1];
                    break;
                }
            }
            currentPath = chosenPath;

            //GUIWindow.PrintLog("Path from Router" + startingNode.GetRouterID() + " to Router" + endingNode.GetRouterID() + " at " + speed + " Gb/s");
            if (chosenPath == null)
            {
                GUIWindow.PrintLog("RC: Sent RouteTableQueryResponse(null) to CC");
                Program.cc.HandleRequest(Util.DecodeRequest("component:CC;name:RouteTableQueryResponse;path:null"));
                return;
            }

            int nextConnectionID = currentConnectionID + 1;

            if (Convert.ToBoolean(cachedData["IDC"]))
            {
                nextConnectionID = Math.Max(nextConnectionID, Convert.ToInt32(cachedData["peerConnID"]) + 1);
            }
            currentConnectionID = nextConnectionID;
            string pathString = (chosenPath == null ? "null" : chosenPath.ToString());

            GUIWindow.PrintLog("RC: Sent RouteTableQueryResponse(" + pathString + ") to CC");
            GUIWindow.PrintLog("CC: Received RouteTableQueryResponse(" + pathString + ") from RC");

            UpdateRoutingTables(chosenPath, currentConnectionID, false, false);
            UpdateRoutingTables(chosenPath, currentConnectionID, true, false);

            string message = "component:CC;name:RouteTableQueryResponse;path:" + pathString;

            Program.cc.HandleRequest(Util.DecodeRequest(message));
        }