def redirect(tokeniser): data = tokeniser() if data.count(':') == 1: prefix, suffix = data.split(':', 1) if prefix.count('.'): raise ValueError( 'this format has been deprecaded as it does not make sense and it is not supported by other vendors' ) asn = int(prefix) route_target = int(suffix) if asn >= pow(2, 32): raise ValueError('asn is a 32 bits number, value too large %s' % asn) if asn >= pow(2, 16): if route_target >= pow(2, 16): raise ValueError( 'asn is a 32 bits number, route target can only be 16 bit %s' % route_target) return NoNextHop, ExtendedCommunities().add( TrafficRedirectASN4(asn, route_target)) if route_target >= pow(2, 32): raise ValueError( 'route target is a 32 bits number, value too large %s' % route_target) return NoNextHop, ExtendedCommunities().add( TrafficRedirect(asn, route_target)) else: return IP.create(data), ExtendedCommunities().add( TrafficNextHop(False))
def redirect_next_hop(self, scope, name, command, tokens): try: change = scope[-1]['announce'][-1] if change.nlri.nexthop is NoNextHop: return self.error.set(self.syntax) change.attributes[Attribute.CODE.EXTENDED_COMMUNITY].add( TrafficNextHop(False)) return True except (IndexError, ValueError): return self.error.set(self.syntax)
def copy(self, scope, name, command, tokens): # README: We are setting the ASN as zero as that what Juniper (and Arbor) did when we created a local flow route try: if scope[-1]['announce'][-1].attributes.has( Attribute.CODE.NEXT_HOP): return self.error.set(self.syntax) change = scope[-1]['announce'][-1] change.nlri.nexthop = IP.create(tokens.pop(0)) change.attributes[Attribute.CODE.EXTENDED_COMMUNITY].add( TrafficNextHop(True)) return True except (IndexError, ValueError): return self.error.set(self.syntax)
def redirect(self, scope, name, command, tokens): try: if tokens[0].count(':') == 1: prefix, suffix = tokens[0].split(':', 1) if prefix.count('.'): raise ValueError( 'this format has been deprecaded as it does not make sense and it is not supported by other vendors' ) else: asn = int(prefix) route_target = int(suffix) if asn >= pow(2, 16): raise ValueError( 'asn is a 32 bits number, it can only be 16 bit %s' % route_target) if route_target >= pow(2, 32): raise ValueError( 'route target is a 32 bits number, value too large %s' % route_target) scope[-1]['announce'][-1].attributes[ Attribute.CODE.EXTENDED_COMMUNITY].add( TrafficRedirect(asn, route_target)) return True else: change = scope[-1]['announce'][-1] if change.nlri.nexthop is not NoNextHop: return self.error.set(self.syntax) nh = IP.create(tokens.pop(0)) change.nlri.nexthop = nh change.attributes[Attribute.CODE.EXTENDED_COMMUNITY].add( TrafficNextHop(False)) return True except (IndexError, ValueError): return self.error.set(self.syntax)
def copy(tokeniser): return IP.create(tokeniser()), ExtendedCommunities().add( TrafficNextHop(True))
def redirect_next_hop(tokeniser): return ExtendedCommunities().add(TrafficNextHop(False))