def session_addSession(stub):
    session = openoffload_pb2.sessionRequest()
    session.inLif = 1
    session.outLif = 2
    session.ipVersion = openoffload_pb2._IPV4
    session.sourceIp = socket.inet_pton(socket.AF_INET, '10.2.2.4')
    session.sourcePort = 12345
    session.destinationIp = socket.inet_pton(socket.AF_INET, '172.16.2.3')
    session.destinationPort = 443
    session.protocolId = openoffload_pb2._TCP
    session.action.actionType = openoffload_pb2._FORWARD
    session.action.actionNextHop = "12.2.3.4"

    print("Adding Session to Offload Engine...")
    try:
        sessionResponse = stub.addSession(session)
    except grpc.RpcError as e:
        print(f"ERROR Exception Caught: {e}")
        print(f"exception details: {e.details()}")
        status_code = e.code()
        print(f"exception status code: #{status_code.name}")
        print(f"exception status code value: #{status_code.value}")

    else:
        if sessionResponse.requestStatus == openoffload_pb2._REJECTED_SESSION_ALREADY_EXISTS:
            print(f"ERROR session already exists")
        elif sessionResponse.requestStatus == openoffload_pb2._REJECTED_SESSION_TABLE_FULL:
            print(f"WARNING session table is full")
        else:
            print(f"new offload session added id: {sessionResponse.sessionId}")
Exemple #2
0
def session_addSession(stub):
    session = openoffload_pb2.sessionRequest()
    session.sessionId = 12345678910
    session.inLif = 1
    session.outLif = 2
    session.sourceIp = int.from_bytes(socket.inet_pton(socket.AF_INET,
                                                       "10.0.0.1"),
                                      byteorder=sys.byteorder)
    session.sourcePort = 12345
    session.destinationIp = int.from_bytes(socket.inet_pton(
        socket.AF_INET, "10.1.0.3"),
                                           byteorder=sys.byteorder)
    session.destinationPort = 80
    session.protocolId = openoffload_pb2._TCP
    session.ipVersion = openoffload_pb2._IPV4
    session.action.actionType = openoffload_pb2._FORWARD
    session.action.actionNextHop = int.from_bytes(socket.inet_pton(
        socket.AF_INET, "12.2.3.4"),
                                                  byteorder=sys.byteorder)
    sessions_value = Sessions()
    sessions_value.addSessionMembers(session)
    session_iterator = iter(sessions_value)
    addSessionResponse = stub.addSession(session_iterator)
    print("addSessionResponse:", addSessionResponse.requestStatus)
    return addSessionResponse.requestStatus
def session_addMirrorSession(stub):
    # not yet implemented within the local session table
    session = openoffload_pb2.sessionRequest()
    session.inLif = 1
    session.outLif = 2
    session.sourceIp = "10.0.1.1"
    session.sourcePort = str(int.random(8096, 65355))
    session.destinationIp = "10.1.1.1"
    session.destinationPort = randomServerPort()
    session.protocolId = openoffload_pb2._UDP
    session.ipVersion = openoffload_pb2._IPV4
    session.action.actionType = openoffload_pb2._MIRROR
    session.action.actionNextHop = "12.2.3.4"
    sessionResponse = stub.addSession(session)
    print("Adding Session")
    print(sessionResponse.sessionId)
Exemple #4
0
def session_addMirrorSession(stub):
    session = openoffload_pb2.sessionRequest()
    session.sessionId = 12345678910
    session.inLif = 1
    session.outLif = 2
    session.sourceIp = socket.inet_pton(socket.AF_INET, "10.0.0.1")
    session.sourcePort = 12345
    session.destinationIp = socket.inet_pton(socket.AF_INET, "10.1.0.3")
    session.destinationPort = 80
    session.protocolId = openoffload_pb2._UDP
    session.action.actionType = openoffload_pb2._MIRROR
    session.action.actionNextHop = "12.2.3.4"
    sessionResponse = stub.addSession(session)
    print("Adding Session")
    print(sessionResponse.requestStatus)
    print(
        "Request Status: ", openoffload_pb2._REQUEST_STATUS.values_by_number[
            sessionResponse.requestStatus].name)
    return sessionResponse.requestStatus
Exemple #5
0
def session_addSession_ipv6(stub):
    session = openoffload_pb2.sessionRequest()
    session.sessionId = 12345678910
    session.inLif = 1
    session.outLif = 2
    session.sourceIp = socket.inet_pton(
        socket.AF_INET6, "2001:0db8:85a3:0000:0000:8a2e:0370:7332")
    session.sourcePort = 4430
    session.destinationIp = socket.inet_pton(
        socket.AF_INET6, "2001:0db8:85a3:0000:0000:8a03:0370:234F")
    session.destinationPort = 80
    session.protocolId = openoffload_pb2._TCP
    session.ipVersion = openoffload_pb2._IPV6
    session.action.actionType = openoffload_pb2._FORWARD
    session.action.actionNextHop = "12.2.3.4"
    addSessionResponse = stub.addSession(session)
    print("Adding Session")
    print(addSessionResponse.requestStatus)
    print(
        "Request Status: ", openoffload_pb2._REQUEST_STATUS.values_by_number[
            addSessionResponse.requestStatus].name)
    return addSessionResponse.requestStatus
Exemple #6
0
def session_addSession_ipv6(stub):
    session = openoffload_pb2.sessionRequest()
    session.sessionId = 12345678910
    session.inLif = 1
    session.outLif = 2
    session.sourceIpV6 = socket.inet_pton(
        socket.AF_INET6, "2001:0db8:85a3:0000:0000:8a2e:0370:7332")
    session.sourcePort = 4430
    session.destinationIpV6 = socket.inet_pton(
        socket.AF_INET6, "2001:0db8:85a3:0000:0000:8a03:0370:234F")
    session.destinationPort = 80
    session.protocolId = openoffload_pb2._TCP
    session.ipVersion = openoffload_pb2._IPV6
    session.action.actionType = openoffload_pb2._FORWARD
    session.action.actionNextHop = int.from_bytes(socket.inet_pton(
        socket.AF_INET, "12.2.3.4"),
                                                  byteorder=sys.byteorder)
    sessions_value = Sessions()
    sessions_value.addSessionMembers(session)
    session_iterator = iter(sessions_value)
    addSessionResponse = stub.addSession(session_iterator)
    print("addSessionResponse:", addSessionResponse.requestStatus)
    return addSessionResponse.requestStatus
def session_addSession(stub):
    global sessionTable

    sessionId = nextSessionId()

    session = openoffload_pb2.sessionRequest()
    session.sessionId = sessionId
    session.inLif = 1
    session.outLif = 2
    session.ipVersion = openoffload_pb2._IPV4
    session.sourceIp = int.from_bytes(socket.inet_pton(socket.AF_INET,
                                                       randomIp()),
                                      byteorder=sys.byteorder)
    session.sourcePort = int(random.randint(8192, 65535))
    session.destinationIp = int.from_bytes(socket.inet_pton(
        socket.AF_INET, randomIp()),
                                           byteorder=sys.byteorder)
    session.destinationPort = randomServerPort()
    session.protocolId = openoffload_pb2._TCP
    session.action.actionType = openoffload_pb2._FORWARD
    session.action.actionNextHop = int.from_bytes(socket.inet_pton(
        socket.AF_INET, "12.2.3.4"),
                                                  byteorder=sys.byteorder)

    print(f"\nAdding Session to local table new id {sessionId}")
    sessionTable[sessionId] = {
        "inLif": session.inLif,
        "outLif": session.outLif,
        "ipVersion": session.ipVersion,
        "sourceIp": session.sourceIp,
        "sourcePort": session.sourcePort,
        "destinationIp": session.destinationIp,
        "destinationPort": session.destinationPort,
        "protocolId": session.protocolId,
        "startTime": time.time(),
        "inPackets": 4,
        "inBytes": random.randint(10, 9999),
        "outPackets": 3,
        "outBytes": random.randint(10, 9999),
        "timeout": 3600,
        "offloaded": False,
        "offloadSessionId": None
    }

    print("Requesting Offload of IPv4 Session...")
    try:
        sessions_value = Sessions()
        sessions_value.addSessionMembers(session)
        session_iterator = iter(sessions_value)
        sessionResponse = stub.addSession(session_iterator)

    except grpc.RpcError as e:
        print(f"ERROR Exception Caught: {e}")
        print(f"exception details: {e.details()}")
        status_code = e.code()
        print(f"exception status code: #{status_code.name}")
        print(f"exception status code value: #{status_code.value}")
        return False
    else:
        if sessionResponse.requestStatus == openoffload_pb2._ACCEPTED:
            #:print(f"new session added Offload SessionId: {sessionResponse.sessionId}")
            print(f"new session added to Offload device")
            sessionTable[sessionId]["offloaded"] = True
            # TODO: fw should use same sessionId as request since its not tracked separately
            #sessionTable[sessionId]["offloadSessionId"] = sessionResponse.sessionId
        elif sessionResponse.requestStatus == openoffload_pb2._REJECTED_SESSION_TABLE_FULL:
            print(
                f"Offload Engine has no room for this session, Offload failed since offload session table is full"
            )
        else:
            print("ERROR Offload Engine returned unknown response.")

    return sessionId
def session_addSessionIpv6(stub):
    global sessionTable

    sessionId = nextSessionId()
    session = openoffload_pb2.sessionRequest()
    session.sessionId = sessionId
    session.inLif = 1
    session.outLif = 2
    session.ipVersion = openoffload_pb2._IPV6
    session.sourceIp = socket.inet_pton(socket.AF_INET6, randomIpv6())
    session.sourcePort = int(random.randint(8192, 65535))
    session.destinationIp = socket.inet_pton(socket.AF_INET6, randomIpv6())
    session.destinationPort = randomServerPort()
    session.protocolId = openoffload_pb2._UDP
    session.action.actionType = openoffload_pb2._FORWARD
    session.action.actionNextHop = "12.2.3.4"

    print(f"\nAdding Session to local table new id {sessionId}")
    timestamp = Timestamp()
    sessionTable[sessionId] = {
        "inLif": session.inLif,
        "outLif": session.outLif,
        "ipVersion": session.ipVersion,
        "sourceIp": session.sourceIp,
        "sourcePort": session.sourcePort,
        "destinationIp": session.destinationIp,
        "destinationPort": session.destinationPort,
        "protocolId": session.protocolId,
        "startTime": time.time(),
        "inPackets": 4,
        "inBytes": random.randint(10, 9999),
        "outPackets": 3,
        "outBytes": random.randint(10, 9999),
        "timeout": 3600,
        "offloaded": False,
        "offloadSessionId": None
    }

    #print(f" dump table: {sessionTable}")
    print("Requesting Offload of IPv6 Session...")
    try:
        sessionResponse = stub.addSession(session)
    except grpc.RpcError as e:
        print(f"ERROR Exception Caught: {e}")
        print(f"exception details: {e.details()}")
        status_code = e.code()
        print(f"exception status code: #{status_code.name}")
        print(f"exception status code value: #{status_code.value}")
        return False
    else:
        if sessionResponse.requestStatus == openoffload_pb2._ACCEPTED:
            print(f"new session added Offload device")
            sessionTable[sessionId]["offloaded"] = True
        elif sessionResponse.requestStatus == openoffload_pb2._REJECTED_SESSION_TABLE_FULL:
            print(
                f"Offload Engine has no room for this session, Offload failed since offload session table is full"
            )
        else:
            print("ERROR Offload Engine returned unknown response.")

    return sessionId