]> git.proxmox.com Git - mirror_frr.git/blame - tests/test_lblmgr.c
lib, zebra: support label chunk requests for SRGB
[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 *
896014f4
DL
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
fea12efb 22 */
23
b45ac5f5
DL
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
fea12efb 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
35struct zclient *zclient;
d7c0a89a 36unsigned short instance = 1;
fea12efb 37
38const char *sequence = "GGRGGGRRG";
39
d62a17ae 40static int zebra_send_get_label_chunk(void);
41static int zebra_send_release_label_chunk(uint32_t start, uint32_t end);
fea12efb 42
d62a17ae 43static void process_next_call(uint32_t start, uint32_t end)
fea12efb 44{
d62a17ae 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);
fea12efb 52}
53
54/* Connect to Label Manager */
55
d62a17ae 56static int zebra_send_label_manager_connect()
fea12efb 57{
d62a17ae 58 int ret;
fea12efb 59
d62a17ae 60 printf("Connect to Label Manager\n");
fea12efb 61
f533be73 62 ret = lm_label_manager_connect(zclient, 0);
d62a17ae 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 }
fea12efb 69
d62a17ae 70 process_next_call(0, 0);
fea12efb 71}
72
73/* Get Label Chunk */
74
d62a17ae 75static int zebra_send_get_label_chunk()
fea12efb 76{
d62a17ae 77 uint32_t start;
78 uint32_t end;
79 int ret;
fea12efb 80
d62a17ae 81 printf("Ask for label chunk \n");
fea12efb 82
0e3b6a92
EDP
83 ret = lm_get_label_chunk(zclient, KEEP, MPLS_LABEL_BASE_ANY, CHUNK_SIZE,
84 &start, &end);
d62a17ae 85 if (ret != 0) {
86 fprintf(stderr, "Error %d requesting label chunk %s\n", ret,
87 strerror(errno));
88 exit(1);
89 }
fea12efb 90
d62a17ae 91 sequence++;
fea12efb 92
d62a17ae 93 printf("Label Chunk assign: %u - %u \n", start, end);
fea12efb 94
d62a17ae 95 process_next_call(start, end);
fea12efb 96}
97
98/* Release Label Chunk */
99
d62a17ae 100static int zebra_send_release_label_chunk(uint32_t start, uint32_t end)
fea12efb 101{
d62a17ae 102 struct stream *s;
103 int ret;
fea12efb 104
d62a17ae 105 printf("Release label chunk: %u - %u\n", start, end);
fea12efb 106
d62a17ae 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 }
fea12efb 112
d62a17ae 113 sequence++;
fea12efb 114
d62a17ae 115 process_next_call(start - CHUNK_SIZE, end - CHUNK_SIZE);
fea12efb 116}
117
118
d62a17ae 119void init_zclient(struct thread_master *master, char *lm_zserv_path)
fea12efb 120{
689f5a8c 121 frr_zclient_addr(&zclient_addr, &zclient_addr_len, lm_zserv_path);
d62a17ae 122
26f63a1e 123 zclient = zclient_new(master, &zclient_options_default);
d62a17ae 124 /* zclient_init(zclient, ZEBRA_LABEL_MANAGER, 0); */
125 zclient->sock = -1;
126 zclient->redist_default = ZEBRA_ROUTE_LDP;
127 zclient->instance = instance;
128 if (zclient_socket_connect(zclient) < 0) {
129 printf("Error connecting synchronous zclient!\n");
130 exit(1);
131 }
fea12efb 132}
133
d62a17ae 134int main(int argc, char *argv[])
fea12efb 135{
d62a17ae 136 struct thread_master *master;
137 struct thread thread;
138 int ret;
fea12efb 139
d62a17ae 140 printf("Sequence to be tested: %s\n", sequence);
fea12efb 141
d62a17ae 142 master = thread_master_create(NULL);
143 init_zclient(master, ZSERV_PATH);
fea12efb 144
d62a17ae 145 zebra_send_label_manager_connect();
fea12efb 146
d62a17ae 147 return 0;
fea12efb 148}