Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def unpack_message (cls, data, negotiated):
header_length = len(EOR.NLRI.PREFIX)
return cls(AFI.unpack(data[header_length:header_length+2]),SAFI.unpack(data[header_length+2]))
def _add (self, tokeniser, afi_name, safi_names):
self._check_duplicate(tokeniser,RaisedFamily)
known = self.content.setdefault(AFI(AFI.value(afi_name)),[])
for (idx_line,idx_column,line,safi_name) in safi_names:
if safi_name not in AFI.implemented_safi(afi_name):
raise RaisedFamily(Location(idx_line,idx_column,line),'the family pair afi/safi %s/%s is unimplemented' % (afi_name,safi_name))
safi = SAFI(SAFI.value(safi_name))
if safi in known:
raise RaisedFamily(Location(idx_line,idx_column,line),'afi/safi pair already defined in this family')
known.append(safi)
rr_announced.append((afi,safi))
yield Update(RouteRefresh(afi,safi,RouteRefresh.start),Attributes())
# generating Updates from what is in the RIB
for attr_index,per_family in attr_af_nlri.items():
for family, changes in per_family.items():
if not changes:
continue
# only yield once we have a consistent state, otherwise it will go wrong
# as we will try to modify things we are iterating over and using
attributes = new_attr[attr_index]
if family == (AFI.ipv4,SAFI.unicast) and grouped:
yield Update([change.nlri for change in changes.values()], attributes)
else:
for change in changes.values():
yield Update([change.nlri,], attributes)
# If we are performing a route-refresh, indicating that the
# update were all sent
if rr_announced:
for afi,safi in rr_announced:
self._enhanced_refresh_start.remove((afi,safi))
yield Update(RouteRefresh(afi,safi,RouteRefresh.end),Attributes())
for change in self._enhanced_refresh_delay:
self.add_to_rib(change,True)
self._enhanced_refresh_delay = []
env.log.enable = True
if LOG.logger.getEffectiveLevel():
env.log.level = environment.syslog_value(
python_logging.getLevelName(LOG.logger.getEffectiveLevel())
)
else:
env.log.level = environment.syslog_value('INFO')
env.log.all = True
env.log.packets = True
# monkey patch exabgp to work around exabgp issue #690
# only relevant for exabgp 4.0.2
# ( https://github.com/Exa-Networks/exabgp/issues/690 )
if hasattr(exa_family.Family, 'size'):
exa_family.Family.size[(exa_family.AFI.l2vpn,
exa_family.SAFI.evpn)] = ((4,), 0)
for c in string:
value = (value << 8) + ord(c)
return value
# def short (value):
# return (ord(value[0]) << 8) + ord(value[1])
# Interface ..................
class IPv4 (object):
afi = AFI.ipv4
class IPv6 (object):
afi = AFI.ipv6
class IPrefix (object):
pass
# Prococol
class IPrefix4 (IPrefix,IComponent,IPv4):
# Must be defined in subclasses
CODE = -1
NAME = ''
# not used, just present for simplying the nlri generation
operations = 0x0
def top (self, negotiated=None, afi=AFI.undefined):
if not self._ip:
self._ip = IP.ntop(self._packed)
return self._ip
if self.debug: raise Exception() # noqa
return False
try:
safi = tokens.pop(0)
except IndexError:
self._error = 'missing family safi'
if self.debug: raise Exception() # noqa
return False
if safi == 'unicast':
scope[-1]['families'].append((AFI(AFI.ipv4),SAFI(SAFI.unicast)))
elif safi == 'multicast':
scope[-1]['families'].append((AFI(AFI.ipv4),SAFI(SAFI.multicast)))
elif safi == 'nlri-mpls':
scope[-1]['families'].append((AFI(AFI.ipv4),SAFI(SAFI.nlri_mpls)))
elif safi == 'mpls-vpn':
scope[-1]['families'].append((AFI(AFI.ipv4),SAFI(SAFI.mpls_vpn)))
elif safi in ('flow'):
scope[-1]['families'].append((AFI(AFI.ipv4),SAFI(SAFI.flow_ip)))
elif safi == 'flow-vpn':
scope[-1]['families'].append((AFI(AFI.ipv4),SAFI(SAFI.flow_vpn)))
else:
return False
return True