]> git.proxmox.com Git - mirror_frr.git/blob - tests/test_lblmgr.c
bgp-ecmp-topo1: fix vrf default change
[mirror_frr.git] / tests / test_lblmgr.c
1 /*
2 * Label Manager Test
3 *
4 * Copyright (C) 2017 by Bingen Eguzkitza,
5 * Volta Networks Inc.
6 *
7 * This file is part of FreeRangeRouting (FRR)
8 *
9 * FRR is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * FRR is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "lib/stream.h"
29 #include "lib/zclient.h"
30
31 #define ZSERV_PATH "/tmp/zserv.api" // TODO!!
32 #define KEEP 0 /* change to 1 to avoid garbage collection */
33 #define CHUNK_SIZE 32
34
35 struct zclient *zclient;
36 unsigned short instance = 1;
37
38 const char *sequence = "GGRGGGRRG";
39
40 static int zebra_send_get_label_chunk(void);
41 static int zebra_send_release_label_chunk(uint32_t start, uint32_t end);
42
43 static void process_next_call(uint32_t start, uint32_t end)
44 {
45 sleep(3);
46 if (!*sequence)
47 exit(0);
48 if (*sequence == 'G')
49 zebra_send_get_label_chunk();
50 else if (*sequence == 'R')
51 zebra_send_release_label_chunk(start, end);
52 }
53
54 /* Connect to Label Manager */
55
56 static int zebra_send_label_manager_connect()
57 {
58 int ret;
59
60 printf("Connect to Label Manager\n");
61
62 ret = lm_label_manager_connect(zclient, 0);
63 printf("Label Manager connection result: %u \n", ret);
64 if (ret != 0) {
65 fprintf(stderr, "Error %d connecting to Label Manager %s\n",
66 ret, strerror(errno));
67 exit(1);
68 }
69
70 process_next_call(0, 0);
71 }
72
73 /* Get Label Chunk */
74
75 static int zebra_send_get_label_chunk()
76 {
77 uint32_t start;
78 uint32_t end;
79 int ret;
80
81 printf("Ask for label chunk \n");
82
83 ret = lm_get_label_chunk(zclient, KEEP, CHUNK_SIZE, &start, &end);
84 if (ret != 0) {
85 fprintf(stderr, "Error %d requesting label chunk %s\n", ret,
86 strerror(errno));
87 exit(1);
88 }
89
90 sequence++;
91
92 printf("Label Chunk assign: %u - %u \n", start, end);
93
94 process_next_call(start, end);
95 }
96
97 /* Release Label Chunk */
98
99 static int zebra_send_release_label_chunk(uint32_t start, uint32_t end)
100 {
101 struct stream *s;
102 int ret;
103
104 printf("Release label chunk: %u - %u\n", start, end);
105
106 ret = lm_release_label_chunk(zclient, start, end);
107 if (ret != 0) {
108 fprintf(stderr, "Error releasing label chunk\n");
109 exit(1);
110 }
111
112 sequence++;
113
114 process_next_call(start - CHUNK_SIZE, end - CHUNK_SIZE);
115 }
116
117
118 void init_zclient(struct thread_master *master, char *lm_zserv_path)
119 {
120 frr_zclient_addr(&zclient_addr, &zclient_addr_len, lm_zserv_path);
121
122 zclient = zclient_new(master, &zclient_options_default);
123 /* zclient_init(zclient, ZEBRA_LABEL_MANAGER, 0); */
124 zclient->sock = -1;
125 zclient->redist_default = ZEBRA_ROUTE_LDP;
126 zclient->instance = instance;
127 if (zclient_socket_connect(zclient) < 0) {
128 printf("Error connecting synchronous zclient!\n");
129 exit(1);
130 }
131 }
132
133 int main(int argc, char *argv[])
134 {
135 struct thread_master *master;
136 struct thread thread;
137 int ret;
138
139 printf("Sequence to be tested: %s\n", sequence);
140
141 master = thread_master_create(NULL);
142 init_zclient(master, ZSERV_PATH);
143
144 zebra_send_label_manager_connect();
145
146 return 0;
147 }