]> git.proxmox.com Git - mirror_ovs.git/blame - lib/autopath.c
Global replace of Nicira Networks.
[mirror_ovs.git] / lib / autopath.c
CommitLineData
3b6a2571 1/*
e0edde6f 2 * Copyright (c) 2011 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"
90bf1e07 27#include "ofp-errors.h"
3b6a2571
EJ
28#include "ofp-util.h"
29#include "openflow/nicira-ext.h"
30#include "vlog.h"
31
32VLOG_DEFINE_THIS_MODULE(autopath);
33
3b6a2571
EJ
34/* Loads 'ofp_port' into the appropriate register in accordance with the
35 * autopath action. */
36void
37autopath_execute(const struct nx_action_autopath *ap, struct flow *flow,
38 uint16_t ofp_port)
39{
816fd533
BP
40 struct mf_subfield dst;
41
42 nxm_decode(&dst, ap->dst, ap->ofs_nbits);
43 mf_set_subfield_value(&dst, ofp_port, flow);
3b6a2571
EJ
44}
45
46void
47autopath_parse(struct nx_action_autopath *ap, const char *s_)
48{
49 char *s;
816fd533
BP
50 char *id_str, *dst_s, *save_ptr;
51 struct mf_subfield dst;
52 int id_int;
3b6a2571
EJ
53
54 s = xstrdup(s_);
55 save_ptr = NULL;
56 id_str = strtok_r(s, ", ", &save_ptr);
816fd533 57 dst_s = strtok_r(NULL, ", ", &save_ptr);
3b6a2571 58
816fd533 59 if (!dst_s) {
3b6a2571
EJ
60 ovs_fatal(0, "%s: not enough arguments to autopath action", s_);
61 }
62
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);
67 }
68
816fd533
BP
69 mf_parse_subfield(&dst, dst_s);
70 if (dst.n_bits < 16) {
3b6a2571 71 ovs_fatal(0, "%s: %d-bit destination field has %u possible values, "
816fd533
BP
72 "less than required 65536",
73 s_, dst.n_bits, 1u << dst.n_bits);
3b6a2571
EJ
74 }
75
93996add 76 ofputil_init_NXAST_AUTOPATH(ap);
3b6a2571 77 ap->id = htonl(id_int);
816fd533
BP
78 ap->ofs_nbits = nxm_encode_ofs_nbits(dst.ofs, dst.n_bits);
79 ap->dst = htonl(dst.field->nxm_header);
3b6a2571
EJ
80
81 free(s);
82}
83
90bf1e07 84enum ofperr
43edca57 85autopath_check(const struct nx_action_autopath *ap, const struct flow *flow)
3b6a2571 86{
816fd533 87 struct mf_subfield dst;
ce523f65 88
816fd533
BP
89 nxm_decode(&dst, ap->dst, ap->ofs_nbits);
90 if (dst.n_bits < 16) {
ce523f65
EJ
91 VLOG_WARN("at least 16 bit destination is required for autopath "
92 "action.");
90bf1e07 93 return OFPERR_OFPBAC_BAD_ARGUMENT;
ce523f65
EJ
94 }
95
816fd533 96 return mf_check_dst(&dst, flow);
3b6a2571 97}