Skip to content

Commit ec69c33

Browse files
[EVPN-MH] Add CLI commands for EVPN VXLAN Multihoming configuration (#4247)
* [EVPN-MH]: add EVPN multihoming CLI and Static Anycast Gateway support Rebased on top of f66ad703 to resolve merge conflict in doc/Command-Reference.md (show vlan brief). Squashes the original PR #4247 commits into a single linear commit. Preserves both the new Static Anycast Gateway field description from the PR and the multi-ASIC namespace note added on master. Also fixes PR-introduced trailing whitespace and the 'show static-anycast_gateway' typo in doc/Command-Reference.md. Signed-off-by: Tamer Ahmed <tamerahmed@microsoft.com> * [EVPN-MH]: address CLI review comments Signed-off-by: Tamer Ahmed <tamerahmed@microsoft.com> * [EVPN-MH]: fix fdbshow CI failures Signed-off-by: Tamer Ahmed <tamerahmed@microsoft.com> * [EVPN-MH]: address follow-up review comments Signed-off-by: Tamer Ahmed <tamerahmed@microsoft.com> * [EVPN-MH]: fix interfaces test imports Signed-off-by: Tamer Ahmed <tamerahmed@microsoft.com> * [EVPN-MH]: address docs and sys-mac test comments Signed-off-by: Tamer Ahmed <tamerahmed@microsoft.com> --------- Signed-off-by: Tamer Ahmed <tamerahmed@microsoft.com> Co-authored-by: Tamer Ahmed <tamerahmed@microsoft.com>
1 parent e502e6a commit ec69c33

19 files changed

Lines changed: 2383 additions & 245 deletions

config/evpn_mh.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import click
2+
import utilities_common.cli as clicommon
3+
4+
from jsonpatch import JsonPatchConflict
5+
6+
from .validated_config_db_connector import ValidatedConfigDBConnector
7+
8+
#
9+
# EVPN MH commands
10+
#
11+
EVPN_MH_TABLE = 'EVPN_MH_GLOBAL'
12+
13+
#
14+
# 'evpn-mh' group ('config evpn-mh ...')
15+
#
16+
17+
18+
@click.group(cls=clicommon.AbbreviationGroup, name='evpn-mh')
19+
@click.pass_context
20+
def evpn_mh(ctx):
21+
"""Set EVPN MH attributes"""
22+
pass
23+
24+
25+
#
26+
# 'startup-delay' subcommand
27+
#
28+
EVPN_MH_STARTUP_DELAY_MIN = 0
29+
EVPN_MH_STARTUP_DELAY_DEFAULT = 300
30+
EVPN_MH_STARTUP_DELAY_MAX = 3600
31+
32+
33+
def is_valid_startup_delay(startup_delay):
34+
try:
35+
if int(startup_delay) in range(EVPN_MH_STARTUP_DELAY_MIN, EVPN_MH_STARTUP_DELAY_MAX + 1):
36+
return True
37+
except (ValueError, TypeError):
38+
pass
39+
return False
40+
41+
42+
@evpn_mh.command('startup-delay')
43+
@click.argument('startup_delay', metavar='<startup_delay>', required=True)
44+
@clicommon.pass_db
45+
@click.pass_context
46+
def set_startup_delay(ctx, db, startup_delay=EVPN_MH_STARTUP_DELAY_DEFAULT):
47+
"""Set EVPN MH startup delay time in seconds"""
48+
config_db = ValidatedConfigDBConnector(db.cfgdb)
49+
if not is_valid_startup_delay(startup_delay):
50+
ctx.fail(f"EVPN MH Startup Delay {startup_delay} is not valid. "
51+
f"Valid values are {EVPN_MH_STARTUP_DELAY_MIN}-{EVPN_MH_STARTUP_DELAY_MAX}.")
52+
53+
try:
54+
# Get existing entry to preserve other fields
55+
entry = config_db.get_entry(EVPN_MH_TABLE, 'default') or {}
56+
entry['startup_delay'] = startup_delay
57+
config_db.set_entry(EVPN_MH_TABLE, 'default', entry)
58+
except (ValueError, JsonPatchConflict) as e:
59+
ctx.fail("Failed to save to ConfigDB. Error: {}".format(e))
60+
61+
62+
#
63+
# 'mac-holdtime' subcommand
64+
#
65+
EVPN_MH_MAC_HOLDTIME_MIN = 0
66+
EVPN_MH_MAC_HOLDTIME_DEFAULT = 1080
67+
EVPN_MH_MAC_HOLDTIME_MAX = 86400
68+
69+
70+
def is_valid_mac_holdtime(mac_holdtime):
71+
try:
72+
if int(mac_holdtime) in range(EVPN_MH_MAC_HOLDTIME_MIN, EVPN_MH_MAC_HOLDTIME_MAX + 1):
73+
return True
74+
except (ValueError, TypeError):
75+
pass
76+
return False
77+
78+
79+
@evpn_mh.command('mac-holdtime')
80+
@click.argument('mac_holdtime', metavar='<mac_holdtime>', required=True)
81+
@clicommon.pass_db
82+
@click.pass_context
83+
def set_mac_holdtime(ctx, db, mac_holdtime=EVPN_MH_MAC_HOLDTIME_DEFAULT):
84+
"""Set EVPN MH MAC holdtime in seconds"""
85+
config_db = ValidatedConfigDBConnector(db.cfgdb)
86+
if not is_valid_mac_holdtime(mac_holdtime):
87+
ctx.fail(f"EVPN MH MAC Holdtime {mac_holdtime} is not valid. "
88+
f"Valid values are {EVPN_MH_MAC_HOLDTIME_MIN}-{EVPN_MH_MAC_HOLDTIME_MAX}.")
89+
90+
try:
91+
# Get existing entry to preserve other fields
92+
entry = config_db.get_entry(EVPN_MH_TABLE, 'default') or {}
93+
entry['mac_holdtime'] = mac_holdtime
94+
config_db.set_entry(EVPN_MH_TABLE, 'default', entry)
95+
except (ValueError, JsonPatchConflict) as e:
96+
ctx.fail("Failed to save to ConfigDB. Error: {}".format(e))
97+
98+
99+
#
100+
# 'neigh_holdtime' subcommand
101+
#
102+
EVPN_MH_NEIGH_HOLDTIME_MIN = 0
103+
EVPN_MH_NEIGH_HOLDTIME_DEFAULT = 1080
104+
EVPN_MH_NEIGH_HOLDTIME_MAX = 86400
105+
106+
107+
def is_valid_neigh_holdtime(neigh_holdtime):
108+
try:
109+
if int(neigh_holdtime) in range(EVPN_MH_NEIGH_HOLDTIME_MIN, EVPN_MH_NEIGH_HOLDTIME_MAX + 1):
110+
return True
111+
except (ValueError, TypeError):
112+
pass
113+
return False
114+
115+
116+
@evpn_mh.command('neigh-holdtime')
117+
@click.argument('neigh_holdtime', metavar='<neigh_holdtime>', required=True)
118+
@clicommon.pass_db
119+
@click.pass_context
120+
def set_neigh_holdtime(ctx, db, neigh_holdtime=EVPN_MH_NEIGH_HOLDTIME_DEFAULT):
121+
"""Set EVPN MH neighbor holdtime in seconds"""
122+
config_db = ValidatedConfigDBConnector(db.cfgdb)
123+
if not is_valid_neigh_holdtime(neigh_holdtime):
124+
ctx.fail(f"EVPN MH Neigh Holdtime {neigh_holdtime} is not valid. "
125+
f"Valid values are {EVPN_MH_NEIGH_HOLDTIME_MIN}-{EVPN_MH_NEIGH_HOLDTIME_MAX}.")
126+
127+
try:
128+
# Get existing entry to preserve other fields
129+
entry = config_db.get_entry(EVPN_MH_TABLE, 'default') or {}
130+
entry['neigh_holdtime'] = neigh_holdtime
131+
config_db.set_entry(EVPN_MH_TABLE, 'default', entry)
132+
except (ValueError, JsonPatchConflict) as e:
133+
ctx.fail("Failed to save to ConfigDB. Error: {}".format(e))

0 commit comments

Comments
 (0)