isis_te.c 38 KB

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