ofproto: Add functions to configure multicast snooping
authorFlavio Leitner <fbl@redhat.com>
Thu, 19 Jun 2014 01:14:32 +0000 (22:14 -0300)
committerBen Pfaff <blp@nicira.com>
Tue, 24 Jun 2014 18:17:08 +0000 (11:17 -0700)
Signed-off-by: Flavio Leitner <fbl@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
ofproto/ofproto-dpif.c
ofproto/ofproto-provider.h
ofproto/ofproto.c
ofproto/ofproto.h

index 27233cb..d623ee7 100644 (file)
@@ -2701,6 +2701,56 @@ set_mac_table_config(struct ofproto *ofproto_, unsigned int idle_time,
     mac_learning_set_max_entries(ofproto->ml, max_entries);
     ovs_rwlock_unlock(&ofproto->ml->rwlock);
 }
+
+/* Configures multicast snooping on 'ofport' using the settings
+ * defined in 's'. */
+static int
+set_mcast_snooping(struct ofproto *ofproto_,
+                   const struct ofproto_mcast_snooping_settings *s)
+{
+    struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
+
+    /* Only revalidate flows if the configuration changed. */
+    if (!s != !ofproto->ms) {
+        ofproto->backer->need_revalidate = REV_RECONFIGURE;
+    }
+
+    if (s) {
+        if (!ofproto->ms) {
+            ofproto->ms = mcast_snooping_create();
+        }
+
+        ovs_rwlock_wrlock(&ofproto->ms->rwlock);
+        mcast_snooping_set_idle_time(ofproto->ms, s->idle_time);
+        mcast_snooping_set_max_entries(ofproto->ms, s->max_entries);
+        if (mcast_snooping_set_flood_unreg(ofproto->ms, s->flood_unreg)) {
+            ofproto->backer->need_revalidate = REV_RECONFIGURE;
+        }
+        ovs_rwlock_unlock(&ofproto->ms->rwlock);
+    } else {
+        mcast_snooping_unref(ofproto->ms);
+        ofproto->ms = NULL;
+    }
+
+    return 0;
+}
+
+/* Configures multicast snooping port's flood setting on 'ofproto'. */
+static int
+set_mcast_snooping_port(struct ofproto *ofproto_, void *aux, bool flood)
+{
+    struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
+    struct ofbundle *bundle = bundle_lookup(ofproto, aux);
+
+    if (ofproto->ms) {
+        ovs_rwlock_wrlock(&ofproto->ms->rwlock);
+        mcast_snooping_set_port_flood(ofproto->ms, bundle->vlan, bundle,
+                                      flood);
+        ovs_rwlock_unlock(&ofproto->ms->rwlock);
+    }
+    return 0;
+}
+
 \f
 /* Ports. */
 
@@ -4988,6 +5038,8 @@ const struct ofproto_class ofproto_dpif_class = {
     is_mirror_output_bundle,
     forward_bpdu_changed,
     set_mac_table_config,
+    set_mcast_snooping,
+    set_mcast_snooping_port,
     set_realdev,
     NULL,                       /* meter_get_features */
     NULL,                       /* meter_set */
index 6d1fb14..af4409e 100644 (file)
@@ -1530,6 +1530,31 @@ struct ofproto_class {
     void (*set_mac_table_config)(struct ofproto *ofproto,
                                  unsigned int idle_time, size_t max_entries);
 
+    /* Configures multicast snooping on 'ofport' using the settings
+     * defined in 's'.
+     *
+     * If 's' is nonnull, this function updates multicast snooping
+     * configuration to 's' in 'ofproto'.
+     *
+     * If 's' is NULL, this function disables multicast snooping
+     * on 'ofproto'.
+     *
+     * An implementation that does not support multicast snooping may set
+     * it to NULL or return EOPNOTSUPP. */
+    int (*set_mcast_snooping)(struct ofproto *ofproto,
+                              const struct ofproto_mcast_snooping_settings *s);
+
+    /* Configures multicast snooping port's flood setting on 'ofproto'.
+     *
+     * All multicast traffic is sent to struct port 'aux' in 'ofproto'
+     * if 'flood' is true. Otherwise, struct port 'aux' is an ordinary
+     * switch port.
+     *
+     * An implementation that does not support multicast snooping may set
+     * it to NULL or return EOPNOTSUPP. */
+    int (*set_mcast_snooping_port)(struct ofproto *ofproto_, void *aux,
+                                   bool flood);
+
 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
  *
  * This is deprecated.  It is only for compatibility with broken device drivers
index 670b4ff..5399c9f 100644 (file)
@@ -721,6 +721,33 @@ ofproto_set_mac_table_config(struct ofproto *ofproto, unsigned idle_time,
     }
 }
 
+/* Multicast snooping configuration. */
+
+/* Configures multicast snooping on 'ofproto' using the settings
+ * defined in 's'.  If 's' is NULL, disables multicast snooping.
+ *
+ * Returns 0 if successful, otherwise a positive errno value. */
+int
+ofproto_set_mcast_snooping(struct ofproto *ofproto,
+                           const struct ofproto_mcast_snooping_settings *s)
+{
+    return (ofproto->ofproto_class->set_mcast_snooping
+            ? ofproto->ofproto_class->set_mcast_snooping(ofproto, s)
+            : EOPNOTSUPP);
+}
+
+/* Configures multicast snooping flood setting on 'ofp_port' of 'ofproto'.
+ *
+ * Returns 0 if successful, otherwise a positive errno value.*/
+int
+ofproto_port_set_mcast_snooping(struct ofproto *ofproto, void *aux, bool flood)
+{
+    return (ofproto->ofproto_class->set_mcast_snooping_port
+            ? ofproto->ofproto_class->set_mcast_snooping_port(ofproto, aux,
+                                                              flood)
+            : EOPNOTSUPP);
+}
+
 void
 ofproto_set_threads(int n_handlers_, int n_revalidators_)
 {
index 60b742b..beabcf2 100644 (file)
@@ -123,6 +123,15 @@ struct ofproto_port_queue {
     uint8_t dscp;               /* DSCP bits (e.g. [0, 63]). */
 };
 
+struct ofproto_mcast_snooping_settings {
+    bool flood_unreg;           /* If true, flood unregistered packets to all
+                                   all ports. If false, send only to ports
+                                   connected to multicast routers. */
+    unsigned int idle_time;     /* Entry is removed after the idle time
+                                 * in seconds. */
+    unsigned int max_entries;   /* Size of the multicast snooping table. */
+};
+
 /* How the switch should act if the controller cannot be contacted. */
 enum ofproto_fail_mode {
     OFPROTO_FAIL_SECURE,        /* Preserve flow table. */
@@ -241,6 +250,10 @@ void ofproto_set_max_idle(unsigned max_idle);
 void ofproto_set_forward_bpdu(struct ofproto *, bool forward_bpdu);
 void ofproto_set_mac_table_config(struct ofproto *, unsigned idle_time,
                                   size_t max_entries);
+int ofproto_set_mcast_snooping(struct ofproto *ofproto,
+                              const struct ofproto_mcast_snooping_settings *s);
+int ofproto_port_set_mcast_snooping(struct ofproto *ofproto, void *aux,
+                                    bool flood);
 void ofproto_set_threads(int n_handlers, int n_revalidators);
 void ofproto_set_dp_desc(struct ofproto *, const char *dp_desc);
 int ofproto_set_snoops(struct ofproto *, const struct sset *snoops);