forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathospf_te.c
4654 lines (4026 loc) · 125 KB
/
ospf_te.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* This is an implementation of RFC3630
* Copyright (C) 2001 KDD R&D Laboratories, Inc.
* http://www.kddlabs.co.jp/
*
* Copyright (C) 2012 Orange Labs
* http://www.orange.com
*/
/* Add support of RFC7471 */
/* Add support of RFC5392, RFC6827 */
#include <zebra.h>
#include <math.h>
#include "linklist.h"
#include "prefix.h"
#include "vrf.h"
#include "if.h"
#include "table.h"
#include "memory.h"
#include "command.h"
#include "vty.h"
#include "stream.h"
#include "log.h"
#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "network.h"
#include "link_state.h"
#include "zclient.h"
#include "printfrr.h"
#include <lib/json.h>
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_ism.h"
#include "ospfd/ospf_asbr.h"
#include "ospfd/ospf_lsa.h"
#include "ospfd/ospf_lsdb.h"
#include "ospfd/ospf_neighbor.h"
#include "ospfd/ospf_nsm.h"
#include "ospfd/ospf_flood.h"
#include "ospfd/ospf_packet.h"
#include "ospfd/ospf_spf.h"
#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_route.h"
#include "ospfd/ospf_ase.h"
#include "ospfd/ospf_zebra.h"
#include "ospfd/ospf_te.h"
#include "ospfd/ospf_sr.h"
#include "ospfd/ospf_ri.h"
#include "ospfd/ospf_ext.h"
#include "ospfd/ospf_vty.h"
#include "ospfd/ospf_errors.h"
/*
* Global variable to manage Opaque-LSA/MPLS-TE on this node.
* Note that all parameter values are stored in network byte order.
*/
struct ospf_mpls_te OspfMplsTE;
static const char *const mode2text[] = {"Off", "AS", "Area"};
/*------------------------------------------------------------------------*
* Following are initialize/terminate functions for MPLS-TE handling.
*------------------------------------------------------------------------*/
static int ospf_mpls_te_new_if(struct interface *ifp);
static int ospf_mpls_te_del_if(struct interface *ifp);
static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_status);
static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_status);
static void ospf_mpls_te_config_write_router(struct vty *vty);
static void ospf_mpls_te_show_info(struct vty *vty, struct json_object *json,
struct ospf_lsa *lsa);
static int ospf_mpls_te_lsa_originate_area(void *arg);
static int ospf_mpls_te_lsa_inter_as_as(void *arg);
static int ospf_mpls_te_lsa_inter_as_area(void *arg);
static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa);
static int ospf_mpls_te_lsa_update(struct ospf_lsa *lsa);
static int ospf_mpls_te_lsa_delete(struct ospf_lsa *lsa);
static void del_mpls_te_link(void *val);
static void ospf_mpls_te_register_vty(void);
int ospf_mpls_te_init(void)
{
int rc;
/* Register Opaque AREA LSA Type 1 for Traffic Engineering */
rc = ospf_register_opaque_functab(
OSPF_OPAQUE_AREA_LSA,
OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA,
ospf_mpls_te_new_if,
ospf_mpls_te_del_if,
ospf_mpls_te_ism_change,
ospf_mpls_te_nsm_change,
ospf_mpls_te_config_write_router,
NULL, /* ospf_mpls_te_config_write_if */
NULL, /* ospf_mpls_te_config_write_debug */
ospf_mpls_te_show_info, ospf_mpls_te_lsa_originate_area,
ospf_mpls_te_lsa_refresh,
ospf_mpls_te_lsa_update, /* ospf_mpls_te_new_lsa_hook */
ospf_mpls_te_lsa_delete /* ospf_mpls_te_del_lsa_hook */);
if (rc != 0) {
flog_warn(
EC_OSPF_OPAQUE_REGISTRATION,
"MPLS-TE (%s): Failed to register Traffic Engineering functions",
__func__);
return rc;
}
/*
* Wee need also to register Opaque LSA Type 6 i.e. Inter-AS RFC5392 for
* both AREA and AS at least to have the possibility to call the show()
* function when looking to the opaque LSA of the OSPF database.
*/
rc = ospf_register_opaque_functab(OSPF_OPAQUE_AREA_LSA,
OPAQUE_TYPE_INTER_AS_LSA, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
ospf_mpls_te_show_info,
ospf_mpls_te_lsa_inter_as_area,
ospf_mpls_te_lsa_refresh, NULL, NULL);
if (rc != 0) {
flog_warn(
EC_OSPF_OPAQUE_REGISTRATION,
"MPLS-TE (%s): Failed to register Inter-AS with Area scope",
__func__);
return rc;
}
rc = ospf_register_opaque_functab(OSPF_OPAQUE_AS_LSA,
OPAQUE_TYPE_INTER_AS_LSA, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
ospf_mpls_te_show_info,
ospf_mpls_te_lsa_inter_as_as,
ospf_mpls_te_lsa_refresh, NULL, NULL);
if (rc != 0) {
flog_warn(
EC_OSPF_OPAQUE_REGISTRATION,
"MPLS-TE (%s): Failed to register Inter-AS with AS scope",
__func__);
return rc;
}
memset(&OspfMplsTE, 0, sizeof(OspfMplsTE));
OspfMplsTE.enabled = false;
OspfMplsTE.export = false;
OspfMplsTE.inter_as = Off;
OspfMplsTE.iflist = list_new();
OspfMplsTE.iflist->del = del_mpls_te_link;
ospf_mpls_te_register_vty();
return rc;
}
void ospf_mpls_te_term(void)
{
list_delete(&OspfMplsTE.iflist);
ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA,
OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA);
ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA,
OPAQUE_TYPE_INTER_AS_LSA);
ospf_delete_opaque_functab(OSPF_OPAQUE_AS_LSA,
OPAQUE_TYPE_INTER_AS_LSA);
OspfMplsTE.enabled = false;
OspfMplsTE.inter_as = Off;
OspfMplsTE.export = false;
return;
}
void ospf_mpls_te_finish(void)
{
OspfMplsTE.enabled = false;
OspfMplsTE.inter_as = Off;
OspfMplsTE.export = false;
}
/*------------------------------------------------------------------------*
* Following are control functions for MPLS-TE parameters management.
*------------------------------------------------------------------------*/
static void del_mpls_te_link(void *val)
{
XFREE(MTYPE_OSPF_MPLS_TE, val);
return;
}
static uint32_t get_mpls_te_instance_value(void)
{
static uint32_t seqno = 0;
if (seqno < MAX_LEGAL_TE_INSTANCE_NUM)
seqno += 1;
else
seqno = 1; /* Avoid zero. */
return seqno;
}
static struct mpls_te_link *lookup_linkparams_by_ifp(struct interface *ifp)
{
struct listnode *node, *nnode;
struct mpls_te_link *lp;
for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp))
if (lp->ifp == ifp)
return lp;
return NULL;
}
static struct mpls_te_link *lookup_linkparams_by_instance(struct ospf_lsa *lsa)
{
struct listnode *node;
struct mpls_te_link *lp;
unsigned int key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr));
for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp))
if (lp->instance == key)
return lp;
ote_debug("MPLS-TE (%s): Entry not found: key(%x)", __func__, key);
return NULL;
}
static void ospf_mpls_te_foreach_area(
void (*func)(struct mpls_te_link *lp, enum lsa_opcode sched_opcode),
enum lsa_opcode sched_opcode)
{
struct listnode *node, *nnode;
struct listnode *node2;
struct mpls_te_link *lp;
struct ospf_area *area;
for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) {
/* Skip Inter-AS TEv2 Links */
if (IS_INTER_AS(lp->type))
continue;
if ((area = lp->area) == NULL)
continue;
if (CHECK_FLAG(lp->flags, LPFLG_LOOKUP_DONE))
continue;
if (func != NULL)
(*func)(lp, sched_opcode);
for (node2 = listnextnode(node); node2;
node2 = listnextnode(node2))
if ((lp = listgetdata(node2)) != NULL)
if (lp->area != NULL)
if (IPV4_ADDR_SAME(&lp->area->area_id,
&area->area_id))
SET_FLAG(lp->flags,
LPFLG_LOOKUP_DONE);
}
for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp))
if (lp->area != NULL)
UNSET_FLAG(lp->flags, LPFLG_LOOKUP_DONE);
return;
}
static void set_mpls_te_router_addr(struct in_addr ipv4)
{
OspfMplsTE.router_addr.header.type = htons(TE_TLV_ROUTER_ADDR);
OspfMplsTE.router_addr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
OspfMplsTE.router_addr.value = ipv4;
return;
}
static void set_linkparams_link_header(struct mpls_te_link *lp)
{
uint16_t length = 0;
/* TE_LINK_SUBTLV_LINK_TYPE */
if (ntohs(lp->link_type.header.type) != 0)
length += TLV_SIZE(&lp->link_type.header);
/* TE_LINK_SUBTLV_LINK_ID */
if (ntohs(lp->link_id.header.type) != 0)
length += TLV_SIZE(&lp->link_id.header);
/* TE_LINK_SUBTLV_LCLIF_IPADDR */
if (lp->lclif_ipaddr.header.type != 0)
length += TLV_SIZE(&lp->lclif_ipaddr.header);
/* TE_LINK_SUBTLV_RMTIF_IPADDR */
if (lp->rmtif_ipaddr.header.type != 0)
length += TLV_SIZE(&lp->rmtif_ipaddr.header);
/* TE_LINK_SUBTLV_TE_METRIC */
if (ntohs(lp->te_metric.header.type) != 0)
length += TLV_SIZE(&lp->te_metric.header);
/* TE_LINK_SUBTLV_MAX_BW */
if (ntohs(lp->max_bw.header.type) != 0)
length += TLV_SIZE(&lp->max_bw.header);
/* TE_LINK_SUBTLV_MAX_RSV_BW */
if (ntohs(lp->max_rsv_bw.header.type) != 0)
length += TLV_SIZE(&lp->max_rsv_bw.header);
/* TE_LINK_SUBTLV_UNRSV_BW */
if (ntohs(lp->unrsv_bw.header.type) != 0)
length += TLV_SIZE(&lp->unrsv_bw.header);
/* TE_LINK_SUBTLV_RSC_CLSCLR */
if (ntohs(lp->rsc_clsclr.header.type) != 0)
length += TLV_SIZE(&lp->rsc_clsclr.header);
/* TE_LINK_SUBTLV_LLRI */
if (ntohs(lp->llri.header.type) != 0)
length += TLV_SIZE(&lp->llri.header);
/* TE_LINK_SUBTLV_RIP */
if (ntohs(lp->rip.header.type) != 0)
length += TLV_SIZE(&lp->rip.header);
/* TE_LINK_SUBTLV_RAS */
if (ntohs(lp->ras.header.type) != 0)
length += TLV_SIZE(&lp->ras.header);
/* TE_LINK_SUBTLV_LRRID */
if (ntohs(lp->lrrid.header.type) != 0)
length += TLV_SIZE(&lp->lrrid.header);
/* TE_LINK_SUBTLV_AV_DELAY */
if (ntohs(lp->av_delay.header.type) != 0)
length += TLV_SIZE(&lp->av_delay.header);
/* TE_LINK_SUBTLV_MM_DELAY */
if (ntohs(lp->mm_delay.header.type) != 0)
length += TLV_SIZE(&lp->mm_delay.header);
/* TE_LINK_SUBTLV_DELAY_VAR */
if (ntohs(lp->delay_var.header.type) != 0)
length += TLV_SIZE(&lp->delay_var.header);
/* TE_LINK_SUBTLV_PKT_LOSS */
if (ntohs(lp->pkt_loss.header.type) != 0)
length += TLV_SIZE(&lp->pkt_loss.header);
/* TE_LINK_SUBTLV_RES_BW */
if (ntohs(lp->res_bw.header.type) != 0)
length += TLV_SIZE(&lp->res_bw.header);
/* TE_LINK_SUBTLV_AVA_BW */
if (ntohs(lp->ava_bw.header.type) != 0)
length += TLV_SIZE(&lp->ava_bw.header);
/* TE_LINK_SUBTLV_USE_BW */
if (ntohs(lp->use_bw.header.type) != 0)
length += TLV_SIZE(&lp->use_bw.header);
lp->link_header.header.type = htons(TE_TLV_LINK);
lp->link_header.header.length = htons(length);
return;
}
static void set_linkparams_link_type(struct ospf_interface *oi,
struct mpls_te_link *lp)
{
lp->link_type.header.type = htons(TE_LINK_SUBTLV_LINK_TYPE);
lp->link_type.header.length = htons(TE_LINK_SUBTLV_TYPE_SIZE);
switch (oi->type) {
case OSPF_IFTYPE_POINTOPOINT:
lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_PTP;
break;
case OSPF_IFTYPE_BROADCAST:
case OSPF_IFTYPE_NBMA:
lp->link_type.link_type.value = LINK_TYPE_SUBTLV_VALUE_MA;
break;
default:
/* Not supported yet. */ /* XXX */
lp->link_type.header.type = htons(0);
break;
}
return;
}
static void set_linkparams_link_id(struct mpls_te_link *lp,
struct in_addr link_id)
{
lp->link_id.header.type = htons(TE_LINK_SUBTLV_LINK_ID);
lp->link_id.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->link_id.value = link_id;
return;
}
static void set_linkparams_lclif_ipaddr(struct mpls_te_link *lp,
struct in_addr lclif)
{
lp->lclif_ipaddr.header.type = htons(TE_LINK_SUBTLV_LCLIF_IPADDR);
lp->lclif_ipaddr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->lclif_ipaddr.value[0] = lclif;
return;
}
static void set_linkparams_rmtif_ipaddr(struct mpls_te_link *lp,
struct in_addr rmtif)
{
lp->rmtif_ipaddr.header.type = htons(TE_LINK_SUBTLV_RMTIF_IPADDR);
lp->rmtif_ipaddr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->rmtif_ipaddr.value[0] = rmtif;
return;
}
static void set_linkparams_te_metric(struct mpls_te_link *lp,
uint32_t te_metric)
{
lp->te_metric.header.type = htons(TE_LINK_SUBTLV_TE_METRIC);
lp->te_metric.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->te_metric.value = htonl(te_metric);
return;
}
static void set_linkparams_max_bw(struct mpls_te_link *lp, float fp)
{
lp->max_bw.header.type = htons(TE_LINK_SUBTLV_MAX_BW);
lp->max_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->max_bw.value = htonf(fp);
return;
}
static void set_linkparams_max_rsv_bw(struct mpls_te_link *lp, float fp)
{
lp->max_rsv_bw.header.type = htons(TE_LINK_SUBTLV_MAX_RSV_BW);
lp->max_rsv_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->max_rsv_bw.value = htonf(fp);
return;
}
static void set_linkparams_unrsv_bw(struct mpls_te_link *lp, int priority,
float fp)
{
/* Note that TLV-length field is the size of array. */
lp->unrsv_bw.header.type = htons(TE_LINK_SUBTLV_UNRSV_BW);
lp->unrsv_bw.header.length = htons(TE_LINK_SUBTLV_UNRSV_SIZE);
lp->unrsv_bw.value[priority] = htonf(fp);
return;
}
static void set_linkparams_rsc_clsclr(struct mpls_te_link *lp,
uint32_t classcolor)
{
lp->rsc_clsclr.header.type = htons(TE_LINK_SUBTLV_RSC_CLSCLR);
lp->rsc_clsclr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->rsc_clsclr.value = htonl(classcolor);
return;
}
static void set_linkparams_inter_as(struct mpls_te_link *lp,
struct in_addr addr, uint32_t as)
{
/* Set the Remote ASBR IP address and then the associated AS number */
lp->rip.header.type = htons(TE_LINK_SUBTLV_RIP);
lp->rip.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->rip.value = addr;
lp->ras.header.type = htons(TE_LINK_SUBTLV_RAS);
lp->ras.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->ras.value = htonl(as);
/* Set Type & Flooding flag accordingly */
lp->type = INTER_AS;
if (OspfMplsTE.inter_as == AS)
SET_FLAG(lp->flags, LPFLG_LSA_FLOOD_AS);
else
UNSET_FLAG(lp->flags, LPFLG_LSA_FLOOD_AS);
}
static void unset_linkparams_inter_as(struct mpls_te_link *lp)
{
/* Reset the Remote ASBR IP address and then the associated AS number */
lp->rip.header.type = htons(0);
lp->rip.header.length = htons(0);
lp->rip.value.s_addr = htonl(0);
lp->ras.header.type = htons(0);
lp->ras.header.length = htons(0);
lp->ras.value = htonl(0);
/* Reset Type & Flooding flag accordingly */
lp->type = STD_TE;
UNSET_FLAG(lp->flags, LPFLG_LSA_FLOOD_AS);
}
void set_linkparams_llri(struct mpls_te_link *lp, uint32_t local,
uint32_t remote)
{
lp->llri.header.type = htons(TE_LINK_SUBTLV_LLRI);
lp->llri.header.length = htons(TE_LINK_SUBTLV_LLRI_SIZE);
lp->llri.local = htonl(local);
lp->llri.remote = htonl(remote);
}
void set_linkparams_lrrid(struct mpls_te_link *lp, struct in_addr local,
struct in_addr remote)
{
lp->lrrid.header.type = htons(TE_LINK_SUBTLV_LRRID);
lp->lrrid.header.length = htons(TE_LINK_SUBTLV_LRRID_SIZE);
lp->lrrid.local.s_addr = local.s_addr;
lp->lrrid.remote.s_addr = remote.s_addr;
}
static void set_linkparams_av_delay(struct mpls_te_link *lp, uint32_t delay,
uint8_t anormal)
{
uint32_t tmp;
/* Note that TLV-length field is the size of array. */
lp->av_delay.header.type = htons(TE_LINK_SUBTLV_AV_DELAY);
lp->av_delay.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
tmp = delay & TE_EXT_MASK;
if (anormal)
tmp |= TE_EXT_ANORMAL;
lp->av_delay.value = htonl(tmp);
return;
}
static void set_linkparams_mm_delay(struct mpls_te_link *lp, uint32_t low,
uint32_t high, uint8_t anormal)
{
uint32_t tmp;
/* Note that TLV-length field is the size of array. */
lp->mm_delay.header.type = htons(TE_LINK_SUBTLV_MM_DELAY);
lp->mm_delay.header.length = htons(TE_LINK_SUBTLV_MM_DELAY_SIZE);
tmp = low & TE_EXT_MASK;
if (anormal)
tmp |= TE_EXT_ANORMAL;
lp->mm_delay.low = htonl(tmp);
lp->mm_delay.high = htonl(high);
return;
}
static void set_linkparams_delay_var(struct mpls_te_link *lp, uint32_t jitter)
{
/* Note that TLV-length field is the size of array. */
lp->delay_var.header.type = htons(TE_LINK_SUBTLV_DELAY_VAR);
lp->delay_var.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->delay_var.value = htonl(jitter & TE_EXT_MASK);
return;
}
static void set_linkparams_pkt_loss(struct mpls_te_link *lp, uint32_t loss,
uint8_t anormal)
{
uint32_t tmp;
/* Note that TLV-length field is the size of array. */
lp->pkt_loss.header.type = htons(TE_LINK_SUBTLV_PKT_LOSS);
lp->pkt_loss.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
tmp = loss & TE_EXT_MASK;
if (anormal)
tmp |= TE_EXT_ANORMAL;
lp->pkt_loss.value = htonl(tmp);
return;
}
static void set_linkparams_res_bw(struct mpls_te_link *lp, float fp)
{
/* Note that TLV-length field is the size of array. */
lp->res_bw.header.type = htons(TE_LINK_SUBTLV_RES_BW);
lp->res_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->res_bw.value = htonf(fp);
return;
}
static void set_linkparams_ava_bw(struct mpls_te_link *lp, float fp)
{
/* Note that TLV-length field is the size of array. */
lp->ava_bw.header.type = htons(TE_LINK_SUBTLV_AVA_BW);
lp->ava_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->ava_bw.value = htonf(fp);
return;
}
static void set_linkparams_use_bw(struct mpls_te_link *lp, float fp)
{
/* Note that TLV-length field is the size of array. */
lp->use_bw.header.type = htons(TE_LINK_SUBTLV_USE_BW);
lp->use_bw.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE);
lp->use_bw.value = htonf(fp);
return;
}
/* Update TE parameters from Interface */
static void update_linkparams(struct mpls_te_link *lp)
{
int i;
struct interface *ifp;
/* Get the Interface structure */
if ((ifp = lp->ifp) == NULL) {
ote_debug(
"MPLS-TE (%s): Abort update TE parameters: no interface associated to Link Parameters",
__func__);
return;
}
if (!HAS_LINK_PARAMS(ifp)) {
ote_debug(
"MPLS-TE (%s): Abort update TE parameters: no Link Parameters for interface",
__func__);
return;
}
/* RFC3630 metrics */
if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP))
set_linkparams_rsc_clsclr(lp, ifp->link_params->admin_grp);
else
TLV_TYPE(lp->rsc_clsclr) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW))
set_linkparams_max_bw(lp, ifp->link_params->max_bw);
else
TLV_TYPE(lp->max_bw) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW))
set_linkparams_max_rsv_bw(lp, ifp->link_params->max_rsv_bw);
else
TLV_TYPE(lp->max_rsv_bw) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW))
for (i = 0; i < MAX_CLASS_TYPE; i++)
set_linkparams_unrsv_bw(lp, i,
ifp->link_params->unrsv_bw[i]);
else
TLV_TYPE(lp->unrsv_bw) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC))
set_linkparams_te_metric(lp, ifp->link_params->te_metric);
else
TLV_TYPE(lp->te_metric) = 0;
/* TE metric Extensions */
if (IS_PARAM_SET(ifp->link_params, LP_DELAY))
set_linkparams_av_delay(lp, ifp->link_params->av_delay, 0);
else
TLV_TYPE(lp->av_delay) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY))
set_linkparams_mm_delay(lp, ifp->link_params->min_delay,
ifp->link_params->max_delay, 0);
else
TLV_TYPE(lp->mm_delay) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR))
set_linkparams_delay_var(lp, ifp->link_params->delay_var);
else
TLV_TYPE(lp->delay_var) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS))
set_linkparams_pkt_loss(lp, ifp->link_params->pkt_loss, 0);
else
TLV_TYPE(lp->pkt_loss) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_RES_BW))
set_linkparams_res_bw(lp, ifp->link_params->res_bw);
else
TLV_TYPE(lp->res_bw) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW))
set_linkparams_ava_bw(lp, ifp->link_params->ava_bw);
else
TLV_TYPE(lp->ava_bw) = 0;
if (IS_PARAM_SET(ifp->link_params, LP_USE_BW))
set_linkparams_use_bw(lp, ifp->link_params->use_bw);
else
TLV_TYPE(lp->use_bw) = 0;
/* RFC5392 */
if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS)) {
/* Flush LSA if it engaged and was previously a STD_TE one */
if (IS_STD_TE(lp->type)
&& CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
ote_debug(
"MPLS-TE (%s): Update IF: Switch from Standard LSA to INTER-AS for %s[%d/%d]",
__func__, ifp->name, lp->flags, lp->type);
ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
/* Then, switch it to INTER-AS */
if (OspfMplsTE.inter_as == AS) {
lp->type = INTER_AS;
SET_FLAG(lp->flags, LPFLG_LSA_FLOOD_AS);
} else {
lp->type = INTER_AS;
UNSET_FLAG(lp->flags, LPFLG_LSA_FLOOD_AS);
lp->area = ospf_area_lookup_by_area_id(
ospf_lookup_by_vrf_id(VRF_DEFAULT),
OspfMplsTE.interas_areaid);
}
}
set_linkparams_inter_as(lp, ifp->link_params->rmt_ip,
ifp->link_params->rmt_as);
} else {
ote_debug(
"MPLS-TE (%s): Update IF: Switch from INTER-AS LSA to Standard for %s[%d/%d]",
__func__, ifp->name, lp->flags, lp->type);
/* reset inter-as TE params */
/* Flush LSA if it engaged and was previously an INTER_AS one */
if (IS_INTER_AS(lp->type)
&& CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
/* Then, switch it to Standard TE */
lp->flags = STD_TE;
UNSET_FLAG(lp->flags, LPFLG_LSA_FLOOD_AS);
}
unset_linkparams_inter_as(lp);
}
}
static void initialize_linkparams(struct mpls_te_link *lp)
{
struct interface *ifp = lp->ifp;
struct ospf_interface *oi = NULL;
struct route_node *rn;
ote_debug("MPLS-TE (%s): Initialize Link Parameters for interface %s",
__func__, ifp->name);
/* Search OSPF Interface parameters for this interface */
for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
if ((oi = rn->info) == NULL)
continue;
if (oi->ifp == ifp)
break;
}
if ((oi == NULL) || (oi->ifp != ifp)) {
ote_debug(
"MPLS-TE (%s): Could not find corresponding OSPF Interface for %s",
__func__, ifp->name);
return;
}
/*
* Try to set initial values those can be derived from
* zebra-interface information.
*/
set_linkparams_link_type(oi, lp);
/* Set local IP addr */
set_linkparams_lclif_ipaddr(lp, oi->address->u.prefix4);
/* Set Remote IP addr if Point to Point Interface */
if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
struct prefix *pref = CONNECTED_PREFIX(oi->connected);
if (pref != NULL)
set_linkparams_rmtif_ipaddr(lp, pref->u.prefix4);
}
/* Keep Area information in combination with link parameters. */
lp->area = oi->area;
return;
}
static int is_mandated_params_set(struct mpls_te_link *lp)
{
int rc = 0;
if (ntohs(OspfMplsTE.router_addr.header.type) == 0) {
flog_warn(EC_OSPF_TE_UNEXPECTED,
"MPLS-TE (%s): Missing Router Address", __func__);
return rc;
}
if (ntohs(lp->link_type.header.type) == 0) {
flog_warn(EC_OSPF_TE_UNEXPECTED,
"MPLS-TE (%s): Missing Link Type", __func__);
return rc;
}
if (!IS_INTER_AS(lp->type) && (ntohs(lp->link_id.header.type) == 0)) {
flog_warn(EC_OSPF_TE_UNEXPECTED, "MPLS-TE (%s) Missing Link ID",
__func__);
return rc;
}
rc = 1;
return rc;
}
/*------------------------------------------------------------------------*
* Following are callback functions against generic Opaque-LSAs handling.
*------------------------------------------------------------------------*/
static int ospf_mpls_te_new_if(struct interface *ifp)
{
struct mpls_te_link *new;
ote_debug("MPLS-TE (%s): Add new %s interface %s to MPLS-TE list",
__func__, ifp->link_params ? "Active" : "Inactive",
ifp->name);
if (lookup_linkparams_by_ifp(ifp) != NULL)
return 0;
new = XCALLOC(MTYPE_OSPF_MPLS_TE, sizeof(struct mpls_te_link));
new->instance = get_mpls_te_instance_value();
new->ifp = ifp;
/* By default TE-Link is RFC3630 compatible flooding in Area and not
* active */
/* This default behavior will be adapted with call to
* ospf_mpls_te_update_if() */
new->type = STD_TE;
new->flags = LPFLG_LSA_INACTIVE;
/* Initialize Link Parameters from Interface */
initialize_linkparams(new);
/* Set TE Parameters from Interface */
update_linkparams(new);
/* Add Link Parameters structure to the list */
listnode_add(OspfMplsTE.iflist, new);
ote_debug("MPLS-TE (%s): Add new LP context for %s[%d/%d]", __func__,
ifp->name, new->flags, new->type);
/* Schedule Opaque-LSA refresh. */ /* XXX */
return 0;
}
static int ospf_mpls_te_del_if(struct interface *ifp)
{
struct mpls_te_link *lp;
int rc = -1;
if ((lp = lookup_linkparams_by_ifp(ifp)) != NULL) {
struct list *iflist = OspfMplsTE.iflist;
/* Dequeue listnode entry from the list. */
listnode_delete(iflist, lp);
XFREE(MTYPE_OSPF_MPLS_TE, lp);
}
/* Schedule Opaque-LSA refresh. */ /* XXX */
rc = 0;
return rc;
}
/* Main initialization / update function of the MPLS TE Link context */
/* Call when interface TE Link parameters are modified */
void ospf_mpls_te_update_if(struct interface *ifp)
{
struct mpls_te_link *lp;
ote_debug("MPLS-TE (%s): Update LSA parameters for interface %s [%s]",
__func__, ifp->name, HAS_LINK_PARAMS(ifp) ? "ON" : "OFF");
/* Get Link context from interface */
if ((lp = lookup_linkparams_by_ifp(ifp)) == NULL) {
flog_warn(
EC_OSPF_TE_UNEXPECTED,
"MPLS-TE (%s): Did not find Link Parameters context for interface %s",
__func__, ifp->name);
return;
}
/* Fulfill MPLS-TE Link TLV from Interface TE Link parameters */
if (HAS_LINK_PARAMS(ifp)) {
SET_FLAG(lp->flags, LPFLG_LSA_ACTIVE);
/* Update TE parameters */
update_linkparams(lp);
/* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is
* enabled */
if (OspfMplsTE.enabled)
if (lp->area != NULL) {
if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
ospf_mpls_te_lsa_schedule(
lp, REFRESH_THIS_LSA);
else
ospf_mpls_te_lsa_schedule(
lp, REORIGINATE_THIS_LSA);
}
} else {
/* If MPLS TE is disable on this interface, flush LSA if it is
* already engaged */
if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED))
ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
else
/* Reset Activity flag */
lp->flags = LPFLG_LSA_INACTIVE;
}
return;
}
/*
* Just add interface and set available information. Other information
* and flooding of LSA will be done later when adjacency will be up
* See ospf_mpls_te_nsm_change() after
*/
static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_state)
{
struct mpls_te_link *lp;
lp = lookup_linkparams_by_ifp(oi->ifp);
if (lp == NULL) {
flog_warn(
EC_OSPF_TE_UNEXPECTED,
"MPLS-TE (%s): Cannot get linkparams from OI(%s)?",
__func__, IF_NAME(oi));
return;
}
if (oi->area == NULL || oi->area->ospf == NULL) {
flog_warn(
EC_OSPF_TE_UNEXPECTED,
"MPLS-TE (%s): Cannot refer to OSPF from OI(%s)?",
__func__, IF_NAME(oi));
return;
}
/* Keep Area information in combination with linkparams. */
lp->area = oi->area;
switch (oi->state) {
case ISM_PointToPoint:
case ISM_DROther:
case ISM_Backup:
case ISM_DR:
/* Set Link type and Local IP addr */
set_linkparams_link_type(oi, lp);
set_linkparams_lclif_ipaddr(lp, oi->address->u.prefix4);
break;
case ISM_Down:
/* Interface goes Down: Flush LSA if engaged */
if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) {
ote_debug(
"MPLS-TE (%s): Interface %s goes down: flush LSA",
__func__, IF_NAME(oi));
ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA);
return;
}
break;
default:
break;
}
ote_debug("MPLS-TE (%s): Update Link parameters for interface %s",
__func__, IF_NAME(oi));
return;
}
/*
* Complete TE info and schedule LSA flooding
* Link-ID and Remote IP address must be set with neighbor info
* which are only valid once NSM state is FULL
*/
static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_state)
{
struct ospf_interface *oi = nbr->oi;
struct mpls_te_link *lp;
/* Process Link only when neighbor old or new state is NSM Full */
if (nbr->state != NSM_Full && old_state != NSM_Full)
return;
/* Get interface information for Traffic Engineering */
lp = lookup_linkparams_by_ifp(oi->ifp);
if (lp == NULL) {
flog_warn(
EC_OSPF_TE_UNEXPECTED,
"MPLS-TE (%s): Cannot get linkparams from OI(%s)?",
__func__, IF_NAME(oi));
return;
}
if (oi->area == NULL || oi->area->ospf == NULL) {
flog_warn(
EC_OSPF_TE_UNEXPECTED,