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"
|
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);
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy {
|
|
|
|
|
struct netdev up;
|
2010-11-29 12:21:08 -08:00
|
|
|
|
uint8_t hwaddr[ETH_ADDR_LEN];
|
|
|
|
|
int mtu;
|
|
|
|
|
struct netdev_stats stats;
|
|
|
|
|
enum netdev_flags flags;
|
2011-05-26 14:28:11 -07:00
|
|
|
|
unsigned int change_seq;
|
2013-03-27 23:02:21 -07:00
|
|
|
|
int ifindex;
|
2013-05-10 14:39:19 -07:00
|
|
|
|
|
|
|
|
|
struct list rxes; /* 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
|
|
|
|
};
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
static struct shash dummy_netdevs = SHASH_INITIALIZER(&dummy_netdevs);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
static const struct netdev_rx_class netdev_rx_dummy_class;
|
|
|
|
|
|
2012-08-09 18:08:40 -07:00
|
|
|
|
static unixctl_cb_func netdev_dummy_set_admin_state;
|
2010-11-29 12:21:08 -08:00
|
|
|
|
static int netdev_dummy_create(const struct netdev_class *, const char *,
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev **);
|
|
|
|
|
static void netdev_dummy_poll_notify(struct netdev_dummy *);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_dummy_class(const struct netdev_class *class)
|
|
|
|
|
{
|
|
|
|
|
return class->create == netdev_dummy_create;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
netdev_rx_assert_class(rx, &netdev_rx_dummy_class);
|
|
|
|
|
return CONTAINER_OF(rx, struct netdev_rx_dummy, up);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_create(const struct netdev_class *class, const char *name,
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev **netdevp)
|
2010-11-29 12:21:08 -08:00
|
|
|
|
{
|
|
|
|
|
static unsigned int n = 0xaa550000;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *netdev;
|
|
|
|
|
|
|
|
|
|
netdev = xzalloc(sizeof *netdev);
|
|
|
|
|
netdev_init(&netdev->up, name, class);
|
|
|
|
|
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;
|
|
|
|
|
list_init(&netdev->rxes);
|
|
|
|
|
|
|
|
|
|
shash_add(&dummy_netdevs, name, netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
n++;
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
*netdevp = &netdev->up;
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_destroy(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_);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
shash_find_and_delete(&dummy_netdevs,
|
|
|
|
|
netdev_get_name(netdev_));
|
|
|
|
|
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-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
|
|
|
|
}
|
|
|
|
|
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_);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->ifindex = smap_get_int(args, "ifindex", -EOPNOTSUPP);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 14:15:32 -07:00
|
|
|
|
static int
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_dummy_rx_open(struct netdev *netdev_, struct netdev_rx **rxp)
|
2011-08-05 14:15:32 -07:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_dummy *rx;
|
|
|
|
|
|
|
|
|
|
rx = xmalloc(sizeof *rx);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_rx_init(&rx->up, &netdev->up, &netdev_rx_dummy_class);
|
|
|
|
|
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-05-10 14:39:19 -07:00
|
|
|
|
|
|
|
|
|
*rxp = &rx->up;
|
2011-08-05 14:15:32 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_dummy_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_);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
struct ofpbuf *packet;
|
2012-01-13 13:30:42 -08:00
|
|
|
|
size_t packet_size;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
if (list_is_empty(&rx->recv_queue)) {
|
2011-12-06 14:22:27 -08:00
|
|
|
|
return -EAGAIN;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
packet = ofpbuf_from_list(list_pop_front(&rx->recv_queue));
|
2012-08-16 16:37:32 -07:00
|
|
|
|
rx->recv_queue_len--;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
if (packet->size > size) {
|
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
}
|
2012-01-13 13:30:42 -08:00
|
|
|
|
packet_size = packet->size;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
|
|
|
|
|
memcpy(buffer, packet->data, packet->size);
|
|
|
|
|
ofpbuf_delete(packet);
|
|
|
|
|
|
2012-01-13 13:30:42 -08:00
|
|
|
|
return packet_size;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_dummy_destroy(struct netdev_rx *rx_)
|
2011-08-05 14:15:32 -07:00
|
|
|
|
{
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
|
|
|
|
|
list_remove(&rx->node);
|
|
|
|
|
ofpbuf_list_delete(&rx->recv_queue);
|
|
|
|
|
free(rx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
netdev_rx_dummy_wait(struct netdev_rx *rx_)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
|
|
|
|
|
if (!list_is_empty(&rx->recv_queue)) {
|
2011-12-06 14:22:27 -08:00
|
|
|
|
poll_immediate_wake();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_dummy_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_);
|
|
|
|
|
ofpbuf_list_delete(&rx->recv_queue);
|
2012-08-16 16:37:32 -07:00
|
|
|
|
rx->recv_queue_len = 0;
|
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
|
|
|
|
|
netdev_dummy_send(struct netdev *netdev, const void *buffer OVS_UNUSED,
|
|
|
|
|
size_t size)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2012-09-18 11:06:08 -07:00
|
|
|
|
|
|
|
|
|
dev->stats.tx_packets++;
|
|
|
|
|
dev->stats.tx_bytes += size;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_get_etheraddr(const struct netdev *netdev,
|
|
|
|
|
uint8_t mac[ETH_ADDR_LEN])
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
const struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
memcpy(mac, dev->hwaddr, ETH_ADDR_LEN);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
netdev_dummy_get_mtu(const struct netdev *netdev, int *mtup)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
const struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
*mtup = dev->mtu;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
dev->mtu = mtu;
|
|
|
|
|
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-03-15 15:54:36 -07:00
|
|
|
|
const struct netdev_dummy *dev = netdev_dummy_cast(netdev);
|
2010-11-29 12:21:08 -08:00
|
|
|
|
|
|
|
|
|
*stats = dev->stats;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
dev->stats = *stats;
|
|
|
|
|
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-03-27 23:02:21 -07:00
|
|
|
|
|
|
|
|
|
return dev->ifindex;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
|
static int
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_update_flags(struct netdev *netdev_,
|
2010-11-29 12:21:08 -08:00
|
|
|
|
enum netdev_flags off, enum netdev_flags on,
|
|
|
|
|
enum netdev_flags *old_flagsp)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-26 14:28:11 -07:00
|
|
|
|
static unsigned int
|
|
|
|
|
netdev_dummy_change_seq(const struct netdev *netdev)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
return netdev_dummy_cast(netdev)->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 */
|
|
|
|
|
NULL, /* run */
|
|
|
|
|
NULL, /* wait */
|
|
|
|
|
|
|
|
|
|
netdev_dummy_create,
|
|
|
|
|
netdev_dummy_destroy,
|
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
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_dummy_rx_open,
|
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 */
|
|
|
|
|
NULL, /* dump_queues */
|
|
|
|
|
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,
|
|
|
|
|
|
2011-05-26 14:28:11 -07:00
|
|
|
|
netdev_dummy_change_seq
|
2010-11-29 12:21:08 -08:00
|
|
|
|
};
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
static const struct netdev_rx_class netdev_rx_dummy_class = {
|
|
|
|
|
netdev_rx_dummy_destroy,
|
|
|
|
|
netdev_rx_dummy_recv,
|
|
|
|
|
netdev_rx_dummy_wait,
|
|
|
|
|
netdev_rx_dummy_drain,
|
|
|
|
|
};
|
|
|
|
|
|
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);
|
|
|
|
|
error = odp_flow_key_from_string(s, NULL, &odp_key);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
int n_listeners;
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
dummy_dev = shash_find_data(&dummy_netdevs, argv[1]);
|
2011-12-06 14:22:27 -08:00
|
|
|
|
if (!dummy_dev) {
|
2012-02-14 20:53:59 -08:00
|
|
|
|
unixctl_command_reply_error(conn, "no such dummy netdev");
|
2011-12-06 14:22:27 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n_listeners = 0;
|
|
|
|
|
for (i = 2; i < argc; i++) {
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_dummy *rx;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
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");
|
2011-12-06 14:22:27 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-18 11:06:08 -07:00
|
|
|
|
dummy_dev->stats.rx_packets++;
|
|
|
|
|
dummy_dev->stats.rx_bytes += packet->size;
|
|
|
|
|
|
2011-12-06 14:22:27 -08:00
|
|
|
|
n_listeners = 0;
|
2013-05-10 14:39:19 -07:00
|
|
|
|
LIST_FOR_EACH (rx, node, &dummy_dev->rxes) {
|
2012-08-16 16:37:32 -07:00
|
|
|
|
if (rx->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
|
|
|
|
|
struct ofpbuf *copy = ofpbuf_clone(packet);
|
|
|
|
|
list_push_back(&rx->recv_queue, ©->list_node);
|
|
|
|
|
rx->recv_queue_len++;
|
|
|
|
|
}
|
2013-05-10 14:39:19 -07:00
|
|
|
|
n_listeners++;
|
2011-12-06 14:22:27 -08:00
|
|
|
|
}
|
|
|
|
|
ofpbuf_delete(packet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!n_listeners) {
|
2012-02-14 20:53:59 -08:00
|
|
|
|
unixctl_command_reply(conn, "packets queued but nobody listened");
|
2011-12-06 14:22:27 -08:00
|
|
|
|
} else {
|
2012-02-14 20:53:59 -08:00
|
|
|
|
unixctl_command_reply(conn, "success");
|
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)
|
2012-08-09 18:08:40 -07:00
|
|
|
|
{
|
|
|
|
|
enum netdev_flags old_flags;
|
|
|
|
|
|
|
|
|
|
if (admin_state) {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_update_flags(&dev->up, 0, NETDEV_UP, &old_flags);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
} else {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_update_flags(&dev->up, 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-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_dummy *dummy_dev;
|
2012-08-09 18:08:40 -07:00
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
dummy_dev = shash_find_data(&dummy_netdevs, argv[1]);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
if (dummy_dev) {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_dummy_set_admin_state__(dummy_dev, up);
|
2012-08-09 18:08:40 -07:00
|
|
|
|
} else {
|
|
|
|
|
unixctl_command_reply_error(conn, "Unknown Dummy Interface");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
struct shash_node *node;
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
SHASH_FOR_EACH (node, &dummy_netdevs) {
|
|
|
|
|
netdev_dummy_set_admin_state__(node->data, up);
|
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) {
|
|
|
|
|
if (!netdev_unregister_provider(type)) {
|
|
|
|
|
struct netdev_class *class;
|
|
|
|
|
|
|
|
|
|
class = xmalloc(sizeof *class);
|
|
|
|
|
*class = dummy_class;
|
|
|
|
|
class->type = xstrdup(type);
|
|
|
|
|
netdev_register_provider(class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|