ospf_te.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*
  2. * This is an implementation of RFC3630, RFC5392 & RFC6827
  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 */
  28. /* Add support of RFC6827 (partial) */
  29. #ifndef _ZEBRA_OSPF_MPLS_TE_H
  30. #define _ZEBRA_OSPF_MPLS_TE_H
  31. /*
  32. * Opaque LSA's link state ID for Traffic Engineering is
  33. * structured as follows.
  34. *
  35. * 24 16 8 0
  36. * +--------+--------+--------+--------+
  37. * | 1 | MBZ |........|........|
  38. * +--------+--------+--------+--------+
  39. * |<-Type->|<Resv'd>|<-- Instance --->|
  40. *
  41. *
  42. * Type: IANA has assigned '1' for Traffic Engineering.
  43. * MBZ: Reserved, must be set to zero.
  44. * Instance: User may select an arbitrary 16-bit value.
  45. *
  46. */
  47. #define MAX_LEGAL_TE_INSTANCE_NUM (0xffff)
  48. #define LEGAL_TE_INSTANCE_RANGE(i) (0 <= (i) && (i) <= 0xffff)
  49. /*
  50. * 24 16 8 0
  51. * +--------+--------+--------+--------+ ---
  52. * | LS age |Options | 10 | A
  53. * +--------+--------+--------+--------+ |
  54. * | 1 | 0 | Instance | |
  55. * +--------+--------+--------+--------+ |
  56. * | Advertising router | | Standard (Opaque) LSA header;
  57. * +--------+--------+--------+--------+ | Only type-10 is used.
  58. * | LS sequence number | |
  59. * +--------+--------+--------+--------+ |
  60. * | LS checksum | Length | V
  61. * +--------+--------+--------+--------+ ---
  62. * | Type | Length | A
  63. * +--------+--------+--------+--------+ | TLV part for TE; Values might be
  64. * | Values ... | V structured as a set of sub-TLVs.
  65. * +--------+--------+--------+--------+ ---
  66. */
  67. /* Following define the type of TE link regarding the various RFC */
  68. #define STD_TE 0x01
  69. #define GMPLS 0x02
  70. #define INTER_AS 0x04
  71. #define PSEUDO_TE 0x08
  72. #define FLOOD_AREA 0x10
  73. #define FLOOD_AS 0x20
  74. #define EMULATED 0x80
  75. #define IS_STD_TE(x) (x & STD_TE)
  76. #define IS_PSEUDO_TE(x) (x & PSEUDO_TE)
  77. #define IS_INTER_AS(x) (x & INTER_AS)
  78. #define IS_EMULATED(x) (x & EMULATED)
  79. #define IS_FLOOD_AREA(x) (x & FLOOD_AREA)
  80. #define IS_FLOOD_AS(x) (x & FLOOD_AS)
  81. #define IS_INTER_AS_EMU(x) (x & INTER_AS & EMULATED)
  82. #define IS_INTER_AS_AS(x) (x & INTER_AS & FLOOD_AS)
  83. /* Flags to manage TE Link LSA */
  84. #define LPFLG_LSA_INACTIVE 0x0
  85. #define LPFLG_LSA_ACTIVE 0x1
  86. #define LPFLG_LSA_ENGAGED 0x2
  87. #define LPFLG_LOOKUP_DONE 0x4
  88. #define LPFLG_LSA_FORCED_REFRESH 0x8
  89. /*
  90. * Following section defines TLV (tag, length, value) structures,
  91. * used for Traffic Engineering.
  92. */
  93. struct te_tlv_header
  94. {
  95. u_int16_t type; /* TE_TLV_XXX (see below) */
  96. u_int16_t length; /* Value portion only, in octets */
  97. };
  98. #define TLV_HDR_SIZE \
  99. (sizeof (struct te_tlv_header))
  100. #define TLV_BODY_SIZE(tlvh) \
  101. (ROUNDUP (ntohs ((tlvh)->length), sizeof (u_int32_t)))
  102. #define TLV_SIZE(tlvh) \
  103. (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))
  104. #define TLV_HDR_TOP(lsah) \
  105. (struct te_tlv_header *)((char *)(lsah) + OSPF_LSA_HEADER_SIZE)
  106. #define TLV_HDR_NEXT(tlvh) \
  107. (struct te_tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))
  108. #define TLV_HDR_SUBTLV(tlvh) \
  109. (struct te_tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE)
  110. #define TLV_TYPE(tlvh) tlvh.header.type
  111. #define TLV_LEN(tlvh) tlvh.header.length
  112. #define TLV_HDR(tlvh) tlvh.header
  113. /*
  114. * Following section defines TLV body parts.
  115. */
  116. /* Router Address TLV */ /* Mandatory */
  117. #define TE_TLV_ROUTER_ADDR 1
  118. struct te_tlv_router_addr
  119. {
  120. struct te_tlv_header header; /* Value length is 4 octets. */
  121. struct in_addr value;
  122. };
  123. /* Link TLV */
  124. #define TE_TLV_LINK 2
  125. struct te_tlv_link
  126. {
  127. struct te_tlv_header header;
  128. /* A set of link-sub-TLVs will follow. */
  129. };
  130. #define TE_LINK_SUBTLV_DEF_SIZE 4
  131. /* Link Type Sub-TLV */ /* Mandatory */
  132. #define TE_LINK_SUBTLV_LINK_TYPE 1
  133. #define TE_LINK_SUBTLV_TYPE_SIZE 1
  134. struct te_link_subtlv_link_type
  135. {
  136. struct te_tlv_header header; /* Value length is 1 octet. */
  137. struct
  138. {
  139. #define LINK_TYPE_SUBTLV_VALUE_PTP 1
  140. #define LINK_TYPE_SUBTLV_VALUE_MA 2
  141. u_char value;
  142. u_char padding[3];
  143. } link_type;
  144. };
  145. /* Link Sub-TLV: Link ID */ /* Mandatory */
  146. #define TE_LINK_SUBTLV_LINK_ID 2
  147. struct te_link_subtlv_link_id
  148. {
  149. struct te_tlv_header header; /* Value length is 4 octets. */
  150. struct in_addr value; /* Same as router-lsa's link-id. */
  151. };
  152. /* Link Sub-TLV: Local Interface IP Address */ /* Optional */
  153. #define TE_LINK_SUBTLV_LCLIF_IPADDR 3
  154. struct te_link_subtlv_lclif_ipaddr
  155. {
  156. struct te_tlv_header header; /* Value length is 4 x N octets. */
  157. struct in_addr value[1]; /* Local IP address(es). */
  158. };
  159. /* Link Sub-TLV: Remote Interface IP Address */ /* Optional */
  160. #define TE_LINK_SUBTLV_RMTIF_IPADDR 4
  161. struct te_link_subtlv_rmtif_ipaddr
  162. {
  163. struct te_tlv_header header; /* Value length is 4 x N octets. */
  164. struct in_addr value[1]; /* Neighbor's IP address(es). */
  165. };
  166. /* Link Sub-TLV: Traffic Engineering Metric */ /* Optional */
  167. #define TE_LINK_SUBTLV_TE_METRIC 5
  168. struct te_link_subtlv_te_metric
  169. {
  170. struct te_tlv_header header; /* Value length is 4 octets. */
  171. u_int32_t value; /* Link metric for TE purpose. */
  172. };
  173. /* Link Sub-TLV: Maximum Bandwidth */ /* Optional */
  174. #define TE_LINK_SUBTLV_MAX_BW 6
  175. struct te_link_subtlv_max_bw
  176. {
  177. struct te_tlv_header header; /* Value length is 4 octets. */
  178. float value; /* bytes/sec */
  179. };
  180. /* Link Sub-TLV: Maximum Reservable Bandwidth */ /* Optional */
  181. #define TE_LINK_SUBTLV_MAX_RSV_BW 7
  182. struct te_link_subtlv_max_rsv_bw
  183. {
  184. struct te_tlv_header header; /* Value length is 4 octets. */
  185. float value; /* bytes/sec */
  186. };
  187. /* Link Sub-TLV: Unreserved Bandwidth */ /* Optional */
  188. #define TE_LINK_SUBTLV_UNRSV_BW 8
  189. #define TE_LINK_SUBTLV_UNRSV_SIZE 32
  190. struct te_link_subtlv_unrsv_bw
  191. {
  192. struct te_tlv_header header; /* Value length is 32 octets. */
  193. float value[MAX_CLASS_TYPE]; /* One for each priority level. */
  194. };
  195. /* Link Sub-TLV: Resource Class/Color */ /* Optional */
  196. #define TE_LINK_SUBTLV_RSC_CLSCLR 9
  197. struct te_link_subtlv_rsc_clsclr
  198. {
  199. struct te_tlv_header header; /* Value length is 4 octets. */
  200. u_int32_t value; /* Admin. group membership. */
  201. };
  202. /* For RFC6827 */
  203. /* Local and Remote TE Router ID */
  204. #define TE_LINK_SUBTLV_LRRID 10
  205. #define TE_LINK_SUBTLV_LRRID_SIZE 8
  206. struct te_link_subtlv_lrrid
  207. {
  208. struct te_tlv_header header; /* Value length is 8 octets. */
  209. struct in_addr local; /* Local TE Router Identifier */
  210. struct in_addr remote; /* Remote TE Router Identifier */
  211. };
  212. /* RFC4203: Link Local/Remote Identifiers */
  213. #define TE_LINK_SUBTLV_LLRI 11
  214. #define TE_LINK_SUBTLV_LLRI_SIZE 8
  215. struct te_link_subtlv_llri
  216. {
  217. struct te_tlv_header header; /* Value length is 8 octets. */
  218. u_int32_t local; /* Link Local Identifier */
  219. u_int32_t remote; /* Link Remote Identifier */
  220. };
  221. /* Inter-RA Export Upward sub-TLV (12) and Inter-RA Export Downward sub-TLV (13) (RFC6827bis) are not yet supported */
  222. /* SUBTLV 14-16 (RFC4203) are not yet supported */
  223. /* Bandwidth Constraints sub-TLV (17) (RFC4124) is not yet supported */
  224. /* SUBLV 18-20 are for OSPFv6 TE (RFC5329). see ospf6d */
  225. /* For RFC 5392 */
  226. /* Remote AS Number sub-TLV */
  227. #define TE_LINK_SUBTLV_RAS 21
  228. struct te_link_subtlv_ras
  229. {
  230. struct te_tlv_header header; /* Value length is 4 octets. */
  231. u_int32_t value; /* Remote AS number */
  232. };
  233. /* IPv4 Remote ASBR ID Sub-TLV */
  234. #define TE_LINK_SUBTLV_RIP 22
  235. struct te_link_subtlv_rip
  236. {
  237. struct te_tlv_header header; /* Value length is 4 octets. */
  238. struct in_addr value; /* Remote ASBR IP address */
  239. };
  240. /* SUBTLV 24 is IPv6 Remote ASBR ID (RFC5392). see ospf6d */
  241. /* SUBTLV 23 (RFC5330) and 25 (RFC6001) are not yet supported */
  242. /* SUBTLV 26 (RFC7308) is not yet supported */
  243. /* RFC7471 */
  244. /* Link Sub-TLV: Average Link Delay */ /* Optional */
  245. #define TE_LINK_SUBTLV_AV_DELAY 27
  246. struct te_link_subtlv_av_delay
  247. {
  248. struct te_tlv_header header; /* Value length is 4 bytes. */
  249. u_int32_t value; /* delay in micro-seconds only 24 bits => 0 ... 16777215
  250. with Anomalous Bit as Upper most bit */
  251. };
  252. /* Link Sub-TLV: Low/High Link Delay */
  253. #define TE_LINK_SUBTLV_MM_DELAY 28
  254. #define TE_LINK_SUBTLV_MM_DELAY_SIZE 8
  255. struct te_link_subtlv_mm_delay
  256. {
  257. struct te_tlv_header header; /* Value length is 8 bytes. */
  258. u_int32_t low; /* low delay in micro-seconds only 24 bits => 0 ... 16777215
  259. with Anomalous Bit (A) as Upper most bit */
  260. u_int32_t high; /* high delay in micro-seconds only 24 bits => 0 ... 16777215 */
  261. };
  262. /* Link Sub-TLV: Link Delay Variation i.e. Jitter */
  263. #define TE_LINK_SUBTLV_DELAY_VAR 29
  264. struct te_link_subtlv_delay_var
  265. {
  266. struct te_tlv_header header; /* Value length is 4 bytes. */
  267. u_int32_t value; /* interval in micro-seconds only 24 bits => 0 ... 16777215 */
  268. };
  269. /* Link Sub-TLV: Routine Unidirectional Link Packet Loss */
  270. #define TE_LINK_SUBTLV_PKT_LOSS 30
  271. struct te_link_subtlv_pkt_loss
  272. {
  273. struct te_tlv_header header; /* Value length is 4 bytes. */
  274. u_int32_t value; /* in percentage of total traffic only 24 bits (2^24 - 2)
  275. with Anomalous Bit as Upper most bit */
  276. };
  277. /* Link Sub-TLV: Unidirectional Residual Bandwidth */ /* Optional */
  278. #define TE_LINK_SUBTLV_RES_BW 31
  279. struct te_link_subtlv_res_bw
  280. {
  281. struct te_tlv_header header; /* Value length is 4 bytes. */
  282. float value; /* bandwidth in IEEE floating point format with units in bytes per second */
  283. };
  284. /* Link Sub-TLV: Unidirectional Available Bandwidth */ /* Optional */
  285. #define TE_LINK_SUBTLV_AVA_BW 32
  286. struct te_link_subtlv_ava_bw
  287. {
  288. struct te_tlv_header header; /* Value length is 4 octets. */
  289. float value; /* bandwidth in IEEE floating point format with units in bytes per second */
  290. };
  291. /* Link Sub-TLV: Unidirectional Utilized Bandwidth */ /* Optional */
  292. #define TE_LINK_SUBTLV_USE_BW 33
  293. struct te_link_subtlv_use_bw
  294. {
  295. struct te_tlv_header header; /* Value length is 4 octets. */
  296. float value; /* bandwidth in IEEE floating point format with units in bytes per second */
  297. };
  298. #define TE_LINK_SUBTLV_MAX 34 /* Last SUBTLV + 1 */
  299. /* Here are "non-official" architectural constants. */
  300. #define MPLS_TE_MINIMUM_BANDWIDTH 1.0 /* Reasonable? *//* XXX */
  301. /* Following declaration concerns the MPLS-TE and LINk-TE management */
  302. typedef enum _opcode_t
  303. { REORIGINATE_THIS_LSA, REFRESH_THIS_LSA, FLUSH_THIS_LSA } opcode_t;
  304. typedef enum _status_t
  305. { disabled, enabled } status_t;
  306. /* Mode for Inter-AS Opaque-LSA */
  307. enum inter_as_mode { Disable, AS, Area };
  308. struct te_link_subtlv
  309. {
  310. struct te_tlv_header header;
  311. union
  312. {
  313. u_int32_t link_type;
  314. struct in_addr link_id;
  315. struct in_addr lclif;
  316. struct in_addr rmtif;
  317. u_int32_t te_metric;
  318. float max_bw;
  319. float max_rsv_bw;
  320. float unrsv[8];
  321. u_int32_t rsc_clsclr;
  322. u_int32_t llri[2];
  323. u_int32_t ras;
  324. struct in_addr rip;
  325. struct in_addr lrrid[2];
  326. u_int32_t av_delay;
  327. u_int32_t mm_delay;
  328. u_int32_t delay_var;
  329. u_int32_t pkt_loss;
  330. float res_bw;
  331. float ava_bw;
  332. float use_bw;
  333. } value;
  334. };
  335. /* Following structure are internal use only. */
  336. struct ospf_mpls_te
  337. {
  338. /* Status of MPLS-TE: enable or disable */
  339. status_t status;
  340. /* RFC5392 */
  341. enum inter_as_mode inter_as;
  342. struct in_addr interas_areaid;
  343. /* List elements are zebra-interfaces (ifp), not ospf-interfaces (oi). */
  344. struct list *iflist;
  345. /* Store Router-TLV in network byte order. */
  346. struct te_tlv_router_addr router_addr;
  347. };
  348. struct mpls_te_link
  349. {
  350. /*
  351. * According to MPLS-TE (draft) specification, 24-bit Opaque-ID field
  352. * is subdivided into 8-bit "unused" field and 16-bit "instance" field.
  353. * In this implementation, each Link-TLV has its own instance.
  354. */
  355. u_int32_t instance;
  356. /* Reference pointer to a Zebra-interface. */
  357. struct interface *ifp;
  358. /* Area info in which this MPLS-TE link belongs to. */
  359. struct ospf_area *area;
  360. /* Flags to manage this link parameters. */
  361. u_int32_t flags;
  362. /* Type of MPLS-TE link: RFC3630, RFC5392, RFC5392 emulated, RFC6827 */
  363. u_int8_t type;
  364. /* Store Link-TLV in network byte order. */
  365. /* RFC3630 & RFC6827 / RFC 6827 */
  366. struct te_tlv_link link_header;
  367. struct te_link_subtlv_link_type link_type;
  368. struct te_link_subtlv_link_id link_id;
  369. struct te_link_subtlv_lclif_ipaddr lclif_ipaddr;
  370. struct te_link_subtlv_rmtif_ipaddr rmtif_ipaddr;
  371. struct te_link_subtlv_te_metric te_metric;
  372. struct te_link_subtlv_max_bw max_bw;
  373. struct te_link_subtlv_max_rsv_bw max_rsv_bw;
  374. struct te_link_subtlv_unrsv_bw unrsv_bw;
  375. struct te_link_subtlv_rsc_clsclr rsc_clsclr;
  376. /* RFC4203 */
  377. struct te_link_subtlv_llri llri;
  378. /* RFC5392 */
  379. struct te_link_subtlv_ras ras;
  380. struct te_link_subtlv_rip rip;
  381. /* RFC6827 */
  382. struct te_link_subtlv_lrrid lrrid;
  383. /* RFC7471 */
  384. struct te_link_subtlv_av_delay av_delay;
  385. struct te_link_subtlv_mm_delay mm_delay;
  386. struct te_link_subtlv_delay_var delay_var;
  387. struct te_link_subtlv_pkt_loss pkt_loss;
  388. struct te_link_subtlv_res_bw res_bw;
  389. struct te_link_subtlv_ava_bw ava_bw;
  390. struct te_link_subtlv_use_bw use_bw;
  391. struct in_addr adv_router;
  392. struct in_addr id;
  393. };
  394. /* Prototypes. */
  395. extern int ospf_mpls_te_init (void);
  396. extern void ospf_mpls_te_term (void);
  397. extern struct ospf_mpls_te *get_ospf_mpls_te (void);
  398. extern void ospf_mpls_te_update_if (struct interface *);
  399. extern void ospf_mpls_te_lsa_schedule (struct mpls_te_link *, opcode_t);
  400. extern u_int32_t get_mpls_te_instance_value (void);
  401. extern void set_linkparams_llri (struct mpls_te_link *, u_int32_t, u_int32_t);
  402. extern void set_linkparams_lrrid (struct mpls_te_link *, struct in_addr, struct in_addr);
  403. #endif /* _ZEBRA_OSPF_MPLS_TE_H */