[ovs-dev] [PATCH] cfm: Support random VLAN tag for CCM PDUs.

Ethan Jackson ethan at nicira.com
Sat Mar 17 01:05:21 UTC 2012


CCM PDUs may take a different path through the network depending on
the VLAN tag they carry.  In order to exercise these paths, it
may be advantageous to use a random VLAN tag.

Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
 lib/cfm.c            |   13 +++++++++----
 lib/cfm.h            |    3 ++-
 vswitchd/bridge.c    |   13 +++++++++++--
 vswitchd/vswitch.xml |    3 ++-
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/lib/cfm.c b/lib/cfm.c
index 8d90829..10a9428 100644
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -30,6 +30,7 @@
 #include "ofpbuf.h"
 #include "packets.h"
 #include "poll-loop.h"
+#include "random.h"
 #include "timer.h"
 #include "timeval.h"
 #include "unixctl.h"
@@ -96,7 +97,7 @@ struct cfm {
     uint32_t seq;          /* The sequence number of our last CCM. */
     uint8_t ccm_interval;  /* The CCM transmission interval. */
     int ccm_interval_ms;   /* 'ccm_interval' in milliseconds. */
-    uint16_t ccm_vlan;     /* Vlan tag of CCM PDUs. */
+    uint16_t ccm_vlan;     /* Vlan tag of CCM PDUs. UINT16_MAX if random. */
     uint8_t ccm_pcp;       /* Priority of CCM PDUs. */
     uint8_t maid[CCM_MAID_LEN]; /* The MAID of this CFM. */
 
@@ -391,13 +392,17 @@ void
 cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,
                 uint8_t eth_src[ETH_ADDR_LEN])
 {
+    uint16_t ccm_vlan;
     struct ccm *ccm;
 
     timer_set_duration(&cfm->tx_timer, cfm->ccm_interval_ms);
     eth_compose(packet, cfm_ccm_addr(cfm), eth_src, ETH_TYPE_CFM, sizeof *ccm);
 
-    if (cfm->ccm_vlan || cfm->ccm_pcp) {
-        uint16_t tci = cfm->ccm_vlan | (cfm->ccm_pcp << VLAN_PCP_SHIFT);
+    ccm_vlan = cfm->ccm_vlan != UINT16_MAX ? cfm->ccm_vlan : random_uint16();
+    ccm_vlan = ccm_vlan & VLAN_VID_MASK;
+
+    if (ccm_vlan || cfm->ccm_pcp) {
+        uint16_t tci = ccm_vlan | (cfm->ccm_pcp << VLAN_PCP_SHIFT);
         eth_push_vlan(packet, htons(tci));
     }
 
@@ -455,7 +460,7 @@ cfm_configure(struct cfm *cfm, const struct cfm_settings *s)
     interval = ms_to_ccm_interval(s->interval);
     interval_ms = ccm_interval_to_ms(interval);
 
-    cfm->ccm_vlan = s->ccm_vlan & VLAN_VID_MASK;
+    cfm->ccm_vlan = s->ccm_vlan;
     cfm->ccm_pcp = s->ccm_pcp & (VLAN_PCP_MASK >> VLAN_PCP_SHIFT);
     if (cfm->extended && interval_ms != s->interval) {
         interval = 0;
diff --git a/lib/cfm.h b/lib/cfm.h
index 6d23293..c706c70 100644
--- a/lib/cfm.h
+++ b/lib/cfm.h
@@ -51,7 +51,8 @@ struct cfm_settings {
     int interval;               /* The requested transmission interval. */
     bool extended;              /* Run in extended mode. */
     bool opup;                  /* Operational State. */
-    uint16_t ccm_vlan;          /* CCM Vlan tag. Zero if none. */
+    uint16_t ccm_vlan;          /* CCM Vlan tag. Zero if none.
+                                   UINT16_MAX if random. */
     uint8_t ccm_pcp;            /* CCM Priority. Zero if none. */
 };
 
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 4761cbf..64d7c4d 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -3226,6 +3226,7 @@ iface_configure_cfm(struct iface *iface)
 {
     const struct ovsrec_interface *cfg = iface->cfg;
     const char *extended_str, *opstate_str;
+    const char *cfm_ccm_vlan;
     struct cfm_settings s;
 
     if (!cfg->n_cfm_mpid) {
@@ -3236,14 +3237,22 @@ iface_configure_cfm(struct iface *iface)
     s.mpid = *cfg->cfm_mpid;
     s.interval = atoi(get_interface_other_config(iface->cfg, "cfm_interval",
                                                  "0"));
-    s.ccm_vlan = atoi(get_interface_other_config(iface->cfg, "cfm_ccm_vlan",
-                                                 "0"));
+    cfm_ccm_vlan = get_interface_other_config(iface->cfg, "cfm_ccm_vlan", "0");
     s.ccm_pcp = atoi(get_interface_other_config(iface->cfg, "cfm_ccm_pcp",
                                                 "0"));
     if (s.interval <= 0) {
         s.interval = 1000;
     }
 
+    if (!strcasecmp("random", cfm_ccm_vlan)) {
+        s.ccm_vlan = UINT16_MAX;
+    } else {
+        s.ccm_vlan = atoi(cfm_ccm_vlan);
+        if (s.ccm_vlan == UINT16_MAX) {
+            s.ccm_vlan = 0;
+        }
+    }
+
     extended_str = get_interface_other_config(iface->cfg, "cfm_extended",
                                               "false");
     s.extended = !strcasecmp("true", extended_str);
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 7739793..3ea6810 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -1768,7 +1768,8 @@
       <column name="other_config" key="cfm_ccm_vlan"
         type='{"type": "integer", "minInteger": 1, "maxInteger": 4095}'>
         When set, the CFM module will apply a VLAN tag to all CCMs it generates
-        with the given value.
+        with the given value.  May be the string "random" in which case each
+        CCM will be tagged with a different randomly generated VLAN.
       </column>
 
       <column name="other_config" key="cfm_ccm_pcp"
-- 
1.7.9.2




More information about the dev mailing list