private void RecieveMessages()
        {
            try {
                while (true)
                {
                    string   message = reader.ReadLine();
                    string[] pieces  = message.Split(';');
                    Dictionary <string, string> data = new Dictionary <string, string>();
                    foreach (string piece in pieces)
                    {
                        string[] keyAndValue = piece.Split(':');
                        data.Add(keyAndValue[0], keyAndValue[1]);
                    }

                    switch (data["component"])
                    {
                    case "RC":
                        Program.rc.HandleRequest(data);
                        break;

                    case "CC":
                        Program.cc.HandleRequest(data);
                        break;
                    }
                }
            } catch (Exception e) {
                GUIWindow.PrintLog(e.Message);
                GUIWindow.PrintLog(e.StackTrace);
            }
        }
Beispiel #2
0
 public GUIWindow()
 {
     InitializeComponent();
     CreateChannelTable();
     //UpdateChannelTable();
     instance = this;
 }
Beispiel #3
0
        private void RecieveMessages()
        {
            try {
                while (true)
                {
                    string message = reader.ReadLine();
                    Dictionary <string, string> data = Util.DecodeRequest(message);

                    switch (data["component"])
                    {
                    case "NCC":
                        ncc.HandleRequest(data, null);
                        break;

                    case "RC":
                        Program.rc.HandleRequest(data);
                        break;

                    case "LRM":
                        Program.lrm.HandleRequest(data);
                        break;

                    case "CC":
                        Program.cc.HandleRequest(data);
                        break;
                    }
                }
            } catch (Exception e) {
                GUIWindow.PrintLog(e.Message);
                GUIWindow.PrintLog(e.StackTrace);
            }
        }
Beispiel #4
0
        private void ConnectionRequest(bool interDomainConnection)
        {
            GUIWindow.PrintLog("NCC: Sent ConnectionRequest(" + lastRouterXIP + ", " + lastRouterYIP + ", " + lastSpeed + " Gb/s, InterDomainConnection: " + interDomainConnection + ") to CC");
            string message = "name:ConnectionRequest;routerX:" + lastRouterXIP + ";routerY:" + lastRouterYIP + ";speed:" + lastSpeed + ";IDC:" + interDomainConnection.ToString() + ";layer:upper";

            Program.cc.HandleRequest(Util.DecodeRequest(message));
        }
Beispiel #5
0
        private Tuple <string, string, int, int> HandleDirectory(string hostX, string hostY)
        {
            GUIWindow.PrintLog("NCC: Sent DirectoryRequest(" + hostX + ") to Directory");
            string routerXIP;
            int    routerXAsId = 0;

            try {
                Tuple <string, int> info = directory[hostX];
                routerXIP   = info.Item1;
                routerXAsId = info.Item2;
            } catch (Exception) {
                routerXIP = "WRONG NAME";
            }
            GUIWindow.PrintLog("NCC: Received DirectoryRequestResponse(" + routerXIP + ", " + routerXAsId + ") from Directory");
            GUIWindow.PrintLog("NCC: Sent DirectoryRequest(" + hostY + ") to Directory");

            string routerYIP;
            int    routerYAsId = 0;

            try {
                Tuple <string, int> info = directory[hostY];
                routerYIP   = info.Item1;
                routerYAsId = info.Item2;
            } catch (Exception) {
                routerYIP = "WRONG NAME";
            }
            GUIWindow.PrintLog("NCC: Received DirectoryRequestResponse(" + routerYIP + ", " + routerYAsId + ") from Directory");

            return(new Tuple <string, string, int, int>(routerXIP, routerYIP, routerXAsId, routerYAsId));
        }
Beispiel #6
0
        public void PrintPath()
        {
            string line = "";

            foreach (Connection edge in edges)
            {
                line += edge.endPoints.Item1.GetRouterID() + "-" + edge.endPoints.Item2.GetRouterID() + "   ";
            }
            GUIWindow.PrintLog(line);
        }
        public Server(NCC ncc)
        {
            this.ncc  = ncc;
            ipAddress = Dns.GetHostEntry(ip).AddressList[0];
            server    = new TcpListener(ipAddress, port);
            //TODO: tu jakiś konfig wczytujemy

            GUIWindow.PrintLog("Control center is waiting for connections...");
            server.Start();

            new Thread(StartListening).Start();
        }
        public void HandleClient(TcpClient client)
        {
            TcpClient     MyClient = client;
            NetworkStream stream   = MyClient.GetStream();
            StreamReader  reader   = new StreamReader(stream);
            StreamWriter  writer   = new StreamWriter(stream);

            try {
                string   request = reader.ReadLine();
                string[] cut     = request.Split(':');

                if (cut[0].Equals("REGISTRATION") && cut[1].Equals("HOST"))
                {
                    numOfHosts++;

                    foreach (Host h in ConfigLoader.GetHosts())
                    {
                        if (h.getIP() == cut[2])
                        {
                            lock (hostConnections) {
                                hostConnections.AddLast(new HostConnection(h, client, Convert.ToInt32(cut[3]), this, ncc));
                            }
                            writer.WriteLine("component:NONE;name:RegistrationResponse;succeeded:true");
                            writer.Flush();
                            GUIWindow.PrintLog("Host #" + cut[3] + "|" + cut[2] + "| has been registered");
                            break;
                        }
                    }
                }
                else if (cut[0].Equals("REGISTRATION") && cut[1].Equals("ROUTER"))
                {
                    numOfRouters++;

                    foreach (Router r in ConfigLoader.GetRouters())
                    {
                        if (r.getIP() == cut[2])
                        {
                            lock (routerConnections) {
                                routerConnections.AddLast(new RouterConnection(r, client, Convert.ToInt32(cut[3]), this));
                            }
                            writer.WriteLine("REGISTRATION:OK");
                            writer.Flush();

                            GUIWindow.PrintLog("Router #" + cut[3] + "|" + cut[2] + "| has been registered");

                            break;
                        }
                    }
                }
            } catch (IOException) {
                GUIWindow.PrintLog("One of the network nodes has been disconected");
            }
        }
 public void SendRoutingTable(Dictionary <int, int> routingTable)
 {
     try {
         byte[] bytes = Server.SerializeObject(routingTable);
         stream.Write(bytes, 0, bytes.Length);
         string subnetworkTag = id > 5 ? "SN" : "";
         //string tag = subnetworkTag.Length == 0 ? asID.ToString() : subnetworkTag;
         //RouteControl.savedLogs.Add(new Tuple<string, string>(tag, "Sending Connection Table to Router #" + id));
         //GUIWindow.PrintLog("RC: Seding Connection Table to Router #" + id, asID);
     } catch (Exception e) {
         GUIWindow.PrintLog(e.Message);
     }
 }
 private void PrintLRMLogs()
 {
     foreach (Connection connection in ConfigLoader.myConnections.Values)
     {
         if (connection.endPoints.Item1.GetRouterID() == id || connection.endPoints.Item2.GetRouterID() == id)
         {
             GUIWindow.PrintLog("Internal LRM: LinkConnection #" + connection.GetID() + " has stopped working");
             GUIWindow.PrintLog("Internal LRM: Sent LocalTopology(" + connection.GetID() + ", DISABLED) to RC");
             GUIWindow.PrintLog("RC: Received LocalTopology(" + connection.GetID() + ", DISABLED) from Internal LRM");
             GUIWindow.PrintLog("RC: Sent LocalTopologyResponse() to Internal LRM");
             GUIWindow.PrintLog("Internal LRM: Received LocalTopologyResponse() from RC");
         }
     }
 }
Beispiel #11
0
        static void Main(String[] args)
        {
            try {
                args = Environment.GetCommandLineArgs();

                new Thread(() => {
                    Thread.Sleep(1000);
                    try {
                        String config = String.Concat(File.ReadAllLines(args[1]));
                        ConfigLoader.loadConfig(config, args[2]);

                        //String config = String.Concat(File.ReadAllLines("./../../../../sharedResources/tsst_config.xml"));
                        //ConfigLoader.loadConfig(config, "1");


                        //String config = String.Concat(File.ReadAllLines("./../../../../sharedResources/tsst_config.xml"));
                        //ConfigLoader.loadConfig(config);
                        //String config = String.Concat(File.ReadAllLines(args[1]));
                        //ConfigLoader.LoadConfig(config, args[2]);
                        ncc    = new NCC();
                        server = new Server(ncc);

                        if (ConfigLoader.ccID == 2)
                        {
                            interCCServer = new InterCcCommunicationServer(ncc);
                        }
                        else if (ConfigLoader.ccID == 1)
                        {
                            peerConnection = new PeerConnection(new TcpClient("localhost", 12500), true, ncc);
                        }
                        else
                        {
                            childConnection = new ChildConnection(new TcpClient("localhost", 12500), ncc);
                        }
                        GUIWindow.UpdateChannelTable();
                    }
                    catch (Exception e) {
                        GUIWindow.PrintLog(e.StackTrace);
                    }
                }).Start();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new GUIWindow());
            }
            catch (Exception ex) {
                GUIWindow.PrintLog(ex.StackTrace);
            }
        }
Beispiel #12
0
 private void FindRouterConnectionAndSend(Router router, int id, int port, bool log)
 {
     foreach (RouterConnection routerConnection in Server.GetRouterConnections())
     {
         if (routerConnection.router == router)
         {
             Dictionary <int, int> routingTable = new Dictionary <int, int>();
             routingTable.Add(id, port);
             routerConnection.SendRoutingTable(routingTable);
             //if(log) {
             GUIWindow.PrintLog("CC: Sent MatrixConnection(" + id + ", " + port + ") to Router #" + router.GetRouterID() + "'s CC");
             GUIWindow.PrintLog("CC: Received MatrixConnectionResponse() from Router #" + router.GetRouterID() + "'s CC");
             //}
             break;
         }
     }
 }
        public RouterConnection(Router router, TcpClient client, int id, Server server)
        {
            this.router    = router;
            this.client    = client;
            this.id        = id;
            this.server    = server;
            stream         = client.GetStream();
            reader         = new StreamReader(stream);
            router.working = true;

            try {
                ReceiveKeepAlive();
            } catch (Exception e) {
                GUIWindow.PrintLog(e.Message);
                GUIWindow.PrintLog(e.StackTrace);
            }
        }
        private void ReceiveKeepAlive()
        {
            new Thread(() => {
                Thread.Sleep(2000);

                while (true)
                {
                    try {
                        string message = reader.ReadLine();
                        string IDs     = message.Split(':')[1];
                        currentConnections.Clear();
                        if (IDs.Length > 0)
                        {
                            foreach (string idString in IDs.Split(' '))
                            {
                                if (idString.Length > 0)
                                {
                                    currentConnections.Add(Convert.ToInt32(idString));
                                }
                            }
                        }

                        if (GUIWindow.ShowKeepAlive())
                        {
                            GUIWindow.PrintLog("CC: KEEP-ALIVE received from Router #" + id);
                        }
                    } catch (IOException) {
                        PrintLRMLogs();
                        GUIWindow.PrintLog("CC: Router #" + id + " has stopped working.");
                        router.working = false;
                        working        = false;
                        server.RemoveRouterConnection(this);
                        //redirect route
                        foreach (int connectionID in currentConnections)
                        {
                            GUIWindow.PrintLog("CC: Sent RouteTableQuery(" + connectionID + ") to RC");
                            Program.rc.FastReroute(NCC.callRegister[connectionID], connectionID);
                        }

                        break;
                    }
                }
            }).Start();
        }
Beispiel #15
0
        public int[,] GetLRMarray(int[] connID)
        {
            int[,] LRMarray = new int[connID.Length, 90];
            int n = 0;

            try {
                foreach (int key in connID)
                {
                    int[] buff = cachedChannels[key];

                    for (int j = 0; j < 90; j++)
                    {
                        LRMarray[n, j] = buff[j];
                    }
                    n++;
                }
            } catch (Exception e) {
                GUIWindow.PrintLog(e.Message);
                GUIWindow.PrintLog(e.StackTrace);
            }

            return(LRMarray);
        }
Beispiel #16
0
        public void HandleRequest(Dictionary <string, string> data)
        {
            switch (data["name"])
            {
            case "NetworkTopology":
                switch (data["receiver"])
                {
                case "peer":
                    GUIWindow.PrintLog("RC: Received NetworkTopology() from peer RC");

                    if (data["scenario"].Equals("1"))
                    {
                        //scenariusz #1
                        GUIWindow.PrintLog("RC: Sent NetworkTopology() to child RC");
                        string message2 = "component:RC;name:NetworkTopology;receiver:child;scenario:" + data["scenario"];
                        Program.parentConnection.SendMessage(message2);
                    }
                    else if (data["scenario"].Equals("2"))
                    {
                        //scenariusz #2
                        string hostList = " Hosts = ";
                        foreach (Host host in ConfigLoader.myHosts)
                        {
                            hostList += host.GetHostID() + ", ";
                        }
                        hostList = hostList.Remove(hostList.Length - 2, 2);

                        string routersList2 = "Routers = ";
                        foreach (Router router in ConfigLoader.myRouters)
                        {
                            routersList2 += (router.working ? "" : "!") + router.GetRouterID() + ", ";
                        }
                        routersList2 = routersList2.Remove(routersList2.Length - 2, 2);

                        string linksList2   = " Links = ";
                        string channelList2 = "";
                        foreach (Connection connection in ConfigLoader.myConnections.Values)
                        {
                            linksList2   += connection.endPoints.Item1.GetHostID() + "-" + connection.endPoints.Item2.GetHostID() + ", ";
                            channelList2 += connection.GetID() + "=" + string.Join(",", connection.GetSlot()) + "-";
                        }
                        linksList2   = linksList2.Remove(linksList2.Length - 2, 2);
                        channelList2 = channelList2.Remove(channelList2.Length - 1, 1);
                        //GUIWindow.PrintLog("Channel List: " + channelList2);

                        GUIWindow.PrintLog("RC: Sent NetworkTopologyResponse(" + routersList2 + hostList + linksList2 + ") to peer RC");
                        string message = "component:RC;name:NetworkTopologyResponse;receiver:peer;routersList:" + routersList2 + ";linksList:" + linksList2 + ";hostList:" + hostList + ";scenario:" + data["scenario"] + ";channels:" + channelList2 + ";connID:" + currentConnectionID;
                        Program.peerConnection.SendMessage(message);
                    }
                    break;

                case "child":
                    //scenariusz #1, 2 lub 3
                    GUIWindow.PrintLog("RC: Received NetworkTopology() from parent RC");
                    string routersList = "Routers = ";
                    foreach (Router router in ConfigLoader.myRouters)
                    {
                        routersList += (router.working ? "" : "!") + router.GetRouterID() + ", ";
                    }
                    routersList = routersList.Remove(routersList.Length - 2, 2);

                    string linksList   = " Connections = ";
                    string channelList = "";
                    foreach (Connection connection in ConfigLoader.myConnections.Values)
                    {
                        linksList   += connection.endPoints.Item1.GetHostID() + "-" + connection.endPoints.Item2.GetHostID() + ", ";
                        channelList += connection.GetID() + "=" + string.Join(",", connection.GetSlot()) + "-";
                    }
                    linksList   = linksList.Remove(linksList.Length - 2, 2);
                    channelList = channelList.Remove(channelList.Length - 1, 1);
                    //GUIWindow.PrintLog("Channel List: " + channelList);

                    GUIWindow.PrintLog("RC: Sent NetworkTopologyResponse(" + routersList + linksList + ") to parent RC");
                    string message1 = "component:RC;name:NetworkTopologyResponse;receiver:parent;routersList:" + routersList + ";linksList:" + linksList + ";scenario:" + data["scenario"] + ";channels:" + channelList;
                    Program.childConnection.SendMessage(message1);
                    break;
                }

                break;

            case "NetworkTopologyResponse":
                switch (data["receiver"])
                {
                case "parent":
                    GUIWindow.PrintLog("RC: Received NetworkTopologyResponse(" + data["routersList"] + data["linksList"] + ") from child RC");
                    if (data["scenario"].Equals("1"))
                    {
                        //scenariusz #1
                        string hostList = " Hosts = ";
                        foreach (Host host in ConfigLoader.myHosts)
                        {
                            hostList += host.GetHostID() + ", ";
                        }
                        hostList = hostList.Remove(hostList.Length - 2, 2);

                        string routersList = data["routersList"] + ", ";
                        foreach (Router router in ConfigLoader.myRouters)
                        {
                            routersList += (router.working ? "" : "!") + router.GetRouterID() + ", ";
                        }
                        routersList = routersList.Remove(routersList.Length - 2, 2);

                        string linksList   = data["linksList"] + ", ";
                        string channelList = data["channels"] + "-";
                        foreach (Connection connection in ConfigLoader.myConnections.Values)
                        {
                            linksList   += connection.endPoints.Item1.GetHostID() + "-" + connection.endPoints.Item2.GetHostID() + ", ";
                            channelList += connection.GetID() + "=" + string.Join(",", connection.GetSlot()) + "-";
                        }
                        linksList   = linksList.Remove(linksList.Length - 2, 2);
                        channelList = channelList.Remove(channelList.Length - 1, 1);

                        GUIWindow.PrintLog("RC: Sent NetworkTopologyResponse(" + routersList + hostList + linksList + ") to peer RC");
                        string message = "component:RC;name:NetworkTopologyResponse;receiver:peer;routersList:" + routersList + ";linksList:" + linksList + ";hostList:" + hostList + ";scenario:" + data["scenario"] + ";channels:" + channelList + ";connID:" + currentConnectionID;
                        Program.peerConnection.SendMessage(message);
                    }
                    else if (data["scenario"].Equals("2"))
                    {
                        //scenariusz #2
                        GUIWindow.PrintLog("RC: Sent NetworkTopology() to peer RC");
                        CacheChannels(data["channels"]);
                        FlagRouters(data["routersList"]);
                        string message = "component:RC;name:NetworkTopology;receiver:peer;routersList:" + data["routersList"] + ";linksList:" + data["linksList"] + ";scenario:" + data["scenario"];
                        Program.peerConnection.SendMessage(message);
                    }
                    else if (data["scenario"].Equals("3"))
                    {
                        //koniec scenariusza #3
                        CacheChannels(data["channels"]);
                        FlagRouters(data["routersList"]);
                        LoadMyChannels();
                        CalculateAllPaths();
                    }
                    break;

                case "peer":
                    GUIWindow.PrintLog("RC: Received NetworkTopologyResponse(" + data["routersList"] + data["hostList"] + data["linksList"] + ") from peer RC");
                    if (data["scenario"].Equals("1"))
                    {
                        //koniec scenariusza #1
                        cachedData.Add("peerConnID", data["connID"]);
                        CacheChannels(data["channels"]);
                        FlagRouters(data["routersList"]);
                        LoadMyChannels();
                        CalculateAllPaths();
                    }
                    else if (data["scenario"].Equals("2"))
                    {
                        //koniec scenariusza #2
                        cachedData.Add("peerConnID", data["connID"]);
                        CacheChannels(data["channels"]);
                        FlagRouters(data["routersList"]);
                        LoadMyChannels();
                        CalculateAllPaths();
                    }
                    break;
                }
                break;

            case "RouteTableQuery":
                GUIWindow.PrintLog("RC: Received RouteTableQuery(" + data["routerX"] + ", " + data["routerY"] + ", " + data["speed"] + " Gb/s, InterDomainConnection: " + data["IDC"] + ") from CC");

                cachedData.Clear();
                cachedData.Add("routerX", data["routerX"]);
                cachedData.Add("routerY", data["routerY"]);
                cachedData.Add("speed", data["speed"]);
                cachedData.Add("IDC", data["IDC"]);

                if (ConfigLoader.ccID == 1)
                {
                    if (Convert.ToBoolean(data["IDC"]))
                    {
                        //scenariusz #1
                        string message = "component:RC;name:NetworkTopology;receiver:peer;scenario:1";
                        GUIWindow.PrintLog("RC: Sent NetworkTopology() to peer RC");
                        Program.peerConnection.SendMessage(message);
                    }
                    else
                    {
                        //scenariusz #4
                        LoadMyChannels();
                        CalculateAllPaths();
                    }
                }
                else if (ConfigLoader.ccID == 2)
                {
                    if (Convert.ToBoolean(data["IDC"]))
                    {
                        //scenariusz #2
                        string message = "component:RC;name:NetworkTopology;receiver:child;scenario:2";
                        GUIWindow.PrintLog("RC: Sent NetworkTopology() to child RC");
                        Program.parentConnection.SendMessage(message);
                    }
                    else
                    {
                        //scenariusz #3
                        string message = "component:RC;name:NetworkTopology;receiver:child;scenario:3";
                        GUIWindow.PrintLog("RC: Sent NetworkTopology() to child RC");
                        Program.parentConnection.SendMessage(message);
                    }
                }
                break;

            case "SendConnectionTables":
                //GUIWindow.PrintLog("RC: Received SendConnectionTables(" + data["path"] + ", " + data["connID"] + ") from CC");
                currentConnectionID = Convert.ToInt32(data["connID"]);
                UpdateRoutingTables(Program.cc.cachedPath, currentConnectionID, false, false);
                UpdateRoutingTables(Program.cc.cachedPath, currentConnectionID, true, false);

                //GUIWindow.PrintLog("RC: Sent SendConnectionTablesResponse() to CC");
                Program.cc.HandleRequest(Util.DecodeRequest("component:CC;name:SendConnectionTablesResponse"));
                break;
            }
        }
Beispiel #17
0
        public void HandleRequest(Dictionary <string, string> data, HostConnection caller)
        {
            try {
                switch (data["name"])
                {
                case "CallRequest":
                    GUIWindow.PrintLog("NCC: Received CallRequest(" + data["hostX"] + ", " + data["hostY"] + ", " + data["speed"] + " Gb/s) from CPCC");

                    Tuple <string, string, int, int> routerData = HandleDirectory(data["hostX"], data["hostY"]);
                    if (routerData.Item1.Equals("WRONG NAME") || routerData.Item2.Equals("WRONG NAME"))
                    {
                        GUIWindow.PrintLog("NCC: Host name does not exist");
                        GUIWindow.PrintLog("NCC: Sent CallRequestResponse(UNSUCCESSFUL)");
                        RefuseConnection(caller);
                        break;
                    }
                    else if (routerData.Item1.Equals(routerData.Item2))
                    {
                        GUIWindow.PrintLog("NCC: Target Host name is the same as the source one");
                        GUIWindow.PrintLog("NCC: Sent CallRequestResponse(UNUSCCESSFUL)");
                        RefuseConnection(caller);
                        break;
                    }
                    HandlePolicy();

                    lastCaller    = caller;
                    lastRouterXIP = routerData.Item1;
                    lastRouterYIP = routerData.Item2;;
                    lastSpeed     = Convert.ToInt32(data["speed"]);
                    lastIDC       = routerData.Item3 != routerData.Item4;

                    if (!lastIDC)
                    {
                        string         hostYIP1        = routerData.Item2.Remove(routerData.Item2.Length - 1, 1) + "2";
                        HostConnection hostConnection1 = Server.GetHostConnectionByIP(hostYIP1);
                        string         message1        = "component:CPCC;name:CallAccept;routerX:" + data["hostX"] + ";routerY:" + data["hostY"] + ";speed:" + data["speed"];
                        hostConnection1.SendMessage(message1);
                        cachedHostYConnection = hostConnection1;
                        GUIWindow.PrintLog("NCC: Sent CallAccept(" + data["hostX"] + ", " + data["hostY"] + ", " + data["speed"] + " Gb/s) to other NCC");
                        break;
                    }

                    string message = "component:NCC;name:CallCoordination;routerX:" + routerData.Item1 + ";routerY:" + routerData.Item2 + ";speed:" + data["speed"] + ";IDC:" + lastIDC.ToString();
                    Program.peerConnection.SendMessage(message);
                    GUIWindow.PrintLog("NCC: Sent CallCoordination(" + routerData.Item1 + ", " + routerData.Item2 + ", " + data["speed"] + " Gb/s) to other NCC");

                    break;

                case "CallCoordination":

                    GUIWindow.PrintLog("NCC: Received CallCoordination(" + data["routerX"] + ", " + data["routerY"] + ", " + data["speed"] + " Gb/s) from other NCC");
                    lastIDC = Convert.ToBoolean(data["IDC"]);

                    //odwrotne dzialanie funkcji -- dajemy IP dostajemy nazwy
                    routerData = HandleDirectory(data["routerX"], data["routerY"]);
                    HandlePolicy();
                    string         hostYIP        = data["routerY"].Remove(data["routerY"].Length - 1, 1) + "2";
                    HostConnection hostConnection = Server.GetHostConnectionByIP(hostYIP);
                    cachedHostYConnection = hostConnection;
                    message = "component:CPCC;name:CallAccept;routerX:" + routerData.Item1 + ";routerY:" + routerData.Item2 + ";speed:" + data["speed"];
                    hostConnection.SendMessage(message);
                    GUIWindow.PrintLog("NCC: Sent CallAccept(" + routerData.Item1 + ", " + routerData.Item2 + ", " + data["speed"] + " Gb/s) to other NCC");
                    break;

                case "CallCoordinationResponse":
                    if (!Convert.ToBoolean(data["succeeded"]))
                    {
                        GUIWindow.PrintLog("NCC: Received CallRequestResponse(DENIED) from other NCC");
                        RefuseConnection(lastCaller);
                    }
                    else
                    {
                        GUIWindow.PrintLog("NCC: Received CallRequestResponse(ACCEPTED) from other NCC");
                        ConnectionRequest(lastIDC);
                        //message = "component:CPCC;name:CallRequestResponse;succeeded:true;connectionID:0"; //hard-kodowane connID na razie
                        //lastCaller.SendMessage(message);
                    }
                    break;

                case "CallAcceptResponse":
                    string status = "ACCEPTED";
                    if (lastIDC)
                    {
                        if (!Convert.ToBoolean(data["succeeded"]))
                        {
                            message = "component:NCC;name:CallCoordinationResponse;succeeded:false";
                            status  = "DENIED";
                        }
                        else
                        {
                            message = "component:NCC;name:CallCoordinationResponse;succeeded:true";
                        }
                        Program.peerConnection.SendMessage(message);
                        GUIWindow.PrintLog("NCC: Sent CallCoordinationResponse(" + status + ") to other NCC");
                    }
                    else
                    {
                        if (!Convert.ToBoolean(data["succeeded"]))
                        {
                            GUIWindow.PrintLog("NCC: Received CallAcceptResponse(DENIED) from CPCC");
                            RefuseConnection(lastCaller);
                        }
                        else
                        {
                            GUIWindow.PrintLog("NCC: Received CallAcceptResponse(ACCEPTED) from CPCC");
                            ConnectionRequest(lastIDC);
                        }
                    }
                    break;

                case "CallTeardownCPCC":
                    GUIWindow.PrintLog("NCC: Received CallTeardownCPCC(" + data["connectionID"] + ") from CPCC");

                    GUIWindow.PrintLog("NCC: Sent ConnectionRequest(" + data["connectionID"] + ") to CC");
                    message = "component:CC;name:ConnectionTeardown;connectionID:" + data["connectionID"];
                    Program.cc.HandleRequest(Util.DecodeRequest(message));
                    break;

                case "ConnectionTeardownResponse":
                    GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(" + data["connectionID"] + ") from CC : OK");

                    if (callRegister[Int32.Parse(data["connectionID"])].GetStartAsID() == ConfigLoader.ccID)
                    {
                        // Pierwszy AS
                        if (!callRegister[Int32.Parse(data["connectionID"])].GetInterDomainConnectionFlag())
                        {
                            //polaczenie wewnatrzdomenowe
                            GUIWindow.PrintLog("NCC: Sent CallTeardownCPCC(" + data["connectionID"] + ") to CPCC");
                            message = "component:CPCC;name:CallTeardownCPCC;connectionID:" + data["connectionID"];
                            callRegister[Int32.Parse(data["connectionID"])].GetTargetHostConnection().SendMessage(message);
                            break;
                        }
                        else
                        {
                            //polaczenie zewnatrzdomenowe
                            GUIWindow.PrintLog("NCC: Sent CallTeardownNCC(" + data["connectionID"] + ") to other AS NCC");
                            message = "component:NCC;name:CallTeardownNCC;connectionID:" + data["connectionID"];
                            Program.peerConnection.SendMessage(message);
                        }
                    }
                    else
                    {
                        // Drugi AS
                        GUIWindow.PrintLog("NCC: Sent CallTeardownNCCResponse(" + data["connectionID"] + ") to other AS NCC : OK");
                        message = "component:NCC;name:CallTeardownNCCResponse;connectionID:" + data["connectionID"];
                        Program.peerConnection.SendMessage(message);
                    }
                    break;

                case "CallTeardownNCC":
                    GUIWindow.PrintLog("NCC: Received CallTeardownNCC(" + data["connectionID"] + ") from other AS NCC");

                    GUIWindow.PrintLog("NCC: Sent CallTeardownCPCC(" + data["connectionID"] + ") to CPCC");
                    message = "component:CPCC;name:CallTeardownCPCC;connectionID:" + data["connectionID"];
                    callRegister[Int32.Parse(data["connectionID"])].GetTargetHostConnection().SendMessage(message);
                    break;

                case "CallTeardownCPCCResponse":
                    GUIWindow.PrintLog("NCC: Received CallTeardownCPCCResponse(" + data["connectionID"] + ") from CPCC: OK");
                    if (!callRegister[Int32.Parse(data["connectionID"])].GetInterDomainConnectionFlag())
                    {
                        //polaczenie wewnatrzdomenowe
                        GUIWindow.PrintLog("NCC: Sent CallTeardownCPCCResponse(" + data["connectionID"] + ") to CPCC : OK");
                        message = "component:CPCC;name:CallTeardownCPCCResponse;connectionID:" + data["connectionID"];
                        callRegister[Int32.Parse(data["connectionID"])].GetStartHostConnection().SendMessage(message);
                    }
                    else
                    {
                        //polaczenie zewnatrzdomenowe
                        GUIWindow.PrintLog("NCC: Sent ConnectionRequest(" + data["connectionID"] + ") to CC");
                        message = "component:CC;name:ConnectionTeardown;connectionID:" + data["connectionID"];
                        Program.cc.HandleRequest(Util.DecodeRequest(message));
                    }
                    break;

                case "CallTeardownNCCResponse":
                    GUIWindow.PrintLog("NCC: Received CallTeardownNCCResponse(" + data["connectionID"] + ") from other AS NCC : OK");
                    GUIWindow.PrintLog("NCC: Sent CallTeardownCPCCResponse(" + data["connectionID"] + ") to CPCC : OK");
                    message = "component:CPCC;name:CallTeardownCPCCResponse;connectionID:" + data["connectionID"];
                    callRegister[Int32.Parse(data["connectionID"])].GetStartHostConnection().SendMessage(message);
                    break;

                case "CallConfirmation":
                    if (!Convert.ToBoolean(data["succeeded"]))
                    {
                        GUIWindow.PrintLog("NCC: Received CallConfirmation(SUCCEEDED: false) from other NCC");
                        GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: false) to CPCC");
                        cachedHostYConnection.SendMessage("component:CPCC;name:CallConfirmation;IDC:" + data["IDC"] + ";succeeded:false");
                    }
                    else
                    {
                        GUIWindow.PrintLog("NCC: Received CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") from other NCC");
                        GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") to CPCC");
                        cachedHostYConnection.SendMessage("component:CPCC;name:CallConfirmation;IDC:" + data["IDC"] + ";succeeded:true;connID:" + data["connID"]);
                    }
                    break;

                case "CallConfirmationResponse":
                    switch (data["sender"])
                    {
                    case "CPCC":
                        GUIWindow.PrintLog("NCC: Received CallConfirmationResponse() from CPCC");
                        if (Convert.ToBoolean(data["IDC"]))
                        {
                            GUIWindow.PrintLog("NCC: Sent CallConfirmationResponse() to other NCC");
                            Program.peerConnection.SendMessage("component:NCC;name:CallConfirmationResponse;sender:NCC");
                        }
                        else
                        {
                            if (!cachedSuccess)
                            {
                                GUIWindow.PrintLog("NCC: Sent CallRequestResponse(SUCCEEDED: false) to CPCC");
                                lastCaller.SendMessage("component:CPCC;name:CallRequestResponse;succeeded:false");
                            }
                            else
                            {
                                GUIWindow.PrintLog("NCC: Sent CallRequestResponse(SUCCEEDED: true, connectionID: " + RC.currentConnectionID + ") to CPCC");
                                lastCaller.SendMessage("component:CPCC;name:CallRequestResponse;succeeded:true;connectionID:" + RC.currentConnectionID);
                            }
                        }
                        break;

                    case "NCC":
                        GUIWindow.PrintLog("NCC: Received CallConfirmationResponse() from other NCC");
                        if (!cachedSuccess)
                        {
                            GUIWindow.PrintLog("NCC: Sent CallRequestResponse(SUCCEEDED: false) to CPCC");
                            lastCaller.SendMessage("component:CPCC;name:CallRequestResponse;succeeded:false");
                        }
                        else
                        {
                            GUIWindow.PrintLog("NCC: Sent CallRequestResponse(SUCCEEDED: true, connectionID: " + RC.currentConnectionID + ") to CPCC");
                            lastCaller.SendMessage("component:CPCC;name:CallRequestResponse;succeeded:true;connectionID:" + RC.currentConnectionID);
                        }
                        break;
                    }
                    break;

                case "ConnectionRequestResponse":
                    cachedSuccess = Convert.ToBoolean(data["succeeded"]);
                    if (lastIDC)
                    {
                        if (!Convert.ToBoolean(data["succeeded"]))
                        {
                            GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(SUCCEEDED: false) from CC");
                            GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: false) to other NCC");
                            Program.peerConnection.SendMessage("component:NCC;name:CallConfirmation;IDC:true;succeeded:false");
                        }
                        else
                        {
                            GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(SUCCEEDED: true, connectionID: " + data["connID"] + ") from CC");
                            GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") to other NCC");
                            Program.peerConnection.SendMessage("component:NCC;name:CallConfirmation;IDC:true;succeeded:true;connID:" + data["connID"]);
                        }
                    }
                    else
                    {
                        if (!Convert.ToBoolean(data["succeeded"]))
                        {
                            GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(SUCCEEDED: false) from CC");
                            GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: false) to CPCC");
                            cachedHostYConnection.SendMessage("component:CPCC;name:CallConfirmation;succeeded:false;IDC:false");
                        }
                        else
                        {
                            GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(SUCCEEDED: true, connectionID: " + data["connID"] + ") from CC");
                            GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") to CPCC");
                            cachedHostYConnection.SendMessage("component:CPCC;name:CallConfirmation;succeeded:true;IDC:false;connID:" + data["connID"]);
                        }
                    }
                    break;
                }
            } catch (Exception e) {
                GUIWindow.PrintLog(e.Message);
                GUIWindow.PrintLog(e.StackTrace);
            }
        }
Beispiel #18
0
 private void HandlePolicy()
 {
     GUIWindow.PrintLog("NCC: Sent Policy() to CAC");
     GUIWindow.PrintLog("NCC: Received PolicyResponse(OK)");
 }
Beispiel #19
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);
        }
Beispiel #20
0
        public static void loadConfig(String config, String id)
        {
            ccID = Int32.Parse(id);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(config);

            int    nodeID;
            int    asID;
            String ip;
            int    port;
            bool   subnetworkRouter = false;
            //LinkedList<int> ports = new LinkedList<int>();

            XmlElement  root                   = doc.DocumentElement;
            XmlNodeList hostNodesList          = root.SelectNodes("/config/hosts/host");
            XmlNodeList routerNodesList        = root.SelectNodes("/config/routers/router");
            XmlNodeList connectionNodesList    = root.SelectNodes("/config/cloud/connections/connection");
            XmlNodeList controlCenterNodesList = root.SelectNodes("/config/control-centers/control-center");

            //HOSTS:
            LinkedList <Host> hosts = new LinkedList <Host>();
            //ROUTERS:
            LinkedList <Router> routers = new LinkedList <Router>();
            //CONNECTIONS:
            //LinkedList<Connection> connections = new LinkedList<Connection>();
            Dictionary <int, Connection> connections = new Dictionary <int, Connection>();

            foreach (XmlNode n in controlCenterNodesList)
            {
                if (Int32.Parse(n.Attributes["id"].Value) == ccID)
                {
                    ccListeningPort = Int32.Parse(n.Attributes["listening-port"].Value);
                    break;
                }
            }

            //routery
            foreach (XmlNode node in routerNodesList)
            {
                nodeID           = Int32.Parse(node.Attributes["id"].Value);
                asID             = Int32.Parse(node.Attributes["as-id"].Value);
                ip               = node.SelectSingleNode("router-ip").InnerText;
                subnetworkRouter = Boolean.Parse(node.Attributes["subnetwork-router"].Value);

                LinkedList <int> ports           = new LinkedList <int>();
                XmlNodeList      routerPortsList = node.SelectNodes("router-ports/router-port");
                foreach (XmlNode portNode in routerPortsList)
                {
                    ports.AddLast(Int32.Parse(portNode.InnerText));
                }
                routers.AddLast(new Router(nodeID, ip, asID, ports, subnetworkRouter));
            }

            //hosty
            foreach (XmlNode node in hostNodesList)
            {
                nodeID = Int32.Parse(node.Attributes["id"].Value);
                asID   = Int32.Parse(node.Attributes["as-id"].Value);
                ip     = node.SelectSingleNode("host-ip").InnerText;
                port   = Int32.Parse(node.SelectSingleNode("host-port").InnerText);

                Router neighbor = null;
                foreach (Router r in routers)
                {
                    if (r.GetRouterID() == Int32.Parse(node.Attributes["router-id"].Value))
                    {
                        neighbor = r;
                        break;
                    }
                }

                hosts.AddLast(new Host(nodeID, ip, asID, port, neighbor));
            }

            //polaczenia
            foreach (XmlNode node in connectionNodesList)
            {
                nodeID = 0;
                asID   = 0;
                int portA = 0;
                int portB = 0;

                nodeID = Int32.Parse(node.Attributes["id"].Value);
                String connectionType = node.Attributes["type"].Value;
                int    distance       = Int32.Parse(node.Attributes["distance"].Value);
                double maxBandwidth   = Double.Parse(node.Attributes["max-bandwidth"].Value);
                bool   external       = Boolean.Parse(node.Attributes["external"].Value);
                asID = Int32.Parse(node.Attributes["as-id"].Value);

                XmlNodeList childNodes;
                childNodes = node.SelectNodes("endpoint");
                if (connectionType.Equals("host-router"))
                {
                    Host   host   = null;
                    Router router = null;

                    foreach (XmlNode childNode in childNodes)
                    {
                        int ID = Int32.Parse(childNode.Attributes["id"].Value);
                        if (childNode.Attributes["type"].Value.Equals("host"))
                        {
                            foreach (Host searchHost in hosts)
                            {
                                if (searchHost.GetHostID() == ID)
                                {
                                    host  = searchHost;
                                    portA = 100;
                                }
                            }
                        }
                        if (childNode.Attributes["type"].Value.Equals("router"))
                        {
                            foreach (Router searchRouter in routers)
                            {
                                if (searchRouter.GetRouterID() == ID)
                                {
                                    router = searchRouter;
                                    portB  = Int32.Parse(childNode.Attributes["port"].Value);
                                }
                            }
                        }
                    }
                    if (router != null && host != null)
                    {
                        //connections.AddLast(new Connection(nodeID, host, router, distance, maxBandwidth, external, asID));
                        connections.Add(nodeID, new Connection(nodeID, host, router, distance, maxBandwidth, external, asID, new Tuple <int, int>(portA, portB)));
                    }
                }
                else if (connectionType.Equals("router-router"))
                {
                    Router a = null, b = null;

                    foreach (XmlNode childNode in childNodes)
                    {
                        int ID = Int32.Parse(childNode.Attributes["id"].Value);

                        foreach (Router searchRouter in routers)
                        {
                            if (searchRouter.GetRouterID() == ID)
                            {
                                if (a == null)
                                {
                                    a     = searchRouter;
                                    portA = Int32.Parse(childNode.Attributes["port"].Value);
                                }
                                else
                                {
                                    b     = searchRouter;
                                    portB = Int32.Parse(childNode.Attributes["port"].Value);
                                }
                            }
                        }
                    }
                    if (a != null && b != null)
                    {
                        connections.Add(nodeID, new Connection(nodeID, a, b, distance, maxBandwidth, external, asID, new Tuple <int, int>(portA, portB)));
                    }
                }
            }
            ConfigLoader.hosts       = hosts;
            ConfigLoader.routers     = routers;
            ConfigLoader.connections = connections;
            GUIWindow.ChangeWindowName("ControlCenter" + ccID);

            sortItems();

            //foreach (Connection edge in myConnections.Values) {
            //    GUIWindow.PrintLog(edge.GetID().ToString());
            //}
        }
 public void RemoveHostConnection(HostConnection hostConnection)
 {
     GUIWindow.PrintLog("Host #" + hostConnection.GetID() + " has disconnected");
     hostConnections.Remove(hostConnection);
 }
Beispiel #22
0
        public static List <Path> AllPaths(Host sender, Host receiver)
        {
            if (sender == null || receiver == null)
            {
                GUIWindow.PrintLog("One or both host IDs do not exist!");
                return(null);
            }

            Graph  graph         = new Graph(ConfigLoader.routers.Count + 1);
            Router initialRouter = null;
            Router finalRouter   = null;

            int i = 0;

            foreach (Connection edge in ConfigLoader.connections.Values)
            {
                Node n1 = edge.endPoints.Item1;
                Node n2 = edge.endPoints.Item2;
                if (!n1.working || !n2.working)
                {
                    continue;
                }

                if (n1 is Router && n2 is Router)
                {
                    graph.addEdge(n1.GetRouterID(), n2.GetRouterID());
                    graph.addEdge(n2.GetRouterID(), n1.GetRouterID());
                }
                else if (n1 is Router && n2 is Host)
                {
                    if ((Host)n2 == sender)
                    {
                        initialRouter = (Router)n1;
                    }
                    else if ((Host)n2 == receiver)
                    {
                        finalRouter = (Router)n1;
                    }
                }
                else if (n1 is Host && n2 is Router)
                {
                    if ((Host)n1 == sender)
                    {
                        initialRouter = (Router)n2;
                    }
                    else if ((Host)n1 == receiver)
                    {
                        finalRouter = (Router)n2;
                    }
                }
            }

            if (initialRouter == null || finalRouter == null)
            {
                GUIWindow.PrintLog("Could not calculate shortest paths (either the IDs are incorrect or graph was incorrectly configured)!");
                return(null);
            }

            //Console.WriteLine("Paths between " + initialRouter.GetRouterID() + " and " + finalRouter.GetRouterID());
            graph.printAllPaths(initialRouter.GetRouterID(), finalRouter.GetRouterID());
            List <List <int> > allPathsNodes = graph.allPaths;

            List <Path> allPaths = new List <Path>();

            foreach (List <int> path in allPathsNodes)
            {
                allPaths.Add(new Path(path, sender, receiver));
            }

            allPaths.Sort();

            return(allPaths);
        }
Beispiel #23
0
        public void HandleRequest(Dictionary <string, string> data)
        {
            switch (data["name"])
            {
            case "ConnectionRequest":
                switch (data["layer"])
                {
                case "upper":
                    GUIWindow.PrintLog("CC: Received ConnectionRequest(" + data["routerX"] + ", " + data["routerY"] + ", " + data["speed"] + " Gb/s, InterDomainConnection: " + data["IDC"] + ") from NCC");

                    string networkCase = ConfigLoader.ccID == 3 ? "SN" : "FirstAS";
                    string message420  = "component:RC;name:RouteTableQuery;routerX:" + data["routerX"] + ";routerY:" + data["routerY"] + ";speed:" + data["speed"] + ";IDC:" + data["IDC"] + ";case:" + networkCase;
                    GUIWindow.PrintLog("CC: Sent RouteTableQuery(" + data["routerX"] + ", " + data["routerY"] + ", " + data["speed"] + " Gb/s, InterDomainConnection: " + data["IDC"] + ") to RC");
                    Program.rc.HandleRequest(Util.DecodeRequest(message420));
                    break;

                case "lower":
                    GUIWindow.PrintLog("CC: Received ConnectionRequest(routerX: " + data["routerX"] + ", routerY: " + data["routerY"] + ", path:" + data["path"] + ") from parent CC");
                    List <int> routerID2 = new List <int>();
                    foreach (string id in data["path"].Split('-'))
                    {
                        routerID2.Add(Convert.ToInt32(id));
                    }
                    Host hostX2 = ConfigLoader.FindHostAmongAll(Convert.ToInt32(data["endPoint1"]));
                    Host hostY2 = ConfigLoader.FindHostAmongAll(Convert.ToInt32(data["endPoint2"]));
                    cachedPath = new Path(routerID2, hostX2, hostY2);
                    cachedPath.channelRange = data["channelRange"];
                    Tuple <HostConnection, HostConnection> connections2 = GetHostConnections(cachedPath);
                    Call call2 = new Call(Convert.ToInt32(data["connID"]), true, (ConfigLoader.ccID == 1 ? 2 : 1), cachedPath.throughSN, connections2.Item1, connections2.Item2, cachedPath);
                    NCC.callRegister.Add(Convert.ToInt32(data["connID"]), call2);

                    //GUIWindow.PrintLog("CC: Sent SendConnectionTables(" + data["path"] + ", " + data["connID"] + ") to RC");
                    Program.rc.HandleRequest(Util.DecodeRequest("name:SendConnectionTables;connID:" + data["connID"] + ";path:" + data["path"]));
                    break;
                }
                break;

            case "ConnectionRequestResponse":
                GUIWindow.PrintLog("CC: Received ConnectionRequestResponse() from child CC");
                if (cachedScenario == 1)
                {
                    //scenariusz 1
                    GUIWindow.PrintLog("CC: Sent PeerCoordinationResponse() to peer CC");
                    Program.peerConnection.SendMessage("component:CC;name:PeerCoordinationResponse");
                }
                else
                {
                    //scenariusz 2
                    var decoded = Util.DecodeRequest(cachedMessage);
                    GUIWindow.PrintLog("CC: Sent PeerCoordination(routerX: " + decoded["routerX"] + ", routerY: " + decoded["routerY"] + ", path:" + decoded["path"] + ") to peer CC");
                    Program.peerConnection.SendMessage(cachedMessage);
                }
                break;

            case "RouteTableQueryResponse":
                //GUIWindow.PrintLog("Received RouteTableQueryResponse(" + data["path"] + ") from RC");
                if (data["path"].Equals("null"))
                {
                    GUIWindow.PrintLog("CC: Requested connection could not be established");
                    string message1 = "component:CC;name:ConnectionRequestResponse;succeeded:false";
                    GUIWindow.PrintLog("CC: Sent ConnectionRequestResponse(SUCCEEDED: false) to NCC");
                    Program.ncc.HandleRequest(Util.DecodeRequest(message1), null);
                    break;
                }

                //tutaj wysyłamy LRMom request o alokacje, potem PeerCoordination jeśli to połączenie IDC
                bool throughSN = ConfigLoader.ccID == 1 ? false : RC.currentPath.throughSN;
                Tuple <HostConnection, HostConnection> connections = GetHostConnections(RC.currentPath);
                Call call = new Call(RC.currentConnectionID, Convert.ToBoolean(RC.cachedData["IDC"]), ConfigLoader.ccID, throughSN, connections.Item1, connections.Item2, RC.currentPath);
                NCC.callRegister.Add(RC.currentConnectionID, call);

                //GUIWindow.PrintLog("CC: Sent LinkConnectionRequest(" + RC.cachedData["channelRange"] + ") to internal LRM");
                string message2 = "name:LinkConnectionRequest;type:internal;channelRange:" + RC.cachedData["channelRange"] + ";asType:first";
                Program.lrm.HandleRequest(Util.DecodeRequest(message2));

                break;

            case "LinkConnectionRequestResponse":
                switch (data["type"])
                {
                case "internal":
                    //GUIWindow.PrintLog("CC: Received LinkConnectionRequestResponse() from internal LRM");

                    if (data["asType"].Equals("second"))
                    {
                        if (cachedPath.throughSN && ConfigLoader.ccID == 2)
                        {
                            //tu jeszcze external LinkConnectionRequest
                            string message3 = "name:LinkConnectionRequest;type:external;respond:false;channelRange:" + cachedPath.channelRange;
                            Program.lrm.HandleRequest(Util.DecodeRequest(message3));
                            GUIWindow.PrintLog("External LRM: Sent LinkConnectionRequestResponse() to CC");
                            GUIWindow.PrintLog("CC: Received LinkConnectionRequestResponse() from External LRM");

                            var decoded = Util.DecodeRequest(cachedMessage);
                            cachedScenario = 1;
                            GUIWindow.PrintLog("CC: Sent ConnectionRequest(routerX: " + decoded["routerX"] + ", routerY: " + decoded["routerY"] + ", path:" + decoded["path"] + ") to child CC");
                            Program.parentConnection.SendMessage(cachedMessage);
                        }
                        else
                        {
                            //zwrotka do peera
                            GUIWindow.PrintLog("CC: Sent PeerCoordinationResponse() to peer CC");
                            Program.peerConnection.SendMessage("component:CC;name:PeerCoordinationResponse");
                        }
                        break;
                    }
                    else if (data["asType"].Equals("SN"))
                    {
                        //zwrotka do parent CC
                        GUIWindow.PrintLog("CC: Sent ConnectionRequestResponse() to parent CC");
                        Program.childConnection.SendMessage("component:CC;name:ConnectionRequestResponse");
                        break;
                    }


                    if (Convert.ToBoolean(RC.cachedData["IDC"]))
                    {
                        GUIWindow.PrintLog("CC: Sent LinkConnectionRequest(" + RC.cachedData["channelRange"] + ") to extrenal LRM");
                        string message3 = "name:LinkConnectionRequest;type:external;respond:true;channelRange:" + RC.cachedData["channelRange"];
                        Program.lrm.HandleRequest(Util.DecodeRequest(message3));
                    }
                    else
                    {
                        //connectionRequestResponse
                        string message1 = "component:CC;name:ConnectionRequestResponse;succeeded:true;connID:" + RC.currentConnectionID;
                        GUIWindow.PrintLog("CC: Sent ConnectionRequestResponse(SUCCEEDED: true, connectionID: " + RC.currentConnectionID + ") to NCC");
                        Program.ncc.HandleRequest(Util.DecodeRequest(message1), null);
                    }
                    break;

                case "external":
                    GUIWindow.PrintLog("CC: Received LinkConnectionRequestResponse() from external LRM");

                    try {
                        string listOfRouters = "";
                        foreach (int router in RC.currentPath.routerIDs)
                        {
                            listOfRouters += router + "-";
                        }
                        listOfRouters = listOfRouters.Remove(listOfRouters.Length - 1, 1);

                        string message4 = "component:CC;name:PeerCoordination;connID:" + RC.currentConnectionID + ";routerX:" + RC.cachedData["routerX"] + ";routerY:" + RC.cachedData["routerY"]
                                          + ";routerIDs:" + listOfRouters + ";endPoint1:" + RC.currentPath.endPoints.Item1.GetHostID() + ";" + "endPoint2:" + RC.currentPath.endPoints.Item2.GetHostID()
                                          + ";path:" + listOfRouters + ";channelRange:" + RC.cachedData["channelRange"];

                        if (ConfigLoader.ccID == 1)
                        {
                            //robimy PeerCoordination
                            GUIWindow.PrintLog("CC: Sent PeerCoordination(routerX: " + RC.cachedData["routerX"] + ", routerY: " + RC.cachedData["routerY"] + ", path:" + listOfRouters + ") to peer CC");
                            Program.peerConnection.SendMessage(message4);
                        }
                        else if (ConfigLoader.ccID == 2)
                        {
                            cachedScenario = 2;
                            cachedMessage  = message4;
                            GUIWindow.PrintLog("CC: Sent ConnectionRequest(routerX: " + RC.cachedData["routerX"] + ", routerY: " + RC.cachedData["routerY"] + ", path:" + listOfRouters + ") to child CC");
                            Program.parentConnection.SendMessage(message4 + ";layer:lower;actualName:ConnectionRequest");
                        }
                    }
                    catch (Exception e) {
                        GUIWindow.PrintLog(e.Message);
                        GUIWindow.PrintLog(e.StackTrace);
                    }
                    break;
                }
                break;

            case "PeerCoordination":
                try {
                    GUIWindow.PrintLog("CC: Received " + data["actualName"] + "(routerX: " + data["routerX"] + ", routerY: " + data["routerY"] + ", path:" + data["path"] + ") from parent CC");
                } catch (Exception) {
                    GUIWindow.PrintLog("CC: Received PeerCoordination(routerX: " + data["routerX"] + ", routerY: " + data["routerY"] + ", path:" + data["path"] + ") from peer CC");
                }
                List <int> routerID = new List <int>();
                foreach (string id in data["path"].Split('-'))
                {
                    routerID.Add(Convert.ToInt32(id));
                }
                Host hostX = ConfigLoader.FindHostAmongAll(Convert.ToInt32(data["endPoint1"]));
                Host hostY = ConfigLoader.FindHostAmongAll(Convert.ToInt32(data["endPoint2"]));
                cachedPath = new Path(routerID, hostX, hostY);
                cachedPath.channelRange = data["channelRange"];
                Tuple <HostConnection, HostConnection> connections1 = GetHostConnections(cachedPath);
                //GUIWindow.PrintLog(connections1.Item1.ToString());
                //GUIWindow.PrintLog(connections1.Item2.GetID().ToString());
                Call call1 = new Call(Convert.ToInt32(data["connID"]), true, (ConfigLoader.ccID == 1 ? 2 : 1), cachedPath.throughSN, connections1.Item1, connections1.Item2, cachedPath);
                NCC.callRegister.Add(Convert.ToInt32(data["connID"]), call1);

                cachedMessage = "component:CC;name:ConnectionRequest;layer:lower;connID:" + data["connID"] + ";routerX:" + data["routerX"] + ";routerY:" + data["routerY"]
                                + ";routerIDs:" + data["routerIDs"] + ";endPoint1:" + data["endPoint1"] + ";" + "endPoint2:" + data["endPoint2"] + ";path:"
                                + data["path"] + ";channelRange:" + data["channelRange"];

                //GUIWindow.PrintLog("CC: Sent SendConnectionTables(" + data["path"] + ", " + data["connID"] + ") to RC");
                Program.rc.HandleRequest(Util.DecodeRequest("name:SendConnectionTables;connID:" + data["connID"] + ";path:" + data["path"]));

                break;

            case "PeerCoordinationResponse":
                GUIWindow.PrintLog("CC: Received PeerCoordinationResponse() from peer CC");
                GUIWindow.PrintLog("CC: Sent ConnectionRequestResponse() to NCC");
                Program.ncc.HandleRequest(Util.DecodeRequest("name:ConnectionRequestResponse;succeeded:true;connID:" + RC.currentConnectionID), null);
                break;

            case "SendConnectionTablesResponse":
                //GUIWindow.PrintLog("CC: Received SendConnectionTablesResponse() from RC");
                try {
                    //GUIWindow.PrintLog("CC: Sent LinkConnectionRequest(" + cachedPath.channelRange + ") to internal LRM");
                    string message22 = "name:LinkConnectionRequest;type:internal;channelRange:" + cachedPath.channelRange + ";asType:" + (ConfigLoader.ccID == 3 ? "SN" : "second");
                    Program.lrm.HandleRequest(Util.DecodeRequest(message22));
                } catch (Exception e) {
                    GUIWindow.PrintLog(e.Message);
                    GUIWindow.PrintLog(e.StackTrace);
                }

                break;

            case "ConnectionTeardown":


                if (ConfigLoader.ccID == 3)
                {
                    //CHILD
                    GUIWindow.PrintLog("CC: Received ConnectionRequest(" + data["connectionID"] + ") from Parent CC");
                    Path path = NCC.callRegister[Int32.Parse(data["connectionID"])].GetPath();

                    //GUIWindow.PrintLog("CC: Sent SendConnectionTables(" + data["connectionID"] + ", " + path.ToString() + ", disconnect) to RC");
                    //GUIWindow.PrintLog("RC: Received SendConnectionTables(" + data["connectionID"] + ", " + path.ToString() + ", disconnect) from CC");

                    Program.rc.UpdateRoutingTables(path, Int32.Parse(data["connectionID"]), false, true);
                    //Program.rc.UpdateRoutingTables(path, Int32.Parse(data["connectionID"]), true, true);

                    //GUIWindow.PrintLog("RC: Sent SendConnectionTablesResponse() to CC : OK");
                    //GUIWindow.PrintLog("CC: Received SendConnectionTablesResponse() from RC : OK");
                    //GUIWindow.PrintLog("CC: Sent LinkConnectionInternalDeallocation(" + data["connectionID"] + ") to Internal LRM");
                    string message1 = "component:LRM;name:LinkConnectionInternalDeallocation;connectionID:" + data["connectionID"];
                    Program.lrm.HandleRequest(Util.DecodeRequest(message1));
                }
                else
                {
                    GUIWindow.PrintLog("CC: Received ConnectionRequest(" + data["connectionID"] + ") from NCC");     // InterDomainConnection: " + data["IDC"]
                    Path path = NCC.callRegister[Int32.Parse(data["connectionID"])].GetPath();

                    //GUIWindow.PrintLog("CC: Sent SendConnectionTables(" + data["connectionID"] + ", " + path.ToString() + ", disconnect) to RC");
                    //GUIWindow.PrintLog("RC: Received SendConnectionTables(" + data["connectionID"] + ", " + path.ToString() + ", disconnect) from CC");

                    Program.rc.UpdateRoutingTables(path, Int32.Parse(data["connectionID"]), false, true);
                    //Program.rc.UpdateRoutingTables(path, Int32.Parse(data["connectionID"]), true, true);

                    //GUIWindow.PrintLog("RC: Sent SendConnectionTablesResponse() to CC : OK");
                    //GUIWindow.PrintLog("CC: Received SendConnectionTablesResponse() from RC : OK");
                    var  element = NCC.callRegister[Int32.Parse(data["connectionID"])];
                    bool interDomainConnectionFlag = element.GetInterDomainConnectionFlag();
                    int  asID = element.GetStartAsID();

                    if (interDomainConnectionFlag && asID == ConfigLoader.ccID)
                    {
                        GUIWindow.PrintLog("CC: Sent LinkConnectionExternalDeallocation(" + data["connectionID"] + ") to External LRM");
                        string message3 = "component:LRM;name:LinkConnectionExternalDeallocation;connectionID:" + data["connectionID"] + ";deleteChannels:true";
                        Program.lrm.HandleRequest(Util.DecodeRequest(message3));
                    }
                    else if (!interDomainConnectionFlag)
                    {
                        //GUIWindow.PrintLog("CC: Sent LinkConnectionInternalDeallocation(" + data["connectionID"] + ") to Internal LRM");
                        string message3 = "component:LRM;name:LinkConnectionInternalDeallocation;connectionID:" + data["connectionID"];
                        Program.lrm.HandleRequest(Util.DecodeRequest(message3));
                    }
                    else
                    {
                        GUIWindow.PrintLog("CC: Sent LinkConnectionExternalDeallocation(" + data["connectionID"] + ") to External LRM");
                        string message3 = "component:LRM;name:LinkConnectionExternalDeallocation;connectionID:" + data["connectionID"] + ";deleteChannels:false";
                        Program.lrm.HandleRequest(Util.DecodeRequest(message3));
                    }
                }
                break;

            case "LinkConnectionExternalDeallocationResponse":
                GUIWindow.PrintLog("CC: Received LinkConnectionExternalDeallocation(" + data["connectionID"] + ") from External LRM : OK");
                //GUIWindow.PrintLog("CC: Sent LinkConnectionInternalDeallocation(" + data["connectionID"] + ") to Internal LRM");
                string message = "component:LRM;name:LinkConnectionInternalDeallocation;connectionID:" + data["connectionID"];
                Program.lrm.HandleRequest(Util.DecodeRequest(message));
                break;

            case "LinkConnectionInternalDeallocationResponse":
                //GUIWindow.PrintLog("CC: Received LinkConnectionInternalDeallocationResponse(" + data["connectionID"] + ") from Internal LRM : OK");

                if (NCC.callRegister[Int32.Parse(data["connectionID"])].GetThroughSubnetwork() && ConfigLoader.ccID == 2)
                {
                    // PARENT
                    GUIWindow.PrintLog("CC: Sent ConnectionRequest(" + data["connectionID"] + ") to Child CC");
                    message = "component:CC;name:ConnectionTeardown;connectionID:" + data["connectionID"];
                    Program.parentConnection.SendMessage(message);
                }
                else if (ConfigLoader.ccID == 3)
                {
                    // CHILD
                    GUIWindow.PrintLog("CC: Sent ConnectionRequestResponse(" + data["connectionID"] + ") to Parent CC : OK");
                    message = "component:CC;name:ConnectionTeardownResponse;connectionID:" + data["connectionID"];
                    Program.childConnection.SendMessage(message);
                }
                else
                {
                    GUIWindow.PrintLog("CC: Sent ConnectionRequestResponse(" + data["connectionID"] + ") to NCC : OK");
                    message = "component:NCC;name:ConnectionTeardownResponse;connectionID:" + data["connectionID"];
                    Program.ncc.HandleRequest(Util.DecodeRequest(message), null);
                }
                break;

            case "ConnectionTeardownResponse":
                //Odpowiedz od CHILD
                GUIWindow.PrintLog("CC: Received ConnectionRequestResponse(" + data["connectionID"] + ") from Child CC : OK");
                GUIWindow.PrintLog("CC: Sent ConnectionRequestResponse(" + data["connectionID"] + ") to NCC : OK");
                message = "component:NCC;name:ConnectionTeardownResponse;connectionID:" + data["connectionID"];
                Program.ncc.HandleRequest(Util.DecodeRequest(message), null);
                break;
            }
        }
Beispiel #24
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));
        }