コード例 #1
0
ファイル: ip.py プロジェクト: steiler/exabgp
def ip(tokeniser, afi, safi):
    ipmask = prefix(tokeniser)

    nlri = INET(afi, safi, OUT.ANNOUNCE)
    nlri.cidr = CIDR(ipmask.pack(), ipmask.mask)

    change = Change(nlri, Attributes())

    while True:
        command = tokeniser()

        if not command:
            break

        action = ParseIP.action.get(command, '')

        if action == 'attribute-add':
            change.attributes.add(ParseIP.known[command](tokeniser))
        elif action == 'nlri-set':
            change.nlri.assign(ParseIP.assign[command],
                               ParseIP.known[command](tokeniser))
        elif action == 'nexthop-and-attribute':
            nexthop, attribute = ParseIP.known[command](tokeniser)
            change.nlri.nexthop = nexthop
            change.attributes.add(attribute)
        else:
            raise ValueError('route: unknown command "%s"' % command)

    return [change]
コード例 #2
0
ファイル: ip.py プロジェクト: Exa-Networks/exabgp
def ip_multicast (tokeniser,afi,safi):
	ipmask = prefix(tokeniser)

	nlri = INET(afi,safi,OUT.ANNOUNCE)
	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)

	change = Change(
		nlri,
		Attributes()
	)

	while True:
		command = tokeniser()

		if not command:
			break

		action = AnnounceIP.action.get(command,'')

		if action == 'attribute-add':
			change.attributes.add(AnnounceIP.known[command](tokeniser))
		elif action == 'nlri-set':
			change.nlri.assign(AnnounceIP.assign[command],AnnounceIP.known[command](tokeniser))
		elif action == 'nexthop-and-attribute':
			nexthop,attribute = AnnounceIP.known[command](tokeniser)
			change.nlri.nexthop = nexthop
			change.attributes.add(attribute)
		else:
			raise ValueError('route: unknown command "%s"' % command)

	return [change]
コード例 #3
0
ファイル: path.py プロジェクト: bopopescu/exabgp-1
def ip_unicast(tokeniser, afi, safi):
    action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW
    ipmask = prefix(tokeniser)

    nlri = INET(afi, safi, action)
    nlri.cidr = CIDR(ipmask.pack(), ipmask.mask)

    change = Change(nlri, Attributes())

    while True:
        command = tokeniser()

        if not command:
            break

        action = AnnouncePath.action.get(command, '')

        if action == 'attribute-add':
            change.attributes.add(AnnouncePath.known[command](tokeniser))
        elif action == 'nlri-set':
            change.nlri.assign(AnnouncePath.assign[command],
                               AnnouncePath.known[command](tokeniser))
        elif action == 'nexthop-and-attribute':
            nexthop, attribute = AnnouncePath.known[command](tokeniser)
            change.nlri.nexthop = nexthop
            change.attributes.add(attribute)
        else:
            raise ValueError('unknown command "%s"' % command)

    if not AnnouncePath.check(change, afi):
        raise ValueError('invalid announcement (missing next-hop ?)')

    return [change]
コード例 #4
0
def route (tokeniser):
	action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW
	ipmask = prefix(tokeniser)
	check = lambda change,afi: True

	if 'rd' in tokeniser.tokens or 'route-distinguisher' in tokeniser.tokens:
		nlri = IPVPN(IP.toafi(ipmask.top()),SAFI.mpls_vpn,action)
		check = AnnounceVPN.check
	elif 'label' in tokeniser.tokens:
		nlri = Label(IP.toafi(ipmask.top()),SAFI.nlri_mpls,action)
		check = AnnounceLabel.check
	else:
		nlri = INET(IP.toafi(ipmask.top()), IP.tosafi(ipmask.top()), action)
		check = AnnouncePath.check

	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)

	change = Change(
		nlri,
		Attributes()
	)

	while True:
		command = tokeniser()

		if not command:
			break

		if command == 'label':
			nlri.labels = label(tokeniser)
			continue

		if command == 'rd' or command == 'route-distinguisher':
			nlri.rd = route_distinguisher(tokeniser)
			continue

		action = ParseStatic.action.get(command,'')

		if action == 'attribute-add':
			change.attributes.add(ParseStatic.known[command](tokeniser))
		elif action == 'nlri-set':
			change.nlri.assign(ParseStatic.assign[command],ParseStatic.known[command](tokeniser))
		elif action == 'nexthop-and-attribute':
			nexthop,attribute = ParseStatic.known[command](tokeniser)
			change.nlri.nexthop = nexthop
			change.attributes.add(attribute)
		else:
			raise ValueError('unknown command "%s"' % command)

	if not check(change,nlri.afi):
		raise ValueError('invalid route (missing next-hop, label or rd ?)')

	return list(ParseStatic.split(change))
コード例 #5
0
ファイル: __init__.py プロジェクト: plajjan/exabgp
def route (tokeniser):
	ipmask = prefix(tokeniser)

	if 'rd' in tokeniser.tokens or 'route-distinguisher' in tokeniser.tokens:
		klass = MPLS
		safi = SAFI(SAFI.mpls_vpn)
	elif 'label' in tokeniser.tokens:
		# XXX: should we create a LABEL class ?
		klass = MPLS
		safi = SAFI(SAFI.nlri_mpls)
	else:
		klass = INET
		safi = IP.tosafi(ipmask.string)

	change = Change(
		klass(
			IP.toafi(ipmask.string),
			safi,
			ipmask.pack(),
			ipmask.mask,
			'',
			OUT.UNSET
		),
		Attributes()
	)

	while True:
		command = tokeniser()

		if not command:
			break

		action = ParseStatic.action[command]

		if action == 'attribute-add':
			change.attributes.add(ParseStatic.known[command](tokeniser))
		elif action == 'nlri-set':
			change.nlri.assign(ParseStatic.assign[command],ParseStatic.known[command](tokeniser))
		elif action == 'nexthop-and-attribute':
			nexthop,attribute = ParseStatic.known[command](tokeniser)
			change.nlri.nexthop = nexthop
			change.attributes.add(attribute)
		else:
			raise ValueError('route: unknown command "%s"' % command)

	return list(ParseStatic.split(change))
コード例 #6
0
ファイル: __init__.py プロジェクト: Exa-Networks/exabgp
def route (tokeniser):
	ipmask = prefix(tokeniser)

	if 'rd' in tokeniser.tokens or 'route-distinguisher' in tokeniser.tokens:
		nlri = IPVPN(IP.toafi(ipmask.top()),SAFI.mpls_vpn,OUT.ANNOUNCE)
	elif 'label' in tokeniser.tokens:
		nlri = Label(IP.toafi(ipmask.top()),SAFI.nlri_mpls,OUT.ANNOUNCE)
	else:
		nlri = INET(IP.toafi(ipmask.top()),IP.tosafi(ipmask.top()),OUT.ANNOUNCE)

	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)

	change = Change(
		nlri,
		Attributes()
	)

	while True:
		command = tokeniser()

		if not command:
			break

		if command == 'label':
			nlri.labels = label(tokeniser)
			continue

		if command == 'rd' or command == 'route-distinguisher':
			nlri.rd = route_distinguisher(tokeniser)
			continue

		action = ParseStatic.action.get(command,'')

		if action == 'attribute-add':
			change.attributes.add(ParseStatic.known[command](tokeniser))
		elif action == 'nlri-set':
			change.nlri.assign(ParseStatic.assign[command],ParseStatic.known[command](tokeniser))
		elif action == 'nexthop-and-attribute':
			nexthop,attribute = ParseStatic.known[command](tokeniser)
			change.nlri.nexthop = nexthop
			change.attributes.add(attribute)
		else:
			raise ValueError('route: unknown command "%s"' % command)

	return list(ParseStatic.split(change))
コード例 #7
0
ファイル: __init__.py プロジェクト: bopopescu/exabgpsec-1
def route(tokeniser):
    ipmask = prefix(tokeniser)

    if 'rd' in tokeniser.tokens or 'route-distinguisher' in tokeniser.tokens:
        nlri = IPVPN(IP.toafi(ipmask.top()), SAFI.mpls_vpn, OUT.ANNOUNCE)
    elif 'label' in tokeniser.tokens:
        nlri = Label(IP.toafi(ipmask.top()), SAFI.nlri_mpls, OUT.ANNOUNCE)
    else:
        nlri = INET(IP.toafi(ipmask.top()), IP.tosafi(ipmask.top()),
                    OUT.ANNOUNCE)

    nlri.cidr = CIDR(ipmask.pack(), ipmask.mask)

    change = Change(nlri, Attributes())

    while True:
        command = tokeniser()

        if not command:
            break

        if command == 'label':
            nlri.labels = label(tokeniser)
            continue

        if command == 'rd' or command == 'route-distinguisher':
            nlri.rd = route_distinguisher(tokeniser)
            continue

        action = ParseStatic.action.get(command, '')

        if action == 'attribute-add':
            change.attributes.add(ParseStatic.known[command](tokeniser))
        elif action == 'nlri-set':
            change.nlri.assign(ParseStatic.assign[command],
                               ParseStatic.known[command](tokeniser))
        elif action == 'nexthop-and-attribute':
            nexthop, attribute = ParseStatic.known[command](tokeniser)
            change.nlri.nexthop = nexthop
            change.attributes.add(attribute)
        else:
            raise ValueError('route: unknown command "%s"' % command)

    return list(ParseStatic.split(change))
コード例 #8
0
ファイル: __init__.py プロジェクト: schevalier/exabgp
def attributes (tokeniser):
	ipmask = prefix(lambda: tokeniser.tokens[-1])

	if 'rd' in tokeniser.tokens or 'route-distinguisher' in tokeniser.tokens:
		nlri = MPLS(IP.toafi(ipmask.top()),SAFI.mpls_vpn,OUT.ANNOUNCE)
	elif 'label' in tokeniser.tokens:
		nlri = Label(IP.toafi(ipmask.top()),SAFI.nlri_mpls,OUT.ANNOUNCE)
	else:
		nlri = INET(IP.toafi(ipmask.top()),IP.tosafi(ipmask.top()),OUT.ANNOUNCE)

	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)

	change = Change(
		nlri,
		Attributes()
	)

	while True:
		command = tokeniser()

		if not command:
			return []

		if command == 'nlri':
			break

		action = ParseStatic.action[command]

		if action == 'attribute-add':
			change.attributes.add(ParseStatic.known[command](tokeniser))
		elif action == 'nlri-set':
			change.nlri.assign(ParseStatic.assign[command],ParseStatic.known[command](tokeniser))
		elif action == 'nexthop-and-attribute':
			nexthop,attribute = ParseStatic.known[command](tokeniser)
			change.nlri.nexthop = nexthop
			change.attributes.add(attribute)
		else:
			raise ValueError('route: unknown command "%s"' % command)

	attributes = change.attributes
	nexthop = change.nlri.nexthop

	changes = []
	while True:
		nlri = tokeniser.peek()
		if not nlri:
			break

		ipmask = prefix(tokeniser)
		new = Change(
			change.nlri.__class__(
				change.nlri.afi,
				change.nlri.safi,
				OUT.UNSET
			),
			attributes
		)
		new.nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
		new.nlri.nexthop = nexthop
		changes.append(new)

	return changes
コード例 #9
0
def attributes (tokeniser):
	ipmask = prefix(lambda: tokeniser.tokens[-1])

	if 'rd' in tokeniser.tokens or 'route-distinguisher' in tokeniser.tokens:
		nlri = IPVPN(IP.toafi(ipmask.top()),SAFI.mpls_vpn,OUT.ANNOUNCE)
	elif 'label' in tokeniser.tokens:
		nlri = Label(IP.toafi(ipmask.top()),SAFI.nlri_mpls,OUT.ANNOUNCE)
	else:
		nlri = INET(IP.toafi(ipmask.top()),IP.tosafi(ipmask.top()),OUT.ANNOUNCE)

	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)

	change = Change(
		nlri,
		Attributes()
	)

	while True:
		command = tokeniser()

		if not command:
			return []

		if command == 'nlri':
			break

		action = ParseStatic.action[command]

		if action == 'attribute-add':
			change.attributes.add(ParseStatic.known[command](tokeniser))
		elif action == 'nlri-set':
			change.nlri.assign(ParseStatic.assign[command],ParseStatic.known[command](tokeniser))
		elif action == 'nexthop-and-attribute':
			nexthop,attribute = ParseStatic.known[command](tokeniser)
			change.nlri.nexthop = nexthop
			change.attributes.add(attribute)
		else:
			raise ValueError('route: unknown command "%s"' % command)

	attributes = change.attributes
	nexthop = change.nlri.nexthop

	changes = []
	while True:
		nlri = tokeniser.peek()
		if not nlri:
			break

		ipmask = prefix(tokeniser)
		new = Change(
			change.nlri.__class__(
				change.nlri.afi,
				change.nlri.safi,
				OUT.UNSET
			),
			attributes
		)
		new.nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
		new.nlri.nexthop = nexthop
		changes.append(new)

	return changes
コード例 #10
0
def attributes (tokeniser):
	action = OUT.ANNOUNCE if tokeniser.announce else OUT.WITHDRAW
	ipmask = prefix(lambda: tokeniser.tokens[-1])
	tokeniser.afi = ipmask.afi

	if 'rd' in tokeniser.tokens or 'route-distinguisher' in tokeniser.tokens:
		nlri = IPVPN(IP.toafi(ipmask.top()), SAFI.mpls_vpn, action)
	elif 'label' in tokeniser.tokens:
		nlri = Label(IP.toafi(ipmask.top()), SAFI.nlri_mpls, action)
	else:
		nlri = INET(IP.toafi(ipmask.top()), IP.tosafi(ipmask.top()), action)

	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
	attr = Attributes()

	labels = None
	rd = None

	while True:
		command = tokeniser()

		if not command:
			return []

		if command == 'nlri':
			break

		if command == 'label':
			labels = label(tokeniser)
			continue

		if command == 'rd' or command == 'route-distinguisher':
			rd = route_distinguisher(tokeniser)
			continue

		action = ParseStatic.action[command]

		if action == 'attribute-add':
			attr.add(ParseStatic.known[command](tokeniser))
		elif action == 'nlri-set':
			nlri.assign(ParseStatic.assign[command],ParseStatic.known[command](tokeniser))
		elif action == 'nexthop-and-attribute':
			nexthop,attribute = ParseStatic.known[command](tokeniser)
			nlri.nexthop = nexthop
			attr.add(attribute)
		else:
			raise ValueError('unknown command "%s"' % command)

	changes = []
	while True:
		peeked_nlri = tokeniser.peek()
		if not peeked_nlri:
			break

		ipmask = prefix(tokeniser)
		new = Change(
			nlri.__class__(
				nlri.afi,
				nlri.safi,
				OUT.UNSET
			),
			attr
		)
		new.nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
		if labels:
			new.nlri.labels = labels
		if rd:
			new.nlri.rd = rd
		new.nlri.nexthop = nlri.nexthop
		changes.append(new)

	return changes
コード例 #11
0
ファイル: __init__.py プロジェクト: Exa-Networks/exabgp
def attributes (tokeniser):
	ipmask = prefix(lambda: tokeniser.tokens[-1])

	if 'rd' in tokeniser.tokens or 'route-distinguisher' in tokeniser.tokens:
		nlri = IPVPN(IP.toafi(ipmask.top()),SAFI.mpls_vpn,OUT.ANNOUNCE)
	elif 'label' in tokeniser.tokens:
		nlri = Label(IP.toafi(ipmask.top()),SAFI.nlri_mpls,OUT.ANNOUNCE)
	else:
		nlri = INET(IP.toafi(ipmask.top()),IP.tosafi(ipmask.top()),OUT.ANNOUNCE)

	nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
	attr = Attributes()

	labels = None
	rd = None

	while True:
		command = tokeniser()

		if not command:
			return []

		if command == 'nlri':
			break

		if command == 'label':
			labels = label(tokeniser)
			continue

		if command == 'rd' or command == 'route-distinguisher':
			rd = route_distinguisher(tokeniser)
			continue

		action = ParseStatic.action[command]

		if action == 'attribute-add':
			attr.add(ParseStatic.known[command](tokeniser))
		elif action == 'nlri-set':
			nlri.assign(ParseStatic.assign[command],ParseStatic.known[command](tokeniser))
		elif action == 'nexthop-and-attribute':
			nexthop,attribute = ParseStatic.known[command](tokeniser)
			nlri.nexthop = nexthop
			attr.add(attribute)
		else:
			raise ValueError('route: unknown command "%s"' % command)

	changes = []
	while True:
		peeked_nlri = tokeniser.peek()
		if not peeked_nlri:
			break

		ipmask = prefix(tokeniser)
		new = Change(
			nlri.__class__(
				nlri.afi,
				nlri.safi,
				OUT.UNSET
			),
			attr
		)
		new.nlri.cidr = CIDR(ipmask.pack(),ipmask.mask)
		if labels:
			new.nlri.labels = labels
		if rd:
			new.nlri.rd = rd
		new.nlri.nexthop = nlri.nexthop
		changes.append(new)

	return changes