public void LoadConfig(string config) { XmlDocument doc = new XmlDocument(); doc.LoadXml(config); //GUIWindow.PrintLog(mode); 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 hostDestinationsNodeList = root.SelectNodes("/config/management-center/hosts-config/host-possible-destinations"); XmlNodeList routerMPLSTableNodeList = root.SelectNodes("/config/management-center/router-config/router-mpls-table"); //hosty foreach (XmlNode node in hostNodesList) { XmlAttribute attribute = node.Attributes["id"]; int id = Int32.Parse(attribute.Value); String ip = node.SelectSingleNode("host-ip").InnerText; int port = Int32.Parse(node.SelectSingleNode("host-port").InnerText); hosts.AddLast(new Host(id, ip, port)); } //routery foreach (XmlNode node in routerNodesList) { XmlAttribute attribute = node.Attributes["id"]; int id = Int32.Parse(attribute.Value); String ip = node.SelectSingleNode("router-ip").InnerText; XmlNodeList portsNodeList = node.SelectNodes("router-ports/router-port"); LinkedList <int> portsList = new LinkedList <int>(); foreach (XmlNode currentNode in portsNodeList) { portsList.AddLast(Int32.Parse(currentNode.InnerText)); } XmlNodeList assignedHostNodeList = node.SelectNodes("assigned-hosts/assigned-host"); LinkedList <Host> routerHosts = new LinkedList <Host>(); foreach (XmlNode currentNode in assignedHostNodeList) { int assignedId = Int32.Parse(currentNode.Attributes["id"].Value); foreach (Host host in hosts) { if (host.GetHostID() == assignedId) { routerHosts.AddLast(host); } } } routers.AddLast(new Router(id, ip, portsList, routerHosts)); } //polaczenia foreach (XmlNode node in connectionNodesList) { int id = Int32.Parse(node.Attributes["id"].Value); String connectionType = node.Attributes["type"].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; } } } if (childNode.Attributes["type"].Value.Equals("router")) { foreach (Router searchRouter in routers) { if (searchRouter.GetRouterID() == ID) { router = searchRouter; } } } } if (router != null && host != null) { connections.AddLast(new Connection(id, host, router)); } } 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; } else { b = searchRouter; } } } } if (a != null && b != null) { connections.AddLast(new Connection(id, a, b)); } } } //dostepne hosty i ich etykiety foreach (XmlNode hdests in hostDestinationsNodeList) { XmlNodeList dests = hdests.SelectNodes("host-possible-destination"); foreach (XmlNode n in dests) { int id = int.Parse(n.Attributes["id"].Value); int destHostID = int.Parse(n.Attributes["destination-host-id"].Value); int label = int.Parse(n.Attributes["label"].Value); hostPossibleDestinations.Add(new Tuple <int, Tuple <int, int, int> >(int.Parse(hdests.Attributes["host-id"].Value), new Tuple <int, int, int>(id, destHostID, label))); } } //tablice mpls dla routerow //foreach (XmlNode mplsTableNode in routerMPLSTableNodeList) { // int routerID = int.Parse(mplsTableNode.Attributes["router-id"].Value); // XmlNodeList mplsTableRows = mplsTableNode.SelectNodes("router-mpls-row"); // foreach (XmlNode mplsRow in mplsTableRows) { // int rowID = int.Parse(mplsRow.Attributes["row-id"].Value); // int inputPort = int.Parse(mplsRow.Attributes["input-port"].Value); // int inputLabel = int.Parse(mplsRow.Attributes["input-label"].Value); // string action = mplsRow.Attributes["action"].Value; // int outputPort = int.Parse(mplsRow.Attributes["output-port"].Value); // int outputLabel = int.Parse(mplsRow.Attributes["output-label"].Value); // int nextActionRowID = int.Parse(mplsRow.Attributes["next-action-row-id"].Value); // int layer = int.Parse(mplsRow.Attributes["layer"].Value); // var row = Tuple.Create(rowID, inputPort, inputLabel, action, outputPort, outputLabel, nextActionRowID, layer); // routerMPLSTables.Add(new Tuple<int, Tuple<int, int, int, string, int, int, int, Tuple<int>>>(routerID, row)); // } //} this.copyNodes(); GUIWindow.PrintLog("Config Loaded"); }
public void HandleRequest(Dictionary <string, string> data) { switch (data["name"]) { case "LinkConnectionExternalDeallocation": GUIWindow.PrintLog("External LRM: Received LinkConnectionExternalDeallocation(" + data["connectionID"] + ") from CC"); String routerIP = null; if (ConfigLoader.ccID == 1) { routerIP = "10.0.3.1"; } else if (ConfigLoader.ccID == 2) { routerIP = "10.0.10.1"; } GUIWindow.PrintLog("External LRM: Sent SNPRelase(" + routerIP + ", " + data["connectionID"] + ") to other AS LRM"); string message = "component:LRM;name:SNPRelase;routerX:" + routerIP + ";connectionID:" + data["connectionID"] + ";deleteChannels:" + data["deleteChannels"]; Program.peerConnection.SendMessage(message); break; case "SNPRelase": GUIWindow.PrintLog("External LRM: Received SNPRelase(" + data["routerX"] + ", " + data["connectionID"] + ") from other AS LRM"); GUIWindow.PrintLog("External LRM: Sent SNPRelaseResponse(" + data["routerX"] + ", " + data["connectionID"] + ") from other AS LRM : OK"); message = "component:LRM;name:SNPRelaseResponse;routerX:" + data["routerX"] + ";connectionID:" + data["connectionID"] + ";deleteChannels:" + data["deleteChannels"];; Program.peerConnection.SendMessage(message); break; case "SNPRelaseResponse": GUIWindow.PrintLog("External LRM: Received SNPRelaseResponse(" + data["routerX"] + ", " + data["connectionID"] + ") from other AS LRM : OK"); // =================================================================== //Dealokacja miedzy AS //Tutaj musi byc wyslane Local Topology do RC ale nie wiem z czym ?? Connection extConnection = ConfigLoader.connections[8]; if (data["deleteChannels"].Equals("true")) { for (int i = 0; i < extConnection.slot.Length; i++) { if (extConnection.slot[i] == Int32.Parse(data["connectionID"])) { extConnection.slot[i] = 0; } } GUIWindow.UpdateChannelTable(); } GUIWindow.PrintLog("External LRM: Sent LocalTopology(" + 8 + ": " + String.Join("", extConnection.slot) + ") to RC : DEALLOCATED"); GUIWindow.PrintLog("RC: Received LocalTopology(" + 8 + ": " + String.Join("", extConnection.slot) + ") from External LRM : DEALLOCATED"); GUIWindow.PrintLog("RC: Sent LocalTopologyResponse() to External LRM : OK"); GUIWindow.PrintLog("External LRM: Received LocalTopologyResponse() from RC : OK"); // =================================================================== GUIWindow.PrintLog("External LRM: Sent LinkConnectionExternalDeallocationResponse(" + data["connectionID"] + ") to CC : OK"); message = "component:CC;name:LinkConnectionExternalDeallocationResponse;connectionID:" + data["connectionID"]; Program.cc.HandleRequest(Util.DecodeRequest(message)); break; case "LinkConnectionInternalDeallocation": // =================================================================== //Dealokacja lokalna //Tutaj musi byc wyslane Local Topology do RC ale nie wiem z czym ?? foreach (Connection connection in NCC.callRegister[Int32.Parse(data["connectionID"])].GetPath().edges) { if (connection.GetAsID() != ConfigLoader.ccID) { continue; } for (int i = 0; i < connection.slot.Length; i++) { if (connection.slot[i] == Int32.Parse(data["connectionID"])) { connection.slot[i] = 0; } } GUIWindow.PrintLog("CC: Sent LinkConnectionInternalDeallocation(" + connection.GetID() + ", " + data["connectionID"] + ") to Internal LRM"); GUIWindow.PrintLog("Internal LRM: Received LinkConnectionInternalDeallocation(" + data["connectionID"] + ") 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 LinkConnectionInternalDeallocationResponse(" + data["connectionID"] + ") to CC : OK"); GUIWindow.PrintLog("CC: Received LinkConnectionInternalDeallocationResponse(" + data["connectionID"] + ") from Internal LRM : OK"); } GUIWindow.UpdateChannelTable(); // =================================================================== message = "component:CC;name:LinkConnectionInternalDeallocationResponse;connectionID:" + data["connectionID"]; Program.cc.HandleRequest(Util.DecodeRequest(message)); break; case "LinkConnectionRequest": switch (data["type"]) { case "internal": string[] range = data["channelRange"].Split('-'); foreach (Connection connection in (RC.currentPath == null ? Program.cc.cachedPath.edges : RC.currentPath.edges)) { if (!ConfigLoader.myConnections.ContainsValue(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() + ", " + data["channelRange"] + ") to internal LRM"); GUIWindow.PrintLog("Internal LRM: Received LinkConnectionRequest(" + connection.GetID() + ", " + data["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(); Program.cc.HandleRequest(Util.DecodeRequest("name:LinkConnectionRequestResponse;type:internal;asType:" + data["asType"])); break; case "external": GUIWindow.PrintLog("Extrenal LRM: Received LinkConnectionRequest(" + data["channelRange"] + ") from CC"); string[] range2 = data["channelRange"].Split('-'); extConnection = ConfigLoader.connections[8]; for (int i = Convert.ToInt32(range2[0]); i <= Convert.ToInt32(range2[1]); i++) { extConnection.slot[i] = RC.currentConnectionID; } GUIWindow.PrintLog("External LRM: Sent LocalTopology(" + 8 + ": " + String.Join("", extConnection.slot) + ") to RC"); GUIWindow.PrintLog("RC: Received LocalTopology(" + 8 + ": " + String.Join("", extConnection.slot) + ") from External LRM"); GUIWindow.PrintLog("RC: Sent LocalTopologyResponse() to External LRM : OK"); GUIWindow.PrintLog("External LRM: Received LocalTopologyResponse() from RC : OK"); if (Convert.ToBoolean(data["respond"])) { GUIWindow.PrintLog("External LRM: Sent LinkConnectionRequestResponse() to CC"); Program.cc.HandleRequest(Util.DecodeRequest("name:LinkConnectionRequestResponse;type:external")); } break; } break; } }