2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <arpa/inet.h>
22 #include <sys/socket.h>
24 #include <netinet/in.h>
33 #include "command-line.h"
37 #include "dynamic-string.h"
52 /* -s, --statistics: Print port/flow statistics? */
53 static bool print_statistics;
55 /* --clear: Reset existing statistics to zero when modifying a flow? */
56 static bool zero_statistics;
58 /* --may-create: Allow mod-flows command to create a new flow? */
59 static bool may_create;
61 /* -m, --more: Increase output verbosity. */
64 static const struct command *get_all_commands(void);
66 static void usage(void) NO_RETURN;
67 static void parse_options(int argc, char *argv[]);
70 main(int argc, char *argv[])
72 set_program_name(argv[0]);
73 parse_options(argc, argv);
74 signal(SIGPIPE, SIG_IGN);
75 run_command(argc - optind, argv + optind, get_all_commands());
80 parse_options(int argc, char *argv[])
83 OPT_CLEAR = UCHAR_MAX + 1,
87 static const struct option long_options[] = {
88 {"statistics", no_argument, NULL, 's'},
89 {"clear", no_argument, NULL, OPT_CLEAR},
90 {"may-create", no_argument, NULL, OPT_MAY_CREATE},
91 {"more", no_argument, NULL, 'm'},
92 {"timeout", required_argument, NULL, 't'},
93 {"help", no_argument, NULL, 'h'},
94 {"version", no_argument, NULL, 'V'},
98 char *short_options = long_options_to_short_options(long_options);
101 unsigned long int timeout;
104 c = getopt_long(argc, argv, short_options, long_options, NULL);
111 print_statistics = true;
115 zero_statistics = true;
127 timeout = strtoul(optarg, NULL, 10);
129 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
140 ovs_print_version(0, 0);
158 printf("%s: Open vSwitch datapath management utility\n"
159 "usage: %s [OPTIONS] COMMAND [ARG...]\n"
160 " add-dp DP [IFACE...] add new datapath DP (with IFACEs)\n"
161 " del-dp DP delete local datapath DP\n"
162 " add-if DP IFACE... add each IFACE as a port on DP\n"
163 " set-if DP IFACE... reconfigure each IFACE within DP\n"
164 " del-if DP IFACE... delete each IFACE from DP\n"
165 " dump-dps display names of all datapaths\n"
166 " show show basic info on all datapaths\n"
167 " show DP... show basic info on each DP\n"
168 " dump-flows [DP] display flows in DP\n"
169 " add-flow [DP] FLOW ACTIONS add FLOW with ACTIONS to DP\n"
170 " mod-flow [DP] FLOW ACTIONS change FLOW actions to ACTIONS in DP\n"
171 " del-flow [DP] FLOW delete FLOW from DP\n"
172 " del-flows [DP] delete all flows from DP\n"
173 "Each IFACE on add-dp, add-if, and set-if may be followed by\n"
174 "comma-separated options. See ovs-dpctl(8) for syntax, or the\n"
175 "Interface table in ovs-vswitchd.conf.db(5) for an options list.\n"
176 "For COMMAND dump-flows, add-flow, mod-flow, del-flow and\n"
177 "del-flows, DP is optional if there is only one datapath.\n",
178 program_name, program_name);
180 printf("\nOptions for show and mod-flow:\n"
181 " -s, --statistics print statistics for port or flow\n"
182 "\nOptions for dump-flows:\n"
183 " -m, --more increase verbosity of output\n"
184 "\nOptions for mod-flow:\n"
185 " --may-create create flow if it doesn't exist\n"
186 " --clear reset existing stats to zero\n"
188 " -t, --timeout=SECS give up after SECS seconds\n"
189 " -h, --help display this help message\n"
190 " -V, --version display version information\n");
194 static void run(int retval, const char *message, ...)
197 static void run(int retval, const char *message, ...)
202 va_start(args, message);
203 ovs_fatal_valist(retval, message, args);
207 static void dpctl_add_if(int argc, char *argv[]);
209 static int if_up(const char *netdev_name)
211 struct netdev *netdev;
214 retval = netdev_open(netdev_name, "system", &netdev);
216 retval = netdev_turn_flags_on(netdev, NETDEV_UP, NULL);
217 netdev_close(netdev);
222 /* Retrieve the name of the datapath if exactly one exists. The caller
223 * is responsible for freeing the returned string. If there is not one
224 * datapath, aborts with an error message. */
230 char *dp_name = NULL;
234 dp_enumerate_types(&types);
235 SSET_FOR_EACH (type, &types) {
239 if (!dp_enumerate_names(type, &names)) {
240 count += sset_count(&names);
241 if (!dp_name && count == 1) {
242 dp_name = xasprintf("%s@%s", type, SSET_FIRST(&names));
245 sset_destroy(&names);
247 sset_destroy(&types);
250 ovs_fatal(0, "no datapaths exist");
251 } else if (count > 1) {
252 ovs_fatal(0, "multiple datapaths, specify one");
259 parsed_dpif_open(const char *arg_, bool create, struct dpif **dpifp)
264 dp_parse_name(arg_, &name, &type);
267 result = dpif_create(name, type, dpifp);
269 result = dpif_open(name, type, dpifp);
278 dpctl_add_dp(int argc OVS_UNUSED, char *argv[])
281 run(parsed_dpif_open(argv[1], true, &dpif), "add_dp");
284 dpctl_add_if(argc, argv);
289 dpctl_del_dp(int argc OVS_UNUSED, char *argv[])
292 run(parsed_dpif_open(argv[1], false, &dpif), "opening datapath");
293 run(dpif_delete(dpif), "del_dp");
298 dpctl_add_if(int argc OVS_UNUSED, char *argv[])
300 bool failure = false;
304 run(parsed_dpif_open(argv[1], false, &dpif), "opening datapath");
305 for (i = 2; i < argc; i++) {
306 const char *name, *type;
307 char *save_ptr = NULL;
308 struct netdev *netdev = NULL;
310 odp_port_t port_no = ODPP_NONE;
314 name = strtok_r(argv[i], ",", &save_ptr);
318 ovs_error(0, "%s is not a valid network device name", argv[i]);
324 while ((option = strtok_r(NULL, ",", &save_ptr)) != NULL) {
325 char *save_ptr_2 = NULL;
328 key = strtok_r(option, "=", &save_ptr_2);
329 value = strtok_r(NULL, "", &save_ptr_2);
334 if (!strcmp(key, "type")) {
336 } else if (!strcmp(key, "port_no")) {
337 port_no = u32_to_odp(atoi(value));
338 } else if (!smap_add_once(&args, key, value)) {
339 ovs_error(0, "duplicate \"%s\" option", key);
343 error = netdev_open(name, type, &netdev);
345 ovs_error(error, "%s: failed to open network device", name);
349 error = netdev_set_config(netdev, &args);
351 ovs_error(error, "%s: failed to configure network device", name);
355 error = dpif_port_add(dpif, netdev, &port_no);
357 ovs_error(error, "adding %s to %s failed", name, argv[1]);
364 netdev_close(netdev);
376 dpctl_set_if(int argc, char *argv[])
378 bool failure = false;
382 run(parsed_dpif_open(argv[1], false, &dpif), "opening datapath");
383 for (i = 2; i < argc; i++) {
384 struct netdev *netdev = NULL;
385 struct dpif_port dpif_port;
386 char *save_ptr = NULL;
394 name = strtok_r(argv[i], ",", &save_ptr);
396 ovs_error(0, "%s is not a valid network device name", argv[i]);
401 /* Get the port's type from the datapath. */
402 error = dpif_port_query_by_name(dpif, name, &dpif_port);
404 ovs_error(error, "%s: failed to query port in %s", name, argv[1]);
407 type = xstrdup(dpif_port.type);
408 port_no = dpif_port.port_no;
409 dpif_port_destroy(&dpif_port);
411 /* Retrieve its existing configuration. */
412 error = netdev_open(name, type, &netdev);
414 ovs_error(error, "%s: failed to open network device", name);
419 error = netdev_get_config(netdev, &args);
421 ovs_error(error, "%s: failed to fetch configuration", name);
425 /* Parse changes to configuration. */
426 while ((option = strtok_r(NULL, ",", &save_ptr)) != NULL) {
427 char *save_ptr_2 = NULL;
430 key = strtok_r(option, "=", &save_ptr_2);
431 value = strtok_r(NULL, "", &save_ptr_2);
436 if (!strcmp(key, "type")) {
437 if (strcmp(value, type)) {
438 ovs_error(0, "%s: can't change type from %s to %s",
442 } else if (!strcmp(key, "port_no")) {
443 if (port_no != u32_to_odp(atoi(value))) {
444 ovs_error(0, "%s: can't change port number from "
446 name, port_no, atoi(value));
449 } else if (value[0] == '\0') {
450 smap_remove(&args, key);
452 smap_replace(&args, key, value);
456 /* Update configuration. */
457 error = netdev_set_config(netdev, &args);
460 ovs_error(error, "%s: failed to configure network device", name);
466 netdev_close(netdev);
478 get_port_number(struct dpif *dpif, const char *name, odp_port_t *port)
480 struct dpif_port dpif_port;
482 if (!dpif_port_query_by_name(dpif, name, &dpif_port)) {
483 *port = dpif_port.port_no;
484 dpif_port_destroy(&dpif_port);
487 ovs_error(0, "no port named %s", name);
493 dpctl_del_if(int argc OVS_UNUSED, char *argv[])
495 bool failure = false;
499 run(parsed_dpif_open(argv[1], false, &dpif), "opening datapath");
500 for (i = 2; i < argc; i++) {
501 const char *name = argv[i];
505 if (!name[strspn(name, "0123456789")]) {
506 port = u32_to_odp(atoi(name));
507 } else if (!get_port_number(dpif, name, &port)) {
512 error = dpif_port_del(dpif, port);
514 ovs_error(error, "deleting port %s from %s failed", name, argv[1]);
525 print_stat(const char *leader, uint64_t value)
527 fputs(leader, stdout);
528 if (value != UINT64_MAX) {
529 printf("%"PRIu64, value);
536 print_human_size(uint64_t value)
538 if (value == UINT64_MAX) {
540 } else if (value >= 1024ULL * 1024 * 1024 * 1024) {
541 printf(" (%.1f TiB)", value / (1024.0 * 1024 * 1024 * 1024));
542 } else if (value >= 1024ULL * 1024 * 1024) {
543 printf(" (%.1f GiB)", value / (1024.0 * 1024 * 1024));
544 } else if (value >= 1024ULL * 1024) {
545 printf(" (%.1f MiB)", value / (1024.0 * 1024));
546 } else if (value >= 1024) {
547 printf(" (%.1f KiB)", value / 1024.0);
552 show_dpif(struct dpif *dpif)
554 struct dpif_port_dump dump;
555 struct dpif_port dpif_port;
556 struct dpif_dp_stats stats;
557 struct netdev *netdev;
559 printf("%s:\n", dpif_name(dpif));
560 if (!dpif_get_dp_stats(dpif, &stats)) {
561 printf("\tlookups: hit:%"PRIu64" missed:%"PRIu64" lost:%"PRIu64"\n"
562 "\tflows: %"PRIu64"\n",
563 stats.n_hit, stats.n_missed, stats.n_lost, stats.n_flows);
565 DPIF_PORT_FOR_EACH (&dpif_port, &dump, dpif) {
566 printf("\tport %u: %s", dpif_port.port_no, dpif_port.name);
568 if (strcmp(dpif_port.type, "system")) {
571 printf (" (%s", dpif_port.type);
573 error = netdev_open(dpif_port.name, dpif_port.type, &netdev);
578 error = netdev_get_config(netdev, &config);
580 const struct smap_node **nodes;
583 nodes = smap_sort(&config);
584 for (i = 0; i < smap_count(&config); i++) {
585 const struct smap_node *node = nodes[i];
586 printf("%c %s=%s", i ? ',' : ':', node->key,
591 printf(", could not retrieve configuration (%s)",
592 ovs_strerror(error));
594 smap_destroy(&config);
596 netdev_close(netdev);
598 printf(": open failed (%s)", ovs_strerror(error));
604 if (print_statistics) {
605 struct netdev_stats s;
608 error = netdev_open(dpif_port.name, dpif_port.type, &netdev);
610 printf(", open failed (%s)", ovs_strerror(error));
613 error = netdev_get_stats(netdev, &s);
615 printf(", could not retrieve stats (%s)", ovs_strerror(error));
619 netdev_close(netdev);
620 print_stat("\t\tRX packets:", s.rx_packets);
621 print_stat(" errors:", s.rx_errors);
622 print_stat(" dropped:", s.rx_dropped);
623 print_stat(" overruns:", s.rx_over_errors);
624 print_stat(" frame:", s.rx_frame_errors);
627 print_stat("\t\tTX packets:", s.tx_packets);
628 print_stat(" errors:", s.tx_errors);
629 print_stat(" dropped:", s.tx_dropped);
630 print_stat(" aborted:", s.tx_aborted_errors);
631 print_stat(" carrier:", s.tx_carrier_errors);
634 print_stat("\t\tcollisions:", s.collisions);
637 print_stat("\t\tRX bytes:", s.rx_bytes);
638 print_human_size(s.rx_bytes);
639 print_stat(" TX bytes:", s.tx_bytes);
640 print_human_size(s.tx_bytes);
648 dpctl_show(int argc, char *argv[])
650 bool failure = false;
653 for (i = 1; i < argc; i++) {
654 const char *name = argv[i];
658 error = parsed_dpif_open(name, false, &dpif);
662 ovs_error(error, "opening datapath %s failed", name);
671 dp_enumerate_types(&types);
672 SSET_FOR_EACH (type, &types) {
677 if (dp_enumerate_names(type, &names)) {
681 SSET_FOR_EACH (name, &names) {
685 error = dpif_open(name, type, &dpif);
689 ovs_error(error, "opening datapath %s failed", name);
693 sset_destroy(&names);
695 sset_destroy(&types);
703 dpctl_dump_dps(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
705 struct sset dpif_names, dpif_types;
709 sset_init(&dpif_names);
710 sset_init(&dpif_types);
711 dp_enumerate_types(&dpif_types);
713 SSET_FOR_EACH (type, &dpif_types) {
717 retval = dp_enumerate_names(type, &dpif_names);
722 SSET_FOR_EACH (name, &dpif_names) {
724 if (!dpif_open(name, type, &dpif)) {
725 printf("%s\n", dpif_name(dpif));
731 sset_destroy(&dpif_names);
732 sset_destroy(&dpif_types);
739 dpctl_dump_flows(int argc, char *argv[])
741 const struct dpif_flow_stats *stats;
742 const struct nlattr *actions;
743 struct dpif_flow_dump dump;
744 const struct nlattr *key;
745 const struct nlattr *mask;
753 name = (argc == 2) ? xstrdup(argv[1]) : get_one_dp();
754 run(parsed_dpif_open(name, false, &dpif), "opening datapath");
758 dpif_flow_dump_start(&dump, dpif);
759 while (dpif_flow_dump_next(&dump, &key, &key_len,
761 &actions, &actions_len, &stats)) {
763 odp_flow_format(key, key_len, mask, mask_len, &ds, verbosity);
764 ds_put_cstr(&ds, ", ");
766 dpif_flow_stats_format(stats, &ds);
767 ds_put_cstr(&ds, ", actions:");
768 format_odp_actions(&ds, actions, actions_len);
769 printf("%s\n", ds_cstr(&ds));
771 dpif_flow_dump_done(&dump);
777 dpctl_put_flow(int argc, char *argv[], enum dpif_flow_put_flags flags)
779 const char *key_s = argv[argc - 2];
780 const char *actions_s = argv[argc - 1];
781 struct dpif_flow_stats stats;
782 struct ofpbuf actions;
790 ofpbuf_init(&key, 0);
791 ofpbuf_init(&mask, 0);
792 run(odp_flow_from_string(key_s, NULL, &key, &mask), "parsing flow key");
794 ofpbuf_init(&actions, 0);
795 run(odp_actions_from_string(actions_s, NULL, &actions), "parsing actions");
797 dp_name = argc == 4 ? xstrdup(argv[1]) : get_one_dp();
798 run(parsed_dpif_open(dp_name, false, &dpif), "opening datapath");
801 run(dpif_flow_put(dpif, flags,
803 mask.size == 0 ? NULL : mask.data, mask.size,
804 actions.data, actions.size,
805 print_statistics ? &stats : NULL),
806 "updating flow table");
809 ofpbuf_uninit(&mask);
810 ofpbuf_uninit(&actions);
812 if (print_statistics) {
816 dpif_flow_stats_format(&stats, &s);
823 dpctl_add_flow(int argc, char *argv[])
825 dpctl_put_flow(argc, argv, DPIF_FP_CREATE);
829 dpctl_mod_flow(int argc OVS_UNUSED, char *argv[])
831 enum dpif_flow_put_flags flags;
833 flags = DPIF_FP_MODIFY;
835 flags |= DPIF_FP_CREATE;
837 if (zero_statistics) {
838 flags |= DPIF_FP_ZERO_STATS;
841 dpctl_put_flow(argc, argv, flags);
845 dpctl_del_flow(int argc, char *argv[])
847 const char *key_s = argv[argc - 1];
848 struct dpif_flow_stats stats;
850 struct ofpbuf mask; /* To be ignored. */
854 ofpbuf_init(&key, 0);
855 ofpbuf_init(&mask, 0);
856 run(odp_flow_from_string(key_s, NULL, &key, &mask), "parsing flow key");
858 dp_name = argc == 3 ? xstrdup(argv[1]) : get_one_dp();
859 run(parsed_dpif_open(dp_name, false, &dpif), "opening datapath");
862 run(dpif_flow_del(dpif,
864 print_statistics ? &stats : NULL), "deleting flow");
867 ofpbuf_uninit(&mask);
869 if (print_statistics) {
873 dpif_flow_stats_format(&stats, &s);
880 dpctl_del_flows(int argc, char *argv[])
885 name = (argc == 2) ? xstrdup(argv[1]) : get_one_dp();
886 run(parsed_dpif_open(name, false, &dpif), "opening datapath");
889 run(dpif_flow_flush(dpif), "deleting all flows");
894 dpctl_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
899 /* Undocumented commands for unit testing. */
902 dpctl_parse_actions(int argc, char *argv[])
906 for (i = 1; i < argc; i++) {
907 struct ofpbuf actions;
910 ofpbuf_init(&actions, 0);
911 run(odp_actions_from_string(argv[i], NULL, &actions),
912 "odp_actions_from_string");
915 format_odp_actions(&s, actions.data, actions.size);
919 ofpbuf_uninit(&actions);
923 struct actions_for_flow {
924 struct hmap_node hmap_node;
926 struct ofpbuf actions;
929 static struct actions_for_flow *
930 get_actions_for_flow(struct hmap *actions_per_flow, const struct flow *flow)
932 uint32_t hash = flow_hash(flow, 0);
933 struct actions_for_flow *af;
935 HMAP_FOR_EACH_WITH_HASH (af, hmap_node, hash, actions_per_flow) {
936 if (flow_equal(&af->flow, flow)) {
941 af = xmalloc(sizeof *af);
943 ofpbuf_init(&af->actions, 0);
944 hmap_insert(actions_per_flow, &af->hmap_node, hash);
949 compare_actions_for_flow(const void *a_, const void *b_)
951 struct actions_for_flow *const *a = a_;
952 struct actions_for_flow *const *b = b_;
954 return flow_compare_3way(&(*a)->flow, &(*b)->flow);
958 compare_output_actions(const void *a_, const void *b_)
960 const struct nlattr *a = a_;
961 const struct nlattr *b = b_;
962 uint32_t a_port = nl_attr_get_u32(a);
963 uint32_t b_port = nl_attr_get_u32(b);
965 return a_port < b_port ? -1 : a_port > b_port;
969 sort_output_actions__(struct nlattr *first, struct nlattr *end)
971 size_t bytes = (uint8_t *) end - (uint8_t *) first;
972 size_t n = bytes / NL_A_U32_SIZE;
974 ovs_assert(bytes % NL_A_U32_SIZE == 0);
975 qsort(first, n, NL_A_U32_SIZE, compare_output_actions);
979 sort_output_actions(struct nlattr *actions, size_t length)
981 struct nlattr *first_output = NULL;
985 NL_ATTR_FOR_EACH (a, left, actions, length) {
986 if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT) {
992 sort_output_actions__(first_output, a);
998 uint8_t *end = (uint8_t *) actions + length;
999 sort_output_actions__(first_output,
1000 ALIGNED_CAST(struct nlattr *, end));
1004 /* usage: "ovs-dpctl normalize-actions FLOW ACTIONS" where FLOW and ACTIONS
1005 * have the syntax used by "ovs-dpctl dump-flows".
1007 * This command prints ACTIONS in a format that shows what happens for each
1008 * VLAN, independent of the order of the ACTIONS. For example, there is more
1009 * than one way to output a packet on VLANs 9 and 11, but this command will
1010 * print the same output for any form.
1012 * The idea here generalizes beyond VLANs (e.g. to setting other fields) but
1013 * so far the implementation only covers VLANs. */
1015 dpctl_normalize_actions(int argc, char *argv[])
1017 struct simap port_names;
1018 struct ofpbuf keybuf;
1020 struct ofpbuf odp_actions;
1021 struct hmap actions_per_flow;
1022 struct actions_for_flow **afs;
1023 struct actions_for_flow *af;
1032 simap_init(&port_names);
1033 for (i = 3; i < argc; i++) {
1038 if (sscanf(argv[i], "%15[^=]=%d%n", name, &number, &n) > 0 && n > 0) {
1039 uintptr_t n = number;
1040 simap_put(&port_names, name, n);
1042 ovs_fatal(0, "%s: expected NAME=NUMBER", argv[i]);
1046 /* Parse flow key. */
1047 ofpbuf_init(&keybuf, 0);
1048 run(odp_flow_from_string(argv[1], &port_names, &keybuf, NULL),
1049 "odp_flow_key_from_string");
1052 odp_flow_format(keybuf.data, keybuf.size, NULL, 0, &s, verbosity);
1053 printf("input flow: %s\n", ds_cstr(&s));
1055 run(odp_flow_key_to_flow(keybuf.data, keybuf.size, &flow),
1056 "odp_flow_key_to_flow");
1057 ofpbuf_uninit(&keybuf);
1059 /* Parse actions. */
1060 ofpbuf_init(&odp_actions, 0);
1061 run(odp_actions_from_string(argv[2], &port_names, &odp_actions),
1062 "odp_actions_from_string");
1063 simap_destroy(&port_names);
1067 format_odp_actions(&s, odp_actions.data, odp_actions.size);
1068 printf("input actions: %s\n", ds_cstr(&s));
1071 hmap_init(&actions_per_flow);
1072 NL_ATTR_FOR_EACH (a, left, odp_actions.data, odp_actions.size) {
1073 const struct ovs_action_push_vlan *push;
1074 switch(nl_attr_type(a)) {
1075 case OVS_ACTION_ATTR_POP_VLAN:
1076 flow.vlan_tci = htons(0);
1079 case OVS_ACTION_ATTR_PUSH_VLAN:
1080 push = nl_attr_get_unspec(a, sizeof *push);
1081 flow.vlan_tci = push->vlan_tci;
1085 af = get_actions_for_flow(&actions_per_flow, &flow);
1086 nl_msg_put_unspec(&af->actions, nl_attr_type(a),
1087 nl_attr_get(a), nl_attr_get_size(a));
1090 n_afs = hmap_count(&actions_per_flow);
1091 afs = xmalloc(n_afs * sizeof *afs);
1093 HMAP_FOR_EACH (af, hmap_node, &actions_per_flow) {
1096 ovs_assert(i == n_afs);
1098 qsort(afs, n_afs, sizeof *afs, compare_actions_for_flow);
1100 for (i = 0; i < n_afs; i++) {
1101 const struct actions_for_flow *af = afs[i];
1103 sort_output_actions(af->actions.data, af->actions.size);
1105 if (af->flow.vlan_tci != htons(0)) {
1106 printf("vlan(vid=%"PRIu16",pcp=%d): ",
1107 vlan_tci_to_vid(af->flow.vlan_tci),
1108 vlan_tci_to_pcp(af->flow.vlan_tci));
1110 printf("no vlan: ");
1113 if (eth_type_mpls(af->flow.dl_type)) {
1114 printf("mpls(label=%"PRIu32",tc=%d,ttl=%d): ",
1115 mpls_lse_to_label(af->flow.mpls_lse),
1116 mpls_lse_to_tc(af->flow.mpls_lse),
1117 mpls_lse_to_ttl(af->flow.mpls_lse));
1119 printf("no mpls: ");
1123 format_odp_actions(&s, af->actions.data, af->actions.size);
1129 static const struct command all_commands[] = {
1130 { "add-dp", 1, INT_MAX, dpctl_add_dp },
1131 { "del-dp", 1, 1, dpctl_del_dp },
1132 { "add-if", 2, INT_MAX, dpctl_add_if },
1133 { "del-if", 2, INT_MAX, dpctl_del_if },
1134 { "set-if", 2, INT_MAX, dpctl_set_if },
1135 { "dump-dps", 0, 0, dpctl_dump_dps },
1136 { "show", 0, INT_MAX, dpctl_show },
1137 { "dump-flows", 0, 1, dpctl_dump_flows },
1138 { "add-flow", 2, 3, dpctl_add_flow },
1139 { "mod-flow", 2, 3, dpctl_mod_flow },
1140 { "del-flow", 1, 2, dpctl_del_flow },
1141 { "del-flows", 0, 1, dpctl_del_flows },
1142 { "help", 0, INT_MAX, dpctl_help },
1144 /* Undocumented commands for testing. */
1145 { "parse-actions", 1, INT_MAX, dpctl_parse_actions },
1146 { "normalize-actions", 2, INT_MAX, dpctl_normalize_actions },
1148 { NULL, 0, 0, NULL },
1151 static const struct command *get_all_commands(void)
1153 return all_commands;