예제 #1
0
파일: ip.py 프로젝트: steiler/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 = 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
파일: 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]