Developer Documentation > Quick Start Guide
Developing Network Aware Applications with Shabodi’s NA-AEP
This sample code is for developing an intelligent video surveillance application with functionality to dynamically change the video quality and to ensure the availability of required bandwidth based on the detection of events (in this case motion). This helps in optimal bandwidth utilization as when there is no motion, video quality can be downgraded and streamed with the allocation of low bandwidth.
Traditionally, this would require complex integration with the underlying advanced network infrastructure and understanding of varied vendor landscape. However, with Shabodi’s Network-Aware Application Enablement Platform (NA-AEP), developing network-aware applications requires a developer understanding of REST APIs and other telecom complexities are abstracted by Shabodi NA-AEP.
This is a sample application showing integration with Shabodi’s NA-AEP including:
- Registration of application (On-boarding)
- Secure authentication using oAuth2 (one of the supported security methods) and how to generate token.
- On event (motion) detection, dynamically adjusting video resolution and ensuring sufficient bandwidth by using Shabodi NA-AEP Quality on Demand (QoD) API
Application Registration with NA-AEP (Onboarding) using OTT (One Time Token) generated during pre-onboarding.
import requests
from requests_futures.sessions import FuturesSession
session = FuturesSession()
def onboard_application(ott):
url = f"http://{aep_host}:8561/api-invoker-management/v1/onboardedInvokers"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {ott}"
}
data = {
"description": "Sample app description",
"direction": "DL",
"traffic": "TCP",
"ipv4": "x.x.x.x",
"port": 0000
}
response_data = session.post(url, headers=headers, json=data).json()
client_id = response_data["apiInvokerId"]
client_secret = response_data["onboardingInformation"]["onboardingSecret"]
void onboard_Application(const std::string& ott) {
std::string url = "http://" + aepHost + ":8561/api-invoker-management/v1/onboardedInvokers";
json requestBody = {
{"description", "Autonomous Robotic Application"},
{"direction", "BOTH"},
{"traffic", "TCP"},
{"ipv4", "x.x.x.x"},
{"port", 8080}
};
json response = sendPostRequest(url, requestBody, ott);
std::string clientId = extractClientId(response);
std::string clientSecret = extractClientSecret(response);
}
public static void onboard_Application(String ott) throws Exception {
String url = "http://" + AEP_HOST + ":8561/api-invoker-management/v1/onboardedInvokers";
// Prepare the request body with application details
String requestBody = "{" +
"\"description\": \"Telemedicine App\"," +
"\"direction\": \"BOTH\"," +
"\"traffic\": \"UDP\"," +
"\"ipv4\": \"x.x.x.x\"," +
"\"port\": 5060" +
"}";
// Send the onboarding request to AEP
HttpResponse response = sendPostRequest(url, requestBody, ott);
// Extract the clientId and clientSecret from the response
String clientId = extractClientId(response);
String clientSecret = extractClientSecret(response);
}
On successful onboarding, the application is provided with “client_id” and “client_secret”, to be used for secure API invocations.
Secure Authentication
def get_token(client_id, client_secret):
url = f"http://{aep_host}:31002/security/v1/token"
headers = {
"Content-Type": "application/json"
}
data = {
"client_id": client_id,
"client_secret": client_secret
}
response_data = requests.post(url, headers=headers, json=data).json()
token = response_data["access_token"]
std::string get_Token(const std::string& clientId, const std::string& clientSecret) {
std::string url = "http://" + aepHost + ":31002/security/v1/token";
json requestBody = {
{"client_id", clientId},
{"client_secret", clientSecret}
};
json response = sendPostRequest(url, requestBody);
return extractAccessToken(response);
}
public static String get_Token(String clientId, String clientSecret) throws Exception {
String url = "http://" + AEP_HOST + ":31002/security/v1/token";
// Prepare the request body with clientId and clientSecret
String requestBody = "{" +
"\"client_id\": \"" + clientId + "\"," +
"\"client_secret\": \"" + clientSecret + "\"" +
"}";
// Send the token request to AEP
HttpResponse response = sendPostRequest(url, requestBody);
// Extract the access token from the response
String accessToken = extractAccessToken(response);
return accessToken;
}
Using “client_id” and “client_secret” generated during onboarding, a token will be generated after successful authentication, for use in subsequent API invocations.
Quality On Demand (QoD) API – Bandwidth
def set_bandwidth(max_bitrate):
url = f"http://{aep_host}:32398/qos/v1/bandwidth"
headers = {
"Content-type": "application/json",
"Authorization": f"Bearer {token}"
}
data = {
"device": {
"deviceId": 1
},
"maxBitRate": max_bitrate,
"direction": "downlink"
}
session.post(url, headers=headers, json=data)
void set_Bandwidth(int maxBitrate, const std::string& token) {
std::string url = "http://" + aepHost + ":32398/qos/v1/bandwidth";
json requestBody = {
{"device", {{"deviceId", 1}}},
{"maxBitRate", maxBitrate},
{"direction", "downlink"}
};
sendPostRequest(url, requestBody, token);
}
public static void set_Bandwidth(int maxBitrate, String token) throws Exception {
String url = "http://" + AEP_HOST + ":32398/qos/v1/adapt";
// Prepare the request body with the desired maxBitrate
String requestBody = "{\"maxBitrate\": " + maxBitrate + "}";
// Send the QoS adaptation request to AEP
sendPostRequest(url, requestBody, token);
}
This “set_bandwidth” function allows dynamic adjustment of bandwidth allocated to a specific device using Shabodi’s simplified QoS API. By making a POST request with the desired maxBitRate, you can control the network resources dynamically.
Sample Application with Motion Event
HIGH = {"fps": 60, "resolution": "1920x1080"}
LOW = {"fps": 15, "resolution": "640x480"}
@app.route("/eventstarted", methods=["GET"])
def event_started():
set_bandwidth(5000) # Set bandwidth to 5 Mbps
change_resolution(HIGH)
return "Success", 200
@app.route("/eventexpired", methods=["GET"])
def event_expired():
set_bandwidth(1000) # Set bandwidth to 1 Mbps
change_resolution(LOW)
return "Success", 200
const std::map> HIGH = {
{"fps", 60},
{"resolution", "1920x1080"}
};
const std::map> LOW = {
{"fps", 15},
{"resolution", "640x480"}
};
std::string eventStarted() {
setBandwidth(5000); // Set bandwidth to 5 Mbps
changeResolution(HIGH);
return "Success";
}
std::string eventExpired() {
setBandwidth(1000); // Set bandwidth to 1 Mbps
changeResolution(LOW);
return "Success";
}
public static final Map HIGH = Map.of(
"fps", 60,
"resolution", "1920x1080"
);
public static final Map LOW = Map.of(
"fps", 15,
"resolution", "640x480"
);
@GetMapping("/eventstarted")
public ResponseEntity eventStarted() {
setBandwidth(5000); // Set bandwidth to 5 Mbps
changeResolution(HIGH);
return ResponseEntity.ok("Success");
}
@GetMapping("/eventexpired")
public ResponseEntity eventExpired() {
setBandwidth(1000); // Set bandwidth to 1 Mbps
changeResolution(LOW);
return ResponseEntity.ok("Success");
}
This sample application on detecting an event (motion), dynamically increases the bandwidth to 5 Mbps using Shabodi’s NA-AEP to support changing the video resolution to high quality. Once the event expires, it reverts to a low resolution and reduces the bandwidth to 1 Mbps to optimize resource usage.
Shabodi’s Network-Aware Application Enablement Platform (NA-AEP) simplifies the development of applications that interact with advanced networks like 5G. By abstracting the intricacies of network protocols and providing a unified, developer-friendly API, Shabodi enables you to create intelligent, network-aware applications more efficiently.
Whether you’re building video surveillance systems, AR/VR experiences, industrial IoT solutions, or any other application that requires dynamic network control, Shabodi’s NA-AEP streamlines the process and allows you to focus on delivering exceptional user experiences.
To learn more about Shabodi’s NA-AEP and how it can benefit your applications, visit shabodi.com.