]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/client_main.c
2 * GNU Zebra client test main routine.
3 * Copyright (C) 1997 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "zebra/rib.h"
30 #include "zebra/zserv.h"
32 struct thread
*master
;
34 /* Zebra client structure. */
35 struct zclient
*zclient
= NULL
;
40 /* IPv4 route add and delete test. */
41 void zebra_test_ipv4(int command
, int type
, char *prefix
, char *gateway
,
49 str2prefix_ipv4(prefix
, &p
);
50 if (!inet_aton(gateway
, &gate
)) {
51 printf("Gateway specified: %s is illegal\n", gateway
);
57 api
.vrf_id
= VRF_DEFAULT
;
62 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
67 SET_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
);
68 api
.distance
= distance
;
73 case ZEBRA_IPV4_ROUTE_ADD
:
74 zapi_ipv4_add(zclient
, &p
, &api
);
76 case ZEBRA_IPV4_ROUTE_DELETE
:
77 zapi_ipv4_delete(zclient
, &p
, &api
);
82 /* IPv6 route add and delete test. */
83 void zebra_test_v6(int sock
)
86 struct in6_addr nexthop
;
88 str2prefix_ipv6("3ffe:506::2/128", &p
);
89 inet_pton(AF_INET6
, "::1", &nexthop
);
91 /* zebra_ipv6_add (sock, ZEBRA_ROUTE_STATIC, 0, &p, &nexthop, 1); */
94 /* zebra_ipv6_delete (sock, ZEBRA_ROUTE_STATIC, 0, &p, &nexthop, 1); */
97 /* Print out usage and exit. */
100 fprintf(stderr
, "Usage: client filename\n");
107 } zebra_type
[] = {{"static", ZEBRA_ROUTE_STATIC
},
108 {"rip", ZEBRA_ROUTE_RIP
},
109 {"ripng", ZEBRA_ROUTE_RIPNG
},
110 {"ospf", ZEBRA_ROUTE_OSPF
},
111 {"ospf6", ZEBRA_ROUTE_OSPF6
},
112 {"bgp", ZEBRA_ROUTE_BGP
},
113 {"nhrp", ZEBRA_ROUTE_NHRP
},
114 {"pim", ZEBRA_ROUTE_PIM
},
117 /* Zebra route simulator. */
118 void zebra_sim(FILE *fp
)
121 char distance_str
[BUFSIZ
];
124 while (fgets(buf
, sizeof buf
, fp
)) {
128 char str
[BUFSIZ
], command
[BUFSIZ
], prefix
[BUFSIZ
],
136 type
= ZEBRA_ROUTE_STATIC
;
138 ret
= sscanf(buf
, "%s %s %s %s %s\n", command
, str
, prefix
,
139 gateway
, distance_str
);
142 distance
= atoi(distance_str
);
144 ret
= sscanf(buf
, "%s %s %s %s\n", command
, str
, prefix
,
151 for (i
= 0; i
< 10; i
++) {
152 if (!zebra_type
[i
].str
)
154 if (strcmp(zebra_type
[i
].str
, str
) == 0) {
155 type
= zebra_type
[i
].type
;
160 if (strcmp(command
, "add") == 0) {
161 zebra_test_ipv4(ZEBRA_IPV4_ROUTE_ADD
, type
, prefix
,
167 if (strcmp(command
, "del") == 0) {
168 zebra_test_ipv4(ZEBRA_IPV4_ROUTE_DELETE
, type
, prefix
,
176 /* Test zebra client main routine. */
177 int main(int argc
, char **argv
)
179 struct thread_master
*master
;
185 master
= thread_master_create(NULL
);
186 /* Establish connection to zebra. */
187 zclient
= zclient_new_notify(master
, &zclient_options_default
);
189 zclient_socket_connect(zclient
);
191 /* Open simulation file. */
192 fp
= fopen(argv
[1], "r");
195 "%% Can't open configuration file %s due to '%s'\n",
196 argv
[1], safe_strerror(errno
));