def deleteSession(self, request, context): print("############ DELETE SESSION ##################"); print("sessionId:",request.sessionId); ourSessionId=None try: for sessionId, session in offloadSessionTable.items(): if session["clientSessionId"] == request.sessionId: ourSessionId=sessionId break if not ourSessionId: print(f"ERROR ID {request.sessionId} not found") msg = 'session id cannot be found' return openoffload_pb2.sessionResponse(requestStatus=openoffload_pb2._REJECTED_SESSION_NONEXISTENT) except KeyError: print(f"ERROR ID {request.sessionId} not found") msg = 'session id cannot be found' return openoffload_pb2.sessionResponse(requestStatus=openoffload_pb2._REJECTED_SESSION_NONEXISTENT) try: del offloadSessionTable[ourSessionId] except KeyError: print(f"ERROR ID {request.sessionId} can not be deleted") context.set_details(msg) context.set_code(grpc.StatusCode.UNKNOWN) return openoffload_pb2.sessionResponse() timestamp = google.protobuf.timestamp_pb2.Timestamp() timestamp.GetCurrentTime() return openoffload_pb2.sessionResponse(sessionId=request.sessionId, sessionState=openoffload_pb2._CLOSING_1, requestStatus=openoffload_pb2._ACCEPTED, startTime=timestamp, endTime=timestamp);
def getSession(self, request, context): global offloadSessionTable print("############ GET SESSION ##################") print("request sessionId:", request.sessionId) try: # now find this client session id in our local Session Tablea for sessionId, session in offloadSessionTable.items(): #print(f"checking our session id:{sessionId} client session id:", session["clientSessionId"], " matches the request sessionId:", request.sessionId ) if session["clientSessionId"] == request.sessionId: return openoffload_pb2.sessionResponse( sessionId=sessionId, sessionState=session["state"], requestStatus=openoffload_pb2._ACCEPTED, inPackets=session["inPackets"], inBytes=session["inBytes"], outPackets=session["outPackets"], outBytes=session["outBytes"], startTime=session["startTime"], endTime=session["endTime"], sessionCloseCode=session["sessionCloseCode"]) msg = (f"ERROR: The session was not found.") print(msg) context.set_details(msg) context.set_code(grpc.StatusCode.UNKNOWN) return openoffload_pb2.sessionResponse( requestStatus=openoffload_pb2._REJECTED_SESSION_NONEXISTENT) except: msg = (f"ERROR: The session was not found heer.") print(msg) context.set_details(msg) context.set_code(grpc.StatusCode.UNKNOWN) return openoffload_pb2.sessionResponse( requestStatus=openoffload_pb2._REJECTED_SESSION_NONEXISTENT)
def getAllSessions(self, request, context): print("############ GET ALL SESSIONS ##################"); timestamp = google.protobuf.timestamp_pb2.Timestamp() timestamp.GetCurrentTime() session1 = openoffload_pb2.sessionResponse(sessionId=1001, sessionState=openoffload_pb2._CLOSED, requestStatus=openoffload_pb2._ACCEPTED, inPackets=1000, outPackets=200000, startTime=timestamp); session2 = openoffload_pb2.sessionResponse(sessionId=1002, sessionState=openoffload_pb2._CLOSED, requestStatus=openoffload_pb2._ACCEPTED, inPackets=2000, outPackets=400000, startTime=timestamp); yield session1 yield session2
def getAllSessions(self, request, context): print("############ GET ALL SESSIONS ##################"); #print("pageSize:",request.pageSize); #print("page:",request.page); sessionCount = len(offloadSessionTable) print(f"Offload Session Table has {sessionCount} entries.") if request.pageSize and request.page: if request.page == 1: startIndex = 0 else: startIndex = request.pageSize * (request.page - 1) endIndex = request.pageSize * request.page - 1 if endIndex > sessionCount - 1: endIndex = sessionCount - 1 else: startIndex = 0 endIndex = sessionCount - 1 #print(f"start index = {startIndex} end index = {endIndex}") for x in range(startIndex, endIndex + 1): sessionId = list(offloadSessionTable)[x] session = offloadSessionTable[sessionId] #print(f"index = {x} returning session {sessionId}") yield openoffload_pb2.sessionResponse(sessionId=session["clientSessionId"], sessionState=session["state"], requestStatus=openoffload_pb2._ACCEPTED, inPackets=session["inPackets"], inBytes=session["inBytes"], outPackets=session["outPackets"], outBytes=session["outBytes"], startTime=session["startTime"], endTime=session["endTime"], sessionCloseCode=session["sessionCloseCode"]);
def deleteSession(self, request, context): print("############ DELETE SESSION ##################"); print("sessionId:",request.sessionId); timestamp = google.protobuf.timestamp_pb2.Timestamp() timestamp.GetCurrentTime() return openoffload_pb2.sessionResponse(sessionId=1001, sessionState=openoffload_pb2._CLOSING_1, requestStatus=openoffload_pb2._ACCEPTED, inPackets=2000, outPackets=400000, startTime=timestamp, endTime=timestamp);
def getSession(self, request, context): print("############ GET SESSION ##################"); print("sessionId:",request.sessionId); timestamp = google.protobuf.timestamp_pb2.Timestamp() timestamp.GetCurrentTime() return openoffload_pb2.sessionResponse(sessionId=1001,sessionState=openoffload_pb2._ESTABLISHED, requestStatus=openoffload_pb2._ACCEPTED, inPackets=1000, outPackets=200000, startTime=timestamp);
def getClosedSessions(self, request, context): print("############ GET CLOSED SESSIONS ##################"); for sessionId in list(offloadSessionTable): session = offloadSessionTable[sessionId] if session["state"] == openoffload_pb2._CLOSED: del offloadSessionTable[sessionId] yield openoffload_pb2.sessionResponse(sessionId=session["clientSessionId"], sessionState=session["state"], requestStatus=openoffload_pb2._ACCEPTED, inPackets=session["inPackets"], inBytes=session["inBytes"], outPackets=session["outPackets"], outBytes=session["outBytes"], startTime=session["startTime"], endTime=session["endTime"], sessionCloseCode=session["sessionCloseCode"]);