public ResponsePacket AskForConnection(string srcName, string dstName, int slotsNumber) { LOG.Info($"Send NCC:CallRequest_req(srcName = {srcName}, dstName = {dstName}, slotsNumber = {slotsNumber})"); ResponsePacket nccConnectionRequestResponse = _nccConnectionRequestClient.Get(new RequestPacket.Builder() .SetSrcName(srcName) .SetDstName(dstName) .SetSlotsNumber(slotsNumber) .Build()); ResponsePacket.ResponseType res = nccConnectionRequestResponse.Res; int connectionId = nccConnectionRequestResponse.Id; if (res == ResponsePacket.ResponseType.Ok) { _connectionId = connectionId; } return(nccConnectionRequestResponse); }
public ResponsePacket OnConnectionRequest(RequestPacket requestPacket) { int id = requestPacket.Id; string src = requestPacket.SrcPort; string dst = requestPacket.DstPort; int sl = requestPacket.SlotsNumber; RequestPacket.Est est = requestPacket.Establish; LOG.Info($"Received CC::ConnectionRequest_req(id = {id}, src = {src}, dst = {dst}, sl = {sl}, teardown = {est})"); LOG.Info($"Send RC::RouteTableQuery_req(id = {id}, src = {src}, dst = {dst}, sl = {sl}, teardown = {est})"); ResponsePacket routeTableQueryResponse = _rcRouteTableQueryClient.Get(new RequestPacket.Builder() .SetId(id) .SetSrcPort(src) .SetDstPort(dst) .SetSlotsNumber(sl) .SetEst(est) .Build()); if (routeTableQueryResponse.Res == ResponsePacket.ResponseType.ResourcesProblem) { LOG.Info("Received RC::RouteTableQuery_res(res = ResourcesProblem)"); LOG.Info("Send ConnectionRequest_res(res = ResourcesProblem)"); return(new ResponsePacket.Builder() .SetRes(ResponsePacket.ResponseType.ResourcesProblem) .Build()); } int rtqrId = routeTableQueryResponse.Id; string rtqrGateway = routeTableQueryResponse.Gateway; (int, int)rtqrSlots = routeTableQueryResponse.Slots; string dstZone = routeTableQueryResponse.DstZone; string gatewayOrEnd = rtqrGateway; LOG.Info($"Received RC::RouteTableQuery_res(id = {rtqrId}, gateway = {rtqrGateway}, slots = {rtqrSlots}, dstZone = {dstZone})"); if (dst != rtqrGateway) { string allocDealloc = est == RequestPacket.Est.Establish ? "allocate" : "deallocate"; LOG.Info($"Send LRM::LinkConnectionRequest_req(slots = {rtqrSlots}, {allocDealloc}, who = CC)"); ResponsePacket linkConnectionRequestResponse = _lrmLinkConnectionRequestClients[rtqrGateway].Get( new RequestPacket.Builder() .SetEst(est) .SetSlots(rtqrSlots) .SetShouldAllocate(true) .SetWhoRequests(RequestPacket.Who.Cc) .Build()); if (linkConnectionRequestResponse.Res == ResponsePacket.ResponseType.Refused) { LOG.Info($"Received LRM::LinkConnectionRequest_res(res = Refused)"); LOG.Info($"Send CC::ConnectionRequest_res(res = Refused)"); return(new ResponsePacket.Builder() .SetRes(ResponsePacket.ResponseType.Refused) .Build()); } gatewayOrEnd = linkConnectionRequestResponse.End; LOG.Info($"Received LRM::LinkConnectionRequest_res(end = {gatewayOrEnd})"); } else { LOG.Debug("Dst == Gateway, LRM will be handled by the layers above"); LOG.Info($"Send CC::ConnectionRequest_req(id = {rtqrId}, src = {src}, dst = {rtqrGateway}, sl = {sl}, teardown = {est})"); ResponsePacket connectionRequestResponseDst = _ccConnectionRequestClients[GetCcName(src)].Get(new RequestPacket.Builder() .SetEst(est) .SetId(id) .SetSrcPort(src) .SetDstPort(rtqrGateway) .SetSlotsNumber(sl) .SetSlots(rtqrSlots) .Build()); LOG.Info($"Received CC::ConnectionRequest_res({ResponsePacket.ResponseTypeToString(connectionRequestResponseDst.Res)})"); if (connectionRequestResponseDst.Res == ResponsePacket.ResponseType.Ok) { LOG.Info($"Send CC::ConnectionRequest_res({ResponsePacket.ResponseTypeToString(connectionRequestResponseDst.Res)}, slots = {rtqrSlots})"); return(new ResponsePacket.Builder().SetRes(ResponsePacket.ResponseType.Ok).SetSlots(rtqrSlots).Build()); } } // gateway == dstZone && dstZone != dst -- TODO Not implemented LOG.Info($"Send CC::ConnectionRequest_req(id = {rtqrId}, src = {src}, dst = {rtqrGateway}, sl = {sl}, teardown = {est})"); ResponsePacket connectionRequestResponse = _ccConnectionRequestClients[GetCcName(src)].Get(new RequestPacket.Builder() .SetEst(est) .SetId(id) .SetSrcPort(src) .SetDstPort(rtqrGateway) .SetSlotsNumber(sl) .Build()); LOG.Info($"Received CC::ConnectionRequest_res({ResponsePacket.ResponseTypeToString(connectionRequestResponse.Res)})"); ResponsePacket.ResponseType res = connectionRequestResponse.Res; if (res == ResponsePacket.ResponseType.Ok) { LOG.Info($"Send CC::PeerCoordination_req(id = {id}, src = {gatewayOrEnd}, dst = {dst}, slots = {rtqrSlots}, teardown = {est})"); ResponsePacket peerCoordinationResponse = _ccPeerCoordinationClients[GetCcName(gatewayOrEnd)].Get(new RequestPacket.Builder() .SetEst(est) .SetId(id) .SetSrcPort(gatewayOrEnd) .SetDstPort(dst) .SetSlots(rtqrSlots) .Build()); LOG.Info($"Received CC::PeerCoordination_res(res = {ResponsePacket.ResponseTypeToString(peerCoordinationResponse.Res)})"); if (peerCoordinationResponse.Res == ResponsePacket.ResponseType.Ok) { LOG.Info($"Send CC::ConnectionRequest_res(res = OK, nextZonePort = NULL, slots = {rtqrSlots})"); return(new ResponsePacket.Builder() .SetRes(ResponsePacket.ResponseType.Ok) .SetNextZonePort("") .SetSlots(rtqrSlots) .Build()); } // else LOG.Info($"Send CC::ConnectionRequest_res(res = Refused, nextZonePort = NULL, slots = {rtqrSlots})"); return(new ResponsePacket.Builder() .SetRes(ResponsePacket.ResponseType.Refused) .SetNextZonePort("") .SetSlots(rtqrSlots) .Build()); } LOG.Info($"Send CC::ConnectionRequest_res(res = Refused)"); // else return(new ResponsePacket.Builder() .SetRes(ResponsePacket.ResponseType.Refused) .Build()); }