Building an IOx Application for the IE 4000

This section provides an example of building an IOX application for an IE 4000 in an IOx software development environment (SDE).

In the following steps, you will see how the Cisco IOx SDE uses a virtualization layer on an x86_64-bit build machine that enables a Power PC 32-bit environment to run on that machine. By emulating a Power PC 32-bit CPU in this way, you can cross compile code for a Power PC 32-bit IE 4000 target device without explicitly using a cross compiler.

Compiler

If you have not already loaded the IOx SDE, go to https://developer.cisco.com/docs/iox/#!iox-resource-downloads/downloads and scroll down to IOx SDE.

Testing and Developing an Application in the IOx SDE

  1. In the IOx SDE, use the following commands to run the base image for the IE 4000 and install all build dependencies for the application that you are building. In the fourth command, the base image is a Power PC binary.

    $ mkdir tcpdump-app
    $ cd tcpdump-app
    $ mkdir tcpdump-bin
    $ docker run -v `pwd`/tcpdump-bin:/opt/build -it devhub-docker.cisco.com/iox-docker/ie4k/base-rootfs:yocto-1.7.2

  2. Run the IE 4000 Docker base image and map the host directory “`pwd`/tcpdump-bin” to the "/opt/build" directory inside the container file system.

    Now you are in the running Docker container, and the prompt changes to /#.

  3. Enter the following command to install the build dependencies. In this command, “install iox-toolchain” installs the toolchain that builds the Power PC binaries that that the application requires. The iox-toolchain component is used only in the development environment and is not packaged into the final application.

    / # opkg update && opkg install iox-toolchain bison flex

 

  1. Enter the following commands to download and untar the tcpdump and libpcap sources from the tcpdump official archive, https://www.us.tcpdump.org/release/.

    The versions of the tcpdump and libpcab used here are compatible with the Docker base image for the IE 4000.
    / # mkdir tcpdump
    / # cd tcpdump/
    /tcpdump # wget https://www.us.tcpdump.org/release/tcpdump-4.7.4.tar.gz
    --2018-10-12 21:11:38-- https://www.us.tcpdump.org/release/tcpdump-4.7.4.tar.gz
    Resolving proxy-wsa.esl.cisco.com... 173.36.240.172
    Connecting to proxy-wsa.esl.cisco.com|173.36.240.172|:80... connected.
    Proxy request sent, awaiting response... 200 OK
    Length: 1153657 (1.1M) [application/octet-stream] Saving to: 'tcpdump-4.7.4.tar.gz' 100%[=============================================================================>] 1,153,657 880KB/s in 1.3s

    2018-10-12 21:11:40 (880 KB/s) - 'tcpdump-4.7.4.tar.gz' saved [1153657/1153657]

    /tcpdump # wget https://www.us.tcpdump.org/release/libpcap-1.6.1.tar.gz
    --2018-10-12 21:11:55-- https://www.us.tcpdump.org/release/libpcap-1.6.1.tar.gz
    Resolving proxy-wsa.esl.cisco.com... 173.36.240.184
    Connecting to proxy-wsa.esl.cisco.com|173.36.240.184|:80... connected. Proxy request sent, awaiting response... 200 OK
    Length: 651061 (636K) [application/octet-stream]
    Saving to: 'libpcap-1.6.1.tar.gz'

    100%[=============================================================================>] 651,061 862KB/s in 0.7s

    2018-10-12 21:11:57 (862 KB/s) - 'libpcap-1.6.1.tar.gz' saved [651061/651061]

    /tcpdump # tar -xf tcpdump-4.7.4.tar.gz
    /tcpdump # tar -xf libpcap-1.6.1.tar.gz  

  2. Enter the following commands to configure and build libpcap and tcpdump, and to install the binaries under "/opt/build":
    /tcpdump # cd libpcap-1.6.1/

    /tcpdump/libpcap-1.6.1 # ./configure --prefix=/opt/build/
    /tcpdump/libpcap-1.6.1 # make
    /tcpdump/libpcap-1.6.1 # make install

    /tcpdump/libpcap-1.6.1 # cd ../tcpdump-4.7.4/
    /tcpdump/tcpdump-4.7.4 # ./configure --prefix=/opt/build/
    /tcpdump/tcpdump-4.7.4 # make
    /tcpdump/tcpdump-4.7.4 # make install  

  3. To confirm that lib and bin are installed under “/opt/build,” enter the following commands:

    /tcpdump/tcpdump-4.7.4 # ls /opt/build
    bin include lib sbin share
    /tcpdump/tcpdump-4.7.4 # exit

  4. To verify that the binaries have copied out from the container, enter the following commands.

    Note: The "/opt/build" directory in the container was mapped to the directory "~/tcpdump-app/tcpdump-bin" in the host system.

    $ cd ~/tcpdump-app
    $ ls -l tcpdump-bin
    drwxr-xr-x 2 root root 4096 Oct 12 22:43 bin
    drwxr-xr-x 3 root root 4096 Oct 12 22:43 include
    drwxr-xr-x 2 root root 4096 Oct 12 22:43 lib
    drwxr-xr-x 2 root root 4096 Oct 12 22:52 sbin
    drwxr-xr-x 3 root root 4096 Oct 12 22:43 share

 

Building the Target Docker Image

  1. Use the following command to create a Dockerfile that copies the built tcpdump binaries and libraries into a Docker base image. This file also sets the tcpdump binary as the target and redirects the output log to the /data/logs/tcpdump.log file.

    Note: The iox-toolchain that you used during the application development steps is not installed in this base image.

    $ **cat Dockerfile **
    FROM devhub-docker.cisco.com/iox-docker/ie4k/base-rootfs:yocto-1.7.2
    COPY tcpdump-bin/out/ /
    CMD ["tcpdump -i eth0 > /data/logs/tcpdump.log"]

  2. Use the following command to build the Docker image:

    $ docker build -t ie4k-tcpdump .
    Sending build context to Docker daemon 27.29MB
    Step 1/3 : FROM devhub-docker.cisco.com/iox-docker/ie4k/base-rootfs:yocto-1.7.2
    ---> 0ec1d65ae4c6
    Step 2/3 : COPY tcpdump-bin/out/ /
    ---> Using cache
    ---> 04f9e31780a7
    Step 3/3 : CMD tcpdump -i eth0 > /data/logs/tcpdump.log
    ---> Running in 6e5a6580d198
    ---> 5cdcb8e8ccc5
    Removing intermediate container 6e5a6580d198
    Successfully built 5cdcb8e8ccc5
    Successfully tagged ie4k-tcpdump:latest

 

Packaging the Docker Image as an IOx Application

Use the following commands to use the ioxclient to convert the above image into an IOx app package:

$ mkdir pkg

$ ioxclient docker pkg ie4k-tcpdump pkg/
Currently active profile : ie4k
Command Name: docker-package
Warning: package.yaml not present in project folder. Will attempt to generate one.
No app type specified.
Generating IOx package of type docker with rootfs consisting of a single layer(ext2)
Docker image rootfs size in 1M blocks: 22
Creating iox package with rootfs size in 1M blocks: 27
Finding the minimum schema version for the descriptor file
Setting the descriptor schema version to 2.2
Validating generated descriptor file.
Validating descriptor file /tmp/desc122942266 with package schema definitions
Parsing descriptor file..
Found schema version 2.2
Loading schema file for version 2.2
Validating package descriptor file..
File /tmp/desc122942266 is valid under schema version 2.2
Parsing Package Metadata file : /home/ie4k/projects/tcpdump-app/pkg/.package.metadata
Updated package metadata file : /home/ie4k/projects/tcpdump-app/pkg/.package.metadata
No rsa key and/or certificate files provided to sign the package
Checking if package descriptor file is present..
Skipping descriptor schema validation..
Created Staging directory at : /tmp/225500497
Copying contents to staging directory
Creating an inner envelope for application artifacts
Including rootfs.img
Generated /tmp/225500497/artifacts.tar.gz
Calculating SHA1 checksum for package contents..
Parsing Package Metadata file : /tmp/225500497/.package.metadata
Updated package metadata file : /tmp/225500497/.package.metadata
Root Directory : /tmp/225500497
Output file: /tmp/525807740
Path: .package.metadata
SHA1 : fccf55299ac95401dbc778399df138360d8f7151
Path: artifacts.tar.gz
SHA1 : c44f0dfa62d0b124649d3aee3ec1b39d73acd407
Path: package.yaml
SHA1 : 927ee9f231e5e4bc19319f68d4e4c43726fd8dbb
Generated package manifest at package.mf
Generating IOx Package..
Package docker image ie4k-tcpdump at /home/ie4k/projects/tcpdump-app/pkg/package.tar

Installing and Running the Application on a Physical IE 4000

Use the following commands to install and run the application on the IE 4000:

$ ioxclient app in test_tcpdump package.tar
Currently active profile : ie4k
Command Name: application-install
Saving current configuration
Installation Successful. App is available at : https://1.100.30.166:8443/iox/api/v2/hosting/apps/test_tcpdump
Successfully deployed

$ ioxclient app act test_tcpdump
Currently active profile : ie4k
Command Name: application-activate
App test_tcpdump is Activated

$ ioxclient app start test_tcpdump
Currently active profile : ie4k
Command Name: application-start
App test_tcpdump is Started

$ ioxclient app console test_tcpdump
Currently active profile : ie4k
Command Name: application-console
Console setup is complete..
Running command : [ssh -p 22 -i test_tcpdump.pem appconsole@1.100.30.166]
/ # / # ps
PID USER VSZ STAT COMMAND
1 root 6296 S tcpdump -i eth0
36 root 3948 S /bin/sh
37 root 3948 R ps
/ #
/ # tail -f /data/logs/tcpdump.log
06:32:24.147857 IP 10.31.100.1 > iox-nat0-0: ICMP echo request, id 9060, seq 0, length 64
06:32:24.148043 IP iox-nat0-0 > 10.31.100.1: ICMP echo reply, id 9060, seq 0, length 64
06:32:25.148865 IP 10.31.100.1 > iox-nat0-0: ICMP echo request, id 9060, seq 1, length 64
06:32:25.148991 IP iox-nat0-0 > 10.31.100.1: ICMP echo reply, id 9060, seq 1, length 64
06:32:25.447586 IP iox-nat0-0.41922 > 10.31.100.1.domain: 11218+ PTR? 1.100.31.10.in-addr.arpa. (42)
06:32:26.150037 IP 10.31.100.1 > iox-nat0-0: ICMP echo request, id 9060, seq 2, length 64
06:32:26.150148 IP iox-nat0-0 > 10.31.100.1: ICMP echo reply, id 9060, seq 2, length 64
06:32:27.151486 IP 10.31.100.1 > iox-nat0-0: ICMP echo request, id 9060, seq 3, length 64
06:32:27.151595 IP iox-nat0-0 > 10.31.100.1: ICMP echo reply, id 9060, seq 3, length 64
06:32:28.152926 IP 10.31.100.1 > iox-nat0-0: ICMP echo request, id 9060, seq 4, length 64
06:32:28.153041 IP iox-nat0-0 > 10.31.100.1: ICMP echo reply, id 9060, seq 4, length 64
06:32:29.153994 ARP, Request who-has 10.31.100.1 tell iox-nat0-0, length 28
06:32:29.154008 ARP, Request who-has iox-nat0-0 tell 10.31.100.1, length 28
06:32:29.154046 ARP, Reply iox-nat0-0 is-at 52:54:99:99:00:00 (oui Unknown), length 28
06:32:29.154097 ARP, Reply 10.31.100.1 is-at 52:54:00:a0:8b:50 (oui Unknown), length 28
06:32:29.154309 IP 10.31.100.1 > iox-nat0-0: ICMP echo request, id 9060, seq 5, length 64
06:32:29.154409 IP iox-nat0-0 > 10.31.100.1: ICMP echo reply, id 9060, seq 5, length 64

Note: You can now manage this application using other Cisco IOx methodologies.