82473a177dc94e8aea0781df8e83998dcabd4ee5
[sliver-openvswitch.git] / lib / netdev-dummy.c
1 /*
2  * Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
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>
22
23 #include "flow.h"
24 #include "list.h"
25 #include "netdev-provider.h"
26 #include "netdev-vport.h"
27 #include "odp-util.h"
28 #include "ofp-print.h"
29 #include "ofpbuf.h"
30 #include "packets.h"
31 #include "poll-loop.h"
32 #include "shash.h"
33 #include "sset.h"
34 #include "stream.h"
35 #include "unaligned.h"
36 #include "unixctl.h"
37 #include "vlog.h"
38
39 VLOG_DEFINE_THIS_MODULE(netdev_dummy);
40
41 struct dummy_stream {
42     struct stream *stream;
43     struct ofpbuf rxbuf;
44     struct list txq;
45 };
46
47 struct netdev_dummy {
48     struct netdev up;
49     uint8_t hwaddr[ETH_ADDR_LEN];
50     int mtu;
51     struct netdev_stats stats;
52     enum netdev_flags flags;
53     unsigned int change_seq;
54     int ifindex;
55
56     struct pstream *pstream;
57     struct dummy_stream *streams;
58     size_t n_streams;
59
60     struct list rxes;           /* List of child "netdev_rx_dummy"s. */
61 };
62
63 /* Max 'recv_queue_len' in struct netdev_dummy. */
64 #define NETDEV_DUMMY_MAX_QUEUE 100
65
66 struct netdev_rx_dummy {
67     struct netdev_rx up;
68     struct list node;           /* In netdev_dummy's "rxes" list. */
69     struct list recv_queue;
70     int recv_queue_len;         /* list_size(&recv_queue). */
71     bool listening;
72 };
73
74 static struct shash dummy_netdevs = SHASH_INITIALIZER(&dummy_netdevs);
75
76 static const struct netdev_rx_class netdev_rx_dummy_class;
77
78 static unixctl_cb_func netdev_dummy_set_admin_state;
79 static int netdev_dummy_create(const struct netdev_class *, const char *,
80                                struct netdev **);
81 static void netdev_dummy_poll_notify(struct netdev_dummy *);
82 static void netdev_dummy_queue_packet(struct netdev_dummy *, struct ofpbuf *);
83
84 static void dummy_stream_close(struct dummy_stream *);
85
86 static bool
87 is_dummy_class(const struct netdev_class *class)
88 {
89     return class->create == netdev_dummy_create;
90 }
91
92 static struct netdev_dummy *
93 netdev_dummy_cast(const struct netdev *netdev)
94 {
95     ovs_assert(is_dummy_class(netdev_get_class(netdev)));
96     return CONTAINER_OF(netdev, struct netdev_dummy, up);
97 }
98
99 static struct netdev_rx_dummy *
100 netdev_rx_dummy_cast(const struct netdev_rx *rx)
101 {
102     netdev_rx_assert_class(rx, &netdev_rx_dummy_class);
103     return CONTAINER_OF(rx, struct netdev_rx_dummy, up);
104 }
105
106 static void
107 netdev_dummy_run(void)
108 {
109     struct shash_node *node;
110
111     SHASH_FOR_EACH (node, &dummy_netdevs) {
112         struct netdev_dummy *dev = node->data;
113         size_t i;
114
115         if (dev->pstream) {
116             struct stream *new_stream;
117             int error;
118
119             error = pstream_accept(dev->pstream, &new_stream);
120             if (!error) {
121                 struct dummy_stream *s;
122
123                 dev->streams = xrealloc(dev->streams,
124                                         ((dev->n_streams + 1)
125                                          * sizeof *dev->streams));
126                 s = &dev->streams[dev->n_streams++];
127                 s->stream = new_stream;
128                 ofpbuf_init(&s->rxbuf, 2048);
129                 list_init(&s->txq);
130             } else if (error != EAGAIN) {
131                 VLOG_WARN("%s: accept failed (%s)",
132                           pstream_get_name(dev->pstream), ovs_strerror(error));
133                 pstream_close(dev->pstream);
134                 dev->pstream = NULL;
135             }
136         }
137
138         for (i = 0; i < dev->n_streams; i++) {
139             struct dummy_stream *s = &dev->streams[i];
140             int error = 0;
141             size_t n;
142
143             stream_run(s->stream);
144
145             if (!list_is_empty(&s->txq)) {
146                 struct ofpbuf *txbuf;
147                 int retval;
148
149                 txbuf = ofpbuf_from_list(list_front(&s->txq));
150                 retval = stream_send(s->stream, txbuf->data, txbuf->size);
151                 if (retval > 0) {
152                     ofpbuf_pull(txbuf, retval);
153                     if (!txbuf->size) {
154                         list_remove(&txbuf->list_node);
155                         ofpbuf_delete(txbuf);
156                     }
157                 } else if (retval != -EAGAIN) {
158                     error = -retval;
159                 }
160             }
161
162             if (!error) {
163                 if (s->rxbuf.size < 2) {
164                     n = 2 - s->rxbuf.size;
165                 } else {
166                     uint16_t frame_len;
167
168                     frame_len = ntohs(get_unaligned_be16(s->rxbuf.data));
169                     if (frame_len < ETH_HEADER_LEN) {
170                         error = EPROTO;
171                         n = 0;
172                     } else {
173                         n = (2 + frame_len) - s->rxbuf.size;
174                     }
175                 }
176             }
177             if (!error) {
178                 int retval;
179
180                 ofpbuf_prealloc_tailroom(&s->rxbuf, n);
181                 retval = stream_recv(s->stream, ofpbuf_tail(&s->rxbuf), n);
182                 if (retval > 0) {
183                     s->rxbuf.size += retval;
184                     if (retval == n && s->rxbuf.size > 2) {
185                         ofpbuf_pull(&s->rxbuf, 2);
186                         netdev_dummy_queue_packet(dev,
187                                                   ofpbuf_clone(&s->rxbuf));
188                         ofpbuf_clear(&s->rxbuf);
189                     }
190                 } else if (retval != -EAGAIN) {
191                     error = (retval < 0 ? -retval
192                              : s->rxbuf.size ? EPROTO
193                              : EOF);
194                 }
195             }
196
197             if (error) {
198                 VLOG_DBG("%s: closing connection (%s)",
199                          stream_get_name(s->stream),
200                          ovs_retval_to_string(error));
201                 dummy_stream_close(&dev->streams[i]);
202                 dev->streams[i] = dev->streams[--dev->n_streams];
203             }
204         }
205     }
206 }
207
208 static void
209 dummy_stream_close(struct dummy_stream *s)
210 {
211     stream_close(s->stream);
212     ofpbuf_uninit(&s->rxbuf);
213     ofpbuf_list_delete(&s->txq);
214 }
215
216 static void
217 netdev_dummy_wait(void)
218 {
219     struct shash_node *node;
220
221     SHASH_FOR_EACH (node, &dummy_netdevs) {
222         struct netdev_dummy *dev = node->data;
223         size_t i;
224
225         if (dev->pstream) {
226             pstream_wait(dev->pstream);
227         }
228         for (i = 0; i < dev->n_streams; i++) {
229             struct dummy_stream *s = &dev->streams[i];
230
231             stream_run_wait(s->stream);
232             if (!list_is_empty(&s->txq)) {
233                 stream_send_wait(s->stream);
234             }
235             stream_recv_wait(s->stream);
236         }
237     }
238 }
239
240 static int
241 netdev_dummy_create(const struct netdev_class *class, const char *name,
242                     struct netdev **netdevp)
243 {
244     static unsigned int next_n = 0xaa550000;
245     static pthread_mutex_t mutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER;
246
247     struct netdev_dummy *netdev;
248     unsigned int n;
249
250     xpthread_mutex_lock(&mutex);
251     n = next_n++;
252     xpthread_mutex_unlock(&mutex);
253
254     netdev = xzalloc(sizeof *netdev);
255     netdev_init(&netdev->up, name, class);
256     netdev->hwaddr[0] = 0xaa;
257     netdev->hwaddr[1] = 0x55;
258     netdev->hwaddr[2] = n >> 24;
259     netdev->hwaddr[3] = n >> 16;
260     netdev->hwaddr[4] = n >> 8;
261     netdev->hwaddr[5] = n;
262     netdev->mtu = 1500;
263     netdev->flags = 0;
264     netdev->change_seq = 1;
265     netdev->ifindex = -EOPNOTSUPP;
266
267     netdev->pstream = NULL;
268     netdev->streams = NULL;
269     netdev->n_streams = 0;
270
271     list_init(&netdev->rxes);
272
273     shash_add(&dummy_netdevs, name, netdev);
274
275     *netdevp = &netdev->up;
276
277     return 0;
278 }
279
280 static void
281 netdev_dummy_destroy(struct netdev *netdev_)
282 {
283     struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
284     size_t i;
285
286     shash_find_and_delete(&dummy_netdevs,
287                           netdev_get_name(netdev_));
288     pstream_close(netdev->pstream);
289     for (i = 0; i < netdev->n_streams; i++) {
290         dummy_stream_close(&netdev->streams[i]);
291     }
292     free(netdev->streams);
293     free(netdev);
294 }
295
296 static int
297 netdev_dummy_get_config(const struct netdev *netdev_, struct smap *args)
298 {
299     struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
300
301     if (netdev->ifindex >= 0) {
302         smap_add_format(args, "ifindex", "%d", netdev->ifindex);
303     }
304     if (netdev->pstream) {
305         smap_add(args, "pstream", pstream_get_name(netdev->pstream));
306     }
307     return 0;
308 }
309
310 static int
311 netdev_dummy_set_config(struct netdev *netdev_, const struct smap *args)
312 {
313     struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
314     const char *pstream;
315
316     netdev->ifindex = smap_get_int(args, "ifindex", -EOPNOTSUPP);
317
318     pstream = smap_get(args, "pstream");
319     if (!pstream
320         || !netdev->pstream
321         || strcmp(pstream_get_name(netdev->pstream), pstream)) {
322         pstream_close(netdev->pstream);
323         netdev->pstream = NULL;
324
325         if (pstream) {
326             int error;
327
328             error = pstream_open(pstream, &netdev->pstream, DSCP_DEFAULT);
329             if (error) {
330                 VLOG_WARN("%s: open failed (%s)",
331                           pstream, ovs_strerror(error));
332             }
333         }
334     }
335     return 0;
336 }
337
338 static int
339 netdev_dummy_rx_open(struct netdev *netdev_, struct netdev_rx **rxp)
340 {
341     struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
342     struct netdev_rx_dummy *rx;
343
344     rx = xmalloc(sizeof *rx);
345     netdev_rx_init(&rx->up, &netdev->up, &netdev_rx_dummy_class);
346     list_push_back(&netdev->rxes, &rx->node);
347     list_init(&rx->recv_queue);
348     rx->recv_queue_len = 0;
349
350     *rxp = &rx->up;
351     return 0;
352 }
353
354 static int
355 netdev_rx_dummy_recv(struct netdev_rx *rx_, void *buffer, size_t size)
356 {
357     struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
358     struct ofpbuf *packet;
359     size_t packet_size;
360
361     if (list_is_empty(&rx->recv_queue)) {
362         return -EAGAIN;
363     }
364
365     packet = ofpbuf_from_list(list_pop_front(&rx->recv_queue));
366     rx->recv_queue_len--;
367     if (packet->size > size) {
368         return -EMSGSIZE;
369     }
370     packet_size = packet->size;
371
372     memcpy(buffer, packet->data, packet->size);
373     ofpbuf_delete(packet);
374
375     return packet_size;
376 }
377
378 static void
379 netdev_rx_dummy_destroy(struct netdev_rx *rx_)
380 {
381     struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
382     list_remove(&rx->node);
383     ofpbuf_list_delete(&rx->recv_queue);
384     free(rx);
385 }
386
387 static void
388 netdev_rx_dummy_wait(struct netdev_rx *rx_)
389 {
390     struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
391     if (!list_is_empty(&rx->recv_queue)) {
392         poll_immediate_wake();
393     }
394 }
395
396 static int
397 netdev_rx_dummy_drain(struct netdev_rx *rx_)
398 {
399     struct netdev_rx_dummy *rx = netdev_rx_dummy_cast(rx_);
400     ofpbuf_list_delete(&rx->recv_queue);
401     rx->recv_queue_len = 0;
402     return 0;
403 }
404
405 static int
406 netdev_dummy_send(struct netdev *netdev, const void *buffer, size_t size)
407 {
408     struct netdev_dummy *dev = netdev_dummy_cast(netdev);
409     size_t i;
410
411     if (size < ETH_HEADER_LEN) {
412         return EMSGSIZE;
413     } else {
414         const struct eth_header *eth = buffer;
415         int max_size;
416
417         max_size = dev->mtu + ETH_HEADER_LEN;
418         if (eth->eth_type == htons(ETH_TYPE_VLAN)) {
419             max_size += VLAN_HEADER_LEN;
420         }
421         if (size > max_size) {
422             return EMSGSIZE;
423         }
424     }
425
426     dev->stats.tx_packets++;
427     dev->stats.tx_bytes += size;
428
429     for (i = 0; i < dev->n_streams; i++) {
430         struct dummy_stream *s = &dev->streams[i];
431
432         if (list_size(&s->txq) < NETDEV_DUMMY_MAX_QUEUE) {
433             struct ofpbuf *b;
434
435             b = ofpbuf_clone_data_with_headroom(buffer, size, 2);
436             put_unaligned_be16(ofpbuf_push_uninit(b, 2), htons(size));
437             list_push_back(&s->txq, &b->list_node);
438         }
439     }
440
441     return 0;
442 }
443
444 static int
445 netdev_dummy_set_etheraddr(struct netdev *netdev,
446                            const uint8_t mac[ETH_ADDR_LEN])
447 {
448     struct netdev_dummy *dev = netdev_dummy_cast(netdev);
449
450     if (!eth_addr_equals(dev->hwaddr, mac)) {
451         memcpy(dev->hwaddr, mac, ETH_ADDR_LEN);
452         netdev_dummy_poll_notify(dev);
453     }
454
455     return 0;
456 }
457
458 static int
459 netdev_dummy_get_etheraddr(const struct netdev *netdev,
460                            uint8_t mac[ETH_ADDR_LEN])
461 {
462     const struct netdev_dummy *dev = netdev_dummy_cast(netdev);
463
464     memcpy(mac, dev->hwaddr, ETH_ADDR_LEN);
465     return 0;
466 }
467
468 static int
469 netdev_dummy_get_mtu(const struct netdev *netdev, int *mtup)
470 {
471     const struct netdev_dummy *dev = netdev_dummy_cast(netdev);
472
473     *mtup = dev->mtu;
474     return 0;
475 }
476
477 static int
478 netdev_dummy_set_mtu(const struct netdev *netdev, int mtu)
479 {
480     struct netdev_dummy *dev = netdev_dummy_cast(netdev);
481
482     dev->mtu = mtu;
483     return 0;
484 }
485
486 static int
487 netdev_dummy_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
488 {
489     const struct netdev_dummy *dev = netdev_dummy_cast(netdev);
490
491     *stats = dev->stats;
492     return 0;
493 }
494
495 static int
496 netdev_dummy_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
497 {
498     struct netdev_dummy *dev = netdev_dummy_cast(netdev);
499
500     dev->stats = *stats;
501     return 0;
502 }
503
504 static int
505 netdev_dummy_get_ifindex(const struct netdev *netdev)
506 {
507     struct netdev_dummy *dev = netdev_dummy_cast(netdev);
508
509     return dev->ifindex;
510 }
511
512 static int
513 netdev_dummy_update_flags(struct netdev *netdev_,
514                           enum netdev_flags off, enum netdev_flags on,
515                           enum netdev_flags *old_flagsp)
516 {
517     struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
518
519     if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
520         return EINVAL;
521     }
522
523     *old_flagsp = netdev->flags;
524     netdev->flags |= on;
525     netdev->flags &= ~off;
526     if (*old_flagsp != netdev->flags) {
527         netdev_dummy_poll_notify(netdev);
528     }
529     return 0;
530 }
531
532 static unsigned int
533 netdev_dummy_change_seq(const struct netdev *netdev)
534 {
535     return netdev_dummy_cast(netdev)->change_seq;
536 }
537 \f
538 /* Helper functions. */
539
540 static void
541 netdev_dummy_poll_notify(struct netdev_dummy *dev)
542 {
543     dev->change_seq++;
544     if (!dev->change_seq) {
545         dev->change_seq++;
546     }
547 }
548
549 static const struct netdev_class dummy_class = {
550     "dummy",
551     NULL,                       /* init */
552     netdev_dummy_run,
553     netdev_dummy_wait,
554
555     netdev_dummy_create,
556     netdev_dummy_destroy,
557     netdev_dummy_get_config,
558     netdev_dummy_set_config,
559     NULL,                       /* get_tunnel_config */
560
561     netdev_dummy_rx_open,
562
563     netdev_dummy_send,          /* send */
564     NULL,                       /* send_wait */
565
566     netdev_dummy_set_etheraddr,
567     netdev_dummy_get_etheraddr,
568     netdev_dummy_get_mtu,
569     netdev_dummy_set_mtu,
570     netdev_dummy_get_ifindex,
571     NULL,                       /* get_carrier */
572     NULL,                       /* get_carrier_resets */
573     NULL,                       /* get_miimon */
574     netdev_dummy_get_stats,
575     netdev_dummy_set_stats,
576
577     NULL,                       /* get_features */
578     NULL,                       /* set_advertisements */
579
580     NULL,                       /* set_policing */
581     NULL,                       /* get_qos_types */
582     NULL,                       /* get_qos_capabilities */
583     NULL,                       /* get_qos */
584     NULL,                       /* set_qos */
585     NULL,                       /* get_queue */
586     NULL,                       /* set_queue */
587     NULL,                       /* delete_queue */
588     NULL,                       /* get_queue_stats */
589     NULL,                       /* dump_queues */
590     NULL,                       /* dump_queue_stats */
591
592     NULL,                       /* get_in4 */
593     NULL,                       /* set_in4 */
594     NULL,                       /* get_in6 */
595     NULL,                       /* add_router */
596     NULL,                       /* get_next_hop */
597     NULL,                       /* get_status */
598     NULL,                       /* arp_lookup */
599
600     netdev_dummy_update_flags,
601
602     netdev_dummy_change_seq
603 };
604
605 static const struct netdev_rx_class netdev_rx_dummy_class = {
606     netdev_rx_dummy_destroy,
607     netdev_rx_dummy_recv,
608     netdev_rx_dummy_wait,
609     netdev_rx_dummy_drain,
610 };
611
612 static struct ofpbuf *
613 eth_from_packet_or_flow(const char *s)
614 {
615     enum odp_key_fitness fitness;
616     struct ofpbuf *packet;
617     struct ofpbuf odp_key;
618     struct flow flow;
619     int error;
620
621     if (!eth_from_hex(s, &packet)) {
622         return packet;
623     }
624
625     /* Convert string to datapath key.
626      *
627      * It would actually be nicer to parse an OpenFlow-like flow key here, but
628      * the code for that currently calls exit() on parse error.  We have to
629      * settle for parsing a datapath key for now.
630      */
631     ofpbuf_init(&odp_key, 0);
632     error = odp_flow_from_string(s, NULL, &odp_key, NULL);
633     if (error) {
634         ofpbuf_uninit(&odp_key);
635         return NULL;
636     }
637
638     /* Convert odp_key to flow. */
639     fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
640     if (fitness == ODP_FIT_ERROR) {
641         ofpbuf_uninit(&odp_key);
642         return NULL;
643     }
644
645     packet = ofpbuf_new(0);
646     flow_compose(packet, &flow);
647
648     ofpbuf_uninit(&odp_key);
649     return packet;
650 }
651
652 static void
653 netdev_dummy_queue_packet__(struct netdev_rx_dummy *rx, struct ofpbuf *packet)
654 {
655     list_push_back(&rx->recv_queue, &packet->list_node);
656     rx->recv_queue_len++;
657 }
658
659 static void
660 netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
661 {
662     struct netdev_rx_dummy *rx, *prev;
663
664     prev = NULL;
665     LIST_FOR_EACH (rx, node, &dummy->rxes) {
666         if (rx->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
667             if (prev) {
668                 netdev_dummy_queue_packet__(prev, ofpbuf_clone(packet));
669             }
670             prev = rx;
671         }
672     }
673     if (prev) {
674         netdev_dummy_queue_packet__(prev, packet);
675     } else {
676         ofpbuf_delete(packet);
677     }
678 }
679
680 static void
681 netdev_dummy_receive(struct unixctl_conn *conn,
682                      int argc, const char *argv[], void *aux OVS_UNUSED)
683 {
684     struct netdev_dummy *dummy_dev;
685     int i;
686
687     dummy_dev = shash_find_data(&dummy_netdevs, argv[1]);
688     if (!dummy_dev) {
689         unixctl_command_reply_error(conn, "no such dummy netdev");
690         return;
691     }
692
693     for (i = 2; i < argc; i++) {
694         struct ofpbuf *packet;
695
696         packet = eth_from_packet_or_flow(argv[i]);
697         if (!packet) {
698             unixctl_command_reply_error(conn, "bad packet syntax");
699             return;
700         }
701
702         dummy_dev->stats.rx_packets++;
703         dummy_dev->stats.rx_bytes += packet->size;
704
705         netdev_dummy_queue_packet(dummy_dev, packet);
706     }
707
708     unixctl_command_reply(conn, NULL);
709 }
710
711 static void
712 netdev_dummy_set_admin_state__(struct netdev_dummy *dev, bool admin_state)
713 {
714     enum netdev_flags old_flags;
715
716     if (admin_state) {
717         netdev_dummy_update_flags(&dev->up, 0, NETDEV_UP, &old_flags);
718     } else {
719         netdev_dummy_update_flags(&dev->up, NETDEV_UP, 0, &old_flags);
720     }
721 }
722
723 static void
724 netdev_dummy_set_admin_state(struct unixctl_conn *conn, int argc,
725                              const char *argv[], void *aux OVS_UNUSED)
726 {
727     bool up;
728
729     if (!strcasecmp(argv[argc - 1], "up")) {
730         up = true;
731     } else if ( !strcasecmp(argv[argc - 1], "down")) {
732         up = false;
733     } else {
734         unixctl_command_reply_error(conn, "Invalid Admin State");
735         return;
736     }
737
738     if (argc > 2) {
739         struct netdev_dummy *dummy_dev;
740
741         dummy_dev = shash_find_data(&dummy_netdevs, argv[1]);
742         if (dummy_dev) {
743             netdev_dummy_set_admin_state__(dummy_dev, up);
744         } else {
745             unixctl_command_reply_error(conn, "Unknown Dummy Interface");
746             return;
747         }
748     } else {
749         struct shash_node *node;
750
751         SHASH_FOR_EACH (node, &dummy_netdevs) {
752             netdev_dummy_set_admin_state__(node->data, up);
753         }
754     }
755     unixctl_command_reply(conn, "OK");
756 }
757
758 void
759 netdev_dummy_register(bool override)
760 {
761     unixctl_command_register("netdev-dummy/receive", "NAME PACKET|FLOW...",
762                              2, INT_MAX, netdev_dummy_receive, NULL);
763     unixctl_command_register("netdev-dummy/set-admin-state",
764                              "[netdev] up|down", 1, 2,
765                              netdev_dummy_set_admin_state, NULL);
766
767     if (override) {
768         struct sset types;
769         const char *type;
770
771         sset_init(&types);
772         netdev_enumerate_types(&types);
773         SSET_FOR_EACH (type, &types) {
774             if (!netdev_unregister_provider(type)) {
775                 struct netdev_class *class;
776
777                 class = xmalloc(sizeof *class);
778                 *class = dummy_class;
779                 class->type = xstrdup(type);
780                 netdev_register_provider(class);
781             }
782         }
783         sset_destroy(&types);
784     }
785     netdev_register_provider(&dummy_class);
786
787     netdev_vport_tunnel_register();
788 }