From: Justin Pettit Date: Thu, 5 Jan 2017 01:50:39 +0000 (-0800) Subject: ovn.at: Rewrite a test using ovn-controller 'inject-pkt' command. X-Git-Tag: v2.12.3~4019 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=3c1ae70ad15e1dec1f7c1ebb33f38577a89e5f38;p=mirror_ovs.git ovn.at: Rewrite a test using ovn-controller 'inject-pkt' command. 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 Acked-by: Ben Pfaff --- diff --git a/tests/ovn.at b/tests/ovn.at index b7cb4cbef..65f97768a 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])