From ac9754e3f708e6f8a7bda89be569d89be49e297d Mon Sep 17 00:00:00 2001 From: "sunil.n" Date: Thu, 13 Nov 2025 11:36:48 +0530 Subject: [PATCH] Implement function to get NSSI based on ID Change-Id: I4aa38ee79a5fef446b9613cf42eee40f6eb826d2 Signed-off-by: sunil.n --- .../rapp-slice-prb-prediction/README.md | 54 ++++++++++++++++++++- .../src/ran_nssmf_client.py | 56 ++++++++++++++++++++++ 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/sample-rapp-generator/rapp-slice-prb-prediction/README.md b/sample-rapp-generator/rapp-slice-prb-prediction/README.md index 0fbb646..33a595f 100644 --- a/sample-rapp-generator/rapp-slice-prb-prediction/README.md +++ b/sample-rapp-generator/rapp-slice-prb-prediction/README.md @@ -254,6 +254,47 @@ The client uses the following configuration sections from `config.json`: } ``` +#### Available Methods + +##### subscribe_to_file_ready_notifications(callback_uri) +Subscribes to file-ready notifications from the RAN NSSMF for receiving performance data and configuration updates. + +**Parameters:** +- `callback_uri` (str): The URI where the RAN NSSMF should send notifications + +**Returns:** +- `requests.Response`: The response object from the POST request, or None on failure + +**Example:** +```python +response = ran_client.subscribe_to_file_ready_notifications( + "http://localhost:8080/handleFileReadyNotification" +) +if response and response.status_code == 201: + print("Successfully subscribed to notifications") +``` + +##### get_network_slice_subnet(subnet_id) +Retrieves detailed information about a specific Network Slice Subnet from the RAN NSSMF. This method enables the RAPP to query slice configuration and status information for resource optimization decisions. + +**Parameters:** +- `subnet_id` (str): The unique identifier of the Network Slice Subnet to retrieve + +**Returns:** +- `dict`: A dictionary representing the NetworkSliceSubnetDTO if successful, None otherwise + +**Example:** +```python +# Get details for a specific network slice subnet +subnet_details = ran_client.get_network_slice_subnet("9090d36f-6af5-4cfd-8bda-7a3c88fa82fa") +if subnet_details: + print(f"Slice Name: {subnet_details.get('name')}") + print(f"Slice Status: {subnet_details.get('operationalStatus')}") + print(f"PRB Allocation: {subnet_details.get('prbAllocation')}") +else: + print("Network slice subnet not found or error occurred") +``` + #### Usage Example ```python # Initialize RAN NSSMF client @@ -265,7 +306,16 @@ ran_client.get_url_from_sme() # Use the discovered or configured endpoint if ran_client.ran_nssmf_address: print(f"RAN NSSMF available at: {ran_client.ran_nssmf_address}") - # Make API calls to RAN NSSMF for slice management + + # Subscribe to file-ready notifications + response = ran_client.subscribe_to_file_ready_notifications( + "http://localhost:8080/handleFileReadyNotification" + ) + + # Get network slice subnet details + subnet_info = ran_client.get_network_slice_subnet("slice-subnet-id") + + # Make additional API calls to RAN NSSMF for slice management else: print("RAN NSSMF endpoint not available") ``` @@ -359,4 +409,4 @@ To train a new model: 3. **Configure Application**: - Update `src/config.json` with your environment settings - Configure InfluxDB connection parameters - - Set up SME endpoints if using service discovery \ No newline at end of file + - Set up SME endpoints if using service discovery diff --git a/sample-rapp-generator/rapp-slice-prb-prediction/src/ran_nssmf_client.py b/sample-rapp-generator/rapp-slice-prb-prediction/src/ran_nssmf_client.py index 39bee6f..205e814 100644 --- a/sample-rapp-generator/rapp-slice-prb-prediction/src/ran_nssmf_client.py +++ b/sample-rapp-generator/rapp-slice-prb-prediction/src/ran_nssmf_client.py @@ -91,4 +91,60 @@ class RAN_NSSMF_CLIENT(object): logger.error(f"An unexpected error occurred while subscribing: {req_err}") return None + + def get_network_slice_subnet(self, subnet_id: str): + """ + Retrieves details of a specific Network Slice Subnet from the RAN NSSMF. + + Args: + subnet_id (str): The unique identifier of the Network Slice Subnet. + + Returns: + dict: A dictionary representing the NetworkSliceSubnetDTO if successful, + None otherwise. + """ + base_url = self.ran_nssmf_address + + if not base_url: + logger.error("RAN NSSMF address is not configured. Cannot get network slice subnet.") + return None + + # Ensure base_url does not have a trailing slash + base_url = base_url.rstrip('/') + # The version v17.0.0 is used in other endpoints of the simulator + get_subnet_url = f"{base_url}/3GPPManagement/ProvMnS/v17.0.0/NetworkSliceSubnets/{subnet_id}" + + headers = { + "Accept": "application/json" + } + + logger.info(f"Getting details for Network Slice Subnet ID: {subnet_id} from: {get_subnet_url}") + + try: + response = requests.get(get_subnet_url, headers=headers, timeout=10) + + # Check for 404 Not Found specifically, as the simulator returns this for unknown IDs + if response.status_code == 404: + logger.warning(f"Network Slice Subnet with ID '{subnet_id}' not found. Status: {response.status_code}") + return None + + response.raise_for_status() # Raise an exception for other HTTP errors (4xx or 5xx) + + logger.info(f"Successfully retrieved details for Network Slice Subnet ID: {subnet_id}. Status: {response.status_code}") + # logger.debug(f"Response Body: {response.json()}") # Uncomment for detailed debugging + return response.json() # Return the parsed JSON response (NetworkSliceSubnetDTO) + + except requests.exceptions.HTTPError as http_err: + # This will catch errors from response.raise_for_status() for non-404 codes + logger.error(f"HTTP error occurred while getting network slice subnet '{subnet_id}': {http_err} - Response: {http_err.response.text}") + except requests.exceptions.ConnectionError as conn_err: + logger.error(f"Connection error occurred while getting network slice subnet '{subnet_id}': {conn_err}") + except requests.exceptions.Timeout as timeout_err: + logger.error(f"Timeout error occurred while getting network slice subnet '{subnet_id}': {timeout_err}") + except requests.exceptions.RequestException as req_err: + logger.error(f"An unexpected error occurred while getting network slice subnet '{subnet_id}': {req_err}") + except json.JSONDecodeError as json_err: + logger.error(f"Failed to decode JSON response for network slice subnet '{subnet_id}': {json_err} - Response text: {response.text if 'response' in locals() else 'N/A'}") + + return None \ No newline at end of file -- 2.16.6