2 * Copyright (c) 2011 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.
25 #include "meta-flow.h"
27 #include "ofp-errors.h"
29 #include "openflow/nicira-ext.h"
32 VLOG_DEFINE_THIS_MODULE(autopath);
34 /* Loads 'ofp_port' into the appropriate register in accordance with the
37 autopath_execute(const struct nx_action_autopath *ap, struct flow *flow,
40 struct mf_subfield dst;
42 nxm_decode(&dst, ap->dst, ap->ofs_nbits);
43 mf_set_subfield_value(&dst, ofp_port, flow);
47 autopath_parse(struct nx_action_autopath *ap, const char *s_)
50 char *id_str, *dst_s, *save_ptr;
51 struct mf_subfield dst;
56 id_str = strtok_r(s, ", ", &save_ptr);
57 dst_s = strtok_r(NULL, ", ", &save_ptr);
60 ovs_fatal(0, "%s: not enough arguments to autopath action", s_);
63 id_int = atoi(id_str);
64 if (id_int < 1 || id_int > UINT32_MAX) {
65 ovs_fatal(0, "%s: autopath id %d is not in valid range "
66 "1 to %"PRIu32, s_, id_int, UINT32_MAX);
69 mf_parse_subfield(&dst, dst_s);
70 if (dst.n_bits < 16) {
71 ovs_fatal(0, "%s: %d-bit destination field has %u possible values, "
72 "less than required 65536",
73 s_, dst.n_bits, 1u << dst.n_bits);
76 ofputil_init_NXAST_AUTOPATH(ap);
77 ap->id = htonl(id_int);
78 ap->ofs_nbits = nxm_encode_ofs_nbits(dst.ofs, dst.n_bits);
79 ap->dst = htonl(dst.field->nxm_header);
85 autopath_check(const struct nx_action_autopath *ap, const struct flow *flow)
87 struct mf_subfield dst;
89 nxm_decode(&dst, ap->dst, ap->ofs_nbits);
90 if (dst.n_bits < 16) {
91 VLOG_WARN("at least 16 bit destination is required for autopath "
93 return OFPERR_OFPBAC_BAD_ARGUMENT;
96 return mf_check_dst(&dst, flow);