]>
Commit | Line | Data |
---|---|---|
f8c06e2c OD |
1 | /* |
2 | * IS-IS Rout(e)ing protocol - isis_te.c | |
3 | * | |
68558b13 | 4 | * This is an implementation of RFC5305 & RFC 7810 |
f8c06e2c OD |
5 | * |
6 | * Copyright (C) 2014 Orange Labs | |
7 | * http://www.orange.com | |
8 | * | |
9 | * This file is part of GNU Zebra. | |
10 | * | |
11 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
12 | * under the terms of the GNU General Public License as published by the | |
13 | * Free Software Foundation; either version 2, or (at your option) any | |
14 | * later version. | |
15 | * | |
16 | * GNU Zebra is distributed in the hope that it will be useful, but | |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * General Public License for more details. | |
20 | * | |
896014f4 DL |
21 | * You should have received a copy of the GNU General Public License along |
22 | * with this program; see the file COPYING; if not, write to the Free Software | |
23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
f8c06e2c OD |
24 | */ |
25 | ||
26 | #include <zebra.h> | |
27 | #include <math.h> | |
28 | ||
29 | #include "linklist.h" | |
30 | #include "thread.h" | |
31 | #include "vty.h" | |
32 | #include "stream.h" | |
33 | #include "memory.h" | |
34 | #include "log.h" | |
35 | #include "prefix.h" | |
36 | #include "command.h" | |
37 | #include "hash.h" | |
38 | #include "if.h" | |
39 | #include "vrf.h" | |
40 | #include "checksum.h" | |
41 | #include "md5.h" | |
42 | #include "sockunion.h" | |
43 | #include "network.h" | |
af8ac8f9 | 44 | #include "sbuf.h" |
f8c06e2c OD |
45 | |
46 | #include "isisd/dict.h" | |
47 | #include "isisd/isis_constants.h" | |
48 | #include "isisd/isis_common.h" | |
49 | #include "isisd/isis_flags.h" | |
50 | #include "isisd/isis_circuit.h" | |
51 | #include "isisd/isisd.h" | |
f8c06e2c OD |
52 | #include "isisd/isis_lsp.h" |
53 | #include "isisd/isis_pdu.h" | |
54 | #include "isisd/isis_dynhn.h" | |
55 | #include "isisd/isis_misc.h" | |
56 | #include "isisd/isis_csm.h" | |
57 | #include "isisd/isis_adjacency.h" | |
58 | #include "isisd/isis_spf.h" | |
59 | #include "isisd/isis_te.h" | |
60 | ||
61 | /* Global varial for MPLS TE management */ | |
62 | struct isis_mpls_te isisMplsTE; | |
63 | ||
d62a17ae | 64 | const char *mode2text[] = {"Disable", "Area", "AS", "Emulate"}; |
f8c06e2c OD |
65 | |
66 | /*------------------------------------------------------------------------* | |
67 | * Followings are control functions for MPLS-TE parameters management. | |
68 | *------------------------------------------------------------------------*/ | |
69 | ||
70 | /* Search MPLS TE Circuit context from Interface */ | |
d62a17ae | 71 | static struct mpls_te_circuit *lookup_mpls_params_by_ifp(struct interface *ifp) |
f8c06e2c | 72 | { |
d62a17ae | 73 | struct isis_circuit *circuit; |
f8c06e2c | 74 | |
d62a17ae | 75 | if ((circuit = circuit_scan_by_ifp(ifp)) == NULL) |
76 | return NULL; | |
f8c06e2c | 77 | |
d62a17ae | 78 | return circuit->mtc; |
f8c06e2c OD |
79 | } |
80 | ||
81 | /* Create new MPLS TE Circuit context */ | |
d62a17ae | 82 | struct mpls_te_circuit *mpls_te_circuit_new() |
f8c06e2c | 83 | { |
d62a17ae | 84 | struct mpls_te_circuit *mtc; |
f8c06e2c | 85 | |
d62a17ae | 86 | zlog_debug("ISIS MPLS-TE: Create new MPLS TE Circuit context"); |
f8c06e2c | 87 | |
d62a17ae | 88 | mtc = XCALLOC(MTYPE_ISIS_MPLS_TE, sizeof(struct mpls_te_circuit)); |
f8c06e2c | 89 | |
d62a17ae | 90 | if (mtc == NULL) |
91 | return NULL; | |
f8c06e2c | 92 | |
d62a17ae | 93 | mtc->status = disable; |
94 | mtc->type = STD_TE; | |
95 | mtc->length = 0; | |
f8c06e2c | 96 | |
d62a17ae | 97 | return mtc; |
f8c06e2c OD |
98 | } |
99 | ||
d62a17ae | 100 | /* Copy SUB TLVs parameters into a buffer - No space verification are performed |
101 | */ | |
f8c06e2c | 102 | /* Caller must verify before that there is enough free space in the buffer */ |
af8ac8f9 | 103 | uint8_t add_te_subtlvs(uint8_t *buf, struct mpls_te_circuit *mtc) |
f8c06e2c | 104 | { |
af8ac8f9 | 105 | uint8_t size, *tlvs = buf; |
d62a17ae | 106 | |
107 | zlog_debug("ISIS MPLS-TE: Add TE Sub TLVs to buffer"); | |
108 | ||
109 | if (mtc == NULL) { | |
110 | zlog_debug( | |
111 | "ISIS MPLS-TE: Abort! No MPLS TE Circuit available has been specified"); | |
112 | return 0; | |
113 | } | |
114 | ||
115 | /* Create buffer if not provided */ | |
116 | if (buf == NULL) { | |
117 | zlog_debug("ISIS MPLS-TE: Abort! No Buffer has been specified"); | |
118 | return 0; | |
119 | } | |
120 | ||
121 | /* TE_SUBTLV_ADMIN_GRP */ | |
122 | if (SUBTLV_TYPE(mtc->admin_grp) != 0) { | |
123 | size = SUBTLV_SIZE(&(mtc->admin_grp.header)); | |
124 | memcpy(tlvs, &(mtc->admin_grp), size); | |
125 | tlvs += size; | |
126 | } | |
127 | ||
128 | /* TE_SUBTLV_LLRI */ | |
129 | if (SUBTLV_TYPE(mtc->llri) != 0) { | |
130 | size = SUBTLV_SIZE(&(mtc->llri.header)); | |
131 | memcpy(tlvs, &(mtc->llri), size); | |
132 | tlvs += size; | |
133 | } | |
134 | ||
135 | /* TE_SUBTLV_LCLIF_IPADDR */ | |
136 | if (SUBTLV_TYPE(mtc->local_ipaddr) != 0) { | |
137 | size = SUBTLV_SIZE(&(mtc->local_ipaddr.header)); | |
138 | memcpy(tlvs, &(mtc->local_ipaddr), size); | |
139 | tlvs += size; | |
140 | } | |
141 | ||
142 | /* TE_SUBTLV_RMTIF_IPADDR */ | |
143 | if (SUBTLV_TYPE(mtc->rmt_ipaddr) != 0) { | |
144 | size = SUBTLV_SIZE(&(mtc->rmt_ipaddr.header)); | |
145 | memcpy(tlvs, &(mtc->rmt_ipaddr), size); | |
146 | tlvs += size; | |
147 | } | |
148 | ||
149 | /* TE_SUBTLV_MAX_BW */ | |
150 | if (SUBTLV_TYPE(mtc->max_bw) != 0) { | |
151 | size = SUBTLV_SIZE(&(mtc->max_bw.header)); | |
152 | memcpy(tlvs, &(mtc->max_bw), size); | |
153 | tlvs += size; | |
154 | } | |
155 | ||
156 | /* TE_SUBTLV_MAX_RSV_BW */ | |
157 | if (SUBTLV_TYPE(mtc->max_rsv_bw) != 0) { | |
158 | size = SUBTLV_SIZE(&(mtc->max_rsv_bw.header)); | |
159 | memcpy(tlvs, &(mtc->max_rsv_bw), size); | |
160 | tlvs += size; | |
161 | } | |
162 | ||
163 | /* TE_SUBTLV_UNRSV_BW */ | |
164 | if (SUBTLV_TYPE(mtc->unrsv_bw) != 0) { | |
165 | size = SUBTLV_SIZE(&(mtc->unrsv_bw.header)); | |
166 | memcpy(tlvs, &(mtc->unrsv_bw), size); | |
167 | tlvs += size; | |
168 | } | |
169 | ||
170 | /* TE_SUBTLV_TE_METRIC */ | |
171 | if (SUBTLV_TYPE(mtc->te_metric) != 0) { | |
172 | size = SUBTLV_SIZE(&(mtc->te_metric.header)); | |
173 | memcpy(tlvs, &(mtc->te_metric), size); | |
174 | tlvs += size; | |
175 | } | |
176 | ||
177 | /* TE_SUBTLV_AV_DELAY */ | |
178 | if (SUBTLV_TYPE(mtc->av_delay) != 0) { | |
179 | size = SUBTLV_SIZE(&(mtc->av_delay.header)); | |
180 | memcpy(tlvs, &(mtc->av_delay), size); | |
181 | tlvs += size; | |
182 | } | |
183 | ||
184 | /* TE_SUBTLV_MM_DELAY */ | |
185 | if (SUBTLV_TYPE(mtc->mm_delay) != 0) { | |
186 | size = SUBTLV_SIZE(&(mtc->mm_delay.header)); | |
187 | memcpy(tlvs, &(mtc->mm_delay), size); | |
188 | tlvs += size; | |
189 | } | |
190 | ||
191 | /* TE_SUBTLV_DELAY_VAR */ | |
192 | if (SUBTLV_TYPE(mtc->delay_var) != 0) { | |
193 | size = SUBTLV_SIZE(&(mtc->delay_var.header)); | |
194 | memcpy(tlvs, &(mtc->delay_var), size); | |
195 | tlvs += size; | |
196 | } | |
197 | ||
198 | /* TE_SUBTLV_PKT_LOSS */ | |
199 | if (SUBTLV_TYPE(mtc->pkt_loss) != 0) { | |
200 | size = SUBTLV_SIZE(&(mtc->pkt_loss.header)); | |
201 | memcpy(tlvs, &(mtc->pkt_loss), size); | |
202 | tlvs += size; | |
203 | } | |
204 | ||
205 | /* TE_SUBTLV_RES_BW */ | |
206 | if (SUBTLV_TYPE(mtc->res_bw) != 0) { | |
207 | size = SUBTLV_SIZE(&(mtc->res_bw.header)); | |
208 | memcpy(tlvs, &(mtc->res_bw), size); | |
209 | tlvs += size; | |
210 | } | |
211 | ||
212 | /* TE_SUBTLV_AVA_BW */ | |
213 | if (SUBTLV_TYPE(mtc->ava_bw) != 0) { | |
214 | size = SUBTLV_SIZE(&(mtc->ava_bw.header)); | |
215 | memcpy(tlvs, &(mtc->ava_bw), size); | |
216 | tlvs += size; | |
217 | } | |
218 | ||
219 | /* TE_SUBTLV_USE_BW */ | |
220 | if (SUBTLV_TYPE(mtc->use_bw) != 0) { | |
221 | size = SUBTLV_SIZE(&(mtc->use_bw.header)); | |
222 | memcpy(tlvs, &(mtc->use_bw), size); | |
223 | tlvs += size; | |
224 | } | |
225 | ||
226 | /* Update SubTLVs length */ | |
227 | mtc->length = subtlvs_len(mtc); | |
228 | ||
229 | zlog_debug("ISIS MPLS-TE: Add %d bytes length SubTLVs", mtc->length); | |
230 | ||
231 | return mtc->length; | |
f8c06e2c OD |
232 | } |
233 | ||
234 | /* Compute total Sub-TLVs size */ | |
af8ac8f9 | 235 | uint8_t subtlvs_len(struct mpls_te_circuit *mtc) |
f8c06e2c | 236 | { |
d62a17ae | 237 | int length = 0; |
f8c06e2c | 238 | |
d62a17ae | 239 | /* Sanity Check */ |
240 | if (mtc == NULL) | |
241 | return 0; | |
f8c06e2c | 242 | |
d62a17ae | 243 | /* TE_SUBTLV_ADMIN_GRP */ |
244 | if (SUBTLV_TYPE(mtc->admin_grp) != 0) | |
245 | length += SUBTLV_SIZE(&(mtc->admin_grp.header)); | |
f8c06e2c | 246 | |
d62a17ae | 247 | /* TE_SUBTLV_LLRI */ |
248 | if (SUBTLV_TYPE(mtc->llri) != 0) | |
249 | length += SUBTLV_SIZE(&mtc->llri.header); | |
f8c06e2c | 250 | |
d62a17ae | 251 | /* TE_SUBTLV_LCLIF_IPADDR */ |
252 | if (SUBTLV_TYPE(mtc->local_ipaddr) != 0) | |
253 | length += SUBTLV_SIZE(&mtc->local_ipaddr.header); | |
f8c06e2c | 254 | |
d62a17ae | 255 | /* TE_SUBTLV_RMTIF_IPADDR */ |
256 | if (SUBTLV_TYPE(mtc->rmt_ipaddr) != 0) | |
257 | length += SUBTLV_SIZE(&mtc->rmt_ipaddr.header); | |
f8c06e2c | 258 | |
d62a17ae | 259 | /* TE_SUBTLV_MAX_BW */ |
260 | if (SUBTLV_TYPE(mtc->max_bw) != 0) | |
261 | length += SUBTLV_SIZE(&mtc->max_bw.header); | |
f8c06e2c | 262 | |
d62a17ae | 263 | /* TE_SUBTLV_MAX_RSV_BW */ |
264 | if (SUBTLV_TYPE(mtc->max_rsv_bw) != 0) | |
265 | length += SUBTLV_SIZE(&mtc->max_rsv_bw.header); | |
f8c06e2c | 266 | |
d62a17ae | 267 | /* TE_SUBTLV_UNRSV_BW */ |
268 | if (SUBTLV_TYPE(mtc->unrsv_bw) != 0) | |
269 | length += SUBTLV_SIZE(&mtc->unrsv_bw.header); | |
f8c06e2c | 270 | |
d62a17ae | 271 | /* TE_SUBTLV_TE_METRIC */ |
272 | if (SUBTLV_TYPE(mtc->te_metric) != 0) | |
273 | length += SUBTLV_SIZE(&mtc->te_metric.header); | |
f8c06e2c | 274 | |
d62a17ae | 275 | /* TE_SUBTLV_AV_DELAY */ |
276 | if (SUBTLV_TYPE(mtc->av_delay) != 0) | |
277 | length += SUBTLV_SIZE(&mtc->av_delay.header); | |
f8c06e2c | 278 | |
d62a17ae | 279 | /* TE_SUBTLV_MM_DELAY */ |
280 | if (SUBTLV_TYPE(mtc->mm_delay) != 0) | |
281 | length += SUBTLV_SIZE(&mtc->mm_delay.header); | |
f8c06e2c | 282 | |
d62a17ae | 283 | /* TE_SUBTLV_DELAY_VAR */ |
284 | if (SUBTLV_TYPE(mtc->delay_var) != 0) | |
285 | length += SUBTLV_SIZE(&mtc->delay_var.header); | |
f8c06e2c | 286 | |
d62a17ae | 287 | /* TE_SUBTLV_PKT_LOSS */ |
288 | if (SUBTLV_TYPE(mtc->pkt_loss) != 0) | |
289 | length += SUBTLV_SIZE(&mtc->pkt_loss.header); | |
f8c06e2c | 290 | |
d62a17ae | 291 | /* TE_SUBTLV_RES_BW */ |
292 | if (SUBTLV_TYPE(mtc->res_bw) != 0) | |
293 | length += SUBTLV_SIZE(&mtc->res_bw.header); | |
f8c06e2c | 294 | |
d62a17ae | 295 | /* TE_SUBTLV_AVA_BW */ |
296 | if (SUBTLV_TYPE(mtc->ava_bw) != 0) | |
297 | length += SUBTLV_SIZE(&mtc->ava_bw.header); | |
f8c06e2c | 298 | |
d62a17ae | 299 | /* TE_SUBTLV_USE_BW */ |
300 | if (SUBTLV_TYPE(mtc->use_bw) != 0) | |
301 | length += SUBTLV_SIZE(&mtc->use_bw.header); | |
f8c06e2c | 302 | |
d62a17ae | 303 | /* Check that length is lower than the MAXIMUM SUBTLV size i.e. 256 */ |
304 | if (length > MAX_SUBTLV_SIZE) { | |
305 | mtc->length = 0; | |
306 | return 0; | |
307 | } | |
f8c06e2c | 308 | |
af8ac8f9 | 309 | mtc->length = (uint8_t)length; |
f8c06e2c | 310 | |
d62a17ae | 311 | return mtc->length; |
f8c06e2c OD |
312 | } |
313 | ||
314 | /* Following are various functions to set MPLS TE parameters */ | |
d62a17ae | 315 | static void set_circuitparams_admin_grp(struct mpls_te_circuit *mtc, |
316 | u_int32_t admingrp) | |
f8c06e2c | 317 | { |
d62a17ae | 318 | SUBTLV_TYPE(mtc->admin_grp) = TE_SUBTLV_ADMIN_GRP; |
319 | SUBTLV_LEN(mtc->admin_grp) = SUBTLV_DEF_SIZE; | |
320 | mtc->admin_grp.value = htonl(admingrp); | |
321 | return; | |
f8c06e2c OD |
322 | } |
323 | ||
d62a17ae | 324 | static void __attribute__((unused)) |
325 | set_circuitparams_llri(struct mpls_te_circuit *mtc, u_int32_t local, | |
326 | u_int32_t remote) | |
f8c06e2c | 327 | { |
d62a17ae | 328 | SUBTLV_TYPE(mtc->llri) = TE_SUBTLV_LLRI; |
329 | SUBTLV_LEN(mtc->llri) = TE_SUBTLV_LLRI_SIZE; | |
330 | mtc->llri.local = htonl(local); | |
331 | mtc->llri.remote = htonl(remote); | |
f8c06e2c OD |
332 | } |
333 | ||
d62a17ae | 334 | void set_circuitparams_local_ipaddr(struct mpls_te_circuit *mtc, |
335 | struct in_addr addr) | |
f8c06e2c OD |
336 | { |
337 | ||
d62a17ae | 338 | SUBTLV_TYPE(mtc->local_ipaddr) = TE_SUBTLV_LOCAL_IPADDR; |
339 | SUBTLV_LEN(mtc->local_ipaddr) = SUBTLV_DEF_SIZE; | |
340 | mtc->local_ipaddr.value.s_addr = addr.s_addr; | |
341 | return; | |
f8c06e2c OD |
342 | } |
343 | ||
d62a17ae | 344 | void set_circuitparams_rmt_ipaddr(struct mpls_te_circuit *mtc, |
345 | struct in_addr addr) | |
f8c06e2c OD |
346 | { |
347 | ||
d62a17ae | 348 | SUBTLV_TYPE(mtc->rmt_ipaddr) = TE_SUBTLV_RMT_IPADDR; |
349 | SUBTLV_LEN(mtc->rmt_ipaddr) = SUBTLV_DEF_SIZE; | |
350 | mtc->rmt_ipaddr.value.s_addr = addr.s_addr; | |
351 | return; | |
f8c06e2c OD |
352 | } |
353 | ||
d62a17ae | 354 | static void set_circuitparams_max_bw(struct mpls_te_circuit *mtc, float fp) |
f8c06e2c | 355 | { |
d62a17ae | 356 | SUBTLV_TYPE(mtc->max_bw) = TE_SUBTLV_MAX_BW; |
357 | SUBTLV_LEN(mtc->max_bw) = SUBTLV_DEF_SIZE; | |
358 | mtc->max_bw.value = htonf(fp); | |
359 | return; | |
f8c06e2c OD |
360 | } |
361 | ||
d62a17ae | 362 | static void set_circuitparams_max_rsv_bw(struct mpls_te_circuit *mtc, float fp) |
f8c06e2c | 363 | { |
d62a17ae | 364 | SUBTLV_TYPE(mtc->max_rsv_bw) = TE_SUBTLV_MAX_RSV_BW; |
365 | SUBTLV_LEN(mtc->max_rsv_bw) = SUBTLV_DEF_SIZE; | |
366 | mtc->max_rsv_bw.value = htonf(fp); | |
367 | return; | |
f8c06e2c OD |
368 | } |
369 | ||
d62a17ae | 370 | static void set_circuitparams_unrsv_bw(struct mpls_te_circuit *mtc, |
371 | int priority, float fp) | |
f8c06e2c | 372 | { |
d62a17ae | 373 | /* Note that TLV-length field is the size of array. */ |
374 | SUBTLV_TYPE(mtc->unrsv_bw) = TE_SUBTLV_UNRSV_BW; | |
375 | SUBTLV_LEN(mtc->unrsv_bw) = TE_SUBTLV_UNRSV_SIZE; | |
376 | mtc->unrsv_bw.value[priority] = htonf(fp); | |
377 | return; | |
f8c06e2c OD |
378 | } |
379 | ||
d62a17ae | 380 | static void set_circuitparams_te_metric(struct mpls_te_circuit *mtc, |
381 | u_int32_t te_metric) | |
f8c06e2c | 382 | { |
d62a17ae | 383 | SUBTLV_TYPE(mtc->te_metric) = TE_SUBTLV_TE_METRIC; |
384 | SUBTLV_LEN(mtc->te_metric) = TE_SUBTLV_TE_METRIC_SIZE; | |
385 | mtc->te_metric.value[0] = (te_metric >> 16) & 0xFF; | |
386 | mtc->te_metric.value[1] = (te_metric >> 8) & 0xFF; | |
387 | mtc->te_metric.value[2] = te_metric & 0xFF; | |
388 | return; | |
f8c06e2c OD |
389 | } |
390 | ||
d62a17ae | 391 | static void set_circuitparams_inter_as(struct mpls_te_circuit *mtc, |
392 | struct in_addr addr, u_int32_t as) | |
f8c06e2c OD |
393 | { |
394 | ||
d62a17ae | 395 | /* Set the Remote ASBR IP address and then the associated AS number */ |
396 | SUBTLV_TYPE(mtc->rip) = TE_SUBTLV_RIP; | |
397 | SUBTLV_LEN(mtc->rip) = SUBTLV_DEF_SIZE; | |
398 | mtc->rip.value.s_addr = addr.s_addr; | |
f8c06e2c | 399 | |
d62a17ae | 400 | SUBTLV_TYPE(mtc->ras) = TE_SUBTLV_RAS; |
401 | SUBTLV_LEN(mtc->ras) = SUBTLV_DEF_SIZE; | |
402 | mtc->ras.value = htonl(as); | |
f8c06e2c OD |
403 | } |
404 | ||
d62a17ae | 405 | static void unset_circuitparams_inter_as(struct mpls_te_circuit *mtc) |
f8c06e2c OD |
406 | { |
407 | ||
d62a17ae | 408 | /* Reset the Remote ASBR IP address and then the associated AS number */ |
409 | SUBTLV_TYPE(mtc->rip) = 0; | |
410 | SUBTLV_LEN(mtc->rip) = 0; | |
411 | mtc->rip.value.s_addr = 0; | |
f8c06e2c | 412 | |
d62a17ae | 413 | SUBTLV_TYPE(mtc->ras) = 0; |
414 | SUBTLV_LEN(mtc->ras) = 0; | |
415 | mtc->ras.value = 0; | |
f8c06e2c OD |
416 | } |
417 | ||
d62a17ae | 418 | static void set_circuitparams_av_delay(struct mpls_te_circuit *mtc, |
419 | u_int32_t delay, u_char anormal) | |
f8c06e2c | 420 | { |
d62a17ae | 421 | u_int32_t tmp; |
422 | /* Note that TLV-length field is the size of array. */ | |
423 | SUBTLV_TYPE(mtc->av_delay) = TE_SUBTLV_AV_DELAY; | |
424 | SUBTLV_LEN(mtc->av_delay) = SUBTLV_DEF_SIZE; | |
425 | tmp = delay & TE_EXT_MASK; | |
426 | if (anormal) | |
427 | tmp |= TE_EXT_ANORMAL; | |
428 | mtc->av_delay.value = htonl(tmp); | |
429 | return; | |
f8c06e2c OD |
430 | } |
431 | ||
d62a17ae | 432 | static void set_circuitparams_mm_delay(struct mpls_te_circuit *mtc, |
433 | u_int32_t low, u_int32_t high, | |
434 | u_char anormal) | |
f8c06e2c | 435 | { |
d62a17ae | 436 | u_int32_t tmp; |
437 | /* Note that TLV-length field is the size of array. */ | |
438 | SUBTLV_TYPE(mtc->mm_delay) = TE_SUBTLV_MM_DELAY; | |
439 | SUBTLV_LEN(mtc->mm_delay) = TE_SUBTLV_MM_DELAY_SIZE; | |
440 | tmp = low & TE_EXT_MASK; | |
441 | if (anormal) | |
442 | tmp |= TE_EXT_ANORMAL; | |
443 | mtc->mm_delay.low = htonl(tmp); | |
444 | mtc->mm_delay.high = htonl(high); | |
445 | return; | |
f8c06e2c OD |
446 | } |
447 | ||
d62a17ae | 448 | static void set_circuitparams_delay_var(struct mpls_te_circuit *mtc, |
449 | u_int32_t jitter) | |
f8c06e2c | 450 | { |
d62a17ae | 451 | /* Note that TLV-length field is the size of array. */ |
452 | SUBTLV_TYPE(mtc->delay_var) = TE_SUBTLV_DELAY_VAR; | |
453 | SUBTLV_LEN(mtc->delay_var) = SUBTLV_DEF_SIZE; | |
454 | mtc->delay_var.value = htonl(jitter & TE_EXT_MASK); | |
455 | return; | |
f8c06e2c OD |
456 | } |
457 | ||
d62a17ae | 458 | static void set_circuitparams_pkt_loss(struct mpls_te_circuit *mtc, |
459 | u_int32_t loss, u_char anormal) | |
f8c06e2c | 460 | { |
d62a17ae | 461 | u_int32_t tmp; |
462 | /* Note that TLV-length field is the size of array. */ | |
463 | SUBTLV_TYPE(mtc->pkt_loss) = TE_SUBTLV_PKT_LOSS; | |
464 | SUBTLV_LEN(mtc->pkt_loss) = SUBTLV_DEF_SIZE; | |
465 | tmp = loss & TE_EXT_MASK; | |
466 | if (anormal) | |
467 | tmp |= TE_EXT_ANORMAL; | |
468 | mtc->pkt_loss.value = htonl(tmp); | |
469 | return; | |
f8c06e2c OD |
470 | } |
471 | ||
d62a17ae | 472 | static void set_circuitparams_res_bw(struct mpls_te_circuit *mtc, float fp) |
f8c06e2c | 473 | { |
d62a17ae | 474 | /* Note that TLV-length field is the size of array. */ |
475 | SUBTLV_TYPE(mtc->res_bw) = TE_SUBTLV_RES_BW; | |
476 | SUBTLV_LEN(mtc->res_bw) = SUBTLV_DEF_SIZE; | |
477 | mtc->res_bw.value = htonf(fp); | |
478 | return; | |
f8c06e2c OD |
479 | } |
480 | ||
d62a17ae | 481 | static void set_circuitparams_ava_bw(struct mpls_te_circuit *mtc, float fp) |
f8c06e2c | 482 | { |
d62a17ae | 483 | /* Note that TLV-length field is the size of array. */ |
484 | SUBTLV_TYPE(mtc->ava_bw) = TE_SUBTLV_AVA_BW; | |
485 | SUBTLV_LEN(mtc->ava_bw) = SUBTLV_DEF_SIZE; | |
486 | mtc->ava_bw.value = htonf(fp); | |
487 | return; | |
f8c06e2c OD |
488 | } |
489 | ||
d62a17ae | 490 | static void set_circuitparams_use_bw(struct mpls_te_circuit *mtc, float fp) |
f8c06e2c | 491 | { |
d62a17ae | 492 | /* Note that TLV-length field is the size of array. */ |
493 | SUBTLV_TYPE(mtc->use_bw) = TE_SUBTLV_USE_BW; | |
494 | SUBTLV_LEN(mtc->use_bw) = SUBTLV_DEF_SIZE; | |
495 | mtc->use_bw.value = htonf(fp); | |
496 | return; | |
f8c06e2c OD |
497 | } |
498 | ||
499 | /* Main initialization / update function of the MPLS TE Circuit context */ | |
500 | /* Call when interface TE Link parameters are modified */ | |
d62a17ae | 501 | void isis_link_params_update(struct isis_circuit *circuit, |
502 | struct interface *ifp) | |
f8c06e2c | 503 | { |
d62a17ae | 504 | int i; |
505 | struct prefix_ipv4 *addr; | |
506 | struct mpls_te_circuit *mtc; | |
507 | ||
508 | /* Sanity Check */ | |
509 | if ((circuit == NULL) || (ifp == NULL)) | |
510 | return; | |
511 | ||
512 | zlog_info("MPLS-TE: Initialize circuit parameters for interface %s", | |
513 | ifp->name); | |
514 | ||
515 | /* Check if MPLS TE Circuit context has not been already created */ | |
516 | if (circuit->mtc == NULL) | |
517 | circuit->mtc = mpls_te_circuit_new(); | |
518 | ||
519 | mtc = circuit->mtc; | |
520 | ||
521 | /* Fulfil MTC TLV from ifp TE Link parameters */ | |
522 | if (HAS_LINK_PARAMS(ifp)) { | |
523 | mtc->status = enable; | |
524 | /* STD_TE metrics */ | |
525 | if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP)) | |
526 | set_circuitparams_admin_grp( | |
527 | mtc, ifp->link_params->admin_grp); | |
528 | else | |
529 | SUBTLV_TYPE(mtc->admin_grp) = 0; | |
530 | ||
531 | /* If not already set, register local IP addr from ip_addr list | |
532 | * if it exists */ | |
533 | if (SUBTLV_TYPE(mtc->local_ipaddr) == 0) { | |
534 | if (circuit->ip_addrs != NULL | |
535 | && listcount(circuit->ip_addrs) != 0) { | |
536 | addr = (struct prefix_ipv4 *)listgetdata( | |
537 | (struct listnode *)listhead( | |
538 | circuit->ip_addrs)); | |
539 | set_circuitparams_local_ipaddr(mtc, | |
540 | addr->prefix); | |
541 | } | |
542 | } | |
543 | ||
544 | /* If not already set, try to determine Remote IP addr if | |
545 | * circuit is P2P */ | |
546 | if ((SUBTLV_TYPE(mtc->rmt_ipaddr) == 0) | |
547 | && (circuit->circ_type == CIRCUIT_T_P2P)) { | |
548 | struct isis_adjacency *adj = circuit->u.p2p.neighbor; | |
0c1bd758 CF |
549 | if (adj->ipv4_address_count) { |
550 | set_circuitparams_rmt_ipaddr( | |
551 | mtc, adj->ipv4_addresses[0]); | |
d62a17ae | 552 | } |
553 | } | |
554 | ||
555 | if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW)) | |
556 | set_circuitparams_max_bw(mtc, ifp->link_params->max_bw); | |
557 | else | |
558 | SUBTLV_TYPE(mtc->max_bw) = 0; | |
559 | ||
560 | if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW)) | |
561 | set_circuitparams_max_rsv_bw( | |
562 | mtc, ifp->link_params->max_rsv_bw); | |
563 | else | |
564 | SUBTLV_TYPE(mtc->max_rsv_bw) = 0; | |
565 | ||
566 | if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW)) | |
567 | for (i = 0; i < MAX_CLASS_TYPE; i++) | |
568 | set_circuitparams_unrsv_bw( | |
569 | mtc, i, ifp->link_params->unrsv_bw[i]); | |
570 | else | |
571 | SUBTLV_TYPE(mtc->unrsv_bw) = 0; | |
572 | ||
573 | if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC)) | |
574 | set_circuitparams_te_metric( | |
575 | mtc, ifp->link_params->te_metric); | |
576 | else | |
577 | SUBTLV_TYPE(mtc->te_metric) = 0; | |
578 | ||
579 | /* TE metric Extensions */ | |
580 | if (IS_PARAM_SET(ifp->link_params, LP_DELAY)) | |
581 | set_circuitparams_av_delay( | |
582 | mtc, ifp->link_params->av_delay, 0); | |
583 | else | |
584 | SUBTLV_TYPE(mtc->av_delay) = 0; | |
585 | ||
586 | if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY)) | |
587 | set_circuitparams_mm_delay( | |
588 | mtc, ifp->link_params->min_delay, | |
589 | ifp->link_params->max_delay, 0); | |
590 | else | |
591 | SUBTLV_TYPE(mtc->mm_delay) = 0; | |
592 | ||
593 | if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR)) | |
594 | set_circuitparams_delay_var( | |
595 | mtc, ifp->link_params->delay_var); | |
596 | else | |
597 | SUBTLV_TYPE(mtc->delay_var) = 0; | |
598 | ||
599 | if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS)) | |
600 | set_circuitparams_pkt_loss( | |
601 | mtc, ifp->link_params->pkt_loss, 0); | |
602 | else | |
603 | SUBTLV_TYPE(mtc->pkt_loss) = 0; | |
604 | ||
605 | if (IS_PARAM_SET(ifp->link_params, LP_RES_BW)) | |
606 | set_circuitparams_res_bw(mtc, ifp->link_params->res_bw); | |
607 | else | |
608 | SUBTLV_TYPE(mtc->res_bw) = 0; | |
609 | ||
610 | if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW)) | |
611 | set_circuitparams_ava_bw(mtc, ifp->link_params->ava_bw); | |
612 | else | |
613 | SUBTLV_TYPE(mtc->ava_bw) = 0; | |
614 | ||
615 | if (IS_PARAM_SET(ifp->link_params, LP_USE_BW)) | |
616 | set_circuitparams_use_bw(mtc, ifp->link_params->use_bw); | |
617 | else | |
618 | SUBTLV_TYPE(mtc->use_bw) = 0; | |
619 | ||
620 | /* INTER_AS */ | |
621 | if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS)) | |
622 | set_circuitparams_inter_as(mtc, | |
623 | ifp->link_params->rmt_ip, | |
624 | ifp->link_params->rmt_as); | |
625 | else | |
626 | /* reset inter-as TE params */ | |
627 | unset_circuitparams_inter_as(mtc); | |
628 | ||
629 | /* Compute total length of SUB TLVs */ | |
630 | mtc->length = subtlvs_len(mtc); | |
631 | ||
632 | } else | |
633 | mtc->status = disable; | |
634 | ||
635 | /* Finally Update LSP */ | |
f8c06e2c OD |
636 | #if 0 |
637 | if (IS_MPLS_TE(isisMplsTE) && circuit->area) | |
638 | lsp_regenerate_schedule (circuit->area, circuit->is_type, 0); | |
639 | #endif | |
d62a17ae | 640 | return; |
f8c06e2c OD |
641 | } |
642 | ||
d62a17ae | 643 | void isis_mpls_te_update(struct interface *ifp) |
f8c06e2c | 644 | { |
d62a17ae | 645 | struct isis_circuit *circuit; |
f8c06e2c | 646 | |
d62a17ae | 647 | /* Sanity Check */ |
648 | if (ifp == NULL) | |
649 | return; | |
f8c06e2c | 650 | |
d62a17ae | 651 | /* Get circuit context from interface */ |
652 | if ((circuit = circuit_scan_by_ifp(ifp)) == NULL) | |
653 | return; | |
f8c06e2c | 654 | |
d62a17ae | 655 | /* Update TE TLVs ... */ |
656 | isis_link_params_update(circuit, ifp); | |
f8c06e2c | 657 | |
d62a17ae | 658 | /* ... and LSP */ |
659 | if (IS_MPLS_TE(isisMplsTE) && circuit->area) | |
660 | lsp_regenerate_schedule(circuit->area, circuit->is_type, 0); | |
f8c06e2c | 661 | |
d62a17ae | 662 | return; |
f8c06e2c OD |
663 | } |
664 | ||
665 | /*------------------------------------------------------------------------* | |
666 | * Followings are vty session control functions. | |
667 | *------------------------------------------------------------------------*/ | |
668 | ||
af8ac8f9 CF |
669 | static u_char print_subtlv_admin_grp(struct sbuf *buf, int indent, |
670 | struct te_subtlv_admin_grp *tlv) | |
f8c06e2c | 671 | { |
af8ac8f9 CF |
672 | sbuf_push(buf, indent, "Administrative Group: 0x%" PRIx32 "\n", |
673 | ntohl(tlv->value)); | |
d62a17ae | 674 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
675 | } |
676 | ||
af8ac8f9 CF |
677 | static u_char print_subtlv_llri(struct sbuf *buf, int indent, |
678 | struct te_subtlv_llri *tlv) | |
f8c06e2c | 679 | { |
af8ac8f9 CF |
680 | sbuf_push(buf, indent, "Link Local ID: %" PRIu32 "\n", |
681 | ntohl(tlv->local)); | |
682 | sbuf_push(buf, indent, "Link Remote ID: %" PRIu32 "\n", | |
683 | ntohl(tlv->remote)); | |
d62a17ae | 684 | |
685 | return (SUBTLV_HDR_SIZE + TE_SUBTLV_LLRI_SIZE); | |
f8c06e2c OD |
686 | } |
687 | ||
af8ac8f9 CF |
688 | static u_char print_subtlv_local_ipaddr(struct sbuf *buf, int indent, |
689 | struct te_subtlv_local_ipaddr *tlv) | |
f8c06e2c | 690 | { |
af8ac8f9 CF |
691 | sbuf_push(buf, indent, "Local Interface IP Address(es): %s\n", |
692 | inet_ntoa(tlv->value)); | |
d62a17ae | 693 | |
694 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
695 | } |
696 | ||
af8ac8f9 CF |
697 | static u_char print_subtlv_rmt_ipaddr(struct sbuf *buf, int indent, |
698 | struct te_subtlv_rmt_ipaddr *tlv) | |
f8c06e2c | 699 | { |
af8ac8f9 CF |
700 | sbuf_push(buf, indent, "Remote Interface IP Address(es): %s\n", |
701 | inet_ntoa(tlv->value)); | |
d62a17ae | 702 | |
703 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
704 | } |
705 | ||
af8ac8f9 CF |
706 | static u_char print_subtlv_max_bw(struct sbuf *buf, int indent, |
707 | struct te_subtlv_max_bw *tlv) | |
f8c06e2c | 708 | { |
d62a17ae | 709 | float fval; |
f8c06e2c | 710 | |
d62a17ae | 711 | fval = ntohf(tlv->value); |
f8c06e2c | 712 | |
af8ac8f9 | 713 | sbuf_push(buf, indent, "Maximum Bandwidth: %g (Bytes/sec)\n", fval); |
f8c06e2c | 714 | |
d62a17ae | 715 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
716 | } |
717 | ||
af8ac8f9 CF |
718 | static u_char print_subtlv_max_rsv_bw(struct sbuf *buf, int indent, |
719 | struct te_subtlv_max_rsv_bw *tlv) | |
f8c06e2c | 720 | { |
d62a17ae | 721 | float fval; |
f8c06e2c | 722 | |
d62a17ae | 723 | fval = ntohf(tlv->value); |
f8c06e2c | 724 | |
af8ac8f9 | 725 | sbuf_push(buf, indent, "Maximum Reservable Bandwidth: %g (Bytes/sec)\n", fval); |
f8c06e2c | 726 | |
d62a17ae | 727 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
728 | } |
729 | ||
af8ac8f9 CF |
730 | static u_char print_subtlv_unrsv_bw(struct sbuf *buf, int indent, |
731 | struct te_subtlv_unrsv_bw *tlv) | |
f8c06e2c | 732 | { |
d62a17ae | 733 | float fval1, fval2; |
734 | int i; | |
735 | ||
af8ac8f9 | 736 | sbuf_push(buf, indent, "Unreserved Bandwidth:\n"); |
d62a17ae | 737 | |
738 | for (i = 0; i < MAX_CLASS_TYPE; i += 2) { | |
739 | fval1 = ntohf(tlv->value[i]); | |
740 | fval2 = ntohf(tlv->value[i + 1]); | |
af8ac8f9 CF |
741 | sbuf_push(buf, indent + 2, "[%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n", |
742 | i, fval1, i + 1, fval2); | |
d62a17ae | 743 | } |
744 | ||
745 | return (SUBTLV_HDR_SIZE + TE_SUBTLV_UNRSV_SIZE); | |
f8c06e2c OD |
746 | } |
747 | ||
af8ac8f9 CF |
748 | static u_char print_subtlv_te_metric(struct sbuf *buf, int indent, |
749 | struct te_subtlv_te_metric *tlv) | |
f8c06e2c | 750 | { |
d62a17ae | 751 | u_int32_t te_metric; |
f8c06e2c | 752 | |
d62a17ae | 753 | te_metric = tlv->value[2] | tlv->value[1] << 8 | tlv->value[0] << 16; |
af8ac8f9 | 754 | sbuf_push(buf, indent, "Traffic Engineering Metric: %u\n", te_metric); |
f8c06e2c | 755 | |
d62a17ae | 756 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
757 | } |
758 | ||
af8ac8f9 CF |
759 | static u_char print_subtlv_ras(struct sbuf *buf, int indent, |
760 | struct te_subtlv_ras *tlv) | |
f8c06e2c | 761 | { |
af8ac8f9 CF |
762 | sbuf_push(buf, indent, "Inter-AS TE Remote AS number: %" PRIu32 "\n", |
763 | ntohl(tlv->value)); | |
d62a17ae | 764 | |
765 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
766 | } |
767 | ||
af8ac8f9 CF |
768 | static u_char print_subtlv_rip(struct sbuf *buf, int indent, |
769 | struct te_subtlv_rip *tlv) | |
f8c06e2c | 770 | { |
af8ac8f9 CF |
771 | sbuf_push(buf, indent, "Inter-AS TE Remote ASBR IP address: %s\n", |
772 | inet_ntoa(tlv->value)); | |
d62a17ae | 773 | |
774 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
775 | } |
776 | ||
af8ac8f9 CF |
777 | static u_char print_subtlv_av_delay(struct sbuf *buf, int indent, |
778 | struct te_subtlv_av_delay *tlv) | |
f8c06e2c | 779 | { |
d62a17ae | 780 | u_int32_t delay; |
781 | u_int32_t A; | |
f8c06e2c | 782 | |
d62a17ae | 783 | delay = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; |
784 | A = (u_int32_t)ntohl(tlv->value) & TE_EXT_ANORMAL; | |
f8c06e2c | 785 | |
af8ac8f9 CF |
786 | sbuf_push(buf, indent, "%s Average Link Delay: %" PRIu32 " (micro-sec)\n", |
787 | A ? "Anomalous" : "Normal", delay); | |
f8c06e2c | 788 | |
d62a17ae | 789 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
790 | } |
791 | ||
af8ac8f9 CF |
792 | static u_char print_subtlv_mm_delay(struct sbuf *buf, int indent, |
793 | struct te_subtlv_mm_delay *tlv) | |
f8c06e2c | 794 | { |
d62a17ae | 795 | u_int32_t low, high; |
796 | u_int32_t A; | |
f8c06e2c | 797 | |
d62a17ae | 798 | low = (u_int32_t)ntohl(tlv->low) & TE_EXT_MASK; |
799 | A = (u_int32_t)ntohl(tlv->low) & TE_EXT_ANORMAL; | |
800 | high = (u_int32_t)ntohl(tlv->high) & TE_EXT_MASK; | |
f8c06e2c | 801 | |
af8ac8f9 CF |
802 | sbuf_push(buf, indent, "%s Min/Max Link Delay: %" PRIu32 " / %" PRIu32 " (micro-sec)\n", |
803 | A ? "Anomalous" : "Normal", low, high); | |
f8c06e2c | 804 | |
d62a17ae | 805 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
806 | } |
807 | ||
af8ac8f9 CF |
808 | static u_char print_subtlv_delay_var(struct sbuf *buf, int indent, |
809 | struct te_subtlv_delay_var *tlv) | |
f8c06e2c | 810 | { |
d62a17ae | 811 | u_int32_t jitter; |
f8c06e2c | 812 | |
d62a17ae | 813 | jitter = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; |
f8c06e2c | 814 | |
af8ac8f9 | 815 | sbuf_push(buf, indent, "Delay Variation: %" PRIu32 " (micro-sec)\n", jitter); |
f8c06e2c | 816 | |
d62a17ae | 817 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
818 | } |
819 | ||
af8ac8f9 CF |
820 | static u_char print_subtlv_pkt_loss(struct sbuf *buf, int indent, |
821 | struct te_subtlv_pkt_loss *tlv) | |
f8c06e2c | 822 | { |
d62a17ae | 823 | u_int32_t loss; |
824 | u_int32_t A; | |
825 | float fval; | |
826 | ||
827 | loss = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; | |
828 | fval = (float)(loss * LOSS_PRECISION); | |
829 | A = (u_int32_t)ntohl(tlv->value) & TE_EXT_ANORMAL; | |
830 | ||
af8ac8f9 CF |
831 | sbuf_push(buf, indent, "%s Link Packet Loss: %g (%%)\n", |
832 | A ? "Anomalous" : "Normal", fval); | |
d62a17ae | 833 | |
834 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
835 | } |
836 | ||
af8ac8f9 CF |
837 | static u_char print_subtlv_res_bw(struct sbuf *buf, int indent, |
838 | struct te_subtlv_res_bw *tlv) | |
f8c06e2c | 839 | { |
d62a17ae | 840 | float fval; |
f8c06e2c | 841 | |
d62a17ae | 842 | fval = ntohf(tlv->value); |
f8c06e2c | 843 | |
af8ac8f9 CF |
844 | sbuf_push(buf, indent, "Unidirectional Residual Bandwidth: %g (Bytes/sec)\n", |
845 | fval); | |
f8c06e2c | 846 | |
d62a17ae | 847 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
848 | } |
849 | ||
af8ac8f9 CF |
850 | static u_char print_subtlv_ava_bw(struct sbuf *buf, int indent, |
851 | struct te_subtlv_ava_bw *tlv) | |
f8c06e2c | 852 | { |
d62a17ae | 853 | float fval; |
f8c06e2c | 854 | |
d62a17ae | 855 | fval = ntohf(tlv->value); |
f8c06e2c | 856 | |
af8ac8f9 CF |
857 | sbuf_push(buf, indent, "Unidirectional Available Bandwidth: %g (Bytes/sec)\n", |
858 | fval); | |
f8c06e2c | 859 | |
d62a17ae | 860 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
861 | } |
862 | ||
af8ac8f9 CF |
863 | static u_char print_subtlv_use_bw(struct sbuf *buf, int indent, |
864 | struct te_subtlv_use_bw *tlv) | |
f8c06e2c | 865 | { |
d62a17ae | 866 | float fval; |
f8c06e2c | 867 | |
d62a17ae | 868 | fval = ntohf(tlv->value); |
f8c06e2c | 869 | |
af8ac8f9 CF |
870 | sbuf_push(buf, indent, "Unidirectional Utilized Bandwidth: %g (Bytes/sec)\n", |
871 | fval); | |
f8c06e2c | 872 | |
d62a17ae | 873 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
874 | } |
875 | ||
af8ac8f9 CF |
876 | static u_char print_unknown_tlv(struct sbuf *buf, int indent, |
877 | struct subtlv_header *tlvh) | |
f8c06e2c | 878 | { |
d62a17ae | 879 | int i, rtn = 1; |
880 | u_char *v = (u_char *)tlvh; | |
881 | ||
af8ac8f9 CF |
882 | if (tlvh->length != 0) { |
883 | sbuf_push(buf, indent, | |
884 | "Unknown TLV: [type(%#.2x), length(%#.2x)]\n", | |
885 | tlvh->type, tlvh->length); | |
886 | sbuf_push(buf, indent + 2, "Dump: [00]"); | |
887 | rtn = 1; /* initialize end of line counter */ | |
888 | for (i = 0; i < tlvh->length; i++) { | |
889 | sbuf_push(buf, 0, " %#.2x", v[i]); | |
890 | if (rtn == 8) { | |
891 | sbuf_push(buf, 0, "\n"); | |
892 | sbuf_push(buf, indent + 8, | |
893 | "[%.2x]", i + 1); | |
894 | rtn = 1; | |
895 | } else | |
896 | rtn++; | |
897 | } | |
898 | sbuf_push(buf, 0, "\n"); | |
d62a17ae | 899 | } else { |
af8ac8f9 CF |
900 | sbuf_push(buf, indent, |
901 | "Unknown TLV: [type(%#.2x), length(%#.2x)]\n", | |
902 | tlvh->type, tlvh->length); | |
d62a17ae | 903 | } |
904 | ||
905 | return SUBTLV_SIZE(tlvh); | |
f8c06e2c OD |
906 | } |
907 | ||
908 | /* Main Show function */ | |
af8ac8f9 CF |
909 | void mpls_te_print_detail(struct sbuf *buf, int indent, |
910 | uint8_t *subtlvs, uint8_t subtlv_len) | |
f8c06e2c | 911 | { |
af8ac8f9 CF |
912 | struct subtlv_header *tlvh = (struct subtlv_header *)subtlvs; |
913 | uint16_t sum = 0; | |
d62a17ae | 914 | |
af8ac8f9 | 915 | for (; sum < subtlv_len; tlvh = SUBTLV_HDR_NEXT(tlvh)) { |
d62a17ae | 916 | switch (tlvh->type) { |
917 | case TE_SUBTLV_ADMIN_GRP: | |
af8ac8f9 CF |
918 | sum += print_subtlv_admin_grp(buf, indent, |
919 | (struct te_subtlv_admin_grp *)tlvh); | |
d62a17ae | 920 | break; |
921 | case TE_SUBTLV_LLRI: | |
af8ac8f9 CF |
922 | sum += print_subtlv_llri(buf, indent, |
923 | (struct te_subtlv_llri *)tlvh); | |
d62a17ae | 924 | break; |
925 | case TE_SUBTLV_LOCAL_IPADDR: | |
af8ac8f9 CF |
926 | sum += print_subtlv_local_ipaddr(buf, indent, |
927 | (struct te_subtlv_local_ipaddr *)tlvh); | |
d62a17ae | 928 | break; |
929 | case TE_SUBTLV_RMT_IPADDR: | |
af8ac8f9 CF |
930 | sum += print_subtlv_rmt_ipaddr(buf, indent, |
931 | (struct te_subtlv_rmt_ipaddr *)tlvh); | |
d62a17ae | 932 | break; |
933 | case TE_SUBTLV_MAX_BW: | |
af8ac8f9 CF |
934 | sum += print_subtlv_max_bw(buf, indent, |
935 | (struct te_subtlv_max_bw *)tlvh); | |
d62a17ae | 936 | break; |
937 | case TE_SUBTLV_MAX_RSV_BW: | |
af8ac8f9 CF |
938 | sum += print_subtlv_max_rsv_bw(buf, indent, |
939 | (struct te_subtlv_max_rsv_bw *)tlvh); | |
d62a17ae | 940 | break; |
941 | case TE_SUBTLV_UNRSV_BW: | |
af8ac8f9 CF |
942 | sum += print_subtlv_unrsv_bw(buf, indent, |
943 | (struct te_subtlv_unrsv_bw *)tlvh); | |
d62a17ae | 944 | break; |
945 | case TE_SUBTLV_TE_METRIC: | |
af8ac8f9 CF |
946 | sum += print_subtlv_te_metric(buf, indent, |
947 | (struct te_subtlv_te_metric *)tlvh); | |
d62a17ae | 948 | break; |
949 | case TE_SUBTLV_RAS: | |
af8ac8f9 CF |
950 | sum += print_subtlv_ras(buf, indent, |
951 | (struct te_subtlv_ras *)tlvh); | |
d62a17ae | 952 | break; |
953 | case TE_SUBTLV_RIP: | |
af8ac8f9 CF |
954 | sum += print_subtlv_rip(buf, indent, |
955 | (struct te_subtlv_rip *)tlvh); | |
d62a17ae | 956 | break; |
957 | case TE_SUBTLV_AV_DELAY: | |
af8ac8f9 CF |
958 | sum += print_subtlv_av_delay(buf, indent, |
959 | (struct te_subtlv_av_delay *)tlvh); | |
d62a17ae | 960 | break; |
961 | case TE_SUBTLV_MM_DELAY: | |
af8ac8f9 CF |
962 | sum += print_subtlv_mm_delay(buf, indent, |
963 | (struct te_subtlv_mm_delay *)tlvh); | |
d62a17ae | 964 | break; |
965 | case TE_SUBTLV_DELAY_VAR: | |
af8ac8f9 CF |
966 | sum += print_subtlv_delay_var(buf, indent, |
967 | (struct te_subtlv_delay_var *)tlvh); | |
d62a17ae | 968 | break; |
969 | case TE_SUBTLV_PKT_LOSS: | |
af8ac8f9 CF |
970 | sum += print_subtlv_pkt_loss(buf, indent, |
971 | (struct te_subtlv_pkt_loss *)tlvh); | |
d62a17ae | 972 | break; |
973 | case TE_SUBTLV_RES_BW: | |
af8ac8f9 CF |
974 | sum += print_subtlv_res_bw(buf, indent, |
975 | (struct te_subtlv_res_bw *)tlvh); | |
d62a17ae | 976 | break; |
977 | case TE_SUBTLV_AVA_BW: | |
af8ac8f9 CF |
978 | sum += print_subtlv_ava_bw(buf, indent, |
979 | (struct te_subtlv_ava_bw *)tlvh); | |
d62a17ae | 980 | break; |
981 | case TE_SUBTLV_USE_BW: | |
af8ac8f9 CF |
982 | sum += print_subtlv_use_bw(buf, indent, |
983 | (struct te_subtlv_use_bw *)tlvh); | |
d62a17ae | 984 | break; |
985 | default: | |
af8ac8f9 | 986 | sum += print_unknown_tlv(buf, indent, tlvh); |
d62a17ae | 987 | break; |
988 | } | |
989 | } | |
990 | return; | |
f8c06e2c OD |
991 | } |
992 | ||
993 | /* Specific MPLS TE router parameters write function */ | |
d62a17ae | 994 | void isis_mpls_te_config_write_router(struct vty *vty) |
f8c06e2c | 995 | { |
d62a17ae | 996 | if (IS_MPLS_TE(isisMplsTE)) { |
997 | vty_out(vty, " mpls-te on\n"); | |
998 | vty_out(vty, " mpls-te router-address %s\n", | |
999 | inet_ntoa(isisMplsTE.router_id)); | |
1000 | } | |
1001 | ||
1002 | return; | |
f8c06e2c OD |
1003 | } |
1004 | ||
1005 | ||
1006 | /*------------------------------------------------------------------------* | |
1007 | * Followings are vty command functions. | |
1008 | *------------------------------------------------------------------------*/ | |
1009 | ||
1010 | DEFUN (isis_mpls_te_on, | |
1011 | isis_mpls_te_on_cmd, | |
1012 | "mpls-te on", | |
1013 | MPLS_TE_STR | |
1014 | "Enable MPLS-TE functionality\n") | |
1015 | { | |
d62a17ae | 1016 | struct listnode *node; |
1017 | struct isis_circuit *circuit; | |
1018 | ||
1019 | if (IS_MPLS_TE(isisMplsTE)) | |
1020 | return CMD_SUCCESS; | |
1021 | ||
1022 | if (IS_DEBUG_ISIS(DEBUG_TE)) | |
1023 | zlog_debug("ISIS MPLS-TE: OFF -> ON"); | |
1024 | ||
1025 | isisMplsTE.status = enable; | |
1026 | ||
1027 | /* | |
1028 | * Following code is intended to handle two cases; | |
1029 | * | |
1030 | * 1) MPLS-TE was disabled at startup time, but now become enabled. | |
1031 | * In this case, we must enable MPLS-TE Circuit regarding interface | |
1032 | * MPLS_TE flag | |
1033 | * 2) MPLS-TE was once enabled then disabled, and now enabled again. | |
1034 | */ | |
1035 | for (ALL_LIST_ELEMENTS_RO(isisMplsTE.cir_list, node, circuit)) { | |
1036 | if (circuit->mtc == NULL || IS_FLOOD_AS(circuit->mtc->type)) | |
1037 | continue; | |
1038 | ||
1039 | if ((circuit->mtc->status == disable) | |
1040 | && HAS_LINK_PARAMS(circuit->interface)) | |
1041 | circuit->mtc->status = enable; | |
1042 | else | |
1043 | continue; | |
1044 | ||
1045 | /* Reoriginate STD_TE & GMPLS circuits */ | |
1046 | if (circuit->area) | |
1047 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
1048 | 0); | |
1049 | } | |
1050 | ||
1051 | return CMD_SUCCESS; | |
f8c06e2c OD |
1052 | } |
1053 | ||
1054 | DEFUN (no_isis_mpls_te_on, | |
1055 | no_isis_mpls_te_on_cmd, | |
1056 | "no mpls-te", | |
1057 | NO_STR | |
1058 | "Disable the MPLS-TE functionality\n") | |
1059 | { | |
d62a17ae | 1060 | struct listnode *node; |
1061 | struct isis_circuit *circuit; | |
f8c06e2c | 1062 | |
d62a17ae | 1063 | if (isisMplsTE.status == disable) |
1064 | return CMD_SUCCESS; | |
f8c06e2c | 1065 | |
d62a17ae | 1066 | if (IS_DEBUG_ISIS(DEBUG_TE)) |
1067 | zlog_debug("ISIS MPLS-TE: ON -> OFF"); | |
f8c06e2c | 1068 | |
d62a17ae | 1069 | isisMplsTE.status = disable; |
f8c06e2c | 1070 | |
d62a17ae | 1071 | /* Flush LSP if circuit engage */ |
1072 | for (ALL_LIST_ELEMENTS_RO(isisMplsTE.cir_list, node, circuit)) { | |
1073 | if (circuit->mtc == NULL || (circuit->mtc->status == disable)) | |
1074 | continue; | |
f8c06e2c | 1075 | |
d62a17ae | 1076 | /* disable MPLS_TE Circuit */ |
1077 | circuit->mtc->status = disable; | |
f8c06e2c | 1078 | |
d62a17ae | 1079 | /* Re-originate circuit without STD_TE & GMPLS parameters */ |
1080 | if (circuit->area) | |
1081 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
1082 | 0); | |
1083 | } | |
f8c06e2c | 1084 | |
d62a17ae | 1085 | return CMD_SUCCESS; |
f8c06e2c OD |
1086 | } |
1087 | ||
1088 | DEFUN (isis_mpls_te_router_addr, | |
1089 | isis_mpls_te_router_addr_cmd, | |
1090 | "mpls-te router-address A.B.C.D", | |
1091 | MPLS_TE_STR | |
1092 | "Stable IP address of the advertising router\n" | |
1093 | "MPLS-TE router address in IPv4 address format\n") | |
1094 | { | |
d62a17ae | 1095 | int idx_ipv4 = 2; |
1096 | struct in_addr value; | |
1097 | struct listnode *node; | |
1098 | struct isis_area *area; | |
1099 | ||
1100 | if (!inet_aton(argv[idx_ipv4]->arg, &value)) { | |
1101 | vty_out(vty, "Please specify Router-Addr by A.B.C.D\n"); | |
1102 | return CMD_WARNING_CONFIG_FAILED; | |
1103 | } | |
1104 | ||
1105 | isisMplsTE.router_id.s_addr = value.s_addr; | |
1106 | ||
1107 | if (isisMplsTE.status == disable) | |
1108 | return CMD_SUCCESS; | |
1109 | ||
1110 | /* Update main Router ID in isis global structure */ | |
1111 | isis->router_id = value.s_addr; | |
1112 | /* And re-schedule LSP update */ | |
1113 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) | |
1114 | if (listcount(area->area_addrs) > 0) | |
1115 | lsp_regenerate_schedule(area, area->is_type, 0); | |
1116 | ||
1117 | return CMD_SUCCESS; | |
f8c06e2c OD |
1118 | } |
1119 | ||
1120 | DEFUN (isis_mpls_te_inter_as, | |
1121 | isis_mpls_te_inter_as_cmd, | |
6147e2c6 | 1122 | "mpls-te inter-as <level-1|level-1-2|level-2-only>", |
f8c06e2c OD |
1123 | MPLS_TE_STR |
1124 | "Configure MPLS-TE Inter-AS support\n" | |
1125 | "AREA native mode self originate INTER-AS LSP with L1 only flooding scope)\n" | |
1126 | "AREA native mode self originate INTER-AS LSP with L1 and L2 flooding scope)\n" | |
1127 | "AS native mode self originate INTER-AS LSP with L2 only flooding scope\n") | |
1128 | { | |
d62a17ae | 1129 | vty_out(vty, "Not yet supported\n"); |
1130 | return CMD_SUCCESS; | |
f8c06e2c OD |
1131 | } |
1132 | ||
1133 | DEFUN (no_isis_mpls_te_inter_as, | |
1134 | no_isis_mpls_te_inter_as_cmd, | |
1135 | "no mpls-te inter-as", | |
1136 | NO_STR | |
1137 | "Disable the MPLS-TE functionality\n" | |
1138 | "Disable MPLS-TE Inter-AS support\n") | |
1139 | { | |
1140 | ||
d62a17ae | 1141 | vty_out(vty, "Not yet supported\n"); |
1142 | return CMD_SUCCESS; | |
f8c06e2c OD |
1143 | } |
1144 | ||
1145 | DEFUN (show_isis_mpls_te_router, | |
1146 | show_isis_mpls_te_router_cmd, | |
1147 | "show isis mpls-te router", | |
1148 | SHOW_STR | |
1149 | ISIS_STR | |
1150 | MPLS_TE_STR | |
1151 | "Router information\n") | |
1152 | { | |
d62a17ae | 1153 | if (IS_MPLS_TE(isisMplsTE)) { |
1154 | vty_out(vty, "--- MPLS-TE router parameters ---\n"); | |
1155 | ||
1156 | if (ntohs(isisMplsTE.router_id.s_addr) != 0) | |
1157 | vty_out(vty, " Router-Address: %s\n", | |
1158 | inet_ntoa(isisMplsTE.router_id)); | |
1159 | else | |
1160 | vty_out(vty, " N/A\n"); | |
1161 | } else | |
1162 | vty_out(vty, " MPLS-TE is disable on this router\n"); | |
1163 | ||
1164 | return CMD_SUCCESS; | |
f8c06e2c OD |
1165 | } |
1166 | ||
d62a17ae | 1167 | static void show_mpls_te_sub(struct vty *vty, struct interface *ifp) |
f8c06e2c | 1168 | { |
d62a17ae | 1169 | struct mpls_te_circuit *mtc; |
af8ac8f9 CF |
1170 | struct sbuf buf; |
1171 | ||
1172 | sbuf_init(&buf, NULL, 0); | |
d62a17ae | 1173 | |
1174 | if ((IS_MPLS_TE(isisMplsTE)) | |
1175 | && ((mtc = lookup_mpls_params_by_ifp(ifp)) != NULL)) { | |
1176 | /* Continue only if interface is not passive or support Inter-AS | |
1177 | * TEv2 */ | |
1178 | if (mtc->status != enable) { | |
1179 | if (IS_INTER_AS(mtc->type)) { | |
1180 | vty_out(vty, | |
1181 | "-- Inter-AS TEv2 link parameters for %s --\n", | |
1182 | ifp->name); | |
1183 | } else { | |
1184 | /* MPLS-TE is not activate on this interface */ | |
1185 | /* or this interface is passive and Inter-AS | |
1186 | * TEv2 is not activate */ | |
1187 | vty_out(vty, | |
1188 | " %s: MPLS-TE is disabled on this interface\n", | |
1189 | ifp->name); | |
1190 | return; | |
1191 | } | |
1192 | } else { | |
1193 | vty_out(vty, "-- MPLS-TE link parameters for %s --\n", | |
1194 | ifp->name); | |
1195 | } | |
1196 | ||
af8ac8f9 CF |
1197 | sbuf_reset(&buf); |
1198 | print_subtlv_admin_grp(&buf, 4, &mtc->admin_grp); | |
d62a17ae | 1199 | |
1200 | if (SUBTLV_TYPE(mtc->local_ipaddr) != 0) | |
af8ac8f9 | 1201 | print_subtlv_local_ipaddr(&buf, 4, &mtc->local_ipaddr); |
d62a17ae | 1202 | if (SUBTLV_TYPE(mtc->rmt_ipaddr) != 0) |
af8ac8f9 | 1203 | print_subtlv_rmt_ipaddr(&buf, 4, &mtc->rmt_ipaddr); |
d62a17ae | 1204 | |
af8ac8f9 CF |
1205 | print_subtlv_max_bw(&buf, 4, &mtc->max_bw); |
1206 | print_subtlv_max_rsv_bw(&buf, 4, &mtc->max_rsv_bw); | |
1207 | print_subtlv_unrsv_bw(&buf, 4, &mtc->unrsv_bw); | |
1208 | print_subtlv_te_metric(&buf, 4, &mtc->te_metric); | |
d62a17ae | 1209 | |
1210 | if (IS_INTER_AS(mtc->type)) { | |
1211 | if (SUBTLV_TYPE(mtc->ras) != 0) | |
af8ac8f9 | 1212 | print_subtlv_ras(&buf, 4, &mtc->ras); |
d62a17ae | 1213 | if (SUBTLV_TYPE(mtc->rip) != 0) |
af8ac8f9 | 1214 | print_subtlv_rip(&buf, 4, &mtc->rip); |
d62a17ae | 1215 | } |
1216 | ||
af8ac8f9 CF |
1217 | print_subtlv_av_delay(&buf, 4, &mtc->av_delay); |
1218 | print_subtlv_mm_delay(&buf, 4, &mtc->mm_delay); | |
1219 | print_subtlv_delay_var(&buf, 4, &mtc->delay_var); | |
1220 | print_subtlv_pkt_loss(&buf, 4, &mtc->pkt_loss); | |
1221 | print_subtlv_res_bw(&buf, 4, &mtc->res_bw); | |
1222 | print_subtlv_ava_bw(&buf, 4, &mtc->ava_bw); | |
1223 | print_subtlv_use_bw(&buf, 4, &mtc->use_bw); | |
1224 | ||
1225 | vty_multiline(vty, "", "%s", sbuf_buf(&buf)); | |
d62a17ae | 1226 | vty_out(vty, "---------------\n\n"); |
1227 | } else { | |
1228 | vty_out(vty, " %s: MPLS-TE is disabled on this interface\n", | |
1229 | ifp->name); | |
1230 | } | |
1231 | ||
af8ac8f9 | 1232 | sbuf_free(&buf); |
d62a17ae | 1233 | return; |
f8c06e2c OD |
1234 | } |
1235 | ||
1236 | DEFUN (show_isis_mpls_te_interface, | |
1237 | show_isis_mpls_te_interface_cmd, | |
1238 | "show isis mpls-te interface [INTERFACE]", | |
1239 | SHOW_STR | |
1240 | ISIS_STR | |
1241 | MPLS_TE_STR | |
1242 | "Interface information\n" | |
1243 | "Interface name\n") | |
1244 | { | |
d62a17ae | 1245 | int idx_interface = 4; |
1246 | struct interface *ifp; | |
1247 | struct listnode *node; | |
1248 | ||
1249 | /* Show All Interfaces. */ | |
1250 | if (argc == 4) { | |
1251 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) | |
1252 | show_mpls_te_sub(vty, ifp); | |
1253 | } | |
1254 | /* Interface name is specified. */ | |
1255 | else { | |
1256 | if ((ifp = if_lookup_by_name(argv[idx_interface]->arg, | |
1257 | VRF_DEFAULT)) | |
1258 | == NULL) | |
1259 | vty_out(vty, "No such interface name\n"); | |
1260 | else | |
1261 | show_mpls_te_sub(vty, ifp); | |
1262 | } | |
1263 | ||
1264 | return CMD_SUCCESS; | |
f8c06e2c OD |
1265 | } |
1266 | ||
1267 | /* Initialize MPLS_TE */ | |
d62a17ae | 1268 | void isis_mpls_te_init(void) |
f8c06e2c OD |
1269 | { |
1270 | ||
d62a17ae | 1271 | zlog_debug("ISIS MPLS-TE: Initialize"); |
f8c06e2c | 1272 | |
d62a17ae | 1273 | /* Initialize MPLS_TE structure */ |
1274 | isisMplsTE.status = disable; | |
1275 | isisMplsTE.level = 0; | |
1276 | isisMplsTE.inter_as = off; | |
1277 | isisMplsTE.interas_areaid.s_addr = 0; | |
1278 | isisMplsTE.cir_list = list_new(); | |
1279 | isisMplsTE.router_id.s_addr = 0; | |
f8c06e2c | 1280 | |
d62a17ae | 1281 | /* Register new VTY commands */ |
1282 | install_element(VIEW_NODE, &show_isis_mpls_te_router_cmd); | |
1283 | install_element(VIEW_NODE, &show_isis_mpls_te_interface_cmd); | |
f8c06e2c | 1284 | |
d62a17ae | 1285 | install_element(ISIS_NODE, &isis_mpls_te_on_cmd); |
1286 | install_element(ISIS_NODE, &no_isis_mpls_te_on_cmd); | |
1287 | install_element(ISIS_NODE, &isis_mpls_te_router_addr_cmd); | |
1288 | install_element(ISIS_NODE, &isis_mpls_te_inter_as_cmd); | |
1289 | install_element(ISIS_NODE, &no_isis_mpls_te_inter_as_cmd); | |
f8c06e2c | 1290 | |
d62a17ae | 1291 | return; |
f8c06e2c | 1292 | } |