diff --git a/basic/Makefile b/basic/Makefile new file mode 100644 index 0000000..5fd2125 --- /dev/null +++ b/basic/Makefile @@ -0,0 +1,14 @@ +ONOS_URL := http://localhost:8181/onos +ONOS_POST := curl -sSL --user onos:rocks --noproxy localhost -X POST -H 'Content-Type:application/json' +dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + +start: + docker-compose up -d +stop: + docker-compose down --remove-orphans + +netcfg: + ${ONOS_POST} ${ONOS_URL}/v1/network/configuration/ -d@${dir}netcfg.json + +gnmi: + docker run -it --rm --network=basic_stratum bocon/gnmi-cli --grpc-addr mininet:50001 ${ARGS} diff --git a/basic/README.md b/basic/README.md index 1e4e369..adcd773 100644 --- a/basic/README.md +++ b/basic/README.md @@ -2,7 +2,36 @@ In this demo, you will start a Stratum switch using Mininet. Then, you will connect to the device using the P4Runtime shell and gNMI client. Optionally, you can also connect the device to ONOS. -Each command can be run from a Unix-style shell (e.g. Bash), and the only requirement is `Docker`. +Each command can be run from a Unix-style shell (e.g. Bash), and the requirement are `Docker` and `Docker Compose`. + + +## Operations +We use the docker-compose to manage all services, you can use makefile or `docker-compose` command to operate containers. + +Please note that some of the containers are running in interactive mode, please use the **docker attach** to attach its tty and detach it by ^P^Q (hold the Ctrl, press P, press Q, release Ctrl) + +To start all services, run: +```bash= +$ make start +``` + +To stop all services, run: + +```bash= +$ make stop +``` + +To attach any running container, run: + +```bash= +$ docker attach basic_servicename_1 +``` + +To execute gnmi command with paramentes, run: + +```bash= +$ make ARGS="get ......" gnmi +``` ## Start Mininet @@ -10,11 +39,13 @@ By default, Mininet starts a topology with a single switch and two hosts connect ![topo](single-topo.png) -To start the switch, run: +Please make sure that you already start services by docekr compose. +To attach the mininet interface, run: ``` -$ ./start-mn.sh +$ docker attach basic_mininet_1 ``` +To detach the tty, using ^P^Q (hold the Ctrl, press P, press Q, release Ctrl) ## P4Runtime Shell @@ -26,12 +57,14 @@ In this demo, we will use ONOS' `basic.p4` program, which has a single forwardin Note: If you start multiple switches using Mininet, we run a separate instance of Stratum for each switch. Each switch switch will have it's own gRPC server running P4Runtime, and the switch has a single forwarding "chip" (instance of bmv2). To connect to different switches, you will need to vary the gRPC address, but leave the device ID set to 1. -To start the P4Runtime shell, run the following in a separate shell: +To attach the P4Runtime shell, run the following in a separate shell: ``` -$ ./p4rt-shell.sh +$ docker attach basic_p4rt-shell_1 ``` +To detach the tty, using ^P^Q (hold the Ctrl, press P, press Q, release Ctrl) + ### Simple Forwarding Before starting, let's confirm that `h1` and `h2` are not connected. @@ -172,7 +205,7 @@ The gNMI CLI is a Python CLI that enables you to make gNMI call to a Stratum dev To list all interfaces on the device, run the following in a new shell: ``` -$ ./gnmi-cli.sh get /interfaces/interface[name=*] +$ make ARGS="get /interface/interface[name=*]" gnmi ``` You should see this response: @@ -232,7 +265,6 @@ notification { } } } - *************************** ``` @@ -243,7 +275,7 @@ You can see there are two interfaces, and the names and port numbers match the t Next, we can read the ingress unicast packet counters: ``` -$ ./gnmi-cli.sh --interval 1000 sub-sample /interfaces/interface[name=s1-eth1]/state/counters/in-unicast-pkts +$ make ARGS="--interval 1000 sub-sample /interfaces/interface[name=s1-eth1]/state/counters/in-unicast-pkts" gnmi ``` This command will print the number of packets received on port 1 every second. Here is an example of one response: @@ -292,7 +324,7 @@ Finally, we can demonstrate gNMI set and on-change subscriptions. Start a subscription for the operational status of port 1: ``` -$ ./gnmi-cli.sh sub-onchange /interfaces/interface[name=s1-eth1]/state/oper-status +$ make ARGS="sub-onchange /interfaces/interface[name=s1-eth1]/state/oper-status" gnmi ``` You should see the following response which indicates that port 1 is `UP`: @@ -335,7 +367,7 @@ Leave this shell open as any updates will be printed here. In another shell (ideally one that leaves the subscription shell visible), we will run a command to disable port 1: ``` -$ ./gnmi-cli.sh set /interfaces/interface[name=s1-eth1]/config/enabled --bool-val false +$ make ARGS="set /interfaces/interface[name=s1-eth1]/config/enabled --bool-val false" gnmi ``` In the subscription shell, you should see: @@ -378,7 +410,7 @@ You should also see the ping stop in the Mininet shell. In the set shell, you can renable port 1: ``` -$ ./gnmi-cli.sh set /interfaces/interface[name=s1-eth1]/config/enabled --bool-val true +$ make ARGS="set /interfaces/interface[name=s1-eth1]/config/enabled --bool-val true" gnmi ``` You should see that the port is back `UP` in the subscribe shell and the ping should resume in the Mininet shell. @@ -387,8 +419,12 @@ You should see that the port is back `UP` in the subscribe shell and the ping sh You can start ONOS to look at the topology using the ONOS UI: +Please make sure that you already start services by docekr compose. + +Check the running logs of ONOS, run: + ``` -$ ./start-onos.sh +$ docker logs -f basic_onos_1 ``` ONOS will run in the foreground of this shell and will print its log. @@ -400,7 +436,7 @@ Once you see ONOS' log has quieted down (logging slows), you will push informati In a separate shell, run: ``` -$ ./netcfg.sh +$ make netcfg ``` ### Opening the UI diff --git a/basic/docker-compose.yml b/basic/docker-compose.yml new file mode 100644 index 0000000..b779d28 --- /dev/null +++ b/basic/docker-compose.yml @@ -0,0 +1,53 @@ +version: "3" +services: + mininet: + image: opennetworking/mn-stratum + privileged: true + volumes: + - ./tmp/mn-stratum:/tmp + ports: + - "50001-50030:50001-50030" + networks: + - stratum + tty: true + stdin_open: true + start_dependencies: + image: dadarek/wait-for-dependencies + depends_on: + - mininet + command: mininet:50001 + networks: + - stratum + + p4rt-shell: + image: p4lang/p4runtime-sh + privileged: true + volumes: + - ./cfg:/tmp/cfg + command: --grpc-addr mininet:50001 --device-id 1 --election-id 0,1 --config /tmp/cfg/basic_p4info.txt,/tmp/cfg/basic.json + links: + - mininet + networks: + - stratum + tty: true + stdin_open: true + depends_on: + - start_dependencies + onos: + image: onosproject/onos:2.1.0 + environment: + - ONOS_APPS=gui2,drivers.bmv2,pipelines.basic,lldpprovider,hostprovider,fwd + links: + - mininet + networks: + - stratum + ports: + - "8101:8101" + - "8181:8181" + tty: true + stdin_open: true + depends_on: + - start_dependencies +networks: + stratum: + driver: "bridge" diff --git a/basic/gnmi-cli.sh b/basic/gnmi-cli.sh deleted file mode 100755 index 243628b..0000000 --- a/basic/gnmi-cli.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -docker run -it --rm bocon/gnmi-cli \ - --grpc-addr host.docker.internal:50001 $@ diff --git a/basic/netcfg.json b/basic/netcfg.json index 5b568af..da7e0f7 100644 --- a/basic/netcfg.json +++ b/basic/netcfg.json @@ -2,7 +2,7 @@ "devices": { "device:s1": { "basic": { - "managementAddress": "grpc://host.docker.internal:50001?device_id=1", + "managementAddress": "grpc://mininet:50001?device_id=1", "driver": "stratum-bmv2", "pipeconf": "org.onosproject.pipelines.basic" } diff --git a/basic/netcfg.sh b/basic/netcfg.sh deleted file mode 100755 index 1489933..0000000 --- a/basic/netcfg.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -#FIXME update netcfg file to path based on location of this shell script - -curl -sSL --user onos:rocks --noproxy localhost -X POST -H 'Content-Type:application/json' http://localhost:8181/onos/v1/network/configuration/ -d@netcfg-3switch.json diff --git a/basic/p4rt-shell.sh b/basic/p4rt-shell.sh deleted file mode 100755 index eee38a7..0000000 --- a/basic/p4rt-shell.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -#FIXME update cfg directory to path based on location of this shell script - -docker run -it --rm \ - -v $PWD/cfg:/tmp/cfg \ - p4lang/p4runtime-sh \ - --grpc-addr host.docker.internal:50001 \ - --device-id 1 --election-id 0,1 \ - --config /tmp/cfg/basic_p4info.txt,/tmp/cfg/basic.json diff --git a/basic/start-mn.sh b/basic/start-mn.sh deleted file mode 100755 index 9951f7c..0000000 --- a/basic/start-mn.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -docker run --privileged --rm -it \ - -v /tmp/mn-stratum:/tmp \ - -p 50001-50030:50001-50030 \ - opennetworking/mn-stratum $@ diff --git a/basic/start-onos.sh b/basic/start-onos.sh deleted file mode 100755 index ffa6cf7..0000000 --- a/basic/start-onos.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -docker run -it --rm \ - -e ONOS_APPS=gui2,drivers.bmv2,pipelines.basic,lldpprovider,hostprovider,fwd \ - -p 8101:8101 -p 8181:8181 \ - onosproject/onos:2.1.0 \ No newline at end of file