Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
peers = match_neighbors(reactor.peers,descriptions)
if not peers:
self.log_failure('no neighbor matching the command : %s' % command)
reactor.processes.answer_error(service)
yield True
return
changes = self.api_vpls(command)
if not changes:
self.log_failure('command could not parse vpls in : %s' % command)
reactor.processes.answer_error(service)
yield True
return
for change in changes:
change.nlri.action = OUT.ANNOUNCE
reactor.configuration.inject_change(peers,change)
self.log_message('vpls added to %s : %s' % (', '.join(peers) if peers else 'all peers',change.extensive()))
yield False
reactor.processes.answer_done(service)
except ValueError:
self.log_failure('issue parsing the vpls')
reactor.processes.answer_error(service)
yield True
except IndexError:
self.log_failure('issue parsing the vpls')
reactor.processes.answer_error(service)
yield True
def __init__ (self, rd, ve, base, offset, size):
NLRI.__init__(self,AFI.l2vpn,SAFI.vpls)
self.action = OUT.ANNOUNCE
self.nexthop = None
self.rd = rd
self.base = base
self.offset = offset
self.size = size
self.ve = ve
self.unique = unique.next()
def __init__ (self, afi=AFI.ipv4,safi=SAFI.flow_ip,nexthop=None,rd=None):
NLRI.__init__(self,afi,safi)
self.rules = {}
self.action = OUT.ANNOUNCE
self.nexthop = IP.unpack(nexthop) if nexthop else NoIP
self.rd = rd
self.unique = unique.next()
def update_cache (self,change):
if not self.cache:
return
family = change.nlri.family()
index = change.index()
if change.nlri.action == OUT.ANNOUNCE:
self._seen.setdefault(family,{})[index] = change
elif family in self._seen:
self._seen[family].pop(index,None)
def ip_vpn (tokeniser,afi,safi):
action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW
ipmask = prefix(tokeniser)
nlri = IPVPN(afi, safi, action)
nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
change = Change(
nlri,
Attributes()
)
while True:
command = tokeniser()
if not command:
break
klass = last.nlri.__class__
path_info = last.nlri.path_info
nexthop = last.nlri.nexthop
if klass.has_label():
labels = last.nlri.labels
if klass.has_rd():
rd = last.nlri.rd
# XXX: Looks weird to set and then set to None, check
last.nlri.cidr.mask = cut
last.nlri = None
# generate the new routes
for _ in range(number):
# update ip to the next route, this recalculate the "ip" field of the Inet class
nlri = klass(afi,safi,OUT.ANNOUNCE)
nlri.cidr = CIDR(pack_int(afi,ip),cut)
nlri.nexthop = nexthop # nexthop can be NextHopSelf
nlri.path_info = path_info
# Really ugly
if klass.has_label():
nlri.labels = labels
if klass.has_rd():
nlri.rd = rd
# next ip
ip += increment
yield Change(nlri,last.attributes)
def __init__ (self, afi, safi, action=OUT.UNSET):
MPLS.__init__(self, afi, safi, action)
def new (cls, afi, safi, packed, mask, labels, rd, nexthop=None, action=OUT.UNSET):
instance = cls(afi,safi,action)
instance.cidr = CIDR(packed, mask)
instance.labels = labels
instance.rd = rd
instance.nexthop = IP.create(nexthop) if nexthop else NoNextHop
instance.action = action
return instance
def check (change,afi):
if not AnnouncePath.check(change,afi):
return False
if change.nlri.action == OUT.ANNOUNCE \
and change.nlri.has_label() \
and change.nlri.labels is Labels.NOLABEL:
return False
return True