2 * Copyright (c) 2011, 2012 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-actions.h"
28 #include "ofp-errors.h"
30 #include "openflow/nicira-ext.h"
33 VLOG_DEFINE_THIS_MODULE(autopath);
36 autopath_parse(struct ofpact_autopath *ap, const char *s_)
40 char *id_str, *dst, *save_ptr;
42 ofpact_init_AUTOPATH(ap);
46 id_str = strtok_r(s, ", ", &save_ptr);
47 dst = strtok_r(NULL, ", ", &save_ptr);
50 ovs_fatal(0, "%s: not enough arguments to autopath action", s_);
53 id_int = atoi(id_str);
54 if (id_int < 1 || id_int > UINT32_MAX) {
55 ovs_fatal(0, "%s: autopath id %d is not in valid range "
56 "1 to %"PRIu32, s_, id_int, UINT32_MAX);
60 mf_parse_subfield(&ap->dst, dst);
61 if (ap->dst.n_bits < 16) {
62 ovs_fatal(0, "%s: %d-bit destination field has %u possible values, "
63 "less than required 65536",
64 s_, ap->dst.n_bits, 1u << ap->dst.n_bits);
71 autopath_from_openflow(const struct nx_action_autopath *nap,
72 struct ofpact_autopath *autopath)
74 ofpact_init_AUTOPATH(autopath);
75 autopath->dst.field = mf_from_nxm_header(ntohl(nap->dst));
76 autopath->dst.ofs = nxm_decode_ofs(nap->ofs_nbits);
77 autopath->dst.n_bits = nxm_decode_n_bits(nap->ofs_nbits);
78 autopath->port = ntohl(nap->id);
80 if (autopath->dst.n_bits < 16) {
81 VLOG_WARN("at least 16 bit destination is required for autopath "
83 return OFPERR_OFPBAC_BAD_ARGUMENT;
86 return autopath_check(autopath, NULL);
90 autopath_check(const struct ofpact_autopath *autopath, const struct flow *flow)
92 return mf_check_dst(&autopath->dst, flow);
96 autopath_to_nxast(const struct ofpact_autopath *autopath,
97 struct ofpbuf *openflow)
99 struct nx_action_autopath *ap = ofputil_put_NXAST_AUTOPATH(openflow);
101 ap->ofs_nbits = nxm_encode_ofs_nbits(autopath->dst.ofs,
102 autopath->dst.n_bits);
103 ap->dst = htonl(autopath->dst.field->nxm_header);
104 ap->id = htonl(autopath->port);