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