]>
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; | |
32 | u_short instance = 1; | |
33 | ||
34 | const char *sequence = "GGRGGGRRG"; | |
35 | ||
36 | static int zebra_send_get_label_chunk (void); | |
37 | static int zebra_send_release_label_chunk (uint32_t start, uint32_t end); | |
38 | ||
39 | static void | |
40 | process_next_call (uint32_t start, uint32_t end) | |
41 | { | |
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); | |
49 | } | |
50 | ||
51 | /* Connect to Label Manager */ | |
52 | ||
53 | static int | |
54 | zebra_send_label_manager_connect () | |
55 | { | |
56 | int ret; | |
57 | ||
58 | printf("Connect to Label Manager\n"); | |
59 | ||
60 | ret = lm_label_manager_connect (zclient); | |
61 | printf ("Label Manager connection result: %u \n", ret); | |
62 | if (ret != 0 ) { | |
63 | fprintf (stderr, "Error %d connecting to Label Manager %s\n", ret, | |
64 | strerror(errno)); | |
65 | exit (1); | |
66 | } | |
67 | ||
68 | process_next_call (0, 0); | |
69 | } | |
70 | ||
71 | /* Get Label Chunk */ | |
72 | ||
73 | static int | |
74 | zebra_send_get_label_chunk () | |
75 | { | |
76 | uint32_t start; | |
77 | uint32_t end; | |
78 | int ret; | |
79 | ||
80 | printf("Ask for label chunk \n"); | |
81 | ||
82 | ret = lm_get_label_chunk (zclient, KEEP, CHUNK_SIZE, &start, &end); | |
83 | if (ret != 0 ) { | |
84 | fprintf (stderr, "Error %d requesting label chunk %s\n", ret, strerror(errno)); | |
85 | exit (1); | |
86 | } | |
87 | ||
88 | sequence++; | |
89 | ||
90 | printf ("Label Chunk assign: %u - %u \n", | |
91 | start, end); | |
92 | ||
93 | process_next_call (start, end); | |
94 | } | |
95 | ||
96 | /* Release Label Chunk */ | |
97 | ||
98 | static int | |
99 | zebra_send_release_label_chunk (uint32_t start, uint32_t end) | |
100 | { | |
101 | struct stream *s; | |
102 | int ret; | |
103 | ||
104 | printf("Release label chunk: %u - %u\n", start, end); | |
105 | ||
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 | } | |
111 | ||
112 | sequence++; | |
113 | ||
114 | process_next_call (start-CHUNK_SIZE, end-CHUNK_SIZE); | |
115 | } | |
116 | ||
117 | ||
118 | void init_zclient (struct thread_master *master, char *lm_zserv_path) | |
119 | { | |
120 | if (lm_zserv_path) | |
121 | zclient_serv_path_set(lm_zserv_path); | |
122 | ||
123 | zclient = zclient_new(master); | |
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 | } | |
132 | ||
133 | } | |
134 | ||
135 | int main (int argc, char *argv[]) | |
136 | { | |
137 | struct thread_master *master; | |
138 | struct thread thread; | |
139 | int ret; | |
140 | ||
141 | printf ("Sequence to be tested: %s\n", sequence); | |
142 | ||
143 | master = thread_master_create(); | |
144 | init_zclient (master, ZSERV_PATH); | |
145 | ||
146 | zebra_send_label_manager_connect (); | |
147 | ||
148 | return 0; | |
149 | } |