15
15
#include "linklist.h"
16
16
#include "skiplist.h"
17
17
#include "workqueue.h"
18
- #include "zclient.h"
19
18
#include "mpls.h"
20
19
21
20
#include "bgpd/bgpd.h"
32
31
#include "bgpd/bgp_labelpool_clippy.c"
33
32
34
33
35
- /*
36
- * Definitions and external declarations.
37
- */
38
- extern struct zclient * zclient ;
39
-
40
34
#if BGP_LABELPOOL_ENABLE_TESTS
41
35
static void lptest_init (void );
42
36
static void lptest_finish (void );
@@ -223,6 +217,8 @@ void bgp_lp_finish(void)
223
217
{
224
218
struct lp_fifo * lf ;
225
219
struct work_queue_item * item , * titem ;
220
+ struct listnode * node ;
221
+ struct lp_chunk * chunk ;
226
222
227
223
#if BGP_LABELPOOL_ENABLE_TESTS
228
224
lptest_finish ();
@@ -236,6 +232,9 @@ void bgp_lp_finish(void)
236
232
skiplist_free (lp -> inuse );
237
233
lp -> inuse = NULL ;
238
234
235
+ for (ALL_LIST_ELEMENTS_RO (lp -> chunks , node , chunk ))
236
+ bgp_zebra_release_label_range (chunk -> first , chunk -> last );
237
+
239
238
list_delete (& lp -> chunks );
240
239
241
240
while ((lf = lp_fifo_pop (& lp -> requests ))) {
@@ -448,15 +447,13 @@ void bgp_lp_get(
448
447
lp_fifo_add_tail (& lp -> requests , lf );
449
448
450
449
if (lp_fifo_count (& lp -> requests ) > lp -> pending_count ) {
451
- if (!zclient || zclient -> sock < 0 )
450
+ if (!bgp_zebra_request_label_range (MPLS_LABEL_BASE_ANY ,
451
+ lp -> next_chunksize ))
452
452
return ;
453
- if (zclient_send_get_label_chunk (zclient , 0 , lp -> next_chunksize ,
454
- MPLS_LABEL_BASE_ANY ) !=
455
- ZCLIENT_SEND_FAILURE ) {
456
- lp -> pending_count += lp -> next_chunksize ;
457
- if ((lp -> next_chunksize << 1 ) <= LP_CHUNK_SIZE_MAX )
458
- lp -> next_chunksize <<= 1 ;
459
- }
453
+
454
+ lp -> pending_count += lp -> next_chunksize ;
455
+ if ((lp -> next_chunksize << 1 ) <= LP_CHUNK_SIZE_MAX )
456
+ lp -> next_chunksize <<= 1 ;
460
457
}
461
458
}
462
459
@@ -503,46 +500,12 @@ void bgp_lp_release(
503
500
}
504
501
}
505
502
506
- /*
507
- * zebra response giving us a chunk of labels
508
- */
509
- void bgp_lp_event_chunk (uint8_t keep , uint32_t first , uint32_t last )
503
+ static void bgp_sync_label_manager (struct event * e )
510
504
{
511
- struct lp_chunk * chunk ;
512
505
int debug = BGP_DEBUG (labelpool , LABELPOOL );
513
506
struct lp_fifo * lf ;
514
- uint32_t labelcount ;
515
-
516
- if (last < first ) {
517
- flog_err (EC_BGP_LABEL ,
518
- "%s: zebra label chunk invalid: first=%u, last=%u" ,
519
- __func__ , first , last );
520
- return ;
521
- }
522
507
523
- chunk = XCALLOC (MTYPE_BGP_LABEL_CHUNK , sizeof (struct lp_chunk ));
524
-
525
- labelcount = last - first + 1 ;
526
-
527
- chunk -> first = first ;
528
- chunk -> last = last ;
529
- chunk -> nfree = labelcount ;
530
- bf_init (chunk -> allocated_map , labelcount );
531
-
532
- /*
533
- * Optimize for allocation by adding the new (presumably larger)
534
- * chunk at the head of the list so it is examined first.
535
- */
536
- listnode_add_head (lp -> chunks , chunk );
537
-
538
- lp -> pending_count -= labelcount ;
539
-
540
- if (debug ) {
541
- zlog_debug ("%s: %zu pending requests" , __func__ ,
542
- lp_fifo_count (& lp -> requests ));
543
- }
544
-
545
- while (labelcount && (lf = lp_fifo_first (& lp -> requests ))) {
508
+ while ((lf = lp_fifo_pop (& lp -> requests ))) {
546
509
547
510
struct lp_lcb * lcb ;
548
511
void * labelid = lf -> lcb .labelid ;
@@ -588,8 +551,6 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last)
588
551
break ;
589
552
}
590
553
591
- labelcount -= 1 ;
592
-
593
554
/*
594
555
* we filled the request from local pool.
595
556
* Enqueue response work item with new label.
@@ -610,9 +571,41 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last)
610
571
work_queue_add (lp -> callback_q , q );
611
572
612
573
finishedrequest :
613
- lp_fifo_del (& lp -> requests , lf );
614
574
XFREE (MTYPE_BGP_LABEL_FIFO , lf );
575
+ }
576
+
577
+ event_add_timer (bm -> master , bgp_sync_label_manager , NULL , 1 ,
578
+ & bm -> t_bgp_label_manager );
579
+ }
580
+
581
+ void bgp_lp_event_chunk (uint32_t first , uint32_t last )
582
+ {
583
+ struct lp_chunk * chunk ;
584
+ uint32_t labelcount ;
585
+
586
+ if (last < first ) {
587
+ flog_err (EC_BGP_LABEL ,
588
+ "%s: zebra label chunk invalid: first=%u, last=%u" ,
589
+ __func__ , first , last );
590
+ return ;
615
591
}
592
+
593
+ chunk = XCALLOC (MTYPE_BGP_LABEL_CHUNK , sizeof (struct lp_chunk ));
594
+
595
+ labelcount = last - first + 1 ;
596
+
597
+ chunk -> first = first ;
598
+ chunk -> last = last ;
599
+ chunk -> nfree = labelcount ;
600
+ bf_init (chunk -> allocated_map , labelcount );
601
+
602
+ /*
603
+ * Optimize for allocation by adding the new (presumably larger)
604
+ * chunk at the head of the list so it is examined first.
605
+ */
606
+ listnode_add_head (lp -> chunks , chunk );
607
+
608
+ lp -> pending_count -= labelcount ;
616
609
}
617
610
618
611
/*
@@ -634,7 +627,6 @@ void bgp_lp_event_zebra_up(void)
634
627
unsigned int chunks_needed ;
635
628
void * labelid ;
636
629
struct lp_lcb * lcb ;
637
- int lm_init_ok ;
638
630
639
631
lp -> reconnect_count ++ ;
640
632
/*
@@ -654,22 +646,16 @@ void bgp_lp_event_zebra_up(void)
654
646
chunks_needed = (labels_needed / lp -> next_chunksize ) + 1 ;
655
647
labels_needed = chunks_needed * lp -> next_chunksize ;
656
648
657
- lm_init_ok = lm_label_manager_connect (zclient , 1 ) = = 0 ;
658
-
659
- if (!lm_init_ok ) {
660
- zlog_err ("%s: label manager connection error" , __func__ );
661
- return ;
662
- }
663
-
664
- zclient_send_get_label_chunk (zclient , 0 , labels_needed ,
665
- MPLS_LABEL_BASE_ANY );
666
- lp -> pending_count = labels_needed ;
667
-
668
649
/*
669
650
* Invalidate current list of chunks
670
651
*/
671
652
list_delete_all_node (lp -> chunks );
672
653
654
+ if (!bgp_zebra_request_label_range (MPLS_LABEL_BASE_ANY , labels_needed ))
655
+ return ;
656
+
657
+ lp -> pending_count = labels_needed ;
658
+
673
659
/*
674
660
* Invalidate any existing labels and requeue them as requests
675
661
*/
@@ -712,6 +698,9 @@ void bgp_lp_event_zebra_up(void)
712
698
713
699
skiplist_delete_first (lp -> inuse );
714
700
}
701
+
702
+ event_add_timer (bm -> master , bgp_sync_label_manager , NULL , 1 ,
703
+ & bm -> t_bgp_label_manager );
715
704
}
716
705
717
706
DEFUN (show_bgp_labelpool_summary , show_bgp_labelpool_summary_cmd ,
0 commit comments