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 CC::ConnectionRequest_req(id = {id}, src = {src}, dst = {dst}, sl = {sl}, teardown = {est})"); var connectionRequestResponse = _ccConnectionRequestClients[GetCcName(src)].Get(new RequestPacket.Builder() .SetEst(est) .SetId(id) .SetSrcPort(src) .SetDstPort(dst) .SetSlotsNumber(sl) .Build()); var res = connectionRequestResponse.Res; if (res == ResponsePacket.ResponseType.ResourcesProblem) { LOG.Info("Send CC:ConnectionRequest_res(res = ResourcesProblem)"); return(new ResponsePacket.Builder().SetRes(ResponsePacket.ResponseType.ResourcesProblem).Build()); } (int, int)slots = connectionRequestResponse.Slots; LOG.Info($"Received CC::ConnectionRequest_res({ResponsePacket.ResponseTypeToString(res)}, slots = {slots}, nextZonePort = NULL)"); if (res == ResponsePacket.ResponseType.Ok) { LOG.Info($"Send CC::ConnectionRequest_res(res = OK)"); return(new ResponsePacket.Builder().SetRes(ResponsePacket.ResponseType.Ok).SetSlots(slots).Build()); } LOG.Info($"Send CC::ConnectionRequest_res(res = Refused)"); return(new ResponsePacket.Builder().SetRes(ResponsePacket.ResponseType.Refused).Build()); }
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()); }
public ResponsePacket OnRouteTableQuery(RequestPacket requestPacket) { // Get RouteTableQuery_req packet params int connectionId = requestPacket.Id; string srcPort = requestPacket.SrcPort; string dstPort = requestPacket.DstPort; int slotsNumber = requestPacket.SlotsNumber; RequestPacket.Est est = requestPacket.Establish; if (est == RequestPacket.Est.Teardown) { LOG.Info($"Received RC::RouteTableQuery_req(Teardown, connectionId = {connectionId}, srcPort = {srcPort}," + $" dstPort = {dstPort}, slotsNumber = {slotsNumber})"); // The best idea will be to store the actual responses in a table / dict and when the Teardown RouteTableQuery // arrives, we just match connectionId, srcPort, dstPort, slotsNumber and if they are the same, just return // the same ResponsePacket. // e.g. instead of just returning ResponsePacket, do this: // ResponsePacket responsePacket = new ResponsePacket.Builder().<blablabla>.Build(); // _responsePackets[requestPacket] = responsePacket; // return responsePacket; // // and then when the Teardown comes, just do: LOG.Info($"Sending RC::RouteTableQuery_res(Teardown, connectionId = {connectionId})"); var teardownResponsePacket = _responsePackets[GetUniqueRcId(connectionId, srcPort, dstPort, slotsNumber)].Dequeue(); if (teardownResponsePacket == null) { LOG.Error("Could not find such connection"); return(new ResponsePacket.Builder().SetRes(ResponsePacket.ResponseType.Refused).Build()); } _connections.RemoveAll(connection => connectionId == connection.Id); return(teardownResponsePacket); } LOG.Info($"Received RC::RouteTableQuery_req(connectionId = {connectionId}, srcPort = {srcPort}," + $" dstPort = {dstPort}, slotsNumber = {slotsNumber})"); // Set dstZone depending on destination domain string secondDomainPortPattern = "3xx"; string dstZone; if (Checkers.PortMatches(secondDomainPortPattern, dstPort) > -1) // TODO: Check for matches value { dstZone = "012,021"; LOG.Trace($"Destination port belongs to other zone. Possible leaving ports: {dstZone}"); } else { dstZone = dstPort; LOG.Trace($"Destination port belongs to the same zone. Leaving port: {dstZone}"); } string gateway = GetBestGateway(srcPort, dstPort) ?? "0"; (int, int)slots = (0, 0); // Check whether we don't already have a registered connection with given connectionId if (!_connections.Exists(connection => connection.Id == connectionId)) { try { slots = CreateSlots(gateway, slotsNumber); } catch (Exception e) { LOG.Info(e.Message); return(new ResponsePacket.Builder() .SetRes(ResponsePacket.ResponseType.ResourcesProblem) .Build()); } _connections.Add(new Connection(connectionId, slots)); LOG.Trace($"Allocated slots {slots} for new connection with id {connectionId}"); } else { slots = _connections.Find(connection => connection.Id == connectionId).Slots; LOG.Trace($"There is already registered connection with id {connectionId}. Allocated slots: {slots}"); } ResponsePacket responsePacket = new ResponsePacket.Builder() .SetRes(ResponsePacket.ResponseType.Ok) .SetId(connectionId) .SetGateway(gateway) .SetSlots(slots) .SetDstZone(dstZone) .Build(); RequestPacket requestPacketWhenTeardown = requestPacket; requestPacketWhenTeardown.Establish = RequestPacket.Est.Teardown; string uniqueRcId = GetUniqueRcId(connectionId, srcPort, dstPort, slotsNumber); if (_responsePackets.ContainsKey(uniqueRcId)) { LOG.Trace($"_responsePacketsTable contains key: {uniqueRcId}"); } else { _responsePackets[uniqueRcId] = new Queue <ResponsePacket>(); } _responsePackets[uniqueRcId].Enqueue(responsePacket); LOG.Info($"Sending RC::RouteTableQuery_res" + $"(connectionId = {connectionId}, gateway = {gateway}," + $" slots = {slots.ToString()}, dstZone = {dstZone})"); return(responsePacket); }