#include <errno.h>
+#include "dp-packet.h"
#include "dpif-netdev.h"
#include "dynamic-string.h"
#include "flow.h"
#include "timeval.h"
#include "unixctl.h"
#include "reconnect.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
VLOG_DEFINE_THIS_MODULE(netdev_dummy);
struct dummy_packet_stream {
struct stream *stream;
- struct ofpbuf rxbuf;
- struct list txq;
+ struct dp_packet rxbuf;
+ struct ovs_list txq;
};
enum dummy_packet_conn_type {
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);
+static struct ovs_list dummy_list OVS_GUARDED_BY(dummy_list_mutex)
+ = OVS_LIST_INITIALIZER(&dummy_list);
struct netdev_dummy {
struct netdev up;
/* In dummy_list. */
- struct list list_node OVS_GUARDED_BY(dummy_list_mutex);
+ struct ovs_list list_node OVS_GUARDED_BY(dummy_list_mutex);
/* Protects all members below. */
struct ovs_mutex mutex OVS_ACQ_AFTER(dummy_list_mutex);
FILE *tx_pcap, *rxq_pcap OVS_GUARDED;
- struct list rxes OVS_GUARDED; /* List of child "netdev_rxq_dummy"s. */
+ struct in_addr address, netmask;
+ struct ovs_list rxes OVS_GUARDED; /* List of child "netdev_rxq_dummy"s. */
};
/* Max 'recv_queue_len' in struct netdev_dummy. */
struct netdev_rxq_dummy {
struct netdev_rxq up;
- struct list node; /* In netdev_dummy's "rxes" list. */
- struct list recv_queue;
+ struct ovs_list node; /* In netdev_dummy's "rxes" list. */
+ struct ovs_list recv_queue;
int recv_queue_len; /* list_size(&recv_queue). */
struct seq *seq; /* Reports newly queued packets. */
};
static unixctl_cb_func netdev_dummy_set_admin_state;
static int netdev_dummy_construct(struct netdev *);
-static void netdev_dummy_queue_packet(struct netdev_dummy *, struct ofpbuf *);
+static void netdev_dummy_queue_packet(struct netdev_dummy *, struct dp_packet *);
static void dummy_packet_stream_close(struct dummy_packet_stream *);
{
int rxbuf_size = stream ? 2048 : 0;
s->stream = stream;
- ofpbuf_init(&s->rxbuf, rxbuf_size);
+ dp_packet_init(&s->rxbuf, rxbuf_size);
list_init(&s->txq);
}
dummy_packet_stream_send(struct dummy_packet_stream *s, const void *buffer, size_t size)
{
if (list_size(&s->txq) < NETDEV_DUMMY_MAX_QUEUE) {
- struct ofpbuf *b;
+ struct dp_packet *b;
- b = ofpbuf_clone_data_with_headroom(buffer, size, 2);
- put_unaligned_be16(ofpbuf_push_uninit(b, 2), htons(size));
+ b = dp_packet_clone_data_with_headroom(buffer, size, 2);
+ put_unaligned_be16(dp_packet_push_uninit(b, 2), htons(size));
list_push_back(&s->txq, &b->list_node);
}
}
stream_run(s->stream);
if (!list_is_empty(&s->txq)) {
- struct ofpbuf *txbuf;
+ struct dp_packet *txbuf;
int retval;
- txbuf = ofpbuf_from_list(list_front(&s->txq));
- retval = stream_send(s->stream, ofpbuf_data(txbuf), ofpbuf_size(txbuf));
+ txbuf = dp_packet_from_list(list_front(&s->txq));
+ retval = stream_send(s->stream, dp_packet_data(txbuf), dp_packet_size(txbuf));
if (retval > 0) {
- ofpbuf_pull(txbuf, retval);
- if (!ofpbuf_size(txbuf)) {
+ dp_packet_pull(txbuf, retval);
+ if (!dp_packet_size(txbuf)) {
list_remove(&txbuf->list_node);
- ofpbuf_delete(txbuf);
+ dp_packet_delete(txbuf);
}
} else if (retval != -EAGAIN) {
error = -retval;
}
if (!error) {
- if (ofpbuf_size(&s->rxbuf) < 2) {
- n = 2 - ofpbuf_size(&s->rxbuf);
+ if (dp_packet_size(&s->rxbuf) < 2) {
+ n = 2 - dp_packet_size(&s->rxbuf);
} else {
uint16_t frame_len;
- frame_len = ntohs(get_unaligned_be16(ofpbuf_data(&s->rxbuf)));
+ frame_len = ntohs(get_unaligned_be16(dp_packet_data(&s->rxbuf)));
if (frame_len < ETH_HEADER_LEN) {
error = EPROTO;
n = 0;
} else {
- n = (2 + frame_len) - ofpbuf_size(&s->rxbuf);
+ n = (2 + frame_len) - dp_packet_size(&s->rxbuf);
}
}
}
if (!error) {
int retval;
- ofpbuf_prealloc_tailroom(&s->rxbuf, n);
- retval = stream_recv(s->stream, ofpbuf_tail(&s->rxbuf), n);
+ dp_packet_prealloc_tailroom(&s->rxbuf, n);
+ retval = stream_recv(s->stream, dp_packet_tail(&s->rxbuf), n);
if (retval > 0) {
- ofpbuf_set_size(&s->rxbuf, ofpbuf_size(&s->rxbuf) + retval);
- if (retval == n && ofpbuf_size(&s->rxbuf) > 2) {
- ofpbuf_pull(&s->rxbuf, 2);
+ dp_packet_set_size(&s->rxbuf, dp_packet_size(&s->rxbuf) + retval);
+ if (retval == n && dp_packet_size(&s->rxbuf) > 2) {
+ dp_packet_pull(&s->rxbuf, 2);
netdev_dummy_queue_packet(dev,
- ofpbuf_clone(&s->rxbuf));
- ofpbuf_clear(&s->rxbuf);
+ dp_packet_clone(&s->rxbuf));
+ dp_packet_clear(&s->rxbuf);
}
} else if (retval != -EAGAIN) {
error = (retval < 0 ? -retval
- : ofpbuf_size(&s->rxbuf) ? EPROTO
+ : dp_packet_size(&s->rxbuf) ? EPROTO
: EOF);
}
}
dummy_packet_stream_close(struct dummy_packet_stream *s)
{
stream_close(s->stream);
- ofpbuf_uninit(&s->rxbuf);
- ofpbuf_list_delete(&s->txq);
+ dp_packet_uninit(&s->rxbuf);
+ dp_packet_list_delete(&s->txq);
}
static void
static int
netdev_dummy_construct(struct netdev *netdev_)
{
- static atomic_uint next_n = ATOMIC_VAR_INIT(0xaa550000);
+ static atomic_count next_n = ATOMIC_COUNT_INIT(0xaa550000);
struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
unsigned int n;
- atomic_add(&next_n, 1, &n);
+ n = atomic_count_inc(&next_n);
ovs_mutex_init(&netdev->mutex);
ovs_mutex_lock(&netdev->mutex);
return 0;
}
+static int
+netdev_dummy_get_in4(const struct netdev *netdev_,
+ struct in_addr *address, struct in_addr *netmask)
+{
+ struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
+
+ ovs_mutex_lock(&netdev->mutex);
+ *address = netdev->address;
+ *netmask = netdev->netmask;
+ ovs_mutex_unlock(&netdev->mutex);
+ return 0;
+}
+
+static int
+netdev_dummy_set_in4(struct netdev *netdev_, struct in_addr address,
+ struct in_addr netmask)
+{
+ struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
+
+ ovs_mutex_lock(&netdev->mutex);
+ netdev->address = address;
+ netdev->netmask = netmask;
+ ovs_mutex_unlock(&netdev->mutex);
+
+ return 0;
+}
+
static int
netdev_dummy_set_config(struct netdev *netdev_, const struct smap *args)
{
ovs_mutex_lock(&netdev->mutex);
list_remove(&rx->node);
- ofpbuf_list_delete(&rx->recv_queue);
+ dp_packet_list_delete(&rx->recv_queue);
ovs_mutex_unlock(&netdev->mutex);
seq_destroy(rx->seq);
}
}
static int
-netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct ofpbuf **arr, int *c)
+netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **arr,
+ int *c)
{
struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
- struct ofpbuf *packet;
+ struct dp_packet *packet;
ovs_mutex_lock(&netdev->mutex);
if (!list_is_empty(&rx->recv_queue)) {
- packet = ofpbuf_from_list(list_pop_front(&rx->recv_queue));
+ packet = dp_packet_from_list(list_pop_front(&rx->recv_queue));
rx->recv_queue_len--;
} else {
packet = NULL;
}
ovs_mutex_lock(&netdev->mutex);
netdev->stats.rx_packets++;
- netdev->stats.rx_bytes += ofpbuf_size(packet);
+ netdev->stats.rx_bytes += dp_packet_size(packet);
ovs_mutex_unlock(&netdev->mutex);
dp_packet_pad(packet);
+ dp_packet_set_dp_hash(packet, 0);
+
arr[0] = packet;
*c = 1;
return 0;
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
ovs_mutex_lock(&netdev->mutex);
- ofpbuf_list_delete(&rx->recv_queue);
+ dp_packet_list_delete(&rx->recv_queue);
rx->recv_queue_len = 0;
ovs_mutex_unlock(&netdev->mutex);
}
static int
-netdev_dummy_send(struct netdev *netdev, struct ofpbuf *pkt, bool may_steal)
+netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
+ struct dp_packet **pkts, int cnt, bool may_steal)
{
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
- const void *buffer = ofpbuf_data(pkt);
- size_t size = ofpbuf_size(pkt);
+ int error = 0;
+ int i;
- if (size < ETH_HEADER_LEN) {
- return EMSGSIZE;
- } else {
- const struct eth_header *eth = buffer;
- int max_size;
+ for (i = 0; i < cnt; i++) {
+ const void *buffer = dp_packet_data(pkts[i]);
+ size_t size = dp_packet_size(pkts[i]);
- ovs_mutex_lock(&dev->mutex);
- max_size = dev->mtu + ETH_HEADER_LEN;
- ovs_mutex_unlock(&dev->mutex);
+ if (size < ETH_HEADER_LEN) {
+ error = EMSGSIZE;
+ break;
+ } else {
+ const struct eth_header *eth = buffer;
+ int max_size;
- if (eth->eth_type == htons(ETH_TYPE_VLAN)) {
- max_size += VLAN_HEADER_LEN;
- }
- if (size > max_size) {
- return EMSGSIZE;
+ ovs_mutex_lock(&dev->mutex);
+ max_size = dev->mtu + ETH_HEADER_LEN;
+ ovs_mutex_unlock(&dev->mutex);
+
+ if (eth->eth_type == htons(ETH_TYPE_VLAN)) {
+ max_size += VLAN_HEADER_LEN;
+ }
+ if (size > max_size) {
+ error = EMSGSIZE;
+ break;
+ }
}
- }
- ovs_mutex_lock(&dev->mutex);
- dev->stats.tx_packets++;
- dev->stats.tx_bytes += size;
+ ovs_mutex_lock(&dev->mutex);
+ dev->stats.tx_packets++;
+ dev->stats.tx_bytes += size;
+
+ dummy_packet_conn_send(&dev->conn, buffer, size);
- dummy_packet_conn_send(&dev->conn, buffer, size);
+ if (dev->tx_pcap) {
+ struct dp_packet packet;
- if (dev->tx_pcap) {
- struct ofpbuf packet;
+ dp_packet_use_const(&packet, buffer, size);
+ ovs_pcap_write(dev->tx_pcap, &packet);
+ fflush(dev->tx_pcap);
+ }
- ofpbuf_use_const(&packet, buffer, size);
- ovs_pcap_write(dev->tx_pcap, &packet);
- fflush(dev->tx_pcap);
+ ovs_mutex_unlock(&dev->mutex);
}
- ovs_mutex_unlock(&dev->mutex);
if (may_steal) {
- ofpbuf_delete(pkt);
+ for (i = 0; i < cnt; i++) {
+ dp_packet_delete(pkts[i]);
+ }
}
- return 0;
+ return error;
}
static int
return 0;
}
-static int
-netdev_dummy_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
-{
- struct netdev_dummy *dev = netdev_dummy_cast(netdev);
-
- ovs_mutex_lock(&dev->mutex);
- dev->stats = *stats;
- ovs_mutex_unlock(&dev->mutex);
-
- return 0;
-}
-
static int
netdev_dummy_get_ifindex(const struct netdev *netdev)
{
netdev_dummy_get_config,
netdev_dummy_set_config,
NULL, /* get_tunnel_config */
+ NULL, /* build header */
+ NULL, /* push header */
+ NULL, /* pop header */
+ NULL, /* get_numa_id */
+ NULL, /* set_multiq */
netdev_dummy_send, /* send */
NULL, /* send_wait */
NULL, /* get_carrier_resets */
NULL, /* get_miimon */
netdev_dummy_get_stats,
- netdev_dummy_set_stats,
NULL, /* get_features */
NULL, /* set_advertisements */
NULL, /* queue_dump_done */
NULL, /* dump_queue_stats */
- NULL, /* get_in4 */
+ netdev_dummy_get_in4, /* get_in4 */
NULL, /* set_in4 */
NULL, /* get_in6 */
NULL, /* add_router */
netdev_dummy_rxq_drain,
};
-static struct ofpbuf *
+static struct dp_packet *
eth_from_packet_or_flow(const char *s)
{
enum odp_key_fitness fitness;
- struct ofpbuf *packet;
+ struct dp_packet *packet;
struct ofpbuf odp_key;
struct flow flow;
int error;
}
/* Convert odp_key to flow. */
- fitness = odp_flow_key_to_flow(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key), &flow);
+ fitness = odp_flow_key_to_flow(ofpbuf_data(&odp_key),
+ ofpbuf_size(&odp_key), &flow);
if (fitness == ODP_FIT_ERROR) {
ofpbuf_uninit(&odp_key);
return NULL;
}
- packet = ofpbuf_new(0);
+ packet = dp_packet_new(0);
flow_compose(packet, &flow);
ofpbuf_uninit(&odp_key);
}
static void
-netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct ofpbuf *packet)
+netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct dp_packet *packet)
{
list_push_back(&rx->recv_queue, &packet->list_node);
rx->recv_queue_len++;
}
static void
-netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
+netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct dp_packet *packet)
OVS_REQUIRES(dummy->mutex)
{
struct netdev_rxq_dummy *rx, *prev;
LIST_FOR_EACH (rx, node, &dummy->rxes) {
if (rx->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
if (prev) {
- netdev_dummy_queue_packet__(prev, ofpbuf_clone(packet));
+ netdev_dummy_queue_packet__(prev, dp_packet_clone(packet));
}
prev = rx;
}
if (prev) {
netdev_dummy_queue_packet__(prev, packet);
} else {
- ofpbuf_delete(packet);
+ dp_packet_delete(packet);
}
}
dummy_dev = netdev_dummy_cast(netdev);
for (i = 2; i < argc; i++) {
- struct ofpbuf *packet;
+ struct dp_packet *packet;
packet = eth_from_packet_or_flow(argv[i]);
if (!packet) {
ds_destroy(&s);
}
+static void
+netdev_dummy_ip4addr(struct unixctl_conn *conn, int argc OVS_UNUSED,
+ const char *argv[], void *aux OVS_UNUSED)
+{
+ struct netdev *netdev = netdev_from_name(argv[1]);
+
+ if (netdev && is_dummy_class(netdev->netdev_class)) {
+ struct in_addr ip;
+ uint16_t plen;
+
+ if (ovs_scan(argv[2], IP_SCAN_FMT"/%"SCNi16,
+ IP_SCAN_ARGS(&ip.s_addr), &plen)) {
+ struct in_addr mask;
+
+ mask.s_addr = be32_prefix_mask(plen);
+ netdev_dummy_set_in4(netdev, ip, mask);
+ unixctl_command_reply(conn, "OK");
+ } else {
+ unixctl_command_reply(conn, "Invalid parameters");
+ }
+
+ netdev_close(netdev);
+ } else {
+ unixctl_command_reply_error(conn, "Unknown Dummy Interface");
+ netdev_close(netdev);
+ return;
+ }
+
+}
+
void
netdev_dummy_register(bool override)
{
- unixctl_command_register("netdev-dummy/receive", "NAME PACKET|FLOW...",
+ unixctl_command_register("netdev-dummy/receive", "name packet|flow...",
2, INT_MAX, netdev_dummy_receive, NULL);
unixctl_command_register("netdev-dummy/set-admin-state",
"[netdev] up|down", 1, 2,
unixctl_command_register("netdev-dummy/conn-state",
"[netdev]", 0, 1,
netdev_dummy_conn_state, NULL);
+ unixctl_command_register("netdev-dummy/ip4addr",
+ "[netdev] ipaddr/mask-prefix-len", 2, 2,
+ netdev_dummy_ip4addr, NULL);
+
if (override) {
struct sset types;