/*
- * Copyright (c) 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "byte-order.h"
#include "connectivity.h"
-#include "dynamic-string.h"
+#include "dp-packet.h"
+#include "openvswitch/dynamic-string.h"
#include "flow.h"
#include "hash.h"
-#include "hmap.h"
+#include "openvswitch/hmap.h"
#include "netdev.h"
-#include "ofpbuf.h"
+#include "ovs-atomic.h"
#include "packets.h"
-#include "poll-loop.h"
+#include "openvswitch/poll-loop.h"
#include "random.h"
#include "seq.h"
#include "timer.h"
#include "timeval.h"
#include "unixctl.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
+#include "util.h"
VLOG_DEFINE_THIS_MODULE(cfm);
#define CFM_MAX_RMPS 256
/* Ethernet destination address of CCM packets. */
-static const uint8_t eth_addr_ccm[6] = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 };
-static const uint8_t eth_addr_ccm_x[6] = {
- 0x01, 0x23, 0x20, 0x00, 0x00, 0x30
-};
+static const struct eth_addr eth_addr_ccm = ETH_ADDR_C(01,80,c2,00,00,30);
+static const struct eth_addr eth_addr_ccm_x = ETH_ADDR_C(01,23,20,00,00,30);
#define ETH_TYPE_CFM 0x8902
recomputed. */
long long int last_tx; /* Last CCM transmission time. */
+ /* These bools are atomic to allow readers to check their values
+ * without taking 'mutex'. Such readers do not assume the values they
+ * read are synchronized with any other members. */
atomic_bool check_tnl_key; /* Verify the tunnel key of inbound packets? */
atomic_bool extended; /* Extended mode. */
struct ovs_refcount ref_cnt;
}
}
-static const uint8_t *
+static struct eth_addr
cfm_ccm_addr(struct cfm *cfm)
{
bool extended;
- atomic_read(&cfm->extended, &extended);
+
+ atomic_read_relaxed(&cfm->extended, &extended);
+
return extended ? eth_addr_ccm_x : eth_addr_ccm;
}
void
cfm_unref(struct cfm *cfm) OVS_EXCLUDED(mutex)
{
- struct remote_mp *rmp, *rmp_next;
+ struct remote_mp *rmp;
if (!cfm) {
return;
hmap_remove(all_cfms, &cfm->hmap_node);
ovs_mutex_unlock(&mutex);
- HMAP_FOR_EACH_SAFE (rmp, rmp_next, node, &cfm->remote_mps) {
- hmap_remove(&cfm->remote_mps, &rmp->node);
+ HMAP_FOR_EACH_POP (rmp, node, &cfm->remote_mps) {
free(rmp);
}
/* Composes a CCM message into 'packet'. Messages generated with this function
* should be sent whenever cfm_should_send_ccm() indicates. */
void
-cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,
- uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
+cfm_compose_ccm(struct cfm *cfm, struct dp_packet *packet,
+ const struct eth_addr eth_src) OVS_EXCLUDED(mutex)
{
uint16_t ccm_vlan;
struct ccm *ccm;
eth_push_vlan(packet, htons(ETH_TYPE_VLAN), htons(tci));
}
- ccm = ofpbuf_l3(packet);
+ atomic_read_relaxed(&cfm->extended, &extended);
+
+ ccm = dp_packet_l3(packet);
ccm->mdlevel_version = 0;
ccm->opcode = CCM_OPCODE;
ccm->tlv_offset = 70;
memset(ccm->zero, 0, sizeof ccm->zero);
ccm->end_tlv = 0;
- atomic_read(&cfm->extended, &extended);
if (extended) {
ccm->mpid = htons(hash_mpid(cfm->mpid));
ccm->mpid64 = htonll(cfm->mpid);
if (cfm->last_tx) {
long long int delay = time_msec() - cfm->last_tx;
if (delay > (cfm->ccm_interval_ms * 3 / 2)) {
- VLOG_WARN("%s: long delay of %lldms (expected %dms) sending CCM"
+ VLOG_INFO("%s: long delay of %lldms (expected %dms) sending CCM"
" seq %"PRIu32, cfm->name, delay, cfm->ccm_interval_ms,
cfm->seq);
}
ovs_mutex_unlock(&mutex);
}
-void
+long long int
cfm_wait(struct cfm *cfm) OVS_EXCLUDED(mutex)
{
- poll_timer_wait_until(cfm_wake_time(cfm));
+ long long int wake_time = cfm_wake_time(cfm);
+ poll_timer_wait_until(wake_time);
+ return wake_time;
}
interval = ms_to_ccm_interval(s->interval);
interval_ms = ccm_interval_to_ms(interval);
- atomic_store(&cfm->check_tnl_key, s->check_tnl_key);
- atomic_store(&cfm->extended, s->extended);
+ atomic_store_relaxed(&cfm->check_tnl_key, s->check_tnl_key);
+ atomic_store_relaxed(&cfm->extended, s->extended);
cfm->ccm_vlan = s->ccm_vlan;
cfm->ccm_pcp = s->ccm_pcp & (VLAN_PCP_MASK >> VLAN_PCP_SHIFT);
struct cfm *cfm = CONST_CAST(struct cfm *, cfm_);
bool check_tnl_key;
- atomic_read(&cfm->check_tnl_key, &check_tnl_key);
+ /* Most packets are not CFM. */
+ if (OVS_LIKELY(flow->dl_type != htons(ETH_TYPE_CFM))) {
+ return false;
+ }
+
memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
+ if (OVS_UNLIKELY(!eth_addr_equals(flow->dl_dst, cfm_ccm_addr(cfm)))) {
+ return false;
+ }
+
+ atomic_read_relaxed(&cfm->check_tnl_key, &check_tnl_key);
+
if (check_tnl_key) {
memset(&wc->masks.tunnel.tun_id, 0xff, sizeof wc->masks.tunnel.tun_id);
+ return flow->tunnel.tun_id == htonll(0);
}
- return (ntohs(flow->dl_type) == ETH_TYPE_CFM
- && eth_addr_equals(flow->dl_dst, cfm_ccm_addr(cfm))
- && (!check_tnl_key || flow->tunnel.tun_id == htonll(0)));
+ return true;
}
/* Updates internal statistics relevant to packet 'p'. Should be called on
* every packet whose flow returned true when passed to
* cfm_should_process_flow. */
void
-cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
+cfm_process_heartbeat(struct cfm *cfm, const struct dp_packet *p)
OVS_EXCLUDED(mutex)
{
struct ccm *ccm;
struct eth_header *eth;
+ bool extended;
ovs_mutex_lock(&mutex);
- eth = ofpbuf_l2(p);
- ccm = ofpbuf_at(p, (uint8_t *)ofpbuf_l3(p) - (uint8_t *)ofpbuf_data(p),
+ atomic_read_relaxed(&cfm->extended, &extended);
+
+ eth = dp_packet_eth(p);
+ ccm = dp_packet_at(p, (uint8_t *)dp_packet_l3(p) - (uint8_t *)dp_packet_data(p),
CCM_ACCEPT_LEN);
if (!ccm) {
*
* Faults can cause a controller or Open vSwitch to make potentially
* expensive changes to the network topology. It seems prudent to trigger
- * them judiciously, especially when CFM is used to check slave status of
- * bonds. Furthermore, faults can be maliciously triggered by crafting
+ * them judiciously, especially when CFM is used to check status of bond
+ * members. Furthermore, faults can be maliciously triggered by crafting
* unexpected CCMs. */
if (memcmp(ccm->maid, cfm->maid, sizeof ccm->maid)) {
cfm->recv_fault |= CFM_FAULT_MAID;
uint64_t ccm_mpid;
uint32_t ccm_seq;
bool ccm_opdown;
- bool extended;
enum cfm_fault_reason cfm_fault = 0;
- atomic_read(&cfm->extended, &extended);
if (extended) {
ccm_mpid = ntohll(ccm->mpid64);
ccm_opdown = ccm->opdown;
struct cfm *cfm = CONST_CAST(struct cfm *, cfm_);
bool extended;
- atomic_read(&cfm->extended, &extended);
+ atomic_read_relaxed(&cfm->extended, &extended);
return extended ? cfm->remote_opup : -1;
}
bool extended;
int fault;
- atomic_read(&cfm->extended, &extended);
+ atomic_read_relaxed(&cfm->extended, &extended);
ds_put_format(ds, "---- %s ----\n", cfm->name);
ds_put_format(ds, "MPID %"PRIu64":%s%s\n", cfm->mpid,
fault = cfm_get_fault__(cfm);
if (fault) {
- ds_put_cstr(ds, "\tfault: ");
+ ds_put_cstr(ds, " fault: ");
ds_put_cfm_fault(ds, fault);
ds_put_cstr(ds, "\n");
}
if (cfm->health == -1) {
- ds_put_format(ds, "\taverage health: undefined\n");
+ ds_put_format(ds, " average health: undefined\n");
} else {
- ds_put_format(ds, "\taverage health: %d\n", cfm->health);
+ ds_put_format(ds, " average health: %d\n", cfm->health);
}
- ds_put_format(ds, "\topstate: %s\n", cfm->opup ? "up" : "down");
- ds_put_format(ds, "\tremote_opstate: %s\n",
+ ds_put_format(ds, " opstate: %s\n", cfm->opup ? "up" : "down");
+ ds_put_format(ds, " remote_opstate: %s\n",
cfm->remote_opup ? "up" : "down");
- ds_put_format(ds, "\tinterval: %dms\n", cfm->ccm_interval_ms);
- ds_put_format(ds, "\tnext CCM tx: %lldms\n",
+ ds_put_format(ds, " interval: %dms\n", cfm->ccm_interval_ms);
+ ds_put_format(ds, " next CCM tx: %lldms\n",
timer_msecs_until_expired(&cfm->tx_timer));
- ds_put_format(ds, "\tnext fault check: %lldms\n",
+ ds_put_format(ds, " next fault check: %lldms\n",
timer_msecs_until_expired(&cfm->fault_timer));
HMAP_FOR_EACH (rmp, node, &cfm->remote_mps) {
ds_put_format(ds, "Remote MPID %"PRIu64"\n", rmp->mpid);
- ds_put_format(ds, "\trecv since check: %s\n",
+ ds_put_format(ds, " recv since check: %s\n",
rmp->recv ? "true" : "false");
- ds_put_format(ds, "\topstate: %s\n", rmp->opup? "up" : "down");
+ ds_put_format(ds, " opstate: %s\n", rmp->opup? "up" : "down");
}
}