[frrcfgd][bgpcfgd] Add portchannel support (#8911)
* To add portchannel support in frrcfgd and bgpcfgd * Update is_zero_ip() to handle portchannel name Signed-off-by: d-dashkov <Dmytro_Dashkov@Jabil.com>
This commit is contained in:
parent
434a641026
commit
e8adee2c83
@ -169,7 +169,9 @@ class IpNextHop:
|
||||
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()
|
||||
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):
|
||||
@ -182,8 +184,15 @@ class IpNextHop:
|
||||
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 socket.error:
|
||||
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':
|
||||
|
@ -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"
|
||||
]
|
||||
)
|
||||
|
||||
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(
|
||||
|
@ -1636,7 +1636,9 @@ class IpNextHop:
|
||||
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):
|
||||
@ -1652,8 +1654,15 @@ class IpNextHop:
|
||||
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 socket.error:
|
||||
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)
|
||||
|
Reference in New Issue
Block a user