diff mbox

[ovs-dev,1/2] connmgr: Fix internal packet-in reason code mask

Message ID 1492463490-10251-1-git-send-email-yihung.wei@gmail.com
State Accepted
Headers show

Commit Message

Yi-Hung Wei April 17, 2017, 9:11 p.m. UTC
Starting from OpenFlow 1.4+, OFPR_ACTION is split into four more descriptive
reasons, OFPR_APPLY_ACTION, OFPR_ACTION_SET, OFPR_GROUP, and OFPR_PACKET_OUT.
OVS maintains the new reason code internally, and it currently supports the
first three reason code. If the version of an established OpenFlow connection
is less than 1.4, OVS coverts the internal reason code back to OFPR_ACTION to
be backward compatible. However, the internal packet-in reason code mask is
not properly maintained for the older OpenFlow version that may omit the
packet-in messages wth the new reason code. It is because OVS does not enable
the new reason code internally in the reason code mask for older OpenFlow
version. This commit tries to address the aforementioned issue.

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
---
 include/openflow/openflow-common.h |  9 +++++++--
 ofproto/connmgr.c                  | 10 ++++++++++
 tests/ofproto.at                   | 23 ++++++++++++++++++++---
 3 files changed, 37 insertions(+), 5 deletions(-)

Comments

Ben Pfaff April 24, 2017, 4:58 p.m. UTC | #1
On Mon, Apr 17, 2017 at 02:11:29PM -0700, Yi-Hung Wei wrote:
> Starting from OpenFlow 1.4+, OFPR_ACTION is split into four more descriptive
> reasons, OFPR_APPLY_ACTION, OFPR_ACTION_SET, OFPR_GROUP, and OFPR_PACKET_OUT.
> OVS maintains the new reason code internally, and it currently supports the
> first three reason code. If the version of an established OpenFlow connection
> is less than 1.4, OVS coverts the internal reason code back to OFPR_ACTION to
> be backward compatible. However, the internal packet-in reason code mask is
> not properly maintained for the older OpenFlow version that may omit the
> packet-in messages wth the new reason code. It is because OVS does not enable
> the new reason code internally in the reason code mask for older OpenFlow
> version. This commit tries to address the aforementioned issue.
> 
> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>

Thanks a lot.  I applied both of these to master.
diff mbox

Patch

diff --git a/include/openflow/openflow-common.h b/include/openflow/openflow-common.h
index 530c105286ac..5936e3f096c5 100644
--- a/include/openflow/openflow-common.h
+++ b/include/openflow/openflow-common.h
@@ -291,9 +291,14 @@  enum ofp_packet_in_reason {
 
 #define OFPR10_BITS                                                     \
     ((1u << OFPR_NO_MATCH) | (1u << OFPR_ACTION) | (1u << OFPR_INVALID_TTL))
+
+/* From OF1.4+, OFPR_ACTION is split into four more descriptive reasons,
+ * OFPR_APPLY_ACTION, OFPR_ACTION_SET, OFPR_GROUP, and OFPR_PACKET_OUT.
+ * OFPR_APPLY_ACTION shares the same number as OFPR_ACTION. */
+#define OFPR14_ACTION_BITS                                              \
+    ((1u << OFPR_ACTION_SET) | (1u << OFPR_GROUP) | (1u << OFPR_PACKET_OUT))
 #define OFPR14_BITS                                                     \
-    (OFPR10_BITS |                                                      \
-     (1u << OFPR_ACTION_SET) | (1u << OFPR_GROUP) | (1u << OFPR_PACKET_OUT))
+    (OFPR10_BITS | OFPR14_ACTION_BITS)
 
     /* Nonstandard reason--not exposed via OpenFlow. */
     OFPR_EXPLICIT_MISS,
diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c
index 854868e7be78..2b0b78f6192d 100644
--- a/ofproto/connmgr.c
+++ b/ofproto/connmgr.c
@@ -1092,6 +1092,16 @@  ofconn_set_async_config(struct ofconn *ofconn,
         ofconn->async_cfg = xmalloc(sizeof *ofconn->async_cfg);
     }
     *ofconn->async_cfg = *ac;
+
+    if (ofputil_protocol_to_ofp_version(ofconn_get_protocol(ofconn))
+        < OFP14_VERSION) {
+        if (ofconn->async_cfg->master[OAM_PACKET_IN] & (1u << OFPR_ACTION)) {
+            ofconn->async_cfg->master[OAM_PACKET_IN] |= OFPR14_ACTION_BITS;
+        }
+        if (ofconn->async_cfg->slave[OAM_PACKET_IN] & (1u << OFPR_ACTION)) {
+            ofconn->async_cfg->slave[OAM_PACKET_IN] |= OFPR14_ACTION_BITS;
+        }
+    }
 }
 
 struct ofputil_async_cfg
diff --git a/tests/ofproto.at b/tests/ofproto.at
index 5c0d0762390f..fbd9a8c21683 100644
--- a/tests/ofproto.at
+++ b/tests/ofproto.at
@@ -3361,7 +3361,9 @@  OVS_VSWITCHD_STOP
 AT_CLEANUP
 
 AT_SETUP([ofproto - asynchronous message control (OpenFlow 1.3)])
-OVS_VSWITCHD_START
+OVS_VSWITCHD_START([dnl
+    add-port br0 p1 -- set Interface p1 type=dummy ofport_request=10
+])
 AT_CHECK([ovs-ofctl -O OpenFlow13 -P standard monitor br0 --detach --no-chdir --pidfile])
 check_async () {
     printf '\n\n--- check_async %d ---\n\n\n' $1
@@ -3373,10 +3375,15 @@  check_async () {
     : > expout
 
     # OFPT_PACKET_IN, OFPR_ACTION (controller_id=0)
+    # OFPR_ACTION_SET is treated as OFPR_ACTION in OpenFlow 1.3
     ovs-ofctl -O OpenFlow13 -v packet-out br0 none controller '0001020304050010203040501234'
+    ovs-ofctl -O OpenFlow13 add-flow br0 'in_port=10 actions=write_actions(output(CONTROLLER))'
+    ovs-appctl netdev-dummy/receive p1 'in_port(10),eth(src=00:10:20:30:40:50,dst=00:01:02:03:04:05),eth_type(0x1234)'
     if test X"$1" = X"OFPR_ACTION"; then shift;
         echo >>expout "OFPT_PACKET_IN (OF1.3): total_len=14 in_port=ANY (via action) 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"
+        echo >>expout "OFPT_PACKET_IN (OF1.3): cookie=0x0 total_len=14 in_port=10 (via action) 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"
     fi
 
     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
@@ -3470,7 +3477,9 @@  OVS_VSWITCHD_STOP
 AT_CLEANUP
 
 AT_SETUP([ofproto - asynchronous message control (OpenFlow 1.4)])
-OVS_VSWITCHD_START
+OVS_VSWITCHD_START([dnl
+    add-port br0 p1 -- set Interface p1 type=dummy ofport_request=10
+])
 AT_CHECK([ovs-ofctl -O OpenFlow14 -P standard monitor br0 --detach --no-chdir --pidfile])
 check_async () {
     printf '\n\n--- check_async %d ---\n\n\n' $1
@@ -3488,6 +3497,14 @@  check_async () {
 vlan_tci=0x0000,dl_src=00:10:20:30:40:50,dl_dst=00:01:02:03:04:05,dl_type=0x1234"
     fi
 
+    # OFPT_PACKET_IN, OFPR_ACTION_SET (controller_id=0)
+    ovs-ofctl -O OpenFlow14 add-flow br0 'in_port=10 actions=write_actions(output(CONTROLLER))'
+    ovs-appctl netdev-dummy/receive p1 'in_port(10),eth(src=00:10:20:30:40:50,dst=00:01:02:03:04:05),eth_type(0x1234)'
+    if test X"$1" = X"OFPR_ACTION_SET"; then shift;
+        echo >>expout "OFPT_PACKET_IN (OF1.4): cookie=0x0 total_len=14 in_port=10 (via action_set) 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"
+    fi
+
     # OFPT_PACKET_IN, OFPR_NO_MATCH (controller_id=123)
     ovs-ofctl -O OpenFlow14 -v packet-out br0 none 'controller(reason=no_match,id=123)' '0001020304050010203040501234'
     if test X"$1" = X"OFPR_NO_MATCH"; then shift;
@@ -3644,7 +3661,7 @@  check_async 1
 
 # Set miss_send_len to 128, turning on packet-ins for our service connection.
 ovs-appctl -t ovs-ofctl ofctl/send 0509000c0123456700000080
-check_async 2 OFPR_ACTION OFPPR_ADD OFPPR_MODIFY OFPPR_DELETE OFPRR_DELETE OFPRR_GROUP_DELETE
+check_async 2 OFPR_ACTION OFPR_ACTION_SET OFPPR_ADD OFPPR_MODIFY OFPPR_DELETE OFPRR_DELETE OFPRR_GROUP_DELETE
 
 # Become slave (OF 1.4), which should disable everything except port status.
 ovs-appctl -t ovs-ofctl ofctl/send 051800180000000200000003000000000000000000000001