ospf_te.c 52 KB

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