예제 #1
0
파일: parser.py 프로젝트: eiffelcn/exabgp
def mpls (tokeniser):
	ipmask = prefix(tokeniser)
	mpls = MPLS(
		afi=IP.toafi(ipmask.top()),
		safi=IP.tosafi(ipmask.top()),
		action=OUT.UNSET
	)
	mpls.cidr = CIDR(ipmask.ton(),ipmask.mask)

	return Change(
		mpls,
		Attributes()
	)
예제 #2
0
def route (tokeniser):
	ipmask = prefix(tokeniser)

	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:
			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))
예제 #3
0
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