private static void WaitForInput(CSocket connected) { while (true) { Tuple <String, Object> received = connected.ReceiveObject(); String parameter = received.Item1; Object receivedObject = received.Item2; if (parameter.Equals(CONNECTION_REQEST_FROM_CC) || parameter.Equals(DELETE_CONNECTION_REQUEST)) { Tuple <SNP, SNP> pathToAssign = (Tuple <SNP, SNP>)received.Item2; SNP first = pathToAssign.Item1; SNP second = pathToAssign.Item2; if (!first.Deleting) { LogClass.CyanLog("Received request to SET CONNECTION between " + first.Address + " and " + second.Address); } else { LogClass.CyanLog("Received request to DELETE CONNECTION between " + first.Address + " and " + second.Address); } bool response = connectionController.ConnectionRequestIn(pathToAssign.Item1, pathToAssign.Item2); connected.SendACK(); LogClass.CyanLog("[ACK] Sending confirmation to Connection Controller"); Console.WriteLine(""); } } }
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; } } }