Search in sources :

Example 26 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class ClientAttributePrependHandlerTest method testPreprendClientAttribute.

@Test
public void testPreprendClientAttribute() {
    Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("client-attribute-append-test")).findFirst().get();
    final Attributes att = new AttributesBuilder().setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(IPV4).build()).build()).build();
    final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(att);
    doReturn(Collections.emptyList()).when(this.exportParameters).getClientRouteTargetContrainCache();
    RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
    assertEquals(att, result.getAttributes());
    final Attributes expected = new AttributesBuilder().setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("2.2.2.2")).build()).build()).build();
    final String rk = "testRoute";
    final Route rtRoute = new RouteTargetConstrainRouteBuilder().setRouteKey(rk).setPathId(new PathId(Uint32.ZERO)).setAttributes(expected).build();
    doReturn(Collections.singletonList(rtRoute)).when(this.exportParameters).getClientRouteTargetContrainCache();
    doReturn(rk).when(this.exportParameters).getRouteKey();
    result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
    assertEquals(expected, result.getAttributes());
}
Also used : PathId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId) 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) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) Ipv4AddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone) Statement(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement) 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) RouteTargetConstrainRouteBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRouteBuilder) RouteAttributeContainer(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) Route(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route) IPV4UNICAST(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST) Test(org.junit.Test) AbstractStatementRegistryTest(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.AbstractStatementRegistryTest)

Example 27 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class OriginAttributeParser method parseAttribute.

@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
    final int readable = buffer.readableBytes();
    if (readable != 1) {
        throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "ORIGIN attribute is expected to have size 1, but has %s", readable);
    }
    final byte rawOrigin = buffer.readByte();
    final BgpOrigin borigin = BgpOrigin.forValue(UnsignedBytes.toInt(rawOrigin));
    if (borigin == null) {
        throw errorHandling.reportError(BGPError.ORIGIN_ATTR_NOT_VALID, "Unknown ORIGIN type %s", rawOrigin);
    }
    switch(borigin) {
        case Egp:
            builder.setOrigin(EGP);
            return;
        case Igp:
            builder.setOrigin(IGP);
            return;
        case Incomplete:
            builder.setOrigin(INC);
            return;
        default:
    }
}
Also used : PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) BgpOrigin(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin)

Example 28 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class UnrecognizedAttributesSerializer method serializeAttribute.

@Override
public void serializeAttribute(final Attributes attributes, final ByteBuf byteAggregator) {
    final Map<UnrecognizedAttributesKey, UnrecognizedAttributes> unrecognizedAttrs = attributes.getUnrecognizedAttributes();
    if (unrecognizedAttrs == null) {
        return;
    }
    for (final UnrecognizedAttributes unrecognizedAttr : unrecognizedAttrs.values()) {
        LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType());
        int flags = AttributeUtil.OPTIONAL;
        if (unrecognizedAttr.getPartial()) {
            flags |= AttributeUtil.PARTIAL;
        }
        if (unrecognizedAttr.getTransitive()) {
            flags |= AttributeUtil.TRANSITIVE;
        }
        AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType().toJava(), Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);
    }
}
Also used : UnrecognizedAttributesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes)

Example 29 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class CommunitiesAttributeParser method parseAttribute.

@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
    final int readable = buffer.readableBytes();
    if (readable == 0 && errorHandling != RevisedErrorHandling.NONE) {
        throw new BGPTreatAsWithdrawException(BGPError.ATTR_LENGTH_ERROR, "Empty Community attribute");
    }
    if (readable % COMMUNITY_LENGTH != 0) {
        throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "Community attribute length must be a multiple of %s, have %s", COMMUNITY_LENGTH, readable);
    }
    final int count = readable / COMMUNITY_LENGTH;
    final List<Communities> set = new ArrayList<>(count);
    for (int i = 0; i < count; ++i) {
        set.add((Communities) parseCommunity(this.refCache, buffer.readSlice(COMMUNITY_LENGTH)));
    }
    builder.setCommunities(set);
}
Also used : BGPTreatAsWithdrawException(org.opendaylight.protocol.bgp.parser.BGPTreatAsWithdrawException) Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities) ArrayList(java.util.ArrayList) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Example 30 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class ExtendedCommunitiesAttributeParser method parseAttribute.

@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
    final int readable = buffer.readableBytes();
    if (errorHandling != RevisedErrorHandling.NONE) {
        if (readable == 0) {
            throw new BGPTreatAsWithdrawException(BGPError.ATTR_LENGTH_ERROR, "Empty Extended Community attribute");
        }
    }
    if (readable % 8 != 0) {
        throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "Extended Community attribute length must be a multiple of 8, have %s", readable);
    }
    final List<ExtendedCommunities> set = new ArrayList<>(readable / 8);
    while (buffer.isReadable()) {
        final ExtendedCommunities exComm;
        try {
            // FIXME: BGPCEP-359: revise API contract here
            exComm = this.ecReg.parseExtendedCommunity(buffer);
        } catch (BGPParsingException e) {
            throw errorHandling.reportError(BGPError.MALFORMED_ATTR_LIST, e, "Failed to parse extended community");
        }
        if (exComm != null) {
            set.add(exComm);
        }
    }
    builder.setExtendedCommunities(set);
}
Also used : BGPTreatAsWithdrawException(org.opendaylight.protocol.bgp.parser.BGPTreatAsWithdrawException) ExtendedCommunities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunities) ArrayList(java.util.ArrayList) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)42 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)25 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)21 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)17 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)15 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder)10 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes)10 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)10 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)8 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)8 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder)8 Attributes2 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2)8 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)7 OriginBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginBuilder)7 Attributes1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1)7 Ipv4NextHopCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCase)7 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)7 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)7 Attribute (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute)7