Creating a Session with duration

This helps the application to create a QoD session with the required profile for a certain duration. A QoD session would then be terminated as soon as this time has elapsed. The application can however terminate the QOD session earlier than the specified duration by deleting it.

Specifying session duration

You can create a QoD session with duration to instruct how the network should behave during a specified amount of time.

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(
# Then, create a device object.
# Remember to assign its Device ID and current IP address(es):
my_device = client.devices.get(
    ipv4_address = DeviceIpv4Addr(
    # 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(
# Show a list of all the QoD sessions associated with a device
# You can also show the duration of a given session
# Or use these to check when your session started/expires:

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 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:

profileThe QoS profile that will ensure a maximum bandwidth between these two points.
service_ipv4The service identified by the application IPv4 address and Port (optional).
service_ipv6The service identified by the application IPv6 address and Port (optional).
durationThis will tell when the QoD session should end.


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(

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 May 23, 2024