]> git.proxmox.com Git - mirror_frr.git/blob - tests/test_lblmgr.c
Merge pull request #286 from opensourcerouting/ldpd-tshoot
[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
41 process_next_call (uint32_t start, uint32_t end)
42 {
43 sleep (3);
44 if (!*sequence)
45 exit (0);
46 if (*sequence == 'G')
47 zebra_send_get_label_chunk ();
48 else if (*sequence == 'R')
49 zebra_send_release_label_chunk (start, end);
50 }
51
52 /* Connect to Label Manager */
53
54 static int
55 zebra_send_label_manager_connect ()
56 {
57 int ret;
58
59 printf("Connect to Label Manager\n");
60
61 ret = lm_label_manager_connect (zclient);
62 printf ("Label Manager connection result: %u \n", ret);
63 if (ret != 0 ) {
64 fprintf (stderr, "Error %d connecting to Label Manager %s\n", ret,
65 strerror(errno));
66 exit (1);
67 }
68
69 process_next_call (0, 0);
70 }
71
72 /* Get Label Chunk */
73
74 static int
75 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, strerror(errno));
86 exit (1);
87 }
88
89 sequence++;
90
91 printf ("Label Chunk assign: %u - %u \n",
92 start, end);
93
94 process_next_call (start, end);
95 }
96
97 /* Release Label Chunk */
98
99 static int
100 zebra_send_release_label_chunk (uint32_t start, uint32_t end)
101 {
102 struct stream *s;
103 int ret;
104
105 printf("Release label chunk: %u - %u\n", start, end);
106
107 ret = lm_release_label_chunk (zclient, start, end);
108 if (ret != 0 ) {
109 fprintf (stderr, "Error releasing label chunk\n");
110 exit (1);
111 }
112
113 sequence++;
114
115 process_next_call (start-CHUNK_SIZE, end-CHUNK_SIZE);
116 }
117
118
119 void init_zclient (struct thread_master *master, char *lm_zserv_path)
120 {
121 if (lm_zserv_path)
122 zclient_serv_path_set(lm_zserv_path);
123
124 zclient = zclient_new(master);
125 /* zclient_init(zclient, ZEBRA_LABEL_MANAGER, 0); */
126 zclient->sock = -1;
127 zclient->redist_default = ZEBRA_ROUTE_LDP;
128 zclient->instance = instance;
129 if (zclient_socket_connect (zclient) < 0) {
130 printf ("Error connecting synchronous zclient!\n");
131 exit (1);
132 }
133
134 }
135
136 int main (int argc, char *argv[])
137 {
138 struct thread_master *master;
139 struct thread thread;
140 int ret;
141
142 printf ("Sequence to be tested: %s\n", sequence);
143
144 master = thread_master_create();
145 init_zclient (master, ZSERV_PATH);
146
147 zebra_send_label_manager_connect ();
148
149 return 0;
150 }