Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for grpc configuration for mock HSS at federated integ test #12406

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion feg/gateway/configs/hss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# HSS Config
#
# ---
#subscribers:
# subscribers:
# <imsi>:
# <auth_key>: - required (hex string)
# <non_3gpp_enabled>: - optional (bool)
Expand Down
52 changes: 39 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,7 +18,12 @@
import time

import grpc
from integ_tests.gateway.rpc import get_gateway_hw_id, get_rpc_channel
from feg.protos.hss_service_pb2_grpc import HSSConfiguratorStub
from integ_tests.gateway.rpc import (
get_gateway_hw_id,
get_hss_rpc_channel,
get_rpc_channel,
)
from lte.protos.subscriberdb_pb2 import (
LTESubscription,
SubscriberData,
Expand Down Expand Up @@ -87,18 +92,16 @@ 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, grpc_stub):
""" Init the gRPC stub. """
self._added_sids = set()
self._subscriber_stub = SubscriberDBStub(
get_rpc_channel("subscriberdb"),
)
self._subscriber_stub = grpc_stub

@staticmethod
def _try_to_call(grpc_call):
Expand Down Expand Up @@ -180,21 +183,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 +207,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 +225,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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a space between # and comment as linter suggested.

uri200 marked this conversation as resolved.
Show resolved Hide resolved
# "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,8 +11,9 @@ 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:
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
25 changes: 23 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,7 @@
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 +24,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 @@ -757,6 +757,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 @@ -22,6 +22,7 @@
from integ_tests.common.mobility_service_client import MobilityServiceGrpc
from integ_tests.common.service303_utils import GatewayServicesUtil
from integ_tests.common.subscriber_db_client import (
HSSGrpc,
SubscriberDbCassandra,
SubscriberDbGrpc,
)
Expand Down Expand Up @@ -60,6 +61,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 @@ -77,6 +79,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