forked from EVOLVED-5G/SDK-CLI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request EVOLVED-5G#10 from EVOLVED-5G/libraries
Merging libraries to master
- Loading branch information
Showing
71 changed files
with
16,776 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ __pycache__/ | |
|
||
# C extensions | ||
*.so | ||
|
||
.idea | ||
# Distribution / packaging | ||
.Python | ||
env/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
SDK - Libraries | ||
============ | ||
|
||
At the current release the SDK contains one class "**LocationSubscriber**" | ||
that allows you to track devices and retrieve updates about their location. | ||
You can use LocationSubscriber to create subscriptions, where each one of them can be used to track a device. | ||
|
||
Examples of usage /Have a look at the code | ||
---- | ||
Have a look at the examples folder for code samples on how to use the SDK Library. | ||
|
||
`Location subscriber example <https://github.com/EVOLVED-5G/SDK-CLI/blob/libraries/examples/location_subscriber_examples.py>`_ | ||
|
||
Prerequisites / How to start | ||
---- | ||
|
||
Install the requirements_dev.txt | ||
|
||
pip install -r requirements_dev.txt | ||
|
||
Make sure you have initiated the NEF_EMULATOR at url 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. | ||
|
||
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. | ||
|
||
|
||
export FLASK_APP=/home/user/evolved-5g/SDK-CLI/examples/api.py | ||
|
||
export FLASK_ENV=development | ||
|
||
python -m flask run --host=0.0.0.0 | ||
|
||
where FLASK_APP should point to the absolute path of the SDK-CLI/examples/api.py file. | ||
These commands will initialize a web server at http://127.0.0.1:5000/ | ||
|
||
Now you can run `Location subscriber example <https://github.com/EVOLVED-5G/SDK-CLI/blob/libraries/examples/location_subscriber_examples.py>`_ | ||
You should be able to view the location updates, printed in the terminal that runs the FLASK webserver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,149 @@ | ||
"""SDK module""" | ||
"""SDK module""" | ||
from evolved5g import swagger_client | ||
from evolved5g.swagger_client import MonitoringEventAPIApi, \ | ||
MonitoringEventSubscriptionCreate, MonitoringEventSubscription | ||
|
||
""" | ||
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 | ||
""" | ||
|
||
|
||
class LocationSubscriber: | ||
|
||
def __init__(self, host: str, bearer_access_token: str): | ||
""" | ||
Initializes class LocationSubscriber | ||
:param str host: The url of the 5G-API | ||
:param str bearer_access_token: The beared access token that will be used to authenticate with the 5G-API | ||
""" | ||
configuration = swagger_client.Configuration() | ||
configuration.host = host | ||
configuration.access_token = bearer_access_token | ||
api_client = swagger_client.ApiClient(configuration=configuration) | ||
self.monitoring_event_api = MonitoringEventAPIApi(api_client) | ||
|
||
def __create_subscription_request(self, | ||
external_id, | ||
msisdn, | ||
ipv4_addr, | ||
ipv6_addr, | ||
notification_destination, | ||
maximum_number_of_reports, | ||
monitor_expire_time) -> MonitoringEventSubscriptionCreate: | ||
monitoring_type = "LOCATION_REPORTING" | ||
return MonitoringEventSubscriptionCreate(external_id, | ||
msisdn, | ||
ipv4_addr, | ||
ipv6_addr, | ||
notification_destination, | ||
monitoring_type, | ||
maximum_number_of_reports, | ||
monitor_expire_time) | ||
|
||
def create_subscription(self, | ||
netapp_id: str, | ||
external_id, | ||
misisdn, | ||
ipv4_addr, | ||
ipv6_addr, | ||
notification_destination, | ||
maximum_number_of_reports, | ||
monitor_expire_time): | ||
""" | ||
Creates a subscription that will be used to retrieve Location information about a device. | ||
:param str external_id: string (The ID of the Netapp that creates a subscription) | ||
:param str external_id: Globally unique identifier containing a Domain Identifier and a Local Identifier. <Local Identifier>@<Domain Identifier> | ||
:param str misisdn: Mobile Subscriber ISDN number that consists of Country Code, National Destination Code and Subscriber Number. | ||
:param str ipv4_addr: String identifying an Ipv4 address | ||
:param ipv6_addr: String identifying an Ipv6 address. | ||
:param notification_destination: The url that you will notifications about the location of the user | ||
:param maximum_number_of_reports: Identifies the maximum number of event reports to be generated. Value 1 makes the Monitoring Request a One-time Request | ||
:param monitor_expire_time: Identifies the absolute time at which the related monitoring event request is considered to expire | ||
""" | ||
body = self.__create_subscription_request(external_id, | ||
misisdn, | ||
ipv4_addr, | ||
ipv6_addr, | ||
notification_destination, | ||
maximum_number_of_reports, | ||
monitor_expire_time) | ||
|
||
# a monitoring event report | ||
response = self.monitoring_event_api.create_item_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_post( | ||
body, | ||
netapp_id) | ||
return response | ||
|
||
def update_subscription(self, | ||
netapp_id: str, | ||
subscription_id: str, | ||
external_id, | ||
misisd, | ||
ipv4_addr, | ||
ipv6_addr, | ||
notification_destination, | ||
maximum_number_of_reports, | ||
monitor_expire_time) -> MonitoringEventSubscription: | ||
""" | ||
Creates a subscription that will be used to retrieve Location information about a device. | ||
:param str netapp_id: string (The ID of the Netapp that creates a subscription) | ||
:param str subscription_id: string (Identifier of the subscription resource) | ||
:param str external_id: Globally unique identifier containing a Domain Identifier and a Local Identifier. <Local Identifier>@<Domain Identifier> | ||
:param str misisdn: Mobile Subscriber ISDN number that consists of Country Code, National Destination Code and Subscriber Number. | ||
:param str ipv4_addr: String identifying an Ipv4 address | ||
:param ipv6_addr: String identifying an Ipv6 address. | ||
:param notification_destination: The url that you will notifications about the location of the user | ||
:param maximum_number_of_reports: Identifies the maximum number of event reports to be generated. Value 1 makes the Monitoring Request a One-time Request | ||
:param monitor_expire_time: Identifies the absolute time at which the related monitoring event request is considered to expire | ||
""" | ||
body = self.__create_subscription_request(external_id, | ||
misisd, | ||
ipv4_addr, | ||
ipv6_addr, | ||
notification_destination, | ||
maximum_number_of_reports, | ||
monitor_expire_time) | ||
|
||
return self.monitoring_event_api.update_item_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_subscription_id_put( | ||
body, netapp_id, subscription_id) | ||
|
||
def get_all_subscriptions(self, netapp_id: str,skip:int =0, limit: int=100): | ||
""" | ||
Reads all active subscriptions | ||
:param skip: The number of subscriptions to skip | ||
:param limit: The maximum number of transcriptions to return | ||
:param str netapp_id: string (The ID of the Netapp that creates a subscription) | ||
""" | ||
|
||
return self.monitoring_event_api.read_active_subscriptions_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_get( | ||
netapp_id, | ||
skip=skip, | ||
limit=limit) | ||
|
||
def get_subscription(self, netapp_id: str, subscription_id: str) -> MonitoringEventSubscription: | ||
""" | ||
Gets subscription by id | ||
:param str netapp_id: string (The ID of the Netapp that creates a subscription) | ||
:param str subscription_id: string (Identifier of the subscription resource) | ||
""" | ||
return self.monitoring_event_api.read_item_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_subscription_id_get( | ||
netapp_id, | ||
subscription_id) | ||
|
||
def delete_subscription(self, netapp_id: str, subscription_id: str): | ||
""" | ||
Delete a subscription | ||
:param str netapp_id: string (The ID of the Netapp that creates a subscription) | ||
:param str subscription_id: string (Identifier of the subscription resource) | ||
""" | ||
return self.monitoring_event_api.delete_item_api_v13gpp_monitoring_event_v1_scs_as_id_subscriptions_subscription_id_delete( | ||
netapp_id, | ||
subscription_id) |
Oops, something went wrong.