Nokia logo
DocumentationBlogPricing
Request access

Getting Started

Let's get started with Network as Code! This quick-start guide will help you create an account, get your application keys, and set up your development environment, so that you too can start programming global mobile networks.

Initial setup

Request access

Use the Request Access form accessible from the top-right corner of the page.

Get your first App Key

Please, be careful with your App Keys. Treat them like secrets or passwords. Do not commit them to Git or show them publicly anywhere. Stolen App Keys may be used for malicious purposes and can cause harm in the wrong hands.

  1. When your account is active, click the button to Log in again to on our Network-as-Code developer portal. Your user name should appear at the top-right corner of the page when you're logged in, click it and head over to My dashboard.

    NOTE: A default application and authorization key are automatically created for you on your dashboard.

  2. From the Handy Links section, you can create and manage organizations, view analytics and billing details! Your default application key is right below this section and you can show, hide or copy it to your clipboard.

  3. To access the API Hub, click the Create and Manage Organizations option from the Handy Links section and then API Hub. You will see all your available APIs and from there you can subscribe to them.

Subscribe to APIs and test them

From the API Hub:

  1. Select a specific API to test, for example the Quality-of-service on Demand (QoD) one.
  2. Click the button Subscribe to Test.
  3. Then, all you'll need to do is choose the right plan for you and click Subscribe to confirm your selection. A message for successful subscription should show on the screen!
  4. Finally, go back to the API you selected and click Test Endpoint to use it.

Creating your first Network as Code project

Create a new Python project

We recommend using a dependency management tool, such as venv or Poetry, to manage your Python project's dependencies. This guide will use venv for the sake of simplicity.

Open up the terminal and create a new directory for you project. Let's call it nac-hello-world.

mkdir nac-hello-world

Then, move into this newly created directory, create a virtual environment called env and finally, activate it.

cd nac-hello-world
python3 -m venv env
source env/bin/activate

Install the Network as Code Python SDK

Use pip to install the latest version of the Network as Code Python SDK.

NOTE: Before installing the NaC package, make sure you are using the Python version 3.9 or higher.

pip install network_as_code

Make your first Network as Code program

Open the project directory (nac-hello-world) in your favorite code editor, such as Visual Studio Code, Emacs, or Vim and create a file called main.py.

Copy the following code example into main.py:

import network_as_code as nac
 
# We begin by creating a Network-as-Code client
client = nac.NetworkAsCodeClient(
    token="<your-application-key-here>"
)

What does this code do? It creates a new NetworkAsCodeClient object which will store your application key. The NetworkAsCodeClient is the entry-point to all the functionality Network as Code provides.

Replace the <your-application-key-here> with the App Key you copied earlier from My dashboard section.

Now, with everything configured, we can have a sneak peek at doing some actual network programming using sessions!

Trying out a Quality-of-service on Demand (QoD) session

Network as Code provides a feature called QoD which allows simple management of a device's bandwidth and latency, among other things. With our project skeleton already ready we can try creating a QoD session for a dummy device.

Authorization: Network as Code allows querying any device for its location, modify their network parameters, find out whether the device has been connected to the Internet or not and so on. However, remember that you can only perform these actions against devices you are authorized to use. Remember to read our Consent and identity management policy carefully.

Replace the existing contents of main.py with the following code example:

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>"
)
 
# Then, create a device object
# Identify the device with its ID, IP address(es) and optionally, a phone number
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"
)
 
# ...and create a QoD session for the device
session = 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(device.sessions())
 
# Finally, remember to clear out the sessions for the device
device.clear_sessions()

The programming of the mobile network happens when we call the create_session() method. 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 profile (in this case a DOWNLINK_L_UPLINK_L) which will ensure maximum bandwidth between these two endpoints.

The device.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, device.clear_sessions() is used to destroy 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.

What's next?

You've now set up everything you need to use Network as Code and had a quick taste of how it is used to program the network. Feel free to browse our growing catalog of features to learn more!

Check out our documentation for the following features:

We hope you enjoy using Network as Code!

Last updated on July 31, 2023

On this page
Initial setupRequest accessGet your first App KeySubscribe to APIs and test themCreating your first Network as Code projectCreate a new Python projectInstall the Network as Code Python SDKMake your first Network as Code programTrying out a Quality-of-service on Demand (QoD) sessionDevice object parametersWhat's next?