Search in sources :

Example 16 with CNextHop

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

the class NextHopParserSerializerTest method testSerializeIpv6LinkNextHopCase.

@Test
public void testSerializeIpv6LinkNextHopCase() throws BGPParsingException {
    this.hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).setLinkLocal(IPV6L).build()).build();
    this.buffer.clear();
    this.ipv6NextHopParserSerializer.serializeNextHop(this.hop, this.buffer);
    assertArrayEquals(IPV6LB, ByteArray.readAllBytes(this.buffer));
    final CNextHop parsedHop = this.ipv6NextHopParserSerializer.parseNextHop(Unpooled.wrappedBuffer(IPV6LB));
    assertTrue(parsedHop instanceof Ipv6NextHopCase);
    assertEquals(this.hop, parsedHop);
}
Also used : Ipv6NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop) Ipv6NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder) Ipv6NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCase) Test(org.junit.Test)

Example 17 with CNextHop

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.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.rev200120.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder) Ipv6NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop) ByteBuf(io.netty.buffer.ByteBuf) Ipv6NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder) Test(org.junit.Test)

Example 18 with CNextHop

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

the class SimpleNlriRegistry method registerNlriParser.

synchronized Registration 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);
    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.rev180329.BgpTableType) SimpleEntry(java.util.AbstractMap.SimpleEntry) AbstractRegistration(org.opendaylight.yangtools.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.rev200120.next.hop.CNextHop)

Example 19 with CNextHop

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.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.implementedInterface(), 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.writeByte(0);
    }
    byteAggregator.writeZero(RESERVED);
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.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.rev200120.next.hop.CNextHop) ByteBuf(io.netty.buffer.ByteBuf) NextHopParserSerializer(org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer)

Example 20 with CNextHop

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

the class ActionsRegistryImpl method applyExportAction.

@SuppressWarnings("unchecked")
Attributes applyExportAction(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryExportParameters routeEntryExportParameters, final Attributes attributes, final Actions actions) {
    requireNonNull(attributes);
    if (actions.getRouteDisposition() instanceof RejectRoute) {
        return null;
    }
    Attributes attributesUpdated = attributes;
    final Actions1 augmentation = actions.augmentation(Actions1.class);
    if (augmentation != null && augmentation.getBgpActions() != null) {
        final BgpActions bgpAction = augmentation.getBgpActions();
        final SetAsPathPrepend asPrependAction = bgpAction.getSetAsPathPrepend();
        final Uint32 localPrefPrependAction = bgpAction.getSetLocalPref();
        final BgpOriginAttrType localOriginAction = bgpAction.getSetRouteOrigin();
        final BgpSetMedType medAction = bgpAction.getSetMed();
        final BgpNextHopType nhAction = bgpAction.getSetNextHop();
        final SetCommunity setCommunityAction = bgpAction.getSetCommunity();
        final SetExtCommunity setExtCommunityAction = bgpAction.getSetExtCommunity();
        if (asPrependAction != null) {
            attributesUpdated = this.bgpActions.get(SetAsPathPrepend.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, asPrependAction);
        }
        if (attributesUpdated == null) {
            return null;
        }
        if (setCommunityAction != null) {
            attributesUpdated = this.bgpActions.get(SetCommunity.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, setCommunityAction);
        }
        if (attributesUpdated == null) {
            return null;
        }
        if (setExtCommunityAction != null) {
            attributesUpdated = this.bgpActions.get(SetExtCommunity.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, setExtCommunityAction);
        }
        boolean updated = false;
        if (localPrefPrependAction != null || localOriginAction != null || medAction != null || nhAction != null) {
            updated = true;
        }
        if (updated) {
            final AttributesBuilder attributesUpdatedBuilder = new AttributesBuilder(attributes);
            if (localPrefPrependAction != null) {
                attributesUpdatedBuilder.setLocalPref(new LocalPrefBuilder().setPref(localPrefPrependAction).build());
            }
            if (localOriginAction != null) {
                attributesUpdatedBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.forValue(localOriginAction.getIntValue())).build());
            }
            if (medAction != null) {
                attributesUpdatedBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(medAction.getUint32()).build());
            }
            if (nhAction != null) {
                final IpAddress address = nhAction.getIpAddress();
                CNextHop nhNew;
                if (address != null) {
                    if (address.getIpv4Address() != null) {
                        nhNew = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(IetfInetUtil.INSTANCE.ipv4AddressNoZoneFor(address.getIpv4Address())).build()).build();
                    } else {
                        nhNew = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IetfInetUtil.INSTANCE.ipv6AddressNoZoneFor(address.getIpv6Address())).build()).build();
                    }
                    attributesUpdatedBuilder.setCNextHop(nhNew);
                } else if (nhAction.getEnumeration() != null && BgpNextHopType.Enumeration.SELF == nhAction.getEnumeration()) {
                    nhNew = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(routeEntryInfo.getOriginatorId()).build()).build();
                    attributesUpdatedBuilder.setCNextHop(nhNew);
                }
            }
            attributesUpdated = attributesUpdatedBuilder.build();
        }
        for (final Augmentation<BgpActions> action : bgpAction.augmentations().values()) {
            final BgpActionAugPolicy handler = this.bgpAugActionsRegistry.get(action.implementedInterface());
            if (handler == null) {
                continue;
            } else if (attributesUpdated == null) {
                return null;
            }
            attributesUpdated = handler.applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, action);
        }
    }
    if (attributesUpdated == null) {
        return null;
    }
    // Export Actions Aug
    for (final Augmentation<Actions> entry : actions.augmentations().values()) {
        final ActionsAugPolicy handler = this.actionsRegistry.get(entry.implementedInterface());
        if (attributesUpdated == null) {
            return null;
        } else if (handler == null) {
            continue;
        }
        attributesUpdated = handler.applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, entry);
    }
    return attributesUpdated;
}
Also used : LocalPrefBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder) SetAsPathPrepend(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend) BgpSetMedType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.BgpSetMedType) OriginBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginBuilder) MultiExitDiscBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.MultiExitDiscBuilder) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) RouteEntryBaseAttributes(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes) ActionsAugPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.ActionsAugPolicy) RejectRoute(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.generic.actions.route.disposition.RejectRoute) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) SetCommunity(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetCommunity) Actions1(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.Actions1) BgpOriginAttrType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.BgpOriginAttrType) BgpNextHopType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.BgpNextHopType) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Ipv6NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder) Actions(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.statement.Actions) BgpActions(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.BgpActions) BgpActions(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.BgpActions) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop) Ipv4NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder) BgpActionAugPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) SetExtCommunity(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetExtCommunity) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) Ipv6NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder)

Aggregations

CNextHop (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.CNextHop)18 Test (org.junit.Test)11 ByteBuf (io.netty.buffer.ByteBuf)10 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)9 Ipv4NextHopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder)9 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)6 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder)5 OriginBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginBuilder)5 Ipv6NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder)5 Ipv6NextHopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder)5 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)4 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder)4 LocalPrefBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder)4 CNextHop (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop)4 Ipv6NextHopCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCase)4 NextHopParserSerializer (org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer)3 AsPath (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPath)3 Origin (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Origin)3 Nlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri)3