Creating a QoD session

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. Also, you can specify a duration or terminate a QoD session whenever needed. If the application does not specify a QoD session duration, nor terminates it, then it will 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. The code below also creates a Network as Code client using an application key accessible from your Dashboard and identifies a mobile network device in multiple ways (IP addresses, port, etc). Learn more about the client and device objects.

Note that devices cannot be identified by their public IPv4 address alone. You will need to provide either their public address and port or public and private addresses. Learn more about how the DeviceIPv4Addr model works using NAT technology.

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>"
)
 
# "device@testcsp.net" 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(
    "device@testcsp.net",
    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 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(
    service_ipv4="233.252.0.2",
    service_ipv6="2001:db8:1234:5678:9abc:def0:fedc:ba98",
    profile="DOWNLINK_L_UPLINK_L"
)
 
# Let's confirm that the device has the newly created session
print(my_device.sessions())
 
# Finally, remember to clear out the sessions for the device
my_device.clear_sessions()

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.

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.

Session parameters

ParametersDescription
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(
    "DOWNLINK_L_UPLINK_L",
    "233.252.0.2",
    "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 optional parameters to the session creation method:

ParameterPurpose
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 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",
)

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

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

Last updated on July 09, 2024