QoD sessions

Quality of Service (QoS) profilesheader link

Oftentimes, it is necessary to manage or prioritize certain connectivity characteristics over a wide area network (WAN). Network-as-Code Quality-of-service on Demand (QoD) or QoS (CAMARA) profiles allow establishing these prioritized connections between devices or services and request on-demand capabilities from the network. Read more about it on the "What is Quality of Service (QoS)?" section.

Network as Code QoS profilesheader link

You can choose the amount of bandwidth with an up/downlink profile label, according to your current demand. These are the specific Network as Code QoS profiles labels and their brief description:

QoS profile labelsNetwork Service Description
DOWNLINK_S_UPLINK_Ssmall downlink and uplink bandwidth
DOWNLINK_S_UPLINK_Msmall downlink and medium uplink bandwidth
DOWNLINK_S_UPLINK_Lsmall downlink and large uplink bandwidth
DOWNLINK_M_UPLINK_Smedium downlink and small uplink bandwidth
DOWNLINK_M_UPLINK_Mmedium downlink and medium uplink bandwidth
DOWNLINK_M_UPLINK_Lmedium downlink and large uplink bandwidth
DOWNLINK_L_UPLINK_Slarge downlink and small uplink bandwidth
DOWNLINK_L_UPLINK_Mlarge downlink and medium uplink bandwidth
DOWNLINK_L_UPLINK_Llarge downlink and large uplink bandwidth

NOTE: In each case, the network connection is given priority, which means that the network will aim at maintaining a stable connection at the desired level.

CAMARA QoS profilesheader link

QoD Sessions also support the CAMARA QoS profile labels.

NOTE: You can learn more specifically about each label or its possible constraints here.

These are the currently available ones:

QOS Profile labelsNetwork Service Description
QOS_EMaintains stable latency under congestion with limited bandwidth.
QOS_LPrioritizes the throughput up to a certain higher limit or no explicit limit.
QOS_MPrioritizes the throughput up to a certain medium limit.
QOS_SPrioritizes the throughput up to a certain lower limit.

Good to know: The 5G System throughput refers to the ratio of data that can be transmitted in units of time, for example, bits per second(bps). In this case, a maximum throughput refers to a maximum rate at which data will be transmitted.

Creating a QoD sessionheader link

Applications can create a QoD session with a required Quality of Service profile, which is the technology underpinning QoD. A QoD session has a life cycle so you can keep track of different QoD statuses. You must specify a duration, which can be up to 24 hours. You can also terminate a QoD session whenever needed to avoid unexpected costs over time.

Creating your first sessionheader link

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.

The programming of the mobile network happens when we call the method to create a QoD session. We instruct Network as Code to set up a QoD Session between the device and the service identified by the IP address 233.252.0.2 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.

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(
    token="<your-application-key-here>"
)

my_device = client.devices.get(
    ipv4_address=DeviceIpv4Addr(
        public_address="233.252.0.2",
        private_address="192.0.2.25",
        public_port=80
    ),
    ipv6_address="2001:db8:1234:5678:9abc:def0:fedc:ba98",
    # The phone number does not accept spaces or parentheses
    phone_number="+36721601234567"
)

# ...and create a QoD session for the device
my_session = my_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",
    # We create the session for 3600 seconds, so up to an hour
    duration=3600
)

Session durationheader link

You need to create a QoD session with duration to instruct how the network should behave during a specified amount of time. 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.

import network_as_code as nac

from network_as_code.models.device import 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 phone number and current IP address(es):
my_device = client.devices.get(
    ipv4_address=DeviceIpv4Addr(
        public_address="233.252.0.2",
        private_address="192.0.2.25",
        public_port=80
    ),
    # The phone number does not accept spaces or parentheses
    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
)

# You can 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)

Extending QoD sessionsheader link

It is possible to extend the length of a QoD session after the session was created. This might be handy in case an action takes longer than expected and more time needs to be assigned to the session without creating an interruption. Similar to setting an initial duration, the session duration is extended by specifying the number of seconds the session should be extended by.

Session can be extended by 300 seconds like so:

import network_as_code as nac

client = nac.NetworkAsCodeClient(token="YOUR-TOKEN")

my_device = client.devices.get(
    ipv4_address = DeviceIpv4Addr(
         public_address="233.252.0.2",
         private_address="192.0.2.25",
         public_port=80
    ),
    # The phone number does not accept spaces or parentheses
    phone_number="+36721601234567"
)

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
)

my_session.extend(300)

Portsheader link

For better control and optimized bandwidth or latency, you can also choose whether to use ports. This may be useful in cases where you want to set up session between specific applications. However, the QoD feature will work even without providing them.

You can use a range of ports:

from network_as_code.models.session import PortsSpec, PortRange

my_session = my_device.create_qod_session(
    service_ipv4="233.252.0.2",
    service_ipv6="2001:db8:1234:5678:9abc:def0:fedc:ba98",
    service_ports=PortsSpec(ranges=[PortRange(start=80, end=443)]),
    device_ports=PortsSpec(ranges=[PortRange(start=80, end=443)]),
    profile="QOS_L",
    duration=3600
)

Or you can also specify a list of ports:

from network_as_code.models.session import PortsSpec

my_session = my_device.create_qod_session(
    service_ipv4="233.252.0.2",
    service_ipv6="2001:db8:1234:5678:9abc:def0:fedc:ba98",
    service_ports=PortsSpec(ports=[80, 443]),
    device_ports=PortsSpec(ports=[1600, 2000]),
    profile="QOS_L",
    duration=3600
)

Session parametersheader link

ParametersTypeDescriptionMandatory or Optional
profilestringThe QoS profile that indicates the connection type to be prioritized between two points.Mandatory
service_ipv4stringThe service identified by the application IPv4 address.Mandatory (if no IPv6)
service_ipv6stringThe service identified by the application IPv6 address.Mandatory (if no IPv4)
service_portsintegerTo specify a list of ports or a range of ports for a service.Optional
device_portsintegerTo specify a list of ports or a range of ports for a device.Optional
durationintegerThe length of the QoD session in seconds (maximum: 86400 seconds = 24 hours).Mandatory

Managing QoD sessionsheader link

Here, we will show how to get a QoD session using multiple methods. If you previously created a session and you need to modify or delete it, you can easily retrieve it by its ID or index. You can do so by using the following examples:

Get all QoD sessionsheader link

import network_as_code as nac

from network_as_code.models.device import DeviceIpv4Addr

client = nac.NetworkAsCodeClient(
    token="<your-application-key-here>"
)

my_device = client.devices.get(
    # The phone number does not accept spaces or parentheses
    phone_number="+36721601234567"
    ipv4_address=DeviceIpv4Addr(
        public_address="233.252.0.2",
        private_address="192.0.2.25",
        public_port=80,
    ),
)

# Create a session
my_session = my_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",
    duration=3600
)

# Get all sessions
all_sessions = my_device.sessions()

# Notice how we can use the number '0'
# to retrieve our first session in this case:
first_session = all_sessions[0]

Get session by IDheader link

# Alternatively, you can get a session by its ID:
session_id = client.sessions.get(my_session.id)

Response parametersheader link

ParametersTypeDescription
idstringSession resource identifier.
profilestringThe QoS profile that indicates the connection type to be prioritized between two points.
statusstringQoD session status, whether it is REQUESTED, AVAILABLE, UNAVAILABLE.
started_atdatetimeTimezone-aware timestamp when the session started.
expires_atdatetimeTimezone-aware timestamp when the session expires.
service_ipv4stringThe service identified by the application IPv4 address.
service_ipv6stringThe service identified by the application IPv6 address.
service_portsintegerA list of ports or a range of ports for a service if defined.
device_portsintegerA list of ports or a range of ports for a device if defined.
durationintegerThe length of the QoD session in seconds (maximum: 86400 seconds = 24 hours).

Deleting a sessionheader link

In the example below, we delete specific sessions by their index or ID.

# Get all sessions
all_sessions = my_device.sessions()

# Notice how we can use the number '0'
# to get our first session, in this case:
first_session = all_sessions[0]

# Alternatively, get the session by its ID
session = client.sessions.get(my_session.id)

# Then, delete the session
my_session.delete()

Clearing all sessionsheader link

Now, since creating and maintaining sessions can cost time and effort, you can delete all QoD sessions associated with a particular device. By using the helper function to clear all session, you can retrieve a list with all the sessions created for a device, delete them and your code will return to a clear state.

# Delete all QoD sessions associated with a particular device
my_device.clear_sessions()

Last updated November 05, 2025