Create a QoD Session
This helps application to create QoD session with a required profile.
A QoD Session will be active until the application terminates it by using the session.delete()
operation.
If the application doesn't terminate the QoD session,
then it would be in use for a maximum of 24 hours, after which it would be terminated automatically.
Creating your first session
If you already got setup with Network as Code Getting Started steps, follow this tutorial to create your first QoD session. Also notice that in this section we will explain all the QoD features in detail.
A QoD session is created with an SDK, which will instruct how the network should behave for a particular device connected to it. This way, developers like you can decide which device or network service gets prioritized or not to ensure higher-quality and stable bandwidth use.
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):
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"
)
# Here you can create a QoD session, identify the service IP address(es) and the network profile
session = device.create_qod_session(
service_ipv4="233.252.0.2",
service_ipv6="2001:db8:1234:5678:9abc:def0:fedc:ba98",
profile="DOWNLINK_L_UPLINK_L"
)
# Show a list of all of the QoD sessions associated with a device
print(device.sessions())
Device object parameters
The snippet above identified a mobile network device in multiple ways (IP addresses, port, etc). Learn how to create a device object and understand how the DeviceIPv4Addr
model works using NAT technology.
Session parameters
- The actual network programming happens when you call the
device.create_qod_session()
method. This is where you can create a resource that will instruct Network as Code to set up a session between the device and theservice
, which identifies the application server (backend). This can be identified by application IP address and Port (optionally).
Parameters | Description |
---|---|
service_ipv4 | The service identified by the application IPv4 address and Port (optionally). |
service_ipv6 | The service identified by the application IPv6 address and Port (optionally). |
profile | The QoS profile that will ensure a maximum bandwidth between these two points. |
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 first, before the IP address(es). For example:
session = device.create_qod_session("DOWNLINK_L_UPLINK_L", "192.0.2.25", "2001:db8:1234:5678:9abc:def0:fedc:ba98")
Ports
For better control and optimized bandwidth or latency, you can also choose whether to use ports. However, the QoD feature will work even without providing them.
If you wish to use ports, provide the following parameters to the device.create_qod_session()
method:
Parameter | Purpose |
---|---|
service_ports | To specify a list of ports or a range of ports for a service |
device_ports | To specify a list of ports or a range of ports for a device |
profile | To specify the required QoS profile |
You can use a range of ports:
session = device.create_qod_session(
service_ipv4="192.0.2.25",
service_ports=PortsSpec(ranges=[PortRange(start=80, end=443)]), profile="QOS_L"
)
Or, you can also specify a list of ports:
session = device.create_qod_session(
service_ipv4="192.0.2.25",
service_ports=PortsSpec(ports=[80]),
device_ports=PortsSpec(ports=[20000]),
profile="QOS_L"
)
This may be useful in cases where you want to set up session between specific applications.