2 * Copyright (c) 2011 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.
27 #include "openflow/nicira-ext.h"
30 VLOG_DEFINE_THIS_MODULE(autopath);
32 /* Loads 'ofp_port' into the appropriate register in accordance with the
35 autopath_execute(const struct nx_action_autopath *ap, struct flow *flow,
38 nxm_reg_load(ap->dst, ap->ofs_nbits, ofp_port, flow);
42 autopath_parse(struct nx_action_autopath *ap, const char *s_)
46 int id_int, ofs, n_bits;
47 char *id_str, *dst, *save_ptr;
51 id_str = strtok_r(s, ", ", &save_ptr);
52 dst = strtok_r(NULL, ", ", &save_ptr);
55 ovs_fatal(0, "%s: not enough arguments to autopath action", s_);
58 id_int = atoi(id_str);
59 if (id_int < 1 || id_int > UINT32_MAX) {
60 ovs_fatal(0, "%s: autopath id %d is not in valid range "
61 "1 to %"PRIu32, s_, id_int, UINT32_MAX);
64 nxm_parse_field_bits(dst, ®, &ofs, &n_bits);
66 ovs_fatal(0, "%s: %d-bit destination field has %u possible values, "
67 "less than required 65536", s_, n_bits, 1u << n_bits);
70 ofputil_init_NXAST_AUTOPATH(ap);
71 ap->id = htonl(id_int);
72 ap->ofs_nbits = nxm_encode_ofs_nbits(ofs, n_bits);
79 autopath_check(const struct nx_action_autopath *ap, const struct flow *flow)
81 int n_bits = nxm_decode_n_bits(ap->ofs_nbits);
82 int ofs = nxm_decode_ofs(ap->ofs_nbits);
85 VLOG_WARN("at least 16 bit destination is required for autopath "
87 return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_BAD_ARGUMENT);
90 return nxm_dst_check(ap->dst, ofs, n_bits, flow);