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

Fixbug: EVPN issue in FRR template #4260

Merged
merged 13 commits into from
Apr 3, 2020
107 changes: 107 additions & 0 deletions dockers/docker-fpm-frr/bgpcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ class BGPPeerMgr(Manager):
[
("meta", "localhost/bgp_asn"),
("neigmeta", ""),
("local_addresses", ""),
lguohan marked this conversation as resolved.
Show resolved Hide resolved
("interfaces", ""),
lguohan marked this conversation as resolved.
Show resolved Hide resolved
],
"CONFIG_DB",
swsscommon.CFG_BGP_NEIGHBOR_TABLE_NAME
Expand All @@ -290,6 +292,34 @@ class BGPPeerMgr(Manager):
vrf, nbr = key.split('|', 1)
if key not in self.peers:
cmd = None

if "local_addr" not in data:
syslog.syslog(syslog.LOG_WARNING, 'Peer {}. Error in missing required attribute "local_addr"'.format(key))
else:
# The route that belongs to a vnet cannot be advertised by the default BGP session.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know why you talk about route here. data['local_addr'] is the bgp session's local IP. Here you just check if bgp session's local IP is in one of local interface subnet.

# So we need to check whether this route belongs to a vnet.
local_addresses = self.directory.get_slot("local_addresses")
# Check if the information for the local address of this route has been set
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

route is not clear to me. here is a bgp session, not route.

# Which means we can find the interface for this route by its local address
# We can only process this route message when the local address was set
if data["local_addr"] not in local_addresses:
lguohan marked this conversation as resolved.
Show resolved Hide resolved
return False
local_address = local_addresses[data["local_addr"]]
interfaces = self.directory.get_slot("interfaces")
# Check if the information for the interface of this local address has set
# Which means we can determine whether this route belongs to a vnet
# Because the vnet name will be set in the interface
# Ref:https://github.com/Azure/SONiC/blob/master/doc/vxlan/Vxlan_hld.md#212-vnetinterface-table
if local_address.has_key("interface") and local_address["interface"] in interfaces:
lguohan marked this conversation as resolved.
Show resolved Hide resolved
interface = interfaces[local_address["interface"]]
# Check if this route is belong to a vnet
if interface.has_key("vnet_name") and interface["vnet_name"]:
# Ignore the route that is in a vnet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be bgp session.

syslog.syslog(syslog.LOG_INFO, 'Peer {} in vnet {}'.format(key, interface["vnet_name"]))
return True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i finally understood what you are trying to do in this block (spend about 30 minutes)! it is so difficult to understand because people do not understand what local_addresses and interfaces mean. In fact, what you really should do here is to create two functions.
one function is
find_local_interface(ip). The input is a ip address, and return value is interface name. return None if you cannot find a interface.

second function is
check_interface_type(interface_name). You can return vnet interface it is vnet interface, or default if the interface is in default vrf.

since you do not have such abstract, it is difficult for others to understand the code and maintain.

Please put code readability into priority.

else:
return False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should be the log message here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is an intermediate state. Maybe it should add some log with INFO level to display this state. Same problem at here https://github.com/Azure/sonic-buildimage/blob/master/dockers/docker-fpm-frr/bgpcfgd#L295


neigmeta = self.directory.get_slot("neigmeta")
if 'name' in data and data["name"] not in neigmeta:
return False
Expand Down Expand Up @@ -390,6 +420,79 @@ class BGPPeerMgr(Manager):
return peers


def prefix_attr(attr, value):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really a bad interface design! the function name is generic. in fact the fuction does very specific thing, it assume the value is ip prefix and convert the string into ipnetwork, and then get an attribute, and finally convert it into a string.

to evaulate whether a function provide a good abstraction or not. People should be able to understand the what the function's job by just looking at the function name at the caller without looking into the implementation of the function.

I think you need to either get rid of this function, or have a function get_ip_from_ipprefix function to do the specific job you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with your comment. And I think this is a very common tool function maybe we should extract it to a common python package.
Because we did also use it at : https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-config-engine/sonic-cfggen#L81
Should I do that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, that was my miss. it is not a good code.


In reply to: 400696041 [](ancestors = 400696041)

if not value:
return None
else:
try:
prefix = netaddr.IPNetwork(str(value))
except:
return None
return str(getattr(prefix, attr))


class InterfaceMgr(Manager):
def __init__(self, daemon, directory, interface_table = swsscommon.CFG_INTF_TABLE_NAME):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also want to consider VLAN_INTERFACE as well - CFG_VLAN_INTF_TABLE_NAME

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion. Have added VlanInterfaceMgr.

super(InterfaceMgr, self).__init__(
daemon,
directory,
[],
"CONFIG_DB",
interface_table
)

def set_handler(self, key, data):
# There are two types of entries for an interface.
# One of them is to specify ip and prefix.
# In this case, the key contains '|', like "Ethernet0|192.168.0.6/30".
# Another one is to specify whether this interface belongs to a vnet
# In this case, the key only includes the interface name.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this true that vnet interface will only have interface name without ip addresses? @prsunny ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, vnet interface will also have ip address as any other regular entry. I don't think we need to mention about 'vnet' in this function as this is a generic handler. The comment can just state, "Interface table can have two keys, one with ip prefix and one without ip prefix".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pterosaur , can you modify the comment accordingly, current description is not accurate.

if '|' in key:
data = {}
data["interface"], network = key.split('|', 1)
data["prefixlen"] = prefix_attr("prefixlen", network)
ip = prefix_attr("ip", network)
self.directory.put("local_addresses", ip, data)
else:
self.directory.put("interfaces", key, data)
return True

def del_handler(self, key):
if '|' in key:
_, network = key.split('|', 1)
ip = prefix_attr("ip", network)
self.directory.remove("local_addresses", ip)
else:
self.directory.remove("interfaces", key)


class LoopbackInterfaceMgr(InterfaceMgr):
def __init__(self, daemon, directory):
super(LoopbackInterfaceMgr, self).__init__(
daemon,
directory,
swsscommon.CFG_LOOPBACK_INTERFACE_TABLE_NAME
)


class VlanInterfaceMgr(InterfaceMgr):
def __init__(self, daemon, directory):
super(VlanInterfaceMgr, self).__init__(
daemon,
directory,
swsscommon.CFG_VLAN_INTF_TABLE_NAME
)


class PortChannelInterfaceMgr(InterfaceMgr):
def __init__(self, daemon, directory):
super(PortChannelInterfaceMgr, self).__init__(
daemon,
directory,
swsscommon.CFG_LAG_INTF_TABLE_NAME
)


def wait_for_bgpd():
# wait for 20 seconds
stop_time = datetime.datetime.now() + datetime.timedelta(seconds=20)
Expand All @@ -408,6 +511,10 @@ def main():
BGPDeviceMetaMgr,
BGPNeighborMetaMgr,
BGPPeerMgr,
InterfaceMgr,
LoopbackInterfaceMgr,
VlanInterfaceMgr,
PortChannelInterfaceMgr,
]
wait_for_bgpd()
daemon = Daemon()
Expand Down
3 changes: 1 addition & 2 deletions dockers/docker-fpm-frr/bgpd.peer.conf.j2
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
neighbor {{ neighbor_addr }} next-hop-self
{% endif %}
{% if bgp_session["asn"] == DEVICE_METADATA['localhost']['bgp_asn']
and DEVICE_METADATA['localhost']['type'] == "SpineChassisFrontendRouter"
and (not bgp_session.has_key("local_addr") or bgp_session["local_addr"] not in interfaces_in_vnets) %}
and DEVICE_METADATA['localhost']['type'] == "SpineChassisFrontendRouter" %}
address-family l2vpn evpn
neighbor {{ neighbor_addr }} activate
advertise-all-vni
Expand Down