diff mbox

[ovs-dev,4/5] ofp-parse: Parse pipeline fields in OF1.5 packet-out

Message ID 1494867899-87288-5-git-send-email-yihung.wei@gmail.com
State Accepted
Headers show

Commit Message

Yi-Hung Wei May 15, 2017, 5:04 p.m. UTC
This patch adds support for parsing the pipeline match fields of
OpenFlow 1.5 packet-out messages. With this patch, we can use ovs-ofctl
to specify pipeline fileds for a packet-out message.

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
---
 lib/ofp-parse.c          | 14 ++++++++++++++
 tests/ofproto-dpif.at    | 45 +++++++++++++++++++++++++++++++++++++++++++++
 tests/ofproto.at         | 29 +++++++++++++++++++++++++++++
 utilities/ovs-ofctl.8.in |  5 +++++
 4 files changed, 93 insertions(+)
diff mbox

Patch

diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c
index 7b0d23feb0c3..b52e3c138bc2 100644
--- a/lib/ofp-parse.c
+++ b/lib/ofp-parse.c
@@ -616,12 +616,14 @@  parse_ofp_packet_out_str__(struct ofputil_packet_out *po, char *string,
     char *act_str = NULL;
     char *name, *value;
     char *error = NULL;
+    const struct mf_field *mf;
 
     *usable_protocols = OFPUTIL_P_ANY;
 
     *po = (struct ofputil_packet_out) {
         .buffer_id = UINT32_MAX,
     };
+    match_init_catchall(&po->flow_metadata);
     match_set_in_port(&po->flow_metadata, OFPP_CONTROLLER);
 
     act_str = extract_actions(string);
@@ -654,6 +656,18 @@  parse_ofp_packet_out_str__(struct ofputil_packet_out *po, char *string,
                 error = xasprintf("%s: %s", name, error_msg);
                 goto out;
             }
+        } else if ((mf = mf_from_name(name)) != NULL) {
+            error = parse_field(mf, value, &po->flow_metadata,
+                                usable_protocols);
+            if (error) {
+                goto out;
+            }
+            if (!mf_is_pipeline_field(mf)) {
+                error = xasprintf(
+                            "%s is not a valid pipeline field for PACKET_OUT",
+                            name);
+                goto out;
+            }
         } else {
             error = xasprintf("unknown keyword %s", name);
             goto out;
diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at
index 1f6cd8422e04..743ac2ab3454 100644
--- a/tests/ofproto-dpif.at
+++ b/tests/ofproto-dpif.at
@@ -731,6 +731,7 @@  AT_CHECK([tail -1 stdout], [0], [Datapath actions: 4,6,8,10,12,2
 ])
 OVS_VSWITCHD_STOP
 AT_CLEANUP
+
 AT_SETUP([ofproto-dpif - push-pop])
 OVS_VSWITCHD_START
 add_of_ports br0 20 21 22 33 90
@@ -8368,6 +8369,50 @@  AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br1 ], [0], [expout])
 OVS_VSWITCHD_STOP
 AT_CLEANUP
 
+AT_SETUP([ofproto-dpif packet-out pipeline match field (OpenFlow 1.5)])
+OVS_VSWITCHD_START
+
+AT_DATA([flows.txt], [dnl
+table=0,in_port=1 actions=controller
+table=0,tun_id=3 actions=controller
+table=0,metadata=5 actions=controller
+table=0,reg0=1,reg4=2,reg8=3,reg12=5 actions=controller
+table=0,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_gbp_id=0x01,tun_gbp_flags=0x03 actions=controller
+])
+AT_CHECK([ovs-ofctl -O OpenFlow15 add-flows br0 flows.txt])
+
+AT_CHECK([ovs-ofctl -O OpenFlow15 -P standard monitor br0 --detach --no-chdir --pidfile])
+ovs-appctl -t ovs-ofctl ofctl/send 0609000c0123456700000080
+ovs-appctl -t ovs-ofctl ofctl/barrier
+ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
+AT_CAPTURE_FILE([monitor.log])
+
+AT_CHECK([ovs-ofctl -O OpenFlow15 packet-out br0 "in_port=1 packet=0001020304050010203040501111 actions=table"])
+AT_CHECK([ovs-ofctl -O OpenFlow15 packet-out br0 "in_port=2,tunnel_id=3 packet=0001020304050010203040502222 actions=table"])
+AT_CHECK([ovs-ofctl -O OpenFlow15 packet-out br0 "in_port=2,metadata=5 packet=0001020304050010203040503333 actions=table"])
+AT_CHECK([ovs-ofctl -O OpenFlow15 packet-out br0 "in_port=2,reg0=1,reg4=2,reg8=3,reg12=5 packet=0001020304050010203040503333 actions=table"])
+AT_CHECK([ovs-ofctl -O OpenFlow15 packet-out br0 "in_port=2,tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_gbp_id=0x01,tun_gbp_flags=0x03 packet=0001020304050010203040503333 actions=table"])
+AT_CHECK([ovs-ofctl -O OpenFlow15 packet-out br0 "in_port=2,tun_metadata33=3 packet=0001020304050010203040503333 actions=table"])
+
+ovs-appctl -t ovs-ofctl ofctl/barrier
+OVS_APP_EXIT_AND_WAIT([ovs-ofctl])
+
+AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
+OFPT_PACKET_IN (OF1.5): cookie=0x0 total_len=14 in_port=1 (via packet_out) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1111
+OFPT_PACKET_IN (OF1.5): cookie=0x0 total_len=14 tun_id=0x3,in_port=2 (via packet_out) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x2222
+OFPT_PACKET_IN (OF1.5): cookie=0x0 total_len=14 metadata=0x5,in_port=2 (via packet_out) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x3333
+OFPT_PACKET_IN (OF1.5): cookie=0x0 total_len=14 reg0=0x1,reg4=0x2,reg8=0x3,reg12=0x5,in_port=2 (via packet_out) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x3333
+OFPT_PACKET_IN (OF1.5): cookie=0x0 total_len=14 tun_src=1.1.1.1,tun_dst=2.2.2.2,tun_gbp_id=1,tun_gbp_flags=0x3,in_port=2 (via packet_out) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x3333
+OFPT_BARRIER_REPLY (OF1.5):
+])
+
+OVS_VSWITCHD_STOP
+AT_CLEANUP
 
 AT_SETUP([ofproto-dpif packet-out goto_table])
 OVS_VSWITCHD_START
diff --git a/tests/ofproto.at b/tests/ofproto.at
index 5431f4e8d3c6..6a4e26d98e7b 100644
--- a/tests/ofproto.at
+++ b/tests/ofproto.at
@@ -4078,6 +4078,35 @@  OFPT_BARRIER_REPLY (OF1.1):
 OVS_VSWITCHD_STOP
 AT_CLEANUP
 
+AT_SETUP([ofproto - packet-out from controller (OpenFlow 1.5)])
+OVS_VSWITCHD_START
+
+# Start a monitor listening for packet-ins.
+AT_CHECK([ovs-ofctl -O OpenFlow15 -P standard monitor br0 --detach --no-chdir --pidfile])
+ovs-appctl -t ovs-ofctl ofctl/send 0609000c0123456700000080
+ovs-appctl -t ovs-ofctl ofctl/barrier
+ovs-appctl -t ovs-ofctl ofctl/set-output-file monitor.log
+AT_CAPTURE_FILE([monitor.log])
+
+# Send some packet-outs with OFPP_NONE and OFPP_CONTROLLER (65533) as in_port.
+AT_CHECK([ovs-ofctl -O OpenFlow15 packet-out br0 "in_port=none tun_id=0x11 metadata=0x22 packet=0001020304050010203040501234 actions=controller"])
+AT_CHECK([ovs-ofctl -O OpenFlow15 packet-out br0 "in_port=controller tun_id=0x11 metadata=0x33 packet=0001020304050010203040505678 actions=controller"])
+
+# Stop the monitor and check its output.
+ovs-appctl -t ovs-ofctl ofctl/barrier
+OVS_APP_EXIT_AND_WAIT([ovs-ofctl])
+
+AT_CHECK([sed 's/ (xid=0x[[0-9a-fA-F]]*)//' monitor.log], [0], [dnl
+OFPT_PACKET_IN (OF1.5): total_len=14 tun_id=0x11,metadata=0x22,in_port=ANY (via packet_out) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234
+OFPT_PACKET_IN (OF1.5): total_len=14 tun_id=0x11,metadata=0x33,in_port=CONTROLLER (via packet_out) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x5678
+OFPT_BARRIER_REPLY (OF1.5):
+])
+
+OVS_VSWITCHD_STOP
+AT_CLEANUP
+
 dnl This test checks that metadata and userdata are encoded in NXT_PACKET_IN2.
 AT_SETUP([ofproto - packet-out with metadata and userdata (NXT_PACKET_IN2)])
 OVS_VSWITCHD_START
diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in
index a7e805587186..e6642df74627 100644
--- a/utilities/ovs-ofctl.8.in
+++ b/utilities/ovs-ofctl.8.in
@@ -1920,6 +1920,11 @@  This can be any valid OpenFlow port number, or any of the \fBLOCAL\fR,
 .
 This field is required.
 
+.IP \fIpipeline_field\fR=\fIvalue\fR
+Optionally, user can specify a list of pipeline fields for a packet-out
+message. The supported pipeline fields includes \fBtunnel fields\fR and
+\fBregister fields\fR as defined in \fBovs\-fields\fR(7).
+
 .IP \fBpacket=\fIhex-string\fR
 The actual packet to send, expressed as a string of hexadecimal bytes.
 .