def run():
    # NOTE(gRPC Python Team): openoffload_pb2.close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('localhost:3443', creds)
        stub = openoffload_pb2_grpc.SessionTableStub(channel)

        print(
            "\n\ntry to delete and send a int64 session id that does not exist..."
        )
        try:
            sessionDeleteResponse = stub.deleteSession(
                openoffload_pb2.sessionId(sessionId=12333333))
        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 sessionDeleteResponse.requestStatus == openoffload_pb2._REJECTED_SESSION_NONEXISTENT:
                print(
                    "Delete failed as expected since that session id did not exist"
                )
Ejemplo n.º 2
0
def run():
    # NOTE(gRPC Python Team): openoffload_pb2.close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('localhost:3443', creds)
        stub = openoffload_pb2_grpc.SessionTableStub(channel)
        print("-------------- Add IPv4 Session --------------")
        session_addSession(stub)
        print("-------------- Add IPv6 Session --------------")
        session_addSession_ipv6(stub)
        print("-------------- Get Session --------------")
        session_getSession(stub)
        print("-------------- Delete Session --------------")
        session_deleteSession(stub)
        print("-------------- Add Mirror and Forward Session --------------")
        session_addMirrorSession(stub)
        print("-------------- Check for Closed Sessions --------------")
        session_getClosedSessions(stub)
        session_getAllSessions(stub)

    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        activationChannel = grpc.secure_channel('localhost:3445', creds)
        activationStub = openoffload_pb2_grpc.ActivationStub(activationChannel)
        print("\n\n------------Creating new devices---------------------\n")
        activation_registerDevice(activationStub)
        print(
            "\n------------- Listing available Devices --------------------\n")
        activation_getAllDevices(activationStub)
        print("\n------------- Activating Device --------------------\n")
        activation_activateDevice(activationStub)
        print(
            "\n------------- Activation Tests Complete --------------------\n")
Ejemplo n.º 3
0
def run_get_all_sessions():
    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('localhost:3443', creds)
        stub = openoffload_pb2_grpc.SessionTableStub(channel)
        print("-------------- Get All Sessions --------------")
        session_getAllSessions(stub)
Ejemplo n.º 4
0
def run_add_mirror_session():
    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('localhost:3443', creds)
        stub = openoffload_pb2_grpc.SessionTableStub(channel)
        print("-------------- Add Mirror Session --------------")
        result = session_addMirrorSession(stub)
        print("SESSIONID=", result)
Ejemplo n.º 5
0
def run_add_session_ipv6():
    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('localhost:3443', creds)
        stub = openoffload_pb2_grpc.SessionTableStub(channel)
        print("-------------- Add IPv6 Session --------------")
        result = session_addSession_ipv6(stub)
        print("RequestStatus=", result)
def run():
    # NOTE(gRPC Python Team): openoffload_pb2.close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('localhost:3443', creds)
        stub = openoffload_pb2_grpc.SessionTableStub(channel)
        statsStub = openoffload_pb2_grpc.SessionStatisticsTableStub(channel)
        print("-------------- Initialize the FW session table ---------------")
        print(
            " Some firewalls may want to get all the current offloaded sessions"
        )
        print(
            " and load them into its current session table.  An example could "
        )
        print(
            " be if a firewall has offload sessions and crashes/reboots.\n\n")
        session_getOffloadedSessions(statsStub, 0, 0)
        # we currently just print these on the screen, but an actual production
        # implementation would want to consider loading them into the firwall's
        # session table.

        print(
            "-------------- Adding 10 IPv4 & 10 IPv6 Sessions --------------")
        newSessionId = None
        for x in range(10):
            newSessionId = session_addSession(stub)
            print(f"Added new session id: {newSessionId}")

        print("Fetch the session from Offload device for testing purposes.")
        session_getSession(stub, newSessionId)

        for x in range(10):
            newSessionId = session_addSessionIpv6(stub)

        # We did not thread this code, but would expect parrallism be used to add new offload
        # sessions and to receive the offloaded sessions that have closed.
        while True:
            print(
                "\n-------------- Get All the Closed Sessions and update our session table  --------------"
            )
            sessionClosedSessions(statsStub)

            for x in range(2):
                print("\nAdding new IPv4 Session")
                newSessionId = session_addSession(stub)
            for x in range(2):
                print("\nAdding new IPv6 Session")
                newSessionId = session_addSessionIpv6(stub)

            time.sleep(2)
def run():
    # NOTE(gRPC Python Team): openoffload_pb2.close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('localhost:3443', creds)
        stub = openoffload_pb2_grpc.SessionTableStub(channel)

        print("adding session")
        session_addSession(stub)

        print("adding the same session")
        session_addSession(stub)
Ejemplo n.º 8
0
def run():
    global sessionTable, sessionId
    # NOTE(gRPC Python Team): .close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with open('ssl/server.crt', 'rb') as f:
        creds = grpc.ssl_channel_credentials(f.read())
        channel = grpc.secure_channel('localhost:3443', creds)
        stub = openoffload_pb2_grpc.SessionTableStub(channel)
        print("\n\n-------------- Watch the Sessions --------------")
        while True:
            print("\n\n-------------- Get All the Sessions --------------")
            session_getOffloadedSessions(stub, 0, 0)

            # lets try out Paging
            print(
                "\n\n-------------- Get the second five Sessions --------------"
            )
            session_getOffloadedSessions(stub, 5, 2)
            time.sleep(3)

            print("\n")