]>
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" | |
44 | ||
45 | #include "isisd/dict.h" | |
46 | #include "isisd/isis_constants.h" | |
47 | #include "isisd/isis_common.h" | |
48 | #include "isisd/isis_flags.h" | |
49 | #include "isisd/isis_circuit.h" | |
50 | #include "isisd/isisd.h" | |
51 | #include "isisd/isis_tlv.h" | |
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 */ |
d62a17ae | 103 | u_char add_te_subtlvs(u_char *buf, struct mpls_te_circuit *mtc) |
f8c06e2c | 104 | { |
d62a17ae | 105 | u_char size, *tlvs = buf; |
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 */ | |
d62a17ae | 235 | u_char 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 | |
d62a17ae | 309 | mtc->length = (u_char)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; | |
549 | if (adj->ipv4_addrs != NULL | |
550 | && listcount(adj->ipv4_addrs) != 0) { | |
551 | struct in_addr *ip_addr; | |
552 | ip_addr = (struct in_addr *)listgetdata( | |
553 | (struct listnode *)listhead( | |
554 | adj->ipv4_addrs)); | |
555 | set_circuitparams_rmt_ipaddr(mtc, *ip_addr); | |
556 | } | |
557 | } | |
558 | ||
559 | if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW)) | |
560 | set_circuitparams_max_bw(mtc, ifp->link_params->max_bw); | |
561 | else | |
562 | SUBTLV_TYPE(mtc->max_bw) = 0; | |
563 | ||
564 | if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW)) | |
565 | set_circuitparams_max_rsv_bw( | |
566 | mtc, ifp->link_params->max_rsv_bw); | |
567 | else | |
568 | SUBTLV_TYPE(mtc->max_rsv_bw) = 0; | |
569 | ||
570 | if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW)) | |
571 | for (i = 0; i < MAX_CLASS_TYPE; i++) | |
572 | set_circuitparams_unrsv_bw( | |
573 | mtc, i, ifp->link_params->unrsv_bw[i]); | |
574 | else | |
575 | SUBTLV_TYPE(mtc->unrsv_bw) = 0; | |
576 | ||
577 | if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC)) | |
578 | set_circuitparams_te_metric( | |
579 | mtc, ifp->link_params->te_metric); | |
580 | else | |
581 | SUBTLV_TYPE(mtc->te_metric) = 0; | |
582 | ||
583 | /* TE metric Extensions */ | |
584 | if (IS_PARAM_SET(ifp->link_params, LP_DELAY)) | |
585 | set_circuitparams_av_delay( | |
586 | mtc, ifp->link_params->av_delay, 0); | |
587 | else | |
588 | SUBTLV_TYPE(mtc->av_delay) = 0; | |
589 | ||
590 | if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY)) | |
591 | set_circuitparams_mm_delay( | |
592 | mtc, ifp->link_params->min_delay, | |
593 | ifp->link_params->max_delay, 0); | |
594 | else | |
595 | SUBTLV_TYPE(mtc->mm_delay) = 0; | |
596 | ||
597 | if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR)) | |
598 | set_circuitparams_delay_var( | |
599 | mtc, ifp->link_params->delay_var); | |
600 | else | |
601 | SUBTLV_TYPE(mtc->delay_var) = 0; | |
602 | ||
603 | if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS)) | |
604 | set_circuitparams_pkt_loss( | |
605 | mtc, ifp->link_params->pkt_loss, 0); | |
606 | else | |
607 | SUBTLV_TYPE(mtc->pkt_loss) = 0; | |
608 | ||
609 | if (IS_PARAM_SET(ifp->link_params, LP_RES_BW)) | |
610 | set_circuitparams_res_bw(mtc, ifp->link_params->res_bw); | |
611 | else | |
612 | SUBTLV_TYPE(mtc->res_bw) = 0; | |
613 | ||
614 | if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW)) | |
615 | set_circuitparams_ava_bw(mtc, ifp->link_params->ava_bw); | |
616 | else | |
617 | SUBTLV_TYPE(mtc->ava_bw) = 0; | |
618 | ||
619 | if (IS_PARAM_SET(ifp->link_params, LP_USE_BW)) | |
620 | set_circuitparams_use_bw(mtc, ifp->link_params->use_bw); | |
621 | else | |
622 | SUBTLV_TYPE(mtc->use_bw) = 0; | |
623 | ||
624 | /* INTER_AS */ | |
625 | if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS)) | |
626 | set_circuitparams_inter_as(mtc, | |
627 | ifp->link_params->rmt_ip, | |
628 | ifp->link_params->rmt_as); | |
629 | else | |
630 | /* reset inter-as TE params */ | |
631 | unset_circuitparams_inter_as(mtc); | |
632 | ||
633 | /* Compute total length of SUB TLVs */ | |
634 | mtc->length = subtlvs_len(mtc); | |
635 | ||
636 | } else | |
637 | mtc->status = disable; | |
638 | ||
639 | /* Finally Update LSP */ | |
f8c06e2c OD |
640 | #if 0 |
641 | if (IS_MPLS_TE(isisMplsTE) && circuit->area) | |
642 | lsp_regenerate_schedule (circuit->area, circuit->is_type, 0); | |
643 | #endif | |
d62a17ae | 644 | return; |
f8c06e2c OD |
645 | } |
646 | ||
d62a17ae | 647 | void isis_mpls_te_update(struct interface *ifp) |
f8c06e2c | 648 | { |
d62a17ae | 649 | struct isis_circuit *circuit; |
f8c06e2c | 650 | |
d62a17ae | 651 | /* Sanity Check */ |
652 | if (ifp == NULL) | |
653 | return; | |
f8c06e2c | 654 | |
d62a17ae | 655 | /* Get circuit context from interface */ |
656 | if ((circuit = circuit_scan_by_ifp(ifp)) == NULL) | |
657 | return; | |
f8c06e2c | 658 | |
d62a17ae | 659 | /* Update TE TLVs ... */ |
660 | isis_link_params_update(circuit, ifp); | |
f8c06e2c | 661 | |
d62a17ae | 662 | /* ... and LSP */ |
663 | if (IS_MPLS_TE(isisMplsTE) && circuit->area) | |
664 | lsp_regenerate_schedule(circuit->area, circuit->is_type, 0); | |
f8c06e2c | 665 | |
d62a17ae | 666 | return; |
f8c06e2c OD |
667 | } |
668 | ||
669 | /*------------------------------------------------------------------------* | |
670 | * Followings are vty session control functions. | |
671 | *------------------------------------------------------------------------*/ | |
672 | ||
d62a17ae | 673 | static u_char show_vty_subtlv_admin_grp(struct vty *vty, |
674 | struct te_subtlv_admin_grp *tlv) | |
f8c06e2c OD |
675 | { |
676 | ||
d62a17ae | 677 | if (vty != NULL) |
678 | vty_out(vty, " Administrative Group: 0x%x\n", | |
679 | (u_int32_t)ntohl(tlv->value)); | |
680 | else | |
681 | zlog_debug(" Administrative Group: 0x%x", | |
682 | (u_int32_t)ntohl(tlv->value)); | |
f8c06e2c | 683 | |
d62a17ae | 684 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
685 | } |
686 | ||
d62a17ae | 687 | static u_char show_vty_subtlv_llri(struct vty *vty, struct te_subtlv_llri *tlv) |
f8c06e2c | 688 | { |
d62a17ae | 689 | if (vty != NULL) { |
690 | vty_out(vty, " Link Local ID: %d\n", | |
691 | (u_int32_t)ntohl(tlv->local)); | |
692 | vty_out(vty, " Link Remote ID: %d\n", | |
693 | (u_int32_t)ntohl(tlv->remote)); | |
694 | } else { | |
695 | zlog_debug(" Link Local ID: %d", | |
696 | (u_int32_t)ntohl(tlv->local)); | |
697 | zlog_debug(" Link Remote ID: %d", | |
698 | (u_int32_t)ntohl(tlv->remote)); | |
699 | } | |
700 | ||
701 | return (SUBTLV_HDR_SIZE + TE_SUBTLV_LLRI_SIZE); | |
f8c06e2c OD |
702 | } |
703 | ||
d62a17ae | 704 | static u_char show_vty_subtlv_local_ipaddr(struct vty *vty, |
705 | struct te_subtlv_local_ipaddr *tlv) | |
f8c06e2c | 706 | { |
d62a17ae | 707 | if (vty != NULL) |
708 | vty_out(vty, " Local Interface IP Address(es): %s\n", | |
709 | inet_ntoa(tlv->value)); | |
710 | else | |
711 | zlog_debug(" Local Interface IP Address(es): %s", | |
712 | inet_ntoa(tlv->value)); | |
713 | ||
714 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
715 | } |
716 | ||
d62a17ae | 717 | static u_char show_vty_subtlv_rmt_ipaddr(struct vty *vty, |
718 | struct te_subtlv_rmt_ipaddr *tlv) | |
f8c06e2c | 719 | { |
d62a17ae | 720 | if (vty != NULL) |
721 | vty_out(vty, " Remote Interface IP Address(es): %s\n", | |
722 | inet_ntoa(tlv->value)); | |
723 | else | |
724 | zlog_debug(" Remote Interface IP Address(es): %s", | |
725 | inet_ntoa(tlv->value)); | |
726 | ||
727 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
728 | } |
729 | ||
d62a17ae | 730 | static u_char show_vty_subtlv_max_bw(struct vty *vty, |
731 | struct te_subtlv_max_bw *tlv) | |
f8c06e2c | 732 | { |
d62a17ae | 733 | float fval; |
f8c06e2c | 734 | |
d62a17ae | 735 | fval = ntohf(tlv->value); |
f8c06e2c | 736 | |
d62a17ae | 737 | if (vty != NULL) |
738 | vty_out(vty, " Maximum Bandwidth: %g (Bytes/sec)\n", fval); | |
739 | else | |
740 | zlog_debug(" Maximum Bandwidth: %g (Bytes/sec)", fval); | |
f8c06e2c | 741 | |
d62a17ae | 742 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
743 | } |
744 | ||
d62a17ae | 745 | static u_char show_vty_subtlv_max_rsv_bw(struct vty *vty, |
746 | struct te_subtlv_max_rsv_bw *tlv) | |
f8c06e2c | 747 | { |
d62a17ae | 748 | float fval; |
f8c06e2c | 749 | |
d62a17ae | 750 | fval = ntohf(tlv->value); |
f8c06e2c | 751 | |
d62a17ae | 752 | if (vty != NULL) |
753 | vty_out(vty, | |
754 | " Maximum Reservable Bandwidth: %g (Bytes/sec)\n", | |
755 | fval); | |
756 | else | |
757 | zlog_debug(" Maximum Reservable Bandwidth: %g (Bytes/sec)", | |
758 | fval); | |
f8c06e2c | 759 | |
d62a17ae | 760 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
761 | } |
762 | ||
d62a17ae | 763 | static u_char show_vty_subtlv_unrsv_bw(struct vty *vty, |
764 | struct te_subtlv_unrsv_bw *tlv) | |
f8c06e2c | 765 | { |
d62a17ae | 766 | float fval1, fval2; |
767 | int i; | |
768 | ||
769 | if (vty != NULL) | |
770 | vty_out(vty, " Unreserved Bandwidth:\n"); | |
771 | else | |
772 | zlog_debug(" Unreserved Bandwidth:"); | |
773 | ||
774 | for (i = 0; i < MAX_CLASS_TYPE; i += 2) { | |
775 | fval1 = ntohf(tlv->value[i]); | |
776 | fval2 = ntohf(tlv->value[i + 1]); | |
777 | if (vty != NULL) | |
778 | vty_out(vty, | |
779 | " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n", | |
780 | i, fval1, i + 1, fval2); | |
781 | else | |
782 | zlog_debug( | |
783 | " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)", | |
784 | i, fval1, i + 1, fval2); | |
785 | } | |
786 | ||
787 | return (SUBTLV_HDR_SIZE + TE_SUBTLV_UNRSV_SIZE); | |
f8c06e2c OD |
788 | } |
789 | ||
d62a17ae | 790 | static u_char show_vty_subtlv_te_metric(struct vty *vty, |
791 | struct te_subtlv_te_metric *tlv) | |
f8c06e2c | 792 | { |
d62a17ae | 793 | u_int32_t te_metric; |
f8c06e2c | 794 | |
d62a17ae | 795 | te_metric = tlv->value[2] | tlv->value[1] << 8 | tlv->value[0] << 16; |
796 | if (vty != NULL) | |
797 | vty_out(vty, " Traffic Engineering Metric: %u\n", te_metric); | |
798 | else | |
799 | zlog_debug(" Traffic Engineering Metric: %u", te_metric); | |
f8c06e2c | 800 | |
d62a17ae | 801 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
802 | } |
803 | ||
d62a17ae | 804 | static u_char show_vty_subtlv_ras(struct vty *vty, struct te_subtlv_ras *tlv) |
f8c06e2c | 805 | { |
d62a17ae | 806 | if (vty != NULL) |
807 | vty_out(vty, " Inter-AS TE Remote AS number: %u\n", | |
808 | ntohl(tlv->value)); | |
809 | else | |
810 | zlog_debug(" Inter-AS TE Remote AS number: %u", | |
811 | ntohl(tlv->value)); | |
812 | ||
813 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
814 | } |
815 | ||
d62a17ae | 816 | static u_char show_vty_subtlv_rip(struct vty *vty, struct te_subtlv_rip *tlv) |
f8c06e2c | 817 | { |
d62a17ae | 818 | if (vty != NULL) |
819 | vty_out(vty, " Inter-AS TE Remote ASBR IP address: %s\n", | |
820 | inet_ntoa(tlv->value)); | |
821 | else | |
822 | zlog_debug(" Inter-AS TE Remote ASBR IP address: %s", | |
823 | inet_ntoa(tlv->value)); | |
824 | ||
825 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
826 | } |
827 | ||
d62a17ae | 828 | static u_char show_vty_subtlv_av_delay(struct vty *vty, |
829 | struct te_subtlv_av_delay *tlv) | |
f8c06e2c | 830 | { |
d62a17ae | 831 | u_int32_t delay; |
832 | u_int32_t A; | |
f8c06e2c | 833 | |
d62a17ae | 834 | delay = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; |
835 | A = (u_int32_t)ntohl(tlv->value) & TE_EXT_ANORMAL; | |
f8c06e2c | 836 | |
d62a17ae | 837 | if (vty != NULL) |
838 | vty_out(vty, " %s Average Link Delay: %d (micro-sec)\n", | |
839 | A ? "Anomalous" : "Normal", delay); | |
840 | else | |
841 | zlog_debug(" %s Average Link Delay: %d (micro-sec)", | |
842 | A ? "Anomalous" : "Normal", delay); | |
f8c06e2c | 843 | |
d62a17ae | 844 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
845 | } |
846 | ||
d62a17ae | 847 | static u_char show_vty_subtlv_mm_delay(struct vty *vty, |
848 | struct te_subtlv_mm_delay *tlv) | |
f8c06e2c | 849 | { |
d62a17ae | 850 | u_int32_t low, high; |
851 | u_int32_t A; | |
f8c06e2c | 852 | |
d62a17ae | 853 | low = (u_int32_t)ntohl(tlv->low) & TE_EXT_MASK; |
854 | A = (u_int32_t)ntohl(tlv->low) & TE_EXT_ANORMAL; | |
855 | high = (u_int32_t)ntohl(tlv->high) & TE_EXT_MASK; | |
f8c06e2c | 856 | |
d62a17ae | 857 | if (vty != NULL) |
858 | vty_out(vty, " %s Min/Max Link Delay: %d / %d (micro-sec)\n", | |
859 | A ? "Anomalous" : "Normal", low, high); | |
860 | else | |
861 | zlog_debug(" %s Min/Max Link Delay: %d / %d (micro-sec)", | |
862 | A ? "Anomalous" : "Normal", low, high); | |
f8c06e2c | 863 | |
d62a17ae | 864 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
865 | } |
866 | ||
d62a17ae | 867 | static u_char show_vty_subtlv_delay_var(struct vty *vty, |
868 | struct te_subtlv_delay_var *tlv) | |
f8c06e2c | 869 | { |
d62a17ae | 870 | u_int32_t jitter; |
f8c06e2c | 871 | |
d62a17ae | 872 | jitter = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; |
f8c06e2c | 873 | |
d62a17ae | 874 | if (vty != NULL) |
875 | vty_out(vty, " Delay Variation: %d (micro-sec)\n", jitter); | |
876 | else | |
877 | zlog_debug(" Delay Variation: %d (micro-sec)", jitter); | |
f8c06e2c | 878 | |
d62a17ae | 879 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
880 | } |
881 | ||
d62a17ae | 882 | static u_char show_vty_subtlv_pkt_loss(struct vty *vty, |
883 | struct te_subtlv_pkt_loss *tlv) | |
f8c06e2c | 884 | { |
d62a17ae | 885 | u_int32_t loss; |
886 | u_int32_t A; | |
887 | float fval; | |
888 | ||
889 | loss = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; | |
890 | fval = (float)(loss * LOSS_PRECISION); | |
891 | A = (u_int32_t)ntohl(tlv->value) & TE_EXT_ANORMAL; | |
892 | ||
893 | if (vty != NULL) | |
894 | vty_out(vty, " %s Link Packet Loss: %g (%%)\n", | |
895 | A ? "Anomalous" : "Normal", fval); | |
896 | else | |
897 | zlog_debug(" %s Link Packet Loss: %g (%%)", | |
898 | A ? "Anomalous" : "Normal", fval); | |
899 | ||
900 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); | |
f8c06e2c OD |
901 | } |
902 | ||
d62a17ae | 903 | static u_char show_vty_subtlv_res_bw(struct vty *vty, |
904 | struct te_subtlv_res_bw *tlv) | |
f8c06e2c | 905 | { |
d62a17ae | 906 | float fval; |
f8c06e2c | 907 | |
d62a17ae | 908 | fval = ntohf(tlv->value); |
f8c06e2c | 909 | |
d62a17ae | 910 | if (vty != NULL) |
911 | vty_out(vty, | |
912 | " Unidirectional Residual Bandwidth: %g (Bytes/sec)\n", | |
913 | fval); | |
914 | else | |
915 | zlog_debug( | |
916 | " Unidirectional Residual Bandwidth: %g (Bytes/sec)", | |
917 | fval); | |
f8c06e2c | 918 | |
d62a17ae | 919 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
920 | } |
921 | ||
d62a17ae | 922 | static u_char show_vty_subtlv_ava_bw(struct vty *vty, |
923 | struct te_subtlv_ava_bw *tlv) | |
f8c06e2c | 924 | { |
d62a17ae | 925 | float fval; |
f8c06e2c | 926 | |
d62a17ae | 927 | fval = ntohf(tlv->value); |
f8c06e2c | 928 | |
d62a17ae | 929 | if (vty != NULL) |
930 | vty_out(vty, | |
931 | " Unidirectional Available Bandwidth: %g (Bytes/sec)\n", | |
932 | fval); | |
933 | else | |
934 | zlog_debug( | |
935 | " Unidirectional Available Bandwidth: %g (Bytes/sec)", | |
936 | fval); | |
f8c06e2c | 937 | |
d62a17ae | 938 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
939 | } |
940 | ||
d62a17ae | 941 | static u_char show_vty_subtlv_use_bw(struct vty *vty, |
942 | struct te_subtlv_use_bw *tlv) | |
f8c06e2c | 943 | { |
d62a17ae | 944 | float fval; |
f8c06e2c | 945 | |
d62a17ae | 946 | fval = ntohf(tlv->value); |
f8c06e2c | 947 | |
d62a17ae | 948 | if (vty != NULL) |
949 | vty_out(vty, | |
950 | " Unidirectional Utilized Bandwidth: %g (Bytes/sec)\n", | |
951 | fval); | |
952 | else | |
953 | zlog_debug( | |
954 | " Unidirectional Utilized Bandwidth: %g (Bytes/sec)", | |
955 | fval); | |
f8c06e2c | 956 | |
d62a17ae | 957 | return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); |
f8c06e2c OD |
958 | } |
959 | ||
d62a17ae | 960 | static u_char show_vty_unknown_tlv(struct vty *vty, struct subtlv_header *tlvh) |
f8c06e2c | 961 | { |
d62a17ae | 962 | int i, rtn = 1; |
963 | u_char *v = (u_char *)tlvh; | |
964 | ||
965 | if (vty != NULL) { | |
966 | if (tlvh->length != 0) { | |
967 | vty_out(vty, | |
968 | " Unknown TLV: [type(%#.2x), length(%#.2x)]\n", | |
969 | tlvh->type, tlvh->length); | |
970 | vty_out(vty, " Dump: [00]"); | |
971 | rtn = 1; /* initialize end of line counter */ | |
972 | for (i = 0; i < tlvh->length; i++) { | |
973 | vty_out(vty, " %#.2x", v[i]); | |
974 | if (rtn == 8) { | |
975 | vty_out(vty, "\n [%.2x]", | |
976 | i + 1); | |
977 | rtn = 1; | |
978 | } else | |
979 | rtn++; | |
980 | } | |
981 | vty_out(vty, "\n"); | |
982 | } else | |
983 | vty_out(vty, | |
984 | " Unknown TLV: [type(%#.2x), length(%#.2x)]\n", | |
985 | tlvh->type, tlvh->length); | |
986 | } else { | |
987 | zlog_debug(" Unknown TLV: [type(%#.2x), length(%#.2x)]", | |
988 | tlvh->type, tlvh->length); | |
989 | } | |
990 | ||
991 | return SUBTLV_SIZE(tlvh); | |
f8c06e2c OD |
992 | } |
993 | ||
994 | /* Main Show function */ | |
d62a17ae | 995 | void mpls_te_print_detail(struct vty *vty, struct te_is_neigh *te) |
f8c06e2c | 996 | { |
d62a17ae | 997 | struct subtlv_header *tlvh; |
998 | u_int16_t sum = 0; | |
999 | ||
1000 | zlog_debug("ISIS MPLS-TE: Show database TE detail"); | |
1001 | ||
1002 | tlvh = (struct subtlv_header *)te->sub_tlvs; | |
1003 | ||
1004 | for (; sum < te->sub_tlvs_length; tlvh = SUBTLV_HDR_NEXT(tlvh)) { | |
1005 | switch (tlvh->type) { | |
1006 | case TE_SUBTLV_ADMIN_GRP: | |
1007 | sum += show_vty_subtlv_admin_grp( | |
1008 | vty, (struct te_subtlv_admin_grp *)tlvh); | |
1009 | break; | |
1010 | case TE_SUBTLV_LLRI: | |
1011 | sum += show_vty_subtlv_llri( | |
1012 | vty, (struct te_subtlv_llri *)tlvh); | |
1013 | break; | |
1014 | case TE_SUBTLV_LOCAL_IPADDR: | |
1015 | sum += show_vty_subtlv_local_ipaddr( | |
1016 | vty, (struct te_subtlv_local_ipaddr *)tlvh); | |
1017 | break; | |
1018 | case TE_SUBTLV_RMT_IPADDR: | |
1019 | sum += show_vty_subtlv_rmt_ipaddr( | |
1020 | vty, (struct te_subtlv_rmt_ipaddr *)tlvh); | |
1021 | break; | |
1022 | case TE_SUBTLV_MAX_BW: | |
1023 | sum += show_vty_subtlv_max_bw( | |
1024 | vty, (struct te_subtlv_max_bw *)tlvh); | |
1025 | break; | |
1026 | case TE_SUBTLV_MAX_RSV_BW: | |
1027 | sum += show_vty_subtlv_max_rsv_bw( | |
1028 | vty, (struct te_subtlv_max_rsv_bw *)tlvh); | |
1029 | break; | |
1030 | case TE_SUBTLV_UNRSV_BW: | |
1031 | sum += show_vty_subtlv_unrsv_bw( | |
1032 | vty, (struct te_subtlv_unrsv_bw *)tlvh); | |
1033 | break; | |
1034 | case TE_SUBTLV_TE_METRIC: | |
1035 | sum += show_vty_subtlv_te_metric( | |
1036 | vty, (struct te_subtlv_te_metric *)tlvh); | |
1037 | break; | |
1038 | case TE_SUBTLV_RAS: | |
1039 | sum += show_vty_subtlv_ras( | |
1040 | vty, (struct te_subtlv_ras *)tlvh); | |
1041 | break; | |
1042 | case TE_SUBTLV_RIP: | |
1043 | sum += show_vty_subtlv_rip( | |
1044 | vty, (struct te_subtlv_rip *)tlvh); | |
1045 | break; | |
1046 | case TE_SUBTLV_AV_DELAY: | |
1047 | sum += show_vty_subtlv_av_delay( | |
1048 | vty, (struct te_subtlv_av_delay *)tlvh); | |
1049 | break; | |
1050 | case TE_SUBTLV_MM_DELAY: | |
1051 | sum += show_vty_subtlv_mm_delay( | |
1052 | vty, (struct te_subtlv_mm_delay *)tlvh); | |
1053 | break; | |
1054 | case TE_SUBTLV_DELAY_VAR: | |
1055 | sum += show_vty_subtlv_delay_var( | |
1056 | vty, (struct te_subtlv_delay_var *)tlvh); | |
1057 | break; | |
1058 | case TE_SUBTLV_PKT_LOSS: | |
1059 | sum += show_vty_subtlv_pkt_loss( | |
1060 | vty, (struct te_subtlv_pkt_loss *)tlvh); | |
1061 | break; | |
1062 | case TE_SUBTLV_RES_BW: | |
1063 | sum += show_vty_subtlv_res_bw( | |
1064 | vty, (struct te_subtlv_res_bw *)tlvh); | |
1065 | break; | |
1066 | case TE_SUBTLV_AVA_BW: | |
1067 | sum += show_vty_subtlv_ava_bw( | |
1068 | vty, (struct te_subtlv_ava_bw *)tlvh); | |
1069 | break; | |
1070 | case TE_SUBTLV_USE_BW: | |
1071 | sum += show_vty_subtlv_use_bw( | |
1072 | vty, (struct te_subtlv_use_bw *)tlvh); | |
1073 | break; | |
1074 | default: | |
1075 | sum += show_vty_unknown_tlv(vty, tlvh); | |
1076 | break; | |
1077 | } | |
1078 | } | |
1079 | return; | |
f8c06e2c OD |
1080 | } |
1081 | ||
1082 | /* Specific MPLS TE router parameters write function */ | |
d62a17ae | 1083 | void isis_mpls_te_config_write_router(struct vty *vty) |
f8c06e2c | 1084 | { |
d62a17ae | 1085 | if (IS_MPLS_TE(isisMplsTE)) { |
1086 | vty_out(vty, " mpls-te on\n"); | |
1087 | vty_out(vty, " mpls-te router-address %s\n", | |
1088 | inet_ntoa(isisMplsTE.router_id)); | |
1089 | } | |
1090 | ||
1091 | return; | |
f8c06e2c OD |
1092 | } |
1093 | ||
1094 | ||
1095 | /*------------------------------------------------------------------------* | |
1096 | * Followings are vty command functions. | |
1097 | *------------------------------------------------------------------------*/ | |
1098 | ||
1099 | DEFUN (isis_mpls_te_on, | |
1100 | isis_mpls_te_on_cmd, | |
1101 | "mpls-te on", | |
1102 | MPLS_TE_STR | |
1103 | "Enable MPLS-TE functionality\n") | |
1104 | { | |
d62a17ae | 1105 | struct listnode *node; |
1106 | struct isis_circuit *circuit; | |
1107 | ||
1108 | if (IS_MPLS_TE(isisMplsTE)) | |
1109 | return CMD_SUCCESS; | |
1110 | ||
1111 | if (IS_DEBUG_ISIS(DEBUG_TE)) | |
1112 | zlog_debug("ISIS MPLS-TE: OFF -> ON"); | |
1113 | ||
1114 | isisMplsTE.status = enable; | |
1115 | ||
1116 | /* | |
1117 | * Following code is intended to handle two cases; | |
1118 | * | |
1119 | * 1) MPLS-TE was disabled at startup time, but now become enabled. | |
1120 | * In this case, we must enable MPLS-TE Circuit regarding interface | |
1121 | * MPLS_TE flag | |
1122 | * 2) MPLS-TE was once enabled then disabled, and now enabled again. | |
1123 | */ | |
1124 | for (ALL_LIST_ELEMENTS_RO(isisMplsTE.cir_list, node, circuit)) { | |
1125 | if (circuit->mtc == NULL || IS_FLOOD_AS(circuit->mtc->type)) | |
1126 | continue; | |
1127 | ||
1128 | if ((circuit->mtc->status == disable) | |
1129 | && HAS_LINK_PARAMS(circuit->interface)) | |
1130 | circuit->mtc->status = enable; | |
1131 | else | |
1132 | continue; | |
1133 | ||
1134 | /* Reoriginate STD_TE & GMPLS circuits */ | |
1135 | if (circuit->area) | |
1136 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
1137 | 0); | |
1138 | } | |
1139 | ||
1140 | return CMD_SUCCESS; | |
f8c06e2c OD |
1141 | } |
1142 | ||
1143 | DEFUN (no_isis_mpls_te_on, | |
1144 | no_isis_mpls_te_on_cmd, | |
1145 | "no mpls-te", | |
1146 | NO_STR | |
1147 | "Disable the MPLS-TE functionality\n") | |
1148 | { | |
d62a17ae | 1149 | struct listnode *node; |
1150 | struct isis_circuit *circuit; | |
f8c06e2c | 1151 | |
d62a17ae | 1152 | if (isisMplsTE.status == disable) |
1153 | return CMD_SUCCESS; | |
f8c06e2c | 1154 | |
d62a17ae | 1155 | if (IS_DEBUG_ISIS(DEBUG_TE)) |
1156 | zlog_debug("ISIS MPLS-TE: ON -> OFF"); | |
f8c06e2c | 1157 | |
d62a17ae | 1158 | isisMplsTE.status = disable; |
f8c06e2c | 1159 | |
d62a17ae | 1160 | /* Flush LSP if circuit engage */ |
1161 | for (ALL_LIST_ELEMENTS_RO(isisMplsTE.cir_list, node, circuit)) { | |
1162 | if (circuit->mtc == NULL || (circuit->mtc->status == disable)) | |
1163 | continue; | |
f8c06e2c | 1164 | |
d62a17ae | 1165 | /* disable MPLS_TE Circuit */ |
1166 | circuit->mtc->status = disable; | |
f8c06e2c | 1167 | |
d62a17ae | 1168 | /* Re-originate circuit without STD_TE & GMPLS parameters */ |
1169 | if (circuit->area) | |
1170 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
1171 | 0); | |
1172 | } | |
f8c06e2c | 1173 | |
d62a17ae | 1174 | return CMD_SUCCESS; |
f8c06e2c OD |
1175 | } |
1176 | ||
1177 | DEFUN (isis_mpls_te_router_addr, | |
1178 | isis_mpls_te_router_addr_cmd, | |
1179 | "mpls-te router-address A.B.C.D", | |
1180 | MPLS_TE_STR | |
1181 | "Stable IP address of the advertising router\n" | |
1182 | "MPLS-TE router address in IPv4 address format\n") | |
1183 | { | |
d62a17ae | 1184 | int idx_ipv4 = 2; |
1185 | struct in_addr value; | |
1186 | struct listnode *node; | |
1187 | struct isis_area *area; | |
1188 | ||
1189 | if (!inet_aton(argv[idx_ipv4]->arg, &value)) { | |
1190 | vty_out(vty, "Please specify Router-Addr by A.B.C.D\n"); | |
1191 | return CMD_WARNING_CONFIG_FAILED; | |
1192 | } | |
1193 | ||
1194 | isisMplsTE.router_id.s_addr = value.s_addr; | |
1195 | ||
1196 | if (isisMplsTE.status == disable) | |
1197 | return CMD_SUCCESS; | |
1198 | ||
1199 | /* Update main Router ID in isis global structure */ | |
1200 | isis->router_id = value.s_addr; | |
1201 | /* And re-schedule LSP update */ | |
1202 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) | |
1203 | if (listcount(area->area_addrs) > 0) | |
1204 | lsp_regenerate_schedule(area, area->is_type, 0); | |
1205 | ||
1206 | return CMD_SUCCESS; | |
f8c06e2c OD |
1207 | } |
1208 | ||
1209 | DEFUN (isis_mpls_te_inter_as, | |
1210 | isis_mpls_te_inter_as_cmd, | |
6147e2c6 | 1211 | "mpls-te inter-as <level-1|level-1-2|level-2-only>", |
f8c06e2c OD |
1212 | MPLS_TE_STR |
1213 | "Configure MPLS-TE Inter-AS support\n" | |
1214 | "AREA native mode self originate INTER-AS LSP with L1 only flooding scope)\n" | |
1215 | "AREA native mode self originate INTER-AS LSP with L1 and L2 flooding scope)\n" | |
1216 | "AS native mode self originate INTER-AS LSP with L2 only flooding scope\n") | |
1217 | { | |
d62a17ae | 1218 | vty_out(vty, "Not yet supported\n"); |
1219 | return CMD_SUCCESS; | |
f8c06e2c OD |
1220 | } |
1221 | ||
1222 | DEFUN (no_isis_mpls_te_inter_as, | |
1223 | no_isis_mpls_te_inter_as_cmd, | |
1224 | "no mpls-te inter-as", | |
1225 | NO_STR | |
1226 | "Disable the MPLS-TE functionality\n" | |
1227 | "Disable MPLS-TE Inter-AS support\n") | |
1228 | { | |
1229 | ||
d62a17ae | 1230 | vty_out(vty, "Not yet supported\n"); |
1231 | return CMD_SUCCESS; | |
f8c06e2c OD |
1232 | } |
1233 | ||
1234 | DEFUN (show_isis_mpls_te_router, | |
1235 | show_isis_mpls_te_router_cmd, | |
1236 | "show isis mpls-te router", | |
1237 | SHOW_STR | |
1238 | ISIS_STR | |
1239 | MPLS_TE_STR | |
1240 | "Router information\n") | |
1241 | { | |
d62a17ae | 1242 | if (IS_MPLS_TE(isisMplsTE)) { |
1243 | vty_out(vty, "--- MPLS-TE router parameters ---\n"); | |
1244 | ||
1245 | if (ntohs(isisMplsTE.router_id.s_addr) != 0) | |
1246 | vty_out(vty, " Router-Address: %s\n", | |
1247 | inet_ntoa(isisMplsTE.router_id)); | |
1248 | else | |
1249 | vty_out(vty, " N/A\n"); | |
1250 | } else | |
1251 | vty_out(vty, " MPLS-TE is disable on this router\n"); | |
1252 | ||
1253 | return CMD_SUCCESS; | |
f8c06e2c OD |
1254 | } |
1255 | ||
d62a17ae | 1256 | static void show_mpls_te_sub(struct vty *vty, struct interface *ifp) |
f8c06e2c | 1257 | { |
d62a17ae | 1258 | struct mpls_te_circuit *mtc; |
1259 | ||
1260 | if ((IS_MPLS_TE(isisMplsTE)) | |
1261 | && ((mtc = lookup_mpls_params_by_ifp(ifp)) != NULL)) { | |
1262 | /* Continue only if interface is not passive or support Inter-AS | |
1263 | * TEv2 */ | |
1264 | if (mtc->status != enable) { | |
1265 | if (IS_INTER_AS(mtc->type)) { | |
1266 | vty_out(vty, | |
1267 | "-- Inter-AS TEv2 link parameters for %s --\n", | |
1268 | ifp->name); | |
1269 | } else { | |
1270 | /* MPLS-TE is not activate on this interface */ | |
1271 | /* or this interface is passive and Inter-AS | |
1272 | * TEv2 is not activate */ | |
1273 | vty_out(vty, | |
1274 | " %s: MPLS-TE is disabled on this interface\n", | |
1275 | ifp->name); | |
1276 | return; | |
1277 | } | |
1278 | } else { | |
1279 | vty_out(vty, "-- MPLS-TE link parameters for %s --\n", | |
1280 | ifp->name); | |
1281 | } | |
1282 | ||
1283 | show_vty_subtlv_admin_grp(vty, &mtc->admin_grp); | |
1284 | ||
1285 | if (SUBTLV_TYPE(mtc->local_ipaddr) != 0) | |
1286 | show_vty_subtlv_local_ipaddr(vty, &mtc->local_ipaddr); | |
1287 | if (SUBTLV_TYPE(mtc->rmt_ipaddr) != 0) | |
1288 | show_vty_subtlv_rmt_ipaddr(vty, &mtc->rmt_ipaddr); | |
1289 | ||
1290 | show_vty_subtlv_max_bw(vty, &mtc->max_bw); | |
1291 | show_vty_subtlv_max_rsv_bw(vty, &mtc->max_rsv_bw); | |
1292 | show_vty_subtlv_unrsv_bw(vty, &mtc->unrsv_bw); | |
1293 | show_vty_subtlv_te_metric(vty, &mtc->te_metric); | |
1294 | ||
1295 | if (IS_INTER_AS(mtc->type)) { | |
1296 | if (SUBTLV_TYPE(mtc->ras) != 0) | |
1297 | show_vty_subtlv_ras(vty, &mtc->ras); | |
1298 | if (SUBTLV_TYPE(mtc->rip) != 0) | |
1299 | show_vty_subtlv_rip(vty, &mtc->rip); | |
1300 | } | |
1301 | ||
1302 | show_vty_subtlv_av_delay(vty, &mtc->av_delay); | |
1303 | show_vty_subtlv_mm_delay(vty, &mtc->mm_delay); | |
1304 | show_vty_subtlv_delay_var(vty, &mtc->delay_var); | |
1305 | show_vty_subtlv_pkt_loss(vty, &mtc->pkt_loss); | |
1306 | show_vty_subtlv_res_bw(vty, &mtc->res_bw); | |
1307 | show_vty_subtlv_ava_bw(vty, &mtc->ava_bw); | |
1308 | show_vty_subtlv_use_bw(vty, &mtc->use_bw); | |
1309 | vty_out(vty, "---------------\n\n"); | |
1310 | } else { | |
1311 | vty_out(vty, " %s: MPLS-TE is disabled on this interface\n", | |
1312 | ifp->name); | |
1313 | } | |
1314 | ||
1315 | return; | |
f8c06e2c OD |
1316 | } |
1317 | ||
1318 | DEFUN (show_isis_mpls_te_interface, | |
1319 | show_isis_mpls_te_interface_cmd, | |
1320 | "show isis mpls-te interface [INTERFACE]", | |
1321 | SHOW_STR | |
1322 | ISIS_STR | |
1323 | MPLS_TE_STR | |
1324 | "Interface information\n" | |
1325 | "Interface name\n") | |
1326 | { | |
d62a17ae | 1327 | int idx_interface = 4; |
1328 | struct interface *ifp; | |
1329 | struct listnode *node; | |
1330 | ||
1331 | /* Show All Interfaces. */ | |
1332 | if (argc == 4) { | |
1333 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) | |
1334 | show_mpls_te_sub(vty, ifp); | |
1335 | } | |
1336 | /* Interface name is specified. */ | |
1337 | else { | |
1338 | if ((ifp = if_lookup_by_name(argv[idx_interface]->arg, | |
1339 | VRF_DEFAULT)) | |
1340 | == NULL) | |
1341 | vty_out(vty, "No such interface name\n"); | |
1342 | else | |
1343 | show_mpls_te_sub(vty, ifp); | |
1344 | } | |
1345 | ||
1346 | return CMD_SUCCESS; | |
f8c06e2c OD |
1347 | } |
1348 | ||
1349 | /* Initialize MPLS_TE */ | |
d62a17ae | 1350 | void isis_mpls_te_init(void) |
f8c06e2c OD |
1351 | { |
1352 | ||
d62a17ae | 1353 | zlog_debug("ISIS MPLS-TE: Initialize"); |
f8c06e2c | 1354 | |
d62a17ae | 1355 | /* Initialize MPLS_TE structure */ |
1356 | isisMplsTE.status = disable; | |
1357 | isisMplsTE.level = 0; | |
1358 | isisMplsTE.inter_as = off; | |
1359 | isisMplsTE.interas_areaid.s_addr = 0; | |
1360 | isisMplsTE.cir_list = list_new(); | |
1361 | isisMplsTE.router_id.s_addr = 0; | |
f8c06e2c | 1362 | |
d62a17ae | 1363 | /* Register new VTY commands */ |
1364 | install_element(VIEW_NODE, &show_isis_mpls_te_router_cmd); | |
1365 | install_element(VIEW_NODE, &show_isis_mpls_te_interface_cmd); | |
f8c06e2c | 1366 | |
d62a17ae | 1367 | install_element(ISIS_NODE, &isis_mpls_te_on_cmd); |
1368 | install_element(ISIS_NODE, &no_isis_mpls_te_on_cmd); | |
1369 | install_element(ISIS_NODE, &isis_mpls_te_router_addr_cmd); | |
1370 | install_element(ISIS_NODE, &isis_mpls_te_inter_as_cmd); | |
1371 | install_element(ISIS_NODE, &no_isis_mpls_te_inter_as_cmd); | |
f8c06e2c | 1372 | |
d62a17ae | 1373 | return; |
f8c06e2c | 1374 | } |