def ip_label (tokeniser,afi,safi): ipmask = prefix(tokeniser) nlri = Label(afi,safi,OUT.ANNOUNCE) nlri.cidr = CIDR(ipmask.pack(),ipmask.mask) change = Change( nlri, Attributes() ) while True: command = tokeniser() if not command: break action = ParseLabel.action.get(command,'') if action == 'attribute-add': change.attributes.add(ParseLabel.known[command](tokeniser)) elif action == 'nlri-set': change.nlri.assign(ParseLabel.assign[command],ParseLabel.known[command](tokeniser)) elif action == 'nexthop-and-attribute': nexthop,attribute = ParseLabel.known[command](tokeniser) change.nlri.nexthop = nexthop change.attributes.add(attribute) else: raise ValueError('route: unknown command "%s"' % command) return [change]
def ip_label(tokeniser, afi, safi): action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW ipmask = prefix(tokeniser) nlri = Label(afi, safi, action) nlri.cidr = CIDR(ipmask.pack(), ipmask.mask) change = Change(nlri, Attributes()) while True: command = tokeniser() if not command: break action = AnnounceLabel.action.get(command, '') if action == 'attribute-add': change.attributes.add(AnnounceLabel.known[command](tokeniser)) elif action == 'nlri-set': change.nlri.assign(AnnounceLabel.assign[command], AnnounceLabel.known[command](tokeniser)) elif action == 'nexthop-and-attribute': nexthop, attribute = AnnounceLabel.known[command](tokeniser) change.nlri.nexthop = nexthop change.attributes.add(attribute) else: raise ValueError('unknown command "%s"' % command) if not AnnounceLabel.check(change, afi): raise ValueError('invalid announcement (missing next-hop or label ?)') return [change]
def __eq__(self, other): return \ Label.__eq__(self, other) and \ self.rd == other.rd and \ Label.__eq__(self,other)
def __len__(self): return Label.__len__(self) + len(self.rd)
def extensive(self): return "%s%s" % (Label.extensive(self), str(self.rd))
def __init__(self, afi, safi, action=OUT.UNSET): Label.__init__(self, afi, safi, action) self.rd = RouteDistinguisher.NORD
def _internal(self, announced=True): r = Label._internal(self, announced) if announced and self.rd: r.append(self.rd.json()) return r
def _internal (self, announced=True): r = Label._internal(self,announced) if announced and self.rd: r.append(self.rd.json()) return r
def __eq__ (self, other): return \ Label.__eq__(self, other) and \ self.rd == other.rd and \ Label.__eq__(self,other)
def __len__ (self): return Label.__len__(self) + len(self.rd)
def extensive (self): return "%s%s" % (Label.extensive(self),str(self.rd))
def __init__ (self, afi, safi, action=OUT.UNSET): Label.__init__(self, afi, safi, action) self.rd = RouteDistinguisher.NORD
def __eq__(self, other): return Label.__eq__( self, other) and self.rd == other.rd and Label.__eq__(self, other)