2010-11-29 12:21:08 -08:00
|
|
|
|
/*
|
2012-12-16 16:42:17 -08:00
|
|
|
|
* Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
|
2010-11-29 12:21:08 -08: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 "dummy.h"
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
2011-12-06 14:22:27 -08:00
|
|
|
|
#include "flow.h"
|
2010-11-29 12:21:08 -08:00
|
|
|
|
#include "list.h"
|
|
|
|
|
#include "netdev-provider.h"
|
2013-01-25 13:30:40 -08:00
|
|
|
|
#include "netdev-vport.h"
|
2011-12-06 14:22:27 -08:00
|
|
|
|
#include "odp-util.h"
|
|
|
|
|
#include "ofp-print.h"
|
|
|
|
|
#include "ofpbuf.h"
|
2010-11-29 12:21:08 -08:00
|
|
|
|
#include "packets.h"
|
2011-12-06 14:22:27 -08:00
|
|
|
|
#include "poll-loop.h"
|
2010-11-29 12:21:08 -08:00
|
|
|
|
#include "shash.h"
|
2012-01-19 10:24:46 -08:00
|
|
|
|
#include "sset.h"
|
2012-10-25 16:54:23 -07:00
|
|
|
|
#include "stream.h"
|
|
|
|
|
#include "unaligned.h"
|
2011-12-06 14:22:27 -08:00
|
|
|
|
#include "unixctl.h"
|
2010-11-29 12:21:08 -08:00
|
|
|
|
#include "vlog.h"
|
|
|
|
|
|
|
|
|
|
VLOG_DEFINE_THIS_MODULE(netdev_dummy);
|
|
|
|
|
|
2012-10-25 16:54:23 -07:00
|
|
|
|
struct dummy_stream {
|
|
|
|
|
struct stream *stream;
|
|
|
|
|
struct ofpbuf rxbuf;
|
|
|
|
|
struct list txq;
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-12 12:49:23 -07:00
|
|
|
|
/* Protects 'dummy_list'. */
|
|
|
|
|
static struct ovs_mutex dummy_list_mutex = OVS_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
|
|
/* Contains all 'struct dummy_dev's. */
|
|
|
|
|
static struct list dummy_list OVS_GUARDED_BY(dummy_list_mutex)
|
|
|
|
|
= LIST_INITIALIZER(&dummy_list);
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy {
|
|
|
|
|
struct netdev up;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
|
2013-08-12 12:49:23 -07:00
|
|
|
|
/* In dummy_list. */
|
|
|
|
|
struct list list_node OVS_GUARDED_BY(dummy_list_mutex);
|
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
/* Protects all members below. */
|
2013-08-12 12:49:23 -07:00
|
|
|
|
struct ovs_mutex mutex OVS_ACQ_AFTER(dummy_list_mutex);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
|
2013-08-16 14:04:08 -07:00
|
|
|
|
uint8_t hwaddr[ETH_ADDR_LEN] OVS_GUARDED;
|
|
|
|
|
int mtu OVS_GUARDED;
|
|
|
|
|
struct netdev_stats stats OVS_GUARDED;
|
|
|
|
|
enum netdev_flags flags OVS_GUARDED;
|
|
|
|
|
unsigned int change_seq OVS_GUARDED;
|
|
|
|
|
int ifindex OVS_GUARDED;
|
|
|
|
|
|
|
|
|
|
struct pstream *pstream OVS_GUARDED;
|
|
|
|
|
struct dummy_stream *streams OVS_GUARDED;
|
|
|
|
|
size_t n_streams OVS_GUARDED;
|
|
|
|
|
|
|
|
|
|
struct list rxes OVS_GUARDED; /* List of child "netdev_rx_dummy"s. */
|
2010-11-29 12:21:08 -08:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-16 16:37:32 -07:00
|
|
|
|
/* Max 'recv_queue_len' in struct netdev_dummy. */
|
|
|
|
|
#define NETDEV_DUMMY_MAX_QUEUE 100
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_dummy {
|
|
|
|
|
struct netdev_rx up;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct list node; /* In netdev_dummy's "rxes" list. */
|
2011-12-06 14:22:27 -08:00
|
|
|
|
struct list recv_queue;
|
2012-08-16 16:37:32 -07:00
|
|
|
|
int recv_queue_len; /* list_size(&recv_queue). */
|
|
|
|
|
bool listening;
|
2010-11-29 12:21:08 -08:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-09 18:08:40 -07:00
|
|
|
|
static unixctl_cb_func netdev_dummy_set_admin_state;
|
2013-08-09 21:21:38 -07:00
|
|
|
|
static int netdev_dummy_construct(struct netdev *);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
static void netdev_dummy_poll_notify(struct netdev_dummy *netdev)
|
|
|
|
|
OVS_REQUIRES(netdev->mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
static void netdev_dummy_queue_packet(struct netdev_dummy *, struct ofpbuf *);
|
|
|
|
|
|
|
|
|
|
static void dummy_stream_close(struct dummy_stream *);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_dummy_class(const struct netdev_class *class)
|
|
|
|
|
{
|
2013-08-09 21:21:38 -07:00
|
|
|
|
return class->construct == netdev_dummy_construct;
|
2010-11-29 12:21:08 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct netdev_dummy *
|
|
|
|
|
netdev_dummy_cast(const struct netdev *netdev)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
ovs_assert(is_dummy_class(netdev_get_class(netdev)));
|
2013-03-08 15:09:42 -08:00
|
|
|
|
return CONTAINER_OF(netdev, struct netdev_dummy, up);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
static struct netdev_rx_dummy *
|
|
|
|
|
netdev_rx_dummy_cast(const struct netdev_rx *rx)
|
|
|
|
|
{
|
2013-08-09 21:21:38 -07:00
|
|
|
|
ovs_assert(is_dummy_class(netdev_get_class(rx->netdev)));
|
2013-05-10 14:39:19 -07:00
|
|
|
|
return CONTAINER_OF(rx, struct netdev_rx_dummy, up);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-25 16:54:23 -07:00
|
|
|
|
static void
|
|
|
|
|
netdev_dummy_run(void)
|
|
|
|
|
{
|
2013-08-12 12:49:23 -07:00
|
|
|
|
struct netdev_dummy *dev;
|
2012-10-25 16:54:23 -07:00
|
|
|
|
|
2013-08-12 12:49:23 -07:00
|
|
|
|
ovs_mutex_lock(&dummy_list_mutex);
|
|
|
|
|
LIST_FOR_EACH (dev, list_node, &dummy_list) {
|
2012-10-25 16:54:23 -07:00
|
|
|
|
size_t i;
|
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
|
|
|
|
|
2012-10-25 16:54:23 -07:00
|
|
|
|
if (dev->pstream) {
|
|
|
|
|
struct stream *new_stream;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
error = pstream_accept(dev->pstream, &new_stream);
|
|
|
|
|
if (!error) {
|
|
|
|
|
struct dummy_stream *s;
|
|
|
|
|
|
|
|
|
|
dev->streams = xrealloc(dev->streams,
|
|
|
|
|
((dev->n_streams + 1)
|
|
|
|
|
* sizeof *dev->streams));
|
|
|
|
|
s = &dev->streams[dev->n_streams++];
|
|
|
|
|
s->stream = new_stream;
|
|
|
|
|
ofpbuf_init(&s->rxbuf, 2048);
|
|
|
|
|
list_init(&s->txq);
|
|
|
|
|
} else if (error != EAGAIN) {
|
|
|
|
|
VLOG_WARN("%s: accept failed (%s)",
|
2013-06-24 10:54:49 -07:00
|
|
|
|
pstream_get_name(dev->pstream), ovs_strerror(error));
|
2012-10-25 16:54:23 -07:00
|
|
|
|
pstream_close(dev->pstream);
|
|
|
|
|
dev->pstream = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < dev->n_streams; i++) {
|
|
|
|
|
struct dummy_stream *s = &dev->streams[i];
|
|
|
|
|
int error = 0;
|
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
|
|
stream_run(s->stream);
|
|
|
|
|
|
|
|
|
|
if (!list_is_empty(&s->txq)) {
|
|
|
|
|
struct ofpbuf *txbuf;
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
|
|
txbuf = ofpbuf_from_list(list_front(&s->txq));
|
|
|
|
|
retval = stream_send(s->stream, txbuf->data, txbuf->size);
|
|
|
|
|
if (retval > 0) {
|
|
|
|
|
ofpbuf_pull(txbuf, retval);
|
|
|
|
|
if (!txbuf->size) {
|
|
|
|
|
list_remove(&txbuf->list_node);
|
|
|
|
|
ofpbuf_delete(txbuf);
|
|
|
|
|
}
|
|
|
|
|
} else if (retval != -EAGAIN) {
|
|
|
|
|
error = -retval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!error) {
|
|
|
|
|
if (s->rxbuf.size < 2) {
|
|
|
|
|
n = 2 - s->rxbuf.size;
|
|
|
|
|
} else {
|
|
|
|
|
uint16_t frame_len;
|
|
|
|
|
|
|
|
|
|
frame_len = ntohs(get_unaligned_be16(s->rxbuf.data));
|
|
|
|
|
if (frame_len < ETH_HEADER_LEN) {
|
|
|
|
|
error = EPROTO;
|
|
|
|
|
n = 0;
|
|
|
|
|
} else {
|
|
|
|
|
n = (2 + frame_len) - s->rxbuf.size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!error) {
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
|
|
ofpbuf_prealloc_tailroom(&s->rxbuf, n);
|
|
|
|
|
retval = stream_recv(s->stream, ofpbuf_tail(&s->rxbuf), n);
|
|
|
|
|
if (retval > 0) {
|
|
|
|
|
s->rxbuf.size += retval;
|
|
|
|
|
if (retval == n && s->rxbuf.size > 2) {
|
|
|
|
|
ofpbuf_pull(&s->rxbuf, 2);
|
|
|
|
|
netdev_dummy_queue_packet(dev,
|
|
|
|
|
ofpbuf_clone(&s->rxbuf));
|
|
|
|
|
ofpbuf_clear(&s->rxbuf);
|
|
|
|
|
}
|
|
|
|
|
} else if (retval != -EAGAIN) {
|
|
|
|
|
error = (retval < 0 ? -retval
|
|
|
|
|
: s->rxbuf.size ? EPROTO
|
|
|
|
|
: EOF);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
VLOG_DBG("%s: closing connection (%s)",
|
|
|
|
|
stream_get_name(s->stream),
|
|
|
|
|
ovs_retval_to_string(error));
|
|
|
|
|
dummy_stream_close(&dev->streams[i]);
|
|
|
|
|
dev->streams[i] = dev->streams[--dev->n_streams];
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-25 16:11:52 -07:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
}
|
2013-08-12 12:49:23 -07:00
|
|
|
|
ovs_mutex_unlock(&dummy_list_mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dummy_stream_close(struct dummy_stream *s)
|
|
|
|
|
{
|
|
|
|
|
stream_close(s->stream);
|
|
|
|
|
ofpbuf_uninit(&s->rxbuf);
|
|
|
|
|
ofpbuf_list_delete(&s->txq);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
netdev_dummy_wait(void)
|
|
|
|
|
{
|
2013-08-12 12:49:23 -07:00
|
|
|
|
struct netdev_dummy *dev;
|
2012-10-25 16:54:23 -07:00
|
|
|
|
|
2013-08-12 12:49:23 -07:00
|
|
|
|
ovs_mutex_lock(&dummy_list_mutex);
|
|
|
|
|
LIST_FOR_EACH (dev, list_node, &dummy_list) {
|
2012-10-25 16:54:23 -07:00
|
|
|
|
size_t i;
|
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
if (dev->pstream) {
|
|
|
|
|
pstream_wait(dev->pstream);
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < dev->n_streams; i++) {
|
|
|
|
|
struct dummy_stream *s = &dev->streams[i];
|
|
|
|
|
|
|
|
|
|
stream_run_wait(s->stream);
|
|
|
|
|
if (!list_is_empty(&s->txq)) {
|
|
|
|
|
stream_send_wait(s->stream);
|
|
|
|
|
}
|
|
|
|
|
stream_recv_wait(s->stream);
|
|
|
|
|
}
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
}
|
2013-08-12 12:49:23 -07:00
|
|
|
|
ovs_mutex_unlock(&dummy_list_mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 21:21:38 -07:00
|
|
|
|
static struct netdev *
|
|
|
|
|
netdev_dummy_alloc(void)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_dummy *netdev = xzalloc(sizeof *netdev);
|
|
|
|
|
return &netdev->up;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
static int
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_construct(struct netdev *netdev_)
|
2010-11-29 12:21:08 -08:00
|
|
|
|
{
|
2013-07-30 15:31:48 -07:00
|
|
|
|
static atomic_uint next_n = ATOMIC_VAR_INIT(0xaa550000);
|
2013-08-09 21:21:38 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
2013-04-26 12:58:14 -07:00
|
|
|
|
unsigned int n;
|
|
|
|
|
|
2013-07-30 15:31:48 -07:00
|
|
|
|
atomic_add(&next_n, 1, &n);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
|
Use "error-checking" mutexes in place of other kinds wherever possible.
We've seen a number of deadlocks in the tree since thread safety was
introduced. So far, all of these are self-deadlocks, that is, a single
thread acquiring a lock and then attempting to re-acquire the same lock
recursively. When this has happened, the process simply hung, and it was
somewhat difficult to find the cause.
POSIX "error-checking" mutexes check for this specific problem (and
others). This commit switches from other types of mutexes to
error-checking mutexes everywhere that we can, that is, everywhere that
we're not using recursive mutexes. This ought to help find problems more
quickly in the future.
There might be performance advantages to other kinds of mutexes in some
cases. However, the existing mutex type choices were just guesses, so I'd
rather go for easy detection of errors until we know that other mutex
types actually perform better in specific cases. Also, I did a quick
microbenchmark of glibc mutex types on my host and found that the
error checking mutexes weren't any slower than the other types, at least
when the mutex is uncontended.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-08-20 13:40:02 -07:00
|
|
|
|
ovs_mutex_init(&netdev->mutex);
|
2013-08-16 14:04:08 -07:00
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->hwaddr[0] = 0xaa;
|
|
|
|
|
netdev->hwaddr[1] = 0x55;
|
|
|
|
|
netdev->hwaddr[2] = n >> 24;
|
|
|
|
|
netdev->hwaddr[3] = n >> 16;
|
|
|
|
|
netdev->hwaddr[4] = n >> 8;
|
|
|
|
|
netdev->hwaddr[5] = n;
|
|
|
|
|
netdev->mtu = 1500;
|
|
|
|
|
netdev->flags = 0;
|
|
|
|
|
netdev->change_seq = 1;
|
|
|
|
|
netdev->ifindex = -EOPNOTSUPP;
|
2012-10-25 16:54:23 -07:00
|
|
|
|
|
|
|
|
|
netdev->pstream = NULL;
|
|
|
|
|
netdev->streams = NULL;
|
|
|
|
|
netdev->n_streams = 0;
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
list_init(&netdev->rxes);
|
2013-08-16 14:04:08 -07:00
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
|
2013-08-12 12:49:23 -07:00
|
|
|
|
ovs_mutex_lock(&dummy_list_mutex);
|
|
|
|
|
list_push_back(&dummy_list, &netdev->list_node);
|
|
|
|
|
ovs_mutex_unlock(&dummy_list_mutex);
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_destruct(struct netdev *netdev_)
|
2010-11-29 12:21:08 -08:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
size_t i;
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-12 12:49:23 -07:00
|
|
|
|
ovs_mutex_lock(&dummy_list_mutex);
|
|
|
|
|
list_remove(&netdev->list_node);
|
|
|
|
|
ovs_mutex_unlock(&dummy_list_mutex);
|
|
|
|
|
|
2013-08-16 14:04:08 -07:00
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
pstream_close(netdev->pstream);
|
|
|
|
|
for (i = 0; i < netdev->n_streams; i++) {
|
|
|
|
|
dummy_stream_close(&netdev->streams[i]);
|
|
|
|
|
}
|
|
|
|
|
free(netdev->streams);
|
2013-08-16 14:04:08 -07:00
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_destroy(&netdev->mutex);
|
2013-08-09 21:21:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
netdev_dummy_dealloc(struct netdev *netdev_)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
free(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 23:02:21 -07:00
|
|
|
|
static int
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_get_config(const struct netdev *netdev_, struct smap *args)
|
2013-03-27 23:02:21 -07:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
2013-03-27 23:02:21 -07:00
|
|
|
|
|
2013-08-12 12:51:47 -07:00
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (netdev->ifindex >= 0) {
|
|
|
|
|
smap_add_format(args, "ifindex", "%d", netdev->ifindex);
|
2013-03-27 23:02:21 -07:00
|
|
|
|
}
|
2012-10-25 16:54:23 -07:00
|
|
|
|
if (netdev->pstream) {
|
|
|
|
|
smap_add(args, "pstream", pstream_get_name(netdev->pstream));
|
|
|
|
|
}
|
2013-08-12 12:51:47 -07:00
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
|
|
|
|
|
2013-03-27 23:02:21 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_set_config(struct netdev *netdev_, const struct smap *args)
|
2010-11-29 12:21:08 -08:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
const char *pstream;
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->ifindex = smap_get_int(args, "ifindex", -EOPNOTSUPP);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
|
|
|
|
|
pstream = smap_get(args, "pstream");
|
|
|
|
|
if (!pstream
|
|
|
|
|
|| !netdev->pstream
|
|
|
|
|
|| strcmp(pstream_get_name(netdev->pstream), pstream)) {
|
|
|
|
|
pstream_close(netdev->pstream);
|
|
|
|
|
netdev->pstream = NULL;
|
|
|
|
|
|
|
|
|
|
if (pstream) {
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
error = pstream_open(pstream, &netdev->pstream, DSCP_DEFAULT);
|
|
|
|
|
if (error) {
|
2013-06-24 10:54:49 -07:00
|
|
|
|
VLOG_WARN("%s: open failed (%s)",
|
|
|
|
|
pstream, ovs_strerror(error));
|
2012-10-25 16:54:23 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 21:21:38 -07:00
|
|
|
|
static struct netdev_rx *
|
|
|
|
|
netdev_dummy_rx_alloc(void)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_rx_dummy *rx = xzalloc(sizeof *rx);
|
|
|
|
|
return &rx->up;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 14:15:32 -07:00
|
|
|
|
static int
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_rx_construct(struct netdev_rx *rx_)
|
2011-08-05 14:15:32 -07:00
|
|
|
|
{
|
2013-08-09 21:21:38 -07:00
|
|
|
|
struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
|
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
list_push_back(&netdev->rxes, &rx->node);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
list_init(&rx->recv_queue);
|
2012-08-16 16:37:32 -07:00
|
|
|
|
rx->recv_queue_len = 0;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
|
2011-08-05 14:15:32 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 21:21:38 -07:00
|
|
|
|
static void
|
|
|
|
|
netdev_dummy_rx_destruct(struct netdev_rx *rx_)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
|
2013-08-09 21:21:38 -07:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
2013-08-09 21:21:38 -07:00
|
|
|
|
list_remove(&rx->node);
|
|
|
|
|
ofpbuf_list_delete(&rx->recv_queue);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
2013-08-09 21:21:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
netdev_dummy_rx_dealloc(struct netdev_rx *rx_)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
|
|
|
|
|
|
|
|
|
|
free(rx);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 14:15:32 -07:00
|
|
|
|
static int
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_rx_recv(struct netdev_rx *rx_, void *buffer, size_t size)
|
2011-12-06 14:22:27 -08:00
|
|
|
|
{
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
struct ofpbuf *packet;
|
2013-07-30 12:26:08 -07:00
|
|
|
|
int retval;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
|
|
|
|
if (!list_is_empty(&rx->recv_queue)) {
|
|
|
|
|
packet = ofpbuf_from_list(list_pop_front(&rx->recv_queue));
|
|
|
|
|
rx->recv_queue_len--;
|
|
|
|
|
} else {
|
|
|
|
|
packet = NULL;
|
|
|
|
|
}
|
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
|
|
|
|
|
|
|
|
|
if (!packet) {
|
2011-12-06 14:22:27 -08:00
|
|
|
|
return -EAGAIN;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 12:26:08 -07:00
|
|
|
|
if (packet->size <= size) {
|
|
|
|
|
memcpy(buffer, packet->data, packet->size);
|
|
|
|
|
retval = packet->size;
|
|
|
|
|
} else {
|
|
|
|
|
retval = -EMSGSIZE;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
|
|
|
|
ofpbuf_delete(packet);
|
|
|
|
|
|
2013-07-30 12:26:08 -07:00
|
|
|
|
return retval;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_rx_wait(struct netdev_rx *rx_)
|
2013-05-10 14:39:19 -07:00
|
|
|
|
{
|
|
|
|
|
struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
|
|
|
|
|
|
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
if (!list_is_empty(&rx->recv_queue)) {
|
2011-12-06 14:22:27 -08:00
|
|
|
|
poll_immediate_wake();
|
|
|
|
|
}
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_rx_drain(struct netdev_rx *rx_)
|
2011-12-06 14:22:27 -08:00
|
|
|
|
{
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
|
|
|
|
|
|
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
ofpbuf_list_delete(&rx->recv_queue);
|
2012-08-16 16:37:32 -07:00
|
|
|
|
rx->recv_queue_len = 0;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
|
|
|
|
|
2011-12-06 14:22:27 -08:00
|
|
|
|
return 0;
|
2011-08-05 14:15:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-18 11:06:08 -07:00
|
|
|
|
static int
|
2012-10-25 16:54:23 -07:00
|
|
|
|
netdev_dummy_send(struct netdev *netdev, const void *buffer, size_t size)
|
2012-09-18 11:06:08 -07:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
if (size < ETH_HEADER_LEN) {
|
|
|
|
|
return EMSGSIZE;
|
|
|
|
|
} else {
|
|
|
|
|
const struct eth_header *eth = buffer;
|
|
|
|
|
int max_size;
|
|
|
|
|
|
2013-08-16 14:04:08 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
max_size = dev->mtu + ETH_HEADER_LEN;
|
2013-08-16 14:04:08 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
|
|
|
|
|
2012-10-25 16:54:23 -07:00
|
|
|
|
if (eth->eth_type == htons(ETH_TYPE_VLAN)) {
|
|
|
|
|
max_size += VLAN_HEADER_LEN;
|
|
|
|
|
}
|
|
|
|
|
if (size > max_size) {
|
|
|
|
|
return EMSGSIZE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-18 11:06:08 -07:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2012-09-18 11:06:08 -07:00
|
|
|
|
dev->stats.tx_packets++;
|
|
|
|
|
dev->stats.tx_bytes += size;
|
|
|
|
|
|
2012-10-25 16:54:23 -07:00
|
|
|
|
for (i = 0; i < dev->n_streams; i++) {
|
|
|
|
|
struct dummy_stream *s = &dev->streams[i];
|
|
|
|
|
|
|
|
|
|
if (list_size(&s->txq) < NETDEV_DUMMY_MAX_QUEUE) {
|
|
|
|
|
struct ofpbuf *b;
|
|
|
|
|
|
|
|
|
|
b = ofpbuf_clone_data_with_headroom(buffer, size, 2);
|
|
|
|
|
put_unaligned_be16(ofpbuf_push_uninit(b, 2), htons(size));
|
|
|
|
|
list_push_back(&s->txq, &b->list_node);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
2012-10-25 16:54:23 -07:00
|
|
|
|
|
2012-09-18 11:06:08 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_set_etheraddr(struct netdev *netdev,
|
|
|
|
|
const uint8_t mac[ETH_ADDR_LEN])
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
if (!eth_addr_equals(dev->hwaddr, mac)) {
|
|
|
|
|
memcpy(dev->hwaddr, mac, ETH_ADDR_LEN);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_poll_notify(dev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
}
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_get_etheraddr(const struct netdev *netdev,
|
|
|
|
|
uint8_t mac[ETH_ADDR_LEN])
|
|
|
|
|
{
|
2013-08-09 21:34:02 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
memcpy(mac, dev->hwaddr, ETH_ADDR_LEN);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_get_mtu(const struct netdev *netdev, int *mtup)
|
|
|
|
|
{
|
2013-08-09 21:34:02 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
*mtup = dev->mtu;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-12 17:12:52 -07:00
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_set_mtu(const struct netdev *netdev, int mtu)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2011-09-12 17:12:52 -07:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2011-09-12 17:12:52 -07:00
|
|
|
|
dev->mtu = mtu;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
|
|
|
|
|
2011-09-12 17:12:52 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
|
|
|
|
|
{
|
2013-08-09 21:34:02 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
*stats = dev->stats;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
dev->stats = *stats;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 23:02:21 -07:00
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_get_ifindex(const struct netdev *netdev)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
int ifindex;
|
|
|
|
|
|
|
|
|
|
ovs_mutex_lock(&dev->mutex);
|
|
|
|
|
ifindex = dev->ifindex;
|
|
|
|
|
ovs_mutex_unlock(&dev->mutex);
|
2013-03-27 23:02:21 -07:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
return ifindex;
|
2013-03-27 23:02:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
static int
|
2013-08-09 21:34:02 -07:00
|
|
|
|
netdev_dummy_update_flags__(struct netdev_dummy *netdev,
|
|
|
|
|
enum netdev_flags off, enum netdev_flags on,
|
|
|
|
|
enum netdev_flags *old_flagsp)
|
|
|
|
|
OVS_REQUIRES(netdev->mutex)
|
2010-11-29 12:21:08 -08:00
|
|
|
|
{
|
|
|
|
|
if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
*old_flagsp = netdev->flags;
|
|
|
|
|
netdev->flags |= on;
|
|
|
|
|
netdev->flags &= ~off;
|
|
|
|
|
if (*old_flagsp != netdev->flags) {
|
|
|
|
|
netdev_dummy_poll_notify(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
}
|
2013-08-09 21:34:02 -07:00
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_update_flags(struct netdev *netdev_,
|
|
|
|
|
enum netdev_flags off, enum netdev_flags on,
|
|
|
|
|
enum netdev_flags *old_flagsp)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
|
|
|
|
error = netdev_dummy_update_flags__(netdev, off, on, old_flagsp);
|
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
|
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-26 14:28:11 -07:00
|
|
|
|
static unsigned int
|
2013-08-09 21:34:02 -07:00
|
|
|
|
netdev_dummy_change_seq(const struct netdev *netdev_)
|
2011-05-26 14:28:11 -07:00
|
|
|
|
{
|
2013-08-09 21:34:02 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
|
|
|
|
unsigned int change_seq;
|
|
|
|
|
|
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
|
|
|
|
change_seq = netdev->change_seq;
|
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
|
|
|
|
|
|
|
|
|
return change_seq;
|
2011-05-26 14:28:11 -07:00
|
|
|
|
}
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
/* Helper functions. */
|
|
|
|
|
|
|
|
|
|
static void
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_poll_notify(struct netdev_dummy *dev)
|
2010-11-29 12:21:08 -08:00
|
|
|
|
{
|
2011-05-26 14:28:11 -07:00
|
|
|
|
dev->change_seq++;
|
|
|
|
|
if (!dev->change_seq) {
|
|
|
|
|
dev->change_seq++;
|
|
|
|
|
}
|
2010-11-29 12:21:08 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct netdev_class dummy_class = {
|
|
|
|
|
"dummy",
|
|
|
|
|
NULL, /* init */
|
2012-10-25 16:54:23 -07:00
|
|
|
|
netdev_dummy_run,
|
|
|
|
|
netdev_dummy_wait,
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_alloc,
|
|
|
|
|
netdev_dummy_construct,
|
|
|
|
|
netdev_dummy_destruct,
|
|
|
|
|
netdev_dummy_dealloc,
|
2013-03-27 23:02:21 -07:00
|
|
|
|
netdev_dummy_get_config,
|
|
|
|
|
netdev_dummy_set_config,
|
2013-01-07 16:56:04 -08:00
|
|
|
|
NULL, /* get_tunnel_config */
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2012-09-18 11:06:08 -07:00
|
|
|
|
netdev_dummy_send, /* send */
|
2010-11-29 12:21:08 -08:00
|
|
|
|
NULL, /* send_wait */
|
|
|
|
|
|
|
|
|
|
netdev_dummy_set_etheraddr,
|
|
|
|
|
netdev_dummy_get_etheraddr,
|
|
|
|
|
netdev_dummy_get_mtu,
|
2011-09-12 17:12:52 -07:00
|
|
|
|
netdev_dummy_set_mtu,
|
2013-03-27 23:02:21 -07:00
|
|
|
|
netdev_dummy_get_ifindex,
|
2010-11-29 12:21:08 -08:00
|
|
|
|
NULL, /* get_carrier */
|
2011-10-14 12:49:57 -07:00
|
|
|
|
NULL, /* get_carrier_resets */
|
2011-01-07 16:22:34 -08:00
|
|
|
|
NULL, /* get_miimon */
|
2010-11-29 12:21:08 -08:00
|
|
|
|
netdev_dummy_get_stats,
|
|
|
|
|
netdev_dummy_set_stats,
|
|
|
|
|
|
|
|
|
|
NULL, /* get_features */
|
|
|
|
|
NULL, /* set_advertisements */
|
|
|
|
|
|
|
|
|
|
NULL, /* set_policing */
|
|
|
|
|
NULL, /* get_qos_types */
|
|
|
|
|
NULL, /* get_qos_capabilities */
|
|
|
|
|
NULL, /* get_qos */
|
|
|
|
|
NULL, /* set_qos */
|
|
|
|
|
NULL, /* get_queue */
|
|
|
|
|
NULL, /* set_queue */
|
|
|
|
|
NULL, /* delete_queue */
|
|
|
|
|
NULL, /* get_queue_stats */
|
2013-08-27 17:15:53 -07:00
|
|
|
|
NULL, /* queue_dump_start */
|
|
|
|
|
NULL, /* queue_dump_next */
|
|
|
|
|
NULL, /* queue_dump_done */
|
2010-11-29 12:21:08 -08:00
|
|
|
|
NULL, /* dump_queue_stats */
|
|
|
|
|
|
|
|
|
|
NULL, /* get_in4 */
|
|
|
|
|
NULL, /* set_in4 */
|
|
|
|
|
NULL, /* get_in6 */
|
|
|
|
|
NULL, /* add_router */
|
|
|
|
|
NULL, /* get_next_hop */
|
2012-12-16 16:42:17 -08:00
|
|
|
|
NULL, /* get_status */
|
2010-11-29 12:21:08 -08:00
|
|
|
|
NULL, /* arp_lookup */
|
|
|
|
|
|
|
|
|
|
netdev_dummy_update_flags,
|
|
|
|
|
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_change_seq,
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-08-09 21:21:38 -07:00
|
|
|
|
netdev_dummy_rx_alloc,
|
|
|
|
|
netdev_dummy_rx_construct,
|
|
|
|
|
netdev_dummy_rx_destruct,
|
|
|
|
|
netdev_dummy_rx_dealloc,
|
|
|
|
|
netdev_dummy_rx_recv,
|
|
|
|
|
netdev_dummy_rx_wait,
|
|
|
|
|
netdev_dummy_rx_drain,
|
2013-05-10 14:39:19 -07:00
|
|
|
|
};
|
|
|
|
|
|
2011-12-06 14:22:27 -08:00
|
|
|
|
static struct ofpbuf *
|
|
|
|
|
eth_from_packet_or_flow(const char *s)
|
|
|
|
|
{
|
|
|
|
|
enum odp_key_fitness fitness;
|
|
|
|
|
struct ofpbuf *packet;
|
|
|
|
|
struct ofpbuf odp_key;
|
|
|
|
|
struct flow flow;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if (!eth_from_hex(s, &packet)) {
|
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert string to datapath key.
|
|
|
|
|
*
|
|
|
|
|
* It would actually be nicer to parse an OpenFlow-like flow key here, but
|
|
|
|
|
* the code for that currently calls exit() on parse error. We have to
|
|
|
|
|
* settle for parsing a datapath key for now.
|
|
|
|
|
*/
|
|
|
|
|
ofpbuf_init(&odp_key, 0);
|
2013-06-19 07:15:10 +00:00
|
|
|
|
error = odp_flow_from_string(s, NULL, &odp_key, NULL);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
if (error) {
|
|
|
|
|
ofpbuf_uninit(&odp_key);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert odp_key to flow. */
|
|
|
|
|
fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
|
|
|
|
|
if (fitness == ODP_FIT_ERROR) {
|
|
|
|
|
ofpbuf_uninit(&odp_key);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
packet = ofpbuf_new(0);
|
|
|
|
|
flow_compose(packet, &flow);
|
|
|
|
|
|
|
|
|
|
ofpbuf_uninit(&odp_key);
|
|
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-28 11:23:29 -07:00
|
|
|
|
static void
|
2012-10-25 16:54:23 -07:00
|
|
|
|
netdev_dummy_queue_packet__(struct netdev_rx_dummy *rx, struct ofpbuf *packet)
|
2012-08-10 15:21:58 -07:00
|
|
|
|
{
|
2012-10-25 16:54:23 -07:00
|
|
|
|
list_push_back(&rx->recv_queue, &packet->list_node);
|
|
|
|
|
rx->recv_queue_len++;
|
|
|
|
|
}
|
2012-08-10 15:21:58 -07:00
|
|
|
|
|
2012-10-25 16:54:23 -07:00
|
|
|
|
static void
|
|
|
|
|
netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_rx_dummy *rx, *prev;
|
|
|
|
|
|
|
|
|
|
prev = NULL;
|
2012-08-10 15:21:58 -07:00
|
|
|
|
LIST_FOR_EACH (rx, node, &dummy->rxes) {
|
|
|
|
|
if (rx->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
|
2012-10-25 16:54:23 -07:00
|
|
|
|
if (prev) {
|
|
|
|
|
netdev_dummy_queue_packet__(prev, ofpbuf_clone(packet));
|
|
|
|
|
}
|
|
|
|
|
prev = rx;
|
2012-08-10 15:21:58 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-25 16:54:23 -07:00
|
|
|
|
if (prev) {
|
|
|
|
|
netdev_dummy_queue_packet__(prev, packet);
|
|
|
|
|
} else {
|
|
|
|
|
ofpbuf_delete(packet);
|
|
|
|
|
}
|
2012-08-10 15:21:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-06 14:22:27 -08:00
|
|
|
|
static void
|
|
|
|
|
netdev_dummy_receive(struct unixctl_conn *conn,
|
|
|
|
|
int argc, const char *argv[], void *aux OVS_UNUSED)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *dummy_dev;
|
2013-07-25 16:11:52 -07:00
|
|
|
|
struct netdev *netdev;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
int i;
|
|
|
|
|
|
2013-07-25 16:11:52 -07:00
|
|
|
|
netdev = netdev_from_name(argv[1]);
|
|
|
|
|
if (!netdev || !is_dummy_class(netdev->netdev_class)) {
|
2012-02-14 20:53:59 -08:00
|
|
|
|
unixctl_command_reply_error(conn, "no such dummy netdev");
|
2013-07-25 16:11:52 -07:00
|
|
|
|
goto exit;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
2013-07-25 16:11:52 -07:00
|
|
|
|
dummy_dev = netdev_dummy_cast(netdev);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
|
|
|
|
|
for (i = 2; i < argc; i++) {
|
|
|
|
|
struct ofpbuf *packet;
|
|
|
|
|
|
|
|
|
|
packet = eth_from_packet_or_flow(argv[i]);
|
|
|
|
|
if (!packet) {
|
2012-02-14 20:53:59 -08:00
|
|
|
|
unixctl_command_reply_error(conn, "bad packet syntax");
|
2013-07-25 16:11:52 -07:00
|
|
|
|
goto exit;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dummy_dev->mutex);
|
2012-09-18 11:06:08 -07:00
|
|
|
|
dummy_dev->stats.rx_packets++;
|
|
|
|
|
dummy_dev->stats.rx_bytes += packet->size;
|
2012-10-25 16:54:23 -07:00
|
|
|
|
netdev_dummy_queue_packet(dummy_dev, packet);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dummy_dev->mutex);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-28 11:23:29 -07:00
|
|
|
|
unixctl_command_reply(conn, NULL);
|
2013-07-25 16:11:52 -07:00
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
netdev_close(netdev);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 18:08:40 -07:00
|
|
|
|
static void
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_set_admin_state__(struct netdev_dummy *dev, bool admin_state)
|
2013-08-09 21:34:02 -07:00
|
|
|
|
OVS_REQUIRES(dev->mutex)
|
2012-08-09 18:08:40 -07:00
|
|
|
|
{
|
|
|
|
|
enum netdev_flags old_flags;
|
|
|
|
|
|
|
|
|
|
if (admin_state) {
|
2013-08-09 21:34:02 -07:00
|
|
|
|
netdev_dummy_update_flags__(dev, 0, NETDEV_UP, &old_flags);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
} else {
|
2013-08-09 21:34:02 -07:00
|
|
|
|
netdev_dummy_update_flags__(dev, NETDEV_UP, 0, &old_flags);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
netdev_dummy_set_admin_state(struct unixctl_conn *conn, int argc,
|
|
|
|
|
const char *argv[], void *aux OVS_UNUSED)
|
|
|
|
|
{
|
|
|
|
|
bool up;
|
|
|
|
|
|
|
|
|
|
if (!strcasecmp(argv[argc - 1], "up")) {
|
|
|
|
|
up = true;
|
|
|
|
|
} else if ( !strcasecmp(argv[argc - 1], "down")) {
|
|
|
|
|
up = false;
|
|
|
|
|
} else {
|
|
|
|
|
unixctl_command_reply_error(conn, "Invalid Admin State");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (argc > 2) {
|
2013-07-25 16:11:52 -07:00
|
|
|
|
struct netdev *netdev = netdev_from_name(argv[1]);
|
|
|
|
|
if (netdev && is_dummy_class(netdev->netdev_class)) {
|
|
|
|
|
struct netdev_dummy *dummy_dev = netdev_dummy_cast(netdev);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&dummy_dev->mutex);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_set_admin_state__(dummy_dev, up);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_unlock(&dummy_dev->mutex);
|
|
|
|
|
|
2013-07-25 16:11:52 -07:00
|
|
|
|
netdev_close(netdev);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
} else {
|
|
|
|
|
unixctl_command_reply_error(conn, "Unknown Dummy Interface");
|
2013-07-25 16:11:52 -07:00
|
|
|
|
netdev_close(netdev);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-08-12 12:49:23 -07:00
|
|
|
|
struct netdev_dummy *netdev;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
|
2013-08-12 12:49:23 -07:00
|
|
|
|
ovs_mutex_lock(&dummy_list_mutex);
|
|
|
|
|
LIST_FOR_EACH (netdev, list_node, &dummy_list) {
|
2013-08-09 21:34:02 -07:00
|
|
|
|
ovs_mutex_lock(&netdev->mutex);
|
|
|
|
|
netdev_dummy_set_admin_state__(netdev, up);
|
|
|
|
|
ovs_mutex_unlock(&netdev->mutex);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
}
|
2013-08-12 12:49:23 -07:00
|
|
|
|
ovs_mutex_unlock(&dummy_list_mutex);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
}
|
|
|
|
|
unixctl_command_reply(conn, "OK");
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
void
|
2012-01-19 10:24:46 -08:00
|
|
|
|
netdev_dummy_register(bool override)
|
2010-11-29 12:21:08 -08:00
|
|
|
|
{
|
2011-12-06 14:22:27 -08:00
|
|
|
|
unixctl_command_register("netdev-dummy/receive", "NAME PACKET|FLOW...",
|
|
|
|
|
2, INT_MAX, netdev_dummy_receive, NULL);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
unixctl_command_register("netdev-dummy/set-admin-state",
|
|
|
|
|
"[netdev] up|down", 1, 2,
|
|
|
|
|
netdev_dummy_set_admin_state, NULL);
|
2012-01-19 10:24:46 -08:00
|
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
|
struct sset types;
|
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
|
|
sset_init(&types);
|
|
|
|
|
netdev_enumerate_types(&types);
|
|
|
|
|
SSET_FOR_EACH (type, &types) {
|
2013-08-28 16:33:07 +09:00
|
|
|
|
if (!strcmp(type, "patch")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-01-19 10:24:46 -08:00
|
|
|
|
if (!netdev_unregister_provider(type)) {
|
|
|
|
|
struct netdev_class *class;
|
2013-08-09 21:34:02 -07:00
|
|
|
|
int error;
|
2012-01-19 10:24:46 -08:00
|
|
|
|
|
2013-08-09 21:34:02 -07:00
|
|
|
|
class = xmemdup(&dummy_class, sizeof dummy_class);
|
2012-01-19 10:24:46 -08:00
|
|
|
|
class->type = xstrdup(type);
|
2013-08-09 21:34:02 -07:00
|
|
|
|
error = netdev_register_provider(class);
|
|
|
|
|
if (error) {
|
|
|
|
|
VLOG_ERR("%s: failed to register netdev provider (%s)",
|
|
|
|
|
type, ovs_strerror(error));
|
|
|
|
|
free(CONST_CAST(char *, class->type));
|
|
|
|
|
free(class);
|
|
|
|
|
}
|
2012-01-19 10:24:46 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sset_destroy(&types);
|
|
|
|
|
}
|
|
|
|
|
netdev_register_provider(&dummy_class);
|
2013-01-25 13:30:40 -08:00
|
|
|
|
|
2013-05-18 08:27:20 -07:00
|
|
|
|
netdev_vport_tunnel_register();
|
2010-11-29 12:21:08 -08:00
|
|
|
|
}
|