#include <errno.h>
-#include "connectivity.h"
+#include "dpif-netdev.h"
#include "flow.h"
#include "list.h"
#include "netdev-provider.h"
#include "packets.h"
#include "pcap-file.h"
#include "poll-loop.h"
-#include "seq.h"
#include "shash.h"
#include "sset.h"
#include "stream.h"
struct dummy_packet_conn conn OVS_GUARDED;
- FILE *tx_pcap, *rx_pcap OVS_GUARDED;
+ FILE *tx_pcap, *rxq_pcap OVS_GUARDED;
- struct list rxes OVS_GUARDED; /* List of child "netdev_rx_dummy"s. */
+ struct list rxes OVS_GUARDED; /* List of child "netdev_rxq_dummy"s. */
};
/* Max 'recv_queue_len' in struct netdev_dummy. */
#define NETDEV_DUMMY_MAX_QUEUE 100
-struct netdev_rx_dummy {
- struct netdev_rx up;
+struct netdev_rxq_dummy {
+ struct netdev_rxq up;
struct list node; /* In netdev_dummy's "rxes" list. */
struct list recv_queue;
int recv_queue_len; /* list_size(&recv_queue). */
return CONTAINER_OF(netdev, struct netdev_dummy, up);
}
-static struct netdev_rx_dummy *
-netdev_rx_dummy_cast(const struct netdev_rx *rx)
+static struct netdev_rxq_dummy *
+netdev_rxq_dummy_cast(const struct netdev_rxq *rx)
{
ovs_assert(is_dummy_class(netdev_get_class(rx->netdev)));
- return CONTAINER_OF(rx, struct netdev_rx_dummy, up);
+ return CONTAINER_OF(rx, struct netdev_rxq_dummy, up);
}
static void
int retval;
txbuf = ofpbuf_from_list(list_front(&s->txq));
- retval = stream_send(s->stream, txbuf->data, txbuf->size);
+ retval = stream_send(s->stream, ofpbuf_data(txbuf), ofpbuf_size(txbuf));
+
if (retval > 0) {
ofpbuf_pull(txbuf, retval);
- if (!txbuf->size) {
+ if (!ofpbuf_size(txbuf)) {
list_remove(&txbuf->list_node);
ofpbuf_delete(txbuf);
}
}
if (!error) {
- if (s->rxbuf.size < 2) {
- n = 2 - s->rxbuf.size;
+ if (ofpbuf_size(&s->rxbuf) < 2) {
+ n = 2 - ofpbuf_size(&s->rxbuf);
} else {
uint16_t frame_len;
- frame_len = ntohs(get_unaligned_be16(s->rxbuf.data));
+ frame_len = ntohs(get_unaligned_be16(ofpbuf_data(&s->rxbuf)));
if (frame_len < ETH_HEADER_LEN) {
error = EPROTO;
n = 0;
} else {
- n = (2 + frame_len) - s->rxbuf.size;
+ n = (2 + frame_len) - ofpbuf_size(&s->rxbuf);
}
}
}
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_set_size(&s->rxbuf, ofpbuf_size(&s->rxbuf) + retval);
+ if (retval == n && ofpbuf_size(&s->rxbuf) > 2) {
ofpbuf_pull(&s->rxbuf, 2);
netdev_dummy_queue_packet(dev,
ofpbuf_clone(&s->rxbuf));
}
} else if (retval != -EAGAIN) {
error = (retval < 0 ? -retval
- : s->rxbuf.size ? EPROTO
+ : ofpbuf_size(&s->rxbuf) ? EPROTO
: EOF);
}
}
reconnect_set_name(reconnect, stream);
reconnect_set_passive(reconnect, false, time_msec());
reconnect_enable(reconnect, time_msec());
- reconnect_set_backoff(reconnect, 1000, INT_MAX);
+ reconnect_set_backoff(reconnect, 100, INT_MAX);
+ reconnect_set_probe_interval(reconnect, 0);
conn->u.rconn.reconnect = reconnect;
+ conn->type = ACTIVE;
error = stream_open(stream, &active_stream, DSCP_DEFAULT);
conn->u.rconn.rstream = dummy_packet_stream_create(active_stream);
switch (error) {
case 0:
- reconnect_connected(conn->u.rconn.reconnect, time_msec());
- conn->type = ACTIVE;
+ reconnect_connected(reconnect, time_msec());
break;
case EAGAIN:
- reconnect_connecting(conn->u.rconn.reconnect, time_msec());
+ reconnect_connecting(reconnect, time_msec());
break;
default:
- reconnect_connecting(conn->u.rconn.reconnect, time_msec());
+ reconnect_connect_failed(reconnect, time_msec(), error);
stream_close(active_stream);
+ conn->u.rconn.rstream->stream = NULL;
break;
}
}
switch (reconnect_run(rconn->reconnect, time_msec())) {
case RECONNECT_CONNECT:
{
- int err = stream_connect(rconn->rstream->stream);
+ int error;
+
+ if (rconn->rstream->stream) {
+ error = stream_connect(rconn->rstream->stream);
+ } else {
+ error = stream_open(reconnect_get_name(rconn->reconnect),
+ &rconn->rstream->stream, DSCP_DEFAULT);
+ }
- switch (err) {
- case 0: /* Connected. */
+ switch (error) {
+ case 0:
reconnect_connected(rconn->reconnect, time_msec());
- dev->conn.type = ACTIVE;
break;
case EAGAIN:
reconnect_connecting(rconn->reconnect, time_msec());
- return;
+ break;
default:
- reconnect_connect_failed(rconn->reconnect, time_msec(), err);
+ reconnect_connect_failed(rconn->reconnect, time_msec(), error);
stream_close(rconn->rstream->stream);
- return;
+ rconn->rstream->stream = NULL;
+ break;
}
}
break;
if (err) {
reconnect_disconnected(rconn->reconnect, time_msec(), err);
stream_close(rconn->rstream->stream);
+ rconn->rstream->stream = NULL;
}
}
}
}
break;
case ACTIVE:
- dummy_packet_stream_wait(conn->u.rconn.rstream);
+ if (reconnect_is_connected(conn->u.rconn.reconnect)) {
+ dummy_packet_stream_wait(conn->u.rconn.rstream);
+ }
break;
case NONE:
break;
case ACTIVE:
- dummy_packet_stream_send(conn->u.rconn.rstream, buffer, size);
- dummy_packet_stream_wait(conn->u.rconn.rstream);
+ if (reconnect_is_connected(conn->u.rconn.reconnect)) {
+ dummy_packet_stream_send(conn->u.rconn.rstream, buffer, size);
+ dummy_packet_stream_wait(conn->u.rconn.rstream);
+ }
break;
case NONE:
dummy_packet_conn_set_config(&netdev->conn, args);
- if (netdev->rx_pcap) {
- fclose(netdev->rx_pcap);
+ if (netdev->rxq_pcap) {
+ fclose(netdev->rxq_pcap);
}
- if (netdev->tx_pcap && netdev->tx_pcap != netdev->rx_pcap) {
+ if (netdev->tx_pcap && netdev->tx_pcap != netdev->rxq_pcap) {
fclose(netdev->tx_pcap);
}
- netdev->rx_pcap = netdev->tx_pcap = NULL;
+ netdev->rxq_pcap = netdev->tx_pcap = NULL;
pcap = smap_get(args, "pcap");
if (pcap) {
- netdev->rx_pcap = netdev->tx_pcap = ovs_pcap_open(pcap, "ab");
+ netdev->rxq_pcap = netdev->tx_pcap = ovs_pcap_open(pcap, "ab");
} else {
- const char *rx_pcap = smap_get(args, "rx_pcap");
+ const char *rxq_pcap = smap_get(args, "rxq_pcap");
const char *tx_pcap = smap_get(args, "tx_pcap");
- if (rx_pcap) {
- netdev->rx_pcap = ovs_pcap_open(rx_pcap, "ab");
+ if (rxq_pcap) {
+ netdev->rxq_pcap = ovs_pcap_open(rxq_pcap, "ab");
}
if (tx_pcap) {
netdev->tx_pcap = ovs_pcap_open(tx_pcap, "ab");
return 0;
}
-static struct netdev_rx *
-netdev_dummy_rx_alloc(void)
+static struct netdev_rxq *
+netdev_dummy_rxq_alloc(void)
{
- struct netdev_rx_dummy *rx = xzalloc(sizeof *rx);
+ struct netdev_rxq_dummy *rx = xzalloc(sizeof *rx);
return &rx->up;
}
static int
-netdev_dummy_rx_construct(struct netdev_rx *rx_)
+netdev_dummy_rxq_construct(struct netdev_rxq *rxq_)
{
- struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
+ struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
ovs_mutex_lock(&netdev->mutex);
}
static void
-netdev_dummy_rx_destruct(struct netdev_rx *rx_)
+netdev_dummy_rxq_destruct(struct netdev_rxq *rxq_)
{
- struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
+ struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
ovs_mutex_lock(&netdev->mutex);
}
static void
-netdev_dummy_rx_dealloc(struct netdev_rx *rx_)
+netdev_dummy_rxq_dealloc(struct netdev_rxq *rxq_)
{
- struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
+ struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
free(rx);
}
static int
-netdev_dummy_rx_recv(struct netdev_rx *rx_, struct ofpbuf *buffer)
+netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct ofpbuf **arr, int *c)
{
- struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
+ struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
struct ofpbuf *packet;
- int retval;
ovs_mutex_lock(&netdev->mutex);
if (!list_is_empty(&rx->recv_queue)) {
if (!packet) {
return EAGAIN;
}
+ ovs_mutex_lock(&netdev->mutex);
+ netdev->stats.rx_packets++;
+ netdev->stats.rx_bytes += ofpbuf_size(packet);
+ ovs_mutex_unlock(&netdev->mutex);
- if (packet->size <= ofpbuf_tailroom(buffer)) {
- memcpy(buffer->data, packet->data, packet->size);
- buffer->size += packet->size;
- retval = 0;
-
- ovs_mutex_lock(&netdev->mutex);
- netdev->stats.rx_packets++;
- netdev->stats.rx_bytes += packet->size;
- ovs_mutex_unlock(&netdev->mutex);
- } else {
- retval = EMSGSIZE;
- }
- ofpbuf_delete(packet);
-
- return retval;
+ dp_packet_pad(packet);
+ arr[0] = packet;
+ *c = 1;
+ return 0;
}
static void
-netdev_dummy_rx_wait(struct netdev_rx *rx_)
+netdev_dummy_rxq_wait(struct netdev_rxq *rxq_)
{
- struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
+ struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
uint64_t seq = seq_read(rx->seq);
}
static int
-netdev_dummy_rx_drain(struct netdev_rx *rx_)
+netdev_dummy_rxq_drain(struct netdev_rxq *rxq_)
{
- struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
+ struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
ovs_mutex_lock(&netdev->mutex);
}
static int
-netdev_dummy_send(struct netdev *netdev, const void *buffer, size_t size)
+netdev_dummy_send(struct netdev *netdev, struct ofpbuf *pkt, bool may_steal)
{
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
+ const void *buffer = ofpbuf_data(pkt);
+ size_t size = ofpbuf_size(pkt);
if (size < ETH_HEADER_LEN) {
return EMSGSIZE;
}
ovs_mutex_unlock(&dev->mutex);
+ if (may_steal) {
+ ofpbuf_delete(pkt);
+ }
return 0;
}
ovs_mutex_lock(&dev->mutex);
if (!eth_addr_equals(dev->hwaddr, mac)) {
memcpy(dev->hwaddr, mac, ETH_ADDR_LEN);
- seq_change(connectivity_seq_get());
+ netdev_change_seq_changed(netdev);
}
ovs_mutex_unlock(&dev->mutex);
netdev->flags |= on;
netdev->flags &= ~off;
if (*old_flagsp != netdev->flags) {
- seq_change(connectivity_seq_get());
+ netdev_change_seq_changed(&netdev->up);
}
return 0;
netdev_dummy_update_flags,
- 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,
+ netdev_dummy_rxq_alloc,
+ netdev_dummy_rxq_construct,
+ netdev_dummy_rxq_destruct,
+ netdev_dummy_rxq_dealloc,
+ netdev_dummy_rxq_recv,
+ netdev_dummy_rxq_wait,
+ netdev_dummy_rxq_drain,
};
static struct ofpbuf *
}
/* Convert odp_key to flow. */
- fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &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;
}
static void
-netdev_dummy_queue_packet__(struct netdev_rx_dummy *rx, struct ofpbuf *packet)
+netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct ofpbuf *packet)
{
list_push_back(&rx->recv_queue, &packet->list_node);
rx->recv_queue_len++;
netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
OVS_REQUIRES(dummy->mutex)
{
- struct netdev_rx_dummy *rx, *prev;
+ struct netdev_rxq_dummy *rx, *prev;
- if (dummy->rx_pcap) {
- ovs_pcap_write(dummy->rx_pcap, packet);
- fflush(dummy->rx_pcap);
+ if (dummy->rxq_pcap) {
+ ovs_pcap_write(dummy->rxq_pcap, packet);
+ fflush(dummy->rxq_pcap);
}
prev = NULL;
LIST_FOR_EACH (rx, node, &dummy->rxes) {