Search in sources :

Example 6 with SubsequentAddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.

the class BGPParserTest method testEORIpv6.

/*
     * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
     *
     * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
     * 00 1d <- length (29) - including header
     * 02 <- message type
     * 00 00 <- withdrawn routes length
     * 00 06 <- total path attribute length
     * 80 <- attribute flags
     * 0f <- attribute type (15 - MP_UNREACH_NLRI)
     * 03 <- attribute length
     * 00 02 <- value (AFI 2: IPv6)
     * 01 <- value (SAFI 1)
     */
@Test
public void testEORIpv6() throws Exception {
    final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(6), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
    final Class<? extends AddressFamily> afi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getAfi();
    final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().augmentation(AttributesUnreach.class).getMpUnreachNlri().getSafi();
    assertEquals(Ipv6AddressFamily.class, afi);
    assertEquals(UnicastSubsequentAddressFamily.class, safi);
    final ByteBuf buffer = Unpooled.buffer();
    BGPParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(INPUT_BYTES.get(6), ByteArray.readAllBytes(buffer));
}
Also used : Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update) ByteBuf(io.netty.buffer.ByteBuf) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) Test(org.junit.Test)

Example 7 with SubsequentAddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.

the class SimpleRIBExtensionProviderContext method registerRIBSupport.

@Override
public <T extends RIBSupport<?, ?>> RIBSupportRegistration<T> registerRIBSupport(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final T support) {
    final TablesKey key = new TablesKey(afi, safi);
    final RIBSupport<?, ?> prev = this.supports.putIfAbsent(key, support);
    checkArgument(prev == null, "AFI %s SAFI %s is already registered with %s", afi, safi, prev);
    this.domSupports.put(RibSupportUtils.toYangTablesKey(afi, safi), support);
    return new AbstractRIBSupportRegistration<>(support) {

        @Override
        protected void removeRegistration() {
            // FIXME: clean up registrations, too
            SimpleRIBExtensionProviderContext.this.supports.remove(key);
        }
    };
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)

Example 8 with SubsequentAddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.

the class GracefulCapabilityHandler method serializeTables.

private void serializeTables(final List<Tables> tables, final ByteBuf bytes) {
    if (tables == null) {
        return;
    }
    for (final Tables t : tables) {
        final Class<? extends AddressFamily> afi = t.getAfi();
        final Integer afival = this.afiReg.numberForClass(afi);
        Preconditions.checkArgument(afival != null, "Unhandled address family " + afi);
        bytes.writeShort(afival);
        final Class<? extends SubsequentAddressFamily> safi = t.getSafi();
        final Integer safival = this.safiReg.numberForClass(safi);
        Preconditions.checkArgument(safival != null, "Unhandled subsequent address family " + safi);
        bytes.writeByte(safival);
        if (t.getAfiFlags() != null && t.getAfiFlags().isForwardingState()) {
            bytes.writeByte(AFI_FLAG_FORWARDING_STATE);
        } else {
            bytes.writeZero(1);
        }
    }
}
Also used : Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.Tables)

Example 9 with SubsequentAddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.

the class VpnDestinationUtil method parseNlri.

static List<VpnDestination> parseNlri(final ByteBuf nlri, final PeerSpecificParserConstraint constraints, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
    if (!nlri.isReadable()) {
        return null;
    }
    final List<VpnDestination> dests = new ArrayList<>();
    while (nlri.isReadable()) {
        final VpnDestinationBuilder builder = new VpnDestinationBuilder();
        if (MultiPathSupportUtil.isTableTypeSupported(constraints, new BgpTableTypeImpl(afi, safi))) {
            builder.setPathId(PathIdUtil.readPathId(nlri));
        }
        final short length = nlri.readUnsignedByte();
        final List<LabelStack> labels = LUNlriParser.parseLabel(nlri);
        builder.setLabelStack(labels);
        final int labelNum = labels != null ? labels.size() : 1;
        final int prefixLen = length - (LUNlriParser.LABEL_LENGTH * Byte.SIZE * labelNum) - (RouteDistinguisherUtil.RD_LENGTH * Byte.SIZE);
        builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(nlri));
        Preconditions.checkState(prefixLen > 0, "A valid VPN IP prefix is required.");
        builder.setPrefix(LUNlriParser.parseIpPrefix(nlri, prefixLen, afi));
        dests.add(builder.build());
    }
    return dests;
}
Also used : VpnDestination(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.destination.type.VpnDestination) LabelStack(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.LabelStack) ArrayList(java.util.ArrayList) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl) VpnDestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.destination.type.VpnDestinationBuilder) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Example 10 with SubsequentAddressFamily

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily in project bgpcep by opendaylight.

the class EvpnNlriParser method parseNlri.

@Nullable
private static List<EvpnDestination> parseNlri(final ByteBuf nlri, final PeerSpecificParserConstraint constraints, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
    if (!nlri.isReadable()) {
        return null;
    }
    final List<EvpnDestination> dests = new ArrayList<>();
    while (nlri.isReadable()) {
        final EvpnDestinationBuilder builder = new EvpnDestinationBuilder();
        if (MultiPathSupportUtil.isTableTypeSupported(constraints, new BgpTableTypeImpl(afi, safi))) {
            builder.setPathId(PathIdUtil.readPathId(nlri));
        }
        final NlriType type = NlriType.forValue(nlri.readUnsignedByte());
        final int length = nlri.readUnsignedByte();
        final ByteBuf nlriBuf = nlri.readSlice(length);
        builder.setRouteDistinguisher(parseRouteDistinguisher(nlriBuf));
        builder.setEvpnChoice(SimpleEvpnNlriRegistry.getInstance().parseEvpn(type, nlriBuf));
        dests.add(builder.build());
    }
    return dests;
}
Also used : ArrayList(java.util.ArrayList) EvpnDestination(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.destination.EvpnDestination) EvpnDestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.destination.EvpnDestinationBuilder) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl) NlriType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.NlriType) ByteBuf(io.netty.buffer.ByteBuf) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)8 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)6 ArrayList (java.util.ArrayList)5 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)5 BgpTableType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType)4 Test (org.junit.Test)3 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)3 CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)3 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder)3 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)3 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 NextHopParserSerializer (org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer)2 NlriParser (org.opendaylight.protocol.bgp.parser.spi.NlriParser)2 Uint24 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.types.rev171204.Uint24)2 SendReceive (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.SendReceive)2 AddressFamilies (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies)2 Tables (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables)2 Tables (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.Tables)2 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.ll.graceful.restart.capability.TablesKey)2 CNextHop (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop)2