2013-10-09 04:30:37 +00:00
|
|
|
|
/*
|
2014-01-15 12:37:04 -08:00
|
|
|
|
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
|
2013-10-09 04:30:37 +00:00
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include "ofproto-dpif-monitor.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "bfd.h"
|
|
|
|
|
#include "cfm.h"
|
2015-02-22 03:21:09 -08:00
|
|
|
|
#include "dp-packet.h"
|
2014-04-03 18:31:13 -07:00
|
|
|
|
#include "guarded-list.h"
|
2013-10-09 04:30:37 +00:00
|
|
|
|
#include "hash.h"
|
2013-10-16 03:32:34 +00:00
|
|
|
|
#include "heap.h"
|
2016-07-12 16:37:34 -05:00
|
|
|
|
#include "openvswitch/hmap.h"
|
2013-10-16 03:32:30 +00:00
|
|
|
|
#include "latch.h"
|
2016-03-25 14:10:24 -07:00
|
|
|
|
#include "openvswitch/ofpbuf.h"
|
2013-10-09 04:30:37 +00:00
|
|
|
|
#include "ofproto-dpif.h"
|
2015-02-20 14:17:10 -05:00
|
|
|
|
#include "ovs-lldp.h"
|
2013-10-16 03:32:30 +00:00
|
|
|
|
#include "ovs-thread.h"
|
2017-11-03 13:53:53 +08:00
|
|
|
|
#include "openvswitch/poll-loop.h"
|
2013-10-16 03:32:30 +00:00
|
|
|
|
#include "seq.h"
|
2013-10-16 03:32:34 +00:00
|
|
|
|
#include "timeval.h"
|
2013-10-09 04:30:37 +00:00
|
|
|
|
#include "util.h"
|
2014-12-15 14:10:38 +01:00
|
|
|
|
#include "openvswitch/vlog.h"
|
2013-10-09 04:30:37 +00:00
|
|
|
|
|
2013-10-16 03:32:30 +00:00
|
|
|
|
VLOG_DEFINE_THIS_MODULE(ofproto_dpif_monitor);
|
|
|
|
|
|
2013-10-16 03:32:34 +00:00
|
|
|
|
/* Converts the time in millisecond to heap priority. */
|
|
|
|
|
#define MSEC_TO_PRIO(TIME) (LLONG_MAX - (TIME))
|
|
|
|
|
/* Converts the heap priority to time in millisecond. */
|
|
|
|
|
#define PRIO_TO_MSEC(PRIO) (LLONG_MAX - (PRIO))
|
|
|
|
|
|
2015-02-20 14:17:10 -05:00
|
|
|
|
/* Monitored port. It owns references to ofport, bfd, cfm, and lldp structs. */
|
2013-10-09 04:30:37 +00:00
|
|
|
|
struct mport {
|
|
|
|
|
struct hmap_node hmap_node; /* In monitor_hmap. */
|
2013-10-16 03:32:34 +00:00
|
|
|
|
struct heap_node heap_node; /* In monitor_heap. */
|
2013-10-09 04:30:37 +00:00
|
|
|
|
const struct ofport_dpif *ofport; /* The corresponding ofport. */
|
|
|
|
|
|
|
|
|
|
struct cfm *cfm; /* Reference to cfm. */
|
|
|
|
|
struct bfd *bfd; /* Reference to bfd. */
|
2015-02-20 14:17:10 -05:00
|
|
|
|
struct lldp *lldp; /* Reference to lldp. */
|
2015-08-28 14:55:11 -07:00
|
|
|
|
struct eth_addr hw_addr; /* Hardware address. */
|
2013-10-09 04:30:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-04-03 18:31:13 -07:00
|
|
|
|
/* Entry of the 'send_soon' list. Contains the pointer to the
|
|
|
|
|
* 'ofport_dpif'. Note, the pointed object is not protected, so
|
|
|
|
|
* users should always use the mport_find() to convert it to 'mport'. */
|
|
|
|
|
struct send_soon_entry {
|
2014-12-15 14:10:38 +01:00
|
|
|
|
struct ovs_list list_node; /* In send_soon. */
|
2014-04-03 18:31:13 -07:00
|
|
|
|
const struct ofport_dpif *ofport;
|
|
|
|
|
};
|
|
|
|
|
|
2013-10-09 04:30:37 +00:00
|
|
|
|
/* hmap that contains "struct mport"s. */
|
2013-12-20 15:12:58 -08:00
|
|
|
|
static struct hmap monitor_hmap = HMAP_INITIALIZER(&monitor_hmap);
|
2013-10-16 03:32:34 +00:00
|
|
|
|
|
|
|
|
|
/* heap for ordering mport based on bfd/cfm wakeup time. */
|
|
|
|
|
static struct heap monitor_heap;
|
2013-10-09 04:30:37 +00:00
|
|
|
|
|
2014-04-03 18:31:13 -07:00
|
|
|
|
/* guarded-list for storing the mports that need to send bfd/cfm control
|
|
|
|
|
* packet soon. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
static struct guarded_list send_soon = GUARDED_OVS_LIST_INITIALIZER(&send_soon);
|
2014-04-03 18:31:13 -07:00
|
|
|
|
|
2013-10-16 03:32:30 +00:00
|
|
|
|
/* The monitor thread id. */
|
|
|
|
|
static pthread_t monitor_tid;
|
|
|
|
|
/* True if the monitor thread is running. */
|
|
|
|
|
static bool monitor_running;
|
|
|
|
|
|
|
|
|
|
static struct latch monitor_exit_latch;
|
2014-01-15 12:37:04 -08:00
|
|
|
|
static struct ovs_mutex monitor_mutex = OVS_MUTEX_INITIALIZER;
|
2013-10-09 04:30:37 +00:00
|
|
|
|
|
2013-10-16 03:32:30 +00:00
|
|
|
|
static void *monitor_main(void *);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
static void monitor_check_send_soon(struct dp_packet *);
|
2013-10-16 03:32:30 +00:00
|
|
|
|
static void monitor_run(void);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
static void monitor_mport_run(struct mport *, struct dp_packet *);
|
2013-10-16 03:32:30 +00:00
|
|
|
|
|
2013-10-09 04:30:37 +00:00
|
|
|
|
static void mport_register(const struct ofport_dpif *, struct bfd *,
|
2015-08-28 14:55:11 -07:00
|
|
|
|
struct cfm *, struct lldp *,
|
|
|
|
|
const struct eth_addr *)
|
2014-01-15 12:37:04 -08:00
|
|
|
|
OVS_REQUIRES(monitor_mutex);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
static void mport_unregister(const struct ofport_dpif *)
|
2014-01-15 12:37:04 -08:00
|
|
|
|
OVS_REQUIRES(monitor_mutex);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
static void mport_update(struct mport *, struct bfd *, struct cfm *,
|
2015-08-28 14:55:11 -07:00
|
|
|
|
struct lldp *, const struct eth_addr *)
|
2015-02-20 14:17:10 -05:00
|
|
|
|
OVS_REQUIRES(monitor_mutex);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
static struct mport *mport_find(const struct ofport_dpif *)
|
2014-01-15 12:37:04 -08:00
|
|
|
|
OVS_REQUIRES(monitor_mutex);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
|
|
|
|
|
/* Tries finding and returning the 'mport' from the monitor_hmap.
|
|
|
|
|
* If there is no such 'mport', returns NULL. */
|
|
|
|
|
static struct mport *
|
2014-01-15 12:37:04 -08:00
|
|
|
|
mport_find(const struct ofport_dpif *ofport) OVS_REQUIRES(monitor_mutex)
|
2013-10-09 04:30:37 +00:00
|
|
|
|
{
|
|
|
|
|
struct mport *node;
|
|
|
|
|
|
|
|
|
|
HMAP_FOR_EACH_WITH_HASH (node, hmap_node, hash_pointer(ofport, 0),
|
|
|
|
|
&monitor_hmap) {
|
|
|
|
|
if (node->ofport == ofport) {
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 03:32:34 +00:00
|
|
|
|
/* Creates a new mport and inserts it into monitor_hmap and monitor_heap,
|
|
|
|
|
* if it doesn't exist. Otherwise, just updates its fields. */
|
2013-10-09 04:30:37 +00:00
|
|
|
|
static void
|
|
|
|
|
mport_register(const struct ofport_dpif *ofport, struct bfd *bfd,
|
2015-08-28 14:55:11 -07:00
|
|
|
|
struct cfm *cfm, struct lldp *lldp,
|
|
|
|
|
const struct eth_addr *hw_addr)
|
2014-01-15 12:37:04 -08:00
|
|
|
|
OVS_REQUIRES(monitor_mutex)
|
2013-10-09 04:30:37 +00:00
|
|
|
|
{
|
|
|
|
|
struct mport *mport = mport_find(ofport);
|
|
|
|
|
|
|
|
|
|
if (!mport) {
|
|
|
|
|
mport = xzalloc(sizeof *mport);
|
|
|
|
|
mport->ofport = ofport;
|
|
|
|
|
hmap_insert(&monitor_hmap, &mport->hmap_node, hash_pointer(ofport, 0));
|
2013-10-16 03:32:34 +00:00
|
|
|
|
heap_insert(&monitor_heap, &mport->heap_node, 0);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
2015-02-20 14:17:10 -05:00
|
|
|
|
mport_update(mport, bfd, cfm, lldp, hw_addr);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 03:32:34 +00:00
|
|
|
|
/* Removes mport from monitor_hmap and monitor_heap and frees it. */
|
2013-10-09 04:30:37 +00:00
|
|
|
|
static void
|
|
|
|
|
mport_unregister(const struct ofport_dpif *ofport)
|
2014-01-15 12:37:04 -08:00
|
|
|
|
OVS_REQUIRES(monitor_mutex)
|
2013-10-09 04:30:37 +00:00
|
|
|
|
{
|
|
|
|
|
struct mport *mport = mport_find(ofport);
|
|
|
|
|
|
|
|
|
|
if (mport) {
|
2015-02-20 14:17:10 -05:00
|
|
|
|
mport_update(mport, NULL, NULL, NULL, NULL);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
hmap_remove(&monitor_hmap, &mport->hmap_node);
|
2013-10-16 03:32:34 +00:00
|
|
|
|
heap_remove(&monitor_heap, &mport->heap_node);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
free(mport);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Updates the fields of an existing mport struct. */
|
|
|
|
|
static void
|
|
|
|
|
mport_update(struct mport *mport, struct bfd *bfd, struct cfm *cfm,
|
2015-08-28 14:55:11 -07:00
|
|
|
|
struct lldp *lldp, const struct eth_addr *hw_addr)
|
2015-02-20 14:17:10 -05:00
|
|
|
|
OVS_REQUIRES(monitor_mutex)
|
2013-10-09 04:30:37 +00:00
|
|
|
|
{
|
|
|
|
|
ovs_assert(mport);
|
|
|
|
|
|
|
|
|
|
if (mport->cfm != cfm) {
|
|
|
|
|
cfm_unref(mport->cfm);
|
|
|
|
|
mport->cfm = cfm_ref(cfm);
|
|
|
|
|
}
|
|
|
|
|
if (mport->bfd != bfd) {
|
|
|
|
|
bfd_unref(mport->bfd);
|
|
|
|
|
mport->bfd = bfd_ref(bfd);
|
|
|
|
|
}
|
2015-02-20 14:17:10 -05:00
|
|
|
|
if (mport->lldp != lldp) {
|
|
|
|
|
lldp_unref(mport->lldp);
|
|
|
|
|
mport->lldp = lldp_ref(lldp);
|
|
|
|
|
}
|
2015-08-28 14:55:11 -07:00
|
|
|
|
if (hw_addr && !eth_addr_equals(mport->hw_addr, *hw_addr)) {
|
|
|
|
|
mport->hw_addr = *hw_addr;
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
2015-02-20 14:17:10 -05:00
|
|
|
|
/* If bfd/cfm/lldp is added or reconfigured, move the mport on top of the heap
|
2013-12-13 17:24:10 -08:00
|
|
|
|
* so that the monitor thread can run the mport next time it wakes up. */
|
2015-02-20 14:17:10 -05:00
|
|
|
|
if (mport->bfd || mport->cfm || mport->lldp) {
|
2013-10-16 03:32:34 +00:00
|
|
|
|
heap_change(&monitor_heap, &mport->heap_node, LLONG_MAX);
|
2013-10-16 03:32:30 +00:00
|
|
|
|
}
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-10-16 03:32:30 +00:00
|
|
|
|
/* The 'main' function for the monitor thread. */
|
|
|
|
|
static void *
|
|
|
|
|
monitor_main(void * args OVS_UNUSED)
|
|
|
|
|
{
|
|
|
|
|
VLOG_INFO("monitor thread created");
|
|
|
|
|
while (!latch_is_set(&monitor_exit_latch)) {
|
|
|
|
|
monitor_run();
|
|
|
|
|
latch_wait(&monitor_exit_latch);
|
|
|
|
|
poll_block();
|
|
|
|
|
}
|
|
|
|
|
VLOG_INFO("monitor thread terminated");
|
|
|
|
|
return NULL;
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 17:24:10 -08:00
|
|
|
|
/* The monitor thread should wake up this often to ensure that newly added or
|
|
|
|
|
* reconfigured monitoring ports are run in a timely manner. */
|
|
|
|
|
#define MONITOR_INTERVAL_MSEC 100
|
|
|
|
|
|
2014-04-03 18:31:13 -07:00
|
|
|
|
/* Checks the 'send_soon' list and the heap for mports that have timed
|
|
|
|
|
* out bfd/cfm sessions. */
|
2013-10-16 03:32:30 +00:00
|
|
|
|
static void
|
|
|
|
|
monitor_run(void)
|
2013-10-09 04:30:37 +00:00
|
|
|
|
{
|
2013-10-10 17:52:31 -07:00
|
|
|
|
uint32_t stub[512 / 4];
|
2013-10-16 03:32:34 +00:00
|
|
|
|
long long int prio_now;
|
2015-02-22 03:21:09 -08:00
|
|
|
|
struct dp_packet packet;
|
2013-10-09 04:30:37 +00:00
|
|
|
|
|
2015-02-22 03:21:09 -08:00
|
|
|
|
dp_packet_use_stub(&packet, stub, sizeof stub);
|
2014-01-15 12:37:04 -08:00
|
|
|
|
ovs_mutex_lock(&monitor_mutex);
|
2014-04-03 18:31:13 -07:00
|
|
|
|
|
|
|
|
|
/* The monitor_check_send_soon() needs to be run twice. The first
|
|
|
|
|
* time is for preventing the same 'mport' from being processed twice
|
|
|
|
|
* (i.e. once from heap, the other from the 'send_soon' array).
|
|
|
|
|
* The second run is to cover the case when the control packet is sent
|
|
|
|
|
* via patch port and the other end needs to send back immediately. */
|
|
|
|
|
monitor_check_send_soon(&packet);
|
|
|
|
|
|
2013-10-16 03:32:34 +00:00
|
|
|
|
prio_now = MSEC_TO_PRIO(time_msec());
|
|
|
|
|
/* Peeks the top of heap and checks if we should run this mport. */
|
|
|
|
|
while (!heap_is_empty(&monitor_heap)
|
|
|
|
|
&& heap_max(&monitor_heap)->priority >= prio_now) {
|
|
|
|
|
struct mport *mport;
|
|
|
|
|
|
|
|
|
|
mport = CONTAINER_OF(heap_max(&monitor_heap), struct mport, heap_node);
|
2014-04-03 18:31:13 -07:00
|
|
|
|
monitor_mport_run(mport, &packet);
|
2013-10-16 03:32:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 18:31:13 -07:00
|
|
|
|
monitor_check_send_soon(&packet);
|
|
|
|
|
|
2013-10-16 03:32:34 +00:00
|
|
|
|
/* Waits on the earliest next wakeup time. */
|
|
|
|
|
if (!heap_is_empty(&monitor_heap)) {
|
2013-12-13 17:24:10 -08:00
|
|
|
|
long long int next_timeout, next_mport_wakeup;
|
|
|
|
|
|
|
|
|
|
next_timeout = time_msec() + MONITOR_INTERVAL_MSEC;
|
|
|
|
|
next_mport_wakeup = PRIO_TO_MSEC(heap_max(&monitor_heap)->priority);
|
|
|
|
|
poll_timer_wait_until(MIN(next_timeout, next_mport_wakeup));
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
2014-01-15 12:37:04 -08:00
|
|
|
|
ovs_mutex_unlock(&monitor_mutex);
|
2015-02-22 03:21:09 -08:00
|
|
|
|
dp_packet_uninit(&packet);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
2014-04-03 18:31:13 -07:00
|
|
|
|
|
|
|
|
|
/* Checks the 'send_soon' list for any mport that needs to send cfm/bfd
|
|
|
|
|
* control packet immediately, and calls monitor_mport_run(). */
|
|
|
|
|
static void
|
2015-02-22 03:21:09 -08:00
|
|
|
|
monitor_check_send_soon(struct dp_packet *packet)
|
2014-04-03 18:31:13 -07:00
|
|
|
|
OVS_REQUIRES(monitor_mutex)
|
|
|
|
|
{
|
|
|
|
|
while (!guarded_list_is_empty(&send_soon)) {
|
|
|
|
|
struct send_soon_entry *entry;
|
|
|
|
|
struct mport *mport;
|
|
|
|
|
|
|
|
|
|
entry = CONTAINER_OF(guarded_list_pop_front(&send_soon),
|
|
|
|
|
struct send_soon_entry, list_node);
|
|
|
|
|
mport = mport_find(entry->ofport);
|
|
|
|
|
if (mport) {
|
|
|
|
|
monitor_mport_run(mport, packet);
|
|
|
|
|
}
|
|
|
|
|
free(entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Checks the sending of control packet on 'mport'. Sends the control
|
|
|
|
|
* packet if needed. Executes bfd and cfm periodic functions (run, wait)
|
|
|
|
|
* on 'mport'. And changes the location of 'mport' in heap based on next
|
|
|
|
|
* timeout. */
|
|
|
|
|
static void
|
2015-02-22 03:21:09 -08:00
|
|
|
|
monitor_mport_run(struct mport *mport, struct dp_packet *packet)
|
2014-04-03 18:31:13 -07:00
|
|
|
|
OVS_REQUIRES(monitor_mutex)
|
|
|
|
|
{
|
|
|
|
|
long long int next_wake_time;
|
2015-02-20 14:17:10 -05:00
|
|
|
|
long long int bfd_wake_time = LLONG_MAX;
|
|
|
|
|
long long int cfm_wake_time = LLONG_MAX;
|
|
|
|
|
long long int lldp_wake_time = LLONG_MAX;
|
2014-04-03 18:31:13 -07:00
|
|
|
|
|
|
|
|
|
if (mport->cfm && cfm_should_send_ccm(mport->cfm)) {
|
|
|
|
|
cfm_compose_ccm(mport->cfm, packet, mport->hw_addr);
|
2016-06-28 18:14:53 -07:00
|
|
|
|
ofproto_dpif_send_packet(mport->ofport, false, packet);
|
2014-04-03 18:31:13 -07:00
|
|
|
|
}
|
|
|
|
|
if (mport->bfd && bfd_should_send_packet(mport->bfd)) {
|
2016-06-28 18:14:53 -07:00
|
|
|
|
bool oam;
|
|
|
|
|
|
|
|
|
|
bfd_put_packet(mport->bfd, packet, mport->hw_addr, &oam);
|
|
|
|
|
ofproto_dpif_send_packet(mport->ofport, oam, packet);
|
2014-04-03 18:31:13 -07:00
|
|
|
|
}
|
2015-02-20 14:17:10 -05:00
|
|
|
|
if (mport->lldp && lldp_should_send_packet(mport->lldp)) {
|
|
|
|
|
lldp_put_packet(mport->lldp, packet, mport->hw_addr);
|
2016-06-28 18:14:53 -07:00
|
|
|
|
ofproto_dpif_send_packet(mport->ofport, false, packet);
|
2015-02-20 14:17:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 18:31:13 -07:00
|
|
|
|
if (mport->cfm) {
|
|
|
|
|
cfm_run(mport->cfm);
|
2015-02-20 14:17:10 -05:00
|
|
|
|
cfm_wake_time = cfm_wait(mport->cfm);
|
2014-04-03 18:31:13 -07:00
|
|
|
|
}
|
|
|
|
|
if (mport->bfd) {
|
|
|
|
|
bfd_run(mport->bfd);
|
2015-02-20 14:17:10 -05:00
|
|
|
|
bfd_wake_time = bfd_wait(mport->bfd);
|
|
|
|
|
}
|
|
|
|
|
if (mport->lldp) {
|
|
|
|
|
lldp_wake_time = lldp_wait(mport->lldp);
|
2014-04-03 18:31:13 -07:00
|
|
|
|
}
|
|
|
|
|
/* Computes the next wakeup time for this mport. */
|
2015-02-20 14:17:10 -05:00
|
|
|
|
next_wake_time = MIN(bfd_wake_time,
|
|
|
|
|
cfm_wake_time);
|
|
|
|
|
next_wake_time = MIN(next_wake_time, lldp_wake_time);
|
2014-04-03 18:31:13 -07:00
|
|
|
|
heap_change(&monitor_heap, &mport->heap_node,
|
|
|
|
|
MSEC_TO_PRIO(next_wake_time));
|
|
|
|
|
}
|
2013-10-16 03:32:30 +00:00
|
|
|
|
|
2013-10-09 04:30:37 +00:00
|
|
|
|
|
2013-10-16 03:32:30 +00:00
|
|
|
|
/* Creates the mport in monitor module if either bfd or cfm
|
|
|
|
|
* is configured. Otherwise, deletes the mport.
|
|
|
|
|
* Also checks whether the monitor thread should be started
|
|
|
|
|
* or terminated. */
|
2013-10-09 04:30:37 +00:00
|
|
|
|
void
|
2013-10-16 03:32:30 +00:00
|
|
|
|
ofproto_dpif_monitor_port_update(const struct ofport_dpif *ofport,
|
|
|
|
|
struct bfd *bfd, struct cfm *cfm,
|
2015-02-20 14:17:10 -05:00
|
|
|
|
struct lldp *lldp,
|
2015-08-28 14:55:11 -07:00
|
|
|
|
const struct eth_addr *hw_addr)
|
2013-10-09 04:30:37 +00:00
|
|
|
|
{
|
2014-01-15 12:37:04 -08:00
|
|
|
|
ovs_mutex_lock(&monitor_mutex);
|
2015-02-20 14:17:10 -05:00
|
|
|
|
if (!cfm && !bfd && !lldp) {
|
2013-10-16 03:32:30 +00:00
|
|
|
|
mport_unregister(ofport);
|
|
|
|
|
} else {
|
2015-02-20 14:17:10 -05:00
|
|
|
|
mport_register(ofport, bfd, cfm, lldp, hw_addr);
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
2014-01-15 12:37:04 -08:00
|
|
|
|
ovs_mutex_unlock(&monitor_mutex);
|
2013-10-16 03:32:30 +00:00
|
|
|
|
|
|
|
|
|
/* If the monitor thread is not running and the hmap
|
|
|
|
|
* is not empty, starts it. If it is and the hmap is empty,
|
|
|
|
|
* terminates it. */
|
|
|
|
|
if (!monitor_running && !hmap_is_empty(&monitor_hmap)) {
|
|
|
|
|
latch_init(&monitor_exit_latch);
|
ovs-thread: Make caller provide thread name when creating a thread.
Thread names are occasionally very useful for debugging, but from time to
time we've forgotten to set one. This commit adds the new thread's name
as a parameter to the function to start a thread, to make that mistake
impossible. This also simplifies code, since two function calls become
only one.
This makes a few other changes to the thread creation function:
* Since it is no longer a direct wrapper around a pthread function,
rename it to avoid giving that impression.
* Remove 'pthread_attr_t *' param that every caller supplied as NULL.
* Change 'pthread *' parameter into a return value, for convenience.
The system-stats code hadn't set a thread name, so this fixes that issue.
This patch is a prerequisite for making RCU report the name of a thread
that is blocking RCU synchronization, because the easiest way to do that is
for ovsrcu_quiesce_end() to record the current thread's name.
ovsrcu_quiesce_end() is called before the thread function is called, so it
won't get a name set within the thread function itself. Setting the thread
name earlier, as in this patch, avoids the problem.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
2014-04-25 17:46:21 -07:00
|
|
|
|
monitor_tid = ovs_thread_create("monitor", monitor_main, NULL);
|
2013-10-16 03:32:30 +00:00
|
|
|
|
monitor_running = true;
|
|
|
|
|
} else if (monitor_running && hmap_is_empty(&monitor_hmap)) {
|
|
|
|
|
latch_set(&monitor_exit_latch);
|
|
|
|
|
xpthread_join(monitor_tid, NULL);
|
|
|
|
|
latch_destroy(&monitor_exit_latch);
|
|
|
|
|
monitor_running = false;
|
|
|
|
|
}
|
2013-10-09 04:30:37 +00:00
|
|
|
|
}
|
2013-12-20 14:53:52 -08:00
|
|
|
|
|
2014-04-03 18:31:13 -07:00
|
|
|
|
/* Registers the 'ofport' in the 'send_soon' list. We cannot directly
|
|
|
|
|
* insert the corresponding mport to the 'send_soon' list, since the
|
|
|
|
|
* 'send_soon' list is not updated when the mport is removed.
|
|
|
|
|
*
|
|
|
|
|
* Reader of the 'send_soon' list is responsible for freeing the entry. */
|
2013-12-20 14:53:52 -08:00
|
|
|
|
void
|
|
|
|
|
ofproto_dpif_monitor_port_send_soon(const struct ofport_dpif *ofport)
|
|
|
|
|
{
|
2014-04-03 18:31:13 -07:00
|
|
|
|
struct send_soon_entry *entry = xzalloc(sizeof *entry);
|
|
|
|
|
entry->ofport = ofport;
|
2013-12-20 14:53:52 -08:00
|
|
|
|
|
2014-04-03 18:31:13 -07:00
|
|
|
|
guarded_list_push_back(&send_soon, &entry->list_node, SIZE_MAX);
|
2013-12-20 14:53:52 -08:00
|
|
|
|
}
|