2 * $Quagga: $Format:%an, %ai, %h$ $
4 * GNU Zebra client test main routine.
5 * Copyright (C) 1997 Kunihiro Ishiguro
7 * This file is part of GNU Zebra.
9 * GNU Zebra 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
14 * GNU Zebra 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.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
32 #include "zebra/rib.h"
33 #include "zebra/zserv.h"
35 struct thread *master;
37 /* Zebra client structure. */
38 struct zclient *zclient = NULL;
43 /* IPv4 route add and delete test. */
45 zebra_test_ipv4 (int command, int type, char *prefix, char *gateway,
53 str2prefix_ipv4 (prefix, &p);
54 inet_aton (gateway, &gate);
57 api.vrf_id = VRF_DEFAULT;
62 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
68 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
69 api.distance = distance;
75 case ZEBRA_IPV4_ROUTE_ADD:
76 zapi_ipv4_add (zclient, &p, &api);
78 case ZEBRA_IPV4_ROUTE_DELETE:
79 zapi_ipv4_delete (zclient, &p, &api);
85 /* IPv6 route add and delete test. */
87 zebra_test_v6 (int sock)
90 struct in6_addr nexthop;
92 str2prefix_ipv6 ("3ffe:506::2/128", &p);
93 inet_pton (AF_INET6, "::1", &nexthop);
95 /* zebra_ipv6_add (sock, ZEBRA_ROUTE_STATIC, 0, &p, &nexthop, 1); */
98 /* zebra_ipv6_delete (sock, ZEBRA_ROUTE_STATIC, 0, &p, &nexthop, 1); */
100 #endif /* HAVE_IPV6 */
102 /* Print out usage and exit. */
106 fprintf (stderr, "Usage: client filename\n");
116 { "static", ZEBRA_ROUTE_STATIC },
117 { "rip", ZEBRA_ROUTE_RIP },
118 { "ripng", ZEBRA_ROUTE_RIPNG },
119 { "babel", ZEBRA_ROUTE_BABEL },
120 { "ospf", ZEBRA_ROUTE_OSPF },
121 { "ospf6", ZEBRA_ROUTE_OSPF6 },
122 { "bgp", ZEBRA_ROUTE_BGP },
123 { "nhrp", ZEBRA_ROUTE_NHRP },
127 /* Zebra route simulator. */
132 char distance_str[BUFSIZ];
135 while (fgets (buf, sizeof buf, fp))
140 char str[BUFSIZ], command[BUFSIZ], prefix[BUFSIZ], gateway[BUFSIZ];
147 type = ZEBRA_ROUTE_STATIC;
149 ret = sscanf (buf, "%s %s %s %s %s\n", command, str, prefix, gateway,
154 distance = atoi (distance_str);
158 ret = sscanf (buf, "%s %s %s %s\n", command, str, prefix, gateway);
164 for (i = 0; i < 10; i++)
166 if (!zebra_type[i].str)
168 if (strcmp (zebra_type[i].str, str) == 0)
170 type = zebra_type[i].type;
175 if (strcmp (command, "add") == 0)
177 zebra_test_ipv4 (ZEBRA_IPV4_ROUTE_ADD, type, prefix, gateway,
183 if (strcmp (command, "del") == 0)
185 zebra_test_ipv4 (ZEBRA_IPV4_ROUTE_DELETE, type, prefix, gateway,
193 /* Test zebra client main routine. */
195 main (int argc, char **argv)
197 struct thread_master *master;
203 master = thread_master_create ();
204 /* Establish connection to zebra. */
205 zclient = zclient_new (master);
207 #ifdef HAVE_TCP_ZEBRA
208 zclient->sock = zclient_socket ();
210 zclient->sock = zclient_socket_un (ZEBRA_SERV_PATH);
211 #endif /* HAVE_TCP_ZEBRA */
213 /* Open simulation file. */
214 fp = fopen (argv[1], "r");
217 fprintf (stderr, "can't open %s\n", argv[1]);