]> git.proxmox.com Git - mirror_ovs.git/blame - lib/netdev-dummy.c
datapath-windows: Correct endianness for deleting zone.
[mirror_ovs.git] / lib / netdev-dummy.c
CommitLineData
614c4892 1/*
d8ada236 2 * Copyright (c) 2010, 2011, 2012, 2013, 2015, 2016, 2017 Nicira, Inc.
614c4892
BP
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <config.h>
18
19#include "dummy.h"
20
21#include <errno.h>
f8cf6502 22#include <unistd.h>
614c4892 23
e14deea0 24#include "dp-packet.h"
df1e5a3b 25#include "dpif-netdev.h"
fbac791a 26#include "flow.h"
614c4892 27#include "netdev-provider.h"
c060c4cf 28#include "netdev-vport.h"
fbac791a 29#include "odp-util.h"
25d436fb
BW
30#include "openvswitch/dynamic-string.h"
31#include "openvswitch/list.h"
32#include "openvswitch/ofp-print.h"
64c96779 33#include "openvswitch/ofpbuf.h"
25d436fb 34#include "openvswitch/vlog.h"
5617ae6a 35#include "ovs-atomic.h"
614c4892 36#include "packets.h"
55d87b06 37#include "pcap-file.h"
fd016ae3 38#include "openvswitch/poll-loop.h"
ee89ea7b 39#include "openvswitch/shash.h"
0cbfe35d 40#include "sset.h"
eab5611a
BP
41#include "stream.h"
42#include "unaligned.h"
55d87b06 43#include "timeval.h"
fbac791a 44#include "unixctl.h"
631486bd 45#include "reconnect.h"
614c4892
BP
46
47VLOG_DEFINE_THIS_MODULE(netdev_dummy);
48
631486bd
AZ
49struct reconnect;
50
51struct dummy_packet_stream {
eab5611a 52 struct stream *stream;
ca6ba700 53 struct ovs_list txq;
7a385993 54 struct dp_packet rxbuf;
eab5611a
BP
55};
56
631486bd
AZ
57enum dummy_packet_conn_type {
58 NONE, /* No connection is configured. */
59 PASSIVE, /* Listener. */
60 ACTIVE /* Connect to listener. */
61};
62
7d7fffe8
AZ
63enum dummy_netdev_conn_state {
64 CONN_STATE_CONNECTED, /* Listener connected. */
65 CONN_STATE_NOT_CONNECTED, /* Listener not connected. */
66 CONN_STATE_UNKNOWN, /* No relavent information. */
67};
68
631486bd
AZ
69struct dummy_packet_pconn {
70 struct pstream *pstream;
7778360b 71 struct dummy_packet_stream **streams;
631486bd
AZ
72 size_t n_streams;
73};
74
75struct dummy_packet_rconn {
76 struct dummy_packet_stream *rstream;
77 struct reconnect *reconnect;
78};
79
80struct dummy_packet_conn {
81 enum dummy_packet_conn_type type;
82 union {
83 struct dummy_packet_pconn pconn;
84 struct dummy_packet_rconn rconn;
85 } u;
86};
87
8613db65
DDP
88struct pkt_list_node {
89 struct dp_packet *pkt;
90 struct ovs_list list_node;
91};
92
5e1de67f
BP
93/* Protects 'dummy_list'. */
94static struct ovs_mutex dummy_list_mutex = OVS_MUTEX_INITIALIZER;
95
96/* Contains all 'struct dummy_dev's. */
ca6ba700 97static struct ovs_list dummy_list OVS_GUARDED_BY(dummy_list_mutex)
55951e15 98 = OVS_LIST_INITIALIZER(&dummy_list);
5e1de67f 99
b5d57fc8
BP
100struct netdev_dummy {
101 struct netdev up;
86383816 102
5e1de67f 103 /* In dummy_list. */
ca6ba700 104 struct ovs_list list_node OVS_GUARDED_BY(dummy_list_mutex);
5e1de67f 105
86383816 106 /* Protects all members below. */
5e1de67f 107 struct ovs_mutex mutex OVS_ACQ_AFTER(dummy_list_mutex);
86383816 108
74ff3298 109 struct eth_addr hwaddr OVS_GUARDED;
36e2140d
BP
110 int mtu OVS_GUARDED;
111 struct netdev_stats stats OVS_GUARDED;
112 enum netdev_flags flags OVS_GUARDED;
36e2140d 113 int ifindex OVS_GUARDED;
d537e73a 114 int numa_id OVS_GUARDED;
36e2140d 115
631486bd 116 struct dummy_packet_conn conn OVS_GUARDED;
36e2140d 117
f7791740 118 FILE *tx_pcap, *rxq_pcap OVS_GUARDED;
55d87b06 119
a36de779 120 struct in_addr address, netmask;
a8704b50 121 struct in6_addr ipv6, ipv6_mask;
ca6ba700 122 struct ovs_list rxes OVS_GUARDED; /* List of child "netdev_rxq_dummy"s. */
9a81a637
IM
123
124 /* The following properties are for dummy-pmd and they cannot be changed
125 * when a device is running, so we remember the request and update them
126 * next time netdev_dummy_reconfigure() is called. */
d537e73a
DDP
127 int requested_n_txq OVS_GUARDED;
128 int requested_n_rxq OVS_GUARDED;
129 int requested_numa_id OVS_GUARDED;
614c4892
BP
130};
131
e34cfdd9
BP
132/* Max 'recv_queue_len' in struct netdev_dummy. */
133#define NETDEV_DUMMY_MAX_QUEUE 100
134
f7791740
PS
135struct netdev_rxq_dummy {
136 struct netdev_rxq up;
ca6ba700
TG
137 struct ovs_list node; /* In netdev_dummy's "rxes" list. */
138 struct ovs_list recv_queue;
417e7e66 139 int recv_queue_len; /* ovs_list_size(&recv_queue). */
98045eda 140 struct seq *seq; /* Reports newly queued packets. */
614c4892
BP
141};
142
95d4ec33 143static unixctl_cb_func netdev_dummy_set_admin_state;
9dc63482 144static int netdev_dummy_construct(struct netdev *);
9a81a637
IM
145static void netdev_dummy_queue_packet(struct netdev_dummy *,
146 struct dp_packet *, int);
eab5611a 147
631486bd 148static void dummy_packet_stream_close(struct dummy_packet_stream *);
614c4892 149
8613db65
DDP
150static void pkt_list_delete(struct ovs_list *);
151
614c4892
BP
152static bool
153is_dummy_class(const struct netdev_class *class)
154{
9dc63482 155 return class->construct == netdev_dummy_construct;
614c4892
BP
156}
157
614c4892
BP
158static struct netdev_dummy *
159netdev_dummy_cast(const struct netdev *netdev)
160{
b5d57fc8 161 ovs_assert(is_dummy_class(netdev_get_class(netdev)));
180c6d0b 162 return CONTAINER_OF(netdev, struct netdev_dummy, up);
614c4892
BP
163}
164
f7791740
PS
165static struct netdev_rxq_dummy *
166netdev_rxq_dummy_cast(const struct netdev_rxq *rx)
796223f5 167{
9dc63482 168 ovs_assert(is_dummy_class(netdev_get_class(rx->netdev)));
f7791740 169 return CONTAINER_OF(rx, struct netdev_rxq_dummy, up);
796223f5
BP
170}
171
eab5611a 172static void
631486bd 173dummy_packet_stream_init(struct dummy_packet_stream *s, struct stream *stream)
eab5611a 174{
631486bd
AZ
175 int rxbuf_size = stream ? 2048 : 0;
176 s->stream = stream;
cf62fa4c 177 dp_packet_init(&s->rxbuf, rxbuf_size);
417e7e66 178 ovs_list_init(&s->txq);
631486bd 179}
eab5611a 180
631486bd
AZ
181static struct dummy_packet_stream *
182dummy_packet_stream_create(struct stream *stream)
183{
184 struct dummy_packet_stream *s;
eab5611a 185
631486bd
AZ
186 s = xzalloc(sizeof *s);
187 dummy_packet_stream_init(s, stream);
86383816 188
631486bd
AZ
189 return s;
190}
eab5611a 191
631486bd
AZ
192static void
193dummy_packet_stream_wait(struct dummy_packet_stream *s)
194{
195 stream_run_wait(s->stream);
417e7e66 196 if (!ovs_list_is_empty(&s->txq)) {
631486bd
AZ
197 stream_send_wait(s->stream);
198 }
199 stream_recv_wait(s->stream);
200}
eab5611a 201
631486bd
AZ
202static void
203dummy_packet_stream_send(struct dummy_packet_stream *s, const void *buffer, size_t size)
204{
417e7e66 205 if (ovs_list_size(&s->txq) < NETDEV_DUMMY_MAX_QUEUE) {
cf62fa4c 206 struct dp_packet *b;
8613db65 207 struct pkt_list_node *node;
eab5611a 208
cf62fa4c
PS
209 b = dp_packet_clone_data_with_headroom(buffer, size, 2);
210 put_unaligned_be16(dp_packet_push_uninit(b, 2), htons(size));
8613db65
DDP
211
212 node = xmalloc(sizeof *node);
213 node->pkt = b;
417e7e66 214 ovs_list_push_back(&s->txq, &node->list_node);
631486bd
AZ
215 }
216}
217
218static int
219dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
220{
221 int error = 0;
222 size_t n;
223
224 stream_run(s->stream);
225
417e7e66 226 if (!ovs_list_is_empty(&s->txq)) {
8613db65 227 struct pkt_list_node *txbuf_node;
cf62fa4c 228 struct dp_packet *txbuf;
631486bd
AZ
229 int retval;
230
417e7e66 231 ASSIGN_CONTAINER(txbuf_node, ovs_list_front(&s->txq), list_node);
8613db65 232 txbuf = txbuf_node->pkt;
cf62fa4c 233 retval = stream_send(s->stream, dp_packet_data(txbuf), dp_packet_size(txbuf));
c0c4982f 234
631486bd 235 if (retval > 0) {
cf62fa4c
PS
236 dp_packet_pull(txbuf, retval);
237 if (!dp_packet_size(txbuf)) {
417e7e66 238 ovs_list_remove(&txbuf_node->list_node);
8613db65 239 free(txbuf_node);
cf62fa4c 240 dp_packet_delete(txbuf);
eab5611a 241 }
631486bd
AZ
242 } else if (retval != -EAGAIN) {
243 error = -retval;
eab5611a 244 }
631486bd 245 }
86f1d032 246
631486bd 247 if (!error) {
cf62fa4c
PS
248 if (dp_packet_size(&s->rxbuf) < 2) {
249 n = 2 - dp_packet_size(&s->rxbuf);
631486bd
AZ
250 } else {
251 uint16_t frame_len;
252
cf62fa4c 253 frame_len = ntohs(get_unaligned_be16(dp_packet_data(&s->rxbuf)));
631486bd
AZ
254 if (frame_len < ETH_HEADER_LEN) {
255 error = EPROTO;
256 n = 0;
257 } else {
cf62fa4c 258 n = (2 + frame_len) - dp_packet_size(&s->rxbuf);
631486bd
AZ
259 }
260 }
eab5611a 261 }
631486bd
AZ
262 if (!error) {
263 int retval;
264
cf62fa4c
PS
265 dp_packet_prealloc_tailroom(&s->rxbuf, n);
266 retval = stream_recv(s->stream, dp_packet_tail(&s->rxbuf), n);
c0c4982f 267
631486bd 268 if (retval > 0) {
cf62fa4c
PS
269 dp_packet_set_size(&s->rxbuf, dp_packet_size(&s->rxbuf) + retval);
270 if (retval == n && dp_packet_size(&s->rxbuf) > 2) {
271 dp_packet_pull(&s->rxbuf, 2);
631486bd 272 netdev_dummy_queue_packet(dev,
9a81a637 273 dp_packet_clone(&s->rxbuf), 0);
cf62fa4c 274 dp_packet_clear(&s->rxbuf);
631486bd
AZ
275 }
276 } else if (retval != -EAGAIN) {
277 error = (retval < 0 ? -retval
cf62fa4c 278 : dp_packet_size(&s->rxbuf) ? EPROTO
631486bd
AZ
279 : EOF);
280 }
281 }
282
283 return error;
eab5611a
BP
284}
285
286static void
631486bd 287dummy_packet_stream_close(struct dummy_packet_stream *s)
eab5611a
BP
288{
289 stream_close(s->stream);
cf62fa4c 290 dp_packet_uninit(&s->rxbuf);
8613db65 291 pkt_list_delete(&s->txq);
eab5611a
BP
292}
293
294static void
631486bd 295dummy_packet_conn_init(struct dummy_packet_conn *conn)
eab5611a 296{
631486bd
AZ
297 memset(conn, 0, sizeof *conn);
298 conn->type = NONE;
299}
eab5611a 300
631486bd
AZ
301static void
302dummy_packet_conn_get_config(struct dummy_packet_conn *conn, struct smap *args)
303{
eab5611a 304
631486bd
AZ
305 switch (conn->type) {
306 case PASSIVE:
307 smap_add(args, "pstream", pstream_get_name(conn->u.pconn.pstream));
308 break;
309
310 case ACTIVE:
311 smap_add(args, "stream", stream_get_name(conn->u.rconn.rstream->stream));
312 break;
313
314 case NONE:
315 default:
316 break;
317 }
318}
319
320static void
321dummy_packet_conn_close(struct dummy_packet_conn *conn)
322{
323 int i;
324 struct dummy_packet_pconn *pconn = &conn->u.pconn;
325 struct dummy_packet_rconn *rconn = &conn->u.rconn;
326
327 switch (conn->type) {
328 case PASSIVE:
329 pstream_close(pconn->pstream);
330 for (i = 0; i < pconn->n_streams; i++) {
7778360b
LR
331 dummy_packet_stream_close(pconn->streams[i]);
332 free(pconn->streams[i]);
631486bd
AZ
333 }
334 free(pconn->streams);
335 pconn->pstream = NULL;
336 pconn->streams = NULL;
337 break;
338
339 case ACTIVE:
340 dummy_packet_stream_close(rconn->rstream);
341 free(rconn->rstream);
342 rconn->rstream = NULL;
343 reconnect_destroy(rconn->reconnect);
344 rconn->reconnect = NULL;
345 break;
346
347 case NONE:
348 default:
349 break;
350 }
351
352 conn->type = NONE;
353 memset(conn, 0, sizeof *conn);
354}
355
356static void
357dummy_packet_conn_set_config(struct dummy_packet_conn *conn,
358 const struct smap *args)
359{
360 const char *pstream = smap_get(args, "pstream");
361 const char *stream = smap_get(args, "stream");
362
363 if (pstream && stream) {
364 VLOG_WARN("Open failed: both %s and %s are configured",
365 pstream, stream);
366 return;
367 }
368
369 switch (conn->type) {
370 case PASSIVE:
966904d2
BP
371 if (pstream &&
372 !strcmp(pstream_get_name(conn->u.pconn.pstream), pstream)) {
631486bd
AZ
373 return;
374 }
375 dummy_packet_conn_close(conn);
376 break;
377 case ACTIVE:
966904d2
BP
378 if (stream &&
379 !strcmp(stream_get_name(conn->u.rconn.rstream->stream), stream)) {
631486bd
AZ
380 return;
381 }
382 dummy_packet_conn_close(conn);
383 break;
384 case NONE:
385 default:
386 break;
387 }
388
389 if (pstream) {
390 int error;
391
392 error = pstream_open(pstream, &conn->u.pconn.pstream, DSCP_DEFAULT);
393 if (error) {
394 VLOG_WARN("%s: open failed (%s)", pstream, ovs_strerror(error));
395 } else {
396 conn->type = PASSIVE;
397 }
398 }
399
400 if (stream) {
401 int error;
402 struct stream *active_stream;
ea53e3a8 403 struct reconnect *reconnect;
631486bd
AZ
404
405 reconnect = reconnect_create(time_msec());
406 reconnect_set_name(reconnect, stream);
407 reconnect_set_passive(reconnect, false, time_msec());
408 reconnect_enable(reconnect, time_msec());
fc24d64d 409 reconnect_set_backoff(reconnect, 100, INT_MAX);
13af13b3 410 reconnect_set_probe_interval(reconnect, 0);
631486bd 411 conn->u.rconn.reconnect = reconnect;
c0c4982f 412 conn->type = ACTIVE;
631486bd
AZ
413
414 error = stream_open(stream, &active_stream, DSCP_DEFAULT);
415 conn->u.rconn.rstream = dummy_packet_stream_create(active_stream);
416
417 switch (error) {
418 case 0:
c0c4982f 419 reconnect_connected(reconnect, time_msec());
631486bd
AZ
420 break;
421
422 case EAGAIN:
c0c4982f 423 reconnect_connecting(reconnect, time_msec());
631486bd
AZ
424 break;
425
426 default:
c0c4982f 427 reconnect_connect_failed(reconnect, time_msec(), error);
631486bd 428 stream_close(active_stream);
c0c4982f 429 conn->u.rconn.rstream->stream = NULL;
631486bd
AZ
430 break;
431 }
432 }
433}
434
435static void
436dummy_pconn_run(struct netdev_dummy *dev)
437 OVS_REQUIRES(dev->mutex)
438{
439 struct stream *new_stream;
440 struct dummy_packet_pconn *pconn = &dev->conn.u.pconn;
441 int error;
442 size_t i;
443
444 error = pstream_accept(pconn->pstream, &new_stream);
445 if (!error) {
446 struct dummy_packet_stream *s;
447
448 pconn->streams = xrealloc(pconn->streams,
449 ((pconn->n_streams + 1)
7778360b
LR
450 * sizeof s));
451 s = xmalloc(sizeof *s);
452 pconn->streams[pconn->n_streams++] = s;
631486bd
AZ
453 dummy_packet_stream_init(s, new_stream);
454 } else if (error != EAGAIN) {
455 VLOG_WARN("%s: accept failed (%s)",
456 pstream_get_name(pconn->pstream), ovs_strerror(error));
457 pstream_close(pconn->pstream);
458 pconn->pstream = NULL;
459 dev->conn.type = NONE;
460 }
461
7778360b
LR
462 for (i = 0; i < pconn->n_streams; ) {
463 struct dummy_packet_stream *s = pconn->streams[i];
631486bd
AZ
464
465 error = dummy_packet_stream_run(dev, s);
466 if (error) {
467 VLOG_DBG("%s: closing connection (%s)",
468 stream_get_name(s->stream),
469 ovs_retval_to_string(error));
470 dummy_packet_stream_close(s);
7778360b 471 free(s);
631486bd 472 pconn->streams[i] = pconn->streams[--pconn->n_streams];
7778360b
LR
473 } else {
474 i++;
eab5611a 475 }
631486bd
AZ
476 }
477}
eab5611a 478
631486bd
AZ
479static void
480dummy_rconn_run(struct netdev_dummy *dev)
481OVS_REQUIRES(dev->mutex)
482{
483 struct dummy_packet_rconn *rconn = &dev->conn.u.rconn;
484
485 switch (reconnect_run(rconn->reconnect, time_msec())) {
486 case RECONNECT_CONNECT:
487 {
c0c4982f
AZ
488 int error;
489
490 if (rconn->rstream->stream) {
491 error = stream_connect(rconn->rstream->stream);
492 } else {
493 error = stream_open(reconnect_get_name(rconn->reconnect),
494 &rconn->rstream->stream, DSCP_DEFAULT);
495 }
631486bd 496
c0c4982f
AZ
497 switch (error) {
498 case 0:
631486bd 499 reconnect_connected(rconn->reconnect, time_msec());
631486bd
AZ
500 break;
501
502 case EAGAIN:
503 reconnect_connecting(rconn->reconnect, time_msec());
c0c4982f 504 break;
631486bd
AZ
505
506 default:
c0c4982f 507 reconnect_connect_failed(rconn->reconnect, time_msec(), error);
631486bd 508 stream_close(rconn->rstream->stream);
c0c4982f
AZ
509 rconn->rstream->stream = NULL;
510 break;
eab5611a 511 }
eab5611a 512 }
631486bd
AZ
513 break;
514
515 case RECONNECT_DISCONNECT:
516 case RECONNECT_PROBE:
517 default:
518 break;
519 }
520
521 if (reconnect_is_connected(rconn->reconnect)) {
522 int err;
523
524 err = dummy_packet_stream_run(dev, rconn->rstream);
525
526 if (err) {
527 reconnect_disconnected(rconn->reconnect, time_msec(), err);
528 stream_close(rconn->rstream->stream);
c0c4982f 529 rconn->rstream->stream = NULL;
631486bd
AZ
530 }
531 }
532}
533
534static void
535dummy_packet_conn_run(struct netdev_dummy *dev)
536 OVS_REQUIRES(dev->mutex)
537{
538 switch (dev->conn.type) {
539 case PASSIVE:
540 dummy_pconn_run(dev);
541 break;
542
543 case ACTIVE:
544 dummy_rconn_run(dev);
545 break;
546
547 case NONE:
548 default:
549 break;
550 }
551}
552
553static void
554dummy_packet_conn_wait(struct dummy_packet_conn *conn)
555{
556 int i;
557 switch (conn->type) {
558 case PASSIVE:
559 pstream_wait(conn->u.pconn.pstream);
560 for (i = 0; i < conn->u.pconn.n_streams; i++) {
7778360b 561 struct dummy_packet_stream *s = conn->u.pconn.streams[i];
631486bd
AZ
562 dummy_packet_stream_wait(s);
563 }
564 break;
565 case ACTIVE:
c0c4982f
AZ
566 if (reconnect_is_connected(conn->u.rconn.reconnect)) {
567 dummy_packet_stream_wait(conn->u.rconn.rstream);
568 }
631486bd
AZ
569 break;
570
571 case NONE:
572 default:
573 break;
574 }
575}
576
577static void
578dummy_packet_conn_send(struct dummy_packet_conn *conn,
579 const void *buffer, size_t size)
580{
581 int i;
582
583 switch (conn->type) {
584 case PASSIVE:
585 for (i = 0; i < conn->u.pconn.n_streams; i++) {
7778360b 586 struct dummy_packet_stream *s = conn->u.pconn.streams[i];
631486bd
AZ
587
588 dummy_packet_stream_send(s, buffer, size);
589 pstream_wait(conn->u.pconn.pstream);
590 }
591 break;
592
593 case ACTIVE:
c0c4982f
AZ
594 if (reconnect_is_connected(conn->u.rconn.reconnect)) {
595 dummy_packet_stream_send(conn->u.rconn.rstream, buffer, size);
596 dummy_packet_stream_wait(conn->u.rconn.rstream);
597 }
631486bd
AZ
598 break;
599
600 case NONE:
601 default:
602 break;
603 }
604}
605
7d7fffe8
AZ
606static enum dummy_netdev_conn_state
607dummy_netdev_get_conn_state(struct dummy_packet_conn *conn)
608{
609 enum dummy_netdev_conn_state state;
610
611 if (conn->type == ACTIVE) {
612 if (reconnect_is_connected(conn->u.rconn.reconnect)) {
613 state = CONN_STATE_CONNECTED;
614 } else {
615 state = CONN_STATE_NOT_CONNECTED;
616 }
617 } else {
618 state = CONN_STATE_UNKNOWN;
619 }
620
621 return state;
622}
623
631486bd 624static void
e98d0cb3 625netdev_dummy_run(const struct netdev_class *netdev_class)
631486bd
AZ
626{
627 struct netdev_dummy *dev;
628
629 ovs_mutex_lock(&dummy_list_mutex);
630 LIST_FOR_EACH (dev, list_node, &dummy_list) {
e98d0cb3
DDP
631 if (netdev_get_class(&dev->up) != netdev_class) {
632 continue;
633 }
631486bd
AZ
634 ovs_mutex_lock(&dev->mutex);
635 dummy_packet_conn_run(dev);
636 ovs_mutex_unlock(&dev->mutex);
637 }
638 ovs_mutex_unlock(&dummy_list_mutex);
639}
640
641static void
e98d0cb3 642netdev_dummy_wait(const struct netdev_class *netdev_class)
631486bd
AZ
643{
644 struct netdev_dummy *dev;
645
646 ovs_mutex_lock(&dummy_list_mutex);
647 LIST_FOR_EACH (dev, list_node, &dummy_list) {
e98d0cb3
DDP
648 if (netdev_get_class(&dev->up) != netdev_class) {
649 continue;
650 }
631486bd
AZ
651 ovs_mutex_lock(&dev->mutex);
652 dummy_packet_conn_wait(&dev->conn);
86383816 653 ovs_mutex_unlock(&dev->mutex);
eab5611a 654 }
5e1de67f 655 ovs_mutex_unlock(&dummy_list_mutex);
eab5611a
BP
656}
657
9dc63482
BP
658static struct netdev *
659netdev_dummy_alloc(void)
660{
661 struct netdev_dummy *netdev = xzalloc(sizeof *netdev);
662 return &netdev->up;
663}
664
614c4892 665static int
9dc63482 666netdev_dummy_construct(struct netdev *netdev_)
614c4892 667{
97e5b2e5 668 static atomic_count next_n = ATOMIC_COUNT_INIT(0xaa550000);
9dc63482 669 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
01cdb3a1
BP
670 unsigned int n;
671
97e5b2e5 672 n = atomic_count_inc(&next_n);
86383816 673
834d6caf 674 ovs_mutex_init(&netdev->mutex);
36e2140d 675 ovs_mutex_lock(&netdev->mutex);
74ff3298
JR
676 netdev->hwaddr.ea[0] = 0xaa;
677 netdev->hwaddr.ea[1] = 0x55;
678 netdev->hwaddr.ea[2] = n >> 24;
679 netdev->hwaddr.ea[3] = n >> 16;
680 netdev->hwaddr.ea[4] = n >> 8;
681 netdev->hwaddr.ea[5] = n;
b5d57fc8
BP
682 netdev->mtu = 1500;
683 netdev->flags = 0;
b5d57fc8 684 netdev->ifindex = -EOPNOTSUPP;
9a81a637
IM
685 netdev->requested_n_rxq = netdev_->n_rxq;
686 netdev->requested_n_txq = netdev_->n_txq;
d537e73a 687 netdev->numa_id = 0;
eab5611a 688
631486bd 689 dummy_packet_conn_init(&netdev->conn);
eab5611a 690
417e7e66 691 ovs_list_init(&netdev->rxes);
36e2140d 692 ovs_mutex_unlock(&netdev->mutex);
b5d57fc8 693
5e1de67f 694 ovs_mutex_lock(&dummy_list_mutex);
417e7e66 695 ovs_list_push_back(&dummy_list, &netdev->list_node);
5e1de67f
BP
696 ovs_mutex_unlock(&dummy_list_mutex);
697
614c4892
BP
698 return 0;
699}
700
701static void
9dc63482 702netdev_dummy_destruct(struct netdev *netdev_)
614c4892 703{
b5d57fc8 704 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
614c4892 705
5e1de67f 706 ovs_mutex_lock(&dummy_list_mutex);
417e7e66 707 ovs_list_remove(&netdev->list_node);
5e1de67f
BP
708 ovs_mutex_unlock(&dummy_list_mutex);
709
36e2140d 710 ovs_mutex_lock(&netdev->mutex);
360990eb
BP
711 if (netdev->rxq_pcap) {
712 fclose(netdev->rxq_pcap);
713 }
714 if (netdev->tx_pcap && netdev->tx_pcap != netdev->rxq_pcap) {
715 fclose(netdev->tx_pcap);
716 }
631486bd
AZ
717 dummy_packet_conn_close(&netdev->conn);
718 netdev->conn.type = NONE;
719
36e2140d 720 ovs_mutex_unlock(&netdev->mutex);
86383816 721 ovs_mutex_destroy(&netdev->mutex);
9dc63482
BP
722}
723
724static void
725netdev_dummy_dealloc(struct netdev *netdev_)
726{
727 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
728
b5d57fc8 729 free(netdev);
614c4892
BP
730}
731
8073dd31 732static int
9a81a637 733netdev_dummy_get_config(const struct netdev *dev, struct smap *args)
8073dd31 734{
9a81a637 735 struct netdev_dummy *netdev = netdev_dummy_cast(dev);
8073dd31 736
5a9bf514 737 ovs_mutex_lock(&netdev->mutex);
55d87b06 738
b5d57fc8
BP
739 if (netdev->ifindex >= 0) {
740 smap_add_format(args, "ifindex", "%d", netdev->ifindex);
8073dd31 741 }
55d87b06 742
631486bd 743 dummy_packet_conn_get_config(&netdev->conn, args);
5a9bf514 744
9a81a637
IM
745 /* 'dummy-pmd' specific config. */
746 if (!netdev_is_pmd(dev)) {
747 goto exit;
748 }
749 smap_add_format(args, "requested_rx_queues", "%d", netdev->requested_n_rxq);
750 smap_add_format(args, "configured_rx_queues", "%d", dev->n_rxq);
751 smap_add_format(args, "requested_tx_queues", "%d", netdev->requested_n_txq);
752 smap_add_format(args, "configured_tx_queues", "%d", dev->n_txq);
753
754exit:
55d87b06 755 ovs_mutex_unlock(&netdev->mutex);
8073dd31
NM
756 return 0;
757}
758
2af602f2 759static int
a8704b50
PS
760netdev_dummy_get_addr_list(const struct netdev *netdev_, struct in6_addr **paddr,
761 struct in6_addr **pmask, int *n_addr)
2af602f2
TLSC
762{
763 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
a8704b50
PS
764 int cnt = 0, i = 0, err = 0;
765 struct in6_addr *addr, *mask;
2af602f2
TLSC
766
767 ovs_mutex_lock(&netdev->mutex);
a8704b50
PS
768 if (netdev->address.s_addr != INADDR_ANY) {
769 cnt++;
770 }
771
772 if (ipv6_addr_is_set(&netdev->ipv6)) {
773 cnt++;
774 }
775 if (!cnt) {
776 err = EADDRNOTAVAIL;
777 goto out;
778 }
779 addr = xmalloc(sizeof *addr * cnt);
780 mask = xmalloc(sizeof *mask * cnt);
781 if (netdev->address.s_addr != INADDR_ANY) {
782 in6_addr_set_mapped_ipv4(&addr[i], netdev->address.s_addr);
783 in6_addr_set_mapped_ipv4(&mask[i], netdev->netmask.s_addr);
784 i++;
785 }
786
787 if (ipv6_addr_is_set(&netdev->ipv6)) {
788 memcpy(&addr[i], &netdev->ipv6, sizeof *addr);
789 memcpy(&mask[i], &netdev->ipv6_mask, sizeof *mask);
790 i++;
791 }
792 if (paddr) {
793 *paddr = addr;
794 *pmask = mask;
795 *n_addr = cnt;
796 } else {
797 free(addr);
798 free(mask);
799 }
800out:
2af602f2
TLSC
801 ovs_mutex_unlock(&netdev->mutex);
802
a8704b50 803 return err;
2af602f2
TLSC
804}
805
a36de779
PS
806static int
807netdev_dummy_set_in4(struct netdev *netdev_, struct in_addr address,
808 struct in_addr netmask)
809{
810 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
811
812 ovs_mutex_lock(&netdev->mutex);
813 netdev->address = address;
814 netdev->netmask = netmask;
d2b11b5b 815 netdev_change_seq_changed(netdev_);
a36de779
PS
816 ovs_mutex_unlock(&netdev->mutex);
817
818 return 0;
819}
820
2af602f2 821static int
a8704b50
PS
822netdev_dummy_set_in6(struct netdev *netdev_, struct in6_addr *in6,
823 struct in6_addr *mask)
2af602f2
TLSC
824{
825 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
826
827 ovs_mutex_lock(&netdev->mutex);
828 netdev->ipv6 = *in6;
a8704b50 829 netdev->ipv6_mask = *mask;
d2b11b5b 830 netdev_change_seq_changed(netdev_);
2af602f2
TLSC
831 ovs_mutex_unlock(&netdev->mutex);
832
833 return 0;
834}
835
bf9f6f80 836#define DUMMY_MAX_QUEUES_PER_PORT 1024
837
8073dd31 838static int
9fff138e
DDP
839netdev_dummy_set_config(struct netdev *netdev_, const struct smap *args,
840 char **errp OVS_UNUSED)
614c4892 841{
b5d57fc8 842 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
55d87b06 843 const char *pcap;
d66e4a5e 844 int new_n_rxq, new_n_txq, new_numa_id;
614c4892 845
86383816 846 ovs_mutex_lock(&netdev->mutex);
b5d57fc8 847 netdev->ifindex = smap_get_int(args, "ifindex", -EOPNOTSUPP);
eab5611a 848
631486bd 849 dummy_packet_conn_set_config(&netdev->conn, args);
55d87b06 850
f7791740
PS
851 if (netdev->rxq_pcap) {
852 fclose(netdev->rxq_pcap);
55d87b06 853 }
f7791740 854 if (netdev->tx_pcap && netdev->tx_pcap != netdev->rxq_pcap) {
55d87b06
BP
855 fclose(netdev->tx_pcap);
856 }
f7791740 857 netdev->rxq_pcap = netdev->tx_pcap = NULL;
55d87b06
BP
858 pcap = smap_get(args, "pcap");
859 if (pcap) {
f7791740 860 netdev->rxq_pcap = netdev->tx_pcap = ovs_pcap_open(pcap, "ab");
55d87b06 861 } else {
f7791740 862 const char *rxq_pcap = smap_get(args, "rxq_pcap");
55d87b06
BP
863 const char *tx_pcap = smap_get(args, "tx_pcap");
864
f7791740
PS
865 if (rxq_pcap) {
866 netdev->rxq_pcap = ovs_pcap_open(rxq_pcap, "ab");
55d87b06
BP
867 }
868 if (tx_pcap) {
50aa0364 869 netdev->tx_pcap = ovs_pcap_open(tx_pcap, "ab");
55d87b06
BP
870 }
871 }
872
9a81a637
IM
873 netdev_change_seq_changed(netdev_);
874
875 /* 'dummy-pmd' specific config. */
876 if (!netdev_->netdev_class->is_pmd) {
877 goto exit;
878 }
879
cce57f8d 880 new_n_rxq = MAX(smap_get_int(args, "n_rxq", NR_QUEUE), 1);
881 new_n_txq = MAX(smap_get_int(args, "n_txq", NR_QUEUE), 1);
bf9f6f80 882
883 if (new_n_rxq > DUMMY_MAX_QUEUES_PER_PORT ||
884 new_n_txq > DUMMY_MAX_QUEUES_PER_PORT) {
885 VLOG_WARN("The one or both of interface %s queues"
886 "(rxq: %d, txq: %d) exceed %d. Sets it %d.\n",
887 netdev_get_name(netdev_),
888 new_n_rxq,
889 new_n_txq,
890 DUMMY_MAX_QUEUES_PER_PORT,
891 DUMMY_MAX_QUEUES_PER_PORT);
892
893 new_n_rxq = MIN(DUMMY_MAX_QUEUES_PER_PORT, new_n_rxq);
894 new_n_txq = MIN(DUMMY_MAX_QUEUES_PER_PORT, new_n_txq);
895 }
896
d537e73a
DDP
897 new_numa_id = smap_get_int(args, "numa_id", 0);
898 if (new_n_rxq != netdev->requested_n_rxq
d66e4a5e 899 || new_n_txq != netdev->requested_n_txq
d537e73a 900 || new_numa_id != netdev->requested_numa_id) {
9a81a637 901 netdev->requested_n_rxq = new_n_rxq;
d66e4a5e 902 netdev->requested_n_txq = new_n_txq;
d537e73a 903 netdev->requested_numa_id = new_numa_id;
9a81a637
IM
904 netdev_request_reconfigure(netdev_);
905 }
86383816 906
9a81a637
IM
907exit:
908 ovs_mutex_unlock(&netdev->mutex);
614c4892
BP
909 return 0;
910}
911
f9176a3a 912static int
d537e73a 913netdev_dummy_get_numa_id(const struct netdev *netdev_)
f9176a3a 914{
d537e73a
DDP
915 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
916
917 ovs_mutex_lock(&netdev->mutex);
918 int numa_id = netdev->numa_id;
919 ovs_mutex_unlock(&netdev->mutex);
920
921 return numa_id;
f9176a3a
IM
922}
923
9a81a637
IM
924/* Sets the number of tx queues and rx queues for the dummy PMD interface. */
925static int
926netdev_dummy_reconfigure(struct netdev *netdev_)
927{
928 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
929
930 ovs_mutex_lock(&netdev->mutex);
931
932 netdev_->n_txq = netdev->requested_n_txq;
933 netdev_->n_rxq = netdev->requested_n_rxq;
d537e73a 934 netdev->numa_id = netdev->requested_numa_id;
9a81a637
IM
935
936 ovs_mutex_unlock(&netdev->mutex);
937 return 0;
938}
939
f7791740
PS
940static struct netdev_rxq *
941netdev_dummy_rxq_alloc(void)
9dc63482 942{
f7791740 943 struct netdev_rxq_dummy *rx = xzalloc(sizeof *rx);
9dc63482
BP
944 return &rx->up;
945}
946
7b6b0ef4 947static int
f7791740 948netdev_dummy_rxq_construct(struct netdev_rxq *rxq_)
7b6b0ef4 949{
f7791740 950 struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
9dc63482 951 struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
796223f5 952
86383816 953 ovs_mutex_lock(&netdev->mutex);
417e7e66
BW
954 ovs_list_push_back(&netdev->rxes, &rx->node);
955 ovs_list_init(&rx->recv_queue);
e34cfdd9 956 rx->recv_queue_len = 0;
98045eda 957 rx->seq = seq_create();
86383816 958 ovs_mutex_unlock(&netdev->mutex);
796223f5 959
7b6b0ef4
BP
960 return 0;
961}
962
9dc63482 963static void
f7791740 964netdev_dummy_rxq_destruct(struct netdev_rxq *rxq_)
9dc63482 965{
f7791740 966 struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
86383816 967 struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
9dc63482 968
86383816 969 ovs_mutex_lock(&netdev->mutex);
417e7e66 970 ovs_list_remove(&rx->node);
8613db65 971 pkt_list_delete(&rx->recv_queue);
86383816 972 ovs_mutex_unlock(&netdev->mutex);
98045eda 973 seq_destroy(rx->seq);
9dc63482
BP
974}
975
976static void
f7791740 977netdev_dummy_rxq_dealloc(struct netdev_rxq *rxq_)
9dc63482 978{
f7791740 979 struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
9dc63482
BP
980
981 free(rx);
982}
983
7b6b0ef4 984static int
64839cf4 985netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet_batch *batch)
fbac791a 986{
f7791740 987 struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
86383816 988 struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
cf62fa4c 989 struct dp_packet *packet;
fbac791a 990
86383816 991 ovs_mutex_lock(&netdev->mutex);
417e7e66 992 if (!ovs_list_is_empty(&rx->recv_queue)) {
8613db65
DDP
993 struct pkt_list_node *pkt_node;
994
417e7e66 995 ASSIGN_CONTAINER(pkt_node, ovs_list_pop_front(&rx->recv_queue), list_node);
8613db65
DDP
996 packet = pkt_node->pkt;
997 free(pkt_node);
86383816
BP
998 rx->recv_queue_len--;
999 } else {
1000 packet = NULL;
1001 }
1002 ovs_mutex_unlock(&netdev->mutex);
1003
1004 if (!packet) {
f8cf6502
DDP
1005 if (netdev_is_pmd(&netdev->up)) {
1006 /* If 'netdev' is a PMD device, this is called as part of the PMD
1007 * thread busy loop. We yield here (without quiescing) for two
1008 * reasons:
1009 *
1010 * - To reduce the CPU utilization during the testsuite
1011 * - To give valgrind a chance to switch thread. According
1012 * to the valgrind documentation, there's a big lock that
1013 * prevents multiple thread from being executed at the same
1014 * time. On my system, without this sleep, the pmd threads
1015 * testcases fail under valgrind, because ovs-vswitchd becomes
1016 * unresponsive. */
1017 sched_yield();
1018 }
bfd3367b 1019 return EAGAIN;
fbac791a 1020 }
df1e5a3b
PS
1021 ovs_mutex_lock(&netdev->mutex);
1022 netdev->stats.rx_packets++;
cf62fa4c 1023 netdev->stats.rx_bytes += dp_packet_size(packet);
df1e5a3b 1024 ovs_mutex_unlock(&netdev->mutex);
fbac791a 1025
64839cf4
WT
1026 batch->packets[0] = packet;
1027 batch->count = 1;
df1e5a3b 1028 return 0;
fbac791a
BP
1029}
1030
1031static void
f7791740 1032netdev_dummy_rxq_wait(struct netdev_rxq *rxq_)
796223f5 1033{
f7791740 1034 struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
86383816 1035 struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
98045eda 1036 uint64_t seq = seq_read(rx->seq);
86383816
BP
1037
1038 ovs_mutex_lock(&netdev->mutex);
417e7e66 1039 if (!ovs_list_is_empty(&rx->recv_queue)) {
fbac791a 1040 poll_immediate_wake();
98045eda
BP
1041 } else {
1042 seq_wait(rx->seq, seq);
fbac791a 1043 }
86383816 1044 ovs_mutex_unlock(&netdev->mutex);
fbac791a
BP
1045}
1046
1047static int
f7791740 1048netdev_dummy_rxq_drain(struct netdev_rxq *rxq_)
fbac791a 1049{
f7791740 1050 struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
86383816
BP
1051 struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
1052
1053 ovs_mutex_lock(&netdev->mutex);
8613db65 1054 pkt_list_delete(&rx->recv_queue);
e34cfdd9 1055 rx->recv_queue_len = 0;
86383816
BP
1056 ovs_mutex_unlock(&netdev->mutex);
1057
98045eda
BP
1058 seq_change(rx->seq);
1059
fbac791a 1060 return 0;
7b6b0ef4
BP
1061}
1062
02d5bfe3 1063static int
f00fa8cb 1064netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
324c8374
IM
1065 struct dp_packet_batch *batch, bool may_steal,
1066 bool concurrent_txq OVS_UNUSED)
02d5bfe3 1067{
b5d57fc8 1068 struct netdev_dummy *dev = netdev_dummy_cast(netdev);
f4fd623c 1069 int error = 0;
eab5611a 1070
72c84bc2
AZ
1071 struct dp_packet *packet;
1072 DP_PACKET_BATCH_FOR_EACH(packet, batch) {
1073 const void *buffer = dp_packet_data(packet);
a61a2891 1074 size_t size = dp_packet_get_send_len(packet);
eab5611a 1075
2482b0b0
JS
1076 if (batch->packets[i]->packet_type != htonl(PT_ETH)) {
1077 error = EPFNOSUPPORT;
1078 break;
1079 }
1080
f4fd623c
DDP
1081 if (size < ETH_HEADER_LEN) {
1082 error = EMSGSIZE;
1083 break;
1084 } else {
1085 const struct eth_header *eth = buffer;
1086 int max_size;
36e2140d 1087
f4fd623c
DDP
1088 ovs_mutex_lock(&dev->mutex);
1089 max_size = dev->mtu + ETH_HEADER_LEN;
1090 ovs_mutex_unlock(&dev->mutex);
1091
1092 if (eth->eth_type == htons(ETH_TYPE_VLAN)) {
1093 max_size += VLAN_HEADER_LEN;
1094 }
1095 if (size > max_size) {
1096 error = EMSGSIZE;
1097 break;
1098 }
eab5611a 1099 }
02d5bfe3 1100
f4fd623c
DDP
1101 ovs_mutex_lock(&dev->mutex);
1102 dev->stats.tx_packets++;
1103 dev->stats.tx_bytes += size;
1104
1105 dummy_packet_conn_send(&dev->conn, buffer, size);
02d5bfe3 1106
bde96a9a
BP
1107 /* Reply to ARP requests for 'dev''s assigned IP address. */
1108 if (dev->address.s_addr) {
71f21279 1109 struct dp_packet dp;
bde96a9a
BP
1110 struct flow flow;
1111
71f21279
BP
1112 dp_packet_use_const(&dp, buffer, size);
1113 flow_extract(&dp, &flow);
bde96a9a
BP
1114 if (flow.dl_type == htons(ETH_TYPE_ARP)
1115 && flow.nw_proto == ARP_OP_REQUEST
1116 && flow.nw_dst == dev->address.s_addr) {
1117 struct dp_packet *reply = dp_packet_new(0);
1118 compose_arp(reply, ARP_OP_REPLY, dev->hwaddr, flow.dl_src,
1119 false, flow.nw_dst, flow.nw_src);
9a81a637 1120 netdev_dummy_queue_packet(dev, reply, 0);
bde96a9a
BP
1121 }
1122 }
1123
f4fd623c 1124 if (dev->tx_pcap) {
71f21279 1125 struct dp_packet dp;
631486bd 1126
71f21279
BP
1127 dp_packet_use_const(&dp, buffer, size);
1128 ovs_pcap_write(dev->tx_pcap, &dp);
f4fd623c
DDP
1129 fflush(dev->tx_pcap);
1130 }
55d87b06 1131
f4fd623c 1132 ovs_mutex_unlock(&dev->mutex);
55d87b06
BP
1133 }
1134
64839cf4 1135 dp_packet_delete_batch(batch, may_steal);
eab5611a 1136
f4fd623c 1137 return error;
02d5bfe3
BP
1138}
1139
614c4892 1140static int
74ff3298 1141netdev_dummy_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
614c4892 1142{
b5d57fc8 1143 struct netdev_dummy *dev = netdev_dummy_cast(netdev);
614c4892 1144
86383816 1145 ovs_mutex_lock(&dev->mutex);
614c4892 1146 if (!eth_addr_equals(dev->hwaddr, mac)) {
74ff3298 1147 dev->hwaddr = mac;
3e912ffc 1148 netdev_change_seq_changed(netdev);
614c4892 1149 }
86383816 1150 ovs_mutex_unlock(&dev->mutex);
614c4892
BP
1151
1152 return 0;
1153}
1154
1155static int
74ff3298 1156netdev_dummy_get_etheraddr(const struct netdev *netdev, struct eth_addr *mac)
614c4892 1157{
86383816 1158 struct netdev_dummy *dev = netdev_dummy_cast(netdev);
614c4892 1159
86383816 1160 ovs_mutex_lock(&dev->mutex);
74ff3298 1161 *mac = dev->hwaddr;
86383816
BP
1162 ovs_mutex_unlock(&dev->mutex);
1163
614c4892
BP
1164 return 0;
1165}
1166
1167static int
1168netdev_dummy_get_mtu(const struct netdev *netdev, int *mtup)
1169{
86383816 1170 struct netdev_dummy *dev = netdev_dummy_cast(netdev);
614c4892 1171
86383816 1172 ovs_mutex_lock(&dev->mutex);
614c4892 1173 *mtup = dev->mtu;
86383816
BP
1174 ovs_mutex_unlock(&dev->mutex);
1175
614c4892
BP
1176 return 0;
1177}
1178
56edfb18 1179#define DUMMY_MIN_MTU 68
1180#define DUMMY_MAX_MTU 65535
1181
9b020780 1182static int
4124cb12 1183netdev_dummy_set_mtu(struct netdev *netdev, int mtu)
9b020780 1184{
56edfb18 1185 if (mtu < DUMMY_MIN_MTU || mtu > DUMMY_MAX_MTU) {
1186 return EINVAL;
1187 }
1188
b5d57fc8 1189 struct netdev_dummy *dev = netdev_dummy_cast(netdev);
9b020780 1190
86383816 1191 ovs_mutex_lock(&dev->mutex);
ae59d134
DDP
1192 if (dev->mtu != mtu) {
1193 dev->mtu = mtu;
1194 netdev_change_seq_changed(netdev);
1195 }
86383816
BP
1196 ovs_mutex_unlock(&dev->mutex);
1197
9b020780
PS
1198 return 0;
1199}
1200
614c4892
BP
1201static int
1202netdev_dummy_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
1203{
86383816 1204 struct netdev_dummy *dev = netdev_dummy_cast(netdev);
614c4892 1205
86383816 1206 ovs_mutex_lock(&dev->mutex);
d6e3feb5 1207 /* Passing only collected counters */
1208 stats->tx_packets = dev->stats.tx_packets;
1209 stats->tx_bytes = dev->stats.tx_bytes;
1210 stats->rx_packets = dev->stats.rx_packets;
1211 stats->rx_bytes = dev->stats.rx_bytes;
86383816
BP
1212 ovs_mutex_unlock(&dev->mutex);
1213
614c4892
BP
1214 return 0;
1215}
1216
f72dff1a
BP
1217static int
1218netdev_dummy_get_queue(const struct netdev *netdev OVS_UNUSED,
1219 unsigned int queue_id, struct smap *details OVS_UNUSED)
1220{
1221 if (queue_id == 0) {
1222 return 0;
1223 } else {
1224 return EINVAL;
1225 }
1226}
1227
1228static void
1229netdev_dummy_init_queue_stats(struct netdev_queue_stats *stats)
1230{
1231 *stats = (struct netdev_queue_stats) {
1232 .tx_bytes = UINT64_MAX,
1233 .tx_packets = UINT64_MAX,
1234 .tx_errors = UINT64_MAX,
1235 .created = LLONG_MIN,
1236 };
1237}
1238
1239static int
1240netdev_dummy_get_queue_stats(const struct netdev *netdev OVS_UNUSED,
1241 unsigned int queue_id,
1242 struct netdev_queue_stats *stats)
1243{
1244 if (queue_id == 0) {
1245 netdev_dummy_init_queue_stats(stats);
1246 return 0;
1247 } else {
1248 return EINVAL;
1249 }
1250}
1251
1252struct netdev_dummy_queue_state {
1253 unsigned int next_queue;
1254};
1255
1256static int
1257netdev_dummy_queue_dump_start(const struct netdev *netdev OVS_UNUSED,
1258 void **statep)
1259{
1260 struct netdev_dummy_queue_state *state = xmalloc(sizeof *state);
1261 state->next_queue = 0;
1262 *statep = state;
1263 return 0;
1264}
1265
1266static int
1267netdev_dummy_queue_dump_next(const struct netdev *netdev OVS_UNUSED,
1268 void *state_,
1269 unsigned int *queue_id,
1270 struct smap *details OVS_UNUSED)
1271{
1272 struct netdev_dummy_queue_state *state = state_;
1273 if (state->next_queue == 0) {
1274 *queue_id = 0;
1275 state->next_queue++;
1276 return 0;
1277 } else {
1278 return EOF;
1279 }
1280}
1281
1282static int
1283netdev_dummy_queue_dump_done(const struct netdev *netdev OVS_UNUSED,
1284 void *state)
1285{
1286 free(state);
1287 return 0;
1288}
1289
1290static int
1291netdev_dummy_dump_queue_stats(const struct netdev *netdev OVS_UNUSED,
1292 void (*cb)(unsigned int queue_id,
1293 struct netdev_queue_stats *,
1294 void *aux),
1295 void *aux)
1296{
1297 struct netdev_queue_stats stats;
1298 netdev_dummy_init_queue_stats(&stats);
1299 cb(0, &stats, aux);
1300 return 0;
1301}
1302
8073dd31
NM
1303static int
1304netdev_dummy_get_ifindex(const struct netdev *netdev)
1305{
b5d57fc8 1306 struct netdev_dummy *dev = netdev_dummy_cast(netdev);
86383816
BP
1307 int ifindex;
1308
1309 ovs_mutex_lock(&dev->mutex);
1310 ifindex = dev->ifindex;
1311 ovs_mutex_unlock(&dev->mutex);
8073dd31 1312
86383816 1313 return ifindex;
8073dd31
NM
1314}
1315
614c4892 1316static int
86383816
BP
1317netdev_dummy_update_flags__(struct netdev_dummy *netdev,
1318 enum netdev_flags off, enum netdev_flags on,
1319 enum netdev_flags *old_flagsp)
1320 OVS_REQUIRES(netdev->mutex)
614c4892 1321{
614c4892
BP
1322 if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
1323 return EINVAL;
1324 }
1325
b5d57fc8
BP
1326 *old_flagsp = netdev->flags;
1327 netdev->flags |= on;
1328 netdev->flags &= ~off;
1329 if (*old_flagsp != netdev->flags) {
3e912ffc 1330 netdev_change_seq_changed(&netdev->up);
614c4892 1331 }
86383816 1332
614c4892
BP
1333 return 0;
1334}
1335
86383816
BP
1336static int
1337netdev_dummy_update_flags(struct netdev *netdev_,
1338 enum netdev_flags off, enum netdev_flags on,
1339 enum netdev_flags *old_flagsp)
1340{
1341 struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
1342 int error;
1343
1344 ovs_mutex_lock(&netdev->mutex);
1345 error = netdev_dummy_update_flags__(netdev, off, on, old_flagsp);
1346 ovs_mutex_unlock(&netdev->mutex);
1347
1348 return error;
1349}
614c4892
BP
1350\f
1351/* Helper functions. */
1352
d66e4a5e 1353#define NETDEV_DUMMY_CLASS(NAME, PMD, RECOFIGURE) \
f9176a3a
IM
1354{ \
1355 NAME, \
1356 PMD, /* is_pmd */ \
1357 NULL, /* init */ \
1358 netdev_dummy_run, \
1359 netdev_dummy_wait, \
1360 \
1361 netdev_dummy_alloc, \
1362 netdev_dummy_construct, \
1363 netdev_dummy_destruct, \
1364 netdev_dummy_dealloc, \
1365 netdev_dummy_get_config, \
1366 netdev_dummy_set_config, \
1367 NULL, /* get_tunnel_config */ \
1368 NULL, /* build header */ \
1369 NULL, /* push header */ \
1370 NULL, /* pop header */ \
1371 netdev_dummy_get_numa_id, \
d66e4a5e 1372 NULL, /* set_tx_multiq */ \
f9176a3a
IM
1373 \
1374 netdev_dummy_send, /* send */ \
1375 NULL, /* send_wait */ \
1376 \
1377 netdev_dummy_set_etheraddr, \
1378 netdev_dummy_get_etheraddr, \
1379 netdev_dummy_get_mtu, \
1380 netdev_dummy_set_mtu, \
1381 netdev_dummy_get_ifindex, \
1382 NULL, /* get_carrier */ \
1383 NULL, /* get_carrier_resets */ \
1384 NULL, /* get_miimon */ \
1385 netdev_dummy_get_stats, \
1386 \
1387 NULL, /* get_features */ \
1388 NULL, /* set_advertisements */ \
875ab130 1389 NULL, /* get_pt_mode */ \
f9176a3a
IM
1390 \
1391 NULL, /* set_policing */ \
1392 NULL, /* get_qos_types */ \
1393 NULL, /* get_qos_capabilities */ \
1394 NULL, /* get_qos */ \
1395 NULL, /* set_qos */ \
1396 netdev_dummy_get_queue, \
1397 NULL, /* set_queue */ \
1398 NULL, /* delete_queue */ \
1399 netdev_dummy_get_queue_stats, \
1400 netdev_dummy_queue_dump_start, \
1401 netdev_dummy_queue_dump_next, \
1402 netdev_dummy_queue_dump_done, \
1403 netdev_dummy_dump_queue_stats, \
1404 \
1405 NULL, /* set_in4 */ \
1406 netdev_dummy_get_addr_list, \
1407 NULL, /* add_router */ \
1408 NULL, /* get_next_hop */ \
1409 NULL, /* get_status */ \
1410 NULL, /* arp_lookup */ \
1411 \
1412 netdev_dummy_update_flags, \
9a81a637 1413 RECOFIGURE, \
f9176a3a
IM
1414 \
1415 netdev_dummy_rxq_alloc, \
1416 netdev_dummy_rxq_construct, \
1417 netdev_dummy_rxq_destruct, \
1418 netdev_dummy_rxq_dealloc, \
1419 netdev_dummy_rxq_recv, \
1420 netdev_dummy_rxq_wait, \
1421 netdev_dummy_rxq_drain, \
18ebd48c
PB
1422 \
1423 NO_OFFLOAD_API \
f9176a3a
IM
1424}
1425
1426static const struct netdev_class dummy_class =
d66e4a5e 1427 NETDEV_DUMMY_CLASS("dummy", false, NULL);
9a81a637 1428
e98d0cb3
DDP
1429static const struct netdev_class dummy_internal_class =
1430 NETDEV_DUMMY_CLASS("dummy-internal", false, NULL);
1431
f9176a3a 1432static const struct netdev_class dummy_pmd_class =
9a81a637 1433 NETDEV_DUMMY_CLASS("dummy-pmd", true,
9a81a637 1434 netdev_dummy_reconfigure);
796223f5 1435
8613db65
DDP
1436static void
1437pkt_list_delete(struct ovs_list *l)
1438{
1439 struct pkt_list_node *pkt;
1440
1441 LIST_FOR_EACH_POP(pkt, list_node, l) {
1442 dp_packet_delete(pkt->pkt);
1443 free(pkt);
1444 }
1445}
1446
cf62fa4c 1447static struct dp_packet *
d8ada236
AZ
1448eth_from_packet(const char *s)
1449{
1450 struct dp_packet *packet;
1451 eth_from_hex(s, &packet);
1452 return packet;
1453}
1454
1455static struct dp_packet *
1e2eecbb 1456eth_from_flow(const char *s, size_t packet_size)
fbac791a
BP
1457{
1458 enum odp_key_fitness fitness;
cf62fa4c 1459 struct dp_packet *packet;
fbac791a
BP
1460 struct ofpbuf odp_key;
1461 struct flow flow;
1462 int error;
1463
fbac791a
BP
1464 /* Convert string to datapath key.
1465 *
1466 * It would actually be nicer to parse an OpenFlow-like flow key here, but
1467 * the code for that currently calls exit() on parse error. We have to
1468 * settle for parsing a datapath key for now.
1469 */
1470 ofpbuf_init(&odp_key, 0);
e6cc0bab 1471 error = odp_flow_from_string(s, NULL, &odp_key, NULL);
fbac791a
BP
1472 if (error) {
1473 ofpbuf_uninit(&odp_key);
1474 return NULL;
1475 }
1476
1477 /* Convert odp_key to flow. */
6fd6ed71 1478 fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
fbac791a
BP
1479 if (fitness == ODP_FIT_ERROR) {
1480 ofpbuf_uninit(&odp_key);
1481 return NULL;
1482 }
1483
cf62fa4c 1484 packet = dp_packet_new(0);
bc0f5176
AZ
1485 if (!flow_compose(packet, &flow, packet_size)) {
1486 dp_packet_delete(packet);
1487 packet = NULL;
1488 };
fbac791a
BP
1489
1490 ofpbuf_uninit(&odp_key);
1491 return packet;
1492}
1493
323cc924 1494static void
cf62fa4c 1495netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct dp_packet *packet)
2273ea5a 1496{
8613db65
DDP
1497 struct pkt_list_node *pkt_node = xmalloc(sizeof *pkt_node);
1498
1499 pkt_node->pkt = packet;
417e7e66 1500 ovs_list_push_back(&rx->recv_queue, &pkt_node->list_node);
eab5611a 1501 rx->recv_queue_len++;
98045eda 1502 seq_change(rx->seq);
eab5611a 1503}
2273ea5a 1504
eab5611a 1505static void
9a81a637
IM
1506netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct dp_packet *packet,
1507 int queue_id)
55d87b06 1508 OVS_REQUIRES(dummy->mutex)
eab5611a 1509{
f7791740 1510 struct netdev_rxq_dummy *rx, *prev;
eab5611a 1511
f7791740
PS
1512 if (dummy->rxq_pcap) {
1513 ovs_pcap_write(dummy->rxq_pcap, packet);
1514 fflush(dummy->rxq_pcap);
55d87b06 1515 }
eab5611a 1516 prev = NULL;
2273ea5a 1517 LIST_FOR_EACH (rx, node, &dummy->rxes) {
9a81a637
IM
1518 if (rx->up.queue_id == queue_id &&
1519 rx->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
eab5611a 1520 if (prev) {
cf62fa4c 1521 netdev_dummy_queue_packet__(prev, dp_packet_clone(packet));
eab5611a
BP
1522 }
1523 prev = rx;
2273ea5a
BP
1524 }
1525 }
eab5611a
BP
1526 if (prev) {
1527 netdev_dummy_queue_packet__(prev, packet);
1528 } else {
cf62fa4c 1529 dp_packet_delete(packet);
eab5611a 1530 }
2273ea5a
BP
1531}
1532
fbac791a
BP
1533static void
1534netdev_dummy_receive(struct unixctl_conn *conn,
1535 int argc, const char *argv[], void *aux OVS_UNUSED)
1536{
b5d57fc8 1537 struct netdev_dummy *dummy_dev;
86f1d032 1538 struct netdev *netdev;
9a81a637 1539 int i, k = 1, rx_qid = 0;
fbac791a 1540
9a81a637 1541 netdev = netdev_from_name(argv[k++]);
86f1d032 1542 if (!netdev || !is_dummy_class(netdev->netdev_class)) {
bde9f75d 1543 unixctl_command_reply_error(conn, "no such dummy netdev");
9a81a637 1544 goto exit_netdev;
fbac791a 1545 }
86f1d032 1546 dummy_dev = netdev_dummy_cast(netdev);
fbac791a 1547
9a81a637
IM
1548 ovs_mutex_lock(&dummy_dev->mutex);
1549
1550 if (argc > k + 1 && !strcmp(argv[k], "--qid")) {
1551 rx_qid = strtol(argv[k + 1], NULL, 10);
1552 if (rx_qid < 0 || rx_qid >= netdev->n_rxq) {
1553 unixctl_command_reply_error(conn, "bad rx queue id.");
1554 goto exit;
1555 }
1556 k += 2;
1557 }
1558
1559 for (i = k; i < argc; i++) {
cf62fa4c 1560 struct dp_packet *packet;
fbac791a 1561
d8ada236
AZ
1562 /* Try to parse 'argv[i]' as packet in hex. */
1563 packet = eth_from_packet(argv[i]);
1564
fbac791a 1565 if (!packet) {
1e2eecbb
IM
1566 int packet_size = 0;
1567 const char *flow_str = argv[i];
1568
1569 /* Parse optional --len argument immediately follows a 'flow'. */
1570 if (argc >= i + 2 && !strcmp(argv[i + 1], "--len")) {
1571 packet_size = strtol(argv[i + 2], NULL, 10);
1572
1573 if (packet_size < ETH_TOTAL_MIN) {
1574 unixctl_command_reply_error(conn, "too small packet len");
1575 goto exit;
1576 }
df3a6d50 1577 i += 2;
1e2eecbb 1578 }
d8ada236 1579 /* Try parse 'argv[i]' as odp flow. */
1e2eecbb 1580 packet = eth_from_flow(flow_str, packet_size);
d8ada236
AZ
1581
1582 if (!packet) {
1583 unixctl_command_reply_error(conn, "bad packet or flow syntax");
1584 goto exit;
1585 }
fbac791a
BP
1586 }
1587
9a81a637 1588 netdev_dummy_queue_packet(dummy_dev, packet, rx_qid);
fbac791a
BP
1589 }
1590
323cc924 1591 unixctl_command_reply(conn, NULL);
86f1d032
BP
1592
1593exit:
9a81a637
IM
1594 ovs_mutex_unlock(&dummy_dev->mutex);
1595exit_netdev:
86f1d032 1596 netdev_close(netdev);
fbac791a
BP
1597}
1598
95d4ec33 1599static void
b5d57fc8 1600netdev_dummy_set_admin_state__(struct netdev_dummy *dev, bool admin_state)
86383816 1601 OVS_REQUIRES(dev->mutex)
95d4ec33
EJ
1602{
1603 enum netdev_flags old_flags;
1604
1605 if (admin_state) {
86383816 1606 netdev_dummy_update_flags__(dev, 0, NETDEV_UP, &old_flags);
95d4ec33 1607 } else {
86383816 1608 netdev_dummy_update_flags__(dev, NETDEV_UP, 0, &old_flags);
95d4ec33
EJ
1609 }
1610}
1611
1612static void
1613netdev_dummy_set_admin_state(struct unixctl_conn *conn, int argc,
1614 const char *argv[], void *aux OVS_UNUSED)
1615{
1616 bool up;
1617
1618 if (!strcasecmp(argv[argc - 1], "up")) {
1619 up = true;
1620 } else if ( !strcasecmp(argv[argc - 1], "down")) {
1621 up = false;
1622 } else {
1623 unixctl_command_reply_error(conn, "Invalid Admin State");
1624 return;
1625 }
1626
1627 if (argc > 2) {
86f1d032
BP
1628 struct netdev *netdev = netdev_from_name(argv[1]);
1629 if (netdev && is_dummy_class(netdev->netdev_class)) {
1630 struct netdev_dummy *dummy_dev = netdev_dummy_cast(netdev);
95d4ec33 1631
86383816 1632 ovs_mutex_lock(&dummy_dev->mutex);
b5d57fc8 1633 netdev_dummy_set_admin_state__(dummy_dev, up);
86383816
BP
1634 ovs_mutex_unlock(&dummy_dev->mutex);
1635
86f1d032 1636 netdev_close(netdev);
95d4ec33
EJ
1637 } else {
1638 unixctl_command_reply_error(conn, "Unknown Dummy Interface");
86f1d032 1639 netdev_close(netdev);
95d4ec33
EJ
1640 return;
1641 }
1642 } else {
5e1de67f 1643 struct netdev_dummy *netdev;
86383816 1644
5e1de67f
BP
1645 ovs_mutex_lock(&dummy_list_mutex);
1646 LIST_FOR_EACH (netdev, list_node, &dummy_list) {
86383816
BP
1647 ovs_mutex_lock(&netdev->mutex);
1648 netdev_dummy_set_admin_state__(netdev, up);
1649 ovs_mutex_unlock(&netdev->mutex);
95d4ec33 1650 }
5e1de67f 1651 ovs_mutex_unlock(&dummy_list_mutex);
95d4ec33
EJ
1652 }
1653 unixctl_command_reply(conn, "OK");
1654}
1655
7d7fffe8
AZ
1656static void
1657display_conn_state__(struct ds *s, const char *name,
1658 enum dummy_netdev_conn_state state)
1659{
1660 ds_put_format(s, "%s: ", name);
1661
1662 switch (state) {
1663 case CONN_STATE_CONNECTED:
1664 ds_put_cstr(s, "connected\n");
1665 break;
1666
1667 case CONN_STATE_NOT_CONNECTED:
1668 ds_put_cstr(s, "disconnected\n");
1669 break;
1670
1671 case CONN_STATE_UNKNOWN:
1672 default:
1673 ds_put_cstr(s, "unknown\n");
1674 break;
1675 };
1676}
1677
1678static void
1679netdev_dummy_conn_state(struct unixctl_conn *conn, int argc,
1680 const char *argv[], void *aux OVS_UNUSED)
1681{
1682 enum dummy_netdev_conn_state state = CONN_STATE_UNKNOWN;
1683 struct ds s;
1684
1685 ds_init(&s);
1686
1687 if (argc > 1) {
1688 const char *dev_name = argv[1];
1689 struct netdev *netdev = netdev_from_name(dev_name);
1690
1691 if (netdev && is_dummy_class(netdev->netdev_class)) {
1692 struct netdev_dummy *dummy_dev = netdev_dummy_cast(netdev);
1693
1694 ovs_mutex_lock(&dummy_dev->mutex);
1695 state = dummy_netdev_get_conn_state(&dummy_dev->conn);
1696 ovs_mutex_unlock(&dummy_dev->mutex);
1697
1698 netdev_close(netdev);
1699 }
1700 display_conn_state__(&s, dev_name, state);
1701 } else {
1702 struct netdev_dummy *netdev;
1703
1704 ovs_mutex_lock(&dummy_list_mutex);
1705 LIST_FOR_EACH (netdev, list_node, &dummy_list) {
1706 ovs_mutex_lock(&netdev->mutex);
1707 state = dummy_netdev_get_conn_state(&netdev->conn);
1708 ovs_mutex_unlock(&netdev->mutex);
1709 if (state != CONN_STATE_UNKNOWN) {
1710 display_conn_state__(&s, netdev->up.name, state);
1711 }
1712 }
1713 ovs_mutex_unlock(&dummy_list_mutex);
1714 }
1715
1716 unixctl_command_reply(conn, ds_cstr(&s));
1717 ds_destroy(&s);
1718}
1719
a36de779
PS
1720static void
1721netdev_dummy_ip4addr(struct unixctl_conn *conn, int argc OVS_UNUSED,
1722 const char *argv[], void *aux OVS_UNUSED)
1723{
1724 struct netdev *netdev = netdev_from_name(argv[1]);
1725
1726 if (netdev && is_dummy_class(netdev->netdev_class)) {
e7695092
BP
1727 struct in_addr ip, mask;
1728 char *error;
a36de779 1729
e7695092
BP
1730 error = ip_parse_masked(argv[2], &ip.s_addr, &mask.s_addr);
1731 if (!error) {
a36de779
PS
1732 netdev_dummy_set_in4(netdev, ip, mask);
1733 unixctl_command_reply(conn, "OK");
1734 } else {
e7695092
BP
1735 unixctl_command_reply_error(conn, error);
1736 free(error);
a36de779 1737 }
2af602f2
TLSC
1738 } else {
1739 unixctl_command_reply_error(conn, "Unknown Dummy Interface");
1740 }
1741
1742 netdev_close(netdev);
1743}
1744
1745static void
1746netdev_dummy_ip6addr(struct unixctl_conn *conn, int argc OVS_UNUSED,
1747 const char *argv[], void *aux OVS_UNUSED)
1748{
1749 struct netdev *netdev = netdev_from_name(argv[1]);
a36de779 1750
2af602f2 1751 if (netdev && is_dummy_class(netdev->netdev_class)) {
2af602f2 1752 struct in6_addr ip6;
a8704b50
PS
1753 char *error;
1754 uint32_t plen;
2af602f2 1755
a8704b50
PS
1756 error = ipv6_parse_cidr(argv[2], &ip6, &plen);
1757 if (!error) {
1758 struct in6_addr mask;
1759
1760 mask = ipv6_create_mask(plen);
1761 netdev_dummy_set_in6(netdev, &ip6, &mask);
2af602f2
TLSC
1762 unixctl_command_reply(conn, "OK");
1763 } else {
a8704b50
PS
1764 unixctl_command_reply_error(conn, error);
1765 free(error);
2af602f2 1766 }
a36de779
PS
1767 } else {
1768 unixctl_command_reply_error(conn, "Unknown Dummy Interface");
a36de779
PS
1769 }
1770
2af602f2 1771 netdev_close(netdev);
a36de779
PS
1772}
1773
2af602f2 1774
8420c7ad
BP
1775static void
1776netdev_dummy_override(const char *type)
1777{
1778 if (!netdev_unregister_provider(type)) {
1779 struct netdev_class *class;
1780 int error;
1781
1782 class = xmemdup(&dummy_class, sizeof dummy_class);
1783 class->type = xstrdup(type);
1784 error = netdev_register_provider(class);
1785 if (error) {
1786 VLOG_ERR("%s: failed to register netdev provider (%s)",
1787 type, ovs_strerror(error));
1788 free(CONST_CAST(char *, class->type));
1789 free(class);
1790 }
1791 }
1792}
1793
614c4892 1794void
8420c7ad 1795netdev_dummy_register(enum dummy_level level)
614c4892 1796{
9a81a637 1797 unixctl_command_register("netdev-dummy/receive",
d8ada236 1798 "name [--qid queue_id] packet|flow [--len packet_len]",
fbac791a 1799 2, INT_MAX, netdev_dummy_receive, NULL);
95d4ec33
EJ
1800 unixctl_command_register("netdev-dummy/set-admin-state",
1801 "[netdev] up|down", 1, 2,
1802 netdev_dummy_set_admin_state, NULL);
7d7fffe8
AZ
1803 unixctl_command_register("netdev-dummy/conn-state",
1804 "[netdev]", 0, 1,
1805 netdev_dummy_conn_state, NULL);
a36de779
PS
1806 unixctl_command_register("netdev-dummy/ip4addr",
1807 "[netdev] ipaddr/mask-prefix-len", 2, 2,
1808 netdev_dummy_ip4addr, NULL);
2af602f2
TLSC
1809 unixctl_command_register("netdev-dummy/ip6addr",
1810 "[netdev] ip6addr", 2, 2,
1811 netdev_dummy_ip6addr, NULL);
a36de779 1812
8420c7ad 1813 if (level == DUMMY_OVERRIDE_ALL) {
0cbfe35d
BP
1814 struct sset types;
1815 const char *type;
1816
1817 sset_init(&types);
1818 netdev_enumerate_types(&types);
1819 SSET_FOR_EACH (type, &types) {
8420c7ad
BP
1820 if (strcmp(type, "patch")) {
1821 netdev_dummy_override(type);
0cbfe35d
BP
1822 }
1823 }
1824 sset_destroy(&types);
8420c7ad
BP
1825 } else if (level == DUMMY_OVERRIDE_SYSTEM) {
1826 netdev_dummy_override("system");
0cbfe35d
BP
1827 }
1828 netdev_register_provider(&dummy_class);
e98d0cb3 1829 netdev_register_provider(&dummy_internal_class);
f9176a3a 1830 netdev_register_provider(&dummy_pmd_class);
c060c4cf 1831
7c54c27f 1832 netdev_vport_tunnel_register();
614c4892 1833}