]> git.proxmox.com Git - mirror_frr.git/blame - tests/test_lblmgr.c
bgp-ecmp-topo1: fix vrf default change
[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
d62a17ae 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,
86 strerror(errno));
87 exit(1);
88 }
fea12efb 89
d62a17ae 90 sequence++;
fea12efb 91
d62a17ae 92 printf("Label Chunk assign: %u - %u \n", start, end);
fea12efb 93
d62a17ae 94 process_next_call(start, end);
fea12efb 95}
96
97/* Release Label Chunk */
98
d62a17ae 99static int zebra_send_release_label_chunk(uint32_t start, uint32_t end)
fea12efb 100{
d62a17ae 101 struct stream *s;
102 int ret;
fea12efb 103
d62a17ae 104 printf("Release label chunk: %u - %u\n", start, end);
fea12efb 105
d62a17ae 106 ret = lm_release_label_chunk(zclient, start, end);
107 if (ret != 0) {
108 fprintf(stderr, "Error releasing label chunk\n");
109 exit(1);
110 }
fea12efb 111
d62a17ae 112 sequence++;
fea12efb 113
d62a17ae 114 process_next_call(start - CHUNK_SIZE, end - CHUNK_SIZE);
fea12efb 115}
116
117
d62a17ae 118void init_zclient(struct thread_master *master, char *lm_zserv_path)
fea12efb 119{
689f5a8c 120 frr_zclient_addr(&zclient_addr, &zclient_addr_len, lm_zserv_path);
d62a17ae 121
26f63a1e 122 zclient = zclient_new(master, &zclient_options_default);
d62a17ae 123 /* zclient_init(zclient, ZEBRA_LABEL_MANAGER, 0); */
124 zclient->sock = -1;
125 zclient->redist_default = ZEBRA_ROUTE_LDP;
126 zclient->instance = instance;
127 if (zclient_socket_connect(zclient) < 0) {
128 printf("Error connecting synchronous zclient!\n");
129 exit(1);
130 }
fea12efb 131}
132
d62a17ae 133int main(int argc, char *argv[])
fea12efb 134{
d62a17ae 135 struct thread_master *master;
136 struct thread thread;
137 int ret;
fea12efb 138
d62a17ae 139 printf("Sequence to be tested: %s\n", sequence);
fea12efb 140
d62a17ae 141 master = thread_master_create(NULL);
142 init_zclient(master, ZSERV_PATH);
fea12efb 143
d62a17ae 144 zebra_send_label_manager_connect();
fea12efb 145
d62a17ae 146 return 0;
fea12efb 147}