ofproto-dpif: Hide rule_dpif_miss_rule().
authorEthan Jackson <ethan@nicira.com>
Fri, 26 Jul 2013 00:20:53 +0000 (17:20 -0700)
committerEthan Jackson <ethan@nicira.com>
Thu, 8 Aug 2013 21:09:08 +0000 (14:09 -0700)
It's simpler to hide it than to make it thread safe and ensure it
stays that way in the long term.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto/ofproto-dpif-xlate.c
ofproto/ofproto-dpif-xlate.h
ofproto/ofproto-dpif.c
ofproto/ofproto-dpif.h

index 86d8222..ef45b54 100644 (file)
@@ -70,6 +70,10 @@ struct xbridge {
     struct dpif_ipfix *ipfix;     /* Ipfix handle, or null. */
     struct stp *stp;              /* STP or null if disabled. */
 
+    /* Special rules installed by ofproto-dpif. */
+    struct rule_dpif *miss_rule;
+    struct rule_dpif *no_packet_in_rule;
+
     enum ofp_config_flags frag;   /* Fragmentation handling. */
     bool has_netflow;             /* Bridge runs netflow? */
     bool has_in_band;             /* Bridge has in band control? */
@@ -209,8 +213,10 @@ static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority,
 
 void
 xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
-                  struct dpif *dpif, const struct mac_learning *ml,
-                  struct stp *stp, const struct mbridge *mbridge,
+                  struct dpif *dpif, struct rule_dpif *miss_rule,
+                  struct rule_dpif *no_packet_in_rule,
+                  const struct mac_learning *ml, struct stp *stp,
+                  const struct mbridge *mbridge,
                   const struct dpif_sflow *sflow,
                   const struct dpif_ipfix *ipfix, enum ofp_config_flags frag,
                   bool forward_bpdu, bool has_in_band, bool has_netflow)
@@ -259,6 +265,8 @@ xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
     xbridge->has_in_band = has_in_band;
     xbridge->has_netflow = has_netflow;
     xbridge->frag = frag;
+    xbridge->miss_rule = miss_rule;
+    xbridge->no_packet_in_rule = no_packet_in_rule;
 }
 
 void
@@ -1586,14 +1594,18 @@ ctx_rule_hooks(struct xlate_ctx *ctx, struct rule_dpif *rule,
         ctx->xin->resubmit_hook(ctx->xin, rule, ctx->recurse);
     }
     if (rule == NULL && may_packet_in) {
+        struct xport *xport;
+
         /* XXX
          * check if table configuration flags
          * OFPTC_TABLE_MISS_CONTROLLER, default.
          * OFPTC_TABLE_MISS_CONTINUE,
          * OFPTC_TABLE_MISS_DROP
-         * When OF1.0, OFPTC_TABLE_MISS_CONTINUE is used. What to do?
-         */
-        rule = rule_dpif_miss_rule(ctx->xbridge->ofproto, &ctx->xin->flow);
+         * When OF1.0, OFPTC_TABLE_MISS_CONTINUE is used. What to do? */
+        xport = get_ofp_port(ctx->xbridge, ctx->xin->flow.in_port.ofp_port);
+        rule = choose_miss_rule(xport ? xport->config : 0,
+                                ctx->xbridge->miss_rule,
+                                ctx->xbridge->no_packet_in_rule);
     }
     if (rule && ctx->xin->resubmit_stats) {
         rule_credit_stats(rule, ctx->xin->resubmit_stats);
index 9f8ff44..881823b 100644 (file)
@@ -111,11 +111,13 @@ struct xlate_in {
 };
 
 void xlate_ofproto_set(struct ofproto_dpif *, const char *name,
-                       struct dpif *, const struct mac_learning *,
-                       struct stp *, const struct mbridge *,
-                       const struct dpif_sflow *, const struct dpif_ipfix *,
-                       enum ofp_config_flags, bool forward_bpdu,
-                       bool has_in_band, bool has_netflow);
+                       struct dpif *, struct rule_dpif *miss_rule,
+                       struct rule_dpif *no_packet_in_rule,
+                       const struct mac_learning *, struct stp *,
+                       const struct mbridge *, const struct dpif_sflow *,
+                       const struct dpif_ipfix *, enum ofp_config_flags,
+                       bool forward_bpdu, bool has_in_band, bool has_netflow);
+
 void xlate_remove_ofproto(struct ofproto_dpif *);
 
 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
index 1a3567d..6ef2eb8 100644 (file)
@@ -799,7 +799,8 @@ type_run(const char *type)
             }
 
             xlate_ofproto_set(ofproto, ofproto->up.name,
-                              ofproto->backer->dpif, ofproto->ml,
+                              ofproto->backer->dpif, ofproto->miss_rule,
+                              ofproto->no_packet_in_rule, ofproto->ml,
                               ofproto->stp, ofproto->mbridge,
                               ofproto->sflow, ofproto->ipfix,
                               ofproto->up.frag_handling,
@@ -5105,14 +5106,21 @@ static struct rule_dpif *
 rule_dpif_lookup(struct ofproto_dpif *ofproto, const struct flow *flow,
                  struct flow_wildcards *wc)
 {
+    struct ofport_dpif *port;
     struct rule_dpif *rule;
 
     rule = rule_dpif_lookup_in_table(ofproto, flow, wc, 0);
     if (rule) {
         return rule;
     }
+    port = get_ofp_port(ofproto, flow->in_port.ofp_port);
+    if (!port) {
+        VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16,
+                     flow->in_port.ofp_port);
+    }
 
-    return rule_dpif_miss_rule(ofproto, flow);
+    return choose_miss_rule(port ? port->up.pp.config : 0, ofproto->miss_rule,
+                            ofproto->no_packet_in_rule);
 }
 
 struct rule_dpif *
@@ -5152,22 +5160,14 @@ rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto,
     return rule_dpif_cast(rule_from_cls_rule(cls_rule));
 }
 
+/* Given a port configuration (specified as zero if there's no port), chooses
+ * which of 'miss_rule' and 'no_packet_in_rule' should be used in case of a
+ * flow table miss. */
 struct rule_dpif *
-rule_dpif_miss_rule(struct ofproto_dpif *ofproto, const struct flow *flow)
+choose_miss_rule(enum ofputil_port_config config, struct rule_dpif *miss_rule,
+                 struct rule_dpif *no_packet_in_rule)
 {
-    struct ofport_dpif *port;
-
-    port = get_ofp_port(ofproto, flow->in_port.ofp_port);
-    if (!port) {
-        VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16,
-                     flow->in_port.ofp_port);
-        return ofproto->miss_rule;
-    }
-
-    if (port->up.pp.config & OFPUTIL_PC_NO_PACKET_IN) {
-        return ofproto->no_packet_in_rule;
-    }
-    return ofproto->miss_rule;
+    return config & OFPUTIL_PC_NO_PACKET_IN ? no_packet_in_rule : miss_rule;
 }
 
 static void
index 88593ce..a74146b 100644 (file)
@@ -22,6 +22,7 @@
 #include "ovs-thread.h"
 #include "timer.h"
 #include "util.h"
+#include "ovs-thread.h"
 
 union user_action_cookie;
 struct ofproto_dpif;
@@ -59,11 +60,12 @@ struct rule_dpif *rule_dpif_lookup_in_table(struct ofproto_dpif *,
                                             struct flow_wildcards *,
                                             uint8_t table_id);
 
-struct rule_dpif *rule_dpif_miss_rule(struct ofproto_dpif *ofproto,
-                                      const struct flow *);
-
 void rule_credit_stats(struct rule_dpif *, const struct dpif_flow_stats *);
 
+struct rule_dpif *choose_miss_rule(enum ofputil_port_config,
+                                   struct rule_dpif *miss_rule,
+                                   struct rule_dpif *no_packet_in_rule);
+
 bool ofproto_has_vlan_splinters(const struct ofproto_dpif *);
 ofp_port_t vsp_realdev_to_vlandev(const struct ofproto_dpif *,
                                   ofp_port_t realdev_ofp_port,