Skip to content

Commit

Permalink
Merge pull request #114 from EVOLVED-5G/develop
Browse files Browse the repository at this point in the history
version 0.8.4
  • Loading branch information
rimarala authored Oct 31, 2022
2 parents 5da0c79 + 6eaf56b commit 21b60e9
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 163 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
=======
History
=======
0.8.4 (2022-10-27)
-------------------
* The SDK Library now communicates first with CAPIF server in order to discover the NEF endpoints

0.8.3 (2022-10-17)
-------------------
Expand Down
7 changes: 7 additions & 0 deletions docs/source/libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Install the requirements_dev.txt
Make sure you have initiated the NEF_EMULATOR at url :py:func:`http://localhost:8888` (See `here <https://github.com/EVOLVED-5G/NEF_emulator>`_ for instructions),
you have logged in to the interface, clicked on the map and have started the simulation.

Make sure that your NetApp has been registered and onboarded to CAPIF. If this process is completed, then in the specified folder the following files should be present

- ca.crt
- capif_api_details.json
- private.key
- your_common_name_you_specified.crt

Then run a webserver in order to capture the callback post requests from NEF EMULATOR: On the terminal run the following commands to initialize the webserver.


Expand Down
2 changes: 1 addition & 1 deletion evolved5g/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Top-level package for Evolved5G_CLI."""

__author__ = "EVOLVED5G project"
__version__ = '0.8.3'
__version__ = '0.8.4'

# Uncomment next lines to give direct import access to modules
#from . import cli
Expand Down
114 changes: 92 additions & 22 deletions evolved5g/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@


class MonitoringSubscriber(ABC):
def __init__(self, host: str, bearer_access_token: str):
def __init__(self, host: str,
nef_bearer_access_token: str,
folder_path_for_certificates_and_capif_api_key: str,
capif_host:str,
capif_https_port:int):
configuration = swagger_client.Configuration()
configuration.host = host
configuration.access_token = bearer_access_token
configuration.access_token = nef_bearer_access_token
service_discoverer = ServiceDiscoverer(folder_path_for_certificates_and_capif_api_key,capif_host,capif_https_port)
configuration.available_endpoints = {
"MONITORING_SUBSCRIPTIONS": service_discoverer.retrieve_specific_resource_name("nef_emulator_endpoints",
"MONITORING_SUBSCRIPTIONS"),
"MONITORING_SUBSCRIPTION_SINGLE": service_discoverer.retrieve_specific_resource_name("nef_emulator_endpoints",
"MONITORING_SUBSCRIPTION_SINGLE"),
}
api_client = swagger_client.ApiClient(configuration=configuration)
self.monitoring_event_api = MonitoringEventAPIApi(api_client)
self.cell_api = CellsApi(api_client)
Expand Down Expand Up @@ -82,17 +93,24 @@ def delete_subscription(self, netapp_id: str, subscription_id: str):

class LocationSubscriber(MonitoringSubscriber):

def __init__(self, host: str, bearer_access_token: str):
def __init__(self, nef_url: str,
nef_bearer_access_token: str,
folder_path_for_certificates_and_capif_api_key: str,
capif_host:str,
capif_https_port:int):
"""
Initializes class LocationSubscriber.
This SKD class allows you to track devices and retrieve updates about their location.
You can create subscriptions where each one of them can be used to track a device.
A notification is sent to a callback url you will provide, everytime the user device changes Cell
:param str host: The url of the 5G-API
:param str bearer_access_token: The bearer access token that will be used to authenticate with the 5G-API
:param str nef_url: The url of the 5G-API
:param str nef_bearer_access_token: The bearer access token that will be used to authenticate with the 5G-API
"""
super().__init__(host, bearer_access_token)
super().__init__(nef_url, nef_bearer_access_token,
folder_path_for_certificates_and_capif_api_key,
capif_host,
capif_https_port)

def __get_monitoring_type(self):
return "LOCATION_REPORTING"
Expand Down Expand Up @@ -198,7 +216,12 @@ class MonitoringType(Enum):
INFORM_WHEN_CONNECTED = 1
INFORM_WHEN_NOT_CONNECTED = 2

def __init__(self, host: str, bearer_access_token: str):
def __init__(self,
nef_url: str,
nef_bearer_access_token: str,
folder_path_for_certificates_and_capif_api_key: str,
capif_host:str,
capif_https_port:int):
"""
Initializes class ConnectionMonitor.
Consider a scenario where a NetApp wants to monitor 100 devices in the 5G Network.
Expand All @@ -208,10 +231,17 @@ def __init__(self, host: str, bearer_access_token: str):
Connection is lost (for example the user device has not been connected to the 5G network for the past 10 seconds)
Connection is alive (for example the user device has been connected to the 5G network for the past 10 seconds)
:param str host: The url of the 5G-API
:param str bearer_access_token: The bearer access token that will be used to authenticate with the 5G-API
:param str nef_url: The url of the 5G-API
:param str nef_bearer_access_token: The bearer access token that will be used to authenticate with the 5G-API
:param folder_path_for_certificates_and_capif_api_key: The folder that contains the NetApp certificates and
CAPIF API Key. These are created while registering and onboarding the NetApp to the CAPIF Server
:param capif_host: The host of the CAPIF Server (ex. "capifcore")
:param capif_https_port: The https_port of the CAPIF Server
"""
super().__init__(host, bearer_access_token)
super().__init__(nef_url, nef_bearer_access_token,
folder_path_for_certificates_and_capif_api_key,
capif_host,
capif_https_port)

def __get_monitoring_type(self, monitoring_type: MonitoringType):
if monitoring_type == self.MonitoringType.INFORM_WHEN_CONNECTED:
Expand Down Expand Up @@ -397,21 +427,35 @@ def get_reporting_mode(self):
def get_reporting_configuration(self):
return self.repetition_period_in_seconds

def __init__(self, host: str, bearer_access_token: str):
def __init__(self, nef_url: str,
nef_bearer_access_token: str,
folder_path_for_certificates_and_capif_api_key: str,
capif_host:str,
capif_https_port:int):
"""
Initializes class QosAwareness.
This SKD class allows you to requests QoS from a set of standardized values for better service experience.
You can create subscriptions where each one of them has specific QoS parameters.
A notification is sent to a callback url you will provide, informing you in case the QoS targets can no
longer be full-filled.
:param str host: The url of the 5G-API
:param str bearer_access_token: The bearer access token that will be used to authenticate with the 5G-API
Initializes class QosAwareness.
This SKD class allows you to request QoS from a set of standardized values for better service experience.
You can create subscriptions where each one of them has specific QoS parameters.
A notification is sent to a callback url you will provide, informing you in case the QoS targets can no
longer be full-filled.
:param nef_url: The url of the 5G-API (ex. NEF emulator)
:param nef_bearer_access_token: The bearer access token that will be used to authenticate with the 5G-API
:param folder_path_for_certificates_and_capif_api_key: The folder that contains the NetApp certificates and
CAPIF API Key. These are created while registering and onboarding the NetApp to the CAPIF Server
:param capif_host: The host of the CAPIF Server (ex. "capifcore")
:param capif_https_port: The https_port of the CAPIF Server
"""

configuration = swagger_client.Configuration()
configuration.host = host
configuration.access_token = bearer_access_token
configuration.host = nef_url
configuration.access_token = nef_bearer_access_token
service_discoverer = ServiceDiscoverer(folder_path_for_certificates_and_capif_api_key,capif_host,capif_https_port)
configuration.available_endpoints = {
"QOS_SUBSCRIPTIONS": service_discoverer.retrieve_specific_resource_name("nef_emulator_endpoints", "QOS_SUBSCRIPTIONS"),
"QOS_SUBSCRIPTION_SINGLE": service_discoverer.retrieve_specific_resource_name("nef_emulator_endpoints", "QOS_SUBSCRIPTION_SINGLE")
}
api_client = swagger_client.ApiClient(configuration=configuration)
self.qos_api = SessionWithQoSAPIApi(api_client)

Expand Down Expand Up @@ -1052,6 +1096,9 @@ def publish_services(self,service_api_description_json_full_path)->None:


class ServiceDiscoverer:
class ServiceDiscovererException(Exception):
pass

def __init__(self,
folder_path_for_certificates_and_api_key: str,
capif_host:str,
Expand Down Expand Up @@ -1089,6 +1136,29 @@ def discover_service_apis(self):
response_payload = json.loads(response.text)
return response_payload

def retrieve_specific_resource_name(self, api_name,resource_name):
"""
Can be used to locate specific resources inside APIS.
For example the NEF emulator exposes an api with name "nef_emulator_endpoints" that contains two resources (two endpoints)
1. '/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions' with resource name:MONITORING_SUBSCRIPTIONS
2. '/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions/{subscriptionId}' with resource name : MONITORING_SUBSCRIPTION_SINGLE
"""
capif_apifs = self.discover_service_apis()
nef_endpoints = (list(filter(lambda api: api["api_name"] == api_name , capif_apifs)))
if len(nef_endpoints)== 0:
raise ServiceDiscoverer.ServiceDiscovererException("Could not find available endpoints for api_name: "
+ api_name + ".Make sure that a) your NetApp is registered and onboarded to CAPIF and b) the NEF emulator has been registered and onboarded to CAPIF")
else:
resources = nef_endpoints[0]["aef_profiles"][0]["versions"][0]["resources"]
uris = (list(filter(lambda resource: resource["resource_name"] == resource_name , resources)))
if len(uris)==0:
raise ServiceDiscoverer.ServiceDiscovererException("Could not find resource_name: "+ resource_name + "at api_name" + api_name)
else:
return uris[0]["uri"]







Expand Down
10 changes: 5 additions & 5 deletions evolved5g/swagger_client/api/monitoring_event_api_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def create_subscription_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_p
auth_settings = ['OAuth2PasswordBearer'] # noqa: E501

return self.api_client.call_api(
'/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions', 'POST',
self.api_client.configuration.available_endpoints["MONITORING_SUBSCRIPTIONS"], 'POST',
path_params,
query_params,
header_params,
Expand Down Expand Up @@ -233,7 +233,7 @@ def delete_subscription_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_s
auth_settings = ['OAuth2PasswordBearer'] # noqa: E501

return self.api_client.call_api(
'/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions/{subscriptionId}', 'DELETE',
self.api_client.configuration.available_endpoints["MONITORING_SUBSCRIPTION_SINGLE"], 'DELETE',
path_params,
query_params,
header_params,
Expand Down Expand Up @@ -336,7 +336,7 @@ def read_active_subscriptions_api_v13gpp_monitoring_event_v1_scs_as_id_subscript
auth_settings = ['OAuth2PasswordBearer'] # noqa: E501

return self.api_client.call_api(
'/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions', 'GET',
self.api_client.configuration.available_endpoints["MONITORING_SUBSCRIPTIONS"], 'GET',
path_params,
query_params,
header_params,
Expand Down Expand Up @@ -439,7 +439,7 @@ def read_subscription_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_sub
auth_settings = ['OAuth2PasswordBearer'] # noqa: E501

return self.api_client.call_api(
'/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions/{subscriptionId}', 'GET',
self.api_client.configuration.available_endpoints["MONITORING_SUBSCRIPTION_SINGLE"], 'GET',
path_params,
query_params,
header_params,
Expand Down Expand Up @@ -554,7 +554,7 @@ def update_subscription_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_s
auth_settings = ['OAuth2PasswordBearer'] # noqa: E501

return self.api_client.call_api(
'/nef/api/v1/3gpp-monitoring-event/v1/{scsAsId}/subscriptions/{subscriptionId}', 'PUT',
self.api_client.configuration.available_endpoints["MONITORING_SUBSCRIPTION_SINGLE"], 'PUT',
path_params,
query_params,
header_params,
Expand Down
Loading

0 comments on commit 21b60e9

Please sign in to comment.