From: Ethan Jackson Date: Thu, 12 May 2011 01:13:35 +0000 (-0700) Subject: cfm: Replace recv_time with a flag. X-Git-Tag: v1.2.0~366 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=dd986e09fdbb79be4a7e8dbb77dca8f68c04c321;p=sliver-openvswitch.git cfm: Replace recv_time with a flag. This makes the code more obviously correct in my opinion. This patch also removes timer_enabled_at() along with its only user. --- diff --git a/lib/cfm.c b/lib/cfm.c index 076344c26..b742d22b6 100644 --- 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"); } } diff --git a/lib/cfm.h b/lib/cfm.h index 1be1981e8..4bb8dc93e 100644 --- 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. */ }; diff --git a/lib/timer.c b/lib/timer.c index 1c3c0f488..b640a7be8 100644 --- a/lib/timer.c +++ b/lib/timer.c @@ -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; - } -} diff --git a/lib/timer.h b/lib/timer.h index 730205566..d2bfd86b0 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -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.