0003-test-scripts.patch revision 55fd743f
1From 344cc48bef87c54a3d7d6c489b56fb1ac513897e Mon Sep 17 00:00:00 2001
2From: Gabriel Ganne <gabriel.ganne@qosmos.com>
3Date: Sat, 17 Sep 2016 10:16:19 +0200
4Subject: [PATCH 3/3] test scripts
5
6Adds small scripts to test both flowtable and portmirroring APIs
7
8Signed-off-by: Gabriel Ganne <gabriel.ganne@qosmos.com>
9Change-Id: I59c6c0860125f8d8f553312fe44a2ed42d0b3e7c
10---
11 ft-test/classifier-env-setup.sh | 24 +++++++++++++++++++++
12 ft-test/classifier-pm.py        | 46 +++++++++++++++++++++++++++++++++++++++++
13 ft-test/flowtable-env-setup.sh  | 27 ++++++++++++++++++++++++
14 ft-test/flowtable-pm.py         | 41 ++++++++++++++++++++++++++++++++++++
15 4 files changed, 138 insertions(+)
16 create mode 100755 ft-test/classifier-env-setup.sh
17 create mode 100755 ft-test/classifier-pm.py
18 create mode 100755 ft-test/flowtable-env-setup.sh
19 create mode 100755 ft-test/flowtable-pm.py
20
21diff --git a/ft-test/classifier-env-setup.sh b/ft-test/classifier-env-setup.sh
22new file mode 100755
23index 0000000..c930ec5
24--- /dev/null
25+++ b/ft-test/classifier-env-setup.sh
26@@ -0,0 +1,24 @@
27+#!/bin/bash
28+
29+for i in `seq 1 3`
30+do
31+    ip netns delete vpp$i
32+    ip netns add vpp$i
33+    vppctl tap connect vpp$i
34+    vppctl set interface state tap-$(($i - 1)) up
35+    ip link set dev vpp$i netns vpp$i
36+    ip netns exec vpp$i ip link set vpp$i up
37+done
38+
39+vppctl set interface l2 bridge tap-0 23
40+vppctl set interface l2 bridge tap-1 23
41+
42+ip netns exec vpp1 ip addr add 192.168.0.1/24 dev vpp1
43+ip netns exec vpp2 ip addr add 192.168.0.2/24 dev vpp2
44+
45+vppctl set int l3 tap-2
46+vppctl set int ip addr tap-2 192.168.1.1/24
47+
48+# test
49+ip netns exec vpp1 ping -c1 192.168.0.2
50+ip netns exec vpp2 ping -c1 192.168.0.1
51diff --git a/ft-test/classifier-pm.py b/ft-test/classifier-pm.py
52new file mode 100755
53index 0000000..4110e24
54--- /dev/null
55+++ b/ft-test/classifier-pm.py
56@@ -0,0 +1,46 @@
57+#!/bin/env python
58+from __future__ import print_function
59+
60+import vpp_papi as vpp 
61+
62+from vpp_papi.portmirroring import *
63+import vpp_papi.portmirroring as pm
64+
65+if_1_name = 'tap-0'
66+if_2_name = 'tap-1'
67+if_3_name = 'tap-2'
68+
69+r = vpp.connect('papi')
70+
71+if_1_sw_if_index = vpp.sw_interface_dump(1, if_1_name)[0].sw_if_index
72+if_2_sw_if_index = vpp.sw_interface_dump(1, if_2_name)[0].sw_if_index
73+if_3_sw_if_index = vpp.sw_interface_dump(1, if_3_name)[0].sw_if_index
74+
75+# add port-mirroring as available classifier next nodes
76+r = vpp.add_node_next("l2-input-classify", "pm-in-hit")
77+print(r)
78+pm_in_hit_idx = r.node_index;
79+
80+r = vpp.add_node_next("l2-output-classify", "pm-out-hit")
81+print(r)
82+pm_out_hit_idx = r.node_index;
83+
84+# configure portmirroring
85+# 0 -> classifier, 0 -> add
86+r = pm.pm_conf(if_3_sw_if_index, 0, 0)
87+print(r)
88+
89+# add, table_index, nbuckets, memory_size, skip_n_vectors, match_n_vectors, next_table_index, miss_next_index, mask
90+cl0 = vpp.classify_add_del_table(1, 0xffffffff, 64, 1024*1024, 0, 1, 0xffffffff, pm_in_hit_idx, '')
91+print(cl0)
92+cl1 = vpp.classify_add_del_table(1, 0xffffffff, 64, 1024*1024, 0, 1, 0xffffffff, pm_out_hit_idx, '')
93+print(cl1)
94+
95+# input -> 1, output -> 0
96+r = vpp.classify_set_interface_l2_tables(if_1_sw_if_index, cl0.new_table_index, 0xffffffff, 0xffffffff, 1)
97+print(r)
98+r = vpp.classify_set_interface_l2_tables(if_1_sw_if_index, cl1.new_table_index, 0xffffffff, 0xffffffff, 0)
99+print(r)
100+
101+r = vpp.disconnect()
102+exit(r)
103diff --git a/ft-test/flowtable-env-setup.sh b/ft-test/flowtable-env-setup.sh
104new file mode 100755
105index 0000000..1584000
106--- /dev/null
107+++ b/ft-test/flowtable-env-setup.sh
108@@ -0,0 +1,27 @@
109+#!/bin/bash
110+
111+for i in `seq 1 3`
112+do
113+    ip netns delete vpp$i
114+    ip netns add vpp$i
115+    vppctl tap connect vpp$i
116+    vppctl set interface state tap-$(($i - 1)) up
117+    ip link set dev vpp$i netns vpp$i
118+    ip netns exec vpp$i ip link set vpp$i up
119+done
120+
121+vppctl set interface l2 bridge tap-0 23
122+vppctl set interface l2 bridge tap-1 23
123+
124+ip netns exec vpp1 ip addr add 192.168.0.1/24 dev vpp1
125+ip netns exec vpp2 ip addr add 192.168.0.2/24 dev vpp2
126+ip netns exec vpp3 ip addr add 192.168.1.1/24 dev vpp3
127+
128+for if in `seq 1 3`
129+do
130+	ip netns exec vpp$i ifconfig vpp$i mtu 10000
131+done
132+
133+# test
134+ip netns exec vpp1 ping -c1 192.168.0.2
135+ip netns exec vpp2 ping -c1 192.168.0.1
136diff --git a/ft-test/flowtable-pm.py b/ft-test/flowtable-pm.py
137new file mode 100755
138index 0000000..6907b8f
139--- /dev/null
140+++ b/ft-test/flowtable-pm.py
141@@ -0,0 +1,41 @@
142+#!/bin/env python
143+from __future__ import print_function
144+
145+import sys
146+import vpp_papi as vpp 
147+
148+from portmirroring import *
149+portmirroring = sys.modules['portmirroring']
150+
151+
152+from flowtable import *
153+flowtable = sys.modules['flowtable']
154+
155+if_1_name = 'tap-0'
156+if_2_name = 'tap-1'
157+if_3_name = 'tap-2'
158+
159+r = vpp.connect('papi')
160+
161+if_1_sw_if_index = vpp.sw_interface_dump(1, if_1_name)[0].sw_if_index
162+if_2_sw_if_index = vpp.sw_interface_dump(1, if_2_name)[0].sw_if_index
163+if_3_sw_if_index = vpp.sw_interface_dump(1, if_3_name)[0].sw_if_index
164+
165+# add port-mirroring as available flowtable next node
166+r = vpp.add_node_next("flowtable-process", "pm-in-hit")
167+print(r)
168+portmirroring_index = r.node_index;
169+
170+# configure portmirroring
171+# 1 = flowtable, 0 = is_add
172+r = portmirroring.pm_conf(if_3_sw_if_index, 1, 0)
173+print(r)
174+
175+# hook flowtable from both intfs 1 & 2:
176+r = flowtable.flowtable_conf(if_1_sw_if_index, portmirroring_index, 0)
177+print(r)
178+r = flowtable.flowtable_conf(if_2_sw_if_index, portmirroring_index, 0)
179+print(r)
180+
181+r = vpp.disconnect()
182+exit(r)
183-- 
1842.10.0.rc1.15.g5cb0d5a
185
186