ospf_te.c 52 KB

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