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_flow_key(struct ds *ds, const struct odp_flow_key *key)
45 ds_put_format(ds, "tun_id0x%08x in_port%d tci(",
46 key->tun_id, key->in_port);
48 ds_put_format(ds, "vlan%"PRIu16",pcp%d",
49 vlan_tci_to_vid(key->dl_tci),
50 vlan_tci_to_pcp(key->dl_tci));
54 ds_put_format(ds, ") mac"ETH_ADDR_FMT"->"ETH_ADDR_FMT" type%04x "
55 "proto%"PRId8" tos%"PRIu8" ip"IP_FMT"->"IP_FMT" port%d->%d",
56 ETH_ADDR_ARGS(key->dl_src), ETH_ADDR_ARGS(key->dl_dst),
57 ntohs(key->dl_type), key->nw_proto, key->nw_tos,
58 IP_ARGS(&key->nw_src), IP_ARGS(&key->nw_dst),
59 ntohs(key->tp_src), ntohs(key->tp_dst));
63 format_odp_action(struct ds *ds, const union odp_action *a)
67 ds_put_format(ds, "%"PRIu16, a->output.port);
69 case ODPAT_CONTROLLER:
70 ds_put_format(ds, "ctl(%"PRIu32")", a->controller.arg);
72 case ODPAT_SET_TUNNEL:
73 ds_put_format(ds, "set_tunnel(0x%08"PRIx32")", ntohl(a->tunnel.tun_id));
75 case ODPAT_SET_DL_TCI:
76 ds_put_format(ds, "set_tci(vid=%"PRIu16",pcp=%d)",
77 vlan_tci_to_vid(a->dl_tci.tci),
78 vlan_tci_to_pcp(a->dl_tci.tci));
80 case ODPAT_STRIP_VLAN:
81 ds_put_format(ds, "strip_vlan");
83 case ODPAT_SET_DL_SRC:
84 ds_put_format(ds, "set_dl_src("ETH_ADDR_FMT")",
85 ETH_ADDR_ARGS(a->dl_addr.dl_addr));
87 case ODPAT_SET_DL_DST:
88 ds_put_format(ds, "set_dl_dst("ETH_ADDR_FMT")",
89 ETH_ADDR_ARGS(a->dl_addr.dl_addr));
91 case ODPAT_SET_NW_SRC:
92 ds_put_format(ds, "set_nw_src("IP_FMT")",
93 IP_ARGS(&a->nw_addr.nw_addr));
95 case ODPAT_SET_NW_DST:
96 ds_put_format(ds, "set_nw_dst("IP_FMT")",
97 IP_ARGS(&a->nw_addr.nw_addr));
99 case ODPAT_SET_NW_TOS:
100 ds_put_format(ds, "set_nw_tos(%"PRIu8")", a->nw_tos.nw_tos);
102 case ODPAT_SET_TP_SRC:
103 ds_put_format(ds, "set_tp_src(%"PRIu16")", ntohs(a->tp_port.tp_port));
105 case ODPAT_SET_TP_DST:
106 ds_put_format(ds, "set_tp_dst(%"PRIu16")", ntohs(a->tp_port.tp_port));
108 case ODPAT_SET_PRIORITY:
109 ds_put_format(ds, "set_priority(0x%"PRIx32")", a->priority.priority);
111 case ODPAT_POP_PRIORITY:
112 ds_put_cstr(ds, "pop_priority");
114 case ODPAT_DROP_SPOOFED_ARP:
115 ds_put_cstr(ds, "drop_spoofed_arp");
118 ds_put_format(ds, "***bad action 0x%"PRIx16"***", a->type);
124 format_odp_actions(struct ds *ds, const union odp_action *actions,
128 for (i = 0; i < n_actions; i++) {
130 ds_put_char(ds, ',');
132 format_odp_action(ds, &actions[i]);
135 ds_put_cstr(ds, "drop");
140 format_odp_flow_stats(struct ds *ds, const struct odp_flow_stats *s)
142 ds_put_format(ds, "packets:%llu, bytes:%llu, used:",
143 (unsigned long long int) s->n_packets,
144 (unsigned long long int) s->n_bytes);
146 long long int used = s->used_sec * 1000 + s->used_nsec / 1000000;
147 ds_put_format(ds, "%.3fs", (time_msec() - used) / 1000.0);
149 ds_put_format(ds, "never");
154 format_odp_flow(struct ds *ds, const struct odp_flow *f)
156 format_odp_flow_key(ds, &f->key);
157 ds_put_cstr(ds, ", ");
158 format_odp_flow_stats(ds, &f->stats);
159 ds_put_cstr(ds, ", actions:");
160 format_odp_actions(ds, f->actions, f->n_actions);
164 odp_flow_key_from_flow(struct odp_flow_key *key, const struct flow *flow)
166 key->tun_id = flow->tun_id;
167 key->nw_src = flow->nw_src;
168 key->nw_dst = flow->nw_dst;
169 key->in_port = flow->in_port;
170 key->dl_tci = flow->vlan_tci;
171 key->dl_type = flow->dl_type;
172 key->tp_src = flow->tp_src;
173 key->tp_dst = flow->tp_dst;
174 memcpy(key->dl_src, flow->dl_src, ETH_ADDR_LEN);
175 memcpy(key->dl_dst, flow->dl_dst, ETH_ADDR_LEN);
176 key->nw_proto = flow->nw_proto;
177 key->nw_tos = flow->nw_tos;
181 odp_flow_key_to_flow(const struct odp_flow_key *key, struct flow *flow)
183 memset(flow->regs, 0, sizeof flow->regs);
184 flow->tun_id = key->tun_id;
185 flow->nw_src = key->nw_src;
186 flow->nw_dst = key->nw_dst;
187 flow->in_port = key->in_port;
188 flow->vlan_tci = key->dl_tci;
189 flow->dl_type = key->dl_type;
190 flow->tp_src = key->tp_src;
191 flow->tp_dst = key->tp_dst;
192 memcpy(flow->dl_src, key->dl_src, ETH_ADDR_LEN);
193 memcpy(flow->dl_dst, key->dl_dst, ETH_ADDR_LEN);
194 flow->nw_proto = key->nw_proto;
195 flow->nw_tos = key->nw_tos;