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(
    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)

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:

ParametersDescription
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.

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