[ovs-dev] [RFC PATCH 2/2] v2: ofproto: Index flows by cookie.

Ben Pfaff blp at nicira.com
Tue Jun 18 17:52:51 UTC 2013


On Tue, Jun 18, 2013 at 07:48:14PM +0300, Jarno Rajahalme wrote:
> The simplest way for an OpenFlow controller to refer to a (set of) flows
> is by a controller-issued flow cookie.  Make this fast by inserting flows
> to a hash index, and use that when flows are queried, deleted, or modified
> with a full cookie mask.
> 
> Signed-off-by: Jarno Rajahalme <jarno.rajahalme at nsn.com>
> ---
> v2: Changed to use the new hindex + also index zero valued cookies.

To avoid "sparse" warnings, I folded in the following:

diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 51c0955..eabe850 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -2626,7 +2626,8 @@ handle_port_desc_stats_request(struct ofconn *ofconn,
 static uint32_t
 hash_cookie(ovs_be64 cookie)
 {
-    return hash_2words((uint32_t)(cookie >> 32),(uint32_t)cookie);
+    return hash_2words((OVS_FORCE uint64_t)cookie >> 32,
+                       (OVS_FORCE uint64_t)cookie);
 }
 
 static void
@@ -2761,7 +2762,7 @@ collect_rules_loose(struct ofproto *ofproto, uint8_t table_id,
     list_init(rules);
     cls_rule_init(&cr, match, 0);
 
-    if (cookie_mask == UINT64_MAX) {
+    if (cookie_mask == htonll(UINT64_MAX)) {
         struct rule *rule;
 
         HINDEX_FOR_EACH_WITH_HASH (rule, cookie_node, hash_cookie(cookie),
@@ -2838,7 +2839,7 @@ collect_rules_strict(struct ofproto *ofproto, uint8_t table_id,
     list_init(rules);
     cls_rule_init(&cr, match, priority);
 
-    if (cookie_mask == UINT64_MAX) {
+    if (cookie_mask == htonll(UINT64_MAX)) {
         struct rule *rule;
 
         HINDEX_FOR_EACH_WITH_HASH (rule, cookie_node, hash_cookie(cookie),

In final review I noticed one other thing: changing a cookie breaks
the transactional model for ofoperations.  The design of ofoperations
is supposed to hide incomplete ofoperations from controllers, so that
a controller can only work with flows that have been committed, and
anything that might still fail is hidden (via OFPROTO_POSTPONE).  But
cookies are an oversight here: match-by-cookie on value X will fail to
find a flow whose cookie was X but is in the process of being changed
to Y.

However, this was broken before and your commit doesn't make it worse,
so I'll commit it in a minute.

Thanks a lot!



More information about the dev mailing list