2 * Copyright (c) 2009, 2010 Nicira Networks.
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.
23 #include "dynamic-string.h"
30 odp_actions_add(struct odp_actions *actions, uint16_t type)
35 idx = actions->n_actions++ & (MAX_ODP_ACTIONS - 1);
36 a = &actions->actions[idx];
37 memset(a, 0, sizeof *a);
43 format_odp_action(struct ds *ds, const union odp_action *a)
47 ds_put_format(ds, "%"PRIu16, a->output.port);
49 case ODPAT_OUTPUT_GROUP:
50 ds_put_format(ds, "g%"PRIu16, a->output_group.group);
52 case ODPAT_CONTROLLER:
53 ds_put_format(ds, "ctl(%"PRIu32")", a->controller.arg);
55 case ODPAT_SET_TUNNEL:
56 ds_put_format(ds, "set_tunnel(0x%08"PRIx32")", ntohl(a->tunnel.tun_id));
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_NW_TOS:
84 ds_put_format(ds, "set_nw_tos(%"PRIu8")", a->nw_tos.nw_tos);
86 case ODPAT_SET_TP_SRC:
87 ds_put_format(ds, "set_tp_src(%"PRIu16")", ntohs(a->tp_port.tp_port));
89 case ODPAT_SET_TP_DST:
90 ds_put_format(ds, "set_tp_dst(%"PRIu16")", ntohs(a->tp_port.tp_port));
92 case ODPAT_SET_PRIORITY:
93 ds_put_format(ds, "set_priority(0x%"PRIx32")", a->priority.priority);
95 case ODPAT_POP_PRIORITY:
96 ds_put_cstr(ds, "pop_priority");
99 ds_put_format(ds, "***bad action 0x%"PRIx16"***", a->type);
105 format_odp_actions(struct ds *ds, const union odp_action *actions,
109 for (i = 0; i < n_actions; i++) {
111 ds_put_char(ds, ',');
113 format_odp_action(ds, &actions[i]);
116 ds_put_cstr(ds, "drop");
121 format_odp_flow_stats(struct ds *ds, const struct odp_flow_stats *s)
123 ds_put_format(ds, "packets:%llu, bytes:%llu, used:",
124 (unsigned long long int) s->n_packets,
125 (unsigned long long int) s->n_bytes);
127 long long int used = s->used_sec * 1000 + s->used_nsec / 1000000;
128 ds_put_format(ds, "%.3fs", (time_msec() - used) / 1000.0);
130 ds_put_format(ds, "never");
135 format_odp_flow(struct ds *ds, const struct odp_flow *f)
137 flow_format(ds, &f->key);
138 ds_put_cstr(ds, ", ");
139 format_odp_flow_stats(ds, &f->stats);
140 ds_put_cstr(ds, ", actions:");
141 format_odp_actions(ds, f->actions, f->n_actions);