]>
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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 #include "zebra/rib.h"
31 #include "zebra/zserv.h"
33 struct thread
*master
;
35 /* Zebra client structure. */
36 struct zclient
*zclient
= NULL
;
41 /* IPv4 route add and delete test. */
43 zebra_test_ipv4 (int command
, int type
, char *prefix
, char *gateway
,
51 str2prefix_ipv4 (prefix
, &p
);
52 inet_aton (gateway
, &gate
);
55 api
.vrf_id
= VRF_DEFAULT
;
60 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
66 SET_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
);
67 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. */
84 zebra_test_v6 (int sock
)
87 struct in6_addr nexthop
;
89 str2prefix_ipv6 ("3ffe:506::2/128", &p
);
90 inet_pton (AF_INET6
, "::1", &nexthop
);
92 /* zebra_ipv6_add (sock, ZEBRA_ROUTE_STATIC, 0, &p, &nexthop, 1); */
95 /* zebra_ipv6_delete (sock, ZEBRA_ROUTE_STATIC, 0, &p, &nexthop, 1); */
98 /* Print out usage and exit. */
102 fprintf (stderr
, "Usage: client filename\n");
112 { "static", ZEBRA_ROUTE_STATIC
},
113 { "rip", ZEBRA_ROUTE_RIP
},
114 { "ripng", ZEBRA_ROUTE_RIPNG
},
115 { "ospf", ZEBRA_ROUTE_OSPF
},
116 { "ospf6", ZEBRA_ROUTE_OSPF6
},
117 { "bgp", ZEBRA_ROUTE_BGP
},
121 /* Zebra route simulator. */
126 char distance_str
[BUFSIZ
];
129 while (fgets (buf
, sizeof buf
, fp
))
134 char str
[BUFSIZ
], command
[BUFSIZ
], prefix
[BUFSIZ
], gateway
[BUFSIZ
];
141 type
= ZEBRA_ROUTE_STATIC
;
143 ret
= sscanf (buf
, "%s %s %s %s %s\n", command
, str
, prefix
, gateway
,
148 distance
= atoi (distance_str
);
152 ret
= sscanf (buf
, "%s %s %s %s\n", command
, str
, prefix
, gateway
);
158 for (i
= 0; i
< 10; i
++)
160 if (!zebra_type
[i
].str
)
162 if (strcmp (zebra_type
[i
].str
, str
) == 0)
164 type
= zebra_type
[i
].type
;
169 if (strcmp (command
, "add") == 0)
171 zebra_test_ipv4 (ZEBRA_IPV4_ROUTE_ADD
, type
, prefix
, gateway
,
177 if (strcmp (command
, "del") == 0)
179 zebra_test_ipv4 (ZEBRA_IPV4_ROUTE_DELETE
, type
, prefix
, gateway
,
187 /* Test zebra client main routine. */
189 main (int argc
, char **argv
)
191 struct thread_master
*master
;
197 master
= thread_master_create();
198 /* Establish connection to zebra. */
199 zclient
= zclient_new(master
);
201 #ifdef HAVE_TCP_ZEBRA
202 zclient
->sock
= zclient_socket ();
204 zclient
->sock
= zclient_socket_un (ZEBRA_SERV_PATH
);
205 #endif /* HAVE_TCP_ZEBRA */
207 /* Open simulation file. */
208 fp
= fopen (argv
[1], "r");
211 fprintf (stderr
,"%% Can't open configuration file %s due to '%s'\n",
212 argv
[1], safe_strerror(errno
));