Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[frrcfgd][bgpcfgd] Add portchannel support #8911

Merged
merged 8 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/sonic-bgpcfgd/bgpcfgd/managers_static_rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def __init__(self, af_id, blackhole, dst_ip, if_name, dist, vrf):
self.ip = zero_ip(af_id) if dst_ip is None or dst_ip == '' else dst_ip
self.interface = '' if if_name is None else if_name
self.nh_vrf = '' if vrf is None else vrf
if self.blackhole != 'true' and self.is_zero_ip() and len(self.interface.strip()) == 0:
if not self.is_portchannel():
self.is_ip_valid()
shi-su marked this conversation as resolved.
Show resolved Hide resolved
if self.blackhole != 'true' and self.is_zero_ip() and not self.is_portchannel() and len(self.interface.strip()) == 0:
log_err('Mandatory attribute not found for nexthop')
raise ValueError
def __eq__(self, other):
Expand All @@ -182,8 +184,15 @@ def __ne__(self, other):
self.distance != other.distance or self.nh_vrf != other.nh_vrf)
def __hash__(self):
return hash((self.af, self.blackhole, self.ip, self.interface, self.distance, self.nh_vrf))
def is_ip_valid(self):
socket.inet_pton(self.af, self.ip)
def is_zero_ip(self):
return sum([x for x in socket.inet_pton(self.af, self.ip)]) == 0
try:
return sum([x for x in socket.inet_pton(self.af, self.ip)]) == 0
except:
return False
def is_portchannel(self):
return True if self.ip.startswith('PortChannel') else False
def __format__(self, format):
ret_val = ''
if self.blackhole == 'true':
Expand Down
54 changes: 54 additions & 0 deletions src/sonic-bgpcfgd/tests/test_static_rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,60 @@ def test_set():
]
)

def test_set_nhportchannel():
mgr = constructor()
set_del_test(
mgr,
"SET",
("10.1.0.0/24", {
"nexthop": "PortChannel0001",
}),
True,
[
"ip route 10.1.0.0/24 PortChannel0001",
"router bgp 65100",
" address-family ipv4",
" redistribute static",
" address-family ipv6",
" redistribute static"
]
)
shi-su marked this conversation as resolved.
Show resolved Hide resolved

set_del_test(
mgr,
"DEL",
("10.1.0.0/24",),
True,
[
"no ip route 10.1.0.0/24 PortChannel0001",
"router bgp 65100",
" address-family ipv4",
" no redistribute static",
" address-family ipv6",
" no redistribute static"
]
)

def test_set_several_nhportchannels():
mgr = constructor()
set_del_test(
mgr,
"SET",
("10.1.0.0/24", {
"nexthop": "PortChannel0003,PortChannel0004",
}),
True,
[
"ip route 10.1.0.0/24 PortChannel0003",
"ip route 10.1.0.0/24 PortChannel0004",
"router bgp 65100",
" address-family ipv4",
" redistribute static",
" address-family ipv6",
" redistribute static"
]
)

def test_set_nhvrf():
mgr = constructor()
set_del_test(
Expand Down
13 changes: 11 additions & 2 deletions src/sonic-frr-mgmt-framework/frrcfgd/frrcfgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,9 @@ def __init__(self, af_id, blackhole, dst_ip, track, if_name, tag, dist, vrf):
self.interface = '' if if_name is None else if_name
self.tag = 0 if tag is None else int(tag)
self.nh_vrf = '' if vrf is None else vrf
if self.blackhole != 'true' and self.is_zero_ip() and len(self.interface.strip()) == 0:
if not self.is_portchannel():
self.is_ip_valid()
if self.blackhole != 'true' and self.is_zero_ip() and not self.is_portchannel() and len(self.interface.strip()) == 0:
syslog.syslog(syslog.LOG_ERR, 'Mandatory attribute not found for nexthop')
raise ValueError
def __eq__(self, other):
Expand All @@ -1652,8 +1654,15 @@ def __hash__(self):
def __str__(self):
return 'AF %d BKH %s IP %s TRACK %d INTF %s TAG %d DIST %d VRF %s' % (
self.af, self.blackhole, self.ip, self.track, self.interface, self.tag, self.distance, self.nh_vrf)
def is_ip_valid(self):
socket.inet_pton(self.af, self.ip)
def is_zero_ip(self):
return sum([x for x in socket.inet_pton(self.af, self.ip)]) == 0
try:
return sum([x for x in socket.inet_pton(self.af, self.ip)]) == 0
except:
return False
def is_portchannel(self):
return True if self.ip.startswith('PortChannel') else False
def get_arg_list(self):
arg = lambda x: '' if x is None else x
num_arg = lambda x: '' if x is None or x == 0 else str(x)
Expand Down