Creating a Session with duration
Applications can create a QoD session with a required Quality of Service (QoS) profile, which is the technology underpinning QoD. A QoD session has a life cycle so you can keep track of different QoD statuses.
Below, you will learn how to set up a QoD session with duration. Also, you can terminate a QoD session whenever needed. If the application does not specify a QoD session duration, nor terminates it, then it will be in use for a maximum of 24 hours, after which it would be terminated automatically.
Specifying session duration
You can create a QoD session with duration to instruct how the network should behave during a specified amount of time.
The code below also creates a Network as Code client using an application key accessible from your Dashboard
and identifies a mobile network device in multiple ways (IP addresses, port, etc).
Learn more about the client
and device objects.
Remember that devices cannot be identified by their public IPv4 address alone.
You will need to provide either their public address and port or public and private addresses.
Learn more
about how the DeviceIPv4Addr
model works using NAT technology.
import network_as_code as nac
from network_as_code.models.device import Device, DeviceIpv4Addr
# Begin by creating a client for Network as Code:
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>",
)
# Then, create a device object.
# Remember to assign its Device ID and current IP address(es):
my_device = client.devices.get(
"device@testcsp.net",
ipv4_address=DeviceIpv4Addr(
public_address="233.252.0.2",
private_address="192.0.2.25",
public_port=80
),
# The phone number accepts the "+" sign, but not spaces or "()" marks
phone_number="36721601234567"
)
# Create a QoD session with QOS_L (large bandwidth)
# that lasts for 3,600 seconds (1 hour):
my_session = my_device.create_qod_session(
service_ipv4="233.252.0.2",
service_ipv6="2001:db8:1234:5678:9abc:def0:fedc:ba98",
profile="QOS_L",
duration=3600
)
# Show a list of all the QoD sessions associated with a device
print(my_device.sessions())
# You can also show the duration of a given session
print(my_session.duration())
# Or use these to check when your session started/expires:
print(my_session.started_at)
print(my_session.expires_at)
Session duration parameters
What we've just done above is create a QoD session with a determined duration of 3,600 seconds (1 hour). We also used methods to show the list of sessions created for a device and their duration. Here are the parameters used and their brief description:
Parameters | Description |
---|---|
profile | The QoS profile that will ensure a maximum bandwidth between these two points. |
service_ipv4 | The service identified by the application IPv4 address and Port (optional). |
service_ipv6 | The service identified by the application IPv6 address and Port (optional). |
duration | This will tell when the QoD session should end. |
Keywords:
If you want to create the QoD session object without passing its parameters by name (keywords), then remember that their ordering will be important for your code to work properly. In which case, you will need to inform the QoS profile before the IP address(es). For example:
session = my_device.create_qod_session(
"DOWNLINK_L_UPLINK_L",
"192.0.2.25",
"2001:db8:1234:5678:9abc:def0:fedc:ba98",
3600
)
Keep in mind: The duration is given in seconds with a default value and upper limit at 24 hours. For example, if the duration desired is for one hour, then the value in seconds should be
3600
.
Last updated on July 25, 2024