Creating 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 a deletion method. 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 DeviceIpv4Addr
# We begin by creating a Network-as-Code client
client = nac.NetworkAsCodeClient(
# The "" should be replaced
# with a test device copied from your Developer Sandbox
# Or you can identify a device with its ID,
# IP address(es) and optionally, a phone number
my_device = client.devices.get(
    ipv4_address = DeviceIpv4Addr(
    ipv6_address = "2001:db8:1234:5678:9abc:def0:fedc:ba98",
    # The phone number accepts the "+" sign, but not spaces or "()" marks
    phone_number = "36721601234567"
# ...and create a QoD session for the device
my_session = my_device.create_qod_session(
# Let's confirm that the device has the newly created session
# Finally, remember to clear out the sessions for the device

The programming of the mobile network happens when we call the method to create a session. We instruct Network as Code to set up a QoD Session between the device and the service identified by the IP address and 2001:db8:1234:5678:9abc:def0:fedc:ba98. In the call parameters, we also specify a session Quality of Service profile (in this case a DOWNLINK_L_UPLINK_L) which will ensure maximum bandwidth between these two endpoints.

The sessions() method is used to get all sessions of the device and check whether we successfully created the QoD session. A device could have multiple sessions programmed for it. Then, a method is used to destroy (clear) all sessions. Remember to do this to avoid unexpected costs over time.

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

profileThe QoS profile that indicates the connection type to be prioritized between two points.
service_ipv4The service identified by the application IPv4 address (optional).
service_ipv6The service identified by the application IPv6 address (optional).

If you don't want to use keywords in Python:

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(


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 optional parameters to the session creation method:

service_portsTo specify a list of ports or a range of ports for a service
device_portsTo specify a list of ports or a range of ports for a device

You can use a range of ports:

from network_as_code.models.session import PortRange
my_session = my_device.create_qod_session(
    service_ports=PortsSpec(ranges=[PortRange(start=80, end=443)]),

Or you can also specify a list of ports:

from network_as_code.models.session import PortsSpec
my_session = my_device.create_qod_session(
    # You can also use port lists
    service_ports=PortsSpec(ports=[80, 443]),
    device_ports=PortsSpec(ports=[1600, 2000]),

This may be useful in cases where you want to set up session between specific applications.

Last updated on May 23, 2024