Skip to content

Commit bf27881

Browse files
rodnymolinajleveque
authored andcommitted
Splitting 'show' and 'clear' parse-chains to address overlapping functionality (sonic-net#128)
The following patch provides a simple mechanism to allow overlapping parse-chains to co-exist without interfering with each other. In this particular example, we are separating BGP functionality attending to the routing-stack being used in the system. As part of these changes, Quagga-based systems will exclusively rely on 'show ip/ipv6 bgp' and 'clear ip/ipv6 bgp' stanzas, whereas FRR will make use of 'show bgp ipv4/ipv6' and 'clear bgp ipv4/ipv6' ones. Also, a few bugs are getting fixed here.
1 parent 875c1a1 commit bf27881

File tree

15 files changed

+1110
-57
lines changed

15 files changed

+1110
-57
lines changed

clear/__init__.py

Whitespace-only changes.

clear/aliases.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[aliases]
2+
running-configuration=runningconfiguration
3+
running-config=runningconfiguration
4+
startup-configuration=startupconfiguration
5+
startup-config=startupconfiguration

clear/bgp_frr_v4.py

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
import click
2+
from clear.main import *
3+
4+
5+
###############################################################################
6+
#
7+
# 'clear bgp' cli stanza
8+
#
9+
###############################################################################
10+
11+
12+
@cli.group(cls=AliasedGroup, default_if_no_args=True)
13+
def bgp():
14+
"""Clear BGP peers / state"""
15+
pass
16+
17+
18+
# Default 'bgp' command (called if no subcommands or their aliases were passed)
19+
@bgp.command(default=True)
20+
def default():
21+
"""Clear all BGP peers"""
22+
command = 'sudo vtysh -c "clear bgp *"'
23+
run_command(command)
24+
25+
26+
@bgp.group(cls=AliasedGroup, default_if_no_args=True,
27+
context_settings=CONTEXT_SETTINGS)
28+
def neighbor():
29+
"""Clear specific BGP peers"""
30+
pass
31+
32+
33+
@neighbor.command(default=True)
34+
@click.argument('ipaddress', required=False)
35+
def default(ipaddress):
36+
"""Clear all BGP peers"""
37+
38+
if ipaddress is not None:
39+
command = 'sudo vtysh -c "clear bgp {} "'.format(ipaddress)
40+
else:
41+
command = 'sudo vtysh -c "clear bgp *"'
42+
run_command(command)
43+
44+
45+
# 'in' subcommand
46+
@neighbor.command('in')
47+
@click.argument('ipaddress', required=False)
48+
def neigh_in(ipaddress):
49+
"""Send route-refresh"""
50+
51+
if ipaddress is not None:
52+
command = 'sudo vtysh -c "clear bgp {} in"'.format(ipaddress)
53+
else:
54+
command = 'sudo vtysh -c "clear bgp * in"'
55+
run_command(command)
56+
57+
58+
# 'out' subcommand
59+
@neighbor.command('out')
60+
@click.argument('ipaddress', required=False)
61+
def neigh_out(ipaddress):
62+
"""Resend all outbound updates"""
63+
64+
if ipaddress is not None:
65+
command = 'sudo vtysh -c "clear bgp {} out"'.format(ipaddress)
66+
else:
67+
command = 'sudo vtysh -c "clear bgp * out"'
68+
run_command(command)
69+
70+
71+
@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
72+
context_settings=CONTEXT_SETTINGS)
73+
def soft():
74+
"""Soft reconfig BGP's inbound/outbound updates"""
75+
pass
76+
77+
78+
@soft.command(default=True)
79+
@click.argument('ipaddress', required=False)
80+
def default(ipaddress):
81+
"""Clear BGP peers soft configuration"""
82+
83+
if ipaddress is not None:
84+
command = 'sudo vtysh -c "clear bgp {} soft "'.format(ipaddress)
85+
else:
86+
command = 'sudo vtysh -c "clear bgp * soft"'
87+
run_command(command)
88+
89+
90+
# 'soft in' subcommand
91+
@soft.command('in')
92+
@click.argument('ipaddress', required=False)
93+
def soft_in(ipaddress):
94+
"""Send route-refresh"""
95+
96+
if ipaddress is not None:
97+
command = 'sudo vtysh -c "clear bgp {} soft in"'.format(ipaddress)
98+
else:
99+
command = 'sudo vtysh -c "clear bgp * soft in"'
100+
run_command(command)
101+
102+
103+
# 'soft out' subcommand
104+
@soft.command('out')
105+
@click.argument('ipaddress', required=False)
106+
def soft_out(ipaddress):
107+
"""Resend all outbound updates"""
108+
109+
if ipaddress is not None:
110+
command = 'sudo vtysh -c "clear bgp {} soft out"'.format(ipaddress)
111+
else:
112+
command = 'sudo vtysh -c "clear bgp * soft out"'
113+
run_command(command)
114+
115+
116+
###############################################################################
117+
#
118+
# 'clear bgp ipv4' cli stanza
119+
#
120+
###############################################################################
121+
122+
123+
@bgp.group(cls=AliasedGroup, default_if_no_args=True,
124+
context_settings=CONTEXT_SETTINGS)
125+
def ipv4():
126+
"""Clear BGP IPv4 peers / state"""
127+
pass
128+
129+
130+
# Default 'bgp' command (called if no subcommands or their aliases were passed)
131+
@ipv4.command(default=True)
132+
def default():
133+
"""Clear all IPv4 BGP peers"""
134+
command = 'sudo vtysh -c "clear bgp ipv4 *"'
135+
run_command(command)
136+
137+
138+
@ipv4.group(cls=AliasedGroup, default_if_no_args=True,
139+
context_settings=CONTEXT_SETTINGS)
140+
def neighbor():
141+
"""Clear specific IPv4 BGP peers"""
142+
pass
143+
144+
145+
@neighbor.command(default=True)
146+
@click.argument('ipaddress', required=False)
147+
def default(ipaddress):
148+
"""Clear all IPv4 BGP peers"""
149+
150+
if ipaddress is not None:
151+
command = 'sudo vtysh -c "clear bgp ipv4 {} "'.format(ipaddress)
152+
else:
153+
command = 'sudo vtysh -c "clear bgp ipv4 *"'
154+
run_command(command)
155+
156+
157+
# 'in' subcommand
158+
@neighbor.command('in')
159+
@click.argument('ipaddress', required=False)
160+
def neigh_in(ipaddress):
161+
"""Send route-refresh"""
162+
163+
if ipaddress is not None:
164+
command = 'sudo vtysh -c "clear bgp ipv4 {} in"'.format(ipaddress)
165+
else:
166+
command = 'sudo vtysh -c "clear bgp ipv4 * in"'
167+
run_command(command)
168+
169+
170+
# 'out' subcommand
171+
@neighbor.command('out')
172+
@click.argument('ipaddress', required=False)
173+
def neigh_out(ipaddress):
174+
"""Resend all outbound updates"""
175+
176+
if ipaddress is not None:
177+
command = 'sudo vtysh -c "clear bgp ipv4 {} out"'.format(ipaddress)
178+
else:
179+
command = 'sudo vtysh -c "clear bgp ipv4 * out"'
180+
run_command(command)
181+
182+
183+
@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
184+
context_settings=CONTEXT_SETTINGS)
185+
def soft():
186+
"""Soft reconfig BGP's inbound/outbound updates"""
187+
pass
188+
189+
190+
@soft.command(default=True)
191+
@click.argument('ipaddress', required=False)
192+
def default(ipaddress):
193+
"""Clear BGP neighbors soft configuration"""
194+
195+
if ipaddress is not None:
196+
command = 'sudo vtysh -c "clear bgp ipv4 {} soft "'.format(ipaddress)
197+
else:
198+
command = 'sudo vtysh -c "clear bgp ipv4 * soft"'
199+
run_command(command)
200+
201+
202+
# 'soft in' subcommand
203+
@soft.command('in')
204+
@click.argument('ipaddress', required=False)
205+
def soft_in(ipaddress):
206+
"""Send route-refresh"""
207+
208+
if ipaddress is not None:
209+
command = 'sudo vtysh -c "clear bgp ipv4 {} soft in"'.format(ipaddress)
210+
else:
211+
command = 'sudo vtysh -c "clear bgp ipv4 * soft in"'
212+
run_command(command)
213+
214+
215+
# 'soft out' subcommand
216+
@soft.command('out')
217+
@click.argument('ipaddress', required=False)
218+
def soft_out(ipaddress):
219+
"""Resend all outbound updates"""
220+
221+
if ipaddress is not None:
222+
command = 'sudo vtysh -c "clear bgp ipv4 {} soft out"'.\
223+
format(ipaddress)
224+
else:
225+
command = 'sudo vtysh -c "clear bgp ipv4 * soft out"'
226+
run_command(command)

clear/bgp_frr_v6.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import click
2+
from clear.main import *
3+
4+
5+
###############################################################################
6+
#
7+
# 'clear bgp ipv6' cli stanza
8+
#
9+
###############################################################################
10+
11+
12+
@bgp.group(cls=AliasedGroup, default_if_no_args=True)
13+
def ipv6():
14+
"""Clear BGP IPv6 peers / state"""
15+
pass
16+
17+
18+
# Default 'bgp' command (called if no subcommands or their aliases were passed)
19+
@ipv6.command(default=True)
20+
def default():
21+
"""Clear all IPv6 BGP peers"""
22+
command = 'sudo vtysh -c "clear bgp ipv6 *"'
23+
run_command(command)
24+
25+
26+
@ipv6.group(cls=AliasedGroup, default_if_no_args=True,
27+
context_settings=CONTEXT_SETTINGS)
28+
def neighbor():
29+
"""Clear specific IPv6 BGP peers"""
30+
pass
31+
32+
33+
@neighbor.command(default=True)
34+
@click.argument('ipaddress', required=False)
35+
def default(ipaddress):
36+
"""Clear all IPv6 BGP peers"""
37+
38+
if ipaddress is not None:
39+
command = 'sudo vtysh -c "clear bgp ipv6 {} "'.format(ipaddress)
40+
else:
41+
command = 'sudo vtysh -c "clear bgp ipv6 *"'
42+
run_command(command)
43+
44+
45+
# 'in' subcommand
46+
@neighbor.command('in')
47+
@click.argument('ipaddress', required=False)
48+
def neigh_in(ipaddress):
49+
"""Send route-refresh"""
50+
51+
if ipaddress is not None:
52+
command = 'sudo vtysh -c "clear bgp ipv6 {} in"'.format(ipaddress)
53+
else:
54+
command = 'sudo vtysh -c "clear bgp ipv6 * in"'
55+
run_command(command)
56+
57+
58+
# 'out' subcommand
59+
@neighbor.command('out')
60+
@click.argument('ipaddress', required=False)
61+
def neigh_out(ipaddress):
62+
"""Resend all outbound updates"""
63+
64+
if ipaddress is not None:
65+
command = 'sudo vtysh -c "clear bgp ipv6 {} out"'.format(ipaddress)
66+
else:
67+
command = 'sudo vtysh -c "clear bgp ipv6 * out"'
68+
run_command(command)
69+
70+
71+
@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
72+
context_settings=CONTEXT_SETTINGS)
73+
def soft():
74+
"""Soft reconfig BGP's inbound/outbound updates"""
75+
pass
76+
77+
78+
@soft.command(default=True)
79+
@click.argument('ipaddress', required=False)
80+
def default(ipaddress):
81+
"""Clear BGP neighbors soft configuration"""
82+
83+
if ipaddress is not None:
84+
command = 'sudo vtysh -c "clear bgp ipv6 {} soft "'.format(ipaddress)
85+
else:
86+
command = 'sudo vtysh -c "clear bgp ipv6 * soft"'
87+
run_command(command)
88+
89+
90+
# 'soft in' subcommand
91+
@soft.command('in')
92+
@click.argument('ipaddress', required=False)
93+
def soft_in(ipaddress):
94+
"""Send route-refresh"""
95+
96+
if ipaddress is not None:
97+
command = 'sudo vtysh -c "clear bgp ipv6 {} soft in"'.format(ipaddress)
98+
else:
99+
command = 'sudo vtysh -c "clear bgp ipv6 * soft in"'
100+
run_command(command)
101+
102+
103+
# 'soft out' subcommand
104+
@soft.command('out')
105+
@click.argument('ipaddress', required=False)
106+
def soft_out(ipaddress):
107+
"""Resend all outbound updates"""
108+
109+
if ipaddress is not None:
110+
command = 'sudo vtysh -c "clear bgp ipv6 {} soft out"' \
111+
.format(ipaddress)
112+
else:
113+
command = 'sudo vtysh -c "clear bgp ipv6 * soft out"'
114+
run_command(command)

0 commit comments

Comments
 (0)