[ovs-dev,9/9] ovn.at: Rewrite a test using ovn-controller 'inject-pkt' command.
diff mbox

Message ID 1483582391-114359-9-git-send-email-jpettit@ovn.org
State Accepted
Headers show

Commit Message

Justin Pettit Jan. 5, 2017, 2:13 a.m. UTC
Provide an example of using ovn-controller 'inject-pkt' and ovn-test
'expr-to-packets' commands to generate and verify proper handling of
packets.  Tests written in this way should be easier to understand than
raw packets written in hexadecimal.

Signed-off-by: Justin Pettit <jpettit@ovn.org>
---
 tests/ovn.at | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

Comments

Ben Pfaff Jan. 5, 2017, 3:48 p.m. UTC | #1
On Wed, Jan 04, 2017 at 06:13:11PM -0800, Justin Pettit wrote:
> Provide an example of using ovn-controller 'inject-pkt' and ovn-test
> 'expr-to-packets' commands to generate and verify proper handling of
> packets.  Tests written in this way should be easier to understand than
> raw packets written in hexadecimal.
> 
> Signed-off-by: Justin Pettit <jpettit@ovn.org>

Much nicer.  Thank you.

Acked-by: Ben Pfaff <blp@ovn.org>
Justin Pettit Jan. 5, 2017, 10 p.m. UTC | #2
> On Jan 5, 2017, at 7:48 AM, Ben Pfaff <blp@ovn.org> wrote:
> 
> On Wed, Jan 04, 2017 at 06:13:11PM -0800, Justin Pettit wrote:
>> Provide an example of using ovn-controller 'inject-pkt' and ovn-test
>> 'expr-to-packets' commands to generate and verify proper handling of
>> packets.  Tests written in this way should be easier to understand than
>> raw packets written in hexadecimal.
>> 
>> Signed-off-by: Justin Pettit <jpettit@ovn.org>
> 
> Much nicer.  Thank you.
> 
> Acked-by: Ben Pfaff <blp@ovn.org>

Thanks for the reviews.  I've pushed the series to master.

--Justin

Patch
diff mbox

diff --git a/tests/ovn.at b/tests/ovn.at
index b7cb4cb..65f9776 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -2853,6 +2853,14 @@  ovn_start
 # network. R1 has a switchs ls1 (191.168.1.0/24) connected to it.
 # R2 has ls2 (172.16.1.0/24) connected to it.
 
+ls1_lp1_mac="f0:00:00:01:02:03"
+rp_ls1_mac="00:00:00:01:02:03"
+rp_ls2_mac="00:00:00:01:02:04"
+ls2_lp1_mac="f0:00:00:01:02:04"
+
+ls1_lp1_ip="192.168.1.2"
+ls2_lp1_ip="172.16.1.2"
+
 ovn-nbctl lr-add R1
 ovn-nbctl lr-add R2
 
@@ -2860,16 +2868,16 @@  ovn-nbctl ls-add ls1
 ovn-nbctl ls-add ls2
 
 # Connect ls1 to R1
-ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24
+ovn-nbctl lrp-add R1 ls1 $rp_ls1_mac 192.168.1.1/24
 
 ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \
-  options:router-port=ls1 addresses=\"00:00:00:01:02:03\"
+  options:router-port=ls1 addresses=\"$rp_ls1_mac\"
 
 # Connect ls2 to R2
-ovn-nbctl lrp-add R2 ls2 00:00:00:01:02:04 172.16.1.1/24
+ovn-nbctl lrp-add R2 ls2 $rp_ls2_mac 172.16.1.1/24
 
 ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \
-  options:router-port=ls2 addresses=\"00:00:00:01:02:04\"
+  options:router-port=ls2 addresses=\"$rp_ls2_mac\"
 
 # Connect R1 to R2
 ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 peer=R2_R1
@@ -2880,11 +2888,11 @@  ovn-nbctl lr-route-add R2 "0.0.0.0/0" 20.0.0.1
 
 # Create logical port ls1-lp1 in ls1
 ovn-nbctl lsp-add ls1 ls1-lp1 \
--- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2"
+-- lsp-set-addresses ls1-lp1 "$ls1_lp1_mac $ls1_lp1_ip"
 
 # Create logical port ls2-lp1 in ls2
 ovn-nbctl lsp-add ls2 ls2-lp1 \
--- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2"
+-- lsp-set-addresses ls2-lp1 "$ls2_lp1_mac $ls2_lp1_ip"
 
 # Create two hypervisor and create OVS ports corresponding to logical ports.
 net_add n1
@@ -2919,18 +2927,11 @@  ovn_populate_arp
 # XXX This should be more systematic.
 sleep 1
 
-# Send ip packets between the two ports.
-ip_to_hex() {
-    printf "%02x%02x%02x%02x" "$@"
-}
-
 # Packet to send.
-src_mac="f00000010203"
-dst_mac="000000010203"
-src_ip=`ip_to_hex 192 168 1 2`
-dst_ip=`ip_to_hex 172 16 1 2`
-packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
-as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
+packet="inport==\"ls1-lp1\" && eth.src==$ls1_lp1_mac && eth.dst==$rp_ls1_mac &&
+        ip4 && ip.ttl==64 && ip4.src==$ls1_lp1_ip && ip4.dst==$ls2_lp1_ip &&
+        udp && udp.src==53 && udp.dst==4369"
+as hv1 ovs-appctl -t ovn-controller inject-pkt "$packet"
 
 
 echo "---------NB dump-----"
@@ -2955,9 +2956,11 @@  as hv2 ovs-ofctl show br-int
 as hv2 ovs-ofctl dump-flows br-int
 
 # Packet to Expect
-src_mac="000000010204"
-dst_mac="f00000010204"
-echo "${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000" > expected
+# The TTL should be decremented by 2.
+packet="eth.src==$rp_ls2_mac && eth.dst==$ls2_lp1_mac &&
+        ip4 && ip.ttl==62 && ip4.src==$ls1_lp1_ip && ip4.dst==$ls2_lp1_ip &&
+        udp && udp.src==53 && udp.dst==4369"
+echo $packet | ovstest test-ovn expr-to-packets > expected
 
 OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected])