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 "ofp-actions.h"
20 #include "byte-order.h"
22 #include "dynamic-string.h"
24 #include "meta-flow.h"
25 #include "multipath.h"
32 VLOG_DEFINE_THIS_MODULE(ofp_actions);
34 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
36 /* Converting OpenFlow 1.0 to ofpacts. */
40 struct ofp_action_header header;
41 struct ofp_action_vendor_header vendor;
42 struct ofp10_action_output output10;
43 struct ofp_action_vlan_vid vlan_vid;
44 struct ofp_action_vlan_pcp vlan_pcp;
45 struct ofp_action_nw_addr nw_addr;
46 struct ofp_action_nw_tos nw_tos;
47 struct ofp11_action_nw_ecn nw_ecn;
48 struct ofp11_action_nw_ttl nw_ttl;
49 struct ofp_action_tp_port tp_port;
50 struct ofp_action_dl_addr dl_addr;
51 struct ofp10_action_enqueue enqueue;
52 struct ofp11_action_output ofp11_output;
53 struct ofp11_action_push push;
54 struct ofp11_action_pop_mpls ofp11_pop_mpls;
55 struct ofp11_action_set_queue ofp11_set_queue;
56 struct ofp11_action_mpls_ttl ofp11_mpls_ttl;
57 struct ofp11_action_group group;
58 struct ofp12_action_set_field set_field;
59 struct nx_action_header nxa_header;
60 struct nx_action_resubmit resubmit;
61 struct nx_action_set_tunnel set_tunnel;
62 struct nx_action_set_tunnel64 set_tunnel64;
63 struct nx_action_write_metadata write_metadata;
64 struct nx_action_set_queue set_queue;
65 struct nx_action_reg_move reg_move;
66 struct nx_action_reg_load reg_load;
67 struct nx_action_stack stack;
68 struct nx_action_note note;
69 struct nx_action_multipath multipath;
70 struct nx_action_bundle bundle;
71 struct nx_action_output_reg output_reg;
72 struct nx_action_cnt_ids cnt_ids;
73 struct nx_action_fin_timeout fin_timeout;
74 struct nx_action_controller controller;
75 struct nx_action_push_mpls push_mpls;
76 struct nx_action_mpls_ttl mpls_ttl;
77 struct nx_action_pop_mpls pop_mpls;
78 struct nx_action_sample sample;
79 struct nx_action_learn learn;
83 output_from_openflow10(const struct ofp10_action_output *oao,
86 struct ofpact_output *output;
88 output = ofpact_put_OUTPUT(out);
89 output->port = u16_to_ofp(ntohs(oao->port));
90 output->max_len = ntohs(oao->max_len);
92 return ofpact_check_output_port(output->port, OFPP_MAX);
96 enqueue_from_openflow10(const struct ofp10_action_enqueue *oae,
99 struct ofpact_enqueue *enqueue;
101 enqueue = ofpact_put_ENQUEUE(out);
102 enqueue->port = u16_to_ofp(ntohs(oae->port));
103 enqueue->queue = ntohl(oae->queue_id);
104 if (ofp_to_u16(enqueue->port) >= ofp_to_u16(OFPP_MAX)
105 && enqueue->port != OFPP_IN_PORT
106 && enqueue->port != OFPP_LOCAL) {
107 return OFPERR_OFPBAC_BAD_OUT_PORT;
113 resubmit_from_openflow(const struct nx_action_resubmit *nar,
116 struct ofpact_resubmit *resubmit;
118 resubmit = ofpact_put_RESUBMIT(out);
119 resubmit->ofpact.compat = OFPUTIL_NXAST_RESUBMIT;
120 resubmit->in_port = u16_to_ofp(ntohs(nar->in_port));
121 resubmit->table_id = 0xff;
125 resubmit_table_from_openflow(const struct nx_action_resubmit *nar,
128 struct ofpact_resubmit *resubmit;
130 if (nar->pad[0] || nar->pad[1] || nar->pad[2]) {
131 return OFPERR_OFPBAC_BAD_ARGUMENT;
134 resubmit = ofpact_put_RESUBMIT(out);
135 resubmit->ofpact.compat = OFPUTIL_NXAST_RESUBMIT_TABLE;
136 resubmit->in_port = u16_to_ofp(ntohs(nar->in_port));
137 resubmit->table_id = nar->table;
142 output_reg_from_openflow(const struct nx_action_output_reg *naor,
145 struct ofpact_output_reg *output_reg;
147 if (!is_all_zeros(naor->zero, sizeof naor->zero)) {
148 return OFPERR_OFPBAC_BAD_ARGUMENT;
151 output_reg = ofpact_put_OUTPUT_REG(out);
152 output_reg->src.field = mf_from_nxm_header(ntohl(naor->src));
153 output_reg->src.ofs = nxm_decode_ofs(naor->ofs_nbits);
154 output_reg->src.n_bits = nxm_decode_n_bits(naor->ofs_nbits);
155 output_reg->max_len = ntohs(naor->max_len);
157 return mf_check_src(&output_reg->src, NULL);
161 fin_timeout_from_openflow(const struct nx_action_fin_timeout *naft,
164 struct ofpact_fin_timeout *oft;
166 oft = ofpact_put_FIN_TIMEOUT(out);
167 oft->fin_idle_timeout = ntohs(naft->fin_idle_timeout);
168 oft->fin_hard_timeout = ntohs(naft->fin_hard_timeout);
172 controller_from_openflow(const struct nx_action_controller *nac,
175 struct ofpact_controller *oc;
177 oc = ofpact_put_CONTROLLER(out);
178 oc->max_len = ntohs(nac->max_len);
179 oc->controller_id = ntohs(nac->controller_id);
180 oc->reason = nac->reason;
184 metadata_from_nxast(const struct nx_action_write_metadata *nawm,
187 struct ofpact_metadata *om;
189 if (!is_all_zeros(nawm->zeros, sizeof nawm->zeros)) {
190 return OFPERR_NXBRC_MUST_BE_ZERO;
193 om = ofpact_put_WRITE_METADATA(out);
194 om->metadata = nawm->metadata;
195 om->mask = nawm->mask;
201 note_from_openflow(const struct nx_action_note *nan, struct ofpbuf *out)
203 struct ofpact_note *note;
206 length = ntohs(nan->len) - offsetof(struct nx_action_note, note);
207 note = ofpact_put(out, OFPACT_NOTE,
208 offsetof(struct ofpact_note, data) + length);
209 note->length = length;
210 memcpy(note->data, nan->note, length);
214 dec_ttl_from_openflow(struct ofpbuf *out, enum ofputil_action_code compat)
217 struct ofpact_cnt_ids *ids;
218 enum ofperr error = 0;
220 ids = ofpact_put_DEC_TTL(out);
221 ids->ofpact.compat = compat;
222 ids->n_controllers = 1;
223 ofpbuf_put(out, &id, sizeof id);
225 ofpact_update_len(out, &ids->ofpact);
230 dec_ttl_cnt_ids_from_openflow(const struct nx_action_cnt_ids *nac_ids,
233 struct ofpact_cnt_ids *ids;
237 ids = ofpact_put_DEC_TTL(out);
238 ids->ofpact.compat = OFPUTIL_NXAST_DEC_TTL_CNT_IDS;
239 ids->n_controllers = ntohs(nac_ids->n_controllers);
240 ids_size = ntohs(nac_ids->len) - sizeof *nac_ids;
242 if (!is_all_zeros(nac_ids->zeros, sizeof nac_ids->zeros)) {
243 return OFPERR_NXBRC_MUST_BE_ZERO;
246 if (ids_size < ids->n_controllers * sizeof(ovs_be16)) {
247 VLOG_WARN_RL(&rl, "Nicira action dec_ttl_cnt_ids only has %zu bytes "
248 "allocated for controller ids. %zu bytes are required for "
249 "%"PRIu16" controllers.", ids_size,
250 ids->n_controllers * sizeof(ovs_be16), ids->n_controllers);
251 return OFPERR_OFPBAC_BAD_LEN;
254 for (i = 0; i < ids->n_controllers; i++) {
255 uint16_t id = ntohs(((ovs_be16 *)(nac_ids + 1))[i]);
256 ofpbuf_put(out, &id, sizeof id);
260 ofpact_update_len(out, &ids->ofpact);
266 sample_from_openflow(const struct nx_action_sample *nas,
269 struct ofpact_sample *sample;
271 sample = ofpact_put_SAMPLE(out);
272 sample->probability = ntohs(nas->probability);
273 sample->collector_set_id = ntohl(nas->collector_set_id);
274 sample->obs_domain_id = ntohl(nas->obs_domain_id);
275 sample->obs_point_id = ntohl(nas->obs_point_id);
277 if (sample->probability == 0) {
278 return OFPERR_OFPBAC_BAD_ARGUMENT;
285 push_mpls_from_openflow(ovs_be16 ethertype, enum ofpact_mpls_position position,
288 struct ofpact_push_mpls *oam;
290 if (!eth_type_mpls(ethertype)) {
291 return OFPERR_OFPBAC_BAD_ARGUMENT;
293 oam = ofpact_put_PUSH_MPLS(out);
294 oam->ethertype = ethertype;
295 oam->position = position;
301 decode_nxast_action(const union ofp_action *a, enum ofputil_action_code *code)
303 const struct nx_action_header *nah = &a->nxa_header;
304 uint16_t len = ntohs(a->header.len);
306 if (len < sizeof(struct nx_action_header)) {
307 return OFPERR_OFPBAC_BAD_LEN;
308 } else if (a->vendor.vendor != CONSTANT_HTONL(NX_VENDOR_ID)) {
309 return OFPERR_OFPBAC_BAD_VENDOR;
312 switch (nah->subtype) {
313 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
314 case CONSTANT_HTONS(ENUM): \
316 ? len >= sizeof(struct STRUCT) \
317 : len == sizeof(struct STRUCT)) { \
318 *code = OFPUTIL_##ENUM; \
321 return OFPERR_OFPBAC_BAD_LEN; \
324 #include "ofp-util.def"
326 case CONSTANT_HTONS(NXAST_SNAT__OBSOLETE):
327 case CONSTANT_HTONS(NXAST_DROP_SPOOFED_ARP__OBSOLETE):
329 return OFPERR_OFPBAC_BAD_TYPE;
333 /* Parses 'a' to determine its type. On success stores the correct type into
334 * '*code' and returns 0. On failure returns an OFPERR_* error code and
335 * '*code' is indeterminate.
337 * The caller must have already verified that 'a''s length is potentially
338 * correct (that is, a->header.len is nonzero and a multiple of
339 * OFP_ACTION_ALIGN and no longer than the amount of space allocated to 'a').
341 * This function verifies that 'a''s length is correct for the type of action
342 * that it represents. */
344 decode_openflow10_action(const union ofp_action *a,
345 enum ofputil_action_code *code)
348 case CONSTANT_HTONS(OFPAT10_VENDOR):
349 return decode_nxast_action(a, code);
351 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \
352 case CONSTANT_HTONS(ENUM): \
353 if (a->header.len == htons(sizeof(struct STRUCT))) { \
354 *code = OFPUTIL_##ENUM; \
357 return OFPERR_OFPBAC_BAD_LEN; \
360 #include "ofp-util.def"
363 return OFPERR_OFPBAC_BAD_TYPE;
368 ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code,
371 struct ofpact_tunnel *tunnel;
372 enum ofperr error = 0;
375 case OFPUTIL_ACTION_INVALID:
376 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM:
377 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
378 #include "ofp-util.def"
381 case OFPUTIL_NXAST_RESUBMIT:
382 resubmit_from_openflow(&a->resubmit, out);
385 case OFPUTIL_NXAST_SET_TUNNEL:
386 tunnel = ofpact_put_SET_TUNNEL(out);
387 tunnel->ofpact.compat = code;
388 tunnel->tun_id = ntohl(a->set_tunnel.tun_id);
391 case OFPUTIL_NXAST_WRITE_METADATA:
392 error = metadata_from_nxast(&a->write_metadata, out);
395 case OFPUTIL_NXAST_SET_QUEUE:
396 ofpact_put_SET_QUEUE(out)->queue_id = ntohl(a->set_queue.queue_id);
399 case OFPUTIL_NXAST_POP_QUEUE:
400 ofpact_put_POP_QUEUE(out);
403 case OFPUTIL_NXAST_REG_MOVE:
404 error = nxm_reg_move_from_openflow(&a->reg_move, out);
407 case OFPUTIL_NXAST_REG_LOAD:
408 error = nxm_reg_load_from_openflow(&a->reg_load, out);
411 case OFPUTIL_NXAST_STACK_PUSH:
412 error = nxm_stack_push_from_openflow(&a->stack, out);
415 case OFPUTIL_NXAST_STACK_POP:
416 error = nxm_stack_pop_from_openflow(&a->stack, out);
419 case OFPUTIL_NXAST_NOTE:
420 note_from_openflow(&a->note, out);
423 case OFPUTIL_NXAST_SET_TUNNEL64:
424 tunnel = ofpact_put_SET_TUNNEL(out);
425 tunnel->ofpact.compat = code;
426 tunnel->tun_id = ntohll(a->set_tunnel64.tun_id);
429 case OFPUTIL_NXAST_MULTIPATH:
430 error = multipath_from_openflow(&a->multipath,
431 ofpact_put_MULTIPATH(out));
434 case OFPUTIL_NXAST_BUNDLE:
435 case OFPUTIL_NXAST_BUNDLE_LOAD:
436 error = bundle_from_openflow(&a->bundle, out);
439 case OFPUTIL_NXAST_OUTPUT_REG:
440 error = output_reg_from_openflow(&a->output_reg, out);
443 case OFPUTIL_NXAST_RESUBMIT_TABLE:
444 error = resubmit_table_from_openflow(&a->resubmit, out);
447 case OFPUTIL_NXAST_LEARN:
448 error = learn_from_openflow(&a->learn, out);
451 case OFPUTIL_NXAST_EXIT:
452 ofpact_put_EXIT(out);
455 case OFPUTIL_NXAST_DEC_TTL:
456 error = dec_ttl_from_openflow(out, code);
459 case OFPUTIL_NXAST_DEC_TTL_CNT_IDS:
460 error = dec_ttl_cnt_ids_from_openflow(&a->cnt_ids, out);
463 case OFPUTIL_NXAST_FIN_TIMEOUT:
464 fin_timeout_from_openflow(&a->fin_timeout, out);
467 case OFPUTIL_NXAST_CONTROLLER:
468 controller_from_openflow(&a->controller, out);
471 case OFPUTIL_NXAST_PUSH_MPLS:
472 error = push_mpls_from_openflow(a->push_mpls.ethertype,
473 OFPACT_MPLS_AFTER_VLAN, out);
476 case OFPUTIL_NXAST_SET_MPLS_TTL:
477 ofpact_put_SET_MPLS_TTL(out)->ttl = a->mpls_ttl.ttl;
480 case OFPUTIL_NXAST_DEC_MPLS_TTL:
481 ofpact_put_DEC_MPLS_TTL(out);
484 case OFPUTIL_NXAST_POP_MPLS:
485 if (eth_type_mpls(a->pop_mpls.ethertype)) {
486 return OFPERR_OFPBAC_BAD_ARGUMENT;
488 ofpact_put_POP_MPLS(out)->ethertype = a->pop_mpls.ethertype;
491 case OFPUTIL_NXAST_SAMPLE:
492 error = sample_from_openflow(&a->sample, out);
500 ofpact_from_openflow10(const union ofp_action *a,
501 enum ofp_version version OVS_UNUSED,
504 enum ofputil_action_code code;
506 struct ofpact_vlan_vid *vlan_vid;
507 struct ofpact_vlan_pcp *vlan_pcp;
509 error = decode_openflow10_action(a, &code);
515 case OFPUTIL_ACTION_INVALID:
516 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
517 #include "ofp-util.def"
520 case OFPUTIL_OFPAT10_OUTPUT:
521 return output_from_openflow10(&a->output10, out);
523 case OFPUTIL_OFPAT10_SET_VLAN_VID:
524 if (a->vlan_vid.vlan_vid & ~htons(0xfff)) {
525 return OFPERR_OFPBAC_BAD_ARGUMENT;
527 vlan_vid = ofpact_put_SET_VLAN_VID(out);
528 vlan_vid->vlan_vid = ntohs(a->vlan_vid.vlan_vid);
529 vlan_vid->push_vlan_if_needed = true;
530 vlan_vid->ofpact.compat = code;
533 case OFPUTIL_OFPAT10_SET_VLAN_PCP:
534 if (a->vlan_pcp.vlan_pcp & ~7) {
535 return OFPERR_OFPBAC_BAD_ARGUMENT;
537 vlan_pcp = ofpact_put_SET_VLAN_PCP(out);
538 vlan_pcp->vlan_pcp = a->vlan_pcp.vlan_pcp;
539 vlan_pcp->push_vlan_if_needed = true;
540 vlan_pcp->ofpact.compat = code;
543 case OFPUTIL_OFPAT10_STRIP_VLAN:
544 ofpact_put_STRIP_VLAN(out)->ofpact.compat = code;
547 case OFPUTIL_OFPAT10_SET_DL_SRC:
548 memcpy(ofpact_put_SET_ETH_SRC(out)->mac, a->dl_addr.dl_addr,
552 case OFPUTIL_OFPAT10_SET_DL_DST:
553 memcpy(ofpact_put_SET_ETH_DST(out)->mac, a->dl_addr.dl_addr,
557 case OFPUTIL_OFPAT10_SET_NW_SRC:
558 ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr;
561 case OFPUTIL_OFPAT10_SET_NW_DST:
562 ofpact_put_SET_IPV4_DST(out)->ipv4 = a->nw_addr.nw_addr;
565 case OFPUTIL_OFPAT10_SET_NW_TOS:
566 if (a->nw_tos.nw_tos & ~IP_DSCP_MASK) {
567 return OFPERR_OFPBAC_BAD_ARGUMENT;
569 ofpact_put_SET_IP_DSCP(out)->dscp = a->nw_tos.nw_tos;
572 case OFPUTIL_OFPAT10_SET_TP_SRC:
573 ofpact_put_SET_L4_SRC_PORT(out)->port = ntohs(a->tp_port.tp_port);
576 case OFPUTIL_OFPAT10_SET_TP_DST:
577 ofpact_put_SET_L4_DST_PORT(out)->port = ntohs(a->tp_port.tp_port);
581 case OFPUTIL_OFPAT10_ENQUEUE:
582 error = enqueue_from_openflow10(&a->enqueue, out);
585 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
586 #include "ofp-util.def"
587 return ofpact_from_nxast(a, code, out);
593 static enum ofperr ofpact_from_openflow11(const union ofp_action *,
597 static inline union ofp_action *
598 action_next(const union ofp_action *a)
600 return ((union ofp_action *) (void *)
601 ((uint8_t *) a + ntohs(a->header.len)));
605 action_is_valid(const union ofp_action *a, size_t max_actions)
607 uint16_t len = ntohs(a->header.len);
608 return (!(len % OFP_ACTION_ALIGN)
609 && len >= OFP_ACTION_ALIGN
610 && len / OFP_ACTION_ALIGN <= max_actions);
613 /* This macro is careful to check for actions with bad lengths. */
614 #define ACTION_FOR_EACH(ITER, LEFT, ACTIONS, MAX_ACTIONS) \
615 for ((ITER) = (ACTIONS), (LEFT) = (MAX_ACTIONS); \
616 (LEFT) > 0 && action_is_valid(ITER, LEFT); \
617 ((LEFT) -= ntohs((ITER)->header.len) / OFP_ACTION_ALIGN, \
618 (ITER) = action_next(ITER)))
621 log_bad_action(const union ofp_action *actions, size_t max_actions,
622 const union ofp_action *bad_action, enum ofperr error)
624 if (!VLOG_DROP_WARN(&rl)) {
628 ds_put_hex_dump(&s, actions, max_actions * OFP_ACTION_ALIGN, 0, false);
629 VLOG_WARN("bad action at offset %#tx (%s):\n%s",
630 (char *)bad_action - (char *)actions,
631 ofperr_get_name(error), ds_cstr(&s));
637 ofpacts_from_openflow(const union ofp_action *in, size_t n_in,
638 enum ofp_version version, struct ofpbuf *out)
640 const union ofp_action *a;
643 enum ofperr (*ofpact_from_openflow)(const union ofp_action *a,
645 struct ofpbuf *out) =
646 (version == OFP10_VERSION) ?
647 ofpact_from_openflow10 : ofpact_from_openflow11;
649 ACTION_FOR_EACH (a, left, in, n_in) {
650 enum ofperr error = ofpact_from_openflow(a, version, out);
652 log_bad_action(in, n_in, a, error);
657 enum ofperr error = OFPERR_OFPBAC_BAD_LEN;
658 log_bad_action(in, n_in, a, error);
666 /* Attempts to convert 'actions_len' bytes of OpenFlow actions from the
667 * front of 'openflow' into ofpacts. On success, replaces any existing content
668 * in 'ofpacts' by the converted ofpacts; on failure, clears 'ofpacts'.
669 * Returns 0 if successful, otherwise an OpenFlow error.
671 * Actions are processed according to their OpenFlow version which
672 * is provided in the 'version' parameter.
674 * In most places in OpenFlow 1.1 and 1.2, actions appear encapsulated in
675 * instructions, so you should call ofpacts_pull_openflow_instructions()
676 * instead of this function.
678 * The parsed actions are valid generically, but they may not be valid in a
679 * specific context. For example, port numbers up to OFPP_MAX are valid
680 * generically, but specific datapaths may only support port numbers in a
681 * smaller range. Use ofpacts_check() to additional check whether actions are
682 * valid in a specific context. */
684 ofpacts_pull_openflow_actions(struct ofpbuf *openflow,
685 unsigned int actions_len,
686 enum ofp_version version,
687 struct ofpbuf *ofpacts) {
688 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
689 const union ofp_action *actions;
692 ofpbuf_clear(ofpacts);
694 if (actions_len % OFP_ACTION_ALIGN != 0) {
695 VLOG_WARN_RL(&rl, "OpenFlow message actions length %u is not a "
696 "multiple of %d", actions_len, OFP_ACTION_ALIGN);
697 return OFPERR_OFPBRC_BAD_LEN;
700 actions = ofpbuf_try_pull(openflow, actions_len);
701 if (actions == NULL) {
702 VLOG_WARN_RL(&rl, "OpenFlow message actions length %u exceeds "
703 "remaining message length (%zu)",
704 actions_len, openflow->size);
705 return OFPERR_OFPBRC_BAD_LEN;
708 error = ofpacts_from_openflow(actions, actions_len / OFP_ACTION_ALIGN,
711 ofpbuf_clear(ofpacts);
715 error = ofpacts_verify(ofpacts->data, ofpacts->size);
717 ofpbuf_clear(ofpacts);
723 /* OpenFlow 1.1 actions. */
725 /* Parses 'a' to determine its type. On success stores the correct type into
726 * '*code' and returns 0. On failure returns an OFPERR_* error code and
727 * '*code' is indeterminate.
729 * The caller must have already verified that 'a''s length is potentially
730 * correct (that is, a->header.len is nonzero and a multiple of
731 * OFP_ACTION_ALIGN and no longer than the amount of space allocated to 'a').
733 * This function verifies that 'a''s length is correct for the type of action
734 * that it represents. */
736 decode_openflow11_action(const union ofp_action *a,
737 enum ofputil_action_code *code)
742 case CONSTANT_HTONS(OFPAT11_EXPERIMENTER):
743 return decode_nxast_action(a, code);
745 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \
746 case CONSTANT_HTONS(ENUM): \
747 len = ntohs(a->header.len); \
749 ? len >= sizeof(struct STRUCT) \
750 : len == sizeof(struct STRUCT)) { \
751 *code = OFPUTIL_##ENUM; \
754 return OFPERR_OFPBAC_BAD_LEN; \
757 #include "ofp-util.def"
760 return OFPERR_OFPBAC_BAD_TYPE;
765 set_field_from_openflow(const struct ofp12_action_set_field *oasf,
766 struct ofpbuf *ofpacts)
768 uint16_t oasf_len = ntohs(oasf->len);
769 uint32_t oxm_header = ntohl(oasf->dst);
770 uint8_t oxm_length = NXM_LENGTH(oxm_header);
771 struct ofpact_set_field *sf;
772 const struct mf_field *mf;
774 /* ofp12_action_set_field is padded to 64 bits by zero */
775 if (oasf_len != ROUND_UP(sizeof *oasf + oxm_length, 8)) {
776 return OFPERR_OFPBAC_BAD_SET_LEN;
778 if (!is_all_zeros((const uint8_t *)oasf + sizeof *oasf + oxm_length,
779 oasf_len - oxm_length - sizeof *oasf)) {
780 return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
783 if (NXM_HASMASK(oxm_header)) {
784 return OFPERR_OFPBAC_BAD_SET_TYPE;
786 mf = mf_from_nxm_header(oxm_header);
788 return OFPERR_OFPBAC_BAD_SET_TYPE;
790 ovs_assert(mf->n_bytes == oxm_length);
791 /* oxm_length is now validated to be compatible with mf_value. */
793 VLOG_WARN_RL(&rl, "destination field %s is not writable", mf->name);
794 return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
796 sf = ofpact_put_SET_FIELD(ofpacts);
798 memcpy(&sf->value, oasf + 1, mf->n_bytes);
800 /* The value must be valid for match and must have the OFPVID_PRESENT bit
801 * on for OXM_OF_VLAN_VID. */
802 if (!mf_is_value_valid(mf, &sf->value)
803 || (mf->id == MFF_VLAN_VID
804 && !(sf->value.be16 & htons(OFPVID12_PRESENT)))) {
805 struct ds ds = DS_EMPTY_INITIALIZER;
806 mf_format(mf, &sf->value, NULL, &ds);
807 VLOG_WARN_RL(&rl, "Invalid value for set field %s: %s",
808 mf->name, ds_cstr(&ds));
811 return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
817 set_field_to_openflow12(const struct ofpact_set_field *sf,
818 struct ofpbuf *openflow)
820 uint16_t padded_value_len = ROUND_UP(sf->field->n_bytes, 8);
821 struct ofp12_action_set_field *oasf;
824 oasf = ofputil_put_OFPAT12_SET_FIELD(openflow);
825 oasf->dst = htonl(sf->field->oxm_header);
826 oasf->len = htons(sizeof *oasf + padded_value_len);
828 value = ofpbuf_put_zeros(openflow, padded_value_len);
829 memcpy(value, &sf->value, sf->field->n_bytes);
832 /* Convert 'sf' to one or two REG_LOADs. */
834 set_field_to_nxast(const struct ofpact_set_field *sf, struct ofpbuf *openflow)
836 const struct mf_field *mf = sf->field;
837 struct nx_action_reg_load *narl;
839 if (mf->n_bits > 64) {
840 ovs_assert(mf->n_bytes == 16); /* IPv6 addr. */
841 /* Split into 64bit chunks */
842 /* Lower bits first. */
843 narl = ofputil_put_NXAST_REG_LOAD(openflow);
844 narl->ofs_nbits = nxm_encode_ofs_nbits(0, 64);
845 narl->dst = htonl(mf->nxm_header);
846 memcpy(&narl->value, &sf->value.ipv6.s6_addr[8], sizeof narl->value);
847 /* Higher bits next. */
848 narl = ofputil_put_NXAST_REG_LOAD(openflow);
849 narl->ofs_nbits = nxm_encode_ofs_nbits(64, mf->n_bits - 64);
850 narl->dst = htonl(mf->nxm_header);
851 memcpy(&narl->value, &sf->value.ipv6.s6_addr[0], sizeof narl->value);
853 narl = ofputil_put_NXAST_REG_LOAD(openflow);
854 narl->ofs_nbits = nxm_encode_ofs_nbits(0, mf->n_bits);
855 narl->dst = htonl(mf->nxm_header);
856 memset(&narl->value, 0, 8 - mf->n_bytes);
857 memcpy((char*)&narl->value + (8 - mf->n_bytes),
858 &sf->value, mf->n_bytes);
862 /* Convert 'sf' to standard OpenFlow 1.1 actions, if we can, falling back
863 * to Nicira extensions if we must.
865 * We check only meta-flow types that can appear within set field actions and
866 * that have a mapping to compatible action types. These struct mf_field
867 * definitions have a defined OXM or NXM header value and specify the field as
870 set_field_to_openflow11(const struct ofpact_set_field *sf,
871 struct ofpbuf *openflow)
873 switch ((int) sf->field->id) {
875 /* NXM_OF_VLAN_TCI to OpenFlow 1.1 mapping:
877 * If CFI=1, Add or modify VLAN VID & PCP.
878 * OpenFlow 1.1 set actions only apply if the packet
879 * already has VLAN tags. To be sure that is the case
880 * we have to push a VLAN header. As we do not support
881 * multiple layers of VLANs, this is a no-op, if a VLAN
882 * header already exists. This may backfire, however,
883 * when we start supporting multiple layers of VLANs.
884 * If CFI=0, strip VLAN header, if any.
886 if (sf->value.be16 & htons(VLAN_CFI)) {
887 /* Push a VLAN tag, if one was not seen at action validation
889 if (!sf->flow_has_vlan) {
890 ofputil_put_OFPAT11_PUSH_VLAN(openflow)->ethertype
891 = htons(ETH_TYPE_VLAN_8021Q);
893 ofputil_put_OFPAT11_SET_VLAN_VID(openflow)->vlan_vid
894 = sf->value.be16 & htons(VLAN_VID_MASK);
895 ofputil_put_OFPAT11_SET_VLAN_PCP(openflow)->vlan_pcp
896 = vlan_tci_to_pcp(sf->value.be16);
898 /* If the flow did not match on vlan, we have no way of
899 * knowing if the vlan tag exists, so we must POP just to be
901 ofputil_put_OFPAT11_POP_VLAN(openflow);
906 /* OXM VLAN_PCP to OpenFlow 1.1.
907 * Set field on OXM_OF_VLAN_VID onlyapplies to an existing vlan
908 * tag. Clear the OFPVID_PRESENT bit.
910 ofputil_put_OFPAT11_SET_VLAN_VID(openflow)->vlan_vid
911 = sf->value.be16 & htons(VLAN_VID_MASK);
915 /* OXM VLAN_PCP to OpenFlow 1.1.
916 * OXM_OF_VLAN_PCP only applies to existing vlan tag. */
917 ofputil_put_OFPAT11_SET_VLAN_PCP(openflow)->vlan_pcp = sf->value.u8;
921 memcpy(ofputil_put_OFPAT11_SET_DL_SRC(openflow)->dl_addr,
922 sf->value.mac, ETH_ADDR_LEN);
926 memcpy(ofputil_put_OFPAT11_SET_DL_DST(openflow)->dl_addr,
927 sf->value.mac, ETH_ADDR_LEN);
931 ofputil_put_OFPAT11_SET_NW_SRC(openflow)->nw_addr = sf->value.be32;
935 ofputil_put_OFPAT11_SET_NW_DST(openflow)->nw_addr = sf->value.be32;
939 ofputil_put_OFPAT11_SET_NW_TOS(openflow)->nw_tos = sf->value.u8;
942 case MFF_IP_DSCP_SHIFTED:
943 ofputil_put_OFPAT11_SET_NW_TOS(openflow)->nw_tos = sf->value.u8 << 2;
947 ofputil_put_OFPAT11_SET_NW_ECN(openflow)->nw_ecn = sf->value.u8;
951 ofputil_put_OFPAT11_SET_NW_TTL(openflow)->nw_ttl = sf->value.u8;
957 ofputil_put_OFPAT11_SET_TP_SRC(openflow)->tp_port = sf->value.be16;
963 ofputil_put_OFPAT11_SET_TP_DST(openflow)->tp_port = sf->value.be16;
966 case MFF_MPLS_TC: /* XXX */
967 case MFF_MPLS_LABEL: /* XXX */
969 set_field_to_nxast(sf, openflow);
974 /* Convert 'sf' to standard OpenFlow 1.0 actions, if we can, falling back
975 * to Nicira extensions if we must.
977 * We check only meta-flow types that can appear within set field actions and
978 * that have a mapping to compatible action types. These struct mf_field
979 * definitions have a defined OXM or NXM header value and specify the field as
982 set_field_to_openflow10(const struct ofpact_set_field *sf,
983 struct ofpbuf *openflow)
985 switch ((int) sf->field->id) {
987 /* NXM_OF_VLAN_TCI to OpenFlow 1.0 mapping:
989 * If CFI=1, Add or modify VLAN VID & PCP.
990 * If CFI=0, strip VLAN header, if any.
992 if (sf->value.be16 & htons(VLAN_CFI)) {
993 ofputil_put_OFPAT10_SET_VLAN_VID(openflow)->vlan_vid
994 = sf->value.be16 & htons(VLAN_VID_MASK);
995 ofputil_put_OFPAT10_SET_VLAN_PCP(openflow)->vlan_pcp
996 = vlan_tci_to_pcp(sf->value.be16);
998 ofputil_put_OFPAT10_STRIP_VLAN(openflow);
1003 /* OXM VLAN_VID to OpenFlow 1.0.
1004 * Set field on OXM_OF_VLAN_VID onlyapplies to an existing vlan
1005 * tag. Clear the OFPVID_PRESENT bit.
1007 ofputil_put_OFPAT10_SET_VLAN_VID(openflow)->vlan_vid
1008 = sf->value.be16 & htons(VLAN_VID_MASK);
1012 /* OXM VLAN_PCP to OpenFlow 1.0.
1013 * OXM_OF_VLAN_PCP only applies to existing vlan tag. */
1014 ofputil_put_OFPAT10_SET_VLAN_PCP(openflow)->vlan_pcp = sf->value.u8;
1018 memcpy(ofputil_put_OFPAT10_SET_DL_SRC(openflow)->dl_addr,
1019 sf->value.mac, ETH_ADDR_LEN);
1023 memcpy(ofputil_put_OFPAT10_SET_DL_DST(openflow)->dl_addr,
1024 sf->value.mac, ETH_ADDR_LEN);
1028 ofputil_put_OFPAT10_SET_NW_SRC(openflow)->nw_addr = sf->value.be32;
1032 ofputil_put_OFPAT10_SET_NW_DST(openflow)->nw_addr = sf->value.be32;
1036 ofputil_put_OFPAT10_SET_NW_TOS(openflow)->nw_tos = sf->value.u8;
1039 case MFF_IP_DSCP_SHIFTED:
1040 ofputil_put_OFPAT10_SET_NW_TOS(openflow)->nw_tos = sf->value.u8 << 2;
1045 ofputil_put_OFPAT10_SET_TP_SRC(openflow)->tp_port = sf->value.be16;
1050 ofputil_put_OFPAT10_SET_TP_DST(openflow)->tp_port = sf->value.be16;
1054 set_field_to_nxast(sf, openflow);
1060 set_field_to_openflow(const struct ofpact_set_field *sf,
1061 struct ofpbuf *openflow)
1063 struct ofp_header *oh = (struct ofp_header *)openflow->l2;
1065 if (oh->version >= OFP12_VERSION) {
1066 set_field_to_openflow12(sf, openflow);
1067 } else if (oh->version == OFP11_VERSION) {
1068 set_field_to_openflow11(sf, openflow);
1069 } else if (oh->version == OFP10_VERSION) {
1070 set_field_to_openflow10(sf, openflow);
1077 output_from_openflow11(const struct ofp11_action_output *oao,
1080 struct ofpact_output *output;
1083 output = ofpact_put_OUTPUT(out);
1084 output->max_len = ntohs(oao->max_len);
1086 error = ofputil_port_from_ofp11(oao->port, &output->port);
1091 return ofpact_check_output_port(output->port, OFPP_MAX);
1095 ofpact_from_openflow11(const union ofp_action *a, enum ofp_version version,
1098 enum ofputil_action_code code;
1100 struct ofpact_vlan_vid *vlan_vid;
1101 struct ofpact_vlan_pcp *vlan_pcp;
1103 error = decode_openflow11_action(a, &code);
1108 if (version >= OFP12_VERSION) {
1109 switch ((int)code) {
1110 case OFPUTIL_OFPAT11_SET_VLAN_VID:
1111 case OFPUTIL_OFPAT11_SET_VLAN_PCP:
1112 case OFPUTIL_OFPAT11_SET_DL_SRC:
1113 case OFPUTIL_OFPAT11_SET_DL_DST:
1114 case OFPUTIL_OFPAT11_SET_NW_SRC:
1115 case OFPUTIL_OFPAT11_SET_NW_DST:
1116 case OFPUTIL_OFPAT11_SET_NW_TOS:
1117 case OFPUTIL_OFPAT11_SET_NW_ECN:
1118 case OFPUTIL_OFPAT11_SET_TP_SRC:
1119 case OFPUTIL_OFPAT11_SET_TP_DST:
1120 VLOG_WARN_RL(&rl, "Deprecated action %s received over %s",
1121 ofputil_action_name_from_code(code),
1122 ofputil_version_to_string(version));
1127 case OFPUTIL_ACTION_INVALID:
1128 #define OFPAT10_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM:
1129 #include "ofp-util.def"
1132 case OFPUTIL_OFPAT11_OUTPUT:
1133 return output_from_openflow11(&a->ofp11_output, out);
1135 case OFPUTIL_OFPAT11_SET_VLAN_VID:
1136 if (a->vlan_vid.vlan_vid & ~htons(0xfff)) {
1137 return OFPERR_OFPBAC_BAD_ARGUMENT;
1139 vlan_vid = ofpact_put_SET_VLAN_VID(out);
1140 vlan_vid->vlan_vid = ntohs(a->vlan_vid.vlan_vid);
1141 vlan_vid->push_vlan_if_needed = false;
1142 vlan_vid->ofpact.compat = code;
1145 case OFPUTIL_OFPAT11_SET_VLAN_PCP:
1146 if (a->vlan_pcp.vlan_pcp & ~7) {
1147 return OFPERR_OFPBAC_BAD_ARGUMENT;
1149 vlan_pcp = ofpact_put_SET_VLAN_PCP(out);
1150 vlan_pcp->vlan_pcp = a->vlan_pcp.vlan_pcp;
1151 vlan_pcp->push_vlan_if_needed = false;
1152 vlan_pcp->ofpact.compat = code;
1155 case OFPUTIL_OFPAT11_PUSH_VLAN:
1156 if (a->push.ethertype != htons(ETH_TYPE_VLAN_8021Q)) {
1157 /* XXX 802.1AD(QinQ) isn't supported at the moment */
1158 return OFPERR_OFPBAC_BAD_ARGUMENT;
1160 ofpact_put_PUSH_VLAN(out);
1163 case OFPUTIL_OFPAT11_POP_VLAN:
1164 ofpact_put_STRIP_VLAN(out)->ofpact.compat = code;
1167 case OFPUTIL_OFPAT11_SET_QUEUE:
1168 ofpact_put_SET_QUEUE(out)->queue_id =
1169 ntohl(a->ofp11_set_queue.queue_id);
1172 case OFPUTIL_OFPAT11_SET_DL_SRC:
1173 memcpy(ofpact_put_SET_ETH_SRC(out)->mac, a->dl_addr.dl_addr,
1177 case OFPUTIL_OFPAT11_SET_DL_DST:
1178 memcpy(ofpact_put_SET_ETH_DST(out)->mac, a->dl_addr.dl_addr,
1182 case OFPUTIL_OFPAT11_DEC_NW_TTL:
1183 dec_ttl_from_openflow(out, code);
1186 case OFPUTIL_OFPAT11_SET_NW_SRC:
1187 ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr;
1190 case OFPUTIL_OFPAT11_SET_NW_DST:
1191 ofpact_put_SET_IPV4_DST(out)->ipv4 = a->nw_addr.nw_addr;
1194 case OFPUTIL_OFPAT11_SET_NW_TOS:
1195 if (a->nw_tos.nw_tos & ~IP_DSCP_MASK) {
1196 return OFPERR_OFPBAC_BAD_ARGUMENT;
1198 ofpact_put_SET_IP_DSCP(out)->dscp = a->nw_tos.nw_tos;
1201 case OFPUTIL_OFPAT11_SET_NW_ECN:
1202 if (a->nw_ecn.nw_ecn & ~IP_ECN_MASK) {
1203 return OFPERR_OFPBAC_BAD_ARGUMENT;
1205 ofpact_put_SET_IP_ECN(out)->ecn = a->nw_ecn.nw_ecn;
1208 case OFPUTIL_OFPAT11_SET_NW_TTL:
1209 ofpact_put_SET_IP_TTL(out)->ttl = a->nw_ttl.nw_ttl;
1212 case OFPUTIL_OFPAT11_SET_TP_SRC:
1213 ofpact_put_SET_L4_SRC_PORT(out)->port = ntohs(a->tp_port.tp_port);
1216 case OFPUTIL_OFPAT11_SET_TP_DST:
1217 ofpact_put_SET_L4_DST_PORT(out)->port = ntohs(a->tp_port.tp_port);
1220 case OFPUTIL_OFPAT12_SET_FIELD:
1221 return set_field_from_openflow(&a->set_field, out);
1223 case OFPUTIL_OFPAT11_SET_MPLS_TTL:
1224 ofpact_put_SET_MPLS_TTL(out)->ttl = a->ofp11_mpls_ttl.mpls_ttl;
1227 case OFPUTIL_OFPAT11_DEC_MPLS_TTL:
1228 ofpact_put_DEC_MPLS_TTL(out);
1231 case OFPUTIL_OFPAT11_PUSH_MPLS:
1232 /* OpenFlow 1.3 has different semantics. */
1233 error = push_mpls_from_openflow(a->push.ethertype,
1234 version >= OFP13_VERSION ?
1235 OFPACT_MPLS_BEFORE_VLAN :
1236 OFPACT_MPLS_AFTER_VLAN, out);
1239 case OFPUTIL_OFPAT11_POP_MPLS:
1240 if (eth_type_mpls(a->ofp11_pop_mpls.ethertype)) {
1241 return OFPERR_OFPBAC_BAD_ARGUMENT;
1243 ofpact_put_POP_MPLS(out)->ethertype = a->ofp11_pop_mpls.ethertype;
1246 case OFPUTIL_OFPAT11_GROUP:
1247 ofpact_put_GROUP(out)->group_id = ntohl(a->group.group_id);
1250 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
1251 #include "ofp-util.def"
1252 return ofpact_from_nxast(a, code, out);
1258 /* True if an action sets the value of a field
1259 * in a way that is compatibile with the action set.
1260 * False otherwise. */
1262 ofpact_is_set_action(const struct ofpact *a)
1265 case OFPACT_SET_FIELD:
1266 case OFPACT_REG_LOAD:
1267 case OFPACT_SET_ETH_DST:
1268 case OFPACT_SET_ETH_SRC:
1269 case OFPACT_SET_IP_DSCP:
1270 case OFPACT_SET_IP_ECN:
1271 case OFPACT_SET_IP_TTL:
1272 case OFPACT_SET_IPV4_DST:
1273 case OFPACT_SET_IPV4_SRC:
1274 case OFPACT_SET_L4_DST_PORT:
1275 case OFPACT_SET_L4_SRC_PORT:
1276 case OFPACT_SET_MPLS_TTL:
1277 case OFPACT_SET_QUEUE:
1278 case OFPACT_SET_TUNNEL:
1279 case OFPACT_SET_VLAN_PCP:
1280 case OFPACT_SET_VLAN_VID:
1283 case OFPACT_CLEAR_ACTIONS:
1284 case OFPACT_CONTROLLER:
1285 case OFPACT_DEC_MPLS_TTL:
1286 case OFPACT_DEC_TTL:
1287 case OFPACT_ENQUEUE:
1289 case OFPACT_FIN_TIMEOUT:
1290 case OFPACT_GOTO_TABLE:
1294 case OFPACT_MULTIPATH:
1297 case OFPACT_OUTPUT_REG:
1298 case OFPACT_POP_MPLS:
1299 case OFPACT_POP_QUEUE:
1300 case OFPACT_PUSH_MPLS:
1301 case OFPACT_PUSH_VLAN:
1302 case OFPACT_REG_MOVE:
1303 case OFPACT_RESUBMIT:
1305 case OFPACT_STACK_POP:
1306 case OFPACT_STACK_PUSH:
1307 case OFPACT_STRIP_VLAN:
1308 case OFPACT_WRITE_ACTIONS:
1309 case OFPACT_WRITE_METADATA:
1316 /* True if an action is allowed in the action set.
1317 * False otherwise. */
1319 ofpact_is_allowed_in_actions_set(const struct ofpact *a)
1322 case OFPACT_DEC_MPLS_TTL:
1323 case OFPACT_DEC_TTL:
1326 case OFPACT_POP_MPLS:
1327 case OFPACT_PUSH_MPLS:
1328 case OFPACT_PUSH_VLAN:
1329 case OFPACT_REG_LOAD:
1330 case OFPACT_SET_FIELD:
1331 case OFPACT_SET_ETH_DST:
1332 case OFPACT_SET_ETH_SRC:
1333 case OFPACT_SET_IP_DSCP:
1334 case OFPACT_SET_IP_ECN:
1335 case OFPACT_SET_IP_TTL:
1336 case OFPACT_SET_IPV4_DST:
1337 case OFPACT_SET_IPV4_SRC:
1338 case OFPACT_SET_L4_DST_PORT:
1339 case OFPACT_SET_L4_SRC_PORT:
1340 case OFPACT_SET_MPLS_TTL:
1341 case OFPACT_SET_QUEUE:
1342 case OFPACT_SET_TUNNEL:
1343 case OFPACT_SET_VLAN_PCP:
1344 case OFPACT_SET_VLAN_VID:
1345 case OFPACT_STRIP_VLAN:
1348 /* In general these actions are excluded because they are not part of
1349 * the OpenFlow specification nor map to actions that are defined in
1350 * the specification. Thus the order in which they should be applied
1351 * in the action set is undefined. */
1353 case OFPACT_CONTROLLER:
1354 case OFPACT_ENQUEUE:
1356 case OFPACT_FIN_TIMEOUT:
1358 case OFPACT_MULTIPATH:
1360 case OFPACT_OUTPUT_REG:
1361 case OFPACT_POP_QUEUE:
1362 case OFPACT_REG_MOVE:
1363 case OFPACT_RESUBMIT:
1365 case OFPACT_STACK_POP:
1366 case OFPACT_STACK_PUSH:
1368 /* The action set may only include actions and thus
1369 * may not include any instructions */
1370 case OFPACT_CLEAR_ACTIONS:
1371 case OFPACT_GOTO_TABLE:
1373 case OFPACT_WRITE_ACTIONS:
1374 case OFPACT_WRITE_METADATA:
1381 /* Append ofpact 'a' onto the tail of 'out' */
1383 ofpact_copy(struct ofpbuf *out, const struct ofpact *a)
1385 ofpbuf_put(out, a, OFPACT_ALIGN(a->len));
1388 /* Copies the last ofpact whose type is 'filter' from 'in' to 'out'. */
1390 ofpacts_copy_last(struct ofpbuf *out, const struct ofpbuf *in,
1391 enum ofpact_type filter)
1393 const struct ofpact *target;
1394 const struct ofpact *a;
1397 OFPACT_FOR_EACH (a, in->data, in->size) {
1398 if (a->type == filter) {
1403 ofpact_copy(out, target);
1405 return target != NULL;
1408 /* Append all ofpacts, for which 'filter' returns true, from 'in' to 'out'.
1409 * The order of appended ofpacts is preserved between 'in' and 'out' */
1411 ofpacts_copy_all(struct ofpbuf *out, const struct ofpbuf *in,
1412 bool (*filter)(const struct ofpact *))
1414 const struct ofpact *a;
1416 OFPACT_FOR_EACH (a, in->data, in->size) {
1418 ofpact_copy(out, a);
1423 /* Reads 'action_set', which contains ofpacts accumulated by
1424 * OFPACT_WRITE_ACTIONS instructions, and writes equivalent actions to be
1425 * executed directly into 'action_list'. (These names correspond to the
1426 * "Action Set" and "Action List" terms used in OpenFlow 1.1+.)
1428 * In general this involves appending the last instance of each action that is
1429 * adimissible in the action set in the order described in the OpenFlow
1433 * + output action is only appended if no group action was present in 'in'.
1434 * + As a simplification all set actions are copied in the order the are
1435 * provided in 'in' as many set actions applied to a field has the same
1436 * affect as only applying the last action that sets a field and
1437 * duplicates are removed by do_xlate_actions().
1438 * This has an unwanted side-effect of compsoting multiple
1439 * LOAD_REG actions that touch different regions of the same field. */
1441 ofpacts_execute_action_set(struct ofpbuf *action_list,
1442 const struct ofpbuf *action_set)
1444 /* The OpenFlow spec "Action Set" section specifies this order. */
1445 ofpacts_copy_last(action_list, action_set, OFPACT_STRIP_VLAN);
1446 ofpacts_copy_last(action_list, action_set, OFPACT_POP_MPLS);
1447 ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_MPLS);
1448 ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_VLAN);
1449 ofpacts_copy_last(action_list, action_set, OFPACT_DEC_TTL);
1450 ofpacts_copy_last(action_list, action_set, OFPACT_DEC_MPLS_TTL);
1451 ofpacts_copy_all(action_list, action_set, ofpact_is_set_action);
1452 ofpacts_copy_last(action_list, action_set, OFPACT_SET_QUEUE);
1454 /* If both OFPACT_GROUP and OFPACT_OUTPUT are present, OpenFlow says that
1455 * we should execute only OFPACT_GROUP.
1457 * If neither OFPACT_GROUP nor OFPACT_OUTPUT is present, then we can drop
1458 * all the actions because there's no point in modifying a packet that will
1459 * not be sent anywhere. */
1460 if (!ofpacts_copy_last(action_list, action_set, OFPACT_GROUP) &&
1461 !ofpacts_copy_last(action_list, action_set, OFPACT_OUTPUT)) {
1462 ofpbuf_clear(action_list);
1468 ofpacts_from_openflow11_for_action_set(const union ofp_action *in,
1469 size_t n_in, enum ofp_version version,
1474 size_t start = out->size;
1476 error = ofpacts_from_openflow(in, n_in, version, out);
1482 OFPACT_FOR_EACH (a, ofpact_end(out->data, start), out->size - start) {
1483 if (!ofpact_is_allowed_in_actions_set(a)) {
1484 VLOG_WARN_RL(&rl, "disallowed action in action set");
1485 return OFPERR_OFPBAC_BAD_TYPE;
1493 /* OpenFlow 1.1 instructions. */
1495 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \
1496 static inline const struct STRUCT * OVS_UNUSED \
1497 instruction_get_##ENUM(const struct ofp11_instruction *inst)\
1499 ovs_assert(inst->type == htons(ENUM)); \
1500 return ALIGNED_CAST(struct STRUCT *, inst); \
1503 static inline void OVS_UNUSED \
1504 instruction_init_##ENUM(struct STRUCT *s) \
1506 memset(s, 0, sizeof *s); \
1507 s->type = htons(ENUM); \
1508 s->len = htons(sizeof *s); \
1511 static inline struct STRUCT * OVS_UNUSED \
1512 instruction_put_##ENUM(struct ofpbuf *buf) \
1514 struct STRUCT *s = ofpbuf_put_uninit(buf, sizeof *s); \
1515 instruction_init_##ENUM(s); \
1521 struct instruction_type_info {
1522 enum ovs_instruction_type type;
1526 static const struct instruction_type_info inst_info[] = {
1527 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) {OVSINST_##ENUM, NAME},
1533 ovs_instruction_name_from_type(enum ovs_instruction_type type)
1535 return inst_info[type].name;
1539 ovs_instruction_type_from_name(const char *name)
1541 const struct instruction_type_info *p;
1542 for (p = inst_info; p < &inst_info[ARRAY_SIZE(inst_info)]; p++) {
1543 if (!strcasecmp(name, p->name)) {
1550 enum ovs_instruction_type
1551 ovs_instruction_type_from_ofpact_type(enum ofpact_type type)
1555 return OVSINST_OFPIT13_METER;
1556 case OFPACT_CLEAR_ACTIONS:
1557 return OVSINST_OFPIT11_CLEAR_ACTIONS;
1558 case OFPACT_WRITE_ACTIONS:
1559 return OVSINST_OFPIT11_WRITE_ACTIONS;
1560 case OFPACT_WRITE_METADATA:
1561 return OVSINST_OFPIT11_WRITE_METADATA;
1562 case OFPACT_GOTO_TABLE:
1563 return OVSINST_OFPIT11_GOTO_TABLE;
1566 case OFPACT_CONTROLLER:
1567 case OFPACT_ENQUEUE:
1568 case OFPACT_OUTPUT_REG:
1570 case OFPACT_SET_VLAN_VID:
1571 case OFPACT_SET_VLAN_PCP:
1572 case OFPACT_STRIP_VLAN:
1573 case OFPACT_PUSH_VLAN:
1574 case OFPACT_SET_ETH_SRC:
1575 case OFPACT_SET_ETH_DST:
1576 case OFPACT_SET_IPV4_SRC:
1577 case OFPACT_SET_IPV4_DST:
1578 case OFPACT_SET_IP_DSCP:
1579 case OFPACT_SET_IP_ECN:
1580 case OFPACT_SET_IP_TTL:
1581 case OFPACT_SET_L4_SRC_PORT:
1582 case OFPACT_SET_L4_DST_PORT:
1583 case OFPACT_REG_MOVE:
1584 case OFPACT_REG_LOAD:
1585 case OFPACT_SET_FIELD:
1586 case OFPACT_STACK_PUSH:
1587 case OFPACT_STACK_POP:
1588 case OFPACT_DEC_TTL:
1589 case OFPACT_SET_MPLS_TTL:
1590 case OFPACT_DEC_MPLS_TTL:
1591 case OFPACT_PUSH_MPLS:
1592 case OFPACT_POP_MPLS:
1593 case OFPACT_SET_TUNNEL:
1594 case OFPACT_SET_QUEUE:
1595 case OFPACT_POP_QUEUE:
1596 case OFPACT_FIN_TIMEOUT:
1597 case OFPACT_RESUBMIT:
1599 case OFPACT_MULTIPATH:
1604 return OVSINST_OFPIT11_APPLY_ACTIONS;
1608 static inline struct ofp11_instruction *
1609 instruction_next(const struct ofp11_instruction *inst)
1611 return ((struct ofp11_instruction *) (void *)
1612 ((uint8_t *) inst + ntohs(inst->len)));
1616 instruction_is_valid(const struct ofp11_instruction *inst,
1617 size_t n_instructions)
1619 uint16_t len = ntohs(inst->len);
1620 return (!(len % OFP11_INSTRUCTION_ALIGN)
1621 && len >= sizeof *inst
1622 && len / sizeof *inst <= n_instructions);
1625 /* This macro is careful to check for instructions with bad lengths. */
1626 #define INSTRUCTION_FOR_EACH(ITER, LEFT, INSTRUCTIONS, N_INSTRUCTIONS) \
1627 for ((ITER) = (INSTRUCTIONS), (LEFT) = (N_INSTRUCTIONS); \
1628 (LEFT) > 0 && instruction_is_valid(ITER, LEFT); \
1629 ((LEFT) -= (ntohs((ITER)->len) \
1630 / sizeof(struct ofp11_instruction)), \
1631 (ITER) = instruction_next(ITER)))
1634 decode_openflow11_instruction(const struct ofp11_instruction *inst,
1635 enum ovs_instruction_type *type)
1637 uint16_t len = ntohs(inst->len);
1639 switch (inst->type) {
1640 case CONSTANT_HTONS(OFPIT11_EXPERIMENTER):
1641 return OFPERR_OFPBIC_BAD_EXPERIMENTER;
1643 #define DEFINE_INST(ENUM, STRUCT, EXTENSIBLE, NAME) \
1644 case CONSTANT_HTONS(ENUM): \
1646 ? len >= sizeof(struct STRUCT) \
1647 : len == sizeof(struct STRUCT)) { \
1648 *type = OVSINST_##ENUM; \
1651 return OFPERR_OFPBIC_BAD_LEN; \
1657 return OFPERR_OFPBIC_UNKNOWN_INST;
1662 decode_openflow11_instructions(const struct ofp11_instruction insts[],
1664 const struct ofp11_instruction *out[])
1666 const struct ofp11_instruction *inst;
1669 memset(out, 0, N_OVS_INSTRUCTIONS * sizeof *out);
1670 INSTRUCTION_FOR_EACH (inst, left, insts, n_insts) {
1671 enum ovs_instruction_type type;
1674 error = decode_openflow11_instruction(inst, &type);
1680 return OFPERR_ONFBIC_DUP_INSTRUCTION;
1686 VLOG_WARN_RL(&rl, "bad instruction format at offset %zu",
1687 (n_insts - left) * sizeof *inst);
1688 return OFPERR_OFPBIC_BAD_LEN;
1694 get_actions_from_instruction(const struct ofp11_instruction *inst,
1695 const union ofp_action **actions,
1696 size_t *max_actions)
1698 *actions = ALIGNED_CAST(const union ofp_action *, inst + 1);
1699 *max_actions = (ntohs(inst->len) - sizeof *inst) / OFP11_INSTRUCTION_ALIGN;
1703 ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
1704 unsigned int instructions_len,
1705 enum ofp_version version,
1706 struct ofpbuf *ofpacts)
1708 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1709 const struct ofp11_instruction *instructions;
1710 const struct ofp11_instruction *insts[N_OVS_INSTRUCTIONS];
1713 ofpbuf_clear(ofpacts);
1715 if (instructions_len % OFP11_INSTRUCTION_ALIGN != 0) {
1716 VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u is not a "
1718 instructions_len, OFP11_INSTRUCTION_ALIGN);
1719 error = OFPERR_OFPBIC_BAD_LEN;
1723 instructions = ofpbuf_try_pull(openflow, instructions_len);
1724 if (instructions == NULL) {
1725 VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u exceeds "
1726 "remaining message length (%zu)",
1727 instructions_len, openflow->size);
1728 error = OFPERR_OFPBIC_BAD_LEN;
1732 error = decode_openflow11_instructions(
1733 instructions, instructions_len / OFP11_INSTRUCTION_ALIGN,
1739 if (insts[OVSINST_OFPIT13_METER]) {
1740 const struct ofp13_instruction_meter *oim;
1741 struct ofpact_meter *om;
1743 oim = ALIGNED_CAST(const struct ofp13_instruction_meter *,
1744 insts[OVSINST_OFPIT13_METER]);
1746 om = ofpact_put_METER(ofpacts);
1747 om->meter_id = ntohl(oim->meter_id);
1749 if (insts[OVSINST_OFPIT11_APPLY_ACTIONS]) {
1750 const union ofp_action *actions;
1753 get_actions_from_instruction(insts[OVSINST_OFPIT11_APPLY_ACTIONS],
1754 &actions, &max_actions);
1755 error = ofpacts_from_openflow(actions, max_actions, version, ofpacts);
1760 if (insts[OVSINST_OFPIT11_CLEAR_ACTIONS]) {
1761 instruction_get_OFPIT11_CLEAR_ACTIONS(
1762 insts[OVSINST_OFPIT11_CLEAR_ACTIONS]);
1763 ofpact_put_CLEAR_ACTIONS(ofpacts);
1765 if (insts[OVSINST_OFPIT11_WRITE_ACTIONS]) {
1766 struct ofpact_nest *on;
1767 const union ofp_action *actions;
1771 ofpact_pad(ofpacts);
1772 start = ofpacts->size;
1773 on = ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS,
1774 offsetof(struct ofpact_nest, actions));
1775 get_actions_from_instruction(insts[OVSINST_OFPIT11_WRITE_ACTIONS],
1776 &actions, &max_actions);
1777 error = ofpacts_from_openflow11_for_action_set(actions, max_actions,
1782 on = ofpbuf_at_assert(ofpacts, start, sizeof *on);
1783 on->ofpact.len = ofpacts->size - start;
1785 if (insts[OVSINST_OFPIT11_WRITE_METADATA]) {
1786 const struct ofp11_instruction_write_metadata *oiwm;
1787 struct ofpact_metadata *om;
1789 oiwm = ALIGNED_CAST(const struct ofp11_instruction_write_metadata *,
1790 insts[OVSINST_OFPIT11_WRITE_METADATA]);
1792 om = ofpact_put_WRITE_METADATA(ofpacts);
1793 om->metadata = oiwm->metadata;
1794 om->mask = oiwm->metadata_mask;
1796 if (insts[OVSINST_OFPIT11_GOTO_TABLE]) {
1797 const struct ofp11_instruction_goto_table *oigt;
1798 struct ofpact_goto_table *ogt;
1800 oigt = instruction_get_OFPIT11_GOTO_TABLE(
1801 insts[OVSINST_OFPIT11_GOTO_TABLE]);
1802 ogt = ofpact_put_GOTO_TABLE(ofpacts);
1803 ogt->table_id = oigt->table_id;
1806 error = ofpacts_verify(ofpacts->data, ofpacts->size);
1809 ofpbuf_clear(ofpacts);
1814 /* Checks that 'port' is a valid output port for OFPACT_OUTPUT, given that the
1815 * switch will never have more than 'max_ports' ports. Returns 0 if 'port' is
1816 * valid, otherwise an OpenFlow error code. */
1818 ofpact_check_output_port(ofp_port_t port, ofp_port_t max_ports)
1826 case OFPP_CONTROLLER:
1832 if (ofp_to_u16(port) < ofp_to_u16(max_ports)) {
1835 return OFPERR_OFPBAC_BAD_OUT_PORT;
1839 /* May modify flow->dl_type and flow->vlan_tci, caller must restore them.
1841 * Modifies some actions, filling in fields that could not be properly set
1842 * without context. */
1844 ofpact_check__(struct ofpact *a, struct flow *flow,
1845 bool enforce_consistency, ofp_port_t max_ports,
1846 uint8_t table_id, uint8_t n_tables)
1848 const struct ofpact_enqueue *enqueue;
1849 const struct mf_field *mf;
1853 return ofpact_check_output_port(ofpact_get_OUTPUT(a)->port,
1856 case OFPACT_CONTROLLER:
1859 case OFPACT_ENQUEUE:
1860 enqueue = ofpact_get_ENQUEUE(a);
1861 if (ofp_to_u16(enqueue->port) >= ofp_to_u16(max_ports)
1862 && enqueue->port != OFPP_IN_PORT
1863 && enqueue->port != OFPP_LOCAL) {
1864 return OFPERR_OFPBAC_BAD_OUT_PORT;
1868 case OFPACT_OUTPUT_REG:
1869 return mf_check_src(&ofpact_get_OUTPUT_REG(a)->src, flow);
1872 return bundle_check(ofpact_get_BUNDLE(a), max_ports, flow);
1874 case OFPACT_SET_VLAN_VID:
1875 /* Remember if we saw a vlan tag in the flow to aid translating to
1876 * OpenFlow 1.1+ if need be. */
1877 ofpact_get_SET_VLAN_VID(a)->flow_has_vlan =
1878 (flow->vlan_tci & htons(VLAN_CFI)) == htons(VLAN_CFI);
1879 if (!(flow->vlan_tci & htons(VLAN_CFI)) &&
1880 !ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) {
1883 /* Temporary mark that we have a vlan tag. */
1884 flow->vlan_tci |= htons(VLAN_CFI);
1887 case OFPACT_SET_VLAN_PCP:
1888 /* Remember if we saw a vlan tag in the flow to aid translating to
1889 * OpenFlow 1.1+ if need be. */
1890 ofpact_get_SET_VLAN_PCP(a)->flow_has_vlan =
1891 (flow->vlan_tci & htons(VLAN_CFI)) == htons(VLAN_CFI);
1892 if (!(flow->vlan_tci & htons(VLAN_CFI)) &&
1893 !ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) {
1896 /* Temporary mark that we have a vlan tag. */
1897 flow->vlan_tci |= htons(VLAN_CFI);
1900 case OFPACT_STRIP_VLAN:
1901 if (!(flow->vlan_tci & htons(VLAN_CFI))) {
1904 /* Temporary mark that we have no vlan tag. */
1905 flow->vlan_tci = htons(0);
1908 case OFPACT_PUSH_VLAN:
1909 if (flow->vlan_tci & htons(VLAN_CFI)) {
1910 /* Multiple VLAN headers not supported. */
1911 return OFPERR_OFPBAC_BAD_TAG;
1913 /* Temporary mark that we have a vlan tag. */
1914 flow->vlan_tci |= htons(VLAN_CFI);
1917 case OFPACT_SET_ETH_SRC:
1918 case OFPACT_SET_ETH_DST:
1921 case OFPACT_SET_IPV4_SRC:
1922 case OFPACT_SET_IPV4_DST:
1923 if (flow->dl_type != htons(ETH_TYPE_IP)) {
1928 case OFPACT_SET_IP_DSCP:
1929 case OFPACT_SET_IP_ECN:
1930 case OFPACT_SET_IP_TTL:
1931 case OFPACT_DEC_TTL:
1932 if (!is_ip_any(flow)) {
1937 case OFPACT_SET_L4_SRC_PORT:
1938 if (!is_ip_any(flow) ||
1939 (flow->nw_proto != IPPROTO_TCP && flow->nw_proto != IPPROTO_UDP
1940 && flow->nw_proto != IPPROTO_SCTP)) {
1943 /* Note on which transport protocol the port numbers are set.
1944 * This allows this set action to be converted to an OF1.2 set field
1946 ofpact_get_SET_L4_SRC_PORT(a)->flow_ip_proto = flow->nw_proto;
1949 case OFPACT_SET_L4_DST_PORT:
1950 if (!is_ip_any(flow) ||
1951 (flow->nw_proto != IPPROTO_TCP && flow->nw_proto != IPPROTO_UDP
1952 && flow->nw_proto != IPPROTO_SCTP)) {
1955 /* Note on which transport protocol the port numbers are set.
1956 * This allows this set action to be converted to an OF1.2 set field
1958 ofpact_get_SET_L4_DST_PORT(a)->flow_ip_proto = flow->nw_proto;
1961 case OFPACT_REG_MOVE:
1962 return nxm_reg_move_check(ofpact_get_REG_MOVE(a), flow);
1964 case OFPACT_REG_LOAD:
1965 return nxm_reg_load_check(ofpact_get_REG_LOAD(a), flow);
1967 case OFPACT_SET_FIELD:
1968 mf = ofpact_get_SET_FIELD(a)->field;
1969 /* Require OXM_OF_VLAN_VID to have an existing VLAN header. */
1970 if (!mf_are_prereqs_ok(mf, flow) ||
1971 (mf->id == MFF_VLAN_VID && !(flow->vlan_tci & htons(VLAN_CFI)))) {
1972 VLOG_WARN_RL(&rl, "set_field %s lacks correct prerequisities",
1974 return OFPERR_OFPBAC_MATCH_INCONSISTENT;
1976 /* Remember if we saw a vlan tag in the flow to aid translating to
1977 * OpenFlow 1.1 if need be. */
1978 ofpact_get_SET_FIELD(a)->flow_has_vlan =
1979 (flow->vlan_tci & htons(VLAN_CFI)) == htons(VLAN_CFI);
1980 if (mf->id == MFF_VLAN_TCI) {
1981 /* The set field may add or remove the vlan tag,
1982 * Mark the status temporarily. */
1983 flow->vlan_tci = ofpact_get_SET_FIELD(a)->value.be16;
1987 case OFPACT_STACK_PUSH:
1988 return nxm_stack_push_check(ofpact_get_STACK_PUSH(a), flow);
1990 case OFPACT_STACK_POP:
1991 return nxm_stack_pop_check(ofpact_get_STACK_POP(a), flow);
1993 case OFPACT_SET_MPLS_TTL:
1994 case OFPACT_DEC_MPLS_TTL:
1995 if (!eth_type_mpls(flow->dl_type)) {
2000 case OFPACT_SET_TUNNEL:
2001 case OFPACT_SET_QUEUE:
2002 case OFPACT_POP_QUEUE:
2003 case OFPACT_RESUBMIT:
2006 case OFPACT_FIN_TIMEOUT:
2007 if (flow->nw_proto != IPPROTO_TCP) {
2013 return learn_check(ofpact_get_LEARN(a), flow);
2015 case OFPACT_MULTIPATH:
2016 return multipath_check(ofpact_get_MULTIPATH(a), flow);
2022 case OFPACT_PUSH_MPLS:
2023 flow->dl_type = ofpact_get_PUSH_MPLS(a)->ethertype;
2026 case OFPACT_POP_MPLS:
2027 flow->dl_type = ofpact_get_POP_MPLS(a)->ethertype;
2028 if (!eth_type_mpls(flow->dl_type)) {
2036 case OFPACT_CLEAR_ACTIONS:
2039 case OFPACT_WRITE_ACTIONS: {
2040 struct ofpact_nest *on = ofpact_get_WRITE_ACTIONS(a);
2041 return ofpacts_check(on->actions, ofpact_nest_get_action_len(on),
2042 flow, false, max_ports, table_id, n_tables);
2045 case OFPACT_WRITE_METADATA:
2048 case OFPACT_METER: {
2049 uint32_t mid = ofpact_get_METER(a)->meter_id;
2050 if (mid == 0 || mid > OFPM13_MAX) {
2051 return OFPERR_OFPMMFC_INVALID_METER;
2056 case OFPACT_GOTO_TABLE: {
2057 uint8_t goto_table = ofpact_get_GOTO_TABLE(a)->table_id;
2058 if ((table_id != 255 && goto_table <= table_id)
2059 || (n_tables != 255 && goto_table >= n_tables)) {
2060 return OFPERR_OFPBRC_BAD_TABLE_ID;
2073 if (enforce_consistency) {
2074 return OFPERR_OFPBAC_MATCH_INCONSISTENT;
2079 /* Checks that the 'ofpacts_len' bytes of actions in 'ofpacts' are
2080 * appropriate for a packet with the prerequisites satisfied by 'flow' in a
2081 * switch with no more than 'max_ports' ports.
2083 * May annotate ofpacts with information gathered from the 'flow'.
2085 * May temporarily modify 'flow', but restores the changes before returning. */
2087 ofpacts_check(struct ofpact ofpacts[], size_t ofpacts_len,
2088 struct flow *flow, bool enforce_consistency,
2089 ofp_port_t max_ports,
2090 uint8_t table_id, uint8_t n_tables)
2093 ovs_be16 dl_type = flow->dl_type;
2094 ovs_be16 vlan_tci = flow->vlan_tci;
2095 enum ofperr error = 0;
2097 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2098 error = ofpact_check__(a, flow, enforce_consistency,
2099 max_ports, table_id, n_tables);
2104 /* Restore fields that may have been modified. */
2105 flow->dl_type = dl_type;
2106 flow->vlan_tci = vlan_tci;
2110 /* Verifies that the 'ofpacts_len' bytes of actions in 'ofpacts' are
2111 * in the appropriate order as defined by the OpenFlow spec. */
2113 ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len)
2115 const struct ofpact *a;
2116 enum ovs_instruction_type inst;
2118 inst = OVSINST_OFPIT11_APPLY_ACTIONS;
2119 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2120 enum ovs_instruction_type next;
2122 next = ovs_instruction_type_from_ofpact_type(a->type);
2123 if (inst == OVSINST_OFPIT11_APPLY_ACTIONS
2126 const char *name = ovs_instruction_name_from_type(inst);
2127 const char *next_name = ovs_instruction_name_from_type(next);
2130 VLOG_WARN("duplicate %s instruction not allowed, for OpenFlow "
2131 "1.1+ compatibility", name);
2133 VLOG_WARN("invalid instruction ordering: %s must appear "
2134 "before %s, for OpenFlow 1.1+ compatibility",
2137 return OFPERR_OFPBAC_UNSUPPORTED_ORDER;
2146 /* Converting ofpacts to Nicira OpenFlow extensions. */
2149 ofpact_output_reg_to_nxast(const struct ofpact_output_reg *output_reg,
2152 struct nx_action_output_reg *naor = ofputil_put_NXAST_OUTPUT_REG(out);
2154 naor->ofs_nbits = nxm_encode_ofs_nbits(output_reg->src.ofs,
2155 output_reg->src.n_bits);
2156 naor->src = htonl(output_reg->src.field->nxm_header);
2157 naor->max_len = htons(output_reg->max_len);
2161 ofpact_resubmit_to_nxast(const struct ofpact_resubmit *resubmit,
2164 struct nx_action_resubmit *nar;
2166 if (resubmit->table_id == 0xff
2167 && resubmit->ofpact.compat != OFPUTIL_NXAST_RESUBMIT_TABLE) {
2168 nar = ofputil_put_NXAST_RESUBMIT(out);
2170 nar = ofputil_put_NXAST_RESUBMIT_TABLE(out);
2171 nar->table = resubmit->table_id;
2173 nar->in_port = htons(ofp_to_u16(resubmit->in_port));
2177 ofpact_set_tunnel_to_nxast(const struct ofpact_tunnel *tunnel,
2180 uint64_t tun_id = tunnel->tun_id;
2182 if (tun_id <= UINT32_MAX
2183 && tunnel->ofpact.compat != OFPUTIL_NXAST_SET_TUNNEL64) {
2184 ofputil_put_NXAST_SET_TUNNEL(out)->tun_id = htonl(tun_id);
2186 ofputil_put_NXAST_SET_TUNNEL64(out)->tun_id = htonll(tun_id);
2191 ofpact_write_metadata_to_nxast(const struct ofpact_metadata *om,
2194 struct nx_action_write_metadata *nawm;
2196 nawm = ofputil_put_NXAST_WRITE_METADATA(out);
2197 nawm->metadata = om->metadata;
2198 nawm->mask = om->mask;
2202 ofpact_note_to_nxast(const struct ofpact_note *note, struct ofpbuf *out)
2204 size_t start_ofs = out->size;
2205 struct nx_action_note *nan;
2206 unsigned int remainder;
2209 nan = ofputil_put_NXAST_NOTE(out);
2210 out->size -= sizeof nan->note;
2212 ofpbuf_put(out, note->data, note->length);
2214 len = out->size - start_ofs;
2215 remainder = len % OFP_ACTION_ALIGN;
2217 ofpbuf_put_zeros(out, OFP_ACTION_ALIGN - remainder);
2219 nan = ofpbuf_at(out, start_ofs, sizeof *nan);
2220 nan->len = htons(out->size - start_ofs);
2224 ofpact_controller_to_nxast(const struct ofpact_controller *oc,
2227 struct nx_action_controller *nac;
2229 nac = ofputil_put_NXAST_CONTROLLER(out);
2230 nac->max_len = htons(oc->max_len);
2231 nac->controller_id = htons(oc->controller_id);
2232 nac->reason = oc->reason;
2236 ofpact_dec_ttl_to_nxast(const struct ofpact_cnt_ids *oc_ids,
2239 if (oc_ids->ofpact.compat == OFPUTIL_NXAST_DEC_TTL) {
2240 ofputil_put_NXAST_DEC_TTL(out);
2242 struct nx_action_cnt_ids *nac_ids =
2243 ofputil_put_NXAST_DEC_TTL_CNT_IDS(out);
2244 int ids_len = ROUND_UP(2 * oc_ids->n_controllers, OFP_ACTION_ALIGN);
2248 nac_ids->len = htons(ntohs(nac_ids->len) + ids_len);
2249 nac_ids->n_controllers = htons(oc_ids->n_controllers);
2251 ids = ofpbuf_put_zeros(out, ids_len);
2252 for (i = 0; i < oc_ids->n_controllers; i++) {
2253 ids[i] = htons(oc_ids->cnt_ids[i]);
2259 ofpact_fin_timeout_to_nxast(const struct ofpact_fin_timeout *fin_timeout,
2262 struct nx_action_fin_timeout *naft = ofputil_put_NXAST_FIN_TIMEOUT(out);
2263 naft->fin_idle_timeout = htons(fin_timeout->fin_idle_timeout);
2264 naft->fin_hard_timeout = htons(fin_timeout->fin_hard_timeout);
2268 ofpact_sample_to_nxast(const struct ofpact_sample *os,
2271 struct nx_action_sample *nas;
2273 nas = ofputil_put_NXAST_SAMPLE(out);
2274 nas->probability = htons(os->probability);
2275 nas->collector_set_id = htonl(os->collector_set_id);
2276 nas->obs_domain_id = htonl(os->obs_domain_id);
2277 nas->obs_point_id = htonl(os->obs_point_id);
2281 ofpact_to_nxast(const struct ofpact *a, struct ofpbuf *out)
2284 case OFPACT_CONTROLLER:
2285 ofpact_controller_to_nxast(ofpact_get_CONTROLLER(a), out);
2288 case OFPACT_OUTPUT_REG:
2289 ofpact_output_reg_to_nxast(ofpact_get_OUTPUT_REG(a), out);
2293 bundle_to_nxast(ofpact_get_BUNDLE(a), out);
2296 case OFPACT_REG_MOVE:
2297 nxm_reg_move_to_nxast(ofpact_get_REG_MOVE(a), out);
2300 case OFPACT_REG_LOAD:
2301 nxm_reg_load_to_nxast(ofpact_get_REG_LOAD(a), out);
2304 case OFPACT_STACK_PUSH:
2305 nxm_stack_push_to_nxast(ofpact_get_STACK_PUSH(a), out);
2308 case OFPACT_STACK_POP:
2309 nxm_stack_pop_to_nxast(ofpact_get_STACK_POP(a), out);
2312 case OFPACT_DEC_TTL:
2313 ofpact_dec_ttl_to_nxast(ofpact_get_DEC_TTL(a), out);
2316 case OFPACT_SET_MPLS_TTL:
2317 ofputil_put_NXAST_SET_MPLS_TTL(out)->ttl
2318 = ofpact_get_SET_MPLS_TTL(a)->ttl;
2321 case OFPACT_DEC_MPLS_TTL:
2322 ofputil_put_NXAST_DEC_MPLS_TTL(out);
2325 case OFPACT_SET_TUNNEL:
2326 ofpact_set_tunnel_to_nxast(ofpact_get_SET_TUNNEL(a), out);
2329 case OFPACT_WRITE_METADATA:
2330 ofpact_write_metadata_to_nxast(ofpact_get_WRITE_METADATA(a), out);
2333 case OFPACT_SET_QUEUE:
2334 ofputil_put_NXAST_SET_QUEUE(out)->queue_id
2335 = htonl(ofpact_get_SET_QUEUE(a)->queue_id);
2338 case OFPACT_POP_QUEUE:
2339 ofputil_put_NXAST_POP_QUEUE(out);
2342 case OFPACT_FIN_TIMEOUT:
2343 ofpact_fin_timeout_to_nxast(ofpact_get_FIN_TIMEOUT(a), out);
2346 case OFPACT_RESUBMIT:
2347 ofpact_resubmit_to_nxast(ofpact_get_RESUBMIT(a), out);
2351 learn_to_nxast(ofpact_get_LEARN(a), out);
2354 case OFPACT_MULTIPATH:
2355 multipath_to_nxast(ofpact_get_MULTIPATH(a), out);
2359 ofpact_note_to_nxast(ofpact_get_NOTE(a), out);
2363 ofputil_put_NXAST_EXIT(out);
2366 case OFPACT_PUSH_MPLS:
2367 ofputil_put_NXAST_PUSH_MPLS(out)->ethertype =
2368 ofpact_get_PUSH_MPLS(a)->ethertype;
2371 case OFPACT_POP_MPLS:
2372 ofputil_put_NXAST_POP_MPLS(out)->ethertype =
2373 ofpact_get_POP_MPLS(a)->ethertype;
2377 ofpact_sample_to_nxast(ofpact_get_SAMPLE(a), out);
2382 case OFPACT_ENQUEUE:
2383 case OFPACT_SET_VLAN_VID:
2384 case OFPACT_SET_VLAN_PCP:
2385 case OFPACT_STRIP_VLAN:
2386 case OFPACT_PUSH_VLAN:
2387 case OFPACT_SET_ETH_SRC:
2388 case OFPACT_SET_ETH_DST:
2389 case OFPACT_SET_IPV4_SRC:
2390 case OFPACT_SET_IPV4_DST:
2391 case OFPACT_SET_IP_DSCP:
2392 case OFPACT_SET_IP_ECN:
2393 case OFPACT_SET_IP_TTL:
2394 case OFPACT_SET_L4_SRC_PORT:
2395 case OFPACT_SET_L4_DST_PORT:
2396 case OFPACT_WRITE_ACTIONS:
2397 case OFPACT_CLEAR_ACTIONS:
2398 case OFPACT_GOTO_TABLE:
2400 case OFPACT_SET_FIELD:
2405 /* Converting ofpacts to OpenFlow 1.0. */
2408 ofpact_output_to_openflow10(const struct ofpact_output *output,
2411 struct ofp10_action_output *oao;
2413 oao = ofputil_put_OFPAT10_OUTPUT(out);
2414 oao->port = htons(ofp_to_u16(output->port));
2415 oao->max_len = htons(output->max_len);
2419 ofpact_enqueue_to_openflow10(const struct ofpact_enqueue *enqueue,
2422 struct ofp10_action_enqueue *oae;
2424 oae = ofputil_put_OFPAT10_ENQUEUE(out);
2425 oae->port = htons(ofp_to_u16(enqueue->port));
2426 oae->queue_id = htonl(enqueue->queue);
2430 ofpact_to_openflow10(const struct ofpact *a, struct ofpbuf *out)
2434 ofpact_output_to_openflow10(ofpact_get_OUTPUT(a), out);
2437 case OFPACT_ENQUEUE:
2438 ofpact_enqueue_to_openflow10(ofpact_get_ENQUEUE(a), out);
2441 case OFPACT_SET_VLAN_VID:
2442 ofputil_put_OFPAT10_SET_VLAN_VID(out)->vlan_vid
2443 = htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid);
2446 case OFPACT_SET_VLAN_PCP:
2447 ofputil_put_OFPAT10_SET_VLAN_PCP(out)->vlan_pcp
2448 = ofpact_get_SET_VLAN_PCP(a)->vlan_pcp;
2451 case OFPACT_STRIP_VLAN:
2452 ofputil_put_OFPAT10_STRIP_VLAN(out);
2455 case OFPACT_SET_ETH_SRC:
2456 memcpy(ofputil_put_OFPAT10_SET_DL_SRC(out)->dl_addr,
2457 ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2460 case OFPACT_SET_ETH_DST:
2461 memcpy(ofputil_put_OFPAT10_SET_DL_DST(out)->dl_addr,
2462 ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2465 case OFPACT_SET_IPV4_SRC:
2466 ofputil_put_OFPAT10_SET_NW_SRC(out)->nw_addr
2467 = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2470 case OFPACT_SET_IPV4_DST:
2471 ofputil_put_OFPAT10_SET_NW_DST(out)->nw_addr
2472 = ofpact_get_SET_IPV4_DST(a)->ipv4;
2475 case OFPACT_SET_IP_DSCP:
2476 ofputil_put_OFPAT10_SET_NW_TOS(out)->nw_tos
2477 = ofpact_get_SET_IP_DSCP(a)->dscp;
2480 case OFPACT_SET_L4_SRC_PORT:
2481 ofputil_put_OFPAT10_SET_TP_SRC(out)->tp_port
2482 = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
2485 case OFPACT_SET_L4_DST_PORT:
2486 ofputil_put_OFPAT10_SET_TP_DST(out)->tp_port
2487 = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
2490 case OFPACT_PUSH_VLAN:
2491 /* PUSH is a side effect of a SET_VLAN_VID/PCP, which should
2492 * follow this action. */
2495 case OFPACT_CLEAR_ACTIONS:
2496 case OFPACT_WRITE_ACTIONS:
2497 case OFPACT_GOTO_TABLE:
2505 case OFPACT_SET_FIELD:
2506 set_field_to_openflow(ofpact_get_SET_FIELD(a), out);
2509 case OFPACT_CONTROLLER:
2510 case OFPACT_OUTPUT_REG:
2512 case OFPACT_REG_MOVE:
2513 case OFPACT_REG_LOAD:
2514 case OFPACT_STACK_PUSH:
2515 case OFPACT_STACK_POP:
2516 case OFPACT_DEC_TTL:
2517 case OFPACT_SET_IP_ECN:
2518 case OFPACT_SET_IP_TTL:
2519 case OFPACT_SET_MPLS_TTL:
2520 case OFPACT_DEC_MPLS_TTL:
2521 case OFPACT_SET_TUNNEL:
2522 case OFPACT_WRITE_METADATA:
2523 case OFPACT_SET_QUEUE:
2524 case OFPACT_POP_QUEUE:
2525 case OFPACT_FIN_TIMEOUT:
2526 case OFPACT_RESUBMIT:
2528 case OFPACT_MULTIPATH:
2531 case OFPACT_PUSH_MPLS:
2532 case OFPACT_POP_MPLS:
2534 ofpact_to_nxast(a, out);
2539 /* Converting ofpacts to OpenFlow 1.1. */
2542 ofpact_output_to_openflow11(const struct ofpact_output *output,
2545 struct ofp11_action_output *oao;
2547 oao = ofputil_put_OFPAT11_OUTPUT(out);
2548 oao->port = ofputil_port_to_ofp11(output->port);
2549 oao->max_len = htons(output->max_len);
2553 ofpact_dec_ttl_to_openflow11(const struct ofpact_cnt_ids *dec_ttl,
2556 if (dec_ttl->n_controllers == 1 && dec_ttl->cnt_ids[0] == 0
2557 && (!dec_ttl->ofpact.compat ||
2558 dec_ttl->ofpact.compat == OFPUTIL_OFPAT11_DEC_NW_TTL)) {
2559 ofputil_put_OFPAT11_DEC_NW_TTL(out);
2561 ofpact_dec_ttl_to_nxast(dec_ttl, out);
2566 ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out)
2570 return ofpact_output_to_openflow11(ofpact_get_OUTPUT(a), out);
2572 case OFPACT_ENQUEUE:
2576 case OFPACT_SET_VLAN_VID:
2577 /* Push a VLAN tag, if one was not seen at action validation time. */
2578 if (!ofpact_get_SET_VLAN_VID(a)->flow_has_vlan
2579 && ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) {
2580 ofputil_put_OFPAT11_PUSH_VLAN(out)->ethertype
2581 = htons(ETH_TYPE_VLAN_8021Q);
2583 ofputil_put_OFPAT11_SET_VLAN_VID(out)->vlan_vid
2584 = htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid);
2587 case OFPACT_SET_VLAN_PCP:
2588 /* Push a VLAN tag, if one was not seen at action validation time. */
2589 if (!ofpact_get_SET_VLAN_PCP(a)->flow_has_vlan
2590 && ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) {
2591 ofputil_put_OFPAT11_PUSH_VLAN(out)->ethertype
2592 = htons(ETH_TYPE_VLAN_8021Q);
2594 ofputil_put_OFPAT11_SET_VLAN_PCP(out)->vlan_pcp
2595 = ofpact_get_SET_VLAN_PCP(a)->vlan_pcp;
2598 case OFPACT_STRIP_VLAN:
2599 ofputil_put_OFPAT11_POP_VLAN(out);
2602 case OFPACT_PUSH_VLAN:
2603 /* XXX ETH_TYPE_VLAN_8021AD case */
2604 ofputil_put_OFPAT11_PUSH_VLAN(out)->ethertype =
2605 htons(ETH_TYPE_VLAN_8021Q);
2608 case OFPACT_SET_QUEUE:
2609 ofputil_put_OFPAT11_SET_QUEUE(out)->queue_id
2610 = htonl(ofpact_get_SET_QUEUE(a)->queue_id);
2613 case OFPACT_SET_ETH_SRC:
2614 memcpy(ofputil_put_OFPAT11_SET_DL_SRC(out)->dl_addr,
2615 ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2618 case OFPACT_SET_ETH_DST:
2619 memcpy(ofputil_put_OFPAT11_SET_DL_DST(out)->dl_addr,
2620 ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2623 case OFPACT_SET_IPV4_SRC:
2624 ofputil_put_OFPAT11_SET_NW_SRC(out)->nw_addr
2625 = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2628 case OFPACT_SET_IPV4_DST:
2629 ofputil_put_OFPAT11_SET_NW_DST(out)->nw_addr
2630 = ofpact_get_SET_IPV4_DST(a)->ipv4;
2633 case OFPACT_SET_IP_DSCP:
2634 ofputil_put_OFPAT11_SET_NW_TOS(out)->nw_tos
2635 = ofpact_get_SET_IP_DSCP(a)->dscp;
2638 case OFPACT_SET_IP_ECN:
2639 ofputil_put_OFPAT11_SET_NW_ECN(out)->nw_ecn
2640 = ofpact_get_SET_IP_ECN(a)->ecn;
2643 case OFPACT_SET_IP_TTL:
2644 ofputil_put_OFPAT11_SET_NW_TTL(out)->nw_ttl
2645 = ofpact_get_SET_IP_TTL(a)->ttl;
2648 case OFPACT_SET_L4_SRC_PORT:
2649 ofputil_put_OFPAT11_SET_TP_SRC(out)->tp_port
2650 = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
2653 case OFPACT_SET_L4_DST_PORT:
2654 ofputil_put_OFPAT11_SET_TP_DST(out)->tp_port
2655 = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
2658 case OFPACT_DEC_TTL:
2659 ofpact_dec_ttl_to_openflow11(ofpact_get_DEC_TTL(a), out);
2662 case OFPACT_SET_MPLS_TTL:
2663 ofputil_put_OFPAT11_SET_MPLS_TTL(out)->mpls_ttl
2664 = ofpact_get_SET_MPLS_TTL(a)->ttl;
2667 case OFPACT_DEC_MPLS_TTL:
2668 ofputil_put_OFPAT11_DEC_MPLS_TTL(out);
2671 case OFPACT_WRITE_METADATA:
2672 /* OpenFlow 1.1 uses OFPIT_WRITE_METADATA to express this action. */
2675 case OFPACT_PUSH_MPLS:
2676 ofputil_put_OFPAT11_PUSH_MPLS(out)->ethertype =
2677 ofpact_get_PUSH_MPLS(a)->ethertype;
2680 case OFPACT_POP_MPLS:
2681 ofputil_put_OFPAT11_POP_MPLS(out)->ethertype =
2682 ofpact_get_POP_MPLS(a)->ethertype;
2686 case OFPACT_CLEAR_ACTIONS:
2687 case OFPACT_WRITE_ACTIONS:
2688 case OFPACT_GOTO_TABLE:
2693 ofputil_put_OFPAT11_GROUP(out)->group_id =
2694 htonl(ofpact_get_GROUP(a)->group_id);
2697 case OFPACT_SET_FIELD:
2698 set_field_to_openflow(ofpact_get_SET_FIELD(a), out);
2701 case OFPACT_CONTROLLER:
2702 case OFPACT_OUTPUT_REG:
2704 case OFPACT_REG_MOVE:
2705 case OFPACT_REG_LOAD:
2706 case OFPACT_STACK_PUSH:
2707 case OFPACT_STACK_POP:
2708 case OFPACT_SET_TUNNEL:
2709 case OFPACT_POP_QUEUE:
2710 case OFPACT_FIN_TIMEOUT:
2711 case OFPACT_RESUBMIT:
2713 case OFPACT_MULTIPATH:
2717 ofpact_to_nxast(a, out);
2722 /* Output deprecated set actions as set_field actions. */
2724 ofpact_to_openflow12(const struct ofpact *a, struct ofpbuf *out)
2726 enum mf_field_id field;
2727 union mf_value value;
2728 struct ofpact_l4_port *l4port;
2732 * Convert actions deprecated in OpenFlow 1.2 to Set Field actions,
2735 switch ((int)a->type) {
2736 case OFPACT_SET_VLAN_VID:
2737 case OFPACT_SET_VLAN_PCP:
2738 case OFPACT_SET_ETH_SRC:
2739 case OFPACT_SET_ETH_DST:
2740 case OFPACT_SET_IPV4_SRC:
2741 case OFPACT_SET_IPV4_DST:
2742 case OFPACT_SET_IP_DSCP:
2743 case OFPACT_SET_IP_ECN:
2744 case OFPACT_SET_L4_SRC_PORT:
2745 case OFPACT_SET_L4_DST_PORT:
2746 case OFPACT_SET_TUNNEL: /* Convert to a set_field, too. */
2748 switch ((int)a->type) {
2750 case OFPACT_SET_VLAN_VID:
2751 if (!ofpact_get_SET_VLAN_VID(a)->flow_has_vlan &&
2752 ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) {
2753 ofputil_put_OFPAT11_PUSH_VLAN(out)->ethertype
2754 = htons(ETH_TYPE_VLAN_8021Q);
2756 field = MFF_VLAN_VID;
2757 /* Set-Field on OXM_OF_VLAN_VID must have OFPVID_PRESENT set. */
2758 value.be16 = htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid
2759 | OFPVID12_PRESENT);
2762 case OFPACT_SET_VLAN_PCP:
2763 if (!ofpact_get_SET_VLAN_PCP(a)->flow_has_vlan &&
2764 ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) {
2765 ofputil_put_OFPAT11_PUSH_VLAN(out)->ethertype
2766 = htons(ETH_TYPE_VLAN_8021Q);
2768 field = MFF_VLAN_PCP;
2769 value.u8 = ofpact_get_SET_VLAN_PCP(a)->vlan_pcp;
2772 case OFPACT_SET_ETH_SRC:
2773 field = MFF_ETH_SRC;
2774 memcpy(value.mac, ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2777 case OFPACT_SET_ETH_DST:
2778 field = MFF_ETH_DST;
2779 memcpy(value.mac, ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2782 case OFPACT_SET_IPV4_SRC:
2783 field = MFF_IPV4_SRC;
2784 value.be32 = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2787 case OFPACT_SET_IPV4_DST:
2788 field = MFF_IPV4_DST;
2789 value.be32 = ofpact_get_SET_IPV4_DST(a)->ipv4;
2792 case OFPACT_SET_IP_DSCP:
2793 field = MFF_IP_DSCP_SHIFTED; /* OXM_OF_IP_DSCP */
2794 value.u8 = ofpact_get_SET_IP_DSCP(a)->dscp >> 2;
2797 case OFPACT_SET_IP_ECN:
2799 value.u8 = ofpact_get_SET_IP_ECN(a)->ecn;
2802 case OFPACT_SET_L4_SRC_PORT:
2803 /* We keep track of IP protocol while translating actions to be
2804 * able to translate to the proper OXM type.
2805 * If the IP protocol type is unknown, the translation cannot
2806 * be performed and we will send the action using the original
2808 l4port = ofpact_get_SET_L4_SRC_PORT(a);
2809 proto = l4port->flow_ip_proto;
2810 field = proto == IPPROTO_TCP ? MFF_TCP_SRC
2811 : proto == IPPROTO_UDP ? MFF_UDP_SRC
2812 : proto == IPPROTO_SCTP ? MFF_SCTP_SRC
2813 : MFF_N_IDS; /* RFC: Unknown IP proto, do not translate. */
2814 value.be16 = htons(l4port->port);
2817 case OFPACT_SET_L4_DST_PORT:
2818 l4port = ofpact_get_SET_L4_DST_PORT(a);
2819 proto = l4port->flow_ip_proto;
2820 field = proto == IPPROTO_TCP ? MFF_TCP_DST
2821 : proto == IPPROTO_UDP ? MFF_UDP_DST
2822 : proto == IPPROTO_SCTP ? MFF_SCTP_DST
2823 : MFF_N_IDS; /* RFC: Unknown IP proto, do not translate. */
2824 value.be16 = htons(l4port->port);
2827 case OFPACT_SET_TUNNEL:
2829 value.be64 = htonll(ofpact_get_SET_TUNNEL(a)->tun_id);
2836 /* Put the action out as a set field action, if possible. */
2837 if (field < MFF_N_IDS) {
2838 uint64_t ofpacts_stub[128 / 8];
2839 struct ofpbuf sf_act;
2840 struct ofpact_set_field *sf;
2842 ofpbuf_use_stub(&sf_act, ofpacts_stub, sizeof ofpacts_stub);
2843 sf = ofpact_put_SET_FIELD(&sf_act);
2844 sf->field = mf_from_id(field);
2845 memcpy(&sf->value, &value, sf->field->n_bytes);
2846 set_field_to_openflow(sf, out);
2851 ofpact_to_openflow11(a, out);
2854 /* Converts the 'ofpacts_len' bytes of ofpacts in 'ofpacts' into OpenFlow
2855 * actions in 'openflow', appending the actions to any existing data in
2858 ofpacts_put_openflow_actions(const struct ofpact ofpacts[], size_t ofpacts_len,
2859 struct ofpbuf *openflow,
2860 enum ofp_version ofp_version)
2862 const struct ofpact *a;
2863 size_t start_size = openflow->size;
2865 void (*translate)(const struct ofpact *a, struct ofpbuf *out) =
2866 (ofp_version == OFP10_VERSION) ? ofpact_to_openflow10 :
2867 (ofp_version == OFP11_VERSION) ? ofpact_to_openflow11 :
2868 ofpact_to_openflow12;
2870 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2871 translate(a, openflow);
2873 return openflow->size - start_size;
2877 ofpacts_update_instruction_actions(struct ofpbuf *openflow, size_t ofs)
2879 struct ofp11_instruction_actions *oia;
2881 /* Update the instruction's length (or, if it's empty, delete it). */
2882 oia = ofpbuf_at_assert(openflow, ofs, sizeof *oia);
2883 if (openflow->size > ofs + sizeof *oia) {
2884 oia->len = htons(openflow->size - ofs);
2886 openflow->size = ofs;
2891 ofpacts_put_openflow_instructions(const struct ofpact ofpacts[],
2893 struct ofpbuf *openflow,
2894 enum ofp_version ofp_version)
2896 const struct ofpact *a;
2898 ovs_assert(ofp_version >= OFP11_VERSION);
2900 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2901 switch (ovs_instruction_type_from_ofpact_type(a->type)) {
2902 case OVSINST_OFPIT11_CLEAR_ACTIONS:
2903 instruction_put_OFPIT11_CLEAR_ACTIONS(openflow);
2906 case OVSINST_OFPIT11_GOTO_TABLE: {
2907 struct ofp11_instruction_goto_table *oigt;
2908 oigt = instruction_put_OFPIT11_GOTO_TABLE(openflow);
2909 oigt->table_id = ofpact_get_GOTO_TABLE(a)->table_id;
2910 memset(oigt->pad, 0, sizeof oigt->pad);
2914 case OVSINST_OFPIT11_WRITE_METADATA: {
2915 const struct ofpact_metadata *om;
2916 struct ofp11_instruction_write_metadata *oiwm;
2918 om = ofpact_get_WRITE_METADATA(a);
2919 oiwm = instruction_put_OFPIT11_WRITE_METADATA(openflow);
2920 oiwm->metadata = om->metadata;
2921 oiwm->metadata_mask = om->mask;
2925 case OVSINST_OFPIT13_METER:
2926 if (ofp_version >= OFP13_VERSION) {
2927 const struct ofpact_meter *om;
2928 struct ofp13_instruction_meter *oim;
2930 om = ofpact_get_METER(a);
2931 oim = instruction_put_OFPIT13_METER(openflow);
2932 oim->meter_id = htonl(om->meter_id);
2936 case OVSINST_OFPIT11_APPLY_ACTIONS: {
2937 const size_t ofs = openflow->size;
2938 const size_t ofpacts_len_left =
2939 (uint8_t*)ofpact_end(ofpacts, ofpacts_len) - (uint8_t*)a;
2940 const struct ofpact *action;
2941 const struct ofpact *processed = a;
2943 instruction_put_OFPIT11_APPLY_ACTIONS(openflow);
2944 OFPACT_FOR_EACH(action, a, ofpacts_len_left) {
2945 if (ovs_instruction_type_from_ofpact_type(action->type)
2946 != OVSINST_OFPIT11_APPLY_ACTIONS) {
2949 if (ofp_version == OFP11_VERSION) {
2950 ofpact_to_openflow11(action, openflow);
2952 ofpact_to_openflow12(action, openflow);
2956 ofpacts_update_instruction_actions(openflow, ofs);
2961 case OVSINST_OFPIT11_WRITE_ACTIONS: {
2962 const size_t ofs = openflow->size;
2963 const struct ofpact_nest *on;
2965 on = ofpact_get_WRITE_ACTIONS(a);
2966 instruction_put_OFPIT11_WRITE_ACTIONS(openflow);
2967 ofpacts_put_openflow_actions(on->actions,
2968 ofpact_nest_get_action_len(on),
2969 openflow, ofp_version);
2970 ofpacts_update_instruction_actions(openflow, ofs);
2978 /* Returns true if 'action' outputs to 'port', false otherwise. */
2980 ofpact_outputs_to_port(const struct ofpact *ofpact, ofp_port_t port)
2982 switch (ofpact->type) {
2984 return ofpact_get_OUTPUT(ofpact)->port == port;
2985 case OFPACT_ENQUEUE:
2986 return ofpact_get_ENQUEUE(ofpact)->port == port;
2987 case OFPACT_CONTROLLER:
2988 return port == OFPP_CONTROLLER;
2990 case OFPACT_OUTPUT_REG:
2992 case OFPACT_SET_VLAN_VID:
2993 case OFPACT_SET_VLAN_PCP:
2994 case OFPACT_STRIP_VLAN:
2995 case OFPACT_PUSH_VLAN:
2996 case OFPACT_SET_ETH_SRC:
2997 case OFPACT_SET_ETH_DST:
2998 case OFPACT_SET_IPV4_SRC:
2999 case OFPACT_SET_IPV4_DST:
3000 case OFPACT_SET_IP_DSCP:
3001 case OFPACT_SET_IP_ECN:
3002 case OFPACT_SET_IP_TTL:
3003 case OFPACT_SET_L4_SRC_PORT:
3004 case OFPACT_SET_L4_DST_PORT:
3005 case OFPACT_REG_MOVE:
3006 case OFPACT_REG_LOAD:
3007 case OFPACT_SET_FIELD:
3008 case OFPACT_STACK_PUSH:
3009 case OFPACT_STACK_POP:
3010 case OFPACT_DEC_TTL:
3011 case OFPACT_SET_MPLS_TTL:
3012 case OFPACT_DEC_MPLS_TTL:
3013 case OFPACT_SET_TUNNEL:
3014 case OFPACT_WRITE_METADATA:
3015 case OFPACT_SET_QUEUE:
3016 case OFPACT_POP_QUEUE:
3017 case OFPACT_FIN_TIMEOUT:
3018 case OFPACT_RESUBMIT:
3020 case OFPACT_MULTIPATH:
3023 case OFPACT_PUSH_MPLS:
3024 case OFPACT_POP_MPLS:
3026 case OFPACT_CLEAR_ACTIONS:
3027 case OFPACT_WRITE_ACTIONS:
3028 case OFPACT_GOTO_TABLE:
3036 /* Returns true if any action in the 'ofpacts_len' bytes of 'ofpacts' outputs
3037 * to 'port', false otherwise. */
3039 ofpacts_output_to_port(const struct ofpact *ofpacts, size_t ofpacts_len,
3042 const struct ofpact *a;
3044 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
3045 if (ofpact_outputs_to_port(a, port)) {
3053 /* Returns true if any action in the 'ofpacts_len' bytes of 'ofpacts' outputs
3054 * to 'group', false otherwise. */
3056 ofpacts_output_to_group(const struct ofpact *ofpacts, size_t ofpacts_len,
3059 const struct ofpact *a;
3061 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
3062 if (a->type == OFPACT_GROUP
3063 && ofpact_get_GROUP(a)->group_id == group_id) {
3072 ofpacts_equal(const struct ofpact *a, size_t a_len,
3073 const struct ofpact *b, size_t b_len)
3075 return a_len == b_len && !memcmp(a, b, a_len);
3078 /* Finds the OFPACT_METER action, if any, in the 'ofpacts_len' bytes of
3079 * 'ofpacts'. If found, returns its meter ID; if not, returns 0.
3081 * This function relies on the order of 'ofpacts' being correct (as checked by
3082 * ofpacts_verify()). */
3084 ofpacts_get_meter(const struct ofpact ofpacts[], size_t ofpacts_len)
3086 const struct ofpact *a;
3088 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
3089 enum ovs_instruction_type inst;
3091 inst = ovs_instruction_type_from_ofpact_type(a->type);
3092 if (a->type == OFPACT_METER) {
3093 return ofpact_get_METER(a)->meter_id;
3094 } else if (inst > OVSINST_OFPIT13_METER) {
3102 /* Formatting ofpacts. */
3105 print_note(const struct ofpact_note *note, struct ds *string)
3109 ds_put_cstr(string, "note:");
3110 for (i = 0; i < note->length; i++) {
3112 ds_put_char(string, '.');
3114 ds_put_format(string, "%02"PRIx8, note->data[i]);
3119 print_dec_ttl(const struct ofpact_cnt_ids *ids,
3124 ds_put_cstr(s, "dec_ttl");
3125 if (ids->ofpact.compat == OFPUTIL_NXAST_DEC_TTL_CNT_IDS) {
3126 ds_put_cstr(s, "(");
3127 for (i = 0; i < ids->n_controllers; i++) {
3129 ds_put_cstr(s, ",");
3131 ds_put_format(s, "%"PRIu16, ids->cnt_ids[i]);
3133 ds_put_cstr(s, ")");
3138 print_fin_timeout(const struct ofpact_fin_timeout *fin_timeout,
3141 ds_put_cstr(s, "fin_timeout(");
3142 if (fin_timeout->fin_idle_timeout) {
3143 ds_put_format(s, "idle_timeout=%"PRIu16",",
3144 fin_timeout->fin_idle_timeout);
3146 if (fin_timeout->fin_hard_timeout) {
3147 ds_put_format(s, "hard_timeout=%"PRIu16",",
3148 fin_timeout->fin_hard_timeout);
3151 ds_put_char(s, ')');
3155 ofpact_format(const struct ofpact *a, struct ds *s)
3157 const struct ofpact_enqueue *enqueue;
3158 const struct ofpact_resubmit *resubmit;
3159 const struct ofpact_controller *controller;
3160 const struct ofpact_metadata *metadata;
3161 const struct ofpact_tunnel *tunnel;
3162 const struct ofpact_sample *sample;
3163 const struct ofpact_set_field *set_field;
3164 const struct mf_field *mf;
3169 port = ofpact_get_OUTPUT(a)->port;
3170 if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX)) {
3171 ds_put_format(s, "output:%"PRIu16, port);
3173 ofputil_format_port(port, s);
3174 if (port == OFPP_CONTROLLER) {
3175 ds_put_format(s, ":%"PRIu16, ofpact_get_OUTPUT(a)->max_len);
3180 case OFPACT_CONTROLLER:
3181 controller = ofpact_get_CONTROLLER(a);
3182 if (controller->reason == OFPR_ACTION &&
3183 controller->controller_id == 0) {
3184 ds_put_format(s, "CONTROLLER:%"PRIu16,
3185 ofpact_get_CONTROLLER(a)->max_len);
3187 enum ofp_packet_in_reason reason = controller->reason;
3189 ds_put_cstr(s, "controller(");
3190 if (reason != OFPR_ACTION) {
3191 char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
3193 ds_put_format(s, "reason=%s,",
3194 ofputil_packet_in_reason_to_string(
3195 reason, reasonbuf, sizeof reasonbuf));
3197 if (controller->max_len != UINT16_MAX) {
3198 ds_put_format(s, "max_len=%"PRIu16",", controller->max_len);
3200 if (controller->controller_id != 0) {
3201 ds_put_format(s, "id=%"PRIu16",", controller->controller_id);
3204 ds_put_char(s, ')');
3208 case OFPACT_ENQUEUE:
3209 enqueue = ofpact_get_ENQUEUE(a);
3210 ds_put_format(s, "enqueue:");
3211 ofputil_format_port(enqueue->port, s);
3212 ds_put_format(s, "q%"PRIu32, enqueue->queue);
3215 case OFPACT_OUTPUT_REG:
3216 ds_put_cstr(s, "output:");
3217 mf_format_subfield(&ofpact_get_OUTPUT_REG(a)->src, s);
3221 bundle_format(ofpact_get_BUNDLE(a), s);
3224 case OFPACT_SET_VLAN_VID:
3225 ds_put_format(s, "%s:%"PRIu16,
3226 (a->compat == OFPUTIL_OFPAT11_SET_VLAN_VID
3229 ofpact_get_SET_VLAN_VID(a)->vlan_vid);
3232 case OFPACT_SET_VLAN_PCP:
3233 ds_put_format(s, "%s:%"PRIu8,
3234 (a->compat == OFPUTIL_OFPAT11_SET_VLAN_PCP
3237 ofpact_get_SET_VLAN_PCP(a)->vlan_pcp);
3240 case OFPACT_STRIP_VLAN:
3241 ds_put_cstr(s, a->compat == OFPUTIL_OFPAT11_POP_VLAN
3242 ? "pop_vlan" : "strip_vlan");
3245 case OFPACT_PUSH_VLAN:
3246 /* XXX 802.1AD case*/
3247 ds_put_format(s, "push_vlan:%#"PRIx16, ETH_TYPE_VLAN_8021Q);
3250 case OFPACT_SET_ETH_SRC:
3251 ds_put_format(s, "mod_dl_src:"ETH_ADDR_FMT,
3252 ETH_ADDR_ARGS(ofpact_get_SET_ETH_SRC(a)->mac));
3255 case OFPACT_SET_ETH_DST:
3256 ds_put_format(s, "mod_dl_dst:"ETH_ADDR_FMT,
3257 ETH_ADDR_ARGS(ofpact_get_SET_ETH_DST(a)->mac));
3260 case OFPACT_SET_IPV4_SRC:
3261 ds_put_format(s, "mod_nw_src:"IP_FMT,
3262 IP_ARGS(ofpact_get_SET_IPV4_SRC(a)->ipv4));
3265 case OFPACT_SET_IPV4_DST:
3266 ds_put_format(s, "mod_nw_dst:"IP_FMT,
3267 IP_ARGS(ofpact_get_SET_IPV4_DST(a)->ipv4));
3270 case OFPACT_SET_IP_DSCP:
3271 ds_put_format(s, "mod_nw_tos:%d", ofpact_get_SET_IP_DSCP(a)->dscp);
3274 case OFPACT_SET_IP_ECN:
3275 ds_put_format(s, "mod_nw_ecn:%d", ofpact_get_SET_IP_ECN(a)->ecn);
3278 case OFPACT_SET_IP_TTL:
3279 ds_put_format(s, "mod_nw_ttl:%d", ofpact_get_SET_IP_TTL(a)->ttl);
3282 case OFPACT_SET_L4_SRC_PORT:
3283 ds_put_format(s, "mod_tp_src:%d", ofpact_get_SET_L4_SRC_PORT(a)->port);
3286 case OFPACT_SET_L4_DST_PORT:
3287 ds_put_format(s, "mod_tp_dst:%d", ofpact_get_SET_L4_DST_PORT(a)->port);
3290 case OFPACT_REG_MOVE:
3291 nxm_format_reg_move(ofpact_get_REG_MOVE(a), s);
3294 case OFPACT_REG_LOAD:
3295 nxm_format_reg_load(ofpact_get_REG_LOAD(a), s);
3298 case OFPACT_SET_FIELD:
3299 set_field = ofpact_get_SET_FIELD(a);
3300 mf = set_field->field;
3301 ds_put_format(s, "set_field:");
3302 mf_format(mf, &set_field->value, NULL, s);
3303 ds_put_format(s, "->%s", mf->name);
3306 case OFPACT_STACK_PUSH:
3307 nxm_format_stack_push(ofpact_get_STACK_PUSH(a), s);
3310 case OFPACT_STACK_POP:
3311 nxm_format_stack_pop(ofpact_get_STACK_POP(a), s);
3314 case OFPACT_DEC_TTL:
3315 print_dec_ttl(ofpact_get_DEC_TTL(a), s);
3318 case OFPACT_SET_MPLS_TTL:
3319 ds_put_format(s, "set_mpls_ttl(%"PRIu8")",
3320 ofpact_get_SET_MPLS_TTL(a)->ttl);
3323 case OFPACT_DEC_MPLS_TTL:
3324 ds_put_cstr(s, "dec_mpls_ttl");
3327 case OFPACT_SET_TUNNEL:
3328 tunnel = ofpact_get_SET_TUNNEL(a);
3329 ds_put_format(s, "set_tunnel%s:%#"PRIx64,
3330 (tunnel->tun_id > UINT32_MAX
3331 || a->compat == OFPUTIL_NXAST_SET_TUNNEL64 ? "64" : ""),
3335 case OFPACT_SET_QUEUE:
3336 ds_put_format(s, "set_queue:%"PRIu32,
3337 ofpact_get_SET_QUEUE(a)->queue_id);
3340 case OFPACT_POP_QUEUE:
3341 ds_put_cstr(s, "pop_queue");
3344 case OFPACT_FIN_TIMEOUT:
3345 print_fin_timeout(ofpact_get_FIN_TIMEOUT(a), s);
3348 case OFPACT_RESUBMIT:
3349 resubmit = ofpact_get_RESUBMIT(a);
3350 if (resubmit->in_port != OFPP_IN_PORT && resubmit->table_id == 255) {
3351 ds_put_cstr(s, "resubmit:");
3352 ofputil_format_port(resubmit->in_port, s);
3354 ds_put_format(s, "resubmit(");
3355 if (resubmit->in_port != OFPP_IN_PORT) {
3356 ofputil_format_port(resubmit->in_port, s);
3358 ds_put_char(s, ',');
3359 if (resubmit->table_id != 255) {
3360 ds_put_format(s, "%"PRIu8, resubmit->table_id);
3362 ds_put_char(s, ')');
3367 learn_format(ofpact_get_LEARN(a), s);
3370 case OFPACT_MULTIPATH:
3371 multipath_format(ofpact_get_MULTIPATH(a), s);
3375 print_note(ofpact_get_NOTE(a), s);
3378 case OFPACT_PUSH_MPLS:
3379 ds_put_format(s, "push_mpls:0x%04"PRIx16,
3380 ntohs(ofpact_get_PUSH_MPLS(a)->ethertype));
3383 case OFPACT_POP_MPLS:
3384 ds_put_format(s, "pop_mpls:0x%04"PRIx16,
3385 ntohs(ofpact_get_POP_MPLS(a)->ethertype));
3389 ds_put_cstr(s, "exit");
3393 sample = ofpact_get_SAMPLE(a);
3395 s, "sample(probability=%"PRIu16",collector_set_id=%"PRIu32
3396 ",obs_domain_id=%"PRIu32",obs_point_id=%"PRIu32")",
3397 sample->probability, sample->collector_set_id,
3398 sample->obs_domain_id, sample->obs_point_id);
3401 case OFPACT_WRITE_ACTIONS: {
3402 struct ofpact_nest *on = ofpact_get_WRITE_ACTIONS(a);
3403 ds_put_format(s, "%s(",
3404 ovs_instruction_name_from_type(
3405 OVSINST_OFPIT11_WRITE_ACTIONS));
3406 ofpacts_format(on->actions, ofpact_nest_get_action_len(on), s);
3407 ds_put_char(s, ')');
3411 case OFPACT_CLEAR_ACTIONS:
3412 ds_put_format(s, "%s",
3413 ovs_instruction_name_from_type(
3414 OVSINST_OFPIT11_CLEAR_ACTIONS));
3417 case OFPACT_WRITE_METADATA:
3418 metadata = ofpact_get_WRITE_METADATA(a);
3419 ds_put_format(s, "%s:%#"PRIx64,
3420 ovs_instruction_name_from_type(
3421 OVSINST_OFPIT11_WRITE_METADATA),
3422 ntohll(metadata->metadata));
3423 if (metadata->mask != OVS_BE64_MAX) {
3424 ds_put_format(s, "/%#"PRIx64, ntohll(metadata->mask));
3428 case OFPACT_GOTO_TABLE:
3429 ds_put_format(s, "%s:%"PRIu8,
3430 ovs_instruction_name_from_type(
3431 OVSINST_OFPIT11_GOTO_TABLE),
3432 ofpact_get_GOTO_TABLE(a)->table_id);
3436 ds_put_format(s, "%s:%"PRIu32,
3437 ovs_instruction_name_from_type(OVSINST_OFPIT13_METER),
3438 ofpact_get_METER(a)->meter_id);
3442 ds_put_format(s, "group:%"PRIu32,
3443 ofpact_get_GROUP(a)->group_id);
3448 /* Appends a string representing the 'ofpacts_len' bytes of ofpacts in
3449 * 'ofpacts' to 'string'. */
3451 ofpacts_format(const struct ofpact *ofpacts, size_t ofpacts_len,
3455 ds_put_cstr(string, "drop");
3457 const struct ofpact *a;
3459 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
3461 ds_put_cstr(string, ",");
3464 /* XXX write-actions */
3465 ofpact_format(a, string);
3470 /* Internal use by helpers. */
3473 ofpact_put(struct ofpbuf *ofpacts, enum ofpact_type type, size_t len)
3475 struct ofpact *ofpact;
3477 ofpact_pad(ofpacts);
3478 ofpact = ofpacts->l2 = ofpbuf_put_uninit(ofpacts, len);
3479 ofpact_init(ofpact, type, len);
3484 ofpact_init(struct ofpact *ofpact, enum ofpact_type type, size_t len)
3486 memset(ofpact, 0, len);
3487 ofpact->type = type;
3488 ofpact->compat = OFPUTIL_ACTION_INVALID;
3492 /* Updates 'ofpact->len' to the number of bytes in the tail of 'ofpacts'
3493 * starting at 'ofpact'.
3495 * This is the correct way to update a variable-length ofpact's length after
3496 * adding the variable-length part of the payload. (See the large comment
3497 * near the end of ofp-actions.h for more information.) */
3499 ofpact_update_len(struct ofpbuf *ofpacts, struct ofpact *ofpact)
3501 ovs_assert(ofpact == ofpacts->l2);
3502 ofpact->len = (char *) ofpbuf_tail(ofpacts) - (char *) ofpact;
3505 /* Pads out 'ofpacts' to a multiple of OFPACT_ALIGNTO bytes in length. Each
3506 * ofpact_put_<ENUM>() calls this function automatically beforehand, but the
3507 * client must call this itself after adding the final ofpact to an array of
3510 * (The consequences of failing to call this function are probably not dire.
3511 * OFPACT_FOR_EACH will calculate a pointer beyond the end of the ofpacts, but
3512 * not dereference it. That's undefined behavior, technically, but it will not
3513 * cause a real problem on common systems. Still, it seems better to call
3516 ofpact_pad(struct ofpbuf *ofpacts)
3518 unsigned int rem = ofpacts->size % OFPACT_ALIGNTO;
3520 ofpbuf_put_zeros(ofpacts, OFPACT_ALIGNTO - rem);