]> git.proxmox.com Git - mirror_frr.git/blob - tests/test_lblmgr.c
*: reindent
[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
20 * along with FRR; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 * 02111-1307, USA.
23 */
24
25 #include "lib/stream.h"
26 #include "lib/zclient.h"
27
28 #define ZSERV_PATH "/tmp/zserv.api" // TODO!!
29 #define KEEP 0 /* change to 1 to avoid garbage collection */
30 #define CHUNK_SIZE 32
31
32 struct zclient *zclient;
33 u_short instance = 1;
34
35 const char *sequence = "GGRGGGRRG";
36
37 static int zebra_send_get_label_chunk(void);
38 static int zebra_send_release_label_chunk(uint32_t start, uint32_t end);
39
40 static void process_next_call(uint32_t start, uint32_t end)
41 {
42 sleep(3);
43 if (!*sequence)
44 exit(0);
45 if (*sequence == 'G')
46 zebra_send_get_label_chunk();
47 else if (*sequence == 'R')
48 zebra_send_release_label_chunk(start, end);
49 }
50
51 /* Connect to Label Manager */
52
53 static int zebra_send_label_manager_connect()
54 {
55 int ret;
56
57 printf("Connect to Label Manager\n");
58
59 ret = lm_label_manager_connect(zclient);
60 printf("Label Manager connection result: %u \n", ret);
61 if (ret != 0) {
62 fprintf(stderr, "Error %d connecting to Label Manager %s\n",
63 ret, strerror(errno));
64 exit(1);
65 }
66
67 process_next_call(0, 0);
68 }
69
70 /* Get Label Chunk */
71
72 static int zebra_send_get_label_chunk()
73 {
74 uint32_t start;
75 uint32_t end;
76 int ret;
77
78 printf("Ask for label chunk \n");
79
80 ret = lm_get_label_chunk(zclient, KEEP, CHUNK_SIZE, &start, &end);
81 if (ret != 0) {
82 fprintf(stderr, "Error %d requesting label chunk %s\n", ret,
83 strerror(errno));
84 exit(1);
85 }
86
87 sequence++;
88
89 printf("Label Chunk assign: %u - %u \n", start, end);
90
91 process_next_call(start, end);
92 }
93
94 /* Release Label Chunk */
95
96 static int zebra_send_release_label_chunk(uint32_t start, uint32_t end)
97 {
98 struct stream *s;
99 int ret;
100
101 printf("Release label chunk: %u - %u\n", start, end);
102
103 ret = lm_release_label_chunk(zclient, start, end);
104 if (ret != 0) {
105 fprintf(stderr, "Error releasing label chunk\n");
106 exit(1);
107 }
108
109 sequence++;
110
111 process_next_call(start - CHUNK_SIZE, end - CHUNK_SIZE);
112 }
113
114
115 void init_zclient(struct thread_master *master, char *lm_zserv_path)
116 {
117 if (lm_zserv_path)
118 zclient_serv_path_set(lm_zserv_path);
119
120 zclient = zclient_new(master);
121 /* zclient_init(zclient, ZEBRA_LABEL_MANAGER, 0); */
122 zclient->sock = -1;
123 zclient->redist_default = ZEBRA_ROUTE_LDP;
124 zclient->instance = instance;
125 if (zclient_socket_connect(zclient) < 0) {
126 printf("Error connecting synchronous zclient!\n");
127 exit(1);
128 }
129 }
130
131 int main(int argc, char *argv[])
132 {
133 struct thread_master *master;
134 struct thread thread;
135 int ret;
136
137 printf("Sequence to be tested: %s\n", sequence);
138
139 master = thread_master_create();
140 init_zclient(master, ZSERV_PATH);
141
142 zebra_send_label_manager_connect();
143
144 return 0;
145 }