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 VLOG_DEFINE_THIS_MODULE(dpctl
);
54 /* -s, --statistics: Print port/flow statistics? */
55 static bool print_statistics
;
57 /* --clear: Reset existing statistics to zero when modifying a flow? */
58 static bool zero_statistics
;
60 /* --may-create: Allow mod-flows command to create a new flow? */
61 static bool may_create
;
63 /* -m, --more: Output verbosity.
65 * So far only undocumented commands honor this option, so we don't document
66 * the option itself. */
69 static const struct command all_commands
[];
71 static void usage(void) NO_RETURN
;
72 static void parse_options(int argc
, char *argv
[]);
75 main(int argc
, char *argv
[])
77 set_program_name(argv
[0]);
78 parse_options(argc
, argv
);
79 signal(SIGPIPE
, SIG_IGN
);
80 run_command(argc
- optind
, argv
+ optind
, all_commands
);
85 parse_options(int argc
, char *argv
[])
88 OPT_CLEAR
= UCHAR_MAX
+ 1,
92 static const struct option long_options
[] = {
93 {"statistics", no_argument
, NULL
, 's'},
94 {"clear", no_argument
, NULL
, OPT_CLEAR
},
95 {"may-create", no_argument
, NULL
, OPT_MAY_CREATE
},
96 {"more", no_argument
, NULL
, 'm'},
97 {"timeout", required_argument
, NULL
, 't'},
98 {"help", no_argument
, NULL
, 'h'},
99 {"version", no_argument
, NULL
, 'V'},
103 char *short_options
= long_options_to_short_options(long_options
);
106 unsigned long int timeout
;
109 c
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
);
116 print_statistics
= true;
120 zero_statistics
= true;
132 timeout
= strtoul(optarg
, NULL
, 10);
134 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
145 ovs_print_version(0, 0);
163 printf("%s: Open vSwitch datapath management utility\n"
164 "usage: %s [OPTIONS] COMMAND [ARG...]\n"
165 " add-dp DP [IFACE...] add new datapath DP (with IFACEs)\n"
166 " del-dp DP delete local datapath DP\n"
167 " add-if DP IFACE... add each IFACE as a port on DP\n"
168 " set-if DP IFACE... reconfigure each IFACE within DP\n"
169 " del-if DP IFACE... delete each IFACE from DP\n"
170 " dump-dps display names of all datapaths\n"
171 " show show basic info on all datapaths\n"
172 " show DP... show basic info on each DP\n"
173 " dump-flows DP display flows in DP\n"
174 " add-flow DP FLOW ACTIONS add FLOW with ACTIONS to DP\n"
175 " mod-flow DP FLOW ACTIONS change FLOW actions to ACTIONS in DP\n"
176 " del-flow DP FLOW delete FLOW from DP\n"
177 " del-flows DP delete all flows from DP\n"
178 "Each IFACE on add-dp, add-if, and set-if may be followed by\n"
179 "comma-separated options. See ovs-dpctl(8) for syntax, or the\n"
180 "Interface table in ovs-vswitchd.conf.db(5) for an options list.\n",
181 program_name
, program_name
);
183 printf("\nOptions for show and mod-flow:\n"
184 " -s, --statistics print statistics for port or flow\n"
185 "\nOptions for mod-flow:\n"
186 " --may-create create flow if it doesn't exist\n"
187 " --clear reset existing stats to zero\n"
189 " -t, --timeout=SECS give up after SECS seconds\n"
190 " -h, --help display this help message\n"
191 " -V, --version display version information\n");
195 static void run(int retval
, const char *message
, ...)
198 static void run(int retval
, const char *message
, ...)
203 va_start(args
, message
);
204 ovs_fatal_valist(retval
, message
, args
);
208 static void dpctl_add_if(int argc
, char *argv
[]);
210 static int if_up(const char *netdev_name
)
212 struct netdev
*netdev
;
215 retval
= netdev_open(netdev_name
, "system", &netdev
);
217 retval
= netdev_turn_flags_on(netdev
, NETDEV_UP
, NULL
);
218 netdev_close(netdev
);
223 /* Retrieve the name of the datapath if exactly one exists. The caller
224 * is responsible for freeing the returned string. If there is not one
225 * datapath, aborts with an error message. */
231 char *dp_name
= NULL
;
235 dp_enumerate_types(&types
);
236 SSET_FOR_EACH (type
, &types
) {
240 if (!dp_enumerate_names(type
, &names
)) {
241 count
+= sset_count(&names
);
242 if (!dp_name
&& count
== 1) {
243 dp_name
= xasprintf("%s@%s", type
, SSET_FIRST(&names
));
246 sset_destroy(&names
);
248 sset_destroy(&types
);
251 ovs_fatal(0, "no datapaths exist");
252 } else if (count
> 1) {
253 ovs_fatal(0, "multiple datapaths, specify one");
260 parsed_dpif_open(const char *arg_
, bool create
, struct dpif
**dpifp
)
265 dp_parse_name(arg_
, &name
, &type
);
268 result
= dpif_create(name
, type
, dpifp
);
270 result
= dpif_open(name
, type
, dpifp
);
279 dpctl_add_dp(int argc OVS_UNUSED
, char *argv
[])
282 run(parsed_dpif_open(argv
[1], true, &dpif
), "add_dp");
285 dpctl_add_if(argc
, argv
);
290 dpctl_del_dp(int argc OVS_UNUSED
, char *argv
[])
293 run(parsed_dpif_open(argv
[1], false, &dpif
), "opening datapath");
294 run(dpif_delete(dpif
), "del_dp");
299 dpctl_add_if(int argc OVS_UNUSED
, char *argv
[])
301 bool failure
= false;
305 run(parsed_dpif_open(argv
[1], false, &dpif
), "opening datapath");
306 for (i
= 2; i
< argc
; i
++) {
307 const char *name
, *type
;
308 char *save_ptr
= NULL
;
309 struct netdev
*netdev
= NULL
;
311 odp_port_t port_no
= ODPP_NONE
;
315 name
= strtok_r(argv
[i
], ",", &save_ptr
);
319 ovs_error(0, "%s is not a valid network device name", argv
[i
]);
325 while ((option
= strtok_r(NULL
, ",", &save_ptr
)) != NULL
) {
326 char *save_ptr_2
= NULL
;
329 key
= strtok_r(option
, "=", &save_ptr_2
);
330 value
= strtok_r(NULL
, "", &save_ptr_2
);
335 if (!strcmp(key
, "type")) {
337 } else if (!strcmp(key
, "port_no")) {
338 port_no
= u32_to_odp(atoi(value
));
339 } else if (!smap_add_once(&args
, key
, value
)) {
340 ovs_error(0, "duplicate \"%s\" option", key
);
344 error
= netdev_open(name
, type
, &netdev
);
346 ovs_error(error
, "%s: failed to open network device", name
);
350 error
= netdev_set_config(netdev
, &args
);
352 ovs_error(error
, "%s: failed to configure network device", name
);
356 error
= dpif_port_add(dpif
, netdev
, &port_no
);
358 ovs_error(error
, "adding %s to %s failed", name
, argv
[1]);
365 netdev_close(netdev
);
377 dpctl_set_if(int argc
, char *argv
[])
379 bool failure
= false;
383 run(parsed_dpif_open(argv
[1], false, &dpif
), "opening datapath");
384 for (i
= 2; i
< argc
; i
++) {
385 struct netdev
*netdev
= NULL
;
386 struct dpif_port dpif_port
;
387 char *save_ptr
= NULL
;
395 name
= strtok_r(argv
[i
], ",", &save_ptr
);
397 ovs_error(0, "%s is not a valid network device name", argv
[i
]);
402 /* Get the port's type from the datapath. */
403 error
= dpif_port_query_by_name(dpif
, name
, &dpif_port
);
405 ovs_error(error
, "%s: failed to query port in %s", name
, argv
[1]);
408 type
= xstrdup(dpif_port
.type
);
409 port_no
= dpif_port
.port_no
;
410 dpif_port_destroy(&dpif_port
);
412 /* Retrieve its existing configuration. */
413 error
= netdev_open(name
, type
, &netdev
);
415 ovs_error(error
, "%s: failed to open network device", name
);
420 error
= netdev_get_config(netdev
, &args
);
422 ovs_error(error
, "%s: failed to fetch configuration", name
);
426 /* Parse changes to configuration. */
427 while ((option
= strtok_r(NULL
, ",", &save_ptr
)) != NULL
) {
428 char *save_ptr_2
= NULL
;
431 key
= strtok_r(option
, "=", &save_ptr_2
);
432 value
= strtok_r(NULL
, "", &save_ptr_2
);
437 if (!strcmp(key
, "type")) {
438 if (strcmp(value
, type
)) {
439 ovs_error(0, "%s: can't change type from %s to %s",
443 } else if (!strcmp(key
, "port_no")) {
444 if (port_no
!= u32_to_odp(atoi(value
))) {
445 ovs_error(0, "%s: can't change port number from "
447 name
, port_no
, atoi(value
));
450 } else if (value
[0] == '\0') {
451 smap_remove(&args
, key
);
453 smap_replace(&args
, key
, value
);
457 /* Update configuration. */
458 error
= netdev_set_config(netdev
, &args
);
461 ovs_error(error
, "%s: failed to configure network device", name
);
467 netdev_close(netdev
);
479 get_port_number(struct dpif
*dpif
, const char *name
, odp_port_t
*port
)
481 struct dpif_port dpif_port
;
483 if (!dpif_port_query_by_name(dpif
, name
, &dpif_port
)) {
484 *port
= dpif_port
.port_no
;
485 dpif_port_destroy(&dpif_port
);
488 ovs_error(0, "no port named %s", name
);
494 dpctl_del_if(int argc OVS_UNUSED
, char *argv
[])
496 bool failure
= false;
500 run(parsed_dpif_open(argv
[1], false, &dpif
), "opening datapath");
501 for (i
= 2; i
< argc
; i
++) {
502 const char *name
= argv
[i
];
506 if (!name
[strspn(name
, "0123456789")]) {
507 port
= u32_to_odp(atoi(name
));
508 } else if (!get_port_number(dpif
, name
, &port
)) {
513 error
= dpif_port_del(dpif
, port
);
515 ovs_error(error
, "deleting port %s from %s failed", name
, argv
[1]);
526 print_stat(const char *leader
, uint64_t value
)
528 fputs(leader
, stdout
);
529 if (value
!= UINT64_MAX
) {
530 printf("%"PRIu64
, value
);
537 print_human_size(uint64_t value
)
539 if (value
== UINT64_MAX
) {
541 } else if (value
>= 1024ULL * 1024 * 1024 * 1024) {
542 printf(" (%.1f TiB)", value
/ (1024.0 * 1024 * 1024 * 1024));
543 } else if (value
>= 1024ULL * 1024 * 1024) {
544 printf(" (%.1f GiB)", value
/ (1024.0 * 1024 * 1024));
545 } else if (value
>= 1024ULL * 1024) {
546 printf(" (%.1f MiB)", value
/ (1024.0 * 1024));
547 } else if (value
>= 1024) {
548 printf(" (%.1f KiB)", value
/ 1024.0);
553 show_dpif(struct dpif
*dpif
)
555 struct dpif_port_dump dump
;
556 struct dpif_port dpif_port
;
557 struct dpif_dp_stats stats
;
558 struct netdev
*netdev
;
560 printf("%s:\n", dpif_name(dpif
));
561 if (!dpif_get_dp_stats(dpif
, &stats
)) {
562 printf("\tlookups: hit:%"PRIu64
" missed:%"PRIu64
" lost:%"PRIu64
"\n"
563 "\tflows: %"PRIu64
"\n",
564 stats
.n_hit
, stats
.n_missed
, stats
.n_lost
, stats
.n_flows
);
566 DPIF_PORT_FOR_EACH (&dpif_port
, &dump
, dpif
) {
567 printf("\tport %u: %s", dpif_port
.port_no
, dpif_port
.name
);
569 if (strcmp(dpif_port
.type
, "system")) {
572 printf (" (%s", dpif_port
.type
);
574 error
= netdev_open(dpif_port
.name
, dpif_port
.type
, &netdev
);
579 error
= netdev_get_config(netdev
, &config
);
581 const struct smap_node
**nodes
;
584 nodes
= smap_sort(&config
);
585 for (i
= 0; i
< smap_count(&config
); i
++) {
586 const struct smap_node
*node
= nodes
[i
];
587 printf("%c %s=%s", i
? ',' : ':', node
->key
,
592 printf(", could not retrieve configuration (%s)",
593 ovs_strerror(error
));
595 smap_destroy(&config
);
597 netdev_close(netdev
);
599 printf(": open failed (%s)", ovs_strerror(error
));
605 if (print_statistics
) {
606 struct netdev_stats s
;
609 error
= netdev_open(dpif_port
.name
, dpif_port
.type
, &netdev
);
611 printf(", open failed (%s)", ovs_strerror(error
));
614 error
= netdev_get_stats(netdev
, &s
);
616 printf(", could not retrieve stats (%s)", ovs_strerror(error
));
620 netdev_close(netdev
);
621 print_stat("\t\tRX packets:", s
.rx_packets
);
622 print_stat(" errors:", s
.rx_errors
);
623 print_stat(" dropped:", s
.rx_dropped
);
624 print_stat(" overruns:", s
.rx_over_errors
);
625 print_stat(" frame:", s
.rx_frame_errors
);
628 print_stat("\t\tTX packets:", s
.tx_packets
);
629 print_stat(" errors:", s
.tx_errors
);
630 print_stat(" dropped:", s
.tx_dropped
);
631 print_stat(" aborted:", s
.tx_aborted_errors
);
632 print_stat(" carrier:", s
.tx_carrier_errors
);
635 print_stat("\t\tcollisions:", s
.collisions
);
638 print_stat("\t\tRX bytes:", s
.rx_bytes
);
639 print_human_size(s
.rx_bytes
);
640 print_stat(" TX bytes:", s
.tx_bytes
);
641 print_human_size(s
.tx_bytes
);
649 dpctl_show(int argc
, char *argv
[])
651 bool failure
= false;
654 for (i
= 1; i
< argc
; i
++) {
655 const char *name
= argv
[i
];
659 error
= parsed_dpif_open(name
, false, &dpif
);
663 ovs_error(error
, "opening datapath %s failed", name
);
672 dp_enumerate_types(&types
);
673 SSET_FOR_EACH (type
, &types
) {
678 if (dp_enumerate_names(type
, &names
)) {
682 SSET_FOR_EACH (name
, &names
) {
686 error
= dpif_open(name
, type
, &dpif
);
690 ovs_error(error
, "opening datapath %s failed", name
);
694 sset_destroy(&names
);
696 sset_destroy(&types
);
704 dpctl_dump_dps(int argc OVS_UNUSED
, char *argv
[] OVS_UNUSED
)
706 struct sset dpif_names
, dpif_types
;
710 sset_init(&dpif_names
);
711 sset_init(&dpif_types
);
712 dp_enumerate_types(&dpif_types
);
714 SSET_FOR_EACH (type
, &dpif_types
) {
718 retval
= dp_enumerate_names(type
, &dpif_names
);
723 SSET_FOR_EACH (name
, &dpif_names
) {
725 if (!dpif_open(name
, type
, &dpif
)) {
726 printf("%s\n", dpif_name(dpif
));
732 sset_destroy(&dpif_names
);
733 sset_destroy(&dpif_types
);
740 dpctl_dump_flows(int argc
, char *argv
[])
742 const struct dpif_flow_stats
*stats
;
743 const struct nlattr
*actions
;
744 struct dpif_flow_dump dump
;
745 const struct nlattr
*key
;
746 const struct nlattr
*mask
;
754 name
= (argc
== 2) ? xstrdup(argv
[1]) : get_one_dp();
755 run(parsed_dpif_open(name
, false, &dpif
), "opening datapath");
759 dpif_flow_dump_start(&dump
, dpif
);
760 while (dpif_flow_dump_next(&dump
, &key
, &key_len
,
762 &actions
, &actions_len
, &stats
)) {
764 odp_flow_format(key
, key_len
, mask
, mask_len
, &ds
);
765 ds_put_cstr(&ds
, ", ");
767 dpif_flow_stats_format(stats
, &ds
);
768 ds_put_cstr(&ds
, ", actions:");
769 format_odp_actions(&ds
, actions
, actions_len
);
770 printf("%s\n", ds_cstr(&ds
));
772 dpif_flow_dump_done(&dump
);
778 dpctl_put_flow(int argc
, char *argv
[], enum dpif_flow_put_flags flags
)
780 const char *key_s
= argv
[argc
- 2];
781 const char *actions_s
= argv
[argc
- 1];
782 struct dpif_flow_stats stats
;
783 struct ofpbuf actions
;
791 ofpbuf_init(&key
, 0);
792 ofpbuf_init(&mask
, 0);
793 run(odp_flow_from_string(key_s
, NULL
, &key
, &mask
), "parsing flow key");
795 ofpbuf_init(&actions
, 0);
796 run(odp_actions_from_string(actions_s
, NULL
, &actions
), "parsing actions");
798 dp_name
= argc
== 4 ? xstrdup(argv
[1]) : get_one_dp();
799 run(parsed_dpif_open(dp_name
, false, &dpif
), "opening datapath");
802 run(dpif_flow_put(dpif
, flags
,
804 mask
.size
== 0 ? NULL
: mask
.data
, mask
.size
,
805 actions
.data
, actions
.size
,
806 print_statistics
? &stats
: NULL
),
807 "updating flow table");
810 ofpbuf_uninit(&mask
);
811 ofpbuf_uninit(&actions
);
813 if (print_statistics
) {
817 dpif_flow_stats_format(&stats
, &s
);
824 dpctl_add_flow(int argc
, char *argv
[])
826 dpctl_put_flow(argc
, argv
, DPIF_FP_CREATE
);
830 dpctl_mod_flow(int argc OVS_UNUSED
, char *argv
[])
832 enum dpif_flow_put_flags flags
;
834 flags
= DPIF_FP_MODIFY
;
836 flags
|= DPIF_FP_CREATE
;
838 if (zero_statistics
) {
839 flags
|= DPIF_FP_ZERO_STATS
;
842 dpctl_put_flow(argc
, argv
, flags
);
846 dpctl_del_flow(int argc
, char *argv
[])
848 const char *key_s
= argv
[argc
- 1];
849 struct dpif_flow_stats stats
;
851 struct ofpbuf mask
; /* To be ignored. */
855 ofpbuf_init(&key
, 0);
856 ofpbuf_init(&mask
, 0);
857 run(odp_flow_from_string(key_s
, NULL
, &key
, &mask
), "parsing flow key");
859 dp_name
= argc
== 2 ? xstrdup(argv
[1]) : get_one_dp();
860 run(parsed_dpif_open(dp_name
, false, &dpif
), "opening datapath");
863 run(dpif_flow_del(dpif
,
865 print_statistics
? &stats
: NULL
), "deleting flow");
868 ofpbuf_uninit(&mask
);
870 if (print_statistics
) {
874 dpif_flow_stats_format(&stats
, &s
);
881 dpctl_del_flows(int argc
, char *argv
[])
886 name
= (argc
== 2) ? xstrdup(argv
[1]) : get_one_dp();
887 run(parsed_dpif_open(name
, false, &dpif
), "opening datapath");
890 run(dpif_flow_flush(dpif
), "deleting all flows");
895 dpctl_help(int argc OVS_UNUSED
, char *argv
[] OVS_UNUSED
)
900 /* Undocumented commands for unit testing. */
903 dpctl_parse_actions(int argc
, char *argv
[])
907 for (i
= 1; i
< argc
; i
++) {
908 struct ofpbuf actions
;
911 ofpbuf_init(&actions
, 0);
912 run(odp_actions_from_string(argv
[i
], NULL
, &actions
),
913 "odp_actions_from_string");
916 format_odp_actions(&s
, actions
.data
, actions
.size
);
920 ofpbuf_uninit(&actions
);
924 struct actions_for_flow
{
925 struct hmap_node hmap_node
;
927 struct ofpbuf actions
;
930 static struct actions_for_flow
*
931 get_actions_for_flow(struct hmap
*actions_per_flow
, const struct flow
*flow
)
933 uint32_t hash
= flow_hash(flow
, 0);
934 struct actions_for_flow
*af
;
936 HMAP_FOR_EACH_WITH_HASH (af
, hmap_node
, hash
, actions_per_flow
) {
937 if (flow_equal(&af
->flow
, flow
)) {
942 af
= xmalloc(sizeof *af
);
944 ofpbuf_init(&af
->actions
, 0);
945 hmap_insert(actions_per_flow
, &af
->hmap_node
, hash
);
950 compare_actions_for_flow(const void *a_
, const void *b_
)
952 struct actions_for_flow
*const *a
= a_
;
953 struct actions_for_flow
*const *b
= b_
;
955 return flow_compare_3way(&(*a
)->flow
, &(*b
)->flow
);
959 compare_output_actions(const void *a_
, const void *b_
)
961 const struct nlattr
*a
= a_
;
962 const struct nlattr
*b
= b_
;
963 uint32_t a_port
= nl_attr_get_u32(a
);
964 uint32_t b_port
= nl_attr_get_u32(b
);
966 return a_port
< b_port
? -1 : a_port
> b_port
;
970 sort_output_actions__(struct nlattr
*first
, struct nlattr
*end
)
972 size_t bytes
= (uint8_t *) end
- (uint8_t *) first
;
973 size_t n
= bytes
/ NL_A_U32_SIZE
;
975 ovs_assert(bytes
% NL_A_U32_SIZE
== 0);
976 qsort(first
, n
, NL_A_U32_SIZE
, compare_output_actions
);
980 sort_output_actions(struct nlattr
*actions
, size_t length
)
982 struct nlattr
*first_output
= NULL
;
986 NL_ATTR_FOR_EACH (a
, left
, actions
, length
) {
987 if (nl_attr_type(a
) == OVS_ACTION_ATTR_OUTPUT
) {
993 sort_output_actions__(first_output
, a
);
999 uint8_t *end
= (uint8_t *) actions
+ length
;
1000 sort_output_actions__(first_output
, (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
);
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");
1066 format_odp_actions(&s
, odp_actions
.data
, odp_actions
.size
);
1067 printf("input actions: %s\n", ds_cstr(&s
));
1070 hmap_init(&actions_per_flow
);
1071 NL_ATTR_FOR_EACH (a
, left
, odp_actions
.data
, odp_actions
.size
) {
1072 const struct ovs_action_push_vlan
*push
;
1073 switch(nl_attr_type(a
)) {
1074 case OVS_ACTION_ATTR_POP_VLAN
:
1075 flow
.vlan_tci
= htons(0);
1078 case OVS_ACTION_ATTR_PUSH_VLAN
:
1079 push
= nl_attr_get_unspec(a
, sizeof *push
);
1080 flow
.vlan_tci
= push
->vlan_tci
;
1084 af
= get_actions_for_flow(&actions_per_flow
, &flow
);
1085 nl_msg_put_unspec(&af
->actions
, nl_attr_type(a
),
1086 nl_attr_get(a
), nl_attr_get_size(a
));
1089 n_afs
= hmap_count(&actions_per_flow
);
1090 afs
= xmalloc(n_afs
* sizeof *afs
);
1092 HMAP_FOR_EACH (af
, hmap_node
, &actions_per_flow
) {
1095 ovs_assert(i
== n_afs
);
1097 qsort(afs
, n_afs
, sizeof *afs
, compare_actions_for_flow
);
1099 for (i
= 0; i
< n_afs
; i
++) {
1100 const struct actions_for_flow
*af
= afs
[i
];
1102 sort_output_actions(af
->actions
.data
, af
->actions
.size
);
1104 if (af
->flow
.vlan_tci
!= htons(0)) {
1105 printf("vlan(vid=%"PRIu16
",pcp=%d): ",
1106 vlan_tci_to_vid(af
->flow
.vlan_tci
),
1107 vlan_tci_to_pcp(af
->flow
.vlan_tci
));
1109 printf("no vlan: ");
1112 if (af
->flow
.mpls_depth
) {
1113 printf("mpls(label=%"PRIu32
",tc=%d,ttl=%d): ",
1114 mpls_lse_to_label(af
->flow
.mpls_lse
),
1115 mpls_lse_to_tc(af
->flow
.mpls_lse
),
1116 mpls_lse_to_ttl(af
->flow
.mpls_lse
));
1118 printf("no mpls: ");
1122 format_odp_actions(&s
, af
->actions
.data
, af
->actions
.size
);
1128 static const struct command all_commands
[] = {
1129 { "add-dp", 1, INT_MAX
, dpctl_add_dp
},
1130 { "del-dp", 1, 1, dpctl_del_dp
},
1131 { "add-if", 2, INT_MAX
, dpctl_add_if
},
1132 { "del-if", 2, INT_MAX
, dpctl_del_if
},
1133 { "set-if", 2, INT_MAX
, dpctl_set_if
},
1134 { "dump-dps", 0, 0, dpctl_dump_dps
},
1135 { "show", 0, INT_MAX
, dpctl_show
},
1136 { "dump-flows", 0, 1, dpctl_dump_flows
},
1137 { "add-flow", 2, 3, dpctl_add_flow
},
1138 { "mod-flow", 2, 3, dpctl_mod_flow
},
1139 { "del-flow", 1, 2, dpctl_del_flow
},
1140 { "del-flows", 0, 1, dpctl_del_flows
},
1141 { "help", 0, INT_MAX
, dpctl_help
},
1143 /* Undocumented commands for testing. */
1144 { "parse-actions", 1, INT_MAX
, dpctl_parse_actions
},
1145 { "normalize-actions", 2, INT_MAX
, dpctl_normalize_actions
},
1147 { NULL
, 0, 0, NULL
},