]> git.proxmox.com Git - mirror_frr.git/blame - tests/test_lblmgr.c
debian: add pkg-config to build-depends
[mirror_frr.git] / tests / test_lblmgr.c
CommitLineData
fea12efb 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
32struct zclient *zclient;
33u_short instance = 1;
34
35const char *sequence = "GGRGGGRRG";
36
ac4d0be5 37static int zebra_send_get_label_chunk(void);
38static int zebra_send_release_label_chunk(uint32_t start, uint32_t end);
fea12efb 39
ac4d0be5 40static void process_next_call(uint32_t start, uint32_t end)
fea12efb 41{
ac4d0be5 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);
fea12efb 49}
50
51/* Connect to Label Manager */
52
ac4d0be5 53static int zebra_send_label_manager_connect()
fea12efb 54{
ac4d0be5 55 int ret;
fea12efb 56
ac4d0be5 57 printf("Connect to Label Manager\n");
fea12efb 58
ac4d0be5 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 }
fea12efb 66
ac4d0be5 67 process_next_call(0, 0);
fea12efb 68}
69
70/* Get Label Chunk */
71
ac4d0be5 72static int zebra_send_get_label_chunk()
fea12efb 73{
ac4d0be5 74 uint32_t start;
75 uint32_t end;
76 int ret;
fea12efb 77
ac4d0be5 78 printf("Ask for label chunk \n");
fea12efb 79
ac4d0be5 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 }
fea12efb 86
ac4d0be5 87 sequence++;
fea12efb 88
ac4d0be5 89 printf("Label Chunk assign: %u - %u \n", start, end);
fea12efb 90
ac4d0be5 91 process_next_call(start, end);
fea12efb 92}
93
94/* Release Label Chunk */
95
ac4d0be5 96static int zebra_send_release_label_chunk(uint32_t start, uint32_t end)
fea12efb 97{
ac4d0be5 98 struct stream *s;
99 int ret;
fea12efb 100
ac4d0be5 101 printf("Release label chunk: %u - %u\n", start, end);
fea12efb 102
ac4d0be5 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 }
fea12efb 108
ac4d0be5 109 sequence++;
fea12efb 110
ac4d0be5 111 process_next_call(start - CHUNK_SIZE, end - CHUNK_SIZE);
fea12efb 112}
113
114
ac4d0be5 115void init_zclient(struct thread_master *master, char *lm_zserv_path)
fea12efb 116{
ac4d0be5 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 }
fea12efb 129}
130
ac4d0be5 131int main(int argc, char *argv[])
fea12efb 132{
ac4d0be5 133 struct thread_master *master;
134 struct thread thread;
135 int ret;
fea12efb 136
ac4d0be5 137 printf("Sequence to be tested: %s\n", sequence);
fea12efb 138
ac4d0be5 139 master = thread_master_create();
140 init_zclient(master, ZSERV_PATH);
fea12efb 141
ac4d0be5 142 zebra_send_label_manager_connect();
fea12efb 143
ac4d0be5 144 return 0;
fea12efb 145}