public void SendCallAcceptResponse(String hostXName, String hostYName, String speed, bool response) { string message = "component:NCC;name:CallAcceptResponse;routerX:" + hostXName + ";routerY:" + hostYName + ";speed:" + speed + ";succeeded:" + response.ToString(); SendMessage(message); GUIWindow.PrintLog("NCC: Sent CallAcceptResponse(" + hostXName + ", " + hostYName + ", " + speed + " Gb/s) to NCC : " + (response ? "OK" : "DENIED")); }
public void SendCallTeardownCPCC(String hostXName, String hostYName, int connectionID) { string message = "component:NCC;name:CallTeardownCPCC;hostX:" + hostXName + ";hostY:" + hostYName + ";connectionID:" + connectionID; SendMessage(message); GUIWindow.PrintLog("CPCC: Sent CallTeardownCPCC(" + hostXName + ", " + hostYName + ", " + connectionID + ") to NCC"); GUIWindow.LockSendingMessages(); }
public void SendCallRequest(String myHostName, String targetHostName, int linkSpeed) { lastTargetHostName = targetHostName; string message = "component:NCC;name:CallRequest;hostX:" + myHostName + ";hostY:" + targetHostName + ";speed:" + linkSpeed; SendMessage(message); GUIWindow.PrintLog("CPCC: Sent CallRequest(" + myHostName + ", " + targetHostName + ", " + linkSpeed + " Gb/s) to NCC"); }
public GUIWindow() { InitializeComponent(); instance = this; SetButtonGreen(); lock (Program.waiterConfig) { Monitor.Pulse(Program.waiterConfig); } }
static void Main(string[] args) { args = Environment.GetCommandLineArgs(); new Thread(() => { Thread.Sleep(1000); try { lock (Program.waiterConfig) { //Monitor.Wait(Program.waiterConfig); //String config = String.Concat(File.ReadAllLines("./../../../../sharedResources/tsst_config.xml")); //ConfigLoader.LoadConfig(config, "1"); String config = String.Concat(File.ReadAllLines(args[1])); ConfigLoader.LoadConfig(config, args[2]); lock (Program.waiterManagement) { Monitor.Pulse(Program.waiterManagement); } } } catch (Exception e) { GUIWindow.PrintLog(e.StackTrace); } }).Start(); new Thread(() => { lock (Program.waiterManagement) { Monitor.Wait(Program.waiterManagement); } new ManagementCenterConnection(); }).Start(); new Thread(() => { lock (Program.waiterCloud){ Monitor.Wait(Program.waiterCloud); } cloudConnection = new CloudConnection(); }).Start(); new Thread(() => { Thread.Sleep(2500); /*lock (Program.waiterCloud) { * Monitor.Wait(Program.waiterCloud); * }*/ cpcc = new CPCC(); }).Start(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new GUIWindow()); }
public static void SendMessage(int connectionID, String message, String destinationName) { if (connected) { //nie wiem czy destination jeszcze wgl potrzebne do czegokolwiek Frame frame = new Frame(ClientIP, ClientPort, destinationName, 50000, connectionID, message); byte[] bytes = SerializeObject(frame); stream.Write(bytes, 0, bytes.Length); GUIWindow.PrintLog("Message " + "\"" + message + "\"" + " sent to " + destinationName); } else { GUIWindow.PrintLog("Connect with Cloud to send a message..."); } }
public CPCC() { try { TcpClient tcpClient = new TcpClient("localhost", centerPort); stream = tcpClient.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream); GUIWindow.PrintLog("Connection with Control Center has been established"); GUIWindow.PrintLog("Sent registration request to Control Center"); SendRegistrationRequest(); new Thread(ReceiveMessages).Start(); } catch (SocketException se) { GUIWindow.PrintLog("Connection with Control Center has NOT been established"); GUIWindow.PrintLog(se.Message); } }
public CloudConnection() { try { TcpClient tcpClient = new TcpClient("localhost", CloudPort); stream = tcpClient.GetStream(); connected = true; GUIWindow.PrintLog("Connection with Cloud has been established"); SendRegistrationRequest(); GUIWindow.PrintLog("Sent registration request to Cloud"); new Thread(ReceiveMessages).Start(); } catch (SocketException) { GUIWindow.PrintLog("Connection with Cloud has NOT been established :("); connected = false; } }
private void RecieveRegistrationInfo() { //for (int i = 0; i < 2; i++) { try { string msg = reader.ReadLine(); string[] parameters = msg.Split(':'); if (parameters[0].Equals("REGISTRATION") && parameters[1].Equals("OK")) { GUIWindow.PrintLog("Managment Center accepted registration request"); } else { GUIWindow.PrintLog("Managment Center denied registration request"); } } catch (IOException e) { GUIWindow.PrintLog(e.Message); } //} }
private void ManageCall(bool enableDestinationRestrain) { switch (ToggleButton.Text) { case "CALL": ReturnWindowParams(); if (enableDestinationRestrain && (Destination.Text.Length == 0 || requestedBandwidth == 0)) { GUIWindow.PrintLog("Destination name and throughput must not be empty!"); break; } Program.cpcc.SendCallRequest("Host" + ConfigLoader.nodeID, Destination.Text, requestedBandwidth); break; case "END": Program.cpcc.SendCallTeardownCPCC("Host" + ConfigLoader.nodeID, CPCC.cachedDestination, CPCC.connectionID); break; } }
private void ReceiveMessages() { GUIWindow.PrintLog("Listening for Cloud messages..."); while (true) { try { byte[] receivedBuffer = new byte[8192]; try { stream.Read(receivedBuffer, 0, receivedBuffer.Length); } catch { break; } Frame frame = (Frame)DeserializeObject(receivedBuffer); CPCC.connectionID = frame.ConnectionID; GUIWindow.PrintLog(GetMessageFromFrame(frame)); } catch (IOException ex) { GUIWindow.PrintLog(ex.Message); } } }
//private static ushort ClientPort = 50000; //private static string ClientIP = "160.0.0.50"; public ManagementCenterConnection() { try { TcpClient tcpClient = new TcpClient("localhost", centerPort); stream = tcpClient.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream); GUIWindow.PrintLog("Connection with Management Center has been established"); GUIWindow.PrintLog("Sent registration request to Management Center"); SendRegistrationRequest(); RecieveRegistrationInfo(); lock (Program.waiterCloud) { Monitor.Pulse(Program.waiterCloud); } //new Thread(ReceiveDataFromManagementCenter).Start(); } catch (SocketException) { GUIWindow.PrintLog("Connection with Management Center has NOT been established"); } }
//tak private void button1_Click(object sender, EventArgs e) { GUIWindow.AcceptCall(); }
private void ReceiveMessages() { 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 "CPCC": switch (data["name"]) { case "CallRequestResponse": if (Convert.ToBoolean(data["succeeded"])) { //zapisujemy ID i pozwalamy wysylac wiadomosci GUIWindow.UnlockSendingMessages(); GUIWindow.PrintLog("CPCC: Received CallRequestResponse(SUCCESSFUL, connectionID = " + data["connectionID"] + ") from NCC"); connectionID = Convert.ToInt32(data["connectionID"]); } else { GUIWindow.PrintLog("CPCC: Received CallRequestResponse(UNSUCCESSFUL) from NCC"); lastTargetHostName = null; } break; case "CallAccept": GUIWindow.PrintLog("CPCC: Received CallAccept(" + data["routerX"] + ", " + data["routerY"] + ", " + data["speed"] + " Gb/s) from NCC"); string msg = "Incomming call received from " + data["routerX"] + "\nDo you want to accept it?"; string caption = "Call incoming to " + data["routerY"]; var dialogresult = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogresult == DialogResult.Yes) { cachedDestination = data["routerX"]; SendCallAcceptResponse(data["routerX"], data["routerY"], data["speed"], true); } else if (dialogresult == DialogResult.No) { SendCallAcceptResponse(data["routerX"], data["routerY"], data["speed"], false); } break; case "CallTeardownCPCC": GUIWindow.PrintLog("CPCC: Received CallTeardownCPCC(" + data["connectionID"] + ") from NCC"); GUIWindow.PrintLog("CPCC: Sent CallTeardownCPCCResponse(" + data["connectionID"] + ") to NCC : OK"); message = "component:NCC;name:CallTeardownCPCCResponse;connectionID:" + connectionID; SendMessage(message); GUIWindow.LockSendingMessages(); GUIWindow.instance.GetToggleButton().Enabled = true; break; case "CallConfirmation": if (!Convert.ToBoolean(data["succeeded"])) { GUIWindow.PrintLog("CPCC: Received CallConfirmation(SUCCEEDED: false) from NCC"); } else { GUIWindow.ManageCallButton(false); GUIWindow.ManageMessageBox(true); GUIWindow.ManageSendButton(true); connectionID = Convert.ToInt32(data["connID"]); GUIWindow.SetDestinationValue(cachedDestination); GUIWindow.PrintLog("CPCC: Received CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") from NCC"); } GUIWindow.PrintLog("CPCC: Sent CallConfirmationResponse() to NCC"); SendMessage("component:NCC;name:CallConfirmationResponse;sender:CPCC;IDC:" + data["IDC"]); break; } break; case "NONE": switch (data["name"]) { case "RegistrationResponse": if (Convert.ToBoolean(data["succeeded"])) { GUIWindow.PrintLog("Control Center confirmed registration"); } else { GUIWindow.PrintLog("Control Center denied registration"); } break; } break; } } } catch (Exception ex) { GUIWindow.PrintLog(ex.StackTrace); GUIWindow.PrintLog(ex.Message); } }
public static readonly LinkedList <Tuple <int, String, int, int> > otherHosts = new LinkedList <Tuple <int, String, int, int> >(); //ID|IP|PORT //public static readonly LinkedList<Tuple<int, String, int, int, int>> otherAvailableHosts = new LinkedList<Tuple<int, String, int, int,>>(); //ID|IP|PORT|LABEL public static void LoadConfig(string file, string id) { XmlDocument doc = new XmlDocument(); doc.LoadXml(file); XmlElement root = doc.DocumentElement; XmlNodeList hostNodesList = root.SelectNodes("/config/hosts/host"); XmlNodeList controlCenterList = root.SelectNodes("/config/control-centers/control-center"); //XmlNodeList otherHostsNodesList = root.SelectNodes("/config/management-center/hosts-config/host-possible-destinations"); nodeID = Int32.Parse(id); foreach (XmlNode node in hostNodesList) { if (nodeID == Int32.Parse(node.Attributes["id"].Value)) { asID = Int32.Parse(node.Attributes["as-id"].Value); routerID = Int32.Parse(node.Attributes["router-id"].Value); ip = node.SelectSingleNode("host-ip").InnerText; port = Int32.Parse(node.SelectSingleNode("host-port").InnerText); foreach (XmlNode n in controlCenterList) { if (Int32.Parse(n.Attributes["id"].Value) == asID) { ccPort = Int32.Parse(n.Attributes["listening-port"].Value); break; } } } else { otherHosts.AddLast(new Tuple <int, String, int, int>(Int32.Parse(node.Attributes["id"].Value), node.SelectSingleNode("host-ip").InnerText, Int32.Parse(node.SelectSingleNode("host-port").InnerText), Int32.Parse(node.Attributes["as-id"].Value))); } } /* * //inne hosty i ich etykiety * foreach (XmlNode n in otherHostsNodesList) { * if (int.Parse(n.Attributes["host-id"].Value) == nodeID) { * XmlNodeList list = n.SelectNodes("host-possible-destination"); * * foreach (XmlNode hostNode in list) { * int label = Int32.Parse(hostNode.Attributes["label"].Value); * * foreach (Tuple<int,string,int> t in otherHosts) { * if (int.Parse(hostNode.Attributes["destination-host-id"].Value) == t.Item1) { * * otherAvailableHosts.AddLast(new Tuple<int,string,int,int>(t.Item1, t.Item2, t.Item3, label)); * break; * } * } * } * break; * } * } */ CloudConnection.ClientIP = ip + "/24"; CloudConnection.ClientPort = (ushort)port; CloudConnection.asID = asID; GUIWindow.PrintLog("Config loaded: " + id + "|" + ip + "|" + port); GUIWindow.ChangeWindowName("Host" + nodeID); //GUIWindow.AddDestinations(); GUIWindow.ChangeIP(ip); }