private static void WaitForInput(CSocket connected) { if (!connected.Equals(toParentSocket)) { ProcessConnectInformation(connected); } while (true) { Tuple <String, Object> received = connected.ReceiveObject(); String parameter = received.Item1; Object receivedObject = received.Item2; if (parameter.Equals(SNPP_SUBNETWORK_INFORMATION)) { InsertSNPPSToRC((List <SNPP>)receivedObject); } else if (parameter.Equals(CONNECTION_REQUEST_FROM_NCC)) { MessageParameters parameters = (MessageParameters)receivedObject; String sourceIP = parameters.getFirstParameter(); String destinationIP = parameters.getSecondParameter(); int capacity = parameters.getCapacity(); LogClass.CyanLog("Received CONNECTION REQUEST from NCC."); bool success = connectionController.ConnectionRequestFromNCC(sourceIP, destinationIP, capacity); String parentSubnetworkAddress = "127.0.0.1"; CSocket c = new CSocket(IPAddress.Parse(parentSubnetworkAddress), 40000, CSocket.CONNECT_FUNCTION); SendACKorNACK(success, c); } else if (parameter.Equals(PEER_COORDINATION)) { Tuple <SNP, string> receivedPair = (Tuple <SNP, string>)receivedObject; LogClass.CyanLog("Received PEER COORDINATION from AS 1"); bool success = connectionController.PeerCoordinationIn(receivedPair.Item1, receivedPair.Item2); SendACKorNACK(success, connected); } else if (parameter.Equals(DELETE_PEER_COORDINATION)) { Tuple <SNP, string> receivedPair = (Tuple <SNP, string>)receivedObject; LogClass.CyanLog("Received DELETE PEER COORDINATION from AS 1"); bool success = connectionController.DeletePeerCoordinationIn(receivedPair.Item1, receivedPair.Item2); SendACKorNACK(success, connected); } else if (parameter.Equals(NETWORK_TOPOLOGY)) { } else if (parameter.Equals(CONNECTION_REQUEST_FROM_CC)) { Tuple <SNP, SNP> pathToAssign = (Tuple <SNP, SNP>)received.Item2; SNP first = pathToAssign.Item1; SNP second = pathToAssign.Item2; LogClass.CyanLog("Received CONNECTION REQUEST to set connection between " + first.Address + " and " + second.Address); bool response = callConnectionRequest(pathToAssign.Item1, pathToAssign.Item2); SendACKorNACK(response, connected); } else if (parameter.Equals(CALL_TEARDOWN)) { MessageParameters parameters = (MessageParameters)receivedObject; String sourceIP = parameters.getFirstParameter(); String destinationIP = parameters.getSecondParameter(); LogClass.CyanLog("Received TEARDOWN to deallocate connection between " + sourceIP + " and " + destinationIP); bool success = connectionController.DeleteConnection(sourceIP, destinationIP); String parentSubnetworkAddress = "127.0.0.1"; CSocket c = new CSocket(IPAddress.Parse(parentSubnetworkAddress), 40000, CSocket.CONNECT_FUNCTION); SendACKorNACK(success, c); } else if (parameter.Equals(DELETE_CONNECTION_REQUEST)) { Tuple <SNP, SNP> pathToDelete = (Tuple <SNP, SNP>)received.Item2; string pathBegin = pathToDelete.Item1.Address; string pathEnd = pathToDelete.Item2.Address; LogClass.CyanLog("Received DELETE CONNECTION REQUEST to delete connection between " + pathBegin + " and " + pathEnd); bool success = connectionController.DeleteConnection(pathBegin, pathEnd); SendACKorNACK(success, connected); } else if (parameter.Equals(CSocket.ACK_FUNCTION)) { LogClass.CyanLog("Received ACK"); acked = true; } else if (parameter.Equals(CSocket.NACK_FUNCTION)) { LogClass.CyanLog("Received NACK"); nacked = true; } } }
private static void WaitForInput(CSocket socket) { Tuple <String, Object> received = socket.ReceiveObject(); String parameter = received.Item1; messageParameters = (MessageParameters)received.Item2; if (parameter.Equals(CALL_INDICATION)) { CPCC.PrintLogs(CALL_INDICATION); CPCC.SendMessage(CALL_CONFIRMED_CPCC, messageParameters.getFirstParameter(), messageParameters.getSecondParameter(), messageParameters.getCapacity()); } else if (parameter.Equals(CALL_TEARDOWN_CPCC)) { CPCC.PrintLogs(CALL_TEARDOWN_CPCC); CPCC.SendMessage(CALL_TEARDOWN_CPCC, messageParameters.getFirstParameter(), messageParameters.getSecondParameter(), messageParameters.getCapacity()); } else if (parameter.Equals(CALL_CONFIRMED_CPCC)) { CPCC.PrintLogs(CALL_CONFIRMED_CPCC); } else if (parameter.Equals(CALL_REJECTED_CPCC)) { CPCC.PrintLogs(CALL_REJECTED_CPCC); } }
private static void waitForInput(CSocket socket) { Tuple <String, Object> received = socket.ReceiveObject(); String parameter = received.Item1; Object receivedObject = received.Item2; string firstParam = null; string secondParam = null; if (receivedObject is MessageParameters) { messageParameters = (MessageParameters)received.Item2; firstParam = messageParameters.getFirstParameter(); secondParam = messageParameters.getSecondParameter(); capacity = messageParameters.getCapacity(); } if (parameter.Equals(CALL_REQUEST)) { LogClass.Log("Received CALL REQUEST from " + firstParam); try { Policy.userAuthentication(firstParam); userAddress_1 = Directory.getTranslatedAddress(firstParam); LogClass.Log("Translated " + firstParam + " to " + userAddress_1); userAddress_2 = Directory.getTranslatedAddress(secondParam); if (userAddress_2 != null) { LogClass.Log("Translated " + secondParam + " to " + userAddress_2); } if (userAddress_2.Contains("10.1")) { SendingManager.Init(Config.getIntegerProperty("sendPortToCC")); LogClass.Log("Sending CONNECTION REQUEST to CC" + Environment.NewLine); SendingManager.SendObject(new Dictionary <string, string>()); SendingManager.SendMessage(CONNECTION_REQUEST, userAddress_1, userAddress_2, capacity); } else if (userAddress_2.Contains("10.2")) { SendingManager.Init(Config.getIntegerProperty("sendPortToNCC")); LogClass.Log("Sending CALL COORDINATION to NCC_2" + Environment.NewLine); SendingManager.SendMessage(CALL_COORDINATION, userAddress_1, userAddress_2, capacity); } } catch (NullReferenceException) { LogClass.Log("Cannot translate " + secondParam); LogClass.Log("Cannot set up the connection"); SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC")); LogClass.Log("Sending CALL REJECTED to CPCC" + Environment.NewLine); SendingManager.SendMessage(CALL_REJECTED_CPCC, "1", "1", 0); } } else if (parameter.Equals(CALL_TEARDOWN)) { LogClass.Log("Received CALL TEARDOWN from " + firstParam); try { Policy.userAuthentication(firstParam); userAddress_1 = Directory.getTranslatedAddress(firstParam); LogClass.Log("Translated " + firstParam + " to " + userAddress_1); userAddress_2 = Directory.getTranslatedAddress(secondParam); if (userAddress_2 != null) { LogClass.Log("Translated " + secondParam + " to " + userAddress_2); } if (userAddress_2.Contains("10.1")) { SendingManager.Init(Config.getIntegerProperty("sendPortToCC")); LogClass.Log("Sending CALL TEARDOWN to CC" + Environment.NewLine); SendingManager.SendObject(new Dictionary <string, string>()); SendingManager.SendMessage(CALL_TEARDOWN, userAddress_1, userAddress_2, capacity); } else if (userAddress_2.Contains("10.2")) { SendingManager.Init(Config.getIntegerProperty("sendPortToNCC")); LogClass.Log("Sending CALL TEARDOWN to NCC_2" + Environment.NewLine); SendingManager.SendMessage(CALL_TEARDOWN_NCC, userAddress_1, userAddress_2, capacity); } } catch (NullReferenceException) { LogClass.Log("Cannot translate " + secondParam); LogClass.Log("Cannot set up the connection"); SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC")); LogClass.Log("Sending CALL REJECTED to CPCC" + Environment.NewLine); SendingManager.SendMessage(CALL_REJECTED_CPCC, "1", "1", 0); } } else if (parameter.Equals(CALL_TEARDOWN_NCC)) { LogClass.Log("Received CALL TEARDOWN from NCC_1"); SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC")); LogClass.Log("Sending CALL TEARDOWN to " + secondParam + Environment.NewLine); SendingManager.SendMessage(CALL_TEARDOWN_CPCC, firstParam, secondParam, capacity); } else if (parameter.Equals(CALL_TEARDOWN_CPCC)) { LogClass.Log(secondParam + " accepted the dealocation"); SendingManager.Init(Config.getIntegerProperty("sendPortToNCC")); LogClass.Log("Sending CALL TEARDOWN to NCC_1" + Environment.NewLine); SendingManager.SendMessage(CALL_TEARDOWN_NCC_2, userAddress_1, userAddress_2, capacity); } else if (parameter.Equals(CALL_TEARDOWN_NCC_2)) { LogClass.Log("Received DEALLOCATION CONFIRMATION from NCC_2"); SendingManager.Init(Config.getIntegerProperty("sendPortToCC")); LogClass.Log("Sending CALL TEARDOWN to CC" + Environment.NewLine); SendingManager.SendObject(new Dictionary <string, string>()); SendingManager.SendMessage(CALL_TEARDOWN, userAddress_1, userAddress_2, capacity); } else if (parameter.Equals(CALL_COORDINATION)) { LogClass.Log("Received CALL COORDINATION from NCC_1"); SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC")); LogClass.Log("Sending CALL INDICATION to " + secondParam + Environment.NewLine); SendingManager.SendMessage(CALL_INDICATION, firstParam, secondParam, capacity); } else if (parameter.Equals(CALL_CONFIRMED_CPCC)) { LogClass.Log("Received CALL CONFIRMED from " + secondParam); SendingManager.Init(Config.getIntegerProperty("sendPortToNCC")); LogClass.Log("Sending CALL CONFIRMED to NCC_1" + Environment.NewLine); SendingManager.SendMessage(CALL_CONFIRMED_NCC, firstParam, secondParam, capacity); } else if (parameter.Equals(CALL_CONFIRMED_NCC)) { LogClass.Log("Received CALL CONFIRMED from NCC_2"); SendingManager.Init(Config.getIntegerProperty("sendPortToCC")); LogClass.Log("Sending CONNECTION REQUEST to CC" + Environment.NewLine); SendingManager.SendObject(new Dictionary <string, string>()); SendingManager.SendMessage(CONNECTION_REQUEST, firstParam, secondParam, capacity); } else if (parameter.Equals(ACK_FUNCTION)) { LogClass.Log("Connection set properly"); SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC")); LogClass.Log("Sending CALL CONFIRMED to CPCC" + Environment.NewLine); SendingManager.SendMessage(CALL_CONFIRMED_CPCC, "1", "1", 0); } else if (parameter.Equals(NACK_FUNCTION)) { LogClass.Log("Cannot set up the connection"); SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC")); LogClass.Log("Sending CALL REJECTED to CPCC" + Environment.NewLine); SendingManager.SendMessage(CALL_REJECTED_CPCC, "1", "1", 0); } }