2 * Copyright (c) 2009 Nicira Networks.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #include "dynamic-string.h"
30 odp_actions_add(struct odp_actions *actions, uint16_t type)
33 if (actions->n_actions < MAX_ODP_ACTIONS) {
34 a = &actions->actions[actions->n_actions++];
36 COVERAGE_INC(odp_overflow);
37 actions->n_actions = MAX_ODP_ACTIONS + 1;
38 a = &actions->actions[MAX_ODP_ACTIONS - 1];
40 memset(a, 0, sizeof *a);
46 format_odp_action(struct ds *ds, const union odp_action *a)
50 ds_put_format(ds, "%"PRIu16, a->output.port);
52 case ODPAT_OUTPUT_GROUP:
53 ds_put_format(ds, "g%"PRIu16, a->output_group.group);
55 case ODPAT_CONTROLLER:
56 ds_put_format(ds, "ctl(%"PRIu32")", a->controller.arg);
58 case ODPAT_SET_VLAN_VID:
59 ds_put_format(ds, "set_vlan(%"PRIu16")", ntohs(a->vlan_vid.vlan_vid));
61 case ODPAT_SET_VLAN_PCP:
62 ds_put_format(ds, "set_vlan_pcp(%"PRIu8")", a->vlan_pcp.vlan_pcp);
64 case ODPAT_STRIP_VLAN:
65 ds_put_format(ds, "strip_vlan");
67 case ODPAT_SET_DL_SRC:
68 ds_put_format(ds, "set_dl_src("ETH_ADDR_FMT")",
69 ETH_ADDR_ARGS(a->dl_addr.dl_addr));
71 case ODPAT_SET_DL_DST:
72 ds_put_format(ds, "set_dl_dst("ETH_ADDR_FMT")",
73 ETH_ADDR_ARGS(a->dl_addr.dl_addr));
75 case ODPAT_SET_NW_SRC:
76 ds_put_format(ds, "set_nw_src("IP_FMT")",
77 IP_ARGS(&a->nw_addr.nw_addr));
79 case ODPAT_SET_NW_DST:
80 ds_put_format(ds, "set_nw_dst("IP_FMT")",
81 IP_ARGS(&a->nw_addr.nw_addr));
83 case ODPAT_SET_TP_SRC:
84 ds_put_format(ds, "set_tp_src(%"PRIu16")", ntohs(a->tp_port.tp_port));
86 case ODPAT_SET_TP_DST:
87 ds_put_format(ds, "set_tp_dst(%"PRIu16")", ntohs(a->tp_port.tp_port));
90 ds_put_format(ds, "***bad action %"PRIu16"***", a->type);
96 format_odp_actions(struct ds *ds, const union odp_action *actions,
100 for (i = 0; i < n_actions; i++) {
102 ds_put_char(ds, ',');
104 format_odp_action(ds, &actions[i]);
107 ds_put_cstr(ds, "drop");
112 format_odp_flow_stats(struct ds *ds, const struct odp_flow_stats *s)
114 ds_put_format(ds, "packets:%"PRIu64", bytes:%"PRIu64", used:",
115 s->n_packets, s->n_bytes);
117 long long int used = s->used_sec * 1000 + s->used_nsec / 1000000;
118 ds_put_format(ds, "%.3fs", (time_msec() - used) / 1000.0);
120 ds_put_format(ds, "never");
125 format_odp_flow(struct ds *ds, const struct odp_flow *f)
127 flow_format(ds, &f->key);
128 ds_put_cstr(ds, ", ");
129 format_odp_flow_stats(ds, &f->stats);
130 ds_put_cstr(ds, ", actions:");
131 format_odp_actions(ds, f->actions, f->n_actions);