Search in sources :

Example 6 with Communities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities in project bgpcep by opendaylight.

the class CommunitiesAttributeParserTest method testCommunitiesAttributeParser.

@Test
public void testCommunitiesAttributeParser() throws Exception {
    final List<Communities> comms = new ArrayList<>();
    comms.add((Communities) CommunityUtil.NO_EXPORT);
    comms.add((Communities) CommunityUtil.NO_ADVERTISE);
    comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
    comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
    comms.add((Communities) CommunityUtil.LLGR_STALE);
    comms.add((Communities) CommunityUtil.NO_LLGR);
    final AttributesBuilder paBuilder = new AttributesBuilder();
    paBuilder.setCommunities(comms);
    final ByteBuf actual = Unpooled.buffer();
    registry.serializeAttribute(paBuilder.build(), actual);
    assertArrayEquals(COMMUNITIES_BYTES, ByteArray.getAllBytes(actual));
    final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
    assertEquals(comms, attributeOut.getCommunities());
}
Also used : Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities) ArrayList(java.util.ArrayList) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) ByteBuf(io.netty.buffer.ByteBuf) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) Test(org.junit.Test)

Example 7 with Communities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities in project bgpcep by opendaylight.

the class EffectiveRibInWriter method writeRoute.

private void writeRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport<?, ?> ribSupport, final YangInstanceIdentifier routePath, final Optional<NormalizedNode> routeBefore, final NormalizedNode routeAfter, final boolean longLivedStale) {
    final TablesKey tablesKey = ribSupport.getTablesKey();
    CountersUtil.increment(this.prefixesReceived.get(tablesKey), tablesKey);
    // Lookup per-table attributes from RIBSupport
    final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(routeAfter, ribSupport.routeAttributesIdentifier()).orElse(null);
    final Attributes routeAttrs = ribSupport.attributeFromContainerNode(advertisedAttrs);
    final Optional<Attributes> optEffAtt;
    // considered as received with LLGR_STALE from peer which is not true.
    if (longLivedStale) {
        // LLGR procedures are in effect. If the route is tagged with NO_LLGR, it needs to be removed.
        final List<Communities> effCommunities = routeAttrs.getCommunities();
        if (effCommunities != null && effCommunities.contains(CommunityUtil.NO_LLGR)) {
            deleteRoute(tx, ribSupport, routePath, routeBefore.orElse(null));
            return;
        }
        optEffAtt = Optional.of(wrapLongLivedStale(routeAttrs));
    } else {
        optEffAtt = ribPolicies.applyImportPolicies(peerImportParameters, routeAttrs, verifyNotNull(tableTypeRegistry.getAfiSafiType(ribSupport.getTablesKey())));
    }
    if (!optEffAtt.isPresent()) {
        deleteRoute(tx, ribSupport, routePath, routeBefore.orElse(null));
        return;
    }
    handleRouteTarget(ModificationType.WRITE, ribSupport, routePath, routeAfter);
    tx.put(LogicalDatastoreType.OPERATIONAL, routePath, routeAfter);
    CountersUtil.increment(this.prefixesInstalled.get(tablesKey), tablesKey);
    final Attributes attToStore = optEffAtt.get();
    if (!attToStore.equals(routeAttrs)) {
        final YangInstanceIdentifier attPath = routePath.node(ribSupport.routeAttributesIdentifier());
        final ContainerNode finalAttribute = ribSupport.attributeToContainerNode(attPath, attToStore);
        tx.put(LogicalDatastoreType.OPERATIONAL, attPath, finalAttribute);
    }
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 8 with Communities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities in project bgpcep by opendaylight.

the class TestUtil method createCommunities.

private static List<Communities> createCommunities() {
    final List<Communities> communities = new ArrayList<>();
    final CommunitiesBuilder commBuilder = new CommunitiesBuilder().setAsNumber(new AsNumber(Uint32.valueOf(65535))).setSemantics(Uint16.valueOf(65381));
    final CommunitiesBuilder commBuilder2 = new CommunitiesBuilder().setAsNumber(new AsNumber(Uint32.valueOf(65535))).setSemantics(Uint16.valueOf(65382));
    communities.add(commBuilder.build());
    communities.add(commBuilder2.build());
    return communities;
}
Also used : CommunitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.CommunitiesBuilder) Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities) ArrayList(java.util.ArrayList) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)

Example 9 with Communities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities in project bgpcep by opendaylight.

the class AbstractCommunityHandler method loadCommunitySet.

private List<Communities> loadCommunitySet(final String key) throws ExecutionException, InterruptedException {
    final ReadOnlyTransaction tr = this.databroker.newReadOnlyTransaction();
    final Optional<CommunitySet> result = tr.read(LogicalDatastoreType.CONFIGURATION, COMMUNITY_SETS_IID.child(CommunitySet.class, new CommunitySetKey(key))).get();
    if (!result.isPresent()) {
        return Collections.emptyList();
    }
    return result.get().getCommunities().stream().map(ge -> new CommunitiesBuilder().setAsNumber(ge.getAsNumber()).setSemantics(ge.getSemantics()).build()).collect(Collectors.toList());
}
Also used : Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Communities) LoadingCache(com.google.common.cache.LoadingCache) CommunitySet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.community.sets.CommunitySet) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) CommunitySets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.CommunitySets) RoutingPolicy(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.RoutingPolicy) Collectors(java.util.stream.Collectors) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) CacheLoader(com.google.common.cache.CacheLoader) ExecutionException(java.util.concurrent.ExecutionException) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) CommunitySetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.community.sets.CommunitySetKey) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Optional(com.google.common.base.Optional) Objects.requireNonNull(java.util.Objects.requireNonNull) DefinedSets1(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.DefinedSets1) CommunitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.CommunitiesBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) Collections(java.util.Collections) DefinedSets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.DefinedSets) BgpDefinedSets(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.BgpDefinedSets) CommunitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.CommunitiesBuilder) CommunitySet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.community.sets.CommunitySet) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) CommunitySetKey(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.community.sets.CommunitySetKey)

Example 10 with Communities

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities in project bgpcep by opendaylight.

the class BGPParserTest method testUpdateMessageNlriAddPath.

/*
     * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI with multiple paths.
     *
     * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
     * 00 60 <- length (96) - including header
     * 02 <- message type
     * 00 00 <- withdrawn routes length
     * 00 31 <- total path attribute length (49)
     * 40 <- attribute flags
     * 01 <- attribute type code (origin)
     * 01 <- attribute length
     * 00 <- Origin value (IGP)
     * 40 <- attribute flags
     * 02 <- attribute type code (as path)
     * 06 <- attribute length
     * 02 <- AS_SEQUENCE
     * 01 <- path segment count
     * 00 00 fd ea <- path segment value (65002)
     * 40 <- attribute flags
     * 03 <- attribute type code (Next Hop)
     * 04 <- attribute length
     * 0a 00 00 02 <- value (10.0.0.2)
     * 80 <- attribute flags
     * 04 <- attribute type code (multi exit disc)
     * 04 <- attribute length
     * 00 00 00 00 <- value
     * 40 <- attribute flags
     * 06 <- attribute type code (atomic aggregate)
     * 00 <- attribute length
     * C0 <- attribute flags
     * 08 <- attribute type code (community)
     * 10 <- attribute length
     * FF FF FF 01 <- value (NO_EXPORT)
     * FF FF FF 02 <- value (NO_ADVERTISE)
     * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
     * FF FF FF 10 <- unknown Community
     *
     * //NLRI
     * 00 00 00 01 <- path-id (1)
     * 18 ac 11 02 <- IPv4 Prefix (172.17.1.0 / 24)
     * 00 00 00 01 <- path-id (2)
     * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
     * 00 00 00 01 <- path-id (1)
     * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
     */
@Test
public void testUpdateMessageNlriAddPath() throws Exception {
    final byte[] body = ByteArray.cutBytes(updatesWithMultiplePath.get(0), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(updatesWithMultiplePath.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, mpConstraint);
    // check fields
    assertNull(message.getWithdrawnRoutes());
    // attributes
    final List<AsNumber> asNumbers = new ArrayList<>();
    asNumbers.add(new AsNumber(Uint32.valueOf(65002)));
    final List<Segments> asPath = new ArrayList<>();
    asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
    final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("10.0.0.2")).build()).build();
    final List<Communities> comms = new ArrayList<>();
    comms.add((Communities) CommunityUtil.NO_EXPORT);
    comms.add((Communities) CommunityUtil.NO_ADVERTISE);
    comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
    comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
    final UpdateBuilder builder = new UpdateBuilder();
    // check nlri
    final List<Nlri> nlris = new ArrayList<>();
    nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(Uint32.ONE)).build());
    nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(Uint32.TWO)).build());
    nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.0.0/24")).setPathId(new PathId(Uint32.ONE)).build());
    assertEquals(nlris, message.getNlri());
    builder.setNlri(nlris);
    // check path attributes
    final Attributes attrs = message.getAttributes();
    final AttributesBuilder paBuilder = new AttributesBuilder();
    paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
    assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
    paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
    assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
    paBuilder.setCNextHop(nextHop);
    assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
    paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build());
    assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
    paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
    assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
    paBuilder.setCommunities(comms);
    assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
    paBuilder.setUnrecognizedAttributes(Map.of());
    builder.setAttributes(paBuilder.build());
    assertEquals(builder.build(), message);
    final ByteBuf buffer = Unpooled.buffer();
    BGPParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(updatesWithMultiplePath.get(0), ByteArray.readAllBytes(buffer));
}
Also used : Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities) ExtendedCommunities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunities) 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) ArrayList(java.util.ArrayList) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.Segments) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update) ByteBuf(io.netty.buffer.ByteBuf) PathId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) SegmentsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.SegmentsBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv4NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCase) AtomicAggregateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AtomicAggregateBuilder) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) Nlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri) 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) NlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.NlriBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) Test(org.junit.Test)

Aggregations

Communities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities)10 ArrayList (java.util.ArrayList)7 ByteBuf (io.netty.buffer.ByteBuf)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)6 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes)5 Test (org.junit.Test)4 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)3 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)2 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)2 Communities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Communities)2 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)2 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder)2 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder)2 AtomicAggregateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AtomicAggregateBuilder)2 CommunitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.CommunitiesBuilder)2 ExtendedCommunities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunities)2 MultiExitDiscBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.MultiExitDiscBuilder)2