2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 22:35:15 +00:00

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.
This commit is contained in:
Ethan Jackson
2011-05-11 18:13:35 -07:00
parent aa7f115843
commit dd986e09fd
4 changed files with 15 additions and 25 deletions

View File

@@ -47,6 +47,8 @@ struct cfm_internal {
struct timer fault_timer; /* Check for faults when expired. */ struct timer fault_timer; /* Check for faults when expired. */
}; };
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
static int static int
ccm_interval_to_ms(uint8_t interval) ccm_interval_to_ms(uint8_t interval)
{ {
@@ -173,16 +175,20 @@ cfm_run(struct cfm *cfm)
cfm->fault = false; cfm->fault = false;
HMAP_FOR_EACH (rmp, node, &cfm->remote_mps) { HMAP_FOR_EACH (rmp, node, &cfm->remote_mps) {
if (rmp->recv_time < timer_enabled_at(&cfmi->fault_timer, interval) rmp->fault = !rmp->recv;
|| timer_expired_at(&cfmi->fault_timer, rmp->recv_time)) { rmp->recv = false;
rmp->fault = true;
}
if (rmp->fault) { if (rmp->fault) {
cfm->fault = true; 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); 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; uint8_t ccm_interval;
struct remote_mp *rmp; struct remote_mp *rmp;
struct eth_header *eth; struct eth_header *eth;
struct cfm_internal *cfmi = cfm_to_internal(cfm);
struct cfm_internal *cfmi = cfm_to_internal(cfm);
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
eth = p->l2; eth = p->l2;
ccm = ofpbuf_at(p, (uint8_t *)p->l3 - (uint8_t *)p->data, CCM_LEN); 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); rmp = lookup_remote_mp(&cfm->remote_mps, ccm_mpid);
if (rmp) { if (rmp) {
rmp->recv_time = time_msec(); rmp->recv = true;
if (ccm_interval != cfmi->ccm_interval) { if (ccm_interval != cfmi->ccm_interval) {
VLOG_WARN_RL(&rl, "received a CCM with an invalid 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) { HMAP_FOR_EACH (rmp, node, &cfm->remote_mps) {
ds_put_format(ds, "Remote MPID %"PRIu16": %s\n", rmp->mpid, ds_put_format(ds, "Remote MPID %"PRIu16": %s\n", rmp->mpid,
rmp->fault ? "fault" : ""); rmp->fault ? "fault" : "");
ds_put_format(ds, "\ttime since CCM rx: %lldms\n", ds_put_format(ds, "\trecv since check: %s",
time_msec() - rmp->recv_time); rmp->recv ? "true" : "false");
} }
} }

View File

@@ -69,7 +69,7 @@ struct remote_mp {
uint16_t mpid; /* The Maintenance Point ID of this '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'. */ 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. */ bool fault; /* Indicates a connectivity fault. */
}; };

View File

@@ -40,16 +40,3 @@ timer_wait(const struct timer *timer)
poll_timer_wait_until(timer->t); 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;
}
}

View File

@@ -26,7 +26,6 @@ struct timer {
}; };
long long int timer_msecs_until_expired(const 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 *); void timer_wait(const struct timer *);
/* Causes 'timer' to expire when 'duration' milliseconds have passed. /* Causes 'timer' to expire when 'duration' milliseconds have passed.