ospf_te.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910
  1. /*
  2. * This is an implementation of draft-katz-yeung-ospf-traffic-06.txt
  3. * Copyright (C) 2001 KDD R&D Laboratories, Inc.
  4. * http://www.kddlabs.co.jp/
  5. *
  6. * This file is part of GNU Zebra.
  7. *
  8. * GNU Zebra is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * GNU Zebra is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  20. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. * 02111-1307, USA.
  22. */
  23. /***** MTYPE definition is not reflected to "memory.h" yet. *****/
  24. #define MTYPE_OSPF_MPLS_TE_LINKPARAMS 0
  25. #include <zebra.h>
  26. #ifdef HAVE_OSPF_TE
  27. #ifndef HAVE_OPAQUE_LSA
  28. #error "Wrong configure option"
  29. #endif /* HAVE_OPAQUE_LSA */
  30. #include "linklist.h"
  31. #include "prefix.h"
  32. #include "if.h"
  33. #include "table.h"
  34. #include "memory.h"
  35. #include "command.h"
  36. #include "vty.h"
  37. #include "stream.h"
  38. #include "log.h"
  39. #include "thread.h"
  40. #include "hash.h"
  41. #include "sockunion.h" /* for inet_aton() */
  42. #include "ospfd/ospfd.h"
  43. #include "ospfd/ospf_interface.h"
  44. #include "ospfd/ospf_ism.h"
  45. #include "ospfd/ospf_asbr.h"
  46. #include "ospfd/ospf_lsa.h"
  47. #include "ospfd/ospf_lsdb.h"
  48. #include "ospfd/ospf_neighbor.h"
  49. #include "ospfd/ospf_nsm.h"
  50. #include "ospfd/ospf_flood.h"
  51. #include "ospfd/ospf_packet.h"
  52. #include "ospfd/ospf_spf.h"
  53. #include "ospfd/ospf_dump.h"
  54. #include "ospfd/ospf_route.h"
  55. #include "ospfd/ospf_ase.h"
  56. #include "ospfd/ospf_zebra.h"
  57. #include "ospfd/ospf_te.h"
  58. /* Following structure are internal use only. */
  59. struct ospf_mpls_te
  60. {
  61. enum { disabled, enabled } status;
  62. /* List elements are zebra-interfaces (ifp), not ospf-interfaces (oi). */
  63. struct list *iflist;
  64. /* Store Router-TLV in network byte order. */
  65. struct te_tlv_router_addr router_addr;
  66. };
  67. struct mpls_te_link
  68. {
  69. /*
  70. * According to MPLS-TE (draft) specification, 24-bit Opaque-ID field
  71. * is subdivided into 8-bit "unused" field and 16-bit "instance" field.
  72. * In this implementation, each Link-TLV has its own instance.
  73. */
  74. u_int32_t instance;
  75. /* Reference pointer to a Zebra-interface. */
  76. struct interface *ifp;
  77. /* Area info in which this MPLS-TE link belongs to. */
  78. struct ospf_area *area;
  79. /* Flags to manage this link parameters. */
  80. u_int32_t flags;
  81. #define LPFLG_LOOKUP_DONE 0x1
  82. #define LPFLG_LSA_ENGAGED 0x2
  83. #define LPFLG_LSA_FORCED_REFRESH 0x4
  84. /* Store Link-TLV in network byte order. */
  85. struct te_tlv_link link_header;
  86. struct te_link_subtlv_link_type link_type;
  87. struct te_link_subtlv_link_id link_id;
  88. struct te_link_subtlv_lclif_ipaddr *lclif_ipaddr;
  89. struct te_link_subtlv_rmtif_ipaddr *rmtif_ipaddr;
  90. struct te_link_subtlv_te_metric te_metric;
  91. struct te_link_subtlv_max_bw max_bw;
  92. struct te_link_subtlv_max_rsv_bw max_rsv_bw;
  93. struct te_link_subtlv_unrsv_bw unrsv_bw;
  94. struct te_link_subtlv_rsc_clsclr rsc_clsclr;
  95. };
  96. /*
  97. * Global variable to manage Opaque-LSA/MPLS-TE on this node.
  98. * Note that all parameter values are stored in network byte order.
  99. */
  100. static struct ospf_mpls_te OspfMplsTE;
  101. enum oifstate {
  102. OI_ANY, OI_DOWN, OI_UP
  103. };
  104. enum sched_opcode {
  105. REORIGINATE_PER_AREA, REFRESH_THIS_LSA, FLUSH_THIS_LSA
  106. };
  107. /*------------------------------------------------------------------------*
  108. * Followings are initialize/terminate functions for MPLS-TE handling.
  109. *------------------------------------------------------------------------*/
  110. static int ospf_mpls_te_new_if (struct interface *ifp);
  111. static int ospf_mpls_te_del_if (struct interface *ifp);
  112. static void ospf_mpls_te_ism_change (struct ospf_interface *oi, int old_status);
  113. static void ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_status);
  114. static void ospf_mpls_te_config_write_router (struct vty *vty);
  115. static void ospf_mpls_te_config_write_if (struct vty *vty, struct interface *ifp);
  116. static void ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa);
  117. static int ospf_mpls_te_lsa_originate (void *arg);
  118. static struct ospf_lsa *ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa);
  119. static void ospf_mpls_te_lsa_schedule (struct mpls_te_link *lp, enum sched_opcode);
  120. static void del_mpls_te_link (void *val);
  121. static void ospf_mpls_te_register_vty (void);
  122. int
  123. ospf_mpls_te_init (void)
  124. {
  125. int rc;
  126. rc = ospf_register_opaque_functab (
  127. OSPF_OPAQUE_AREA_LSA,
  128. OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
  129. ospf_mpls_te_new_if,
  130. ospf_mpls_te_del_if,
  131. ospf_mpls_te_ism_change,
  132. ospf_mpls_te_nsm_change,
  133. ospf_mpls_te_config_write_router,
  134. ospf_mpls_te_config_write_if,
  135. NULL,/* ospf_mpls_te_config_write_debug */
  136. ospf_mpls_te_show_info,
  137. ospf_mpls_te_lsa_originate,
  138. ospf_mpls_te_lsa_refresh,
  139. NULL,/* ospf_mpls_te_new_lsa_hook */
  140. NULL /* ospf_mpls_te_del_lsa_hook */);
  141. if (rc != 0)
  142. {
  143. zlog_warn ("ospf_mpls_te_init: Failed to register functions");
  144. goto out;
  145. }
  146. memset (&OspfMplsTE, 0, sizeof (struct ospf_mpls_te));
  147. OspfMplsTE.status = disabled;
  148. OspfMplsTE.iflist = list_new ();
  149. OspfMplsTE.iflist->del = del_mpls_te_link;
  150. ospf_mpls_te_register_vty ();
  151. out:
  152. return rc;
  153. }
  154. void
  155. ospf_mpls_te_term (void)
  156. {
  157. list_delete (OspfMplsTE.iflist);
  158. OspfMplsTE.iflist = NULL;
  159. OspfMplsTE.status = disabled;
  160. ospf_delete_opaque_functab (OSPF_OPAQUE_AREA_LSA,
  161. OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
  162. return;
  163. }
  164. /*------------------------------------------------------------------------*
  165. * Followings are control functions for MPLS-TE parameters management.
  166. *------------------------------------------------------------------------*/
  167. static void
  168. del_mpls_te_link (void *val)
  169. {
  170. XFREE (MTYPE_OSPF_MPLS_TE_LINKPARAMS, val);
  171. return;
  172. }
  173. static u_int32_t
  174. get_mpls_te_instance_value (void)
  175. {
  176. static u_int32_t seqno = 0;
  177. if (seqno < MAX_LEGAL_TE_INSTANCE_NUM )
  178. seqno += 1;
  179. else
  180. seqno = 1; /* Avoid zero. */
  181. return seqno;
  182. }
  183. static struct ospf_interface *
  184. lookup_oi_by_ifp (struct interface *ifp,
  185. struct ospf_area *area, enum oifstate oifstate)
  186. {
  187. struct ospf_interface *oi = NULL;
  188. struct route_node *rn;
  189. for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
  190. {
  191. if ((oi = rn->info) == NULL)
  192. continue;
  193. switch (oifstate)
  194. {
  195. case OI_ANY:
  196. break;
  197. case OI_DOWN:
  198. if (ospf_if_is_enable (oi))
  199. continue;
  200. break;
  201. case OI_UP:
  202. if (! ospf_if_is_enable (oi))
  203. continue;
  204. break;
  205. default:
  206. zlog_warn ("lookup_oi_by_ifp: Unknown oifstate: %x", oifstate);
  207. goto out;
  208. }
  209. if (area == NULL || oi->area == area)
  210. return oi;
  211. }
  212. out:
  213. return NULL;
  214. }
  215. static struct mpls_te_link *
  216. lookup_linkparams_by_ifp (struct interface *ifp)
  217. {
  218. struct listnode *node, *nnode;
  219. struct mpls_te_link *lp;
  220. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  221. if (lp->ifp == ifp)
  222. return lp;
  223. return NULL;
  224. }
  225. static struct mpls_te_link *
  226. lookup_linkparams_by_instance (struct ospf_lsa *lsa)
  227. {
  228. struct listnode *node;
  229. struct mpls_te_link *lp;
  230. unsigned int key = GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr));
  231. for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
  232. if (lp->instance == key)
  233. return lp;
  234. zlog_warn ("lookup_linkparams_by_instance: Entry not found: key(%x)", key);
  235. return NULL;
  236. }
  237. static void
  238. ospf_mpls_te_foreach_area (
  239. void (*func)(struct mpls_te_link *lp, enum sched_opcode),
  240. enum sched_opcode sched_opcode)
  241. {
  242. struct listnode *node, *nnode;
  243. struct listnode *node2;
  244. struct mpls_te_link *lp;
  245. struct ospf_area *area;
  246. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  247. {
  248. if ((area = lp->area) == NULL)
  249. continue;
  250. if (lp->flags & LPFLG_LOOKUP_DONE)
  251. continue;
  252. if (func != NULL)
  253. (* func)(lp, sched_opcode);
  254. for (node2 = listnextnode (node); node2; node2 = listnextnode (node2))
  255. if ((lp = listgetdata (node2)) != NULL)
  256. if (lp->area != NULL)
  257. if (IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id))
  258. lp->flags |= LPFLG_LOOKUP_DONE;
  259. }
  260. for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
  261. if (lp->area != NULL)
  262. lp->flags &= ~LPFLG_LOOKUP_DONE;
  263. return;
  264. }
  265. static void
  266. set_mpls_te_router_addr (struct in_addr ipv4)
  267. {
  268. OspfMplsTE.router_addr.header.type = htons (TE_TLV_ROUTER_ADDR);
  269. OspfMplsTE.router_addr.header.length = htons (sizeof (ipv4));
  270. OspfMplsTE.router_addr.value = ipv4;
  271. return;
  272. }
  273. static void
  274. set_linkparams_link_header (struct mpls_te_link *lp)
  275. {
  276. struct te_tlv_header *tlvh;
  277. u_int16_t length = 0;
  278. /* TE_LINK_SUBTLV_LINK_TYPE */
  279. if (ntohs (lp->link_type.header.type) != 0)
  280. length += TLV_SIZE (&lp->link_type.header);
  281. /* TE_LINK_SUBTLV_LINK_ID */
  282. if (ntohs (lp->link_id.header.type) != 0)
  283. length += TLV_SIZE (&lp->link_id.header);
  284. /* TE_LINK_SUBTLV_LCLIF_IPADDR */
  285. if ((tlvh = (struct te_tlv_header *) lp->lclif_ipaddr) != NULL
  286. && ntohs (tlvh->type) != 0)
  287. length += TLV_SIZE (tlvh);
  288. /* TE_LINK_SUBTLV_RMTIF_IPADDR */
  289. if ((tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr) != NULL
  290. && ntohs (tlvh->type) != 0)
  291. length += TLV_SIZE (tlvh);
  292. /* TE_LINK_SUBTLV_TE_METRIC */
  293. if (ntohs (lp->te_metric.header.type) != 0)
  294. length += TLV_SIZE (&lp->te_metric.header);
  295. /* TE_LINK_SUBTLV_MAX_BW */
  296. if (ntohs (lp->max_bw.header.type) != 0)
  297. length += TLV_SIZE (&lp->max_bw.header);
  298. /* TE_LINK_SUBTLV_MAX_RSV_BW */
  299. if (ntohs (lp->max_rsv_bw.header.type) != 0)
  300. length += TLV_SIZE (&lp->max_rsv_bw.header);
  301. /* TE_LINK_SUBTLV_UNRSV_BW */
  302. if (ntohs (lp->unrsv_bw.header.type) != 0)
  303. length += TLV_SIZE (&lp->unrsv_bw.header);
  304. /* TE_LINK_SUBTLV_RSC_CLSCLR */
  305. if (ntohs (lp->rsc_clsclr.header.type) != 0)
  306. length += TLV_SIZE (&lp->rsc_clsclr.header);
  307. lp->link_header.header.type = htons (TE_TLV_LINK);
  308. lp->link_header.header.length = htons (length);
  309. return;
  310. }
  311. static void
  312. set_linkparams_link_type (struct ospf_interface *oi, struct mpls_te_link *lp)
  313. {
  314. lp->link_type.header.type = htons (TE_LINK_SUBTLV_LINK_TYPE);
  315. lp->link_type.header.length = htons (sizeof (lp->link_type.link_type.value));
  316. switch (oi->type)
  317. {
  318. case OSPF_IFTYPE_POINTOPOINT:
  319. lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_PTP;
  320. break;
  321. case OSPF_IFTYPE_BROADCAST:
  322. case OSPF_IFTYPE_NBMA:
  323. lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_MA;
  324. break;
  325. default:
  326. /* Not supported yet. *//* XXX */
  327. lp->link_type.header.type = htons (0);
  328. break;
  329. }
  330. return;
  331. }
  332. static void
  333. set_linkparams_link_id (struct ospf_interface *oi, struct mpls_te_link *lp)
  334. {
  335. struct ospf_neighbor *nbr;
  336. int done = 0;
  337. lp->link_id.header.type = htons (TE_LINK_SUBTLV_LINK_ID);
  338. lp->link_id.header.length = htons (sizeof (lp->link_id.value));
  339. /*
  340. * The Link ID is identical to the contents of the Link ID field
  341. * in the Router LSA for these link types.
  342. */
  343. switch (oi->type)
  344. {
  345. case OSPF_IFTYPE_POINTOPOINT:
  346. /* Take the router ID of the neighbor. */
  347. if ((nbr = ospf_nbr_lookup_ptop (oi))
  348. && nbr->state == NSM_Full)
  349. {
  350. lp->link_id.value = nbr->router_id;
  351. done = 1;
  352. }
  353. break;
  354. case OSPF_IFTYPE_BROADCAST:
  355. case OSPF_IFTYPE_NBMA:
  356. /* Take the interface address of the designated router. */
  357. if ((nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &DR (oi))) == NULL)
  358. break;
  359. if (nbr->state == NSM_Full
  360. || (IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))
  361. && ospf_nbr_count (oi, NSM_Full) > 0))
  362. {
  363. lp->link_id.value = DR (oi);
  364. done = 1;
  365. }
  366. break;
  367. default:
  368. /* Not supported yet. *//* XXX */
  369. lp->link_id.header.type = htons (0);
  370. break;
  371. }
  372. if (! done)
  373. {
  374. struct in_addr mask;
  375. masklen2ip (oi->address->prefixlen, &mask);
  376. lp->link_id.value.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr;
  377. }
  378. return;
  379. }
  380. static void
  381. set_linkparams_te_metric (struct mpls_te_link *lp, u_int32_t te_metric)
  382. {
  383. lp->te_metric.header.type = htons (TE_LINK_SUBTLV_TE_METRIC);
  384. lp->te_metric.header.length = htons (sizeof (lp->te_metric.value));
  385. lp->te_metric.value = htonl (te_metric);
  386. return;
  387. }
  388. static void
  389. set_linkparams_max_bw (struct mpls_te_link *lp, float *fp)
  390. {
  391. lp->max_bw.header.type = htons (TE_LINK_SUBTLV_MAX_BW);
  392. lp->max_bw.header.length = htons (sizeof (lp->max_bw.value));
  393. htonf (fp, &lp->max_bw.value);
  394. return;
  395. }
  396. static void
  397. set_linkparams_max_rsv_bw (struct mpls_te_link *lp, float *fp)
  398. {
  399. lp->max_rsv_bw.header.type = htons (TE_LINK_SUBTLV_MAX_RSV_BW);
  400. lp->max_rsv_bw.header.length = htons (sizeof (lp->max_rsv_bw.value));
  401. htonf (fp, &lp->max_rsv_bw.value);
  402. return;
  403. }
  404. static void
  405. set_linkparams_unrsv_bw (struct mpls_te_link *lp, int priority, float *fp)
  406. {
  407. /* Note that TLV-length field is the size of array. */
  408. lp->unrsv_bw.header.type = htons (TE_LINK_SUBTLV_UNRSV_BW);
  409. lp->unrsv_bw.header.length = htons (sizeof (lp->unrsv_bw.value));
  410. htonf (fp, &lp->unrsv_bw.value [priority]);
  411. return;
  412. }
  413. static void
  414. set_linkparams_rsc_clsclr (struct mpls_te_link *lp, u_int32_t classcolor)
  415. {
  416. lp->rsc_clsclr.header.type = htons (TE_LINK_SUBTLV_RSC_CLSCLR);
  417. lp->rsc_clsclr.header.length = htons (sizeof (lp->rsc_clsclr.value));
  418. lp->rsc_clsclr.value = htonl (classcolor);
  419. return;
  420. }
  421. static void
  422. initialize_linkparams (struct mpls_te_link *lp)
  423. {
  424. struct interface *ifp = lp->ifp;
  425. struct ospf_interface *oi;
  426. float fval;
  427. int i;
  428. if ((oi = lookup_oi_by_ifp (ifp, NULL, OI_ANY)) == NULL)
  429. return;
  430. /*
  431. * Try to set initial values those can be derived from
  432. * zebra-interface information.
  433. */
  434. set_linkparams_link_type (oi, lp);
  435. /*
  436. * Linux and *BSD kernel holds bandwidth parameter as an "int" type.
  437. * We may have to reconsider, if "ifp->bandwidth" type changes to float.
  438. */
  439. fval = (float)((ifp->bandwidth ? ifp->bandwidth
  440. : OSPF_DEFAULT_BANDWIDTH) * 1000 / 8);
  441. set_linkparams_max_bw (lp, &fval);
  442. set_linkparams_max_rsv_bw (lp, &fval);
  443. for (i = 0; i < 8; i++)
  444. set_linkparams_unrsv_bw (lp, i, &fval);
  445. return;
  446. }
  447. static int
  448. is_mandated_params_set (struct mpls_te_link *lp)
  449. {
  450. int rc = 0;
  451. if (ntohs (OspfMplsTE.router_addr.header.type) == 0)
  452. goto out;
  453. if (ntohs (lp->link_type.header.type) == 0)
  454. goto out;
  455. if (ntohs (lp->link_id.header.type) == 0)
  456. goto out;
  457. rc = 1;
  458. out:
  459. return rc;
  460. }
  461. /*------------------------------------------------------------------------*
  462. * Followings are callback functions against generic Opaque-LSAs handling.
  463. *------------------------------------------------------------------------*/
  464. static int
  465. ospf_mpls_te_new_if (struct interface *ifp)
  466. {
  467. struct mpls_te_link *new;
  468. int rc = -1;
  469. if (lookup_linkparams_by_ifp (ifp) != NULL)
  470. {
  471. zlog_warn ("ospf_mpls_te_new_if: ifp(%p) already in use?", ifp);
  472. rc = 0; /* Do nothing here. */
  473. goto out;
  474. }
  475. new = XCALLOC (MTYPE_OSPF_MPLS_TE_LINKPARAMS,
  476. sizeof (struct mpls_te_link));
  477. if (new == NULL)
  478. {
  479. zlog_warn ("ospf_mpls_te_new_if: XMALLOC: %s", safe_strerror (errno));
  480. goto out;
  481. }
  482. new->area = NULL;
  483. new->flags = 0;
  484. new->instance = get_mpls_te_instance_value ();
  485. new->ifp = ifp;
  486. initialize_linkparams (new);
  487. listnode_add (OspfMplsTE.iflist, new);
  488. /* Schedule Opaque-LSA refresh. *//* XXX */
  489. rc = 0;
  490. out:
  491. return rc;
  492. }
  493. static int
  494. ospf_mpls_te_del_if (struct interface *ifp)
  495. {
  496. struct mpls_te_link *lp;
  497. int rc = -1;
  498. if ((lp = lookup_linkparams_by_ifp (ifp)) != NULL)
  499. {
  500. struct list *iflist = OspfMplsTE.iflist;
  501. /* Dequeue listnode entry from the list. */
  502. listnode_delete (iflist, lp);
  503. /* Avoid misjudgement in the next lookup. */
  504. if (listcount (iflist) == 0)
  505. iflist->head = iflist->tail = NULL;
  506. XFREE (MTYPE_OSPF_MPLS_TE_LINKPARAMS, lp);
  507. }
  508. /* Schedule Opaque-LSA refresh. *//* XXX */
  509. rc = 0;
  510. /*out:*/
  511. return rc;
  512. }
  513. static void
  514. ospf_mpls_te_ism_change (struct ospf_interface *oi, int old_state)
  515. {
  516. struct te_link_subtlv_link_type old_type;
  517. struct te_link_subtlv_link_id old_id;
  518. struct mpls_te_link *lp;
  519. if ((lp = lookup_linkparams_by_ifp (oi->ifp)) == NULL)
  520. {
  521. zlog_warn ("ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?", IF_NAME (oi));
  522. goto out;
  523. }
  524. if (oi->area == NULL || oi->area->ospf == NULL)
  525. {
  526. zlog_warn ("ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?",
  527. IF_NAME (oi));
  528. goto out;
  529. }
  530. #ifdef notyet
  531. if ((lp->area != NULL
  532. && ! IPV4_ADDR_SAME (&lp->area->area_id, &oi->area->area_id))
  533. || (lp->area != NULL && oi->area == NULL))
  534. {
  535. /* How should we consider this case? */
  536. zlog_warn ("MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs", IF_NAME (oi), oi->area ? inet_ntoa (oi->area->area_id) : "N/A");
  537. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  538. }
  539. #endif
  540. /* Keep Area information in conbination with linkparams. */
  541. lp->area = oi->area;
  542. switch (oi->state)
  543. {
  544. case ISM_PointToPoint:
  545. case ISM_DROther:
  546. case ISM_Backup:
  547. case ISM_DR:
  548. old_type = lp->link_type;
  549. old_id = lp->link_id;
  550. set_linkparams_link_type (oi, lp);
  551. set_linkparams_link_id (oi, lp);
  552. if ((ntohs (old_type.header.type) != ntohs (lp->link_type.header.type)
  553. || old_type.link_type.value != lp->link_type.link_type.value)
  554. || (ntohs (old_id.header.type) != ntohs (lp->link_id.header.type)
  555. || ntohl (old_id.value.s_addr) != ntohl (lp->link_id.value.s_addr)))
  556. {
  557. if (lp->flags & LPFLG_LSA_ENGAGED)
  558. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  559. else
  560. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
  561. }
  562. break;
  563. default:
  564. lp->link_type.header.type = htons (0);
  565. lp->link_id.header.type = htons (0);
  566. if (lp->flags & LPFLG_LSA_ENGAGED)
  567. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  568. break;
  569. }
  570. out:
  571. return;
  572. }
  573. static void
  574. ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_state)
  575. {
  576. /* So far, nothing to do here. */
  577. return;
  578. }
  579. /*------------------------------------------------------------------------*
  580. * Followings are OSPF protocol processing functions for MPLS-TE.
  581. *------------------------------------------------------------------------*/
  582. static void
  583. build_tlv_header (struct stream *s, struct te_tlv_header *tlvh)
  584. {
  585. stream_put (s, tlvh, sizeof (struct te_tlv_header));
  586. return;
  587. }
  588. static void
  589. build_router_tlv (struct stream *s)
  590. {
  591. struct te_tlv_header *tlvh = &OspfMplsTE.router_addr.header;
  592. if (ntohs (tlvh->type) != 0)
  593. {
  594. build_tlv_header (s, tlvh);
  595. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  596. }
  597. return;
  598. }
  599. static void
  600. build_link_subtlv_link_type (struct stream *s, struct mpls_te_link *lp)
  601. {
  602. struct te_tlv_header *tlvh = &lp->link_type.header;
  603. if (ntohs (tlvh->type) != 0)
  604. {
  605. build_tlv_header (s, tlvh);
  606. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  607. }
  608. return;
  609. }
  610. static void
  611. build_link_subtlv_link_id (struct stream *s, struct mpls_te_link *lp)
  612. {
  613. struct te_tlv_header *tlvh = &lp->link_id.header;
  614. if (ntohs (tlvh->type) != 0)
  615. {
  616. build_tlv_header (s, tlvh);
  617. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  618. }
  619. return;
  620. }
  621. static void
  622. build_link_subtlv_lclif_ipaddr (struct stream *s, struct mpls_te_link *lp)
  623. {
  624. struct te_tlv_header *tlvh = (struct te_tlv_header *) lp->lclif_ipaddr;
  625. if (tlvh != NULL && ntohs (tlvh->type) != 0)
  626. {
  627. build_tlv_header (s, tlvh);
  628. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  629. }
  630. return;
  631. }
  632. static void
  633. build_link_subtlv_rmtif_ipaddr (struct stream *s, struct mpls_te_link *lp)
  634. {
  635. struct te_tlv_header *tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr;
  636. if (tlvh != NULL && ntohs (tlvh->type) != 0)
  637. {
  638. build_tlv_header (s, tlvh);
  639. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  640. }
  641. return;
  642. }
  643. static void
  644. build_link_subtlv_te_metric (struct stream *s, struct mpls_te_link *lp)
  645. {
  646. struct te_tlv_header *tlvh = &lp->te_metric.header;
  647. if (ntohs (tlvh->type) != 0)
  648. {
  649. build_tlv_header (s, tlvh);
  650. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  651. }
  652. return;
  653. }
  654. static void
  655. build_link_subtlv_max_bw (struct stream *s, struct mpls_te_link *lp)
  656. {
  657. struct te_tlv_header *tlvh = &lp->max_bw.header;
  658. if (ntohs (tlvh->type) != 0)
  659. {
  660. build_tlv_header (s, tlvh);
  661. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  662. }
  663. return;
  664. }
  665. static void
  666. build_link_subtlv_max_rsv_bw (struct stream *s, struct mpls_te_link *lp)
  667. {
  668. struct te_tlv_header *tlvh = &lp->max_rsv_bw.header;
  669. if (ntohs (tlvh->type) != 0)
  670. {
  671. build_tlv_header (s, tlvh);
  672. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  673. }
  674. return;
  675. }
  676. static void
  677. build_link_subtlv_unrsv_bw (struct stream *s, struct mpls_te_link *lp)
  678. {
  679. struct te_tlv_header *tlvh = &lp->unrsv_bw.header;
  680. if (ntohs (tlvh->type) != 0)
  681. {
  682. build_tlv_header (s, tlvh);
  683. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  684. }
  685. return;
  686. }
  687. static void
  688. build_link_subtlv_rsc_clsclr (struct stream *s, struct mpls_te_link *lp)
  689. {
  690. struct te_tlv_header *tlvh = &lp->rsc_clsclr.header;
  691. if (ntohs (tlvh->type) != 0)
  692. {
  693. build_tlv_header (s, tlvh);
  694. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  695. }
  696. return;
  697. }
  698. static void
  699. build_link_tlv (struct stream *s, struct mpls_te_link *lp)
  700. {
  701. set_linkparams_link_header (lp);
  702. build_tlv_header (s, &lp->link_header.header);
  703. build_link_subtlv_link_type (s, lp);
  704. build_link_subtlv_link_id (s, lp);
  705. build_link_subtlv_lclif_ipaddr (s, lp);
  706. build_link_subtlv_rmtif_ipaddr (s, lp);
  707. build_link_subtlv_te_metric (s, lp);
  708. build_link_subtlv_max_bw (s, lp);
  709. build_link_subtlv_max_rsv_bw (s, lp);
  710. build_link_subtlv_unrsv_bw (s, lp);
  711. build_link_subtlv_rsc_clsclr (s, lp);
  712. return;
  713. }
  714. static void
  715. ospf_mpls_te_lsa_body_set (struct stream *s, struct mpls_te_link *lp)
  716. {
  717. /*
  718. * The router address TLV is type 1, and ...
  719. * It must appear in exactly one
  720. * Traffic Engineering LSA originated by a router.
  721. */
  722. build_router_tlv (s);
  723. /*
  724. * Only one Link TLV shall be carried in each LSA, allowing for fine
  725. * granularity changes in topology.
  726. */
  727. build_link_tlv (s, lp);
  728. return;
  729. }
  730. /* Create new opaque-LSA. */
  731. static struct ospf_lsa *
  732. ospf_mpls_te_lsa_new (struct ospf_area *area, struct mpls_te_link *lp)
  733. {
  734. struct stream *s;
  735. struct lsa_header *lsah;
  736. struct ospf_lsa *new = NULL;
  737. u_char options, lsa_type;
  738. struct in_addr lsa_id;
  739. u_int32_t tmp;
  740. u_int16_t length;
  741. /* Create a stream for LSA. */
  742. if ((s = stream_new (OSPF_MAX_LSA_SIZE)) == NULL)
  743. {
  744. zlog_warn ("ospf_mpls_te_lsa_new: stream_new() ?");
  745. goto out;
  746. }
  747. lsah = (struct lsa_header *) STREAM_DATA (s);
  748. options = LSA_OPTIONS_GET (area);
  749. options |= LSA_OPTIONS_NSSA_GET (area);
  750. options |= OSPF_OPTION_O; /* Don't forget this :-) */
  751. lsa_type = OSPF_OPAQUE_AREA_LSA;
  752. tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance);
  753. lsa_id.s_addr = htonl (tmp);
  754. if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
  755. zlog_debug ("LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance", lsa_type, inet_ntoa (lsa_id));
  756. /* Set opaque-LSA header fields. */
  757. lsa_header_set (s, options, lsa_type, lsa_id, area->ospf->router_id);
  758. /* Set opaque-LSA body fields. */
  759. ospf_mpls_te_lsa_body_set (s, lp);
  760. /* Set length. */
  761. length = stream_get_endp (s);
  762. lsah->length = htons (length);
  763. /* Now, create an OSPF LSA instance. */
  764. if ((new = ospf_lsa_new ()) == NULL)
  765. {
  766. zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_new() ?");
  767. stream_free (s);
  768. goto out;
  769. }
  770. if ((new->data = ospf_lsa_data_new (length)) == NULL)
  771. {
  772. zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
  773. ospf_lsa_unlock (&new);
  774. new = NULL;
  775. stream_free (s);
  776. goto out;
  777. }
  778. new->area = area;
  779. SET_FLAG (new->flags, OSPF_LSA_SELF);
  780. memcpy (new->data, lsah, length);
  781. stream_free (s);
  782. out:
  783. return new;
  784. }
  785. static int
  786. ospf_mpls_te_lsa_originate1 (struct ospf_area *area, struct mpls_te_link *lp)
  787. {
  788. struct ospf_lsa *new;
  789. int rc = -1;
  790. /* Create new Opaque-LSA/MPLS-TE instance. */
  791. if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL)
  792. {
  793. zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
  794. goto out;
  795. }
  796. /* Install this LSA into LSDB. */
  797. if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL)
  798. {
  799. zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
  800. ospf_lsa_unlock (&new);
  801. goto out;
  802. }
  803. /* Now this linkparameter entry has associated LSA. */
  804. lp->flags |= LPFLG_LSA_ENGAGED;
  805. /* Update new LSA origination count. */
  806. area->ospf->lsa_originate_count++;
  807. /* Flood new LSA through area. */
  808. ospf_flood_through_area (area, NULL/*nbr*/, new);
  809. if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
  810. {
  811. char area_id[INET_ADDRSTRLEN];
  812. strcpy (area_id, inet_ntoa (area->area_id));
  813. zlog_debug ("LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)", new->data->type, inet_ntoa (new->data->id), area_id, lp->ifp->name);
  814. ospf_lsa_header_dump (new->data);
  815. }
  816. rc = 0;
  817. out:
  818. return rc;
  819. }
  820. static int
  821. ospf_mpls_te_lsa_originate (void *arg)
  822. {
  823. struct ospf_area *area = (struct ospf_area *) arg;
  824. struct listnode *node, *nnode;
  825. struct mpls_te_link *lp;
  826. int rc = -1;
  827. if (OspfMplsTE.status == disabled)
  828. {
  829. zlog_info ("ospf_mpls_te_lsa_originate: MPLS-TE is disabled now.");
  830. rc = 0; /* This is not an error case. */
  831. goto out;
  832. }
  833. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  834. {
  835. if (lp->area == NULL)
  836. continue;
  837. if (! IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id))
  838. continue;
  839. if (lp->flags & LPFLG_LSA_ENGAGED)
  840. {
  841. if (lp->flags & LPFLG_LSA_FORCED_REFRESH)
  842. {
  843. lp->flags &= ~LPFLG_LSA_FORCED_REFRESH;
  844. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  845. }
  846. continue;
  847. }
  848. if (! is_mandated_params_set (lp))
  849. {
  850. zlog_warn ("ospf_mpls_te_lsa_originate: Link(%s) lacks some mandated MPLS-TE parameters.", lp->ifp ? lp->ifp->name : "?");
  851. continue;
  852. }
  853. /* Ok, let's try to originate an LSA for this area and Link. */
  854. if (ospf_mpls_te_lsa_originate1 (area, lp) != 0)
  855. goto out;
  856. }
  857. rc = 0;
  858. out:
  859. return rc;
  860. }
  861. static struct ospf_lsa *
  862. ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa)
  863. {
  864. struct mpls_te_link *lp;
  865. struct ospf_area *area = lsa->area;
  866. struct ospf_lsa *new = NULL;
  867. if (OspfMplsTE.status == disabled)
  868. {
  869. /*
  870. * This LSA must have flushed before due to MPLS-TE status change.
  871. * It seems a slip among routers in the routing domain.
  872. */
  873. zlog_info ("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
  874. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
  875. }
  876. /* At first, resolve lsa/lp relationship. */
  877. if ((lp = lookup_linkparams_by_instance (lsa)) == NULL)
  878. {
  879. zlog_warn ("ospf_mpls_te_lsa_refresh: Invalid parameter?");
  880. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
  881. }
  882. /* If the lsa's age reached to MaxAge, start flushing procedure. */
  883. if (IS_LSA_MAXAGE (lsa))
  884. {
  885. lp->flags &= ~LPFLG_LSA_ENGAGED;
  886. ospf_opaque_lsa_flush_schedule (lsa);
  887. goto out;
  888. }
  889. /* Create new Opaque-LSA/MPLS-TE instance. */
  890. if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL)
  891. {
  892. zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
  893. goto out;
  894. }
  895. new->data->ls_seqnum = lsa_seqnum_increment (lsa);
  896. /* Install this LSA into LSDB. */
  897. /* Given "lsa" will be freed in the next function. */
  898. if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL)
  899. {
  900. zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
  901. ospf_lsa_unlock (&new);
  902. goto out;
  903. }
  904. /* Flood updated LSA through area. */
  905. ospf_flood_through_area (area, NULL/*nbr*/, new);
  906. /* Debug logging. */
  907. if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
  908. {
  909. zlog_debug ("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
  910. new->data->type, inet_ntoa (new->data->id));
  911. ospf_lsa_header_dump (new->data);
  912. }
  913. out:
  914. return new;
  915. }
  916. static void
  917. ospf_mpls_te_lsa_schedule (struct mpls_te_link *lp,
  918. enum sched_opcode opcode)
  919. {
  920. struct ospf_lsa lsa;
  921. struct lsa_header lsah;
  922. u_int32_t tmp;
  923. memset (&lsa, 0, sizeof (lsa));
  924. memset (&lsah, 0, sizeof (lsah));
  925. lsa.area = lp->area;
  926. lsa.data = &lsah;
  927. lsah.type = OSPF_OPAQUE_AREA_LSA;
  928. tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance);
  929. lsah.id.s_addr = htonl (tmp);
  930. switch (opcode)
  931. {
  932. case REORIGINATE_PER_AREA:
  933. ospf_opaque_lsa_reoriginate_schedule ((void *) lp->area,
  934. OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
  935. break;
  936. case REFRESH_THIS_LSA:
  937. ospf_opaque_lsa_refresh_schedule (&lsa);
  938. break;
  939. case FLUSH_THIS_LSA:
  940. lp->flags &= ~LPFLG_LSA_ENGAGED;
  941. ospf_opaque_lsa_flush_schedule (&lsa);
  942. break;
  943. default:
  944. zlog_warn ("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)", opcode);
  945. break;
  946. }
  947. return;
  948. }
  949. /*------------------------------------------------------------------------*
  950. * Followings are vty session control functions.
  951. *------------------------------------------------------------------------*/
  952. static u_int16_t
  953. show_vty_router_addr (struct vty *vty, struct te_tlv_header *tlvh)
  954. {
  955. struct te_tlv_router_addr *top = (struct te_tlv_router_addr *) tlvh;
  956. if (vty != NULL)
  957. vty_out (vty, " Router-Address: %s%s", inet_ntoa (top->value), VTY_NEWLINE);
  958. else
  959. zlog_debug (" Router-Address: %s", inet_ntoa (top->value));
  960. return TLV_SIZE (tlvh);
  961. }
  962. static u_int16_t
  963. show_vty_link_header (struct vty *vty, struct te_tlv_header *tlvh)
  964. {
  965. struct te_tlv_link *top = (struct te_tlv_link *) tlvh;
  966. if (vty != NULL)
  967. vty_out (vty, " Link: %u octets of data%s", ntohs (top->header.length), VTY_NEWLINE);
  968. else
  969. zlog_debug (" Link: %u octets of data", ntohs (top->header.length));
  970. return TLV_HDR_SIZE; /* Here is special, not "TLV_SIZE". */
  971. }
  972. static u_int16_t
  973. show_vty_link_subtlv_link_type (struct vty *vty, struct te_tlv_header *tlvh)
  974. {
  975. struct te_link_subtlv_link_type *top;
  976. const char *cp = "Unknown";
  977. top = (struct te_link_subtlv_link_type *) tlvh;
  978. switch (top->link_type.value)
  979. {
  980. case LINK_TYPE_SUBTLV_VALUE_PTP:
  981. cp = "Point-to-point";
  982. break;
  983. case LINK_TYPE_SUBTLV_VALUE_MA:
  984. cp = "Multiaccess";
  985. break;
  986. default:
  987. break;
  988. }
  989. if (vty != NULL)
  990. vty_out (vty, " Link-Type: %s (%u)%s", cp, top->link_type.value, VTY_NEWLINE);
  991. else
  992. zlog_debug (" Link-Type: %s (%u)", cp, top->link_type.value);
  993. return TLV_SIZE (tlvh);
  994. }
  995. static u_int16_t
  996. show_vty_link_subtlv_link_id (struct vty *vty, struct te_tlv_header *tlvh)
  997. {
  998. struct te_link_subtlv_link_id *top;
  999. top = (struct te_link_subtlv_link_id *) tlvh;
  1000. if (vty != NULL)
  1001. vty_out (vty, " Link-ID: %s%s", inet_ntoa (top->value), VTY_NEWLINE);
  1002. else
  1003. zlog_debug (" Link-ID: %s", inet_ntoa (top->value));
  1004. return TLV_SIZE (tlvh);
  1005. }
  1006. static u_int16_t
  1007. show_vty_link_subtlv_lclif_ipaddr (struct vty *vty, struct te_tlv_header *tlvh)
  1008. {
  1009. struct te_link_subtlv_lclif_ipaddr *top;
  1010. int i, n;
  1011. top = (struct te_link_subtlv_lclif_ipaddr *) tlvh;
  1012. n = ntohs (tlvh->length) / sizeof (top->value[0]);
  1013. if (vty != NULL)
  1014. vty_out (vty, " Local Interface IP Address(es): %d%s", n, VTY_NEWLINE);
  1015. else
  1016. zlog_debug (" Local Interface IP Address(es): %d", n);
  1017. for (i = 0; i < n; i++)
  1018. {
  1019. if (vty != NULL)
  1020. vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]), VTY_NEWLINE);
  1021. else
  1022. zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i]));
  1023. }
  1024. return TLV_SIZE (tlvh);
  1025. }
  1026. static u_int16_t
  1027. show_vty_link_subtlv_rmtif_ipaddr (struct vty *vty, struct te_tlv_header *tlvh)
  1028. {
  1029. struct te_link_subtlv_rmtif_ipaddr *top;
  1030. int i, n;
  1031. top = (struct te_link_subtlv_rmtif_ipaddr *) tlvh;
  1032. n = ntohs (tlvh->length) / sizeof (top->value[0]);
  1033. if (vty != NULL)
  1034. vty_out (vty, " Remote Interface IP Address(es): %d%s", n, VTY_NEWLINE);
  1035. else
  1036. zlog_debug (" Remote Interface IP Address(es): %d", n);
  1037. for (i = 0; i < n; i++)
  1038. {
  1039. if (vty != NULL)
  1040. vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]), VTY_NEWLINE);
  1041. else
  1042. zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i]));
  1043. }
  1044. return TLV_SIZE (tlvh);
  1045. }
  1046. static u_int16_t
  1047. show_vty_link_subtlv_te_metric (struct vty *vty, struct te_tlv_header *tlvh)
  1048. {
  1049. struct te_link_subtlv_te_metric *top;
  1050. top = (struct te_link_subtlv_te_metric *) tlvh;
  1051. if (vty != NULL)
  1052. vty_out (vty, " Traffic Engineering Metric: %u%s", (u_int32_t) ntohl (top->value), VTY_NEWLINE);
  1053. else
  1054. zlog_debug (" Traffic Engineering Metric: %u", (u_int32_t) ntohl (top->value));
  1055. return TLV_SIZE (tlvh);
  1056. }
  1057. static u_int16_t
  1058. show_vty_link_subtlv_max_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1059. {
  1060. struct te_link_subtlv_max_bw *top;
  1061. float fval;
  1062. top = (struct te_link_subtlv_max_bw *) tlvh;
  1063. ntohf (&top->value, &fval);
  1064. if (vty != NULL)
  1065. vty_out (vty, " Maximum Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
  1066. else
  1067. zlog_debug (" Maximum Bandwidth: %g (Bytes/sec)", fval);
  1068. return TLV_SIZE (tlvh);
  1069. }
  1070. static u_int16_t
  1071. show_vty_link_subtlv_max_rsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1072. {
  1073. struct te_link_subtlv_max_rsv_bw *top;
  1074. float fval;
  1075. top = (struct te_link_subtlv_max_rsv_bw *) tlvh;
  1076. ntohf (&top->value, &fval);
  1077. if (vty != NULL)
  1078. vty_out (vty, " Maximum Reservable Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
  1079. else
  1080. zlog_debug (" Maximum Reservable Bandwidth: %g (Bytes/sec)", fval);
  1081. return TLV_SIZE (tlvh);
  1082. }
  1083. static u_int16_t
  1084. show_vty_link_subtlv_unrsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1085. {
  1086. struct te_link_subtlv_unrsv_bw *top;
  1087. float fval;
  1088. int i;
  1089. top = (struct te_link_subtlv_unrsv_bw *) tlvh;
  1090. for (i = 0; i < 8; i++)
  1091. {
  1092. ntohf (&top->value[i], &fval);
  1093. if (vty != NULL)
  1094. vty_out (vty, " Unreserved Bandwidth (pri %d): %g (Bytes/sec)%s", i, fval, VTY_NEWLINE);
  1095. else
  1096. zlog_debug (" Unreserved Bandwidth (pri %d): %g (Bytes/sec)", i, fval);
  1097. }
  1098. return TLV_SIZE (tlvh);
  1099. }
  1100. static u_int16_t
  1101. show_vty_link_subtlv_rsc_clsclr (struct vty *vty, struct te_tlv_header *tlvh)
  1102. {
  1103. struct te_link_subtlv_rsc_clsclr *top;
  1104. top = (struct te_link_subtlv_rsc_clsclr *) tlvh;
  1105. if (vty != NULL)
  1106. vty_out (vty, " Resource class/color: 0x%x%s", (u_int32_t) ntohl (top->value), VTY_NEWLINE);
  1107. else
  1108. zlog_debug (" Resource Class/Color: 0x%x", (u_int32_t) ntohl (top->value));
  1109. return TLV_SIZE (tlvh);
  1110. }
  1111. static u_int16_t
  1112. show_vty_unknown_tlv (struct vty *vty, struct te_tlv_header *tlvh)
  1113. {
  1114. if (vty != NULL)
  1115. vty_out (vty, " Unknown TLV: [type(0x%x), length(0x%x)]%s", ntohs (tlvh->type), ntohs (tlvh->length), VTY_NEWLINE);
  1116. else
  1117. zlog_debug (" Unknown TLV: [type(0x%x), length(0x%x)]", ntohs (tlvh->type), ntohs (tlvh->length));
  1118. return TLV_SIZE (tlvh);
  1119. }
  1120. static u_int16_t
  1121. ospf_mpls_te_show_link_subtlv (struct vty *vty, struct te_tlv_header *tlvh0,
  1122. u_int16_t subtotal, u_int16_t total)
  1123. {
  1124. struct te_tlv_header *tlvh, *next;
  1125. u_int16_t sum = subtotal;
  1126. for (tlvh = tlvh0; sum < total; tlvh = (next ? next : TLV_HDR_NEXT (tlvh)))
  1127. {
  1128. next = NULL;
  1129. switch (ntohs (tlvh->type))
  1130. {
  1131. case TE_LINK_SUBTLV_LINK_TYPE:
  1132. sum += show_vty_link_subtlv_link_type (vty, tlvh);
  1133. break;
  1134. case TE_LINK_SUBTLV_LINK_ID:
  1135. sum += show_vty_link_subtlv_link_id (vty, tlvh);
  1136. break;
  1137. case TE_LINK_SUBTLV_LCLIF_IPADDR:
  1138. sum += show_vty_link_subtlv_lclif_ipaddr (vty, tlvh);
  1139. break;
  1140. case TE_LINK_SUBTLV_RMTIF_IPADDR:
  1141. sum += show_vty_link_subtlv_rmtif_ipaddr (vty, tlvh);
  1142. break;
  1143. case TE_LINK_SUBTLV_TE_METRIC:
  1144. sum += show_vty_link_subtlv_te_metric (vty, tlvh);
  1145. break;
  1146. case TE_LINK_SUBTLV_MAX_BW:
  1147. sum += show_vty_link_subtlv_max_bw (vty, tlvh);
  1148. break;
  1149. case TE_LINK_SUBTLV_MAX_RSV_BW:
  1150. sum += show_vty_link_subtlv_max_rsv_bw (vty, tlvh);
  1151. break;
  1152. case TE_LINK_SUBTLV_UNRSV_BW:
  1153. sum += show_vty_link_subtlv_unrsv_bw (vty, tlvh);
  1154. break;
  1155. case TE_LINK_SUBTLV_RSC_CLSCLR:
  1156. sum += show_vty_link_subtlv_rsc_clsclr (vty, tlvh);
  1157. break;
  1158. default:
  1159. sum += show_vty_unknown_tlv (vty, tlvh);
  1160. break;
  1161. }
  1162. }
  1163. return sum;
  1164. }
  1165. static void
  1166. ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa)
  1167. {
  1168. struct lsa_header *lsah = (struct lsa_header *) lsa->data;
  1169. struct te_tlv_header *tlvh, *next;
  1170. u_int16_t sum, total;
  1171. u_int16_t (* subfunc)(struct vty *vty, struct te_tlv_header *tlvh,
  1172. u_int16_t subtotal, u_int16_t total) = NULL;
  1173. sum = 0;
  1174. total = ntohs (lsah->length) - OSPF_LSA_HEADER_SIZE;
  1175. for (tlvh = TLV_HDR_TOP (lsah); sum < total;
  1176. tlvh = (next ? next : TLV_HDR_NEXT (tlvh)))
  1177. {
  1178. if (subfunc != NULL)
  1179. {
  1180. sum = (* subfunc)(vty, tlvh, sum, total);
  1181. next = (struct te_tlv_header *)((char *) tlvh + sum);
  1182. subfunc = NULL;
  1183. continue;
  1184. }
  1185. next = NULL;
  1186. switch (ntohs (tlvh->type))
  1187. {
  1188. case TE_TLV_ROUTER_ADDR:
  1189. sum += show_vty_router_addr (vty, tlvh);
  1190. break;
  1191. case TE_TLV_LINK:
  1192. sum += show_vty_link_header (vty, tlvh);
  1193. subfunc = ospf_mpls_te_show_link_subtlv;
  1194. next = tlvh + 1;
  1195. break;
  1196. default:
  1197. sum += show_vty_unknown_tlv (vty, tlvh);
  1198. break;
  1199. }
  1200. }
  1201. return;
  1202. }
  1203. static void
  1204. ospf_mpls_te_config_write_router (struct vty *vty)
  1205. {
  1206. if (OspfMplsTE.status == enabled)
  1207. {
  1208. vty_out (vty, " mpls-te%s", VTY_NEWLINE);
  1209. vty_out (vty, " mpls-te router-address %s%s",
  1210. inet_ntoa (OspfMplsTE.router_addr.value), VTY_NEWLINE);
  1211. }
  1212. return;
  1213. }
  1214. static void
  1215. ospf_mpls_te_config_write_if (struct vty *vty, struct interface *ifp)
  1216. {
  1217. struct mpls_te_link *lp;
  1218. if ((OspfMplsTE.status == enabled)
  1219. && (! if_is_loopback (ifp) && if_is_up (ifp) && ospf_oi_count (ifp) > 0)
  1220. && ((lp = lookup_linkparams_by_ifp (ifp)) != NULL))
  1221. {
  1222. float fval;
  1223. int i;
  1224. vty_out (vty, " mpls-te link metric %u%s",
  1225. (u_int32_t) ntohl (lp->te_metric.value), VTY_NEWLINE);
  1226. ntohf (&lp->max_bw.value, &fval);
  1227. if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
  1228. vty_out (vty, " mpls-te link max-bw %g%s", fval, VTY_NEWLINE);
  1229. ntohf (&lp->max_rsv_bw.value, &fval);
  1230. if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
  1231. vty_out (vty, " mpls-te link max-rsv-bw %g%s", fval, VTY_NEWLINE);
  1232. for (i = 0; i < 8; i++)
  1233. {
  1234. ntohf (&lp->unrsv_bw.value[i], &fval);
  1235. if (fval >= MPLS_TE_MINIMUM_BANDWIDTH)
  1236. vty_out (vty, " mpls-te link unrsv-bw %d %g%s",
  1237. i, fval, VTY_NEWLINE);
  1238. }
  1239. vty_out (vty, " mpls-te link rsc-clsclr 0x%x%s",
  1240. (u_int32_t) ntohl (lp->rsc_clsclr.value), VTY_NEWLINE);
  1241. }
  1242. return;
  1243. }
  1244. /*------------------------------------------------------------------------*
  1245. * Followings are vty command functions.
  1246. *------------------------------------------------------------------------*/
  1247. DEFUN (mpls_te,
  1248. mpls_te_cmd,
  1249. "mpls-te",
  1250. "Configure MPLS-TE parameters\n"
  1251. "Enable the MPLS-TE functionality\n")
  1252. {
  1253. struct listnode *node, *nnode;
  1254. struct mpls_te_link *lp;
  1255. if (OspfMplsTE.status == enabled)
  1256. return CMD_SUCCESS;
  1257. if (IS_DEBUG_OSPF_EVENT)
  1258. zlog_debug ("MPLS-TE: OFF -> ON");
  1259. OspfMplsTE.status = enabled;
  1260. /*
  1261. * Following code is intended to handle two cases;
  1262. *
  1263. * 1) MPLS-TE was disabled at startup time, but now become enabled.
  1264. * 2) MPLS-TE was once enabled then disabled, and now enabled again.
  1265. */
  1266. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1267. initialize_linkparams (lp);
  1268. ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule, REORIGINATE_PER_AREA);
  1269. return CMD_SUCCESS;
  1270. }
  1271. ALIAS (mpls_te,
  1272. mpls_te_on_cmd,
  1273. "mpls-te on",
  1274. "Configure MPLS-TE parameters\n"
  1275. "Enable the MPLS-TE functionality\n")
  1276. DEFUN (no_mpls_te,
  1277. no_mpls_te_cmd,
  1278. "no mpls-te",
  1279. NO_STR
  1280. "Configure MPLS-TE parameters\n"
  1281. "Disable the MPLS-TE functionality\n")
  1282. {
  1283. struct listnode *node, *nnode;
  1284. struct mpls_te_link *lp;
  1285. if (OspfMplsTE.status == disabled)
  1286. return CMD_SUCCESS;
  1287. if (IS_DEBUG_OSPF_EVENT)
  1288. zlog_debug ("MPLS-TE: ON -> OFF");
  1289. OspfMplsTE.status = disabled;
  1290. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1291. if (lp->area != NULL)
  1292. if (lp->flags & LPFLG_LSA_ENGAGED)
  1293. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  1294. return CMD_SUCCESS;
  1295. }
  1296. DEFUN (mpls_te_router_addr,
  1297. mpls_te_router_addr_cmd,
  1298. "mpls-te router-address A.B.C.D",
  1299. "MPLS-TE specific commands\n"
  1300. "Stable IP address of the advertising router\n"
  1301. "MPLS-TE router address in IPv4 address format\n")
  1302. {
  1303. struct te_tlv_router_addr *ra = &OspfMplsTE.router_addr;
  1304. struct in_addr value;
  1305. if (! inet_aton (argv[0], &value))
  1306. {
  1307. vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE);
  1308. return CMD_WARNING;
  1309. }
  1310. if (ntohs (ra->header.type) == 0
  1311. || ntohl (ra->value.s_addr) != ntohl (value.s_addr))
  1312. {
  1313. struct listnode *node, *nnode;
  1314. struct mpls_te_link *lp;
  1315. int need_to_reoriginate = 0;
  1316. set_mpls_te_router_addr (value);
  1317. if (OspfMplsTE.status == disabled)
  1318. goto out;
  1319. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1320. {
  1321. if (lp->area == NULL)
  1322. continue;
  1323. if ((lp->flags & LPFLG_LSA_ENGAGED) == 0)
  1324. {
  1325. need_to_reoriginate = 1;
  1326. break;
  1327. }
  1328. }
  1329. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1330. {
  1331. if (lp->area == NULL)
  1332. continue;
  1333. if (need_to_reoriginate)
  1334. lp->flags |= LPFLG_LSA_FORCED_REFRESH;
  1335. else
  1336. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1337. }
  1338. if (need_to_reoriginate)
  1339. ospf_mpls_te_foreach_area (
  1340. ospf_mpls_te_lsa_schedule, REORIGINATE_PER_AREA);
  1341. }
  1342. out:
  1343. return CMD_SUCCESS;
  1344. }
  1345. DEFUN (mpls_te_link_metric,
  1346. mpls_te_link_metric_cmd,
  1347. "mpls-te link metric <0-4294967295>",
  1348. "MPLS-TE specific commands\n"
  1349. "Configure MPLS-TE link parameters\n"
  1350. "Link metric for MPLS-TE purpose\n"
  1351. "Metric\n")
  1352. {
  1353. struct interface *ifp = (struct interface *) vty->index;
  1354. struct mpls_te_link *lp;
  1355. u_int32_t value;
  1356. if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
  1357. {
  1358. vty_out (vty, "mpls_te_link_metric: Something wrong!%s", VTY_NEWLINE);
  1359. return CMD_WARNING;
  1360. }
  1361. value = strtoul (argv[0], NULL, 10);
  1362. if (ntohs (lp->te_metric.header.type) == 0
  1363. || ntohl (lp->te_metric.value) != value)
  1364. {
  1365. set_linkparams_te_metric (lp, value);
  1366. if (OspfMplsTE.status == enabled)
  1367. if (lp->area != NULL)
  1368. {
  1369. if (lp->flags & LPFLG_LSA_ENGAGED)
  1370. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1371. else
  1372. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
  1373. }
  1374. }
  1375. return CMD_SUCCESS;
  1376. }
  1377. DEFUN (mpls_te_link_maxbw,
  1378. mpls_te_link_maxbw_cmd,
  1379. "mpls-te link max-bw BANDWIDTH",
  1380. "MPLS-TE specific commands\n"
  1381. "Configure MPLS-TE link parameters\n"
  1382. "Maximum bandwidth that can be used\n"
  1383. "Bytes/second (IEEE floating point format)\n")
  1384. {
  1385. struct interface *ifp = (struct interface *) vty->index;
  1386. struct mpls_te_link *lp;
  1387. float f1, f2;
  1388. if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
  1389. {
  1390. vty_out (vty, "mpls_te_link_maxbw: Something wrong!%s", VTY_NEWLINE);
  1391. return CMD_WARNING;
  1392. }
  1393. ntohf (&lp->max_bw.value, &f1);
  1394. if (sscanf (argv[0], "%g", &f2) != 1)
  1395. {
  1396. vty_out (vty, "mpls_te_link_maxbw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
  1397. return CMD_WARNING;
  1398. }
  1399. if (ntohs (lp->max_bw.header.type) == 0
  1400. || f1 != f2)
  1401. {
  1402. set_linkparams_max_bw (lp, &f2);
  1403. if (OspfMplsTE.status == enabled)
  1404. if (lp->area != NULL)
  1405. {
  1406. if (lp->flags & LPFLG_LSA_ENGAGED)
  1407. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1408. else
  1409. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
  1410. }
  1411. }
  1412. return CMD_SUCCESS;
  1413. }
  1414. DEFUN (mpls_te_link_max_rsv_bw,
  1415. mpls_te_link_max_rsv_bw_cmd,
  1416. "mpls-te link max-rsv-bw BANDWIDTH",
  1417. "MPLS-TE specific commands\n"
  1418. "Configure MPLS-TE link parameters\n"
  1419. "Maximum bandwidth that may be reserved\n"
  1420. "Bytes/second (IEEE floating point format)\n")
  1421. {
  1422. struct interface *ifp = (struct interface *) vty->index;
  1423. struct mpls_te_link *lp;
  1424. float f1, f2;
  1425. if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
  1426. {
  1427. vty_out (vty, "mpls_te_link_max_rsv_bw: Something wrong!%s", VTY_NEWLINE);
  1428. return CMD_WARNING;
  1429. }
  1430. ntohf (&lp->max_rsv_bw.value, &f1);
  1431. if (sscanf (argv[0], "%g", &f2) != 1)
  1432. {
  1433. vty_out (vty, "mpls_te_link_max_rsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
  1434. return CMD_WARNING;
  1435. }
  1436. if (ntohs (lp->max_rsv_bw.header.type) == 0
  1437. || f1 != f2)
  1438. {
  1439. set_linkparams_max_rsv_bw (lp, &f2);
  1440. if (OspfMplsTE.status == enabled)
  1441. if (lp->area != NULL)
  1442. {
  1443. if (lp->flags & LPFLG_LSA_ENGAGED)
  1444. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1445. else
  1446. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
  1447. }
  1448. }
  1449. return CMD_SUCCESS;
  1450. }
  1451. DEFUN (mpls_te_link_unrsv_bw,
  1452. mpls_te_link_unrsv_bw_cmd,
  1453. "mpls-te link unrsv-bw <0-7> BANDWIDTH",
  1454. "MPLS-TE specific commands\n"
  1455. "Configure MPLS-TE link parameters\n"
  1456. "Unreserved bandwidth at each priority level\n"
  1457. "Priority\n"
  1458. "Bytes/second (IEEE floating point format)\n")
  1459. {
  1460. struct interface *ifp = (struct interface *) vty->index;
  1461. struct mpls_te_link *lp;
  1462. int priority;
  1463. float f1, f2;
  1464. if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
  1465. {
  1466. vty_out (vty, "mpls_te_link_unrsv_bw: Something wrong!%s", VTY_NEWLINE);
  1467. return CMD_WARNING;
  1468. }
  1469. /* We don't have to consider about range check here. */
  1470. if (sscanf (argv[0], "%d", &priority) != 1)
  1471. {
  1472. vty_out (vty, "mpls_te_link_unrsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
  1473. return CMD_WARNING;
  1474. }
  1475. ntohf (&lp->unrsv_bw.value [priority], &f1);
  1476. if (sscanf (argv[1], "%g", &f2) != 1)
  1477. {
  1478. vty_out (vty, "mpls_te_link_unrsv_bw: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
  1479. return CMD_WARNING;
  1480. }
  1481. if (ntohs (lp->unrsv_bw.header.type) == 0
  1482. || f1 != f2)
  1483. {
  1484. set_linkparams_unrsv_bw (lp, priority, &f2);
  1485. if (OspfMplsTE.status == enabled)
  1486. if (lp->area != NULL)
  1487. {
  1488. if (lp->flags & LPFLG_LSA_ENGAGED)
  1489. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1490. else
  1491. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
  1492. }
  1493. }
  1494. return CMD_SUCCESS;
  1495. }
  1496. DEFUN (mpls_te_link_rsc_clsclr,
  1497. mpls_te_link_rsc_clsclr_cmd,
  1498. "mpls-te link rsc-clsclr BITPATTERN",
  1499. "MPLS-TE specific commands\n"
  1500. "Configure MPLS-TE link parameters\n"
  1501. "Administrative group membership\n"
  1502. "32-bit Hexadecimal value (ex. 0xa1)\n")
  1503. {
  1504. struct interface *ifp = (struct interface *) vty->index;
  1505. struct mpls_te_link *lp;
  1506. unsigned long value;
  1507. if ((lp = lookup_linkparams_by_ifp (ifp)) == NULL)
  1508. {
  1509. vty_out (vty, "mpls_te_link_rsc_clsclr: Something wrong!%s", VTY_NEWLINE);
  1510. return CMD_WARNING;
  1511. }
  1512. if (sscanf (argv[0], "0x%lx", &value) != 1)
  1513. {
  1514. vty_out (vty, "mpls_te_link_rsc_clsclr: fscanf: %s%s", safe_strerror (errno), VTY_NEWLINE);
  1515. return CMD_WARNING;
  1516. }
  1517. if (ntohs (lp->rsc_clsclr.header.type) == 0
  1518. || ntohl (lp->rsc_clsclr.value) != value)
  1519. {
  1520. set_linkparams_rsc_clsclr (lp, value);
  1521. if (OspfMplsTE.status == enabled)
  1522. if (lp->area != NULL)
  1523. {
  1524. if (lp->flags & LPFLG_LSA_ENGAGED)
  1525. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1526. else
  1527. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_PER_AREA);
  1528. }
  1529. }
  1530. return CMD_SUCCESS;
  1531. }
  1532. DEFUN (show_mpls_te_router,
  1533. show_mpls_te_router_cmd,
  1534. "show mpls-te router",
  1535. SHOW_STR
  1536. "MPLS-TE information\n"
  1537. "Router information\n")
  1538. {
  1539. if (OspfMplsTE.status == enabled)
  1540. {
  1541. vty_out (vty, "--- MPLS-TE router parameters ---%s",
  1542. VTY_NEWLINE);
  1543. if (ntohs (OspfMplsTE.router_addr.header.type) != 0)
  1544. show_vty_router_addr (vty, &OspfMplsTE.router_addr.header);
  1545. else if (vty != NULL)
  1546. vty_out (vty, " N/A%s", VTY_NEWLINE);
  1547. }
  1548. return CMD_SUCCESS;
  1549. }
  1550. static void
  1551. show_mpls_te_link_sub (struct vty *vty, struct interface *ifp)
  1552. {
  1553. struct mpls_te_link *lp;
  1554. struct te_tlv_header *tlvh;
  1555. if ((OspfMplsTE.status == enabled)
  1556. && (! if_is_loopback (ifp) && if_is_up (ifp) && ospf_oi_count (ifp) > 0)
  1557. && ((lp = lookup_linkparams_by_ifp (ifp)) != NULL))
  1558. {
  1559. vty_out (vty, "-- MPLS-TE link parameters for %s --%s",
  1560. ifp->name, VTY_NEWLINE);
  1561. show_vty_link_subtlv_link_type (vty, &lp->link_type.header);
  1562. show_vty_link_subtlv_link_id (vty, &lp->link_id.header);
  1563. if ((tlvh = (struct te_tlv_header *) lp->lclif_ipaddr) != NULL)
  1564. show_vty_link_subtlv_lclif_ipaddr (vty, tlvh);
  1565. if ((tlvh = (struct te_tlv_header *) lp->rmtif_ipaddr) != NULL)
  1566. show_vty_link_subtlv_rmtif_ipaddr (vty, tlvh);
  1567. show_vty_link_subtlv_te_metric (vty, &lp->te_metric.header);
  1568. show_vty_link_subtlv_max_bw (vty, &lp->max_bw.header);
  1569. show_vty_link_subtlv_max_rsv_bw (vty, &lp->max_rsv_bw.header);
  1570. show_vty_link_subtlv_unrsv_bw (vty, &lp->unrsv_bw.header);
  1571. show_vty_link_subtlv_rsc_clsclr (vty, &lp->rsc_clsclr.header);
  1572. }
  1573. else
  1574. {
  1575. vty_out (vty, " %s: MPLS-TE is disabled on this interface%s",
  1576. ifp->name, VTY_NEWLINE);
  1577. }
  1578. return;
  1579. }
  1580. DEFUN (show_mpls_te_link,
  1581. show_mpls_te_link_cmd,
  1582. "show mpls-te interface [INTERFACE]",
  1583. SHOW_STR
  1584. "MPLS-TE information\n"
  1585. "Interface information\n"
  1586. "Interface name\n")
  1587. {
  1588. struct interface *ifp;
  1589. struct listnode *node, *nnode;
  1590. /* Show All Interfaces. */
  1591. if (argc == 0)
  1592. {
  1593. for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
  1594. show_mpls_te_link_sub (vty, ifp);
  1595. }
  1596. /* Interface name is specified. */
  1597. else
  1598. {
  1599. if ((ifp = if_lookup_by_name (argv[0])) == NULL)
  1600. vty_out (vty, "No such interface name%s", VTY_NEWLINE);
  1601. else
  1602. show_mpls_te_link_sub (vty, ifp);
  1603. }
  1604. return CMD_SUCCESS;
  1605. }
  1606. static void
  1607. ospf_mpls_te_register_vty (void)
  1608. {
  1609. install_element (VIEW_NODE, &show_mpls_te_router_cmd);
  1610. install_element (VIEW_NODE, &show_mpls_te_link_cmd);
  1611. install_element (ENABLE_NODE, &show_mpls_te_router_cmd);
  1612. install_element (ENABLE_NODE, &show_mpls_te_link_cmd);
  1613. install_element (OSPF_NODE, &mpls_te_cmd);
  1614. install_element (OSPF_NODE, &no_mpls_te_cmd);
  1615. install_element (OSPF_NODE, &mpls_te_on_cmd);
  1616. install_element (OSPF_NODE, &mpls_te_router_addr_cmd);
  1617. install_element (INTERFACE_NODE, &mpls_te_link_metric_cmd);
  1618. install_element (INTERFACE_NODE, &mpls_te_link_maxbw_cmd);
  1619. install_element (INTERFACE_NODE, &mpls_te_link_max_rsv_bw_cmd);
  1620. install_element (INTERFACE_NODE, &mpls_te_link_unrsv_bw_cmd);
  1621. install_element (INTERFACE_NODE, &mpls_te_link_rsc_clsclr_cmd);
  1622. return;
  1623. }
  1624. #endif /* HAVE_OSPF_TE */