blob: 1cdcfbde8503ff37dc4ca93d38053ab77bcd0649 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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
Neale Ranns81424992017-05-18 03:03:22 -070016#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>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010020
21/**
22 * Source initialisation Function
23 */
24static void
25fib_entry_src_api_init (fib_entry_src_t *src)
26{
27}
28
29/**
30 * Source deinitialisation Function
31 */
32static void
33fib_entry_src_api_deinit (fib_entry_src_t *src)
34{
35}
36
37static void
38fib_entry_src_api_path_swap (fib_entry_src_t *src,
Neale Ranns81424992017-05-18 03:03:22 -070039 const fib_entry_t *entry,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010040 fib_path_list_flags_t pl_flags,
Neale Ranns81424992017-05-18 03:03:22 -070041 const fib_route_path_t *rpaths)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010042{
Neale Ranns81424992017-05-18 03:03:22 -070043 const fib_route_path_t *rpath;
44
45 fib_path_ext_list_flush(&src->fes_path_exts);
46
Neale Ranns0bfe5d82016-08-25 15:29:12 +010047 src->fes_pl = fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags),
Neale Ranns81424992017-05-18 03:03:22 -070048 rpaths);
49
50 vec_foreach(rpath, rpaths)
51 {
52 if (NULL != rpath->frp_label_stack)
53 {
54 fib_path_ext_list_push_back(&src->fes_path_exts,
55 src->fes_pl,
56 FIB_PATH_EXT_MPLS,
57 rpath);
58 }
59 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +010060}
61
62static void
63fib_entry_src_api_path_add (fib_entry_src_t *src,
64 const fib_entry_t *entry,
65 fib_path_list_flags_t pl_flags,
Neale Ranns81424992017-05-18 03:03:22 -070066 const fib_route_path_t *rpaths)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010067{
Neale Ranns81424992017-05-18 03:03:22 -070068 const fib_route_path_t *rpath;
69
Neale Ranns0bfe5d82016-08-25 15:29:12 +010070 if (FIB_NODE_INDEX_INVALID == src->fes_pl)
71 {
72 src->fes_pl =
Neale Ranns81424992017-05-18 03:03:22 -070073 fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags), rpaths);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010074 }
75 else
76 {
77 src->fes_pl =
78 fib_path_list_copy_and_path_add(src->fes_pl,
79 (FIB_PATH_LIST_FLAG_SHARED | pl_flags),
Neale Ranns81424992017-05-18 03:03:22 -070080 rpaths);
81 }
82
83 /*
84 * re-resolve all the path-extensions with the new path-list
85 */
86 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 vec_foreach(rpath, rpaths)
92 {
93 if (NULL != rpath->frp_label_stack)
94 {
95 fib_path_ext_list_insert(&src->fes_path_exts,
96 src->fes_pl,
97 FIB_PATH_EXT_MPLS,
98 rpath);
99 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100100 }
101}
102
103static void
104fib_entry_src_api_path_remove (fib_entry_src_t *src,
105 fib_path_list_flags_t pl_flags,
Neale Ranns81424992017-05-18 03:03:22 -0700106 const fib_route_path_t *rpaths)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100107{
Neale Ranns81424992017-05-18 03:03:22 -0700108 const fib_route_path_t *rpath;
109
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100110 if (FIB_NODE_INDEX_INVALID != src->fes_pl)
111 {
112 src->fes_pl =
113 fib_path_list_copy_and_path_remove(src->fes_pl,
114 (FIB_PATH_LIST_FLAG_SHARED | pl_flags),
Neale Ranns81424992017-05-18 03:03:22 -0700115 rpaths);
116 /*
117 * remove the path-extension for the path
118 */
119 vec_foreach(rpath, rpaths)
120 {
121 fib_path_ext_list_remove(&src->fes_path_exts, FIB_PATH_EXT_MPLS, rpath);
122 };
123 /*
124 * resolve the remaining extensions
125 */
126 fib_path_ext_list_resolve(&src->fes_path_exts, src->fes_pl);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100127 }
128}
129
130static void
131fib_entry_src_api_add (fib_entry_src_t *src,
132 const fib_entry_t *entry,
133 fib_entry_flag_t flags,
Neale Rannsda78f952017-05-24 09:15:43 -0700134 dpo_proto_t proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100135 const dpo_id_t *dpo)
136{
137 if (FIB_ENTRY_FLAG_NONE != flags)
138 {
139 src->fes_pl = fib_path_list_create_special(
140 proto,
141 fib_entry_src_flags_2_path_list_flags(flags),
142 dpo);
143 }
144}
145
146static void
147fib_entry_src_api_remove (fib_entry_src_t *src)
148{
149 src->fes_pl = FIB_NODE_INDEX_INVALID;
150}
151
152const 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
162void
163fib_entry_src_api_register (void)
164{
165 fib_entry_src_register(FIB_SOURCE_PLUGIN_HI, &api_src_vft);
166 fib_entry_src_register(FIB_SOURCE_API, &api_src_vft);
167 fib_entry_src_register(FIB_SOURCE_CLI, &api_src_vft);
168 fib_entry_src_register(FIB_SOURCE_DHCP, &api_src_vft);
Neale Ranns3f844d02017-02-18 00:03:54 -0800169 fib_entry_src_register(FIB_SOURCE_IP6_ND_PROXY, &api_src_vft);
shwethabb18e0de2017-03-29 11:36:37 +0000170 fib_entry_src_register(FIB_SOURCE_SR, &api_src_vft);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100171}