]>
Commit | Line | Data |
---|---|---|
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 | ||
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; | |
d7c0a89a | 32 | unsigned short instance = 1; |
fea12efb | 33 | |
34 | const char *sequence = "GGRGGGRRG"; | |
35 | ||
d62a17ae | 36 | static int zebra_send_get_label_chunk(void); |
37 | static int zebra_send_release_label_chunk(uint32_t start, uint32_t end); | |
fea12efb | 38 | |
d62a17ae | 39 | static void process_next_call(uint32_t start, uint32_t end) |
fea12efb | 40 | { |
d62a17ae | 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); | |
fea12efb | 48 | } |
49 | ||
50 | /* Connect to Label Manager */ | |
51 | ||
d62a17ae | 52 | static int zebra_send_label_manager_connect() |
fea12efb | 53 | { |
d62a17ae | 54 | int ret; |
fea12efb | 55 | |
d62a17ae | 56 | printf("Connect to Label Manager\n"); |
fea12efb | 57 | |
d62a17ae | 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 | } | |
fea12efb | 65 | |
d62a17ae | 66 | process_next_call(0, 0); |
fea12efb | 67 | } |
68 | ||
69 | /* Get Label Chunk */ | |
70 | ||
d62a17ae | 71 | static int zebra_send_get_label_chunk() |
fea12efb | 72 | { |
d62a17ae | 73 | uint32_t start; |
74 | uint32_t end; | |
75 | int ret; | |
fea12efb | 76 | |
d62a17ae | 77 | printf("Ask for label chunk \n"); |
fea12efb | 78 | |
d62a17ae | 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 | } | |
fea12efb | 85 | |
d62a17ae | 86 | sequence++; |
fea12efb | 87 | |
d62a17ae | 88 | printf("Label Chunk assign: %u - %u \n", start, end); |
fea12efb | 89 | |
d62a17ae | 90 | process_next_call(start, end); |
fea12efb | 91 | } |
92 | ||
93 | /* Release Label Chunk */ | |
94 | ||
d62a17ae | 95 | static int zebra_send_release_label_chunk(uint32_t start, uint32_t end) |
fea12efb | 96 | { |
d62a17ae | 97 | struct stream *s; |
98 | int ret; | |
fea12efb | 99 | |
d62a17ae | 100 | printf("Release label chunk: %u - %u\n", start, end); |
fea12efb | 101 | |
d62a17ae | 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 | } | |
fea12efb | 107 | |
d62a17ae | 108 | sequence++; |
fea12efb | 109 | |
d62a17ae | 110 | process_next_call(start - CHUNK_SIZE, end - CHUNK_SIZE); |
fea12efb | 111 | } |
112 | ||
113 | ||
d62a17ae | 114 | void init_zclient(struct thread_master *master, char *lm_zserv_path) |
fea12efb | 115 | { |
689f5a8c | 116 | frr_zclient_addr(&zclient_addr, &zclient_addr_len, lm_zserv_path); |
d62a17ae | 117 | |
e1a1880d | 118 | zclient = zclient_new_notify(master, &zclient_options_default); |
d62a17ae | 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 | } | |
fea12efb | 127 | } |
128 | ||
d62a17ae | 129 | int main(int argc, char *argv[]) |
fea12efb | 130 | { |
d62a17ae | 131 | struct thread_master *master; |
132 | struct thread thread; | |
133 | int ret; | |
fea12efb | 134 | |
d62a17ae | 135 | printf("Sequence to be tested: %s\n", sequence); |
fea12efb | 136 | |
d62a17ae | 137 | master = thread_master_create(NULL); |
138 | init_zclient(master, ZSERV_PATH); | |
fea12efb | 139 | |
d62a17ae | 140 | zebra_send_label_manager_connect(); |
fea12efb | 141 | |
d62a17ae | 142 | return 0; |
fea12efb | 143 | } |