ospf_te.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639
  1. /*
  2. * This is an implementation of RFC3630
  3. * Copyright (C) 2001 KDD R&D Laboratories, Inc.
  4. * http://www.kddlabs.co.jp/
  5. *
  6. * Copyright (C) 2012 Orange Labs
  7. * http://www.orange.com
  8. *
  9. * This file is part of GNU Zebra.
  10. *
  11. * GNU Zebra is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2, or (at your option) any
  14. * later version.
  15. *
  16. * GNU Zebra is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  23. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. * 02111-1307, USA.
  25. */
  26. /* Add support of RFC7471 */
  27. /* Add support of RFC5392, RFC6827 */
  28. #include <zebra.h>
  29. #include <math.h>
  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 "network.h"
  43. #include "ospfd/ospfd.h"
  44. #include "ospfd/ospf_interface.h"
  45. #include "ospfd/ospf_ism.h"
  46. #include "ospfd/ospf_asbr.h"
  47. #include "ospfd/ospf_lsa.h"
  48. #include "ospfd/ospf_lsdb.h"
  49. #include "ospfd/ospf_neighbor.h"
  50. #include "ospfd/ospf_nsm.h"
  51. #include "ospfd/ospf_flood.h"
  52. #include "ospfd/ospf_packet.h"
  53. #include "ospfd/ospf_spf.h"
  54. #include "ospfd/ospf_dump.h"
  55. #include "ospfd/ospf_route.h"
  56. #include "ospfd/ospf_ase.h"
  57. #include "ospfd/ospf_zebra.h"
  58. #include "ospfd/ospf_te.h"
  59. #include "ospfd/ospf_vty.h"
  60. /*
  61. * Global variable to manage Opaque-LSA/MPLS-TE on this node.
  62. * Note that all parameter values are stored in network byte order.
  63. */
  64. struct ospf_mpls_te OspfMplsTE;
  65. const char *mode2text[] = { "Disable", "AS", "Area", "Emulate" };
  66. enum oifstate
  67. {
  68. OI_ANY, OI_DOWN, OI_UP
  69. };
  70. /*------------------------------------------------------------------------*
  71. * Followings are initialize/terminate functions for MPLS-TE handling.
  72. *------------------------------------------------------------------------*/
  73. static int ospf_mpls_te_new_if (struct interface *ifp);
  74. static int ospf_mpls_te_del_if (struct interface *ifp);
  75. static void ospf_mpls_te_ism_change (struct ospf_interface *oi,
  76. int old_status);
  77. static void ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_status);
  78. static void ospf_mpls_te_config_write_router (struct vty *vty);
  79. static void ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa);
  80. static int ospf_mpls_te_lsa_originate_area (void *arg);
  81. static int ospf_mpls_te_lsa_originate_as (void *arg);
  82. static struct ospf_lsa *ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa);
  83. static void del_mpls_te_link (void *val);
  84. static void ospf_mpls_te_register_vty (void);
  85. int
  86. ospf_mpls_te_init (void)
  87. {
  88. int rc;
  89. rc = ospf_register_opaque_functab (
  90. OSPF_OPAQUE_AREA_LSA,
  91. OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
  92. ospf_mpls_te_new_if,
  93. ospf_mpls_te_del_if,
  94. ospf_mpls_te_ism_change,
  95. ospf_mpls_te_nsm_change,
  96. ospf_mpls_te_config_write_router,
  97. NULL,/*ospf_mpls_te_config_write_if */
  98. NULL,/* ospf_mpls_te_config_write_debug */
  99. ospf_mpls_te_show_info,
  100. ospf_mpls_te_lsa_originate_area,
  101. ospf_mpls_te_lsa_refresh,
  102. NULL,/* ospf_mpls_te_new_lsa_hook */
  103. NULL /* ospf_mpls_te_del_lsa_hook */);
  104. if (rc != 0)
  105. {
  106. zlog_warn ("ospf_mpls_te_init: Failed to register Traffic Engineering functions");
  107. goto out;
  108. }
  109. memset (&OspfMplsTE, 0, sizeof (struct ospf_mpls_te));
  110. OspfMplsTE.status = disabled;
  111. OspfMplsTE.inter_as = Disable;
  112. OspfMplsTE.iflist = list_new ();
  113. OspfMplsTE.iflist->del = del_mpls_te_link;
  114. ospf_mpls_te_register_vty ();
  115. out:
  116. return rc;
  117. }
  118. /* Additional register for RFC5392 support */
  119. static int
  120. ospf_mpls_te_register (enum inter_as_mode mode)
  121. {
  122. int rc;
  123. u_int8_t scope;
  124. if (OspfMplsTE.inter_as != Disable)
  125. return 0;
  126. if (mode == AS)
  127. scope = OSPF_OPAQUE_AS_LSA;
  128. else
  129. scope = OSPF_OPAQUE_AREA_LSA;
  130. rc = ospf_register_opaque_functab (scope,
  131. OPAQUE_TYPE_INTER_AS_LSA,
  132. NULL,
  133. NULL,
  134. NULL,
  135. NULL,
  136. NULL,
  137. NULL,
  138. NULL,
  139. ospf_mpls_te_show_info,
  140. ospf_mpls_te_lsa_originate_as,
  141. ospf_mpls_te_lsa_refresh, NULL, NULL);
  142. if (rc != 0)
  143. {
  144. zlog_warn ("ospf_router_info_init: Failed to register Inter-AS functions");
  145. return rc;
  146. }
  147. return 0;
  148. }
  149. static int
  150. ospf_mpls_te_unregister ()
  151. {
  152. u_int8_t scope;
  153. if (OspfMplsTE.inter_as == Disable)
  154. return 0;
  155. if (OspfMplsTE.inter_as == AS)
  156. scope = OSPF_OPAQUE_AS_LSA;
  157. else
  158. scope = OSPF_OPAQUE_AREA_LSA;
  159. ospf_delete_opaque_functab (scope, OPAQUE_TYPE_INTER_AS_LSA);
  160. return 0;
  161. }
  162. void
  163. ospf_mpls_te_term (void)
  164. {
  165. list_delete (OspfMplsTE.iflist);
  166. OspfMplsTE.iflist = NULL;
  167. ospf_delete_opaque_functab (OSPF_OPAQUE_AREA_LSA,
  168. OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
  169. OspfMplsTE.status = disabled;
  170. ospf_mpls_te_unregister ();
  171. OspfMplsTE.inter_as = Disable;
  172. return;
  173. }
  174. /*------------------------------------------------------------------------*
  175. * Followings are control functions for MPLS-TE parameters management.
  176. *------------------------------------------------------------------------*/
  177. static void
  178. del_mpls_te_link (void *val)
  179. {
  180. XFREE (MTYPE_OSPF_MPLS_TE, val);
  181. return;
  182. }
  183. u_int32_t
  184. get_mpls_te_instance_value (void)
  185. {
  186. static u_int32_t seqno = 0;
  187. if (seqno < MAX_LEGAL_TE_INSTANCE_NUM )
  188. seqno += 1;
  189. else
  190. seqno = 1; /* Avoid zero. */
  191. return seqno;
  192. }
  193. static struct ospf_interface *
  194. lookup_oi_by_ifp (struct interface *ifp,
  195. struct ospf_area *area, enum oifstate oifstate)
  196. {
  197. struct ospf_interface *oi = NULL;
  198. struct route_node *rn;
  199. for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
  200. {
  201. if ((oi = rn->info) == NULL)
  202. continue;
  203. switch (oifstate)
  204. {
  205. case OI_ANY:
  206. break;
  207. case OI_DOWN:
  208. if (ospf_if_is_enable (oi))
  209. continue;
  210. break;
  211. case OI_UP:
  212. if (! ospf_if_is_enable (oi))
  213. continue;
  214. break;
  215. default:
  216. zlog_warn ("lookup_oi_by_ifp: Unknown oifstate: %x", oifstate);
  217. goto out;
  218. }
  219. if (area == NULL || oi->area == area)
  220. return oi;
  221. }
  222. out:
  223. return NULL;
  224. }
  225. static struct mpls_te_link *
  226. lookup_linkparams_by_ifp (struct interface *ifp)
  227. {
  228. struct listnode *node, *nnode;
  229. struct mpls_te_link *lp;
  230. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  231. if (lp->ifp == ifp)
  232. return lp;
  233. return NULL;
  234. }
  235. static struct mpls_te_link *
  236. lookup_linkparams_by_instance (struct ospf_lsa *lsa)
  237. {
  238. struct listnode *node;
  239. struct mpls_te_link *lp;
  240. unsigned int key = GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr));
  241. for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
  242. if (lp->instance == key)
  243. return lp;
  244. zlog_warn ("lookup_linkparams_by_instance: Entry not found: key(%x)", key);
  245. return NULL;
  246. }
  247. static void
  248. ospf_mpls_te_foreach_area (void (*func)
  249. (struct mpls_te_link * lp, opcode_t sched_opcode),
  250. opcode_t sched_opcode)
  251. {
  252. struct listnode *node, *nnode;
  253. struct listnode *node2;
  254. struct mpls_te_link *lp;
  255. struct ospf_area *area;
  256. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  257. {
  258. /* Skip Inter-AS TEv2 Links */
  259. if (IS_INTER_AS (lp->type))
  260. continue;
  261. if ((area = lp->area) == NULL)
  262. continue;
  263. if CHECK_FLAG (lp->flags, LPFLG_LOOKUP_DONE) continue;
  264. if (func != NULL)
  265. (* func)(lp, sched_opcode);
  266. for (node2 = listnextnode (node); node2; node2 = listnextnode (node2))
  267. if ((lp = listgetdata (node2)) != NULL)
  268. if (lp->area != NULL)
  269. if (IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id))
  270. SET_FLAG (lp->flags, LPFLG_LOOKUP_DONE);
  271. }
  272. for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
  273. if (lp->area != NULL)
  274. UNSET_FLAG (lp->flags, LPFLG_LOOKUP_DONE);
  275. return;
  276. }
  277. static void
  278. set_mpls_te_router_addr (struct in_addr ipv4)
  279. {
  280. OspfMplsTE.router_addr.header.type = htons (TE_TLV_ROUTER_ADDR);
  281. OspfMplsTE.router_addr.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  282. OspfMplsTE.router_addr.value = ipv4;
  283. return;
  284. }
  285. static void
  286. set_linkparams_link_header (struct mpls_te_link *lp)
  287. {
  288. u_int16_t length = 0;
  289. /* TE_LINK_SUBTLV_LINK_TYPE */
  290. if (ntohs (lp->link_type.header.type) != 0)
  291. length += TLV_SIZE (&lp->link_type.header);
  292. /* TE_LINK_SUBTLV_LINK_ID */
  293. if (ntohs (lp->link_id.header.type) != 0)
  294. length += TLV_SIZE (&lp->link_id.header);
  295. /* TE_LINK_SUBTLV_LCLIF_IPADDR */
  296. if (lp->lclif_ipaddr.header.type != 0)
  297. length += TLV_SIZE (&lp->lclif_ipaddr.header);
  298. /* TE_LINK_SUBTLV_RMTIF_IPADDR */
  299. if (lp->rmtif_ipaddr.header.type != 0)
  300. length += TLV_SIZE (&lp->rmtif_ipaddr.header);
  301. /* TE_LINK_SUBTLV_TE_METRIC */
  302. if (ntohs (lp->te_metric.header.type) != 0)
  303. length += TLV_SIZE (&lp->te_metric.header);
  304. /* TE_LINK_SUBTLV_MAX_BW */
  305. if (ntohs (lp->max_bw.header.type) != 0)
  306. length += TLV_SIZE (&lp->max_bw.header);
  307. /* TE_LINK_SUBTLV_MAX_RSV_BW */
  308. if (ntohs (lp->max_rsv_bw.header.type) != 0)
  309. length += TLV_SIZE (&lp->max_rsv_bw.header);
  310. /* TE_LINK_SUBTLV_UNRSV_BW */
  311. if (ntohs (lp->unrsv_bw.header.type) != 0)
  312. length += TLV_SIZE (&lp->unrsv_bw.header);
  313. /* TE_LINK_SUBTLV_RSC_CLSCLR */
  314. if (ntohs (lp->rsc_clsclr.header.type) != 0)
  315. length += TLV_SIZE (&lp->rsc_clsclr.header);
  316. /* TE_LINK_SUBTLV_LLRI */
  317. if (ntohs (lp->llri.header.type) != 0)
  318. length += TLV_SIZE (&lp->llri.header);
  319. /* TE_LINK_SUBTLV_RIP */
  320. if (ntohs (lp->rip.header.type) != 0)
  321. length += TLV_SIZE (&lp->rip.header);
  322. /* TE_LINK_SUBTLV_RAS */
  323. if (ntohs (lp->ras.header.type) != 0)
  324. length += TLV_SIZE (&lp->ras.header);
  325. /* TE_LINK_SUBTLV_LRRID */
  326. if (ntohs (lp->lrrid.header.type) != 0)
  327. length += TLV_SIZE (&lp->lrrid.header);
  328. /* TE_LINK_SUBTLV_AV_DELAY */
  329. if (ntohs (lp->av_delay.header.type) != 0)
  330. length += TLV_SIZE (&lp->av_delay.header);
  331. /* TE_LINK_SUBTLV_MM_DELAY */
  332. if (ntohs (lp->mm_delay.header.type) != 0)
  333. length += TLV_SIZE (&lp->mm_delay.header);
  334. /* TE_LINK_SUBTLV_DELAY_VAR */
  335. if (ntohs (lp->delay_var.header.type) != 0)
  336. length += TLV_SIZE (&lp->delay_var.header);
  337. /* TE_LINK_SUBTLV_PKT_LOSS */
  338. if (ntohs (lp->pkt_loss.header.type) != 0)
  339. length += TLV_SIZE (&lp->pkt_loss.header);
  340. /* TE_LINK_SUBTLV_RES_BW */
  341. if (ntohs (lp->res_bw.header.type) != 0)
  342. length += TLV_SIZE (&lp->res_bw.header);
  343. /* TE_LINK_SUBTLV_AVA_BW */
  344. if (ntohs (lp->ava_bw.header.type) != 0)
  345. length += TLV_SIZE (&lp->ava_bw.header);
  346. /* TE_LINK_SUBTLV_USE_BW */
  347. if (ntohs (lp->use_bw.header.type) != 0)
  348. length += TLV_SIZE (&lp->use_bw.header);
  349. lp->link_header.header.type = htons (TE_TLV_LINK);
  350. lp->link_header.header.length = htons (length);
  351. return;
  352. }
  353. static void
  354. set_linkparams_link_type (struct ospf_interface *oi, struct mpls_te_link *lp)
  355. {
  356. lp->link_type.header.type = htons (TE_LINK_SUBTLV_LINK_TYPE);
  357. lp->link_type.header.length = htons (TE_LINK_SUBTLV_TYPE_SIZE);
  358. switch (oi->type)
  359. {
  360. case OSPF_IFTYPE_POINTOPOINT:
  361. lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_PTP;
  362. break;
  363. case OSPF_IFTYPE_BROADCAST:
  364. case OSPF_IFTYPE_NBMA:
  365. lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_MA;
  366. break;
  367. default:
  368. /* Not supported yet. *//* XXX */
  369. lp->link_type.header.type = htons (0);
  370. break;
  371. }
  372. return;
  373. }
  374. static void
  375. set_linkparams_link_id (struct ospf_interface *oi, struct mpls_te_link *lp)
  376. {
  377. struct ospf_neighbor *nbr;
  378. int done = 0;
  379. lp->link_id.header.type = htons (TE_LINK_SUBTLV_LINK_ID);
  380. lp->link_id.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  381. /*
  382. * The Link ID is identical to the contents of the Link ID field
  383. * in the Router LSA for these link types.
  384. */
  385. switch (oi->type)
  386. {
  387. case OSPF_IFTYPE_POINTOPOINT:
  388. /* Take the router ID of the neighbor. */
  389. if ((nbr = ospf_nbr_lookup_ptop (oi)) && nbr->state == NSM_Full)
  390. {
  391. lp->link_id.value = nbr->router_id;
  392. done = 1;
  393. }
  394. break;
  395. case OSPF_IFTYPE_BROADCAST:
  396. case OSPF_IFTYPE_NBMA:
  397. /* Take the interface address of the designated router. */
  398. if ((nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &DR (oi))) == NULL)
  399. break;
  400. if (nbr->state == NSM_Full
  401. || (IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))
  402. && ospf_nbr_count (oi, NSM_Full) > 0))
  403. {
  404. lp->link_id.value = DR (oi);
  405. done = 1;
  406. }
  407. break;
  408. default:
  409. /* Not supported yet. *//* XXX */
  410. lp->link_id.header.type = htons (0);
  411. break;
  412. }
  413. if (! done)
  414. {
  415. struct in_addr mask;
  416. masklen2ip (oi->address->prefixlen, &mask);
  417. lp->link_id.value.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr;
  418. }
  419. return;
  420. }
  421. static void
  422. set_linkparams_lclif_ipaddr (struct mpls_te_link *lp, struct in_addr lclif)
  423. {
  424. lp->lclif_ipaddr.header.type = htons (TE_LINK_SUBTLV_LCLIF_IPADDR);
  425. lp->lclif_ipaddr.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  426. lp->lclif_ipaddr.value[0] = lclif;
  427. return;
  428. }
  429. static void
  430. set_linkparams_rmtif_ipaddr (struct mpls_te_link *lp, struct in_addr rmtif)
  431. {
  432. lp->rmtif_ipaddr.header.type = htons (TE_LINK_SUBTLV_RMTIF_IPADDR);
  433. lp->rmtif_ipaddr.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  434. lp->rmtif_ipaddr.value[0] = rmtif;
  435. return;
  436. }
  437. static void
  438. set_linkparams_te_metric (struct mpls_te_link *lp, u_int32_t te_metric)
  439. {
  440. lp->te_metric.header.type = htons (TE_LINK_SUBTLV_TE_METRIC);
  441. lp->te_metric.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  442. lp->te_metric.value = htonl (te_metric);
  443. return;
  444. }
  445. static void
  446. set_linkparams_max_bw (struct mpls_te_link *lp, float fp)
  447. {
  448. lp->max_bw.header.type = htons (TE_LINK_SUBTLV_MAX_BW);
  449. lp->max_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  450. lp->max_bw.value = htonf (fp);
  451. return;
  452. }
  453. static void
  454. set_linkparams_max_rsv_bw (struct mpls_te_link *lp, float fp)
  455. {
  456. lp->max_rsv_bw.header.type = htons (TE_LINK_SUBTLV_MAX_RSV_BW);
  457. lp->max_rsv_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  458. lp->max_rsv_bw.value = htonf (fp);
  459. return;
  460. }
  461. static void
  462. set_linkparams_unrsv_bw (struct mpls_te_link *lp, int priority, float fp)
  463. {
  464. /* Note that TLV-length field is the size of array. */
  465. lp->unrsv_bw.header.type = htons (TE_LINK_SUBTLV_UNRSV_BW);
  466. lp->unrsv_bw.header.length = htons (TE_LINK_SUBTLV_UNRSV_SIZE);
  467. lp->unrsv_bw.value [priority] = htonf (fp);
  468. return;
  469. }
  470. static void
  471. set_linkparams_rsc_clsclr (struct mpls_te_link *lp, u_int32_t classcolor)
  472. {
  473. lp->rsc_clsclr.header.type = htons (TE_LINK_SUBTLV_RSC_CLSCLR);
  474. lp->rsc_clsclr.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  475. lp->rsc_clsclr.value = htonl (classcolor);
  476. return;
  477. }
  478. static void
  479. set_linkparams_inter_as (struct mpls_te_link *lp, struct in_addr addr,
  480. u_int32_t as)
  481. {
  482. /* Set the Remote ASBR IP address and then the associated AS number */
  483. lp->rip.header.type = htons (TE_LINK_SUBTLV_RIP);
  484. lp->rip.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  485. lp->rip.value = addr;
  486. lp->ras.header.type = htons (TE_LINK_SUBTLV_RAS);
  487. lp->ras.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  488. lp->ras.value = htonl (as);
  489. }
  490. static void
  491. unset_linkparams_inter_as (struct mpls_te_link *lp)
  492. {
  493. /* Reset the Remote ASBR IP address and then the associated AS number */
  494. lp->rip.header.type = htons (0);
  495. lp->rip.header.length = htons (0);
  496. lp->rip.value.s_addr = htonl (0);
  497. lp->ras.header.type = htons (0);
  498. lp->ras.header.length = htons (0);
  499. lp->ras.value = htonl (0);
  500. }
  501. void
  502. set_linkparams_llri (struct mpls_te_link *lp, u_int32_t local,
  503. u_int32_t remote)
  504. {
  505. lp->llri.header.type = htons (TE_LINK_SUBTLV_LLRI);
  506. lp->llri.header.length = htons (TE_LINK_SUBTLV_LLRI_SIZE);
  507. lp->llri.local = htonl (local);
  508. lp->llri.remote = htonl (remote);
  509. }
  510. void
  511. set_linkparams_lrrid (struct mpls_te_link *lp, struct in_addr local,
  512. struct in_addr remote)
  513. {
  514. lp->lrrid.header.type = htons (TE_LINK_SUBTLV_LRRID);
  515. lp->lrrid.header.length = htons (TE_LINK_SUBTLV_LRRID_SIZE);
  516. lp->lrrid.local.s_addr = local.s_addr;
  517. lp->lrrid.remote.s_addr = remote.s_addr;
  518. }
  519. static void
  520. set_linkparams_av_delay (struct mpls_te_link *lp, u_int32_t delay, u_char anormal)
  521. {
  522. u_int32_t tmp;
  523. /* Note that TLV-length field is the size of array. */
  524. lp->av_delay.header.type = htons (TE_LINK_SUBTLV_AV_DELAY);
  525. lp->av_delay.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  526. tmp = delay & TE_EXT_MASK;
  527. if (anormal)
  528. tmp |= TE_EXT_ANORMAL;
  529. lp->av_delay.value = htonl (tmp);
  530. return;
  531. }
  532. static void
  533. set_linkparams_mm_delay (struct mpls_te_link *lp, u_int32_t low, u_int32_t high, u_char anormal)
  534. {
  535. u_int32_t tmp;
  536. /* Note that TLV-length field is the size of array. */
  537. lp->mm_delay.header.type = htons (TE_LINK_SUBTLV_MM_DELAY);
  538. lp->mm_delay.header.length = htons (TE_LINK_SUBTLV_MM_DELAY_SIZE);
  539. tmp = low & TE_EXT_MASK;
  540. if (anormal)
  541. tmp |= TE_EXT_ANORMAL;
  542. lp->mm_delay.low = htonl (tmp);
  543. lp->mm_delay.high = htonl (high);
  544. return;
  545. }
  546. static void
  547. set_linkparams_delay_var (struct mpls_te_link *lp, u_int32_t jitter)
  548. {
  549. /* Note that TLV-length field is the size of array. */
  550. lp->delay_var.header.type = htons (TE_LINK_SUBTLV_DELAY_VAR);
  551. lp->delay_var.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  552. lp->delay_var.value = htonl (jitter & TE_EXT_MASK);
  553. return;
  554. }
  555. static void
  556. set_linkparams_pkt_loss (struct mpls_te_link *lp, u_int32_t loss, u_char anormal)
  557. {
  558. u_int32_t tmp;
  559. /* Note that TLV-length field is the size of array. */
  560. lp->pkt_loss.header.type = htons (TE_LINK_SUBTLV_PKT_LOSS);
  561. lp->pkt_loss.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  562. tmp = loss & TE_EXT_MASK;
  563. if (anormal)
  564. tmp |= TE_EXT_ANORMAL;
  565. lp->pkt_loss.value = htonl (tmp);
  566. return;
  567. }
  568. static void
  569. set_linkparams_res_bw (struct mpls_te_link *lp, float fp)
  570. {
  571. /* Note that TLV-length field is the size of array. */
  572. lp->res_bw.header.type = htons (TE_LINK_SUBTLV_RES_BW);
  573. lp->res_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  574. lp->res_bw.value = htonf (fp);
  575. return;
  576. }
  577. static void
  578. set_linkparams_ava_bw (struct mpls_te_link *lp, float fp)
  579. {
  580. /* Note that TLV-length field is the size of array. */
  581. lp->ava_bw.header.type = htons (TE_LINK_SUBTLV_AVA_BW);
  582. lp->ava_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  583. lp->ava_bw.value = htonf (fp);
  584. return;
  585. }
  586. static void
  587. set_linkparams_use_bw (struct mpls_te_link *lp, float fp)
  588. {
  589. /* Note that TLV-length field is the size of array. */
  590. lp->use_bw.header.type = htons (TE_LINK_SUBTLV_USE_BW);
  591. lp->use_bw.header.length = htons (TE_LINK_SUBTLV_DEF_SIZE);
  592. lp->use_bw.value = htonf (fp);
  593. return;
  594. }
  595. /* Update TE parameters from Interface */
  596. static void
  597. update_linkparams(struct mpls_te_link *lp)
  598. {
  599. int i;
  600. struct interface *ifp;
  601. /* Get the Interface structure */
  602. if ((ifp = lp->ifp) == NULL)
  603. {
  604. zlog_warn("OSPF MPLS-TE: Abort update TE parameters: no interface associated to Link Parameters");
  605. return;
  606. }
  607. if (!HAS_LINK_PARAMS(ifp))
  608. {
  609. zlog_warn("OSPF MPLS-TE: Abort update TE parameters: no Link Parameters for interface");
  610. return;
  611. }
  612. /* RFC3630 metrics */
  613. if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP))
  614. set_linkparams_rsc_clsclr (lp, ifp->link_params->admin_grp);
  615. else
  616. TLV_TYPE(lp->rsc_clsclr) = 0;
  617. if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW))
  618. set_linkparams_max_bw (lp, ifp->link_params->max_bw);
  619. else
  620. TLV_TYPE(lp->max_bw) = 0;
  621. if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW))
  622. set_linkparams_max_rsv_bw (lp, ifp->link_params->max_rsv_bw);
  623. else
  624. TLV_TYPE(lp->max_rsv_bw) = 0;
  625. if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW))
  626. for (i = 0; i < MAX_CLASS_TYPE; i++)
  627. set_linkparams_unrsv_bw (lp, i, ifp->link_params->unrsv_bw[i]);
  628. else
  629. TLV_TYPE(lp->unrsv_bw) = 0;
  630. if (IS_PARAM_SET(ifp->link_params, LP_TE))
  631. set_linkparams_te_metric(lp, ifp->link_params->te_metric);
  632. else
  633. TLV_TYPE(lp->te_metric) = 0;
  634. /* TE metric Extensions */
  635. if (IS_PARAM_SET(ifp->link_params, LP_DELAY))
  636. set_linkparams_av_delay(lp, ifp->link_params->av_delay, 0);
  637. else
  638. TLV_TYPE(lp->av_delay) = 0;
  639. if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY))
  640. set_linkparams_mm_delay(lp, ifp->link_params->min_delay, ifp->link_params->max_delay, 0);
  641. else
  642. TLV_TYPE(lp->mm_delay) = 0;
  643. if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR))
  644. set_linkparams_delay_var(lp, ifp->link_params->delay_var);
  645. else
  646. TLV_TYPE(lp->delay_var) = 0;
  647. if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS))
  648. set_linkparams_pkt_loss(lp, ifp->link_params->pkt_loss, 0);
  649. else
  650. TLV_TYPE(lp->pkt_loss) = 0;
  651. if (IS_PARAM_SET(ifp->link_params, LP_RES_BW))
  652. set_linkparams_res_bw(lp, ifp->link_params->res_bw);
  653. else
  654. TLV_TYPE(lp->res_bw) = 0;
  655. if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW))
  656. set_linkparams_ava_bw(lp, ifp->link_params->ava_bw);
  657. else
  658. TLV_TYPE(lp->ava_bw) = 0;
  659. if (IS_PARAM_SET(ifp->link_params, LP_USE_BW))
  660. set_linkparams_use_bw(lp, ifp->link_params->use_bw);
  661. else
  662. TLV_TYPE(lp->use_bw) = 0;
  663. /* RFC5392 */
  664. if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS))
  665. {
  666. /* Flush LSA if it engaged and was previously a STD_TE one */
  667. if (IS_STD_TE(lp->type) && CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED))
  668. {
  669. if (IS_DEBUG_OSPF_TE)
  670. zlog_debug("OSPF MPLS-TE Update IF: Switch from Standard LSA to INTER-AS for %s[%d/%d]",
  671. ifp->name, lp->flags, lp->type);
  672. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  673. /* Then, switch it to INTER-AS */
  674. if (OspfMplsTE.inter_as == AS)
  675. lp->flags = INTER_AS | FLOOD_AS;
  676. else
  677. {
  678. lp->flags = INTER_AS | FLOOD_AREA;
  679. lp->area = ospf_area_lookup_by_area_id (ospf_lookup(), OspfMplsTE.interas_areaid);
  680. }
  681. }
  682. set_linkparams_inter_as(lp, ifp->link_params->rmt_ip, ifp->link_params->rmt_as);
  683. }
  684. else
  685. {
  686. if (IS_DEBUG_OSPF_TE)
  687. zlog_debug("OSPF MPLS-TE Update IF: Switch from INTER-AS LSA to Standard for %s[%d/%d]",
  688. ifp->name, lp->flags, lp->type);
  689. /* reset inter-as TE params */
  690. /* Flush LSA if it engaged and was previously an INTER_AS one */
  691. if (IS_INTER_AS(lp->type) && CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED))
  692. {
  693. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  694. /* Then, switch it to Standard TE */
  695. lp->flags = STD_TE | FLOOD_AREA;
  696. }
  697. unset_linkparams_inter_as (lp);
  698. }
  699. }
  700. static void
  701. initialize_linkparams (struct mpls_te_link *lp)
  702. {
  703. struct interface *ifp = lp->ifp;
  704. struct ospf_interface *oi;
  705. if (IS_DEBUG_OSPF_TE)
  706. zlog_debug("MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s",
  707. ifp->name);
  708. if ((oi = lookup_oi_by_ifp (ifp, NULL, OI_ANY)) == NULL)
  709. {
  710. zlog_warn("MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s",
  711. ifp->name);
  712. return;
  713. }
  714. /*
  715. * Try to set initial values those can be derived from
  716. * zebra-interface information.
  717. */
  718. set_linkparams_link_type (oi, lp);
  719. /* Set local IP addr */
  720. set_linkparams_lclif_ipaddr (lp, oi->address->u.prefix4);
  721. /* Set Remote IP addr if Point to Point Interface */
  722. if (oi->type == LINK_TYPE_SUBTLV_VALUE_PTP)
  723. {
  724. struct prefix *pref = CONNECTED_PREFIX(oi->connected);
  725. if (pref != NULL)
  726. set_linkparams_rmtif_ipaddr(lp, pref->u.prefix4);
  727. }
  728. /* Keep Area information in combination with link parameters. */
  729. lp->area = oi->area;
  730. return;
  731. }
  732. static int
  733. is_mandated_params_set (struct mpls_te_link *lp)
  734. {
  735. int rc = 0;
  736. if (ntohs (OspfMplsTE.router_addr.header.type) == 0)
  737. {
  738. zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Router Address");
  739. goto out;
  740. }
  741. if (ntohs (lp->link_type.header.type) == 0)
  742. {
  743. zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Link Type");
  744. goto out;
  745. }
  746. if (!IS_INTER_AS (lp->type) && (ntohs (lp->link_id.header.type) == 0))
  747. {
  748. zlog_warn ("MPLS-TE(is_mandated_params_set) Missing Link ID");
  749. goto out;
  750. }
  751. rc = 1;
  752. out:
  753. return rc;
  754. }
  755. /*------------------------------------------------------------------------*
  756. * Followings are callback functions against generic Opaque-LSAs handling.
  757. *------------------------------------------------------------------------*/
  758. static int
  759. ospf_mpls_te_new_if (struct interface *ifp)
  760. {
  761. struct mpls_te_link *new;
  762. int rc = -1;
  763. if (IS_DEBUG_OSPF_TE)
  764. zlog_debug ("MPLS-TE(ospf_mpls_te_new_if) Add new %s interface %s to MPLS-TE list",
  765. ifp->link_params ? "Active" : "Inactive", ifp->name);
  766. if (lookup_linkparams_by_ifp (ifp) != NULL)
  767. {
  768. zlog_warn ("ospf_mpls_te_new_if: ifp(%p) already in use?", (void *)ifp);
  769. rc = 0; /* Do nothing here. */
  770. goto out;
  771. }
  772. new = XCALLOC (MTYPE_OSPF_MPLS_TE, sizeof (struct mpls_te_link));
  773. if (new == NULL)
  774. {
  775. zlog_warn ("ospf_mpls_te_new_if: XMALLOC: %s", safe_strerror (errno));
  776. goto out;
  777. }
  778. new->instance = get_mpls_te_instance_value ();
  779. new->ifp = ifp;
  780. /* By default TE-Link is RFC3630 compatible flooding in Area and not active */
  781. /* This default behavior will be adapted with call to ospf_mpls_te_update_if() */
  782. new->type = STD_TE | FLOOD_AREA;
  783. new->flags = LPFLG_LSA_INACTIVE;
  784. /* Initialize Link Parameters from Interface */
  785. initialize_linkparams(new);
  786. /* Set TE Parameters from Interface */
  787. update_linkparams(new);
  788. /* Add Link Parameters structure to the list */
  789. listnode_add (OspfMplsTE.iflist, new);
  790. if (IS_DEBUG_OSPF_TE)
  791. zlog_debug("OSPF MPLS-TE New IF: Add new LP context for %s[%d/%d]",
  792. ifp->name, new->flags, new->type);
  793. /* Schedule Opaque-LSA refresh. *//* XXX */
  794. rc = 0;
  795. out:
  796. return rc;
  797. }
  798. static int
  799. ospf_mpls_te_del_if (struct interface *ifp)
  800. {
  801. struct mpls_te_link *lp;
  802. int rc = -1;
  803. if ((lp = lookup_linkparams_by_ifp (ifp)) != NULL)
  804. {
  805. struct list *iflist = OspfMplsTE.iflist;
  806. /* Dequeue listnode entry from the list. */
  807. listnode_delete (iflist, lp);
  808. /* Avoid misjudgement in the next lookup. */
  809. if (listcount (iflist) == 0)
  810. iflist->head = iflist->tail = NULL;
  811. XFREE (MTYPE_OSPF_MPLS_TE, lp);
  812. }
  813. /* Schedule Opaque-LSA refresh. *//* XXX */
  814. rc = 0;
  815. /*out:*/
  816. return rc;
  817. }
  818. /* Main initialization / update function of the MPLS TE Link context */
  819. /* Call when interface TE Link parameters are modified */
  820. void
  821. ospf_mpls_te_update_if (struct interface *ifp)
  822. {
  823. struct mpls_te_link *lp;
  824. if (IS_DEBUG_OSPF_TE)
  825. zlog_debug ("OSPF MPLS-TE: Update LSA parameters for interface %s [%s]",
  826. ifp->name, HAS_LINK_PARAMS(ifp) ? "ON" : "OFF");
  827. /* Get Link context from interface */
  828. if ((lp = lookup_linkparams_by_ifp(ifp)) == NULL)
  829. {
  830. zlog_warn ("OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s", ifp->name);
  831. return;
  832. }
  833. /* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
  834. if (HAS_LINK_PARAMS(ifp))
  835. {
  836. SET_FLAG (lp->flags, LPFLG_LSA_ACTIVE);
  837. /* Update TE parameters */
  838. update_linkparams(lp);
  839. /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is enabled */
  840. if (OspfMplsTE.status == enabled)
  841. if (lp->area != NULL)
  842. {
  843. if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
  844. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  845. else
  846. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_THIS_LSA);
  847. }
  848. }
  849. else
  850. {
  851. /* If MPLS TE is disable on this interface, flush LSA if it is already engaged */
  852. if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
  853. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  854. else
  855. /* Reset Activity flag */
  856. lp->flags = LPFLG_LSA_INACTIVE;
  857. }
  858. return;
  859. }
  860. static void
  861. ospf_mpls_te_ism_change (struct ospf_interface *oi, int old_state)
  862. {
  863. struct te_link_subtlv_link_type old_type;
  864. struct te_link_subtlv_link_id old_id;
  865. struct mpls_te_link *lp;
  866. if ((lp = lookup_linkparams_by_ifp (oi->ifp)) == NULL)
  867. {
  868. zlog_warn ("ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?", IF_NAME (oi));
  869. goto out;
  870. }
  871. if (oi->area == NULL || oi->area->ospf == NULL)
  872. {
  873. zlog_warn ("ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?", IF_NAME (oi));
  874. goto out;
  875. }
  876. #ifdef notyet
  877. if ((lp->area != NULL
  878. && ! IPV4_ADDR_SAME (&lp->area->area_id, &oi->area->area_id))
  879. || (lp->area != NULL && oi->area == NULL))
  880. {
  881. /* How should we consider this case? */
  882. zlog_warn ("MPLS-TE: Area for OI(%s) has changed to [%s], flush previous LSAs",
  883. IF_NAME (oi), oi->area ? inet_ntoa (oi->area->area_id) : "N/A");
  884. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  885. }
  886. #endif
  887. /* Keep Area information in combination with linkparams. */
  888. lp->area = oi->area;
  889. /* Keep interface MPLS-TE status */
  890. lp->flags = HAS_LINK_PARAMS(oi->ifp);
  891. switch (oi->state)
  892. {
  893. case ISM_PointToPoint:
  894. case ISM_DROther:
  895. case ISM_Backup:
  896. case ISM_DR:
  897. old_type = lp->link_type;
  898. old_id = lp->link_id;
  899. /* Set Link type, Link ID, Local and Remote IP addr */
  900. set_linkparams_link_type (oi, lp);
  901. set_linkparams_link_id (oi, lp);
  902. set_linkparams_lclif_ipaddr (lp, oi->address->u.prefix4);
  903. if (oi->type == LINK_TYPE_SUBTLV_VALUE_PTP)
  904. {
  905. struct prefix *pref = CONNECTED_PREFIX(oi->connected);
  906. if (pref != NULL)
  907. set_linkparams_rmtif_ipaddr(lp, pref->u.prefix4);
  908. }
  909. /* Update TE parameters */
  910. update_linkparams(lp);
  911. /* Try to Schedule LSA */
  912. if ((ntohs (old_type.header.type) != ntohs (lp->link_type.header.type)
  913. || old_type.link_type.value != lp->link_type.link_type.value)
  914. || (ntohs (old_id.header.type) != ntohs (lp->link_id.header.type)
  915. || ntohl (old_id.value.s_addr) !=
  916. ntohl (lp->link_id.value.s_addr)))
  917. {
  918. if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
  919. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  920. else
  921. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_THIS_LSA);
  922. }
  923. break;
  924. default:
  925. lp->link_type.header.type = htons (0);
  926. lp->link_id.header.type = htons (0);
  927. if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
  928. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  929. break;
  930. }
  931. out:
  932. return;
  933. }
  934. static void
  935. ospf_mpls_te_nsm_change (struct ospf_neighbor *nbr, int old_state)
  936. {
  937. /* Nothing to do here */
  938. return;
  939. }
  940. /*------------------------------------------------------------------------*
  941. * Followings are OSPF protocol processing functions for MPLS-TE.
  942. *------------------------------------------------------------------------*/
  943. static void
  944. build_tlv_header (struct stream *s, struct te_tlv_header *tlvh)
  945. {
  946. stream_put (s, tlvh, sizeof (struct te_tlv_header));
  947. return;
  948. }
  949. static void
  950. build_router_tlv (struct stream *s)
  951. {
  952. struct te_tlv_header *tlvh = &OspfMplsTE.router_addr.header;
  953. if (ntohs (tlvh->type) != 0)
  954. {
  955. build_tlv_header (s, tlvh);
  956. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  957. }
  958. return;
  959. }
  960. static void
  961. build_link_subtlv (struct stream *s, struct te_tlv_header *tlvh)
  962. {
  963. if ((tlvh != NULL) && (ntohs (tlvh->type) != 0))
  964. {
  965. build_tlv_header (s, tlvh);
  966. stream_put (s, tlvh+1, TLV_BODY_SIZE (tlvh));
  967. }
  968. return;
  969. }
  970. static void
  971. build_link_tlv (struct stream *s, struct mpls_te_link *lp)
  972. {
  973. set_linkparams_link_header (lp);
  974. build_tlv_header (s, &lp->link_header.header);
  975. build_link_subtlv (s, &lp->link_type.header);
  976. build_link_subtlv (s, &lp->link_id.header);
  977. build_link_subtlv (s, &lp->lclif_ipaddr.header);
  978. build_link_subtlv (s, &lp->rmtif_ipaddr.header);
  979. build_link_subtlv (s, &lp->te_metric.header);
  980. build_link_subtlv (s, &lp->max_bw.header);
  981. build_link_subtlv (s, &lp->max_rsv_bw.header);
  982. build_link_subtlv (s, &lp->unrsv_bw.header);
  983. build_link_subtlv (s, &lp->rsc_clsclr.header);
  984. build_link_subtlv (s, &lp->lrrid.header);
  985. build_link_subtlv (s, &lp->llri.header);
  986. build_link_subtlv (s, &lp->rip.header);
  987. build_link_subtlv (s, &lp->ras.header);
  988. build_link_subtlv (s, &lp->av_delay.header);
  989. build_link_subtlv (s, &lp->mm_delay.header);
  990. build_link_subtlv (s, &lp->delay_var.header);
  991. build_link_subtlv (s, &lp->pkt_loss.header);
  992. build_link_subtlv (s, &lp->res_bw.header);
  993. build_link_subtlv (s, &lp->ava_bw.header);
  994. build_link_subtlv (s, &lp->res_bw.header);
  995. return;
  996. }
  997. static void
  998. ospf_mpls_te_lsa_body_set (struct stream *s, struct mpls_te_link *lp)
  999. {
  1000. /*
  1001. * The router address TLV is type 1, and ...
  1002. * It must appear in exactly one
  1003. * Traffic Engineering LSA originated by a router.
  1004. */
  1005. build_router_tlv (s);
  1006. /*
  1007. * Only one Link TLV shall be carried in each LSA, allowing for fine
  1008. * granularity changes in topology.
  1009. */
  1010. build_link_tlv (s, lp);
  1011. return;
  1012. }
  1013. /* Create new opaque-LSA. */
  1014. static struct ospf_lsa *
  1015. ospf_mpls_te_lsa_new (struct ospf_area *area, struct mpls_te_link *lp)
  1016. {
  1017. struct stream *s;
  1018. struct lsa_header *lsah;
  1019. struct ospf_lsa *new = NULL;
  1020. u_char options, lsa_type = 0;
  1021. struct in_addr lsa_id;
  1022. u_int32_t tmp;
  1023. u_int16_t length;
  1024. /* Create a stream for LSA. */
  1025. if ((s = stream_new (OSPF_MAX_LSA_SIZE)) == NULL)
  1026. {
  1027. zlog_warn ("ospf_mpls_te_lsa_new: stream_new() ?");
  1028. goto out;
  1029. }
  1030. lsah = (struct lsa_header *) STREAM_DATA (s);
  1031. options = OSPF_OPTION_O; /* Don't forget this :-) */
  1032. /* Set opaque-LSA header fields depending of the type of RFC */
  1033. if (IS_INTER_AS (lp->type))
  1034. {
  1035. if IS_FLOOD_AS (lp->type)
  1036. {
  1037. options |= OSPF_OPTION_E; /* Enable AS external as we flood Inter-AS with Opaque Type 11 */
  1038. lsa_type = OSPF_OPAQUE_AS_LSA;
  1039. }
  1040. else
  1041. {
  1042. options |= LSA_OPTIONS_GET (area); /* Get area default option */
  1043. options |= LSA_OPTIONS_NSSA_GET (area);
  1044. lsa_type = OSPF_OPAQUE_AREA_LSA;
  1045. }
  1046. tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
  1047. lsa_id.s_addr = htonl (tmp);
  1048. struct ospf *top = ospf_lookup ();
  1049. lsa_header_set (s, options, lsa_type, lsa_id, top->router_id);
  1050. }
  1051. else
  1052. {
  1053. options |= LSA_OPTIONS_GET (area); /* Get area default option */
  1054. options |= LSA_OPTIONS_NSSA_GET (area);
  1055. lsa_type = OSPF_OPAQUE_AREA_LSA;
  1056. tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance);
  1057. lsa_id.s_addr = htonl (tmp);
  1058. lsa_header_set (s, options, lsa_type, lsa_id, area->ospf->router_id);
  1059. }
  1060. if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
  1061. zlog_debug ("LSA[Type%d:%s]: Create an Opaque-LSA/MPLS-TE instance",
  1062. lsa_type, inet_ntoa (lsa_id));
  1063. /* Set opaque-LSA body fields. */
  1064. ospf_mpls_te_lsa_body_set (s, lp);
  1065. /* Set length. */
  1066. length = stream_get_endp (s);
  1067. lsah->length = htons (length);
  1068. /* Now, create an OSPF LSA instance. */
  1069. if ((new = ospf_lsa_new ()) == NULL)
  1070. {
  1071. zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_new() ?");
  1072. stream_free (s);
  1073. goto out;
  1074. }
  1075. if ((new->data = ospf_lsa_data_new (length)) == NULL)
  1076. {
  1077. zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
  1078. ospf_lsa_unlock (&new);
  1079. new = NULL;
  1080. stream_free (s);
  1081. goto out;
  1082. }
  1083. new->area = area;
  1084. SET_FLAG (new->flags, OSPF_LSA_SELF);
  1085. memcpy (new->data, lsah, length);
  1086. stream_free (s);
  1087. out:
  1088. return new;
  1089. }
  1090. static int
  1091. ospf_mpls_te_lsa_originate1 (struct ospf_area *area, struct mpls_te_link *lp)
  1092. {
  1093. struct ospf_lsa *new;
  1094. int rc = -1;
  1095. /* Create new Opaque-LSA/MPLS-TE instance. */
  1096. if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL)
  1097. {
  1098. zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
  1099. goto out;
  1100. }
  1101. /* Install this LSA into LSDB. */
  1102. if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL)
  1103. {
  1104. zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
  1105. ospf_lsa_unlock (&new);
  1106. goto out;
  1107. }
  1108. /* Now this link-parameter entry has associated LSA. */
  1109. SET_FLAG (lp->flags, LPFLG_LSA_ENGAGED);
  1110. /* Update new LSA origination count. */
  1111. area->ospf->lsa_originate_count++;
  1112. /* Flood new LSA through area. */
  1113. ospf_flood_through_area (area, NULL/*nbr*/, new);
  1114. if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
  1115. {
  1116. char area_id[INET_ADDRSTRLEN];
  1117. strcpy (area_id, inet_ntoa (area->area_id));
  1118. zlog_debug ("LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE: Area(%s), Link(%s)",
  1119. new->data->type, inet_ntoa (new->data->id), area_id, lp->ifp->name);
  1120. ospf_lsa_header_dump (new->data);
  1121. }
  1122. rc = 0;
  1123. out:
  1124. return rc;
  1125. }
  1126. static int
  1127. ospf_mpls_te_lsa_originate_area (void *arg)
  1128. {
  1129. struct ospf_area *area = (struct ospf_area *) arg;
  1130. struct listnode *node, *nnode;
  1131. struct mpls_te_link *lp;
  1132. int rc = -1;
  1133. if (OspfMplsTE.status == disabled)
  1134. {
  1135. zlog_info ("ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now.");
  1136. rc = 0; /* This is not an error case. */
  1137. goto out;
  1138. }
  1139. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1140. {
  1141. /* Process only enabled LSA with area scope flooding */
  1142. if (!CHECK_FLAG (lp->flags, LPFLG_LSA_ACTIVE) || IS_FLOOD_AS (lp->type))
  1143. continue;
  1144. if (lp->area == NULL)
  1145. continue;
  1146. if (! IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id))
  1147. continue;
  1148. if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
  1149. {
  1150. if CHECK_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH)
  1151. {
  1152. UNSET_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH);
  1153. zlog_warn ("OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate");
  1154. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1155. }
  1156. continue;
  1157. }
  1158. if (! is_mandated_params_set (lp))
  1159. {
  1160. zlog_warn ("ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.",
  1161. lp->ifp ? lp->ifp->name : "?");
  1162. continue;
  1163. }
  1164. /* Ok, let's try to originate an LSA for this area and Link. */
  1165. if (IS_DEBUG_OSPF_TE)
  1166. zlog_debug ("MPLS-TE(ospf_mpls_te_lsa_originate_area) Let's finally reoriginate the LSA %d through the Area %s for Link %s",
  1167. lp->instance, inet_ntoa (area->area_id), lp->ifp ? lp->ifp->name : "?");
  1168. if (ospf_mpls_te_lsa_originate1 (area, lp) != 0)
  1169. goto out;
  1170. }
  1171. rc = 0;
  1172. out:
  1173. return rc;
  1174. }
  1175. static int
  1176. ospf_mpls_te_lsa_originate2 (struct ospf *top, struct mpls_te_link *lp)
  1177. {
  1178. struct ospf_lsa *new;
  1179. int rc = -1;
  1180. /* Create new Opaque-LSA/Inter-AS instance. */
  1181. if ((new = ospf_mpls_te_lsa_new (NULL, lp)) == NULL)
  1182. {
  1183. zlog_warn ("ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
  1184. goto out;
  1185. }
  1186. /* Install this LSA into LSDB. */
  1187. if (ospf_lsa_install (top, NULL /*oi */ , new) == NULL)
  1188. {
  1189. zlog_warn ("ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?");
  1190. ospf_lsa_unlock (&new);
  1191. goto out;
  1192. }
  1193. /* Now this Router Info parameter entry has associated LSA. */
  1194. SET_FLAG (lp->flags, LPFLG_LSA_ENGAGED);
  1195. /* Update new LSA origination count. */
  1196. top->lsa_originate_count++;
  1197. /* Flood new LSA through AS. */
  1198. ospf_flood_through_as (top, NULL /*nbr */ , new);
  1199. if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
  1200. {
  1201. zlog_debug ("LSA[Type%d:%s]: Originate Opaque-LSA/MPLS-TE Inter-AS",
  1202. new->data->type, inet_ntoa (new->data->id));
  1203. ospf_lsa_header_dump (new->data);
  1204. }
  1205. rc = 0;
  1206. out:return rc;
  1207. }
  1208. static int
  1209. ospf_mpls_te_lsa_originate_as (void *arg)
  1210. {
  1211. struct ospf *top;
  1212. struct ospf_area *area;
  1213. struct listnode *node, *nnode;
  1214. struct mpls_te_link *lp;
  1215. int rc = -1;
  1216. if ((OspfMplsTE.status == disabled) || (OspfMplsTE.inter_as == Disable))
  1217. {
  1218. zlog_info
  1219. ("ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now.");
  1220. rc = 0; /* This is not an error case. */
  1221. goto out;
  1222. }
  1223. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1224. {
  1225. /* Process only enabled INTER_AS Links or Pseudo-Links */
  1226. if (!CHECK_FLAG (lp->flags, LPFLG_LSA_ACTIVE) || !IS_INTER_AS (lp->type))
  1227. continue;
  1228. if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
  1229. {
  1230. if CHECK_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH)
  1231. {
  1232. UNSET_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH);
  1233. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1234. }
  1235. continue;
  1236. }
  1237. if (!is_mandated_params_set (lp))
  1238. {
  1239. zlog_warn ("ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.",
  1240. lp->ifp ? lp->ifp->name : "?");
  1241. continue;
  1242. }
  1243. /* Ok, let's try to originate an LSA for this AS and Link. */
  1244. if (IS_DEBUG_OSPF_TE)
  1245. zlog_debug ("MPLS-TE(ospf_mpls_te_lsa_originate_as) Let's finally re-originate the Inter-AS LSA %d through the %s for Link %s",
  1246. lp->instance, IS_FLOOD_AS (lp->type) ? "AS" : "Area", lp->ifp ? lp->ifp->name : "Unknown");
  1247. if (IS_FLOOD_AS (lp->type))
  1248. {
  1249. top = (struct ospf *) arg;
  1250. rc = ospf_mpls_te_lsa_originate2 (top, lp);
  1251. }
  1252. else
  1253. {
  1254. area = (struct ospf_area *) arg;
  1255. rc = ospf_mpls_te_lsa_originate1 (area, lp);
  1256. }
  1257. }
  1258. rc = 0;
  1259. out:return rc;
  1260. }
  1261. static struct ospf_lsa *
  1262. ospf_mpls_te_lsa_refresh (struct ospf_lsa *lsa)
  1263. {
  1264. struct mpls_te_link *lp;
  1265. struct ospf_area *area = lsa->area;
  1266. struct ospf *top;
  1267. struct ospf_lsa *new = NULL;
  1268. if (OspfMplsTE.status == disabled)
  1269. {
  1270. /*
  1271. * This LSA must have flushed before due to MPLS-TE status change.
  1272. * It seems a slip among routers in the routing domain.
  1273. */
  1274. zlog_info ("ospf_mpls_te_lsa_refresh: MPLS-TE is disabled now.");
  1275. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
  1276. }
  1277. /* At first, resolve lsa/lp relationship. */
  1278. if ((lp = lookup_linkparams_by_instance (lsa)) == NULL)
  1279. {
  1280. zlog_warn ("ospf_mpls_te_lsa_refresh: Invalid parameter?");
  1281. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
  1282. }
  1283. /* Check if lp was not disable in the interval */
  1284. if (!CHECK_FLAG (lp->flags, LPFLG_LSA_ACTIVE))
  1285. {
  1286. zlog_warn ("ospf_mpls_te_lsa_refresh: lp was disabled: Flush it!");
  1287. lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); /* Flush it anyway. */
  1288. }
  1289. /* If the lsa's age reached to MaxAge, start flushing procedure. */
  1290. if (IS_LSA_MAXAGE (lsa))
  1291. {
  1292. if (lp)
  1293. UNSET_FLAG (lp->flags, LPFLG_LSA_ENGAGED);
  1294. ospf_opaque_lsa_flush_schedule (lsa);
  1295. goto out;
  1296. }
  1297. /* Create new Opaque-LSA/MPLS-TE instance. */
  1298. if ((new = ospf_mpls_te_lsa_new (area, lp)) == NULL)
  1299. {
  1300. zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
  1301. goto out;
  1302. }
  1303. new->data->ls_seqnum = lsa_seqnum_increment (lsa);
  1304. /* Install this LSA into LSDB. */
  1305. /* Given "lsa" will be freed in the next function. */
  1306. /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use ospf_lookup() to get ospf instance */
  1307. if (area)
  1308. top = area->ospf;
  1309. else
  1310. top = ospf_lookup ();
  1311. if (ospf_lsa_install (top, NULL /*oi */ , new) == NULL)
  1312. {
  1313. zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
  1314. ospf_lsa_unlock (&new);
  1315. goto out;
  1316. }
  1317. /* Flood updated LSA through AS or Area depending of the RFC of the link */
  1318. if (IS_FLOOD_AS (lp->type))
  1319. ospf_flood_through_as (top, NULL, new);
  1320. else
  1321. ospf_flood_through_area (area, NULL/*nbr*/, new);
  1322. /* Debug logging. */
  1323. if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
  1324. {
  1325. zlog_debug ("LSA[Type%d:%s]: Refresh Opaque-LSA/MPLS-TE",
  1326. new->data->type, inet_ntoa (new->data->id));
  1327. ospf_lsa_header_dump (new->data);
  1328. }
  1329. out:
  1330. return new;
  1331. }
  1332. void
  1333. ospf_mpls_te_lsa_schedule (struct mpls_te_link *lp, opcode_t opcode)
  1334. {
  1335. struct ospf_lsa lsa;
  1336. struct lsa_header lsah;
  1337. struct ospf *top;
  1338. u_int32_t tmp;
  1339. memset (&lsa, 0, sizeof (lsa));
  1340. memset (&lsah, 0, sizeof (lsah));
  1341. top = ospf_lookup ();
  1342. /* Check if the pseudo link is ready to flood */
  1343. if (!(CHECK_FLAG (lp->flags, LPFLG_LSA_ACTIVE))
  1344. || !(IS_FLOOD_AREA (lp->type) || IS_FLOOD_AS (lp->type))) {
  1345. return;
  1346. }
  1347. lsa.area = lp->area;
  1348. lsa.data = &lsah;
  1349. if (IS_FLOOD_AS (lp->type))
  1350. {
  1351. lsah.type = OSPF_OPAQUE_AS_LSA;
  1352. tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
  1353. lsah.id.s_addr = htonl (tmp);
  1354. }
  1355. else
  1356. {
  1357. lsah.type = OSPF_OPAQUE_AREA_LSA;
  1358. if (IS_INTER_AS (lp->type))
  1359. {
  1360. /* Set the area context if not know */
  1361. if (lp->area == NULL)
  1362. lp->area = ospf_area_lookup_by_area_id (top, OspfMplsTE.interas_areaid);
  1363. /* Unable to set the area context. Abort! */
  1364. if (lp->area == NULL)
  1365. {
  1366. zlog_warn ("MPLS-TE(ospf_mpls_te_lsa_schedule) Area context is null. Abort !");
  1367. return;
  1368. }
  1369. tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
  1370. }
  1371. else
  1372. tmp = SET_OPAQUE_LSID (OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA, lp->instance);
  1373. lsah.id.s_addr = htonl (tmp);
  1374. }
  1375. switch (opcode)
  1376. {
  1377. case REORIGINATE_THIS_LSA:
  1378. if (IS_FLOOD_AS (lp->type))
  1379. {
  1380. ospf_opaque_lsa_reoriginate_schedule ((void *) top, OSPF_OPAQUE_AS_LSA,
  1381. OPAQUE_TYPE_INTER_AS_LSA);
  1382. break;
  1383. }
  1384. if (IS_FLOOD_AREA (lp->type))
  1385. {
  1386. if (IS_INTER_AS (lp->type))
  1387. ospf_opaque_lsa_reoriginate_schedule ((void *) lp->area, OSPF_OPAQUE_AREA_LSA,
  1388. OPAQUE_TYPE_INTER_AS_LSA);
  1389. else
  1390. ospf_opaque_lsa_reoriginate_schedule ((void *) lp->area, OSPF_OPAQUE_AREA_LSA,
  1391. OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
  1392. break;
  1393. }
  1394. break;
  1395. case REFRESH_THIS_LSA:
  1396. ospf_opaque_lsa_refresh_schedule (&lsa);
  1397. break;
  1398. case FLUSH_THIS_LSA:
  1399. /* Reset Activity flag */
  1400. lp->flags = LPFLG_LSA_INACTIVE;
  1401. ospf_opaque_lsa_flush_schedule (&lsa);
  1402. break;
  1403. default:
  1404. zlog_warn ("ospf_mpls_te_lsa_schedule: Unknown opcode (%u)", opcode);
  1405. break;
  1406. }
  1407. return;
  1408. }
  1409. /*------------------------------------------------------------------------*
  1410. * Followings are vty session control functions.
  1411. *------------------------------------------------------------------------*/
  1412. static u_int16_t
  1413. show_vty_router_addr (struct vty *vty, struct te_tlv_header *tlvh)
  1414. {
  1415. struct te_tlv_router_addr *top = (struct te_tlv_router_addr *) tlvh;
  1416. if (vty != NULL)
  1417. vty_out (vty, " Router-Address: %s%s", inet_ntoa (top->value),
  1418. VTY_NEWLINE);
  1419. else
  1420. zlog_debug (" Router-Address: %s", inet_ntoa (top->value));
  1421. return TLV_SIZE (tlvh);
  1422. }
  1423. static u_int16_t
  1424. show_vty_link_header (struct vty *vty, struct te_tlv_header *tlvh)
  1425. {
  1426. struct te_tlv_link *top = (struct te_tlv_link *) tlvh;
  1427. if (vty != NULL)
  1428. vty_out (vty, " Link: %u octets of data%s", ntohs (top->header.length),
  1429. VTY_NEWLINE);
  1430. else
  1431. zlog_debug (" Link: %u octets of data", ntohs (top->header.length));
  1432. return TLV_HDR_SIZE; /* Here is special, not "TLV_SIZE". */
  1433. }
  1434. static u_int16_t
  1435. show_vty_link_subtlv_link_type (struct vty *vty, struct te_tlv_header *tlvh)
  1436. {
  1437. struct te_link_subtlv_link_type *top;
  1438. const char *cp = "Unknown";
  1439. top = (struct te_link_subtlv_link_type *) tlvh;
  1440. switch (top->link_type.value)
  1441. {
  1442. case LINK_TYPE_SUBTLV_VALUE_PTP:
  1443. cp = "Point-to-point";
  1444. break;
  1445. case LINK_TYPE_SUBTLV_VALUE_MA:
  1446. cp = "Multiaccess";
  1447. break;
  1448. default:
  1449. break;
  1450. }
  1451. if (vty != NULL)
  1452. vty_out (vty, " Link-Type: %s (%u)%s", cp, top->link_type.value,
  1453. VTY_NEWLINE);
  1454. else
  1455. zlog_debug (" Link-Type: %s (%u)", cp, top->link_type.value);
  1456. return TLV_SIZE (tlvh);
  1457. }
  1458. static u_int16_t
  1459. show_vty_link_subtlv_link_id (struct vty *vty, struct te_tlv_header *tlvh)
  1460. {
  1461. struct te_link_subtlv_link_id *top;
  1462. top = (struct te_link_subtlv_link_id *) tlvh;
  1463. if (vty != NULL)
  1464. vty_out (vty, " Link-ID: %s%s", inet_ntoa (top->value), VTY_NEWLINE);
  1465. else
  1466. zlog_debug (" Link-ID: %s", inet_ntoa (top->value));
  1467. return TLV_SIZE (tlvh);
  1468. }
  1469. static u_int16_t
  1470. show_vty_link_subtlv_lclif_ipaddr (struct vty *vty,
  1471. struct te_tlv_header *tlvh)
  1472. {
  1473. struct te_link_subtlv_lclif_ipaddr *top;
  1474. int i, n;
  1475. top = (struct te_link_subtlv_lclif_ipaddr *) tlvh;
  1476. n = ntohs (tlvh->length) / sizeof (top->value[0]);
  1477. if (vty != NULL)
  1478. vty_out (vty, " Local Interface IP Address(es): %d%s", n, VTY_NEWLINE);
  1479. else
  1480. zlog_debug (" Local Interface IP Address(es): %d", n);
  1481. for (i = 0; i < n; i++)
  1482. {
  1483. if (vty != NULL)
  1484. vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]),
  1485. VTY_NEWLINE);
  1486. else
  1487. zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i]));
  1488. }
  1489. return TLV_SIZE (tlvh);
  1490. }
  1491. static u_int16_t
  1492. show_vty_link_subtlv_rmtif_ipaddr (struct vty *vty,
  1493. struct te_tlv_header *tlvh)
  1494. {
  1495. struct te_link_subtlv_rmtif_ipaddr *top;
  1496. int i, n;
  1497. top = (struct te_link_subtlv_rmtif_ipaddr *) tlvh;
  1498. n = ntohs (tlvh->length) / sizeof (top->value[0]);
  1499. if (vty != NULL)
  1500. vty_out (vty, " Remote Interface IP Address(es): %d%s", n, VTY_NEWLINE);
  1501. else
  1502. zlog_debug (" Remote Interface IP Address(es): %d", n);
  1503. for (i = 0; i < n; i++)
  1504. {
  1505. if (vty != NULL)
  1506. vty_out (vty, " #%d: %s%s", i, inet_ntoa (top->value[i]),
  1507. VTY_NEWLINE);
  1508. else
  1509. zlog_debug (" #%d: %s", i, inet_ntoa (top->value[i]));
  1510. }
  1511. return TLV_SIZE (tlvh);
  1512. }
  1513. static u_int16_t
  1514. show_vty_link_subtlv_te_metric (struct vty *vty, struct te_tlv_header *tlvh)
  1515. {
  1516. struct te_link_subtlv_te_metric *top;
  1517. top = (struct te_link_subtlv_te_metric *) tlvh;
  1518. if (vty != NULL)
  1519. vty_out (vty, " Traffic Engineering Metric: %u%s",
  1520. (u_int32_t) ntohl (top->value), VTY_NEWLINE);
  1521. else
  1522. zlog_debug (" Traffic Engineering Metric: %u",
  1523. (u_int32_t) ntohl (top->value));
  1524. return TLV_SIZE (tlvh);
  1525. }
  1526. static u_int16_t
  1527. show_vty_link_subtlv_max_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1528. {
  1529. struct te_link_subtlv_max_bw *top;
  1530. float fval;
  1531. top = (struct te_link_subtlv_max_bw *) tlvh;
  1532. fval = ntohf (top->value);
  1533. if (vty != NULL)
  1534. vty_out (vty, " Maximum Bandwidth: %g (Bytes/sec)%s", fval, VTY_NEWLINE);
  1535. else
  1536. zlog_debug (" Maximum Bandwidth: %g (Bytes/sec)", fval);
  1537. return TLV_SIZE (tlvh);
  1538. }
  1539. static u_int16_t
  1540. show_vty_link_subtlv_max_rsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1541. {
  1542. struct te_link_subtlv_max_rsv_bw *top;
  1543. float fval;
  1544. top = (struct te_link_subtlv_max_rsv_bw *) tlvh;
  1545. fval = ntohf (top->value);
  1546. if (vty != NULL)
  1547. vty_out (vty, " Maximum Reservable Bandwidth: %g (Bytes/sec)%s", fval,
  1548. VTY_NEWLINE);
  1549. else
  1550. zlog_debug (" Maximum Reservable Bandwidth: %g (Bytes/sec)", fval);
  1551. return TLV_SIZE (tlvh);
  1552. }
  1553. static u_int16_t
  1554. show_vty_link_subtlv_unrsv_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1555. {
  1556. struct te_link_subtlv_unrsv_bw *top;
  1557. float fval1, fval2;
  1558. int i;
  1559. top = (struct te_link_subtlv_unrsv_bw *) tlvh;
  1560. if (vty != NULL)
  1561. vty_out (vty, " Unreserved Bandwidth per Class Type in Byte/s:%s", VTY_NEWLINE);
  1562. else
  1563. zlog_debug (" Unreserved Bandwidth per Class Type in Byte/s:");
  1564. for (i = 0; i < MAX_CLASS_TYPE; i+=2)
  1565. {
  1566. fval1 = ntohf (top->value[i]);
  1567. fval2 = ntohf (top->value[i+1]);
  1568. if (vty != NULL)
  1569. vty_out(vty, " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)%s",
  1570. i, fval1, i+1, fval2, VTY_NEWLINE);
  1571. else
  1572. zlog_debug (" [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)",
  1573. i, fval1, i+1, fval2);
  1574. }
  1575. return TLV_SIZE (tlvh);
  1576. }
  1577. static u_int16_t
  1578. show_vty_link_subtlv_rsc_clsclr (struct vty *vty, struct te_tlv_header *tlvh)
  1579. {
  1580. struct te_link_subtlv_rsc_clsclr *top;
  1581. top = (struct te_link_subtlv_rsc_clsclr *) tlvh;
  1582. if (vty != NULL)
  1583. vty_out (vty, " Resource class/color: 0x%x%s",
  1584. (u_int32_t) ntohl (top->value), VTY_NEWLINE);
  1585. else
  1586. zlog_debug (" Resource Class/Color: 0x%x",
  1587. (u_int32_t) ntohl (top->value));
  1588. return TLV_SIZE (tlvh);
  1589. }
  1590. static u_int16_t
  1591. show_vty_link_subtlv_lrrid (struct vty *vty, struct te_tlv_header *tlvh)
  1592. {
  1593. struct te_link_subtlv_lrrid *top;
  1594. top = (struct te_link_subtlv_lrrid *) tlvh;
  1595. if (vty != NULL)
  1596. {
  1597. vty_out (vty, " Local TE Router ID: %s%s", inet_ntoa (top->local),
  1598. VTY_NEWLINE);
  1599. vty_out (vty, " Remote TE Router ID: %s%s", inet_ntoa (top->remote),
  1600. VTY_NEWLINE);
  1601. }
  1602. else
  1603. {
  1604. zlog_debug (" Local TE Router ID: %s", inet_ntoa (top->local));
  1605. zlog_debug (" Remote TE Router ID: %s", inet_ntoa (top->remote));
  1606. }
  1607. return TLV_SIZE (tlvh);
  1608. }
  1609. static u_int16_t
  1610. show_vty_link_subtlv_llri (struct vty *vty, struct te_tlv_header *tlvh)
  1611. {
  1612. struct te_link_subtlv_llri *top;
  1613. top = (struct te_link_subtlv_llri *) tlvh;
  1614. if (vty != NULL)
  1615. {
  1616. vty_out (vty, " Link Local ID: %d%s", (u_int32_t) ntohl (top->local),
  1617. VTY_NEWLINE);
  1618. vty_out (vty, " Link Remote ID: %d%s", (u_int32_t) ntohl (top->remote),
  1619. VTY_NEWLINE);
  1620. }
  1621. else
  1622. {
  1623. zlog_debug (" Link Local ID: %d", (u_int32_t) ntohl (top->local));
  1624. zlog_debug (" Link Remote ID: %d", (u_int32_t) ntohl (top->remote));
  1625. }
  1626. return TLV_SIZE (tlvh);
  1627. }
  1628. static u_int16_t
  1629. show_vty_link_subtlv_rip (struct vty *vty, struct te_tlv_header *tlvh)
  1630. {
  1631. struct te_link_subtlv_rip *top;
  1632. top = (struct te_link_subtlv_rip *) tlvh;
  1633. if (vty != NULL)
  1634. vty_out (vty, " Inter-AS TE Remote ASBR IP address: %s%s",
  1635. inet_ntoa (top->value), VTY_NEWLINE);
  1636. else
  1637. zlog_debug (" Inter-AS TE Remote ASBR IP address: %s",
  1638. inet_ntoa (top->value));
  1639. return TLV_SIZE (tlvh);
  1640. }
  1641. static u_int16_t
  1642. show_vty_link_subtlv_ras (struct vty *vty, struct te_tlv_header *tlvh)
  1643. {
  1644. struct te_link_subtlv_ras *top;
  1645. top = (struct te_link_subtlv_ras *) tlvh;
  1646. if (vty != NULL)
  1647. vty_out (vty, " Inter-AS TE Remote AS number: %u%s", ntohl (top->value),
  1648. VTY_NEWLINE);
  1649. else
  1650. zlog_debug (" Inter-AS TE Remote AS number: %u", ntohl (top->value));
  1651. return TLV_SIZE (tlvh);
  1652. }
  1653. static u_int16_t
  1654. show_vty_link_subtlv_av_delay (struct vty *vty, struct te_tlv_header *tlvh)
  1655. {
  1656. struct te_link_subtlv_av_delay *top;
  1657. u_int32_t delay;
  1658. u_int32_t anomalous;
  1659. top = (struct te_link_subtlv_av_delay *) tlvh;
  1660. delay = (u_int32_t) ntohl (top->value) & TE_EXT_MASK;
  1661. anomalous = (u_int32_t) ntohl (top->value) & TE_EXT_ANORMAL;
  1662. if (vty != NULL)
  1663. vty_out (vty, " %s Average Link Delay: %d (micro-sec)%s",
  1664. anomalous ? "Anomalous" : "Normal", delay, VTY_NEWLINE);
  1665. else
  1666. zlog_debug (" %s Average Link Delay: %d (micro-sec)",
  1667. anomalous ? "Anomalous" : "Normal", delay);
  1668. return TLV_SIZE (tlvh);
  1669. }
  1670. static u_int16_t
  1671. show_vty_link_subtlv_mm_delay (struct vty *vty, struct te_tlv_header *tlvh)
  1672. {
  1673. struct te_link_subtlv_mm_delay *top;
  1674. u_int32_t low, high;
  1675. u_int32_t anomalous;
  1676. top = (struct te_link_subtlv_mm_delay *) tlvh;
  1677. low = (u_int32_t) ntohl (top->low) & TE_EXT_MASK;
  1678. anomalous = (u_int32_t) ntohl (top->low) & TE_EXT_ANORMAL;
  1679. high = (u_int32_t) ntohl (top->high);
  1680. if (vty != NULL)
  1681. vty_out (vty, " %s Min/Max Link Delay: %d/%d (micro-sec)%s",
  1682. anomalous ? "Anomalous" : "Normal", low, high, VTY_NEWLINE);
  1683. else
  1684. zlog_debug (" %s Min/Max Link Delay: %d/%d (micro-sec)",
  1685. anomalous ? "Anomalous" : "Normal", low, high);
  1686. return TLV_SIZE (tlvh);
  1687. }
  1688. static u_int16_t
  1689. show_vty_link_subtlv_delay_var (struct vty *vty, struct te_tlv_header *tlvh)
  1690. {
  1691. struct te_link_subtlv_delay_var *top;
  1692. u_int32_t jitter;
  1693. top = (struct te_link_subtlv_delay_var *) tlvh;
  1694. jitter = (u_int32_t) ntohl (top->value) & TE_EXT_MASK;
  1695. if (vty != NULL)
  1696. vty_out (vty, " Delay Variation: %d (micro-sec)%s", jitter, VTY_NEWLINE);
  1697. else
  1698. zlog_debug (" Delay Variation: %d (micro-sec)", jitter);
  1699. return TLV_SIZE (tlvh);
  1700. }
  1701. static u_int16_t
  1702. show_vty_link_subtlv_pkt_loss (struct vty *vty, struct te_tlv_header *tlvh)
  1703. {
  1704. struct te_link_subtlv_pkt_loss *top;
  1705. u_int32_t loss;
  1706. u_int32_t anomalous;
  1707. float fval;
  1708. top = (struct te_link_subtlv_pkt_loss *) tlvh;
  1709. loss = (u_int32_t) ntohl (top->value) & TE_EXT_MASK;
  1710. fval = (float) (loss * LOSS_PRECISION);
  1711. anomalous = (u_int32_t) ntohl (top->value) & TE_EXT_ANORMAL;
  1712. if (vty != NULL)
  1713. vty_out (vty, " %s Link Loss: %g (%%)%s", anomalous ? "Anomalous" : "Normal",
  1714. fval, VTY_NEWLINE);
  1715. else
  1716. zlog_debug (" %s Link Loss: %g (%%)", anomalous ? "Anomalous" : "Normal",
  1717. fval);
  1718. return TLV_SIZE (tlvh);
  1719. }
  1720. static u_int16_t
  1721. show_vty_link_subtlv_res_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1722. {
  1723. struct te_link_subtlv_res_bw *top;
  1724. float fval;
  1725. top = (struct te_link_subtlv_res_bw *) tlvh;
  1726. fval = ntohf (top->value);
  1727. if (vty != NULL)
  1728. vty_out (vty, " Unidirectional Residual Bandwidth: %g (Bytes/sec)%s",
  1729. fval, VTY_NEWLINE);
  1730. else
  1731. zlog_debug (" Unidirectional Residual Bandwidth: %g (Bytes/sec)",
  1732. fval);
  1733. return TLV_SIZE (tlvh);
  1734. }
  1735. static u_int16_t
  1736. show_vty_link_subtlv_ava_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1737. {
  1738. struct te_link_subtlv_ava_bw *top;
  1739. float fval;
  1740. top = (struct te_link_subtlv_ava_bw *) tlvh;
  1741. fval = ntohf (top->value);
  1742. if (vty != NULL)
  1743. vty_out (vty, " Unidirectional Available Bandwidth: %g (Bytes/sec)%s",
  1744. fval, VTY_NEWLINE);
  1745. else
  1746. zlog_debug (" Unidirectional Available Bandwidth: %g (Bytes/sec)",
  1747. fval);
  1748. return TLV_SIZE (tlvh);
  1749. }
  1750. static u_int16_t
  1751. show_vty_link_subtlv_use_bw (struct vty *vty, struct te_tlv_header *tlvh)
  1752. {
  1753. struct te_link_subtlv_use_bw *top;
  1754. float fval;
  1755. top = (struct te_link_subtlv_use_bw *) tlvh;
  1756. fval = ntohf (top->value);
  1757. if (vty != NULL)
  1758. vty_out (vty, " Unidirectional Utilized Bandwidth: %g (Bytes/sec)%s",
  1759. fval, VTY_NEWLINE);
  1760. else
  1761. zlog_debug (" Unidirectional Utilized Bandwidth: %g (Bytes/sec)",
  1762. fval);
  1763. return TLV_SIZE (tlvh);
  1764. }
  1765. static u_int16_t
  1766. show_vty_unknown_tlv (struct vty *vty, struct te_tlv_header *tlvh)
  1767. {
  1768. if (vty != NULL)
  1769. vty_out (vty, " Unknown TLV: [type(0x%x), length(0x%x)]%s",
  1770. ntohs (tlvh->type), ntohs (tlvh->length), VTY_NEWLINE);
  1771. else
  1772. zlog_debug (" Unknown TLV: [type(0x%x), length(0x%x)]",
  1773. ntohs (tlvh->type), ntohs (tlvh->length));
  1774. return TLV_SIZE (tlvh);
  1775. }
  1776. static u_int16_t
  1777. ospf_mpls_te_show_link_subtlv (struct vty *vty, struct te_tlv_header *tlvh0,
  1778. u_int16_t subtotal, u_int16_t total)
  1779. {
  1780. struct te_tlv_header *tlvh, *next;
  1781. u_int16_t sum = subtotal;
  1782. for (tlvh = tlvh0; sum < total; tlvh = (next ? next : TLV_HDR_NEXT (tlvh)))
  1783. {
  1784. next = NULL;
  1785. switch (ntohs (tlvh->type))
  1786. {
  1787. case TE_LINK_SUBTLV_LINK_TYPE:
  1788. sum += show_vty_link_subtlv_link_type (vty, tlvh);
  1789. break;
  1790. case TE_LINK_SUBTLV_LINK_ID:
  1791. sum += show_vty_link_subtlv_link_id (vty, tlvh);
  1792. break;
  1793. case TE_LINK_SUBTLV_LCLIF_IPADDR:
  1794. sum += show_vty_link_subtlv_lclif_ipaddr (vty, tlvh);
  1795. break;
  1796. case TE_LINK_SUBTLV_RMTIF_IPADDR:
  1797. sum += show_vty_link_subtlv_rmtif_ipaddr (vty, tlvh);
  1798. break;
  1799. case TE_LINK_SUBTLV_TE_METRIC:
  1800. sum += show_vty_link_subtlv_te_metric (vty, tlvh);
  1801. break;
  1802. case TE_LINK_SUBTLV_MAX_BW:
  1803. sum += show_vty_link_subtlv_max_bw (vty, tlvh);
  1804. break;
  1805. case TE_LINK_SUBTLV_MAX_RSV_BW:
  1806. sum += show_vty_link_subtlv_max_rsv_bw (vty, tlvh);
  1807. break;
  1808. case TE_LINK_SUBTLV_UNRSV_BW:
  1809. sum += show_vty_link_subtlv_unrsv_bw (vty, tlvh);
  1810. break;
  1811. case TE_LINK_SUBTLV_RSC_CLSCLR:
  1812. sum += show_vty_link_subtlv_rsc_clsclr (vty, tlvh);
  1813. break;
  1814. case TE_LINK_SUBTLV_LRRID:
  1815. sum += show_vty_link_subtlv_lrrid (vty, tlvh);
  1816. break;
  1817. case TE_LINK_SUBTLV_LLRI:
  1818. sum += show_vty_link_subtlv_llri (vty, tlvh);
  1819. break;
  1820. case TE_LINK_SUBTLV_RIP:
  1821. sum += show_vty_link_subtlv_rip (vty, tlvh);
  1822. break;
  1823. case TE_LINK_SUBTLV_RAS:
  1824. sum += show_vty_link_subtlv_ras (vty, tlvh);
  1825. break;
  1826. case TE_LINK_SUBTLV_AV_DELAY:
  1827. sum += show_vty_link_subtlv_av_delay (vty, tlvh);
  1828. break;
  1829. case TE_LINK_SUBTLV_MM_DELAY:
  1830. sum += show_vty_link_subtlv_mm_delay (vty, tlvh);
  1831. break;
  1832. case TE_LINK_SUBTLV_DELAY_VAR:
  1833. sum += show_vty_link_subtlv_delay_var (vty, tlvh);
  1834. break;
  1835. case TE_LINK_SUBTLV_PKT_LOSS:
  1836. sum += show_vty_link_subtlv_pkt_loss (vty, tlvh);
  1837. break;
  1838. case TE_LINK_SUBTLV_RES_BW:
  1839. sum += show_vty_link_subtlv_res_bw (vty, tlvh);
  1840. break;
  1841. case TE_LINK_SUBTLV_AVA_BW:
  1842. sum += show_vty_link_subtlv_ava_bw (vty, tlvh);
  1843. break;
  1844. case TE_LINK_SUBTLV_USE_BW:
  1845. sum += show_vty_link_subtlv_use_bw (vty, tlvh);
  1846. break;
  1847. default:
  1848. sum += show_vty_unknown_tlv (vty, tlvh);
  1849. break;
  1850. }
  1851. }
  1852. return sum;
  1853. }
  1854. static void
  1855. ospf_mpls_te_show_info (struct vty *vty, struct ospf_lsa *lsa)
  1856. {
  1857. struct lsa_header *lsah = (struct lsa_header *) lsa->data;
  1858. struct te_tlv_header *tlvh, *next;
  1859. u_int16_t sum, total;
  1860. u_int16_t (* subfunc)(struct vty *vty, struct te_tlv_header *tlvh,
  1861. u_int16_t subtotal, u_int16_t total) = NULL;
  1862. sum = 0;
  1863. total = ntohs (lsah->length) - OSPF_LSA_HEADER_SIZE;
  1864. for (tlvh = TLV_HDR_TOP (lsah); sum < total;
  1865. tlvh = (next ? next : TLV_HDR_NEXT (tlvh)))
  1866. {
  1867. if (subfunc != NULL)
  1868. {
  1869. sum = (* subfunc)(vty, tlvh, sum, total);
  1870. next = (struct te_tlv_header *)((char *) tlvh + sum);
  1871. subfunc = NULL;
  1872. continue;
  1873. }
  1874. next = NULL;
  1875. switch (ntohs (tlvh->type))
  1876. {
  1877. case TE_TLV_ROUTER_ADDR:
  1878. sum += show_vty_router_addr (vty, tlvh);
  1879. break;
  1880. case TE_TLV_LINK:
  1881. sum += show_vty_link_header (vty, tlvh);
  1882. subfunc = ospf_mpls_te_show_link_subtlv;
  1883. next = tlvh + 1;
  1884. break;
  1885. default:
  1886. sum += show_vty_unknown_tlv (vty, tlvh);
  1887. break;
  1888. }
  1889. }
  1890. return;
  1891. }
  1892. static void
  1893. ospf_mpls_te_config_write_router (struct vty *vty)
  1894. {
  1895. if (OspfMplsTE.status == enabled)
  1896. {
  1897. vty_out (vty, " mpls-te on%s", VTY_NEWLINE);
  1898. vty_out (vty, " mpls-te router-address %s%s",
  1899. inet_ntoa (OspfMplsTE.router_addr.value), VTY_NEWLINE);
  1900. }
  1901. if (OspfMplsTE.inter_as == AS)
  1902. vty_out (vty, " mpls-te inter-as as%s", VTY_NEWLINE);
  1903. if (OspfMplsTE.inter_as == Area)
  1904. vty_out (vty, " mpls-te inter-as area %s %s",
  1905. inet_ntoa (OspfMplsTE.interas_areaid), VTY_NEWLINE);
  1906. return;
  1907. }
  1908. /*------------------------------------------------------------------------*
  1909. * Followings are vty command functions.
  1910. *------------------------------------------------------------------------*/
  1911. DEFUN (ospf_mpls_te_on,
  1912. ospf_mpls_te_on_cmd,
  1913. "mpls-te on",
  1914. MPLS_TE_STR
  1915. "Enable the MPLS-TE functionality\n")
  1916. {
  1917. struct listnode *node;
  1918. struct mpls_te_link *lp;
  1919. if (OspfMplsTE.status == enabled)
  1920. return CMD_SUCCESS;
  1921. if (IS_DEBUG_OSPF_EVENT)
  1922. zlog_debug ("MPLS-TE: OFF -> ON");
  1923. OspfMplsTE.status = enabled;
  1924. /* Reoriginate RFC3630 & RFC6827 Links */
  1925. ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule, REORIGINATE_THIS_LSA);
  1926. /* Reoriginate LSA if INTER-AS is always on */
  1927. if (OspfMplsTE.inter_as != Disable)
  1928. {
  1929. for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
  1930. {
  1931. if (IS_INTER_AS (lp->type))
  1932. {
  1933. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_THIS_LSA);
  1934. }
  1935. }
  1936. }
  1937. return CMD_SUCCESS;
  1938. }
  1939. DEFUN (no_ospf_mpls_te,
  1940. no_ospf_mpls_te_cmd,
  1941. "no mpls-te",
  1942. NO_STR
  1943. "Disable the MPLS-TE functionality\n")
  1944. {
  1945. struct listnode *node, *nnode;
  1946. struct mpls_te_link *lp;
  1947. if (OspfMplsTE.status == disabled)
  1948. return CMD_SUCCESS;
  1949. if (IS_DEBUG_OSPF_EVENT)
  1950. zlog_debug ("MPLS-TE: ON -> OFF");
  1951. OspfMplsTE.status = disabled;
  1952. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1953. if CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED)
  1954. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  1955. return CMD_SUCCESS;
  1956. }
  1957. DEFUN (ospf_mpls_te_router_addr,
  1958. ospf_mpls_te_router_addr_cmd,
  1959. "mpls-te router-address A.B.C.D",
  1960. MPLS_TE_STR
  1961. "Stable IP address of the advertising router\n"
  1962. "MPLS-TE router address in IPv4 address format\n")
  1963. {
  1964. struct te_tlv_router_addr *ra = &OspfMplsTE.router_addr;
  1965. struct in_addr value;
  1966. if (! inet_aton (argv[0], &value))
  1967. {
  1968. vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE);
  1969. return CMD_WARNING;
  1970. }
  1971. if (ntohs (ra->header.type) == 0
  1972. || ntohl (ra->value.s_addr) != ntohl (value.s_addr))
  1973. {
  1974. struct listnode *node, *nnode;
  1975. struct mpls_te_link *lp;
  1976. int need_to_reoriginate = 0;
  1977. set_mpls_te_router_addr (value);
  1978. if (OspfMplsTE.status == disabled)
  1979. goto out;
  1980. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1981. {
  1982. if ((lp->area == NULL) || IS_FLOOD_AS (lp->type))
  1983. continue;
  1984. if (!CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED))
  1985. {
  1986. need_to_reoriginate = 1;
  1987. break;
  1988. }
  1989. }
  1990. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  1991. {
  1992. if ((lp->area == NULL) || IS_FLOOD_AS (lp->type))
  1993. continue;
  1994. if (need_to_reoriginate)
  1995. SET_FLAG (lp->flags, LPFLG_LSA_FORCED_REFRESH);
  1996. else
  1997. ospf_mpls_te_lsa_schedule (lp, REFRESH_THIS_LSA);
  1998. }
  1999. if (need_to_reoriginate)
  2000. ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule, REORIGINATE_THIS_LSA);
  2001. }
  2002. out:
  2003. return CMD_SUCCESS;
  2004. }
  2005. static int
  2006. set_inter_as_mode (struct vty *vty, const char *mode_name,
  2007. const char *area_id)
  2008. {
  2009. enum inter_as_mode mode;
  2010. struct listnode *node;
  2011. struct mpls_te_link *lp;
  2012. int format;
  2013. if (OspfMplsTE.status == enabled)
  2014. {
  2015. /* Read and Check inter_as mode */
  2016. if (strcmp (mode_name, "as") == 0)
  2017. mode = AS;
  2018. else if (strcmp (mode_name, "area") == 0)
  2019. {
  2020. mode = Area;
  2021. VTY_GET_OSPF_AREA_ID (OspfMplsTE.interas_areaid, format, area_id);
  2022. }
  2023. else
  2024. {
  2025. vty_out (vty, "Unknown mode. Please choose between as or area%s",
  2026. VTY_NEWLINE);
  2027. return CMD_WARNING;
  2028. }
  2029. if (IS_DEBUG_OSPF_EVENT)
  2030. zlog_debug ("MPLS-TE: Inter-AS enable with %s flooding support",
  2031. mode2text[mode]);
  2032. /* Register new callbacks regarding the flooding scope (AS or Area) */
  2033. if (ospf_mpls_te_register (mode) < 0)
  2034. {
  2035. vty_out (vty, "Internal error: Unable to register Inter-AS functions%s",
  2036. VTY_NEWLINE);
  2037. return CMD_WARNING;
  2038. }
  2039. /* Enable mode and re-originate LSA if needed */
  2040. if ((OspfMplsTE.inter_as == Disable) && (mode != OspfMplsTE.inter_as))
  2041. {
  2042. OspfMplsTE.inter_as = mode;
  2043. /* Re-originate all InterAS-TEv2 LSA */
  2044. for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp))
  2045. {
  2046. if (IS_INTER_AS (lp->type))
  2047. {
  2048. if (mode == AS)
  2049. lp->type |= FLOOD_AS;
  2050. else
  2051. lp->type |= FLOOD_AREA;
  2052. ospf_mpls_te_lsa_schedule (lp, REORIGINATE_THIS_LSA);
  2053. }
  2054. }
  2055. }
  2056. else
  2057. {
  2058. vty_out (vty, "Please change Inter-AS support to disable first before going to mode %s%s",
  2059. mode2text[mode], VTY_NEWLINE);
  2060. return CMD_WARNING;
  2061. }
  2062. }
  2063. return CMD_SUCCESS;
  2064. }
  2065. DEFUN (ospf_mpls_te_inter_as_as,
  2066. ospf_mpls_te_inter_as_cmd,
  2067. "mpls-te inter-as as",
  2068. MPLS_TE_STR
  2069. "Configure MPLS-TE Inter-AS support\n"
  2070. "AS native mode self originate INTER_AS LSA with Type 11 (as flooding scope)\n")
  2071. {
  2072. return set_inter_as_mode (vty, "as", "");
  2073. }
  2074. DEFUN (ospf_mpls_te_inter_as_area,
  2075. ospf_mpls_te_inter_as_area_cmd,
  2076. "mpls-te inter-as area (A.B.C.D|<0-4294967295>)",
  2077. MPLS_TE_STR
  2078. "Configure MPLS-TE Inter-AS support\n"
  2079. "AREA native mode self originate INTER_AS LSA with Type 10 (area flooding scope)\n"
  2080. "OSPF area ID in IP format\n"
  2081. "OSPF area ID as decimal value\n")
  2082. {
  2083. return set_inter_as_mode (vty, "area", argv[0]);
  2084. }
  2085. DEFUN (no_ospf_mpls_te_inter_as,
  2086. no_ospf_mpls_te_inter_as_cmd,
  2087. "no mpls-te inter-as",
  2088. NO_STR
  2089. MPLS_TE_STR
  2090. "Disable MPLS-TE Inter-AS support\n")
  2091. {
  2092. struct listnode *node, *nnode;
  2093. struct mpls_te_link *lp;
  2094. if (IS_DEBUG_OSPF_EVENT)
  2095. zlog_debug ("MPLS-TE: Inter-AS support OFF");
  2096. if ((OspfMplsTE.status == enabled) && (OspfMplsTE.inter_as != Disable))
  2097. {
  2098. OspfMplsTE.inter_as = Disable;
  2099. /* Flush all Inter-AS LSA */
  2100. for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp))
  2101. if (IS_INTER_AS (lp->type) && CHECK_FLAG (lp->flags, LPFLG_LSA_ENGAGED))
  2102. ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA);
  2103. }
  2104. /* Deregister the Callbacks for Inter-AS suport */
  2105. ospf_mpls_te_unregister ();
  2106. return CMD_SUCCESS;
  2107. }
  2108. DEFUN (show_ip_ospf_mpls_te_router,
  2109. show_ip_ospf_mpls_te_router_cmd,
  2110. "show ip ospf mpls-te router",
  2111. SHOW_STR
  2112. IP_STR
  2113. OSPF_STR
  2114. "MPLS-TE information\n"
  2115. "MPLS-TE Router parameters\n")
  2116. {
  2117. if (OspfMplsTE.status == enabled)
  2118. {
  2119. vty_out (vty, "--- MPLS-TE router parameters ---%s", VTY_NEWLINE);
  2120. if (ntohs (OspfMplsTE.router_addr.header.type) != 0)
  2121. show_vty_router_addr (vty, &OspfMplsTE.router_addr.header);
  2122. else if (vty != NULL)
  2123. vty_out (vty, " N/A%s", VTY_NEWLINE);
  2124. }
  2125. return CMD_SUCCESS;
  2126. }
  2127. static void
  2128. show_mpls_te_link_sub (struct vty *vty, struct interface *ifp)
  2129. {
  2130. struct mpls_te_link *lp;
  2131. if ((OspfMplsTE.status == enabled)
  2132. && HAS_LINK_PARAMS(ifp)
  2133. && !if_is_loopback (ifp)
  2134. && if_is_up (ifp)
  2135. && ((lp = lookup_linkparams_by_ifp (ifp)) != NULL))
  2136. {
  2137. /* Continue only if interface is not passive or support Inter-AS TEv2 */
  2138. if (!(ospf_oi_count (ifp) > 0))
  2139. {
  2140. if (IS_INTER_AS (lp->type))
  2141. {
  2142. vty_out (vty, "-- Inter-AS TEv2 link parameters for %s --%s",
  2143. ifp->name, VTY_NEWLINE);
  2144. }
  2145. else
  2146. {
  2147. /* MPLS-TE is not activate on this interface */
  2148. /* or this interface is passive and Inter-AS TEv2 is not activate */
  2149. vty_out (vty, " %s: MPLS-TE is disabled on this interface%s",
  2150. ifp->name, VTY_NEWLINE);
  2151. return;
  2152. }
  2153. }
  2154. else
  2155. {
  2156. vty_out (vty, "-- MPLS-TE link parameters for %s --%s",
  2157. ifp->name, VTY_NEWLINE);
  2158. }
  2159. if (TLV_TYPE(lp->link_type) != 0)
  2160. show_vty_link_subtlv_link_type (vty, &lp->link_type.header);
  2161. if (TLV_TYPE(lp->link_id) != 0)
  2162. show_vty_link_subtlv_link_id (vty, &lp->link_id.header);
  2163. if (TLV_TYPE(lp->lclif_ipaddr) != 0)
  2164. show_vty_link_subtlv_lclif_ipaddr (vty, &lp->lclif_ipaddr.header);
  2165. if (TLV_TYPE(lp->rmtif_ipaddr) != 0)
  2166. show_vty_link_subtlv_rmtif_ipaddr (vty, &lp->rmtif_ipaddr.header);
  2167. if (TLV_TYPE(lp->rip) != 0)
  2168. show_vty_link_subtlv_rip (vty, &lp->rip.header);
  2169. if (TLV_TYPE(lp->ras) != 0)
  2170. show_vty_link_subtlv_ras (vty, &lp->ras.header);
  2171. if (TLV_TYPE(lp->te_metric) != 0)
  2172. show_vty_link_subtlv_te_metric (vty, &lp->te_metric.header);
  2173. if (TLV_TYPE(lp->max_bw) != 0)
  2174. show_vty_link_subtlv_max_bw (vty, &lp->max_bw.header);
  2175. if (TLV_TYPE(lp->max_rsv_bw) != 0)
  2176. show_vty_link_subtlv_max_rsv_bw (vty, &lp->max_rsv_bw.header);
  2177. if (TLV_TYPE(lp->unrsv_bw) != 0)
  2178. show_vty_link_subtlv_unrsv_bw (vty, &lp->unrsv_bw.header);
  2179. if (TLV_TYPE(lp->rsc_clsclr) != 0)
  2180. show_vty_link_subtlv_rsc_clsclr (vty, &lp->rsc_clsclr.header);
  2181. if (TLV_TYPE(lp->av_delay) != 0)
  2182. show_vty_link_subtlv_av_delay (vty, &lp->av_delay.header);
  2183. if (TLV_TYPE(lp->mm_delay) != 0)
  2184. show_vty_link_subtlv_mm_delay (vty, &lp->mm_delay.header);
  2185. if (TLV_TYPE(lp->delay_var) != 0)
  2186. show_vty_link_subtlv_delay_var (vty, &lp->delay_var.header);
  2187. if (TLV_TYPE(lp->pkt_loss) != 0)
  2188. show_vty_link_subtlv_pkt_loss (vty, &lp->pkt_loss.header);
  2189. if (TLV_TYPE(lp->res_bw) != 0)
  2190. show_vty_link_subtlv_res_bw (vty, &lp->res_bw.header);
  2191. if (TLV_TYPE(lp->ava_bw) != 0)
  2192. show_vty_link_subtlv_ava_bw (vty, &lp->ava_bw.header);
  2193. if (TLV_TYPE(lp->use_bw) != 0)
  2194. show_vty_link_subtlv_use_bw (vty, &lp->use_bw.header);
  2195. vty_out (vty, "---------------%s%s", VTY_NEWLINE, VTY_NEWLINE);
  2196. }
  2197. else
  2198. {
  2199. vty_out (vty, " %s: MPLS-TE is disabled on this interface%s",
  2200. ifp->name, VTY_NEWLINE);
  2201. }
  2202. return;
  2203. }
  2204. DEFUN (show_ip_ospf_mpls_te_link,
  2205. show_ip_ospf_mpls_te_link_cmd,
  2206. "show ip ospf mpls-te interface [INTERFACE]",
  2207. SHOW_STR
  2208. IP_STR
  2209. OSPF_STR
  2210. "MPLS-TE information\n"
  2211. "Interface information\n"
  2212. "Interface name\n")
  2213. {
  2214. struct interface *ifp;
  2215. struct listnode *node, *nnode;
  2216. /* Show All Interfaces. */
  2217. if (argc == 0)
  2218. {
  2219. for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
  2220. show_mpls_te_link_sub (vty, ifp);
  2221. }
  2222. /* Interface name is specified. */
  2223. else
  2224. {
  2225. if ((ifp = if_lookup_by_name (argv[0])) == NULL)
  2226. vty_out (vty, "No such interface name%s", VTY_NEWLINE);
  2227. else
  2228. show_mpls_te_link_sub (vty, ifp);
  2229. }
  2230. return CMD_SUCCESS;
  2231. }
  2232. static void
  2233. ospf_mpls_te_register_vty (void)
  2234. {
  2235. install_element (VIEW_NODE, &show_ip_ospf_mpls_te_router_cmd);
  2236. install_element (VIEW_NODE, &show_ip_ospf_mpls_te_link_cmd);
  2237. install_element (OSPF_NODE, &ospf_mpls_te_on_cmd);
  2238. install_element (OSPF_NODE, &no_ospf_mpls_te_cmd);
  2239. install_element (OSPF_NODE, &ospf_mpls_te_router_addr_cmd);
  2240. install_element (OSPF_NODE, &ospf_mpls_te_inter_as_cmd);
  2241. install_element (OSPF_NODE, &ospf_mpls_te_inter_as_area_cmd);
  2242. install_element (OSPF_NODE, &no_ospf_mpls_te_inter_as_cmd);
  2243. return;
  2244. }