cfm: Replace recv_time with a flag.
authorEthan Jackson <ethan@nicira.com>
Thu, 12 May 2011 01:13:35 +0000 (18:13 -0700)
committerEthan Jackson <ethan@nicira.com>
Fri, 13 May 2011 20:09:27 +0000 (13:09 -0700)
This makes the code more obviously correct in my opinion.

This patch also removes timer_enabled_at() along with its only
user.

lib/cfm.c
lib/cfm.h
lib/timer.c
lib/timer.h

index 076344c..b742d22 100644 (file)
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -47,6 +47,8 @@ struct cfm_internal {
     struct timer fault_timer; /* Check for faults when expired. */
 };
 
+static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
+
 static int
 ccm_interval_to_ms(uint8_t interval)
 {
@@ -173,16 +175,20 @@ cfm_run(struct cfm *cfm)
 
         cfm->fault = false;
         HMAP_FOR_EACH (rmp, node, &cfm->remote_mps) {
-            if (rmp->recv_time < timer_enabled_at(&cfmi->fault_timer, interval)
-                || timer_expired_at(&cfmi->fault_timer, rmp->recv_time)) {
-                rmp->fault = true;
-            }
+            rmp->fault = !rmp->recv;
+            rmp->recv = false;
 
             if (rmp->fault) {
                 cfm->fault = true;
+                VLOG_DBG("No CCM from RMP %"PRIu16" in the last %lldms",
+                         rmp->mpid, interval);
             }
         }
 
+        if (!cfm->fault) {
+            VLOG_DBG("All RMPs received CCMs in the last %lldms", interval);
+        }
+
         timer_set_duration(&cfmi->fault_timer, interval);
     }
 }
@@ -352,9 +358,7 @@ cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
     uint8_t ccm_interval;
     struct remote_mp *rmp;
     struct eth_header *eth;
-
-    struct cfm_internal *cfmi        = cfm_to_internal(cfm);
-    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
+    struct cfm_internal *cfmi = cfm_to_internal(cfm);
 
     eth = p->l2;
     ccm = ofpbuf_at(p, (uint8_t *)p->l3 - (uint8_t *)p->data, CCM_LEN);
@@ -389,7 +393,7 @@ cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
         rmp = lookup_remote_mp(&cfm->remote_mps, ccm_mpid);
 
         if (rmp) {
-            rmp->recv_time = time_msec();
+            rmp->recv = true;
 
             if (ccm_interval != cfmi->ccm_interval) {
                 VLOG_WARN_RL(&rl, "received a CCM with an invalid interval"
@@ -422,7 +426,7 @@ cfm_dump_ds(const struct cfm *cfm, struct ds *ds)
     HMAP_FOR_EACH (rmp, node, &cfm->remote_mps) {
         ds_put_format(ds, "Remote MPID %"PRIu16": %s\n", rmp->mpid,
                       rmp->fault ? "fault" : "");
-        ds_put_format(ds, "\ttime since CCM rx: %lldms\n",
-                      time_msec() - rmp->recv_time);
+        ds_put_format(ds, "\trecv since check: %s",
+                      rmp->recv ? "true" : "false");
     }
 }
index 1be1981..4bb8dc9 100644 (file)
--- a/lib/cfm.h
+++ b/lib/cfm.h
@@ -69,7 +69,7 @@ struct remote_mp {
     uint16_t mpid;         /* The Maintenance Point ID of this 'remote_mp'. */
     struct hmap_node node; /* In 'cfm' 'remote_mps' or 'x_remote_mps'. */
 
-    long long recv_time; /* Time the most recent CCM was received. */
+    bool recv;           /* CCM was received since last fault check. */
     bool fault;          /* Indicates a connectivity fault. */
 };
 
index 1c3c0f4..b640a7b 100644 (file)
@@ -40,16 +40,3 @@ timer_wait(const struct timer *timer)
         poll_timer_wait_until(timer->t);
     }
 }
-
-/* Returns the time at which 'timer' was set with 'duration'.  Infinite timers
- * were enabled at time LLONG_MAX.  Manually expired timers were enabled at
- * LLONG_MIN. */
-long long int
-timer_enabled_at(const struct timer *timer, long long int duration)
-{
-    switch (timer->t) {
-    case LLONG_MAX: return LLONG_MAX;
-    case LLONG_MIN: return LLONG_MIN;
-    default: return timer->t - duration;
-    }
-}
index 7302055..d2bfd86 100644 (file)
@@ -26,7 +26,6 @@ struct timer {
 };
 
 long long int timer_msecs_until_expired(const struct timer *);
-long long int timer_enabled_at(const struct timer *, long long int duration);
 void timer_wait(const struct timer *);
 
 /* Causes 'timer' to expire when 'duration' milliseconds have passed.