Skip to content

Commit

Permalink
feat: Add support for grpc configuration for mock HSS at federated in…
Browse files Browse the repository at this point in the history
…teg test

Signed-off-by: Oriol Batalla <obatalla@fb.com>
  • Loading branch information
uri200 committed Apr 5, 2022
1 parent f3e0ceb commit d93b400
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 35 deletions.
2 changes: 2 additions & 0 deletions feg/cloud/configs/service_registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ services:
port: 9079
pcrf:
port: 9079
hss:
port: 9079

health:
host: "localhost"
Expand Down
51 changes: 38 additions & 13 deletions lte/gateway/python/integ_tests/common/subscriber_db_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
import time

import grpc
from integ_tests.gateway.rpc import get_gateway_hw_id, get_rpc_channel
from integ_tests.gateway.rpc import get_gateway_hw_id, get_rpc_channel, get_hss_rpc_channel
from lte.protos.subscriberdb_pb2 import (
LTESubscription,
SubscriberData,
SubscriberID,
SubscriberState,
SubscriberUpdate,
)
from feg.protos.hss_service_pb2_grpc import (
HSSConfiguratorStub
)
from lte.protos.subscriberdb_pb2_grpc import SubscriberDBStub
from magma.subscriberdb.sid import SIDUtils
from orc8r.protos.common_pb2 import Void
Expand Down Expand Up @@ -87,18 +90,17 @@ def wait_for_changes(self):
raise NotImplementedError()


class SubscriberDbGrpc(SubscriberDbClient):
class GenericSubscriberGrpcClient(SubscriberDbClient):
"""
Handle subscriber actions by making calls over gRPC directly to the
gateway.
Generic implementation to handle subscriber actions by making calls
over gRPC
"""

def __init__(self):
def __init__(self, grpcStub):
""" Init the gRPC stub. """
self._added_sids = set()
self._subscriber_stub = SubscriberDBStub(
get_rpc_channel("subscriberdb"),
)
self._subscriber_stub = grpcStub


@staticmethod
def _try_to_call(grpc_call):
Expand Down Expand Up @@ -180,21 +182,20 @@ def add_subscriber(self, sid):
logging.info("Adding subscriber : %s", sid)
self._added_sids.add(sid)
sub_data = self._get_subscriberdb_data(sid)
SubscriberDbGrpc._try_to_call(
GenericSubscriberGrpcClient._try_to_call(
lambda: self._subscriber_stub.AddSubscriber(sub_data),
)
self._check_invariants()

def delete_subscriber(self, sid):
logging.info("Deleting subscriber : %s", sid)
self._added_sids.discard(sid)
sid_pb = SubscriberID(id=sid[4:])
SubscriberDbGrpc._try_to_call(
GenericSubscriberGrpcClient._try_to_call(
lambda: self._subscriber_stub.DeleteSubscriber(sid_pb),
)

def list_subscriber_sids(self):
sids_pb = SubscriberDbGrpc._try_to_call(
sids_pb = GenericSubscriberGrpcClient._try_to_call(
lambda: self._subscriber_stub.ListSubscribers(Void()).sids,
)
sids = ['IMSI' + sid.id for sid in sids_pb]
Expand All @@ -205,9 +206,11 @@ def config_apn_details(self, imsi, apn_list):
update_sub = self._get_apn_data(sid, apn_list)
fields = update_sub.mask.paths
fields.append('non_3gpp')
SubscriberDbGrpc._try_to_call(

GenericSubscriberGrpcClient._try_to_call(
lambda: self._subscriber_stub.UpdateSubscriber(update_sub),
)
self._check_invariants()

def clean_up(self):
# Remove all sids
Expand All @@ -221,6 +224,28 @@ def wait_for_changes(self):
return


class SubscriberDbGrpc(GenericSubscriberGrpcClient):
"""
Handle mock HSS actions by making calls over gRPC directly to the
hss service on the feg.
"""

def __init__(self):
""" Init the gRPC stub to connect to subscriberDb. """
super().__init__(SubscriberDBStub(get_rpc_channel("subscriberdb")))


class HSSGrpc(GenericSubscriberGrpcClient):
"""
Handle mock HSS actions by making calls over gRPC directly to the
hss service on the feg.
"""

def __init__(self):
""" Init the gRPC stub to connect to mock HSS. """
super().__init__(HSSConfiguratorStub(get_hss_rpc_channel()))


class SubscriberDbCassandra(SubscriberDbClient):
"""
Handle subscriber action by making calls to Cassandra database of OAI HSS
Expand Down
18 changes: 11 additions & 7 deletions lte/gateway/python/integ_tests/federated_tests/configs/hss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
# <imsi>:
# <auth_key>: - required (hex string)
# <non_3gpp_enabled>: - optional (bool)
subscribers:
"001010000000001":
auth_key: "000102030405060708090A0B0C0D0E0F"
lte_auth_next_seq: 1
"001010000000002":
auth_key: "000102030405060708090A0B0C0D0E0F"
lte_auth_next_seq: 1
#
#
#
# Sample configuration
#subscribers:
# "001010000000001":
# auth_key: "000102030405060708090A0B0C0D0E0F"
# lte_auth_next_seq: 1
# "001010000000002":
# auth_key: "000102030405060708090A0B0C0D0E0F"
# lte_auth_next_seq: 1
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ services:
- gwconfigs:/var/opt/magma/configs
restart: always
environment:
MAGMA_PRINT_GRPC_PAYLOAD: 2
USE_REMOTE_SWX_PROXY: 0
command: envdir /var/opt/magma/envdir /var/opt/magma/bin/hss -logtostderr=true -v=0
command: envdir /var/opt/magma/envdir /var/opt/magma/bin/hss -logtostderr=true -v=9

control_proxy:
extra_hosts:
- controller.magma.test:127.0.0.1
- bootstrapper-controller.magma.test:127.0.0.1
#- controller.magma.test:10.0.2.2
#- bootstrapper-controller.magma.test:10.0.0.2
#- controller.magma.test:127.0.0.1
#- bootstrapper-controller.magma.test:127.0.0.1
- controller.magma.test:10.0.2.2
- bootstrapper-controller.magma.test:10.0.0.2
command:
- /bin/bash
- -c
Expand All @@ -37,10 +38,10 @@ services:
context: ${BUILD_CONTEXT}
dockerfile: feg/gateway/docker/python/Dockerfile
extra_hosts:
- controller.magma.test:127.0.0.1
- bootstrapper-controller.magma.test:127.0.0.1
#- controller.magma.test:10.0.2.2
#- bootstrapper-controller.magma.test:10.0.2.2
#- controller.magma.test:127.0.0.1
#- bootstrapper-controller.magma.test:127.0.0.1
- controller.magma.test:10.0.2.2
- bootstrapper-controller.magma.test:10.0.2.2
command: python3.8 -m magma.magmad.main

volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ services:
<<: *goservice
container_name: s6a_proxy
environment:
MAGMA_PRINT_GRPC_PAYLOAD: 1
MAGMA_PRINT_GRPC_PAYLOAD: 2
command: envdir /var/opt/magma/envdir /var/opt/magma/bin/s6a_proxy -logtostderr=true -v=9


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class TestAttachDetach(unittest.TestCase):

def setUp(self):
self._s1ap_wrapper = s1ap_wrapper.TestWrapper()
self._s1ap_wrapper = s1ap_wrapper.TestWrapper(federated_mode=True)

def tearDown(self):
self._s1ap_wrapper.cleanup()
Expand All @@ -41,8 +41,8 @@ def test_attach_detach(self):
for i in range(num_ues):
req = self._s1ap_wrapper.ue_req
print(
"************************* Running End to End attach for ",
"UE id ", req.ue_id,
"************************* Running Federated End to End attach "
"for UE id ", req.ue_id,
)
# Now actually complete the attach
self._s1ap_wrapper._s1_util.attach(
Expand Down
29 changes: 27 additions & 2 deletions lte/gateway/python/integ_tests/gateway/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import os
from typing import Any, Dict, List

from magma.common.service_registry import create_grpc_channel
from magma.common.service_registry import (
create_grpc_channel,
get_ssl_creds
)

from magma.configuration.mconfigs import unpack_mconfig_any
from orc8r.protos.common_pb2 import Void
from orc8r.protos.magmad_pb2_grpc import MagmadStub
Expand All @@ -24,12 +28,33 @@ def get_rpc_channel(service):
"""
Returns a RPC channel to the service in the gateway.
"""
return create_grpc_channel(

res = create_grpc_channel(
os.environ.get('GATEWAY_IP', '192.168.60.142'),
os.environ.get('GATEWAY_PORT', '8443'),
'%s.local' % service,
)

return res


def get_hss_rpc_channel():
"""
Returns RPC channel to hss
"""
return get_feg_rpc_channel('9204', 'hss')


def get_feg_rpc_channel(port, service):
"""
Returns RPC channel to the service in the gateway.
"""
return create_grpc_channel(
'192.168.60.142',
port,
'%s.local' % service,
)


def get_gateway_hw_id():
"""
Expand Down
1 change: 1 addition & 0 deletions lte/gateway/python/integ_tests/s1aptests/s1ap_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ def add_sub(self, num_ues=1):
self._subscriber_client.add_subscriber(sid)
imei = self._generate_imei()
subscribers.append(self._get_s1ap_sub(sid, imei))

self._subscriber_client.wait_for_changes()
return subscribers

Expand Down
5 changes: 5 additions & 0 deletions lte/gateway/python/integ_tests/s1aptests/s1ap_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from integ_tests.common.subscriber_db_client import (
SubscriberDbCassandra,
SubscriberDbGrpc,
HSSGrpc,
)
from integ_tests.s1aptests.s1ap_utils import (
MagmadUtil,
Expand Down Expand Up @@ -58,6 +59,7 @@ def __init__(
stateless_mode=MagmadUtil.stateless_cmds.ENABLE,
apn_correction=MagmadUtil.apn_correction_cmds.DISABLE,
health_service=MagmadUtil.health_service_cmds.DISABLE,
federated_mode=False,
):
"""
Initialize the various classes required by the tests and setup.
Expand All @@ -71,6 +73,9 @@ def __init__(
if self._test_oai_upstream:
subscriber_client = SubscriberDbCassandra()
self.wait_gateway_healthy = False
elif federated_mode:
subscriber_client = HSSGrpc()
self.wait_gateway_healthy = True
else:
subscriber_client = SubscriberDbGrpc()
self.wait_gateway_healthy = True
Expand Down

0 comments on commit d93b400

Please sign in to comment.