Search in sources :

Example 71 with AttributesBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder 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 72 with AttributesBuilder

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

the class NextHopAttributeParserTest method testParseEmptyIpv4Attribute.

@Test
public void testParseEmptyIpv4Attribute() {
    final NullPointerException ex = assertThrows(NullPointerException.class, () -> registry.serializeAttribute(new AttributesBuilder().setCNextHop(new Ipv4NextHopCaseBuilder().build()).build(), Unpooled.buffer()));
    assertNull(ex.getMessage());
}
Also used : Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) Test(org.junit.Test)

Example 73 with AttributesBuilder

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

the class OriginatorIdAttributeParserTest method testParseEmptyAttribute.

@Test
public void testParseEmptyAttribute() {
    final ByteBuf actual = Unpooled.buffer();
    registry.serializeAttribute(new AttributesBuilder().setOriginatorId(new OriginatorIdBuilder().build()).build(), actual);
    assertEquals(Unpooled.buffer(), actual);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) OriginatorIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginatorIdBuilder) Test(org.junit.Test)

Example 74 with AttributesBuilder

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

the class AsPathAttributeParserTest method testParseEmptyAttribute.

@Test
public void testParseEmptyAttribute() {
    final ByteBuf actual = Unpooled.buffer();
    registry.serializeAttribute(new AttributesBuilder().setAsPath(new AsPathBuilder().build()).build(), actual);
    assertEquals(Unpooled.buffer().writeBytes(EMPTY_ATTRIBUTE_BYTES), actual);
}
Also used : AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder) 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 75 with AttributesBuilder

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

the class SimpleAttributeRegistry method parseAttributes.

@Override
public ParsedAttributes parseAttributes(final ByteBuf buffer, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
    final RevisedErrorHandling errorHandling = RevisedErrorHandling.from(constraint);
    final Map<Integer, RawAttribute> attributes = new TreeMap<>();
    BGPTreatAsWithdrawException withdrawCause = null;
    while (buffer.isReadable()) {
        try {
            addAttribute(buffer, errorHandling, attributes);
        } catch (BGPTreatAsWithdrawException e) {
            LOG.info("Failed to completely parse attributes list.");
            withdrawCause = e;
            break;
        }
    }
    /*
         * TreeMap guarantees that we will be invoking the parser in the order
         * of increasing attribute type.
         */
    // We may have multiple attribute errors, each specifying a withdraw. We need to finish parsing the message
    // all attributes before we can decide whether we can discard attributes, or whether we need to terminate
    // the session.
    final AttributesBuilder builder = new AttributesBuilder();
    for (final Entry<Integer, RawAttribute> entry : attributes.entrySet()) {
        LOG.debug("Parsing attribute type {}", entry.getKey());
        final RawAttribute a = entry.getValue();
        try {
            a.parser.parseAttribute(a.buffer, builder, errorHandling, constraint);
        } catch (BGPTreatAsWithdrawException e) {
            LOG.info("Attribute {} indicated treat-as-withdraw", entry.getKey(), e);
            if (withdrawCause == null) {
                withdrawCause = e;
            } else {
                withdrawCause.addSuppressed(e);
            }
        }
    }
    builder.setUnrecognizedAttributes(BindingMap.ordered(this.unrecognizedAttributes));
    return new ParsedAttributes(builder.build(), withdrawCause);
}
Also used : RevisedErrorHandling(org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling) BGPTreatAsWithdrawException(org.opendaylight.protocol.bgp.parser.BGPTreatAsWithdrawException) ParsedAttributes(org.opendaylight.protocol.bgp.parser.spi.ParsedAttributes) TreeMap(java.util.TreeMap) UnrecognizedAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)

Aggregations

AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)130 Test (org.junit.Test)117 ByteBuf (io.netty.buffer.ByteBuf)69 ArrayList (java.util.ArrayList)40 RouteAttributeContainer (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer)35 Statement (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement)35 AttributesReachBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReachBuilder)27 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder)26 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes)25 AttributesUnreachBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreachBuilder)24 MpReachNlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder)24 IPV4UNICAST (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST)23 AdvertizedRoutesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutesBuilder)23 OriginBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginBuilder)20 MpUnreachNlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlriBuilder)20 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder)19 WithdrawnRoutesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder)19 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)18 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)18 LocalPrefBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder)17