Line data Source code
1 : /*
2 : * Copyright (c) 2016 Cisco and/or its affiliates.
3 : * Licensed under the Apache License, Version 2.0 (the "License");
4 : * you may not use this file except in compliance with the License.
5 : * You may obtain a copy of the License at:
6 : *
7 : * http://www.apache.org/licenses/LICENSE-2.0
8 : *
9 : * Unless required by applicable law or agreed to in writing, software
10 : * distributed under the License is distributed on an "AS IS" BASIS,
11 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : * See the License for the specific language governing permissions and
13 : * limitations under the License.
14 : */
15 :
16 : #include <vnet/fib/fib_entry.h>
17 : #include <vnet/fib/fib_entry_src.h>
18 : #include <vnet/fib/fib_path_list.h>
19 : #include <vnet/fib/fib_path_ext.h>
20 :
21 : /**
22 : * Source initialisation Function
23 : */
24 : static void
25 6088 : fib_entry_src_api_init (fib_entry_src_t *src)
26 : {
27 6088 : }
28 :
29 : /**
30 : * Source deinitialisation Function
31 : */
32 : static void
33 5829 : fib_entry_src_api_deinit (fib_entry_src_t *src)
34 : {
35 5829 : }
36 :
37 : static void
38 6971 : fib_entry_src_api_path_swap (fib_entry_src_t *src,
39 : const fib_entry_t *entry,
40 : fib_path_list_flags_t pl_flags,
41 : const fib_route_path_t *rpaths)
42 : {
43 : const fib_route_path_t *rpath;
44 :
45 6971 : fib_path_ext_list_flush(&src->fes_path_exts);
46 :
47 6971 : src->fes_pl = fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags),
48 : rpaths);
49 :
50 28155 : vec_foreach(rpath, rpaths)
51 : {
52 21184 : if (NULL != rpath->frp_label_stack)
53 : {
54 270 : fib_path_ext_list_push_back(&src->fes_path_exts,
55 : src->fes_pl,
56 : FIB_PATH_EXT_MPLS,
57 : rpath);
58 : }
59 : }
60 6971 : }
61 :
62 : static void
63 309 : fib_entry_src_api_path_add (fib_entry_src_t *src,
64 : const fib_entry_t *entry,
65 : fib_path_list_flags_t pl_flags,
66 : const fib_route_path_t *rpaths)
67 : {
68 : const fib_route_path_t *rpath;
69 :
70 309 : if (FIB_NODE_INDEX_INVALID == src->fes_pl)
71 : {
72 26 : src->fes_pl =
73 26 : fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags), rpaths);
74 : }
75 : else
76 : {
77 283 : src->fes_pl =
78 283 : fib_path_list_copy_and_path_add(src->fes_pl,
79 283 : (FIB_PATH_LIST_FLAG_SHARED | pl_flags),
80 : rpaths);
81 : }
82 :
83 : /*
84 : * re-resolve all the path-extensions with the new path-list
85 : */
86 309 : fib_path_ext_list_resolve(&src->fes_path_exts, src->fes_pl);
87 :
88 : /*
89 : * if the path has a label we need to add a path extension
90 : */
91 618 : vec_foreach(rpath, rpaths)
92 : {
93 309 : if (NULL != rpath->frp_label_stack)
94 : {
95 6 : fib_path_ext_list_insert(&src->fes_path_exts,
96 : src->fes_pl,
97 : FIB_PATH_EXT_MPLS,
98 : rpath);
99 : }
100 : }
101 309 : }
102 :
103 : static void
104 74 : fib_entry_src_api_path_remove (fib_entry_src_t *src,
105 : fib_path_list_flags_t pl_flags,
106 : const fib_route_path_t *rpaths)
107 : {
108 : const fib_route_path_t *rpath;
109 :
110 74 : if (FIB_NODE_INDEX_INVALID != src->fes_pl)
111 : {
112 74 : src->fes_pl =
113 74 : fib_path_list_copy_and_path_remove(src->fes_pl,
114 74 : (FIB_PATH_LIST_FLAG_SHARED | pl_flags),
115 : rpaths);
116 : /*
117 : * remove the path-extension for the path
118 : */
119 148 : vec_foreach(rpath, rpaths)
120 : {
121 74 : fib_path_ext_list_remove(&src->fes_path_exts, FIB_PATH_EXT_MPLS, rpath);
122 : };
123 : /*
124 : * resolve the remaining extensions
125 : */
126 74 : fib_path_ext_list_resolve(&src->fes_path_exts, src->fes_pl);
127 : }
128 74 : }
129 :
130 : static void
131 6071 : fib_entry_src_api_add (fib_entry_src_t *src,
132 : const fib_entry_t *entry,
133 : fib_entry_flag_t flags,
134 : dpo_proto_t proto,
135 : const dpo_id_t *dpo)
136 : {
137 6071 : if (FIB_ENTRY_FLAG_NONE != flags)
138 : {
139 2199 : src->fes_pl = fib_path_list_create_special(
140 : proto,
141 : fib_entry_src_flags_2_path_list_flags(flags),
142 : dpo);
143 : }
144 6071 : }
145 :
146 : static void
147 5829 : fib_entry_src_api_remove (fib_entry_src_t *src)
148 : {
149 5829 : src->fes_pl = FIB_NODE_INDEX_INVALID;
150 5829 : }
151 :
152 : const static fib_entry_src_vft_t api_src_vft = {
153 : .fesv_init = fib_entry_src_api_init,
154 : .fesv_deinit = fib_entry_src_api_deinit,
155 : .fesv_add = fib_entry_src_api_add,
156 : .fesv_remove = fib_entry_src_api_remove,
157 : .fesv_path_add = fib_entry_src_api_path_add,
158 : .fesv_path_swap = fib_entry_src_api_path_swap,
159 : .fesv_path_remove = fib_entry_src_api_path_remove,
160 : };
161 :
162 : void
163 575 : fib_entry_src_api_register (void)
164 : {
165 575 : fib_entry_src_behaviour_register(FIB_SOURCE_BH_API, &api_src_vft);
166 575 : }
|