From 7cd903564fa4f64a815af311232213f0e770d012 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 15 Nov 2012 22:36:15 -0800 Subject: [PATCH] ofp-util: Allow use of OpenFlow 12 flow format This enables the use of the OpenFlow 12 flow format. Signed-off-by: Simon Horman Signed-off-by: Ben Pfaff --- lib/ofp-util.c | 58 +++++++++++++++++++++++----------------------- lib/ofp-util.h | 6 +++-- tests/learn.at | 2 +- tests/ovs-ofctl.at | 12 +++++----- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/ofp-util.c b/lib/ofp-util.c index c2e97384..6ff9df89 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -726,7 +726,7 @@ ofputil_protocol_to_string(enum ofputil_protocol protocol) return "OpenFlow10+table_id"; case OFPUTIL_P_OF12_OXM: - return NULL; + return "OXM"; } /* Check abbreviations. */ @@ -969,71 +969,71 @@ ofputil_usable_protocols(const struct match *match) BUILD_ASSERT_DECL(FLOW_WC_SEQ == 17); - /* NXM and OF1.1+ supports bitwise matching on ethernet addresses. */ + /* NXM, OXM, and OF1.1 support bitwise matching on ethernet addresses. */ if (!eth_mask_is_exact(wc->masks.dl_src) && !eth_addr_is_zero(wc->masks.dl_src)) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } if (!eth_mask_is_exact(wc->masks.dl_dst) && !eth_addr_is_zero(wc->masks.dl_dst)) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* NXM and OF1.1+ support matching metadata. */ + /* NXM, OXM, and OF1.1+ support matching metadata. */ if (wc->masks.metadata != htonll(0)) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports matching ARP hardware addresses. */ + /* NXM and OXM support matching ARP hardware addresses. */ if (!eth_addr_is_zero(wc->masks.arp_sha) || !eth_addr_is_zero(wc->masks.arp_tha)) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports matching IPv6 traffic. */ + /* NXM and OXM support matching IPv6 traffic. */ if (match->flow.dl_type == htons(ETH_TYPE_IPV6)) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports matching registers. */ + /* NXM and OXM support matching registers. */ if (!regs_fully_wildcarded(wc)) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports matching tun_id. */ + /* NXM and OXM support matching tun_id. */ if (wc->masks.tunnel.tun_id != htonll(0)) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports matching fragments. */ + /* NXM and OXM support matching fragments. */ if (wc->masks.nw_frag) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports matching IPv6 flow label. */ + /* NXM and OXM support matching IPv6 flow label. */ if (wc->masks.ipv6_label) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports matching IP ECN bits. */ + /* NXM and OXM support matching IP ECN bits. */ if (wc->masks.nw_tos & IP_ECN_MASK) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports matching IP TTL/hop limit. */ + /* NXM and OXM support matching IP TTL/hop limit. */ if (wc->masks.nw_ttl) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports non-CIDR IPv4 address masks. */ + /* NXM and OXM support non-CIDR IPv4 address masks. */ if (!ip_is_cidr(wc->masks.nw_src) || !ip_is_cidr(wc->masks.nw_dst)) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } - /* Only NXM supports bitwise matching on transport port. */ + /* NXM and OXM support bitwise matching on transport port. */ if ((wc->masks.tp_src && wc->masks.tp_src != htons(UINT16_MAX)) || (wc->masks.tp_dst && wc->masks.tp_dst != htons(UINT16_MAX))) { - return OFPUTIL_P_OF10_NXM_ANY; + return OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } /* Other formats can express this rule. */ @@ -1597,9 +1597,9 @@ ofputil_flow_mod_usable_protocols(const struct ofputil_flow_mod *fms, usable_protocols &= OFPUTIL_P_TID; } - /* Matching of the cookie is only supported through NXM. */ + /* Matching of the cookie is only supported through NXM or OF1.1+. */ if (fm->cookie_mask != htonll(0)) { - usable_protocols &= OFPUTIL_P_OF10_NXM_ANY; + usable_protocols &= OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } } assert(usable_protocols); @@ -1791,7 +1791,7 @@ ofputil_flow_stats_request_usable_protocols( usable_protocols = ofputil_usable_protocols(&fsr->match); if (fsr->cookie_mask != htonll(0)) { - usable_protocols &= OFPUTIL_P_OF10_NXM_ANY; + usable_protocols &= OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF12_OXM; } return usable_protocols; } diff --git a/lib/ofp-util.h b/lib/ofp-util.h index a081cbf0..edefa2de 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -86,10 +86,12 @@ enum ofputil_protocol { OFPUTIL_P_OF12_OXM = 1 << 4, /* All protocols. */ -#define OFPUTIL_P_ANY (OFPUTIL_P_OF10_STD_ANY | OFPUTIL_P_OF10_NXM_ANY) +#define OFPUTIL_P_ANY ((1 << 5) - 1) /* Protocols in which a specific table may be specified in flow_mods. */ -#define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | OFPUTIL_P_OF10_NXM_TID) +#define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \ + OFPUTIL_P_OF10_NXM_TID | \ + OFPUTIL_P_OF12_OXM) }; /* Protocols to use for flow dumps, from most to least preferred. */ diff --git a/tests/learn.at b/tests/learn.at index adb67a4d..2fc82f18 100644 --- a/tests/learn.at +++ b/tests/learn.at @@ -24,7 +24,7 @@ table=0 actions=learn(table=1,hard_timeout=10, NXM_OF_VLAN_TCI[0..11],output:NXM table=1 priority=0 actions=flood ]]) AT_CHECK([ovs-ofctl parse-flows flows.txt], [0], -[[usable protocols: OpenFlow10+table_id,NXM+table_id +[[usable protocols: OpenFlow10+table_id,NXM+table_id,OXM chosen protocol: OpenFlow10+table_id OFPT_FLOW_MOD (xid=0x1): ADD table:255 actions=learn(table=1,in_port=99,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG1[16..31]) OFPT_FLOW_MOD (xid=0x2): ADD table:255 actions=learn(table=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],output:NXM_OF_IN_PORT[]) diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at index 958982f0..1d9158c8 100644 --- a/tests/ovs-ofctl.at +++ b/tests/ovs-ofctl.at @@ -66,7 +66,7 @@ actions=controller(max_len=123,reason=invalid_ttl,id=555) AT_CHECK([ovs-ofctl parse-flows flows.txt ], [0], [stdout]) AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], -[[usable protocols: NXM+table_id +[[usable protocols: NXM+table_id,OXM chosen protocol: NXM+table_id NXT_FLOW_MOD: ADD table:255 tcp,tp_src=123 actions=FLOOD NXT_FLOW_MOD: ADD table:255 in_port=65534,dl_vlan=9,dl_src=00:0a:e4:25:6b:b0 actions=drop @@ -131,7 +131,7 @@ dl_dst=aa:bb:cc:dd:ee:ff/00:00:00:00:00:00,actions=drop ]) AT_CHECK([ovs-ofctl -F nxm parse-flows flows.txt], [0], [stdout]) AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], [dnl -usable protocols: NXM +usable protocols: NXM,OXM chosen protocol: NXM-table_id NXT_FLOW_MOD: ADD tcp,tp_src=123 actions=FLOOD NXT_FLOW_MOD: ADD in_port=65534,dl_vlan=9,dl_src=00:0a:e4:25:6b:b0 actions=drop @@ -193,7 +193,7 @@ vlan_tci=0x1123/0x1fff,actions=drop ]]) AT_CHECK([ovs-ofctl -F nxm -mmm parse-flows flows.txt], [0], [stdout], [stderr]) AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], -[[usable protocols: NXM +[[usable protocols: NXM,OXM chosen protocol: NXM-table_id NXT_FLOW_MOD: ADD NXM_OF_ETH_TYPE(0800), NXM_OF_IP_PROTO(06), NXM_OF_TCP_SRC(007b) actions=FLOOD NXT_FLOW_MOD: ADD NXM_OF_IN_PORT(fffe), NXM_OF_ETH_SRC(000ae4256bb0), NXM_OF_VLAN_TCI_W(1009/1fff) actions=drop @@ -1863,10 +1863,10 @@ dnl Check that "-F openflow10" rejects a flow_mod with unsupported features, dnl such as tunnels and metadata. AT_SETUP([ovs-ofctl -F option and NXM features]) AT_CHECK([ovs-ofctl -F openflow10 add-flow dummy tun_id=123,actions=drop], - [1], [], [ovs-ofctl: none of the usable flow formats (NXM) is among the allowed flow formats (OpenFlow10) + [1], [], [ovs-ofctl: none of the usable flow formats (NXM,OXM) is among the allowed flow formats (OpenFlow10) ]) AT_CHECK([ovs-ofctl -F openflow10 add-flow dummy metadata=123,actions=drop], - [1], [], [ovs-ofctl: none of the usable flow formats (NXM) is among the allowed flow formats (OpenFlow10) + [1], [], [ovs-ofctl: none of the usable flow formats (NXM,OXM) is among the allowed flow formats (OpenFlow10) ]) AT_CLEANUP @@ -1901,7 +1901,7 @@ dnl can't be represented in OpenFlow 1.0. AT_SETUP([ovs-ofctl dump-flows rejects bad -F option]) OVS_VSWITCHD_START AT_CHECK([ovs-ofctl -F openflow10 dump-flows unix:br0.mgmt reg0=0xabcdef], [1], [], - [ovs-ofctl: none of the usable flow formats (NXM) is among the allowed flow formats (OpenFlow10) + [ovs-ofctl: none of the usable flow formats (NXM,OXM) is among the allowed flow formats (OpenFlow10) ]) OVS_VSWITCHD_STOP AT_CLEANUP -- 2.30.2