Develop and Test IOx Applications

Create IOx Application using Docker image to host on access points

Learn how to create a Python, C, C++, and Go based IOx application and test using the Docker tools for Cisco Catalyst 9100 Family of Access Points.

To develop an IOx application, you need to do the following:

  1. Define the Dockerfile. This file contains instructions to get the base rootfs, the Python package installer, and commands to copy the Python run-time code. These instructions to the Docker daemon assist in building the Docker image.
  2. Create a Docker image containing the required binaries and base rootfs. Depending on the CPU architecture of your Cisco Catalyst 9100 Family of Access Points, choose the appropriate base rootfs (32-bit or 64-bit).

    Note: Use ap3k rootfs for 32-bit CPU architecture and ir1101 for 64-bit.

  3. Define the package.yaml (package description file) for your IOx application.
  4. Create the IOx app using the image created in step 2 and the package.yaml.

Create a Python IOx Application

The following Python configurations need to be done on the virtual machine containing the Docker daemon and the IOxclient binary.

Create an Application Directory

To create an application directory, use the below Python configuration:

$ mkdir python-app
$ cd python-app
$ vi hello-world.py

Write a Python Application

Here is an example of a Python application, hello-world.py:

#!/usr/bin/python print('Hello, world!')

Create a Docker Image with Python Application

Follow the below procedure to create a Python IOx application.

Here is a sample Dockerfile:


# IOx app needs base-rootfs. Select either 32 or 64 bit version by uncommenting out one of the below link.
# Use below link for 32 bit Access Points
# FROM devhub-docker.cisco.com/iox-docker/ap3k/base-rootfs:latest
# Use below link for 64 bit Access Points
# FROM devhub-docker.cisco.com/iox-docker/ir1101/base-rootfs:latest
 
RUN opkg update && opkg install python
COPY hello-world.py /usr/bin/hello-world.py
RUN chmod 777 /usr/bin/hello-world.py

Build the docker image using the above Dockerfile

$ sudo docker build -t iox-hello-py .

Use the docker images command to find the built-in docker images:

# docker images

REPOSITORY                                            TAG                 IMAGE ID            CREATED              SIZE

iox-hello-py                                          latest              e34fe3c89ae1        About a minute ago   29.2MB

Test Your Application Locally Using Docker Tools

The built-in Docker image can be tested on your VM containing Docker daemon as shown below:

$ docker run -d iox-hello-py

29a3161dfb9435809b65b3bcf5788ca0fd0dcd1f6f97fd5ded501fe782fff6da

$ docker run -ti iox-hello-py /bin/sh

/ # python /usr/bin/hello-world.py 

Hello, world!

To convert the docker image to an IOx app, refer to the Create an IOx application package section.

Create a C, C++ Application

For C and C++ applications, you need to configure the following on the virtual machine containing the Docker daemon and the IOxclient binary.

Create an Application Directory

To create an application directory, use the below C configuration:

$ mkdir c-app
$ cd c-app
$ vi hello-world.c

Write a C Application

Here is a sample C application, hello-world.c:

# include <stdio.h>
 
int main()
{ 
   printf("Hello World!");
   return 0;
}

Create a hello-world Binary

Depending on the AP's architecture (64-bit or 32-bit binary), perform the below configurations:

Install GCC/G++ Cross Compilers

# All the APs are based on ARM architecture. We need to cross-compile the C Application for ARM architecture.

# To generate binaries for 32-bit ARM architecture, install the following packages:
$ sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

# To generate 64-bit ARM binaries, install the following packages:
$ sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

Cross-Compile a C Application for ARM architecture

To cross-compile a C Application, use the appropriate configuration given below:

$ aarch64-linux-gnu-gcc hello-world.c -o hello-world-64-bit

$ arm-linux-gnueabi-gcc hello-world.c -o hello-world-32-bit

Create a Docker Image with a C Application

Follow the below procedure to create a C IOx application.

Here is a sample Dockerfile:

# IOx app needs base-rootfs. Select either 32 or 64 bit version by uncommenting out one of the below links.
# Use the below link for 32-bit Access Points
# FROM devhub-docker.cisco.com/iox-docker/ap3k/base-rootfs:latest
# Use the below link for 64-bit Access Points
# FROM devhub-docker.cisco.com/iox-docker/ir1101/base-rootfs:latest
 
# Copy 32 bit binary if the IOx app is for 32 architecture, or the 64-bit binary for a 64-bit IOx app.
COPY hello-world-(32/64)-bit /usr/bin/hello-world 
RUN chmod 777 /usr/bin/hello-world

Tag the Docker image build with a name, say, iox-hello-c.

$ docker build -t iox-hello-c .

Check your built-in image.

# docker images

REPOSITORY             TAG                 IMAGE ID                 CREATED                          SIZE
iox-hello-c                 latest              b4323da25fdc        About a minute ago        23.9MB

Test the Application Locally Using Docker Tools

Run the image locally to ensure it works.

$ docker run -d iox-hello-c
22d5578524a95fcf04e20593a8de478f6c301994f3716652f273eddb802b273b

$ docker run -ti iox-hello-c /bin/sh

/ # ./usr/bin/hello-world 
Hello, World!

To convert the docker image to an IOx app, refer to the Create an IOx application package section.

Create a Go Application

The following Go configurations need to be done on the virtual machine containing the Docker daemon and the IOxclient binary.

Create an Application Directory

To create an application directory, use the below Go configuration:

$ mkdir go-app
$ cd go-app
$ vi hello-world.go

Write a Go Application

Here is a sample Go application, hello-world.go.

package main
import "fmt"
func main()
{
    fmt.Println("Hello, World!")
}

Install Go on Ubuntu

To install Go on Ubuntu, use the below configuration:

$ sudo apt install golang-go

Cross-Compile a Go Application for ARM Architecture

To cross-compile a Go Application, use the appropriate configuration given below:

# All the APs are based on ARM architecture. We need to cross-compile the Go Application for ARM architecture.
$ GOARCH=arm go build hello-world.go

#  if the IOx app is for an AP with 64-bit ARM architecture, use the following command:
$ GOARCH=arm64 go build hello-world.go

Create a Docker Image with the Go Application

Let us create a docker image with the above application in it. Since Access Points are based on ARM architecture, use the latest ARM base rootfs to create the docker image.

Here is a sample Dockerfile.

# IOx app needs base-rootfs. Select either 32 or 64 bit version by uncommenting out one of the below link.
# Use below link for 32 bit Access Points
# FROM devhub-docker.cisco.com/iox-docker/ap3k/base-rootfs:latest
# Use below link for 64 bit Access Points
# FROM devhub-docker.cisco.com/iox-docker/ir1101/base-rootfs:latest

COPY hello-world /usr/bin/hello-world
RUN chmod 777 /usr/bin/hello-world

Build the docker image and tag it iox-hello-go.

$ docker build -t iox-hello-go .

To check the build image, run the following command:

# docker images

REPOSITORY                  TAG             IMAGE ID                  CREATED                       SIZE
iox-hello-go                   latest           a0e5d63cb2e5        About a minute ago     27.7MB

Test your application locally using docker tools

Run the image locally to ensure it works.

$ docker run -d iox-hello-go
da9d38fab8c92167966d17a1d61e9774077cc636937c254937b57c5b2bf61272

$ docker run -ti iox-hello-go /bin/sh
/ # ./usr/bin/hello-world 

Hello, World!