1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* SHARP - vty code
* Copyright (C) Cumulus Networks, Inc.
* Donald Sharp
*
* This file is part of FRR.
*
* FRR is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* FRR is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "vty.h"
#include "command.h"
#include "prefix.h"
#include "nexthop.h"
#include "log.h"
#include "vrf.h"
#include "zclient.h"
#include "sharpd/sharp_zebra.h"
#include "sharpd/sharp_vty.h"
#ifndef VTYSH_EXTRACT_PL
#include "sharpd/sharp_vty_clippy.c"
#endif
extern uint32_t total_routes;
extern uint32_t installed_routes;
extern uint32_t removed_routes;
DEFPY (install_routes,
install_routes_cmd,
"sharp install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes",
"Sharp routing Protocol\n"
"install some routes\n"
"Routes to install\n"
"Address to start /32 generation at\n"
"Nexthop to use\n"
"Nexthop address\n"
"How many to create\n")
{
int i;
struct prefix p;
struct nexthop nhop;
uint32_t temp;
total_routes = routes;
installed_routes = 0;
memset(&p, 0, sizeof(p));
memset(&nhop, 0, sizeof(nhop));
p.family = AF_INET;
p.prefixlen = 32;
p.u.prefix4 = start;
nhop.gate.ipv4 = nexthop;
nhop.type = NEXTHOP_TYPE_IPV4;
zlog_debug("Inserting %ld routes", routes);
temp = ntohl(p.u.prefix4.s_addr);
for (i = 0 ; i < routes ; i++) {
route_add(&p, &nhop);
p.u.prefix4.s_addr = htonl(++temp);
}
return CMD_SUCCESS;
}
DEFPY(vrf_label, vrf_label_cmd,
"sharp label vrf NAME$name label (0-100000)$label",
"Sharp Routing Protocol\n"
"Give a vrf a label\n"
VRF_CMD_HELP_STR
"The label to use, 0 specifies remove the label installed from previous\n"
"Specified range to use\n")
{
struct vrf *vrf;
if (strcmp(name, "default") == 0)
vrf = vrf_lookup_by_id(VRF_DEFAULT);
else
vrf = vrf_lookup_by_name(name);
if (!vrf) {
vty_out(vty, "Unable to find vrf you silly head");
return CMD_WARNING_CONFIG_FAILED;
}
if (label == 0)
label = MPLS_LABEL_NONE;
vrf_label_add(vrf->vrf_id, label);
return CMD_SUCCESS;
}
DEFPY (remove_routes,
remove_routes_cmd,
"sharp remove routes A.B.C.D$start (1-1000000)$routes",
"Sharp Routing Protocol\n"
"Remove some routes\n"
"Routes to remove\n"
"Starting spot\n"
"Routes to uniinstall\n")
{
int i;
struct prefix p;
uint32_t temp;
total_routes = routes;
removed_routes = 0;
memset(&p, 0, sizeof(p));
p.family = AF_INET;
p.prefixlen = 32;
p.u.prefix4 = start;
zlog_debug("Removing %ld routes", routes);
temp = ntohl(p.u.prefix4.s_addr);
for (i = 0; i < routes ; i++) {
route_delete(&p);
p.u.prefix4.s_addr = htonl(++temp);
}
return CMD_SUCCESS;
}
void sharp_vty_init(void)
{
install_element(ENABLE_NODE, &install_routes_cmd);
install_element(ENABLE_NODE, &remove_routes_cmd);
install_element(ENABLE_NODE, &vrf_label_cmd);
return;
}
|