]>
Commit | Line | Data |
---|---|---|
3b6a2571 | 1 | /* |
f25d0cf3 | 2 | * Copyright (c) 2011, 2012 Nicira, Inc. |
3b6a2571 EJ |
3 | * |
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: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
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. | |
15 | */ | |
16 | ||
17 | #include <config.h> | |
18 | ||
19 | #include "autopath.h" | |
20 | ||
21 | #include <inttypes.h> | |
22 | #include <stdlib.h> | |
23 | ||
24 | #include "flow.h" | |
816fd533 | 25 | #include "meta-flow.h" |
3b6a2571 | 26 | #include "nx-match.h" |
f25d0cf3 | 27 | #include "ofp-actions.h" |
90bf1e07 | 28 | #include "ofp-errors.h" |
3b6a2571 EJ |
29 | #include "ofp-util.h" |
30 | #include "openflow/nicira-ext.h" | |
31 | #include "vlog.h" | |
32 | ||
33 | VLOG_DEFINE_THIS_MODULE(autopath); | |
34 | ||
3b6a2571 | 35 | void |
f25d0cf3 | 36 | autopath_parse(struct ofpact_autopath *ap, const char *s_) |
3b6a2571 EJ |
37 | { |
38 | char *s; | |
f25d0cf3 | 39 | char *id_str, *dst, *save_ptr; |
8010100b | 40 | uint16_t port; |
f25d0cf3 BP |
41 | |
42 | ofpact_init_AUTOPATH(ap); | |
3b6a2571 EJ |
43 | |
44 | s = xstrdup(s_); | |
45 | save_ptr = NULL; | |
46 | id_str = strtok_r(s, ", ", &save_ptr); | |
f25d0cf3 | 47 | dst = strtok_r(NULL, ", ", &save_ptr); |
3b6a2571 | 48 | |
f25d0cf3 | 49 | if (!dst) { |
3b6a2571 EJ |
50 | ovs_fatal(0, "%s: not enough arguments to autopath action", s_); |
51 | } | |
52 | ||
8010100b | 53 | if (!ofputil_port_from_string(id_str, &port)) { |
c6100d92 | 54 | ovs_fatal(0, "%s: bad port number", s_); |
3b6a2571 | 55 | } |
8010100b | 56 | ap->port = port; |
3b6a2571 | 57 | |
f25d0cf3 BP |
58 | mf_parse_subfield(&ap->dst, dst); |
59 | if (ap->dst.n_bits < 16) { | |
3b6a2571 | 60 | ovs_fatal(0, "%s: %d-bit destination field has %u possible values, " |
816fd533 | 61 | "less than required 65536", |
f25d0cf3 | 62 | s_, ap->dst.n_bits, 1u << ap->dst.n_bits); |
3b6a2571 EJ |
63 | } |
64 | ||
3b6a2571 EJ |
65 | free(s); |
66 | } | |
67 | ||
90bf1e07 | 68 | enum ofperr |
f25d0cf3 BP |
69 | autopath_from_openflow(const struct nx_action_autopath *nap, |
70 | struct ofpact_autopath *autopath) | |
3b6a2571 | 71 | { |
f25d0cf3 BP |
72 | ofpact_init_AUTOPATH(autopath); |
73 | autopath->dst.field = mf_from_nxm_header(ntohl(nap->dst)); | |
74 | autopath->dst.ofs = nxm_decode_ofs(nap->ofs_nbits); | |
75 | autopath->dst.n_bits = nxm_decode_n_bits(nap->ofs_nbits); | |
76 | autopath->port = ntohl(nap->id); | |
ce523f65 | 77 | |
f25d0cf3 | 78 | if (autopath->dst.n_bits < 16) { |
ce523f65 EJ |
79 | VLOG_WARN("at least 16 bit destination is required for autopath " |
80 | "action."); | |
90bf1e07 | 81 | return OFPERR_OFPBAC_BAD_ARGUMENT; |
ce523f65 EJ |
82 | } |
83 | ||
f25d0cf3 BP |
84 | return autopath_check(autopath, NULL); |
85 | } | |
86 | ||
87 | enum ofperr | |
88 | autopath_check(const struct ofpact_autopath *autopath, const struct flow *flow) | |
89 | { | |
c51c638a EJ |
90 | VLOG_WARN_ONCE("The autopath action is deprecated and may be removed in" |
91 | " February 2013. Please email dev@openvswitch.org with" | |
92 | " concerns."); | |
f25d0cf3 BP |
93 | return mf_check_dst(&autopath->dst, flow); |
94 | } | |
95 | ||
96 | void | |
97 | autopath_to_nxast(const struct ofpact_autopath *autopath, | |
98 | struct ofpbuf *openflow) | |
99 | { | |
c51c638a | 100 | struct nx_action_autopath *ap; |
f25d0cf3 | 101 | |
c51c638a | 102 | ap = ofputil_put_NXAST_AUTOPATH__DEPRECATED(openflow); |
f25d0cf3 BP |
103 | ap->ofs_nbits = nxm_encode_ofs_nbits(autopath->dst.ofs, |
104 | autopath->dst.n_bits); | |
105 | ap->dst = htonl(autopath->dst.field->nxm_header); | |
106 | ap->id = htonl(autopath->port); | |
3b6a2571 | 107 | } |