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]