From c9151e767a4f9f58b4b8e2d698f1be2f62bfe7ab Mon Sep 17 00:00:00 2001 From: theojepsen Date: Fri, 3 Nov 2017 16:41:37 +0000 Subject: [PATCH] Updated ecn exercise to work with new util scripts (#72) * Updated ecn exercise to work with new util scripts * Bugfix and print port mapping in run_exercise.py --- P4D2_2017_Fall/exercises/ecn/Makefile | 1 + P4D2_2017_Fall/exercises/ecn/README.md | 14 ++++---- P4D2_2017_Fall/exercises/ecn/p4app.json | 37 -------------------- P4D2_2017_Fall/exercises/ecn/run.sh | 5 --- P4D2_2017_Fall/exercises/ecn/s1-commands.txt | 4 +-- P4D2_2017_Fall/exercises/ecn/s2-commands.txt | 4 +-- P4D2_2017_Fall/utils/run_exercise.py | 24 +++++++++++-- 7 files changed, 34 insertions(+), 55 deletions(-) create mode 100644 P4D2_2017_Fall/exercises/ecn/Makefile delete mode 100644 P4D2_2017_Fall/exercises/ecn/p4app.json delete mode 100755 P4D2_2017_Fall/exercises/ecn/run.sh diff --git a/P4D2_2017_Fall/exercises/ecn/Makefile b/P4D2_2017_Fall/exercises/ecn/Makefile new file mode 100644 index 0000000..f378756 --- /dev/null +++ b/P4D2_2017_Fall/exercises/ecn/Makefile @@ -0,0 +1 @@ +include ../../utils/Makefile diff --git a/P4D2_2017_Fall/exercises/ecn/README.md b/P4D2_2017_Fall/exercises/ecn/README.md index 709692c..115d84a 100644 --- a/P4D2_2017_Fall/exercises/ecn/README.md +++ b/P4D2_2017_Fall/exercises/ecn/README.md @@ -30,7 +30,7 @@ network in Mininet to test its behavior. 1. In your shell, run: ```bash - ./run.sh + make ``` This will: * compile `ecn.p4`, and @@ -44,7 +44,7 @@ network in Mininet to test its behavior. 2. We want to send a low rate traffic from `h1` to `h2` and a high rate iperf traffic from `h11` to `h22`. The link between `s1` and `s2` is common between the flows and is a bottleneck because we -reduced its bandwidth to 512kbps in p4app.json. Therefore, if we +reduced its bandwidth to 512kbps in topology.json. Therefore, if we capture packets at `h2`, we should see the right ECN value. 3. You should now see a Mininet command prompt. Open four terminals @@ -158,11 +158,11 @@ How can we let the user configure the threshold? There are several ways that problems might manifest: -1. `ecn.p4` fails to compile. In this case, `run.sh` will report the +1. `ecn.p4` fails to compile. In this case, `make` will report the error emitted from the compiler and stop. 2. `ecn.p4` compiles but does not support the control plane rules in - the `sX-commands.txt` files that `run.sh` tries to install using - the BMv2 CLI. In this case, `run.sh` will report these errors to + the `sX-commands.txt` files that `make` tries to install using + the BMv2 CLI. In this case, `make` will report these errors to `stderr`. Use these error messages to fix your `ecn.p4` implementation. 3. `ecn.p4` compiles, and the control plane rules are installed, but @@ -180,12 +180,12 @@ There are several ways that problems might manifest: #### Cleaning up Mininet -In the latter two cases above, `run.sh` may leave a Mininet instance +In the latter two cases above, `make` may leave a Mininet instance running in the background. Use the following command to clean up these instances: ```bash -mn -c +make stop ``` ## Next Steps diff --git a/P4D2_2017_Fall/exercises/ecn/p4app.json b/P4D2_2017_Fall/exercises/ecn/p4app.json deleted file mode 100644 index e54eef2..0000000 --- a/P4D2_2017_Fall/exercises/ecn/p4app.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "program": "ecn.p4", - "language": "p4-16", - "targets": { - "multiswitch": { - "auto-control-plane": true, - "cli": true, - "pcap_dump": true, - "bmv2_log": true, - "links": [["h1", "s1"], ["h11", "s1"], ["s1", "s2", "0", 0.5], ["s1", "s3"], ["s3", "s2"], ["s2", "h2"], ["s2", "h22"], ["s3", "h3"]], - "hosts": { - "h1": { - }, - "h2": { - }, - "h3": { - }, - "h11": { - }, - "h22": { - } - - }, - "switches": { - "s1": { - "entries": "s1-commands.txt" - }, - "s2": { - "entries": "s2-commands.txt" - }, - "s3": { - "entries": "s3-commands.txt" - } - } - } - } -} diff --git a/P4D2_2017_Fall/exercises/ecn/run.sh b/P4D2_2017_Fall/exercises/ecn/run.sh deleted file mode 100755 index d5c1947..0000000 --- a/P4D2_2017_Fall/exercises/ecn/run.sh +++ /dev/null @@ -1,5 +0,0 @@ -P4APPRUNNER=../../utils/p4apprunner.py -mkdir -p build -tar -czf build/p4app.tgz * --exclude='build' -#cd build -sudo python $P4APPRUNNER p4app.tgz --build-dir ./build diff --git a/P4D2_2017_Fall/exercises/ecn/s1-commands.txt b/P4D2_2017_Fall/exercises/ecn/s1-commands.txt index 67e4f74..dc4e260 100644 --- a/P4D2_2017_Fall/exercises/ecn/s1-commands.txt +++ b/P4D2_2017_Fall/exercises/ecn/s1-commands.txt @@ -1,5 +1,5 @@ table_set_default ipv4_lpm drop -table_add ipv4_lpm ipv4_forward 10.0.1.1/32 => 00:00:00:00:01:01 1 -table_add ipv4_lpm ipv4_forward 10.0.1.11/32 => 00:00:00:00:01:0b 2 +table_add ipv4_lpm ipv4_forward 10.0.1.1/32 => 00:00:00:00:01:01 2 +table_add ipv4_lpm ipv4_forward 10.0.1.11/32 => 00:00:00:00:01:0b 1 table_add ipv4_lpm ipv4_forward 10.0.2.0/24 => 00:00:00:02:03:00 3 table_add ipv4_lpm ipv4_forward 10.0.3.0/24 => 00:00:00:03:02:00 4 diff --git a/P4D2_2017_Fall/exercises/ecn/s2-commands.txt b/P4D2_2017_Fall/exercises/ecn/s2-commands.txt index dcbf778..3b80bed 100644 --- a/P4D2_2017_Fall/exercises/ecn/s2-commands.txt +++ b/P4D2_2017_Fall/exercises/ecn/s2-commands.txt @@ -1,5 +1,5 @@ table_set_default ipv4_lpm drop -table_add ipv4_lpm ipv4_forward 10.0.2.2/32 => 00:00:00:00:02:02 1 -table_add ipv4_lpm ipv4_forward 10.0.2.22/32 => 00:00:00:00:02:16 2 +table_add ipv4_lpm ipv4_forward 10.0.2.2/32 => 00:00:00:00:02:02 2 +table_add ipv4_lpm ipv4_forward 10.0.2.22/32 => 00:00:00:00:02:16 1 table_add ipv4_lpm ipv4_forward 10.0.1.0/24 => 00:00:00:01:03:00 3 table_add ipv4_lpm ipv4_forward 10.0.3.0/24 => 00:00:00:03:03:00 4 diff --git a/P4D2_2017_Fall/utils/run_exercise.py b/P4D2_2017_Fall/utils/run_exercise.py index 55ae9a1..09611ae 100755 --- a/P4D2_2017_Fall/utils/run_exercise.py +++ b/P4D2_2017_Fall/utils/run_exercise.py @@ -60,6 +60,7 @@ class ExerciseTopo(Topo): Topo.__init__(self, **opts) host_links = [] switch_links = [] + self.sw_port_mapping = {} for link in links: if link['node1'][0] == 'h': @@ -88,10 +89,29 @@ class ExerciseTopo(Topo): self.addLink(host_name, host_sw, delay=link['latency'], bw=link['bandwidth'], addr1=host_mac, addr2=host_mac) + self.addSwitchPort(host_sw, host_name) for link in switch_links: self.addLink(link['node1'], link['node2'], delay=link['latency'], bw=link['bandwidth']) + self.addSwitchPort(link['node1'], link['node2']) + self.addSwitchPort(link['node2'], link['node1']) + + self.printPortMapping() + + def addSwitchPort(self, sw, node2): + if sw not in self.sw_port_mapping: + self.sw_port_mapping[sw] = [] + portno = len(self.sw_port_mapping[sw])+1 + self.sw_port_mapping[sw].append((portno, node2)) + + def printPortMapping(self): + print "Switch port mapping:" + for sw in sorted(self.sw_port_mapping.keys()): + print "%s: " % sw, + for portno, node2 in self.sw_port_mapping[sw]: + print "%d:%s\t" % (portno, node2), + print class ExerciseRunner: @@ -116,9 +136,9 @@ class ExerciseRunner: if not self.quiet: print(' '.join(items)) - def formatLatency(l): + def formatLatency(self, l): """ Helper method for parsing link latencies from the topology json. """ - if isinstance(latencies[l], (str, unicode)): + if isinstance(l, (str, unicode)): return l else: return str(l) + "ms"