Search in sources :

Example 11 with CNextHop

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.

the class AbstractRIBSupport method buildReach.

/**
 * Build MpReachNlri object from DOM representation.
 *
 * @param routes Collection of MapEntryNode DOM representation of routes
 * @param hop    CNextHop as it was parsed from Attributes, to be included in MpReach object
 * @return MpReachNlri
 */
private MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
    final MpReachNlriBuilder mb = new MpReachNlriBuilder();
    mb.setAfi(this.getAfi());
    mb.setSafi(this.getSafi());
    mb.setCNextHop(hop);
    mb.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(buildDestination(routes)).build());
    return mb.build();
}
Also used : MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder)

Example 12 with CNextHop

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.

the class NextHopUtilTest method testSerializeNextHop.

@Test
public void testSerializeNextHop() {
    CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(IPV4).build()).build();
    final ByteBuf buffer = Unpooled.buffer();
    NextHopUtil.serializeNextHop(hop, buffer);
    assertArrayEquals(IPV4B, ByteArray.readAllBytes(buffer));
    hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).build()).build();
    buffer.clear();
    NextHopUtil.serializeNextHop(hop, buffer);
    assertArrayEquals(IPV6B, ByteArray.readAllBytes(buffer));
    hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).setLinkLocal(IPV6L).build()).build();
    buffer.clear();
    NextHopUtil.serializeNextHop(hop, buffer);
    assertArrayEquals(IPV6LB, ByteArray.readAllBytes(buffer));
    buffer.clear();
    hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setLinkLocal(IPV6L).build()).build();
    buffer.clear();
    try {
        NextHopUtil.serializeNextHop(hop, buffer);
        fail("Exception should happen");
    } catch (final IllegalArgumentException e) {
        assertEquals("Ipv6 Next Hop is missing Global address.", e.getMessage());
    }
}
Also used : Ipv4NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder) Ipv6NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop) ByteBuf(io.netty.buffer.ByteBuf) Ipv6NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder) Test(org.junit.Test)

Example 13 with CNextHop

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.

the class BgpTestActivator method startImpl.

@Override
protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
    initMock();
    final List<AutoCloseable> regs = Lists.newArrayList();
    regs.add(context.registerAttributeParser(TYPE, this.attrParser));
    regs.add(context.registerAttributeSerializer(DataObject.class, this.attrSerializer));
    regs.add(context.registerParameterParser(TYPE, this.paramParser));
    regs.add(context.registerParameterSerializer(BgpParameters.class, this.paramSerializer));
    regs.add(context.registerCapabilityParser(TYPE, this.capaParser));
    regs.add(context.registerCapabilitySerializer(CParameters.class, this.capaSerializer));
    regs.add(context.registerBgpPrefixSidTlvParser(TYPE, this.sidTlvParser));
    regs.add(context.registerBgpPrefixSidTlvSerializer(BgpPrefixSidTlv.class, this.sidTlvSerializer));
    regs.add(context.registerMessageParser(TYPE, this.msgParser));
    regs.add(context.registerMessageSerializer(Notification.class, this.msgSerializer));
    regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
    regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
    regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
    this.nextHopParserSerializer = new NextHopParserSerializer() {

        @Override
        public CNextHop parseNextHop(final ByteBuf buffer) throws BGPParsingException {
            return new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.0.0.1")).build()).build();
        }

        @Override
        public void serializeNextHop(final CNextHop cNextHop, final ByteBuf byteAggregator) {
            final byte[] mpReachBytes = { 0x7f, 0x00, 0x00, 0x01 };
            byteAggregator.writeBytes(mpReachBytes);
        }
    };
    regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv4NextHopCase.class));
    regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv6NextHopCase.class));
    regs.add(context.registerNlriSerializer(DataObject.class, this.nlriSerializer));
    regs.add(context.registerExtendedCommunityParser(0, 0, this.exParser));
    regs.add(context.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, this.exSerializer));
    return regs;
}
Also used : Ipv6AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily) RouteTargetIpv4Case(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetIpv4Case) Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) ByteBuf(io.netty.buffer.ByteBuf) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop) Ipv4NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase) Notification(org.opendaylight.yangtools.yang.binding.Notification) Ipv6NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase) Ipv4NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) BgpPrefixSidTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily) NextHopParserSerializer(org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 14 with CNextHop

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.

the class SimpleNlriRegistry method serializeMpReach.

@Override
public void serializeMpReach(final MpReachNlri mpReachNlri, final ByteBuf byteAggregator) {
    final Class<? extends AddressFamily> afi = mpReachNlri.getAfi();
    final Class<? extends SubsequentAddressFamily> safi = mpReachNlri.getSafi();
    byteAggregator.writeShort(this.afiReg.numberForClass(afi));
    byteAggregator.writeByte(this.safiReg.numberForClass(safi));
    final CNextHop cNextHop = mpReachNlri.getCNextHop();
    if (cNextHop != null) {
        final Entry<Class<? extends CNextHop>, BgpTableType> key = new SimpleEntry(cNextHop.getImplementedInterface(), new BgpTableTypeImpl(afi, safi));
        final NextHopParserSerializer nextHopSerializer = this.nextHopSerializers.get(key);
        final ByteBuf nextHopBuffer = Unpooled.buffer();
        nextHopSerializer.serializeNextHop(cNextHop, nextHopBuffer);
        byteAggregator.writeByte(nextHopBuffer.writerIndex());
        byteAggregator.writeBytes(nextHopBuffer);
    } else {
        byteAggregator.writeZero(NEXT_HOP_LENGHT);
    }
    byteAggregator.writeZero(RESERVED);
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) SimpleEntry(java.util.AbstractMap.SimpleEntry) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop) ByteBuf(io.netty.buffer.ByteBuf) NextHopParserSerializer(org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer)

Example 15 with CNextHop

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop in project bgpcep by opendaylight.

the class SimpleNlriRegistry method registerNlriParser.

synchronized AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final NlriParser parser, final NextHopParserSerializer nextHopSerializer, final Class<? extends CNextHop> cNextHopClass, final Class<? extends CNextHop>... cNextHopClassList) {
    final BgpTableType key = createKey(afi, safi);
    final NlriParser prev = this.handlers.get(key);
    Preconditions.checkState(prev == null, "AFI/SAFI is already bound to parser " + prev);
    this.handlers.put(key, parser);
    this.nextHopParsers.put(key, nextHopSerializer);
    if (cNextHopClass != null) {
        final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cNextHopClass, key);
        this.nextHopSerializers.put(nhKey, nextHopSerializer);
        for (final Class<? extends CNextHop> cNextHop : cNextHopClassList) {
            final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cNextHop, key);
            this.nextHopSerializers.put(nhKeys, nextHopSerializer);
        }
    }
    final Object lock = this;
    return new AbstractRegistration() {

        @Override
        protected void removeRegistration() {
            synchronized (lock) {
                SimpleNlriRegistry.this.handlers.remove(key);
                SimpleNlriRegistry.this.nextHopParsers.remove(key);
                if (cNextHopClass != null) {
                    final Entry<Class<? extends CNextHop>, BgpTableType> nhKey = new SimpleEntry<>(cNextHopClass, key);
                    SimpleNlriRegistry.this.nextHopSerializers.remove(nhKey);
                    for (final Class<? extends CNextHop> cNextHop : cNextHopClassList) {
                        final Entry<Class<? extends CNextHop>, BgpTableType> nhKeys = new SimpleEntry<>(cNextHop, key);
                        SimpleNlriRegistry.this.nextHopSerializers.remove(nhKeys);
                    }
                }
            }
        }
    };
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) SimpleEntry(java.util.AbstractMap.SimpleEntry) AbstractRegistration(org.opendaylight.protocol.concepts.AbstractRegistration) NlriParser(org.opendaylight.protocol.bgp.parser.spi.NlriParser) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop)

Aggregations

CNextHop (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop)16 Test (org.junit.Test)9 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)8 Ipv4NextHopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder)8 ByteBuf (io.netty.buffer.ByteBuf)6 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)6 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder)5 OriginBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder)5 Ipv6NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder)5 Ipv6NextHopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder)5 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder)4 LocalPrefBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPrefBuilder)4 Ipv4NextHopCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase)4 Ipv6NextHopCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase)4 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)3 AsPath (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPath)3 Origin (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin)3 Nlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.Nlri)3 NlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.NlriBuilder)3