]>
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. */
42 zebra_test_ipv4 (int command
, int type
, char *prefix
, char *gateway
,
50 str2prefix_ipv4 (prefix
, &p
);
51 inet_aton (gateway
, &gate
);
54 api
.vrf_id
= VRF_DEFAULT
;
59 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
65 SET_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
);
66 api
.distance
= distance
;
72 case ZEBRA_IPV4_ROUTE_ADD
:
73 zapi_ipv4_add (zclient
, &p
, &api
);
75 case ZEBRA_IPV4_ROUTE_DELETE
:
76 zapi_ipv4_delete (zclient
, &p
, &api
);
81 /* IPv6 route add and delete test. */
83 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. */
101 fprintf (stderr
, "Usage: client filename\n");
111 { "static", ZEBRA_ROUTE_STATIC
},
112 { "rip", ZEBRA_ROUTE_RIP
},
113 { "ripng", ZEBRA_ROUTE_RIPNG
},
114 { "ospf", ZEBRA_ROUTE_OSPF
},
115 { "ospf6", ZEBRA_ROUTE_OSPF6
},
116 { "bgp", ZEBRA_ROUTE_BGP
},
117 { "nhrp", ZEBRA_ROUTE_NHRP
},
118 { "pim", ZEBRA_ROUTE_PIM
},
122 /* Zebra route simulator. */
127 char distance_str
[BUFSIZ
];
130 while (fgets (buf
, sizeof buf
, fp
))
135 char str
[BUFSIZ
], command
[BUFSIZ
], prefix
[BUFSIZ
], gateway
[BUFSIZ
];
142 type
= ZEBRA_ROUTE_STATIC
;
144 ret
= sscanf (buf
, "%s %s %s %s %s\n", command
, str
, prefix
, gateway
,
149 distance
= atoi (distance_str
);
153 ret
= sscanf (buf
, "%s %s %s %s\n", command
, str
, prefix
, gateway
);
159 for (i
= 0; i
< 10; i
++)
161 if (!zebra_type
[i
].str
)
163 if (strcmp (zebra_type
[i
].str
, str
) == 0)
165 type
= zebra_type
[i
].type
;
170 if (strcmp (command
, "add") == 0)
172 zebra_test_ipv4 (ZEBRA_IPV4_ROUTE_ADD
, type
, prefix
, gateway
,
178 if (strcmp (command
, "del") == 0)
180 zebra_test_ipv4 (ZEBRA_IPV4_ROUTE_DELETE
, type
, prefix
, gateway
,
188 /* Test zebra client main routine. */
190 main (int argc
, char **argv
)
192 struct thread_master
*master
;
198 master
= thread_master_create();
199 /* Establish connection to zebra. */
200 zclient
= zclient_new(master
);
202 #ifdef HAVE_TCP_ZEBRA
203 zclient
->sock
= zclient_socket ();
205 zclient
->sock
= zclient_socket_un (ZEBRA_SERV_PATH
);
206 #endif /* HAVE_TCP_ZEBRA */
208 /* Open simulation file. */
209 fp
= fopen (argv
[1], "r");
212 fprintf (stderr
,"%% Can't open configuration file %s due to '%s'\n",
213 argv
[1], safe_strerror(errno
));