Getting Started with Docker Container Over MLNX-OS SDK Interfaces

Version 9

     

    References

     

    Overview

    MLNX-OS adds the ability for users to run their own applications on a Linux dockers image embedded in the switch software (SW). The container is a pure application sandbox with resource isolation in terms of memory and compute from the system code/NOS. The container implementation complements MLNX-OS’s VM support to provide a new set of capabilities:

    • Access to network traffic – containers are implemented in MLNX-OS in the same name space as the network devices. This allows the SW to send and receive packets from the switch’s ports by opening a standard Linux socket over the network device, using an IP address that has been set to the device via the legacy management interface (e.g. JSON over HTTP).
    • Calling SDK interfaces – applications running in the docker container are able to implement their own set of tools such as telemetry features within the network devices. By calling the switch SDK APIs, they can read data that is not exposed in the MLNX-OS user interface, or register to receive events that occur in the system (e.g. port up/down).
    • Query the Linux tables provisioned by MLNX-OS such as neighbor cache, routing tables, L3 interfaces attributes etc.

     

    Here we mainly cover "Calling the SDK interfaces".

     

    Configuration

    The following examples exhibit how to run a docker with SDK support using an Ubuntu and Debian image. We can run the docker with SDK support using CentOS image too.

     

    MLNX-OS Docker with SDK Support Using Ubuntu Image

     

    Step 1: Validate the MLNX-OS version

    # sh version

    Product name:      MLNX-OS

    Product release:   3.6.4112

    Build ID:          #1-dev

    Build date:        2017-08-18 05:25:07

    Target arch:       x86_64

    Target hw:         x86_64

    Built by:          jenkins@aa5ca20f816b

    Version summary:   X86_64 3.6.4112 2017-08-18 05:25:07 x86_64

     

    Product model:     x86onie

    Host ID:           248A078FAD74

    System serial num: MT1650X03800

    System UUID:       51955ee2-c20a-11e6-8000-248a0781ac00

     

    Uptime:            6d 11h 57m 7.456s

    CPU load averages: 1.02 / 1.04 / 1.11

    Number of CPUs:    4

    System memory:     2442 MB used / 5368 MB free / 7810 MB total

    Swap:              0 MB used / 0 MB free / 0 MB total

    Note: Prefered MLNX-OS version is 3.6.4112 and above.

     

    Step 2: Make sure clock is up-to-date

    # show clock

    Time:       20:13:00

    Date:       2017/08/29

    Time zone:  UTC

                (Etc/UTC)

    UTC offset: same as UTC

    Note:  Please update your system time and date or run ntp. Follow the MLNX-OS User Manual section "4.2 NTP, Clock & Time Zones".

     

    Step 3: Start Docker service on the switch

    Switch (config ) #docker

    Switch (config docker) # no shutdown

     

    Step 4: Pull a new image

    (config docker) # pull ubuntu

    Using default tag: latest

    latest: Pulling from library/ubuntu

    Digest: sha256:34471448724419596ca4e890496d375801de21b0e67b81a77fd6155ce001edad

    Status: Image is up to date for ubuntu:latest

     

    Step 5: Start a new container with SDK support

    Switch (config docker) # start ubuntu latest my_sdk_app-ubuntu now privileged sdk

    Attempting to start docker container. Please wait (this can take a minute)...

    Switch (config docker) #

     

    Step 6: Execute /bin/bash from the running container

    Switch [standalone: master] (config docker) # exec my_sdk_app-ubuntu /bin/bash

    Running exec_name:[/bin/bash]

     

    root@Switch:/#

     

    Step 7: Update and install Python from the container

    root@Switch:/# apt-get update && apt-get install -y python

    root@Switch:/# exit

     

    Step 8: To get the SDK object and start developing the SDK app you need to run

    Switch [standalone: master] (config docker) # copy-sdk my_sdk_app-ubuntu to /
    Coping SDK files to docker container. Please wait (this can take a minute)...Switch [standalone: master] (config docker) #

    Step 9: Execute /bin/bash from the running container

    Switch [standalone: master] (config docker) # exec my_sdk_app-ubuntu /bin/bash

    Running exec_name:[/bin/bash]

     

    root@Switch :/#

     

    Step 10: You will have all the needed SDK libs to build new SDK app

    root@Switch:/# cp /usr/lib64/python2.7/site-packages/python_sdk_api/_sx* /usr/lib/python2.7/site-packages/python_sdk_api/.

    root@Switch:/#

     

    Step 11: Container is ready to run the SDK scripts:

    The output below gives an example running the build in SDK script.

    All the built-in SDK APIs are located under "/usr/bin".

    root@Switch:/# /usr/bin/sx_api_ports_dump.py

    [+] Redirecting stderr to: /tmp/python_err_log.txt

    [+] opening sdk

    Aug 29 18:35:47 INFO    LOG: Initializing SX log with STDOUT as output file.

    sx_api_open handle:0x7fb60e2bc174 , rc 0

    sx_api_port_device_get port_cnt:17 , rc 0, port_list :

    ======================================================================================

    |  log_port|local_port|label_port|       mtu| admin_s|  oper_s|       module_s|  pvid|

    ======================================================================================

    |   0x10100|         1|         7|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10500|         5|         8|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10900|         9|         5|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10d00|        13|         6|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11100|        17|         3|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11500|        21|         4|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11900|        25|         1|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11d00|        29|         2|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12100|        33|        10|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12500|        37|         9|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12900|        41|        12|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12d00|        45|        11|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13100|        49|        14|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13500|        53|        13|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13900|        57|        16|      1522|      UP|    DOWN|        PLUGGED|     1|

    |   0x13d00|        61|        15|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    ======================================================================================


    MLNX-OS Docker with SDK Support Using Debian Image

     

    Step 1:  Enable Docker

    Switch [standalone: master] (config) # docker

    Switch [standalone: master] (config docker) # no shutdown

     

    Step 2:  Pull a new image (Debian)

    (config docker) # pull debian

    Using default tag: latest

    latest: Pulling from library/debian

    Digest: sha256:6ccbcbf362dbc4add74711cb774751b59cdfd7aed16c3c29aaecbea871952fe0

    Status: Image is up to date for debian:latest

     

    Step 3:  Start a new container from Debian Image with SDK support

    Switch  (config docker) # start debian latest my-sdk-debian now privileged sdk

    Attempting to start docker container. Please wait (this can take a minute)...

    Switch  (config docker) #

     

    Step 4: Exec the /bin/bash with in the running container

    Switch (config docker) # exec my-sdk-debian /bin/bashRunning exec_name:[/bin/bash]
    root@Switch:/#

     

    Step 5: Update and install Python

    root@Switch:/# apt-get update && apt-get install -y python

     

    Step 6: To get the SDK object and start developing SDK app you need to run

    root@Switch:/#exit

    Switch [standalone: master] (config docker) # copy-sdk my-sdk-debian to /

    Coping SDK files to docker container. Please wait (this can take a minute)...

    Switch [standalone: master] (config docker) #

     

     

    Step 7: Exec the /bin/bash with in the running container

    Switch [standalone: master] (config docker) # exec my-sdk-debian /bin/bash

    Running exec_name:[/bin/bash]

     

    root@Switch :/#

     

    Step 8: You will have all the needed SDK libs to build new SDK app

    root@Switch :/#

    root@Switch :/# mkdir –p /usr/lib/python2.7/site-packages/python_sdk_api/.

    root@Switch :/# cp /usr/lib64/python2.7/site-packages/python_sdk_api/_sx* /usr/lib/python2.7/site-packages/python_sdk_api/.

     

    Step 9: The container is ready to run the SDK Python scripts

    root@Switch:/# /usr/bin/sx_api_ports_dump.py

    [+] Redirecting stderr to: /tmp/python_err_log.txt

    [+] opening sdk

    Aug 29 18:35:47 INFO    LOG: Initializing SX log with STDOUT as output file.

    sx_api_open handle:0x7fb60e2bc174 , rc 0

    sx_api_port_device_get port_cnt:17 , rc 0, port_list :

    ======================================================================================

    |  log_port|local_port|label_port|       mtu| admin_s|  oper_s|       module_s|  pvid|

    ======================================================================================

    |   0x10100|         1|         7|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10500|         5|         8|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10900|         9|         5|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10d00|        13|         6|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11100|        17|         3|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11500|        21|         4|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11900|        25|         1|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11d00|        29|         2|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12100|        33|        10|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12500|        37|         9|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12900|        41|        12|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12d00|        45|        11|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13100|        49|        14|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13500|        53|        13|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13900|        57|        16|      1522|      UP|    DOWN|        PLUGGED|     1|

    |   0x13d00|        61|        15|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    ======================================================================================

    Note: The location of built-in SDK Python scripts: /usr/bin/sx_api*

     

     

    MLNX-OS Docker with SDK Support Using CentOS Image

     

    Step1: Enable Docker

    Switch [standalone: master] (config) # docker

    Switch [standalone: master] (config docker) # no shutdown

     

    Step 2: Pull a new image (CentOS)

    (config docker) # # pull centos

    Using default tag: latest

    latest: Pulling from library/centos

    74f0853ba93b: Pull complete

    Digest: sha256:26f74cefad82967f97f3eeeef88c1b6262f9b42bc96f2ad61d6f3fdf544759b8

    Status: Downloaded newer image for centos:latest

     

    Step 3: Start a new container from Centos Image with SDK support

    Switch (config docker) # start centos latest my-sdk-centos now privileged sdk

    Attempting to start docker container. Please wait (this can take a minute)...

    Switch  (config docker) #

     

    Step 4: Exec the /bin/bash with in the running container

    Switch (config docker) # exec my-sdk-centos /bin/bash

    Running exec_name:[/bin/bash]

     

    root@Switch:/#

     

    Step 5: Update and install Python

    root@Switch:/# yum update && yum install -y python
    root@Switch:/#exit

     

    Step 6: To get the SDK object and start developing SDK app you need to run

    Switch [standalone: master] (config docker) # copy-sdk my-sdk-centos to /

    Coping SDK files to docker container. Please wait (this can take a minute)...

    Switch [standalone: master] (config docker) #

     

    Step 7: Exec the /bin/bash with in the running container

    Switch [standalone: master] (config docker) # exec my-sdk-centos /bin/bash

    Running exec_name:[/bin/bash]

     

    root@Switch :/#

     

    Step 8: Follow one of the below steps to copy the SDK library

            Step 8.1: Move the SDK library to /usr/lib and export the library path as /usr/lib

    [root@Switch/]# mv /usr/lib64/python2.7/site-packages/python_sdk_api/_sx* /usr/lib/python2.7/site-packages/python_sdk_api/

    [root@Switch/]# export LD_LIBRARY_PATH=/usr/lib

            or

            Step 8.2: Move the SDK libraries to the default path

    [root@Switch]#  mv /usr/lib/libsx* /usr/lib64/

    [root@Switch]#  mv /usr/lib/libib* /usr/lib64/

    [root@Switch]#  mv /usr/lib/libsw* /usr/lib64/

     

    Step 9: Container is ready to run SDK Python scripts

    [root@Switch]# sx_api_ports_dump.py

    [+] Redirecting stderr to: /tmp/python_err_log.txt

    [+] opening sdk

    Aug 31 19:08:07 INFO    LOG: Initializing SX log with STDOUT as output file.

    sx_api_open handle:0x29f87b4 , rc 0

    sx_api_port_device_get port_cnt:33 , rc 0, port_list :

    ======================================================================================

    |  log_port|local_port|label_port|       mtu| admin_s|  oper_s|       module_s|  pvid|

    ======================================================================================

    |   0x10100|         1|        17|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10300|         3|        18|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10500|         5|        19|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10700|         7|        20|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10900|         9|        21|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10b00|        11|        22|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10d00|        13|        23|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x10f00|        15|        24|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11100|        17|        25|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11300|        19|        26|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11500|        21|        27|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11700|        23|        28|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11900|        25|        29|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11b00|        27|        30|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11d00|        29|        31|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x11f00|        31|        32|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12100|        33|        15|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12300|        35|        16|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12500|        37|        13|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12700|        39|        14|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12900|        41|        11|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12b00|        43|        12|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12d00|        45|         9|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x12f00|        47|        10|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13100|        49|         7|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13300|        51|         8|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13500|        53|         5|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13700|        55|         6|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13900|        57|         3|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13b00|        59|         4|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13d00|        61|         1|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    |   0x13f00|        63|         2|      1522|      UP|    DOWN|      UNPLUGGED|     1|

    ======================================================================================