Remove AttributeParser.parseAttribute(ByteBuf, int) 21/78021/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Nov 2018 09:31:27 +0000 (10:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Nov 2018 11:01:47 +0000 (12:01 +0100)
We require peer information for parsing, promote the peer-aware
parsing method as the primary contract.

JIRA: BGPCEP-359
Change-Id: I7fe039034563ce416ac6f6d08fbf6de867c35344
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
27 files changed:
bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkstateAttributeParser.java
bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java
bgp/extensions/mvpn/src/main/java/org/opendaylight/protocol/bgp/mvpn/impl/attributes/PEDistinguisherLabelsAttributeHandler.java
bgp/extensions/mvpn/src/main/java/org/opendaylight/protocol/bgp/mvpn/impl/attributes/PMSITunnelAttributeHandler.java
bgp/extensions/mvpn/src/test/java/org/opendaylight/protocol/bgp/mvpn/impl/attributes/PMSITunnelAttributeHandlerTest.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AS4AggregatorAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AS4PathAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AggregatorAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AigpAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AtomicAggregateAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/BgpPrefixSidAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ClusterIdAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ExtendedCommunitiesAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/LocalPreferenceAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MPReachAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MPUnreachAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MultiExitDiscriminatorAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/NextHopAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ReachAttributeParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/BgpPrefixSidAttributeParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ClusterIdAttributeParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ExtendedCommunitiesAttributeParserTest.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/AttributeParser.java

index 117204d189e4cf1a47872e6eca4ca59de3af97cd..56b2192c424cd09f284b9bc7b34de0fb2d7bbd19 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Attributes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Attributes1Builder;
@@ -79,7 +80,9 @@ public final class LinkstateAttributeParser implements AttributeParser, Attribut
     }
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) throws BGPParsingException {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) throws BGPParsingException {
+        // FIXME: BGPCEP-359: what is the handling here?
         final CLinkstateDestination lsDestination = getNlriType(builder);
         if (lsDestination == null) {
             LOG.warn("No Linkstate NLRI found, not parsing Linkstate attribute");
index 8702777d75fae3a44929bfbd950259cbc14a007d..0abf28e5c69d4bbdd4915f296efef5b323e69ea9 100644 (file)
@@ -77,8 +77,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 
 public class LinkstateAttributeParserTest {
 
-    private static final byte[] TE_LSP_ATTR = {0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, lenght, value
-        0x00, (byte) 0x20, (byte) 0x0c, 0x02,  // Lenght, Class, Ctype
+    private static final byte[] TE_LSP_ATTR = {0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, length, value
+        0x00, (byte) 0x20, (byte) 0x0c, 0x02,  // Length, Class, Ctype
         0x00, 0x00, 0x00, 0x07,
         0x01, 0x00, 0x00, 0x06,
         (byte) 0x7f, 0x00, 0x00, 0x05,
@@ -87,7 +87,7 @@ public class LinkstateAttributeParserTest {
         0x00, 0x00, 0x00, 0x03, //Peak Data Rate
         0x00, 0x00, 0x00, 0x04, //Minimum Policed Unit
         0x00, 0x00, 0x00, 0x05, //Maximum Packet Size
-        0x00, (byte) 0x08, (byte) 0xc7, 0x01,  // Lenght, Class, Ctype
+        0x00, (byte) 0x08, (byte) 0xc7, 0x01,  // Length, Class, Ctype
         0x00, 0x01, 0x00, 0x02,
         0x01, 0x02, 0x03, 0x04,};
 
@@ -165,38 +165,42 @@ public class LinkstateAttributeParserTest {
     public void testGetNlriType() throws BGPParsingException {
         final ByteBuf b = Unpooled.buffer();
         AttributesBuilder builder = new AttributesBuilder();
-        this.parser.parseAttribute(b, builder);
+        this.parser.parseAttribute(b, builder, null);
         assertEquals(0, b.readableBytes());
         builder = new AttributesBuilder();
 
         final Attributes1Builder builder1 = new Attributes1Builder();
         builder.addAugmentation(Attributes1.class, builder1.build());
-        this.parser.parseAttribute(b, builder);
+        this.parser.parseAttribute(b, builder, null);
         assertEquals(0, b.readableBytes());
         builder = new AttributesBuilder();
 
         builder.addAugmentation(Attributes1.class, builder1.setMpReachNlri(
-            new MpReachNlriBuilder().setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv4CaseBuilder().build()).build()).build()).build());
-        this.parser.parseAttribute(b, builder);
+            new MpReachNlriBuilder().setAdvertizedRoutes(new AdvertizedRoutesBuilder()
+                .setDestinationType(new DestinationIpv4CaseBuilder().build()).build()).build()).build());
+        this.parser.parseAttribute(b, builder, null);
         assertEquals(0, b.readableBytes());
         builder = new AttributesBuilder();
 
         final Attributes2Builder builder2 = new Attributes2Builder();
         builder.addAugmentation(Attributes2.class, builder2.build());
-        this.parser.parseAttribute(b, builder);
+        this.parser.parseAttribute(b, builder, null);
         assertEquals(0, b.readableBytes());
         builder = new AttributesBuilder();
 
         builder.addAugmentation(Attributes2.class, builder2.setMpUnreachNlri(
-            new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder().build()).build()).build()).build());
-        this.parser.parseAttribute(b, builder);
+            new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329
+                .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder()
+                .build()).build()).build()).build());
+        this.parser.parseAttribute(b, builder, null);
         assertEquals(0, b.readableBytes());
     }
 
     @Test
     public void testPositiveLinks() throws BGPParsingException {
         final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
-        this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder);
+        this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder, null);
         final Attributes1 attrs = builder.augmentation(Attributes1.class);
         final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
         assertNotNull(ls);
@@ -204,8 +208,10 @@ public class LinkstateAttributeParserTest {
         assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
         assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
         assertEquals(Long.valueOf(0L), ls.getAdminGroup().getValue());
-        assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
-        assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
+        assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 },
+            ls.getMaxLinkBandwidth().getValue());
+        assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
+            ls.getMaxReservableBandwidth().getValue());
         assertNotNull(ls.getUnreservedBandwidth());
         assertEquals(8, ls.getUnreservedBandwidth().size());
         assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
@@ -215,11 +221,14 @@ public class LinkstateAttributeParserTest {
         assertEquals(2, ls.getSharedRiskLinkGroups().size());
         assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue());
         assertEquals("12K-2", ls.getLinkName());
-        final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder().setAddressFamily(Boolean.TRUE).setBackup(Boolean.FALSE).setSet(Boolean.FALSE).build();
+        final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder().setAddressFamily(Boolean.TRUE)
+                .setBackup(Boolean.FALSE).setSet(Boolean.FALSE).build();
         assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
         assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
-        assertEquals(new Long(1048575L), ((LocalLabelCase)ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel().getValue());
-        assertEquals(new Long(1048559L), ((LocalLabelCase)ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel().getValue());
+        assertEquals(new Long(1048575L), ((LocalLabelCase)ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel()
+            .getValue());
+        assertEquals(new Long(1048559L), ((LocalLabelCase)ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel()
+            .getValue());
         assertEquals(new Long(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
         assertEquals(new Short("5"), ls.getPeerNodeSid().getWeight().getValue());
         assertEquals(new Long(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
@@ -239,7 +248,7 @@ public class LinkstateAttributeParserTest {
     @Test
     public void testPositiveNodes() throws BGPParsingException {
         final AttributesBuilder builder = createBuilder(new NodeCaseBuilder().build());
-        this.parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder);
+        this.parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder, null);
 
         final Attributes1 attrs = builder.augmentation(Attributes1.class);
         final NodeAttributes ls = ((NodeAttributesCase) attrs.getLinkStateAttribute()).getNodeAttributes();
@@ -268,8 +277,9 @@ public class LinkstateAttributeParserTest {
     @Test
     public void testPositiveV4Prefixes() throws BGPParsingException {
         final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(
-            new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32"))).build()).build());
-        this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder);
+            new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32")))
+            .build()).build());
+        this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder, null);
 
         final Attributes1 attrs = builder.augmentation(Attributes1.class);
         final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
@@ -286,10 +296,11 @@ public class LinkstateAttributeParserTest {
         assertTrue(ispBits.isOspfLocalAddress());
         assertTrue(ispBits.isOspfPropagateNssa());
         assertEquals(2, ls.getRouteTags().size());
-        assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0).getValue());
+        assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0)
+            .getValue());
         assertEquals(1, ls.getExtendedTags().size());
-        assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50,
-            (byte) 0x70 }, ls.getExtendedTags().get(0).getValue());
+        assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30,
+                (byte) 0x50, (byte) 0x70 }, ls.getExtendedTags().get(0).getValue());
         assertEquals(10, ls.getPrefixMetric().getValue().intValue());
         assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4Address().getValue());
 
@@ -304,22 +315,27 @@ public class LinkstateAttributeParserTest {
     @Test
     public void testPositiveTELspAttribute() throws BGPParsingException {
         final AttributesBuilder builder = createBuilder(new TeLspCaseBuilder().build());
-        this.parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder);
+        this.parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder, null);
 
         final Attributes1 attrs = builder.augmentation(Attributes1.class);
-        final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute()).getTeLspAttributes();
+        final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute())
+                .getTeLspAttributes();
         assertNotNull(teLspAttributes);
         final TspecObject tSpec = teLspAttributes.getTspecObject();
         assertNotNull(tSpec);
-        assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}), tSpec.getTokenBucketRate());
-        assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02}), teLspAttributes.getTspecObject().getTokenBucketSize());
-        assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03}), tSpec.getPeakDataRate());
+        assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}),
+            tSpec.getTokenBucketRate());
+        assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02}),
+            teLspAttributes.getTspecObject().getTokenBucketSize());
+        assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03}),
+            tSpec.getPeakDataRate());
         assertEquals(new Long("4"), tSpec.getMinimumPolicedUnit());
         assertEquals(new Long("5"), tSpec.getMaximumPacketSize());
 
         final AssociationObject associationObject = teLspAttributes.getAssociationObject();
         assertEquals(AssociationType.Recovery, associationObject.getAssociationType());
-        final IpAddressNoZone ipv4 = new IpAddressNoZone(Ipv4Util.noZoneAddressForByteBuf(Unpooled.copiedBuffer(new byte[]{0x01, 0x02, 0x03, 0x04})));
+        final IpAddressNoZone ipv4 = new IpAddressNoZone(Ipv4Util.noZoneAddressForByteBuf(Unpooled.copiedBuffer(
+            new byte[]{0x01, 0x02, 0x03, 0x04})));
         assertEquals(ipv4, associationObject.getIpAddress());
         final short associationId = 2;
         assertEquals(associationId, associationObject.getAssociationId().shortValue());
index f63f1c04908dcfd9ef25a33088594191f33fe1fd..038cd0336a28c6aa3e211b66bfea29e9c88f483f 100644 (file)
@@ -5,12 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.bgp.mvpn.impl.attributes;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.opendaylight.protocol.bgp.parser.spi.AttributeUtil.formatAttribute;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
@@ -18,6 +17,7 @@ import java.util.List;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.protocol.util.MplsLabelUtil;
@@ -46,14 +46,16 @@ public final class PEDistinguisherLabelsAttributeHandler implements AttributePar
     }
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
         if (!buffer.isReadable()) {
             return;
         }
         final boolean isIpv4 = buffer.readableBytes() % 7 == 0;
         final boolean isIpv6 = buffer.readableBytes() % 19 == 0;
-        Preconditions.checkArgument(isIpv4 || isIpv6,
-                "Length of byte array should be multiple of 7 or multiple of 19");
+
+        // FIXME: BGPCEP-359: what is the handling here?
+        checkArgument(isIpv4 || isIpv6, "Length of byte array should be multiple of 7 or multiple of 19");
 
         final List<PeDistinguisherLabelAttribute> list = new ArrayList<>();
         while (buffer.isReadable()) {
index 41ef178edbf9bb0817de8ac1c42e265c5dbe49bf..b671a5d3ff5f45019451f26e41b2b60c622bc24f 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.protocol.bgp.mvpn.spi.pojo.attributes.tunnel.identifier.
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.MplsLabelUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
@@ -57,7 +58,9 @@ public final class PMSITunnelAttributeHandler implements AttributeParser, Attrib
     }
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
+        // FIXME: BGPCEP-359: what is the error handling here?
         if (!buffer.isReadable()) {
             return;
         }
index 4fcada764cd0e3c641a40f16454337116c00b9cf..482b4a4b74e5f11d1303c472f7e6ba56ac742789 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.bgp.mvpn.impl.attributes;
 
 import static org.junit.Assert.assertArrayEquals;
@@ -211,7 +210,7 @@ public final class PMSITunnelAttributeHandlerTest {
         assertEquals(22, pmsiHandler.getType());
         final AttributesBuilder builder = new AttributesBuilder();
         final ByteBuf emptyBuffer = Unpooled.buffer();
-        pmsiHandler.parseAttribute(emptyBuffer, builder);
+        pmsiHandler.parseAttribute(emptyBuffer, builder, null);
         final Attributes emptyAttributes = new AttributesBuilder().build();
         assertEquals(emptyAttributes, builder.build());
         pmsiHandler.serializeAttribute(emptyAttributes, emptyBuffer);
index 8e52de0a2afed8daa5a09c4b454726fe29e1ad8c..e87ded6ef4c01f759a0df0d448dc1e47316b4e43 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 
@@ -18,7 +19,8 @@ public final class AS4AggregatorAttributeParser implements AttributeParser, Attr
     public static final int TYPE = 17;
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
         // AS4 Aggregator is ignored
     }
 
index ff7b08595a07093f5da5691399f4158fb109f494..b998ddadbe818d8e96c57595382907afa13165f0 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update;
 import io.netty.buffer.ByteBuf;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 
@@ -18,7 +19,8 @@ public final class AS4PathAttributeParser implements AttributeParser, AttributeS
     public static final int TYPE = 18;
 
     @Override
-    public void parseAttribute(final ByteBuf bytes, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf bytes, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
         // AS4 Path is ignored
     }
 
index 28f026de8315eca8bc3989cb0e0ca1f53348e79a..6a3fbc9f23d0e31bb8e2630d6f1d5ddd40c8a311 100644 (file)
@@ -15,6 +15,7 @@ import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.ReferenceCache;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
@@ -42,7 +43,15 @@ public final class AggregatorAttributeParser implements AttributeParser, Attribu
      * @param builder AttributesBuilder into which parsed {@link Aggregator} will be set
      */
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
+        // FIXME: BGPCEP-359: attribute-discard if:
+        //  o  Its length is not 6 (when the 4-octet AS number capability is not
+        //     advertised to or not received from the peer [RFC6793]).
+        //
+        //  o  Its length is not 8 (when the 4-octet AS number capability is both
+        //     advertised to and received from the peer).
+
         final AsNumber asNumber = this.refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt()));
         final Ipv4Address address = Ipv4Util.addressForByteBuf(buffer);
         builder.setAggregator(new AggregatorBuilder().setAsNumber(asNumber).setNetworkAddress(address).build());
index 92ae2f8076699a604d58d0d9fef0f782844c45a1..acd2dd0a4a3217370b89aa511c8a17638d30b1f7 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.Aigp;
@@ -36,8 +37,8 @@ public class AigpAttributeParser implements AttributeParser, AttributeSerializer
     public static final int TYPE = 26;
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder)
-            throws BGPDocumentedException, BGPParsingException {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
         if(!buffer.isReadable()) {
             return;
         }
index c655448cde86060e3678e8584b53caaa769c5373..9b122af5d262ba5fc06c69dbf619a3c20a5d1388 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentPar
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.ReferenceCache;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
@@ -50,11 +51,12 @@ public final class AsPathAttributeParser implements AttributeParser, AttributeSe
      *
      * @param refCache ReferenceCache shared reference of object
      * @param buffer bytes to be parsed
+     * @param constraint
      * @return new ASPath object
      * @throws BGPDocumentedException if there is no AS_SEQUENCE present (mandatory)
      */
-    private static AsPath parseAsPath(final ReferenceCache refCache, final ByteBuf buffer)
-            throws BGPDocumentedException, BGPParsingException {
+    private static AsPath parseAsPath(final ReferenceCache refCache, final ByteBuf buffer,
+            final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
         if (!buffer.isReadable()) {
             return EMPTY;
         }
@@ -64,12 +66,18 @@ public final class AsPathAttributeParser implements AttributeParser, AttributeSe
             final int type = buffer.readUnsignedByte();
             final SegmentType segmentType = AsPathSegmentParser.parseType(type);
             if (segmentType == null) {
+                // FIXME: BGPCEP-359: treat-as-withdraw
                 throw new BGPParsingException("AS Path segment type unknown : " + type);
             }
+
+            // FIXME: BGPCEP-359: treat-as-withdraw if no data is available
             final int count = buffer.readUnsignedByte();
+            // FIXME: BGPCEP-359: treat-as-withdraw if count == 0
+            final int segmentLength = count * AsPathSegmentParser.AS_NUMBER_LENGTH;
+            // FIXME: BGPCEP-359: treat-as-withdraw if there is a buffer overrun
 
             final List<AsNumber> asList = AsPathSegmentParser.parseAsSegment(refCache, count,
-                    buffer.readSlice(count * AsPathSegmentParser.AS_NUMBER_LENGTH));
+                buffer.readSlice(segmentLength));
             if (segmentType == SegmentType.AS_SEQUENCE) {
                 ases.add(new SegmentsBuilder().setAsSequence(asList).build());
                 isSequence = true;
@@ -87,9 +95,9 @@ public final class AsPathAttributeParser implements AttributeParser, AttributeSe
     }
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder)
-            throws BGPDocumentedException, BGPParsingException {
-        builder.setAsPath(parseAsPath(this.refCache, buffer));
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
+        builder.setAsPath(parseAsPath(this.refCache, buffer, constraint));
     }
 
     @Override
index acc3acbea159faac276a684b5ecf89684ff9bd03..da77c9eddcc01066acc0a0172bf027816de60ae2 100644 (file)
@@ -12,6 +12,7 @@ import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.AtomicAggregateBuilder;
@@ -21,7 +22,9 @@ public final class AtomicAggregateAttributeParser implements AttributeParser, At
     public static final int TYPE = 6;
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
+        // FIXME: BGPCEP-359: attribute discard if length != 0
         builder.setAtomicAggregate(new AtomicAggregateBuilder().build());
     }
 
index 6c31d06b912a2896c09cf8b4261f2211e7c5eaec..c53f91d226179faee5e776d6a381eebcc0fc8dee 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.BgpPrefixSid;
@@ -47,8 +48,8 @@ public final class BgpPrefixSidAttributeParser implements AttributeParser, Attri
     }
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder)
-            throws BGPDocumentedException, BGPParsingException {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
         final BgpPrefixSidBuilder sid = new BgpPrefixSidBuilder();
         final List<BgpPrefixSidTlvs> tlvList = new ArrayList<>();
         while (buffer.isReadable()) {
index 4a6cb9e64042947727adb399eace17d6e6e5ec05..0c5aeb1986500ce9bc16199a05c4c6312dfa1acd 100644 (file)
@@ -14,6 +14,7 @@ import java.util.List;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
@@ -26,7 +27,12 @@ public final class ClusterIdAttributeParser implements AttributeParser, Attribut
     public static final int TYPE = 10;
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
+        // FIXME: BGPCEP-359:
+        //        - external peer: discard attribute (always?)
+        //        - internal peer: treat-as-withdraw if length == 0 or not a multiple of four
+        // FIXME: once do the above check, optimize list allocation
         final List<ClusterIdentifier> list = new ArrayList<>();
         while (buffer.isReadable()) {
             list.add(new ClusterIdentifier(Ipv4Util.addressForByteBuf(buffer)));
index 253de931d0fb1286c5f23f2c4da242a8a75daab6..cc0122a185b0c2109b83b32eba353923b0021017 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.ReferenceCache;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
@@ -45,7 +46,10 @@ public final class CommunitiesAttributeParser implements AttributeParser, Attrib
     }
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) throws BGPDocumentedException {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
+        // FIXME: BGPCEP-359: treat-as-withdraw if buffer.readableBytes() is 0 or not a multiple of COMMUNITY_LENGTH
+        // FIXME: optimize allocation once we have done the above check
         final List<Communities> set = new ArrayList<>();
         while (buffer.isReadable()) {
             set.add((Communities) parseCommunity(this.refCache, buffer.readSlice(COMMUNITY_LENGTH)));
index 4b7b649819c5d95dee1b155f97bfbe853ed831e1..d9abf74cf12d82512f50aedf53d49f39527b9459 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
@@ -35,10 +36,13 @@ public final class ExtendedCommunitiesAttributeParser implements AttributeParser
     }
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder)
-            throws BGPDocumentedException, BGPParsingException {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
+        // FIXME: BGPCEP-359: treat-as-withdraw if length == 0 or not a multiple of 8
+        // FIXME: once we do the above check, optimize list allocation here
         final List<ExtendedCommunities> set = new ArrayList<>();
         while (buffer.isReadable()) {
+            // FIXME: BGPCEP-359: malformed communities need to trigger treat-as-withdraw
             final ExtendedCommunities exComm = this.ecReg.parseExtendedCommunity(buffer);
             if (exComm != null) {
                 set.add(exComm);
index f49943bf1353eead74b7f5da09049875e5c90dac..bca45532462ca7661aafa9051db5205cccb9f47f 100644 (file)
@@ -12,6 +12,7 @@ import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPref;
@@ -22,7 +23,11 @@ public final class LocalPreferenceAttributeParser implements AttributeParser, At
     public static final int TYPE = 5;
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
+        // FIXME: BGPCEP-359:
+        //        - if peer is external: attribute discard
+        //        - if peer is internal: treat-as-withdraw if length != 4
         builder.setLocalPref(new LocalPrefBuilder().setPref(buffer.readUnsignedInt()).build());
     }
 
index 23b9208b4aa1f386d98e1118699a3d69c3e0d0bc..fb2ce1d55adeb4ed7d6f87c79f9a8e4c6a96d2b7 100644 (file)
@@ -35,16 +35,14 @@ public final class MPReachAttributeParser extends ReachAttributeParser{
     }
 
     @Override
-    public void parseAttribute(
-            final ByteBuf buffer,
-            final AttributesBuilder builder,
-            final PeerSpecificParserConstraint constraint)
-            throws BGPDocumentedException {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
         try {
             final MpReachNlri mpReachNlri = this.reg.parseMpReach(buffer, constraint);
             final Attributes1 a = new Attributes1Builder().setMpReachNlri(mpReachNlri).build();
             builder.addAugmentation(Attributes1.class, a);
         } catch (final BGPParsingException e) {
+            // FIXME: BGPCEP-359: revise handling
             throw new BGPDocumentedException("Could not parse MP_REACH_NLRI", BGPError.OPT_ATTR_ERROR, e);
         }
     }
index 4bebea7c6cd5fc3d553c610ea3fa0c62608addd3..f1c6358e56c0f4912210cd09a4a13e4780247ac1 100644 (file)
@@ -34,16 +34,14 @@ public final class MPUnreachAttributeParser extends ReachAttributeParser {
     }
 
     @Override
-    public void parseAttribute(
-            final ByteBuf buffer,
-            final AttributesBuilder builder,
-            final PeerSpecificParserConstraint constraint)
-            throws BGPDocumentedException {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
         try {
             final MpUnreachNlri mpUnreachNlri = this.reg.parseMpUnreach(buffer, constraint);
             final Attributes2 a = new Attributes2Builder().setMpUnreachNlri(mpUnreachNlri).build();
             builder.addAugmentation(Attributes2.class, a);
         } catch (final BGPParsingException e) {
+            // FIXME: BGPCEP-359: revise handling
             throw new BGPDocumentedException("Could not parse MP_UNREACH_NLRI", BGPError.OPT_ATTR_ERROR, e);
         }
     }
index 2acdbf3843fc5a8f18ff810a698c81a5ca2052b4..48f943d01db078123fd1221470e955bed0521d7f 100644 (file)
@@ -12,6 +12,7 @@ import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDisc;
@@ -22,7 +23,9 @@ public final class MultiExitDiscriminatorAttributeParser implements AttributePar
     public static final int TYPE = 4;
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
+        // FIXME: BGPCEP-359: check if length == 4, if not treat-as-withdraw
         builder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(buffer.readUnsignedInt()).build());
     }
 
index be99513f115dcc745de469568c85f973bd317063..3c3a5a1aef9d96cb5bb19460804a50edd0eea3af 100644 (file)
@@ -7,13 +7,15 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.bgp.concepts.NextHopUtil;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
@@ -24,8 +26,10 @@ public final class NextHopAttributeParser implements AttributeParser, AttributeS
     public static final int TYPE = 3;
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
-        Preconditions.checkArgument(buffer.readableBytes() == Ipv4Util.IP4_LENGTH,
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
+        // FIXME: BGPCEP-359: treat-as-withdraw
+        checkArgument(buffer.readableBytes() == Ipv4Util.IP4_LENGTH,
                 "Length of byte array for NEXT_HOP should be %s, but is %s",
                 buffer.readableBytes(), Ipv4Util.IP4_LENGTH);
         builder.setCNextHop(NextHopUtil.parseNextHop(buffer));
index 5eef7554699ce78ab4f9bcb0850d7bb8931d6e39..ff07163f0332c05d7fc105fca31eaa059a4c0412 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.Origin;
@@ -30,10 +31,13 @@ public final class OriginAttributeParser implements AttributeParser, AttributeSe
     private static final Origin INC = new OriginBuilder().setValue(BgpOrigin.Incomplete).build();
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) throws BGPDocumentedException {
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
+        // FIXME: BGPCEP-359: check if a byte is available, treat-as-withdraw
         final byte rawOrigin = buffer.readByte();
         final BgpOrigin borigin = BgpOrigin.forValue(UnsignedBytes.toInt(rawOrigin));
         if (borigin == null) {
+            // FIXME: BGPCEP-359: treat-as-withdraw
             throw new BGPDocumentedException("Unknown Origin type.", BGPError.ORIGIN_ATTR_NOT_VALID,
                     new byte[]{(byte) 0x01, (byte) 0x01, rawOrigin});
         }
index 6cd7fd03fb3605394cd83556339dfde7c8992a0e..cfb1a3f28f25a21ecfa082ff94f9ad8203f2542d 100644 (file)
@@ -7,12 +7,14 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OriginatorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
@@ -24,8 +26,12 @@ public final class OriginatorIdAttributeParser implements AttributeParser, Attri
     public static final int TYPE = 9;
 
     @Override
-    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
-        Preconditions.checkArgument(buffer.readableBytes() == Ipv4Util.IP4_LENGTH,
+    public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
+            final PeerSpecificParserConstraint constraint) {
+        // FIXME: BGPCEP-359:
+        //        - external peers: attribute-discard (always?)
+        //        - internal peers: treat-as-withdraw
+        checkArgument(buffer.readableBytes() == Ipv4Util.IP4_LENGTH,
                 "Length of byte array for ORIGINATOR_ID should be %s, but is %s",
                 Ipv4Util.IP4_LENGTH, buffer.readableBytes());
         builder.setOriginatorId(new OriginatorIdBuilder().setOriginator(Ipv4Util.addressForByteBuf(buffer)).build());
index 3e3b98663b21e9f59def4393005492d54bd2b89f..b4258d87d6f77a86771bce03e38ab1975b32002e 100644 (file)
@@ -7,18 +7,9 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
 
 public abstract class ReachAttributeParser implements AttributeParser, AttributeSerializer {
 
-    @Override
-    public final void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder)
-            throws BGPDocumentedException, BGPParsingException {
-        parseAttribute(buffer, builder, null);
-    }
 }
index 75ba4a41a598b5d908a5797a6c031afc4271ab74..5a8636e7c4d1befd3c9e6d116378ca78e13c680f 100644 (file)
@@ -8,11 +8,18 @@
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvRegistry;
@@ -21,24 +28,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 
 public final class BgpPrefixSidAttributeParserTest {
 
-    private final BgpPrefixSidTlvRegistry reg = Mockito.mock(BgpPrefixSidTlvRegistry.class);
-    private final BgpPrefixSidTlv tlv = Mockito.mock(BgpPrefixSidTlv.class);
+    private final BgpPrefixSidTlvRegistry reg = mock(BgpPrefixSidTlvRegistry.class);
+    private final BgpPrefixSidTlv tlv = mock(BgpPrefixSidTlv.class);
     private final BgpPrefixSidAttributeParser parser = new BgpPrefixSidAttributeParser(this.reg);
     private final byte[] bytes = new byte[] {1, 2, 3};
 
     @Before
     public void setUp() {
-        Mockito.doReturn(this.tlv).when(this.reg).parseBgpPrefixSidTlv(Mockito.anyInt(), Mockito.any(ByteBuf.class));
-        Mockito.doNothing().when(this.reg).serializeBgpPrefixSidTlv(Mockito.any(BgpPrefixSidTlv.class), Mockito.any(ByteBuf.class));
+        doReturn(this.tlv).when(this.reg).parseBgpPrefixSidTlv(anyInt(), any(ByteBuf.class));
+        doNothing().when(this.reg).serializeBgpPrefixSidTlv(any(BgpPrefixSidTlv.class), any(ByteBuf.class));
     }
 
     @Test
     public void testHandling() throws BGPDocumentedException, BGPParsingException {
         final AttributesBuilder builder = new AttributesBuilder();
-        this.parser.parseAttribute(Unpooled.copiedBuffer(this.bytes), builder);
+        this.parser.parseAttribute(Unpooled.copiedBuffer(this.bytes), builder, null);
         assertEquals(3, builder.getBgpPrefixSid().getBgpPrefixSidTlvs().size());
 
         this.parser.serializeAttribute(builder.build(), Unpooled.EMPTY_BUFFER);
-        Mockito.verify(this.reg, Mockito.times(3)).serializeBgpPrefixSidTlv(Mockito.any(BgpPrefixSidTlv.class), Mockito.any(ByteBuf.class));
+        verify(this.reg, times(3)).serializeBgpPrefixSidTlv(any(BgpPrefixSidTlv.class), any(ByteBuf.class));
     }
 }
index b0eb057d818a0fa088e1659bb87ac3ee4b352c0a..9e2723844f1ac0c5ea7b896730e5b42539bc9ab3 100644 (file)
@@ -52,7 +52,8 @@ public class ClusterIdAttributeParserTest {
         assertArrayEquals(clusterIdBytes, ByteArray.getAllBytes(output));
 
         AttributesBuilder clusterIdOutput = new AttributesBuilder();
-        this.parser.parseAttribute(Unpooled.wrappedBuffer(ByteArray.cutBytes(clusterIdBytes, 3)), clusterIdOutput);
+        this.parser.parseAttribute(Unpooled.wrappedBuffer(ByteArray.cutBytes(clusterIdBytes, 3)), clusterIdOutput,
+            null);
         assertEquals(clusterId, clusterIdOutput.build());
     }
 
index 801e70e79b99a93f1c0fbc4f69d2e2474d2e41af..1cba27daf3c8dbc02fb5bcfaa64a2a2fc75de44f 100644 (file)
@@ -5,15 +5,17 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import com.google.common.primitives.Bytes;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
 import java.util.List;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
@@ -55,13 +57,13 @@ public class ExtendedCommunitiesAttributeParserTest {
         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setTransitive(false).setExtendedCommunity(routeOrigin).build();
         final AttributesBuilder attBuilder = new AttributesBuilder();
 
-        this.handler.parseAttribute(Unpooled.copiedBuffer(INPUT), attBuilder);
+        this.handler.parseAttribute(Unpooled.copiedBuffer(INPUT), attBuilder, null);
         final ExtendedCommunities parsed = attBuilder.getExtendedCommunities().get(0);
-        Assert.assertEquals(expected, parsed);
+        assertEquals(expected, parsed);
 
         final ByteBuf output = Unpooled.buffer(INPUT.length);
         this.handler.serializeAttribute(attBuilder.build(), output);
-        Assert.assertArrayEquals(Bytes.concat(new byte[] {(byte)192, 16, 8}, INPUT), ByteArray.readAllBytes(output));
+        assertArrayEquals(Bytes.concat(new byte[] {(byte)192, 16, 8}, INPUT), ByteArray.readAllBytes(output));
     }
 
     @Test
@@ -71,21 +73,20 @@ public class ExtendedCommunitiesAttributeParserTest {
         final ByteBuf output = Unpooled.buffer();
 
         this.handler.serializeAttribute(attBuilder.build(), output);
-        Assert.assertEquals(output, output);
+        assertEquals(output, output);
     }
 
     @Test
     public void testEmptyExtendedCommunityAttributeParser() throws BGPDocumentedException, BGPParsingException {
         final ByteBuf output = Unpooled.buffer();
         this.handler.serializeAttribute(new AttributesBuilder().build(), output);
-        Assert.assertEquals( Unpooled.buffer(), output);
+        assertEquals( Unpooled.buffer(), output);
     }
 
     @Test
     public void testExtendedCommunityAttributeParserUnknown() throws BGPDocumentedException, BGPParsingException {
         final AttributesBuilder attBuilder = new AttributesBuilder();
-        this.handler.parseAttribute(Unpooled.copiedBuffer(UNKOWN), attBuilder);
-        Assert.assertTrue(attBuilder.getExtendedCommunities().isEmpty());
+        this.handler.parseAttribute(Unpooled.copiedBuffer(UNKOWN), attBuilder, null);
+        assertTrue(attBuilder.getExtendedCommunities().isEmpty());
     }
-
 }
index 81e7c7bf5aa78a495c872df418153b50dae54ad6..22eefeb2c12178962c6eb7d8504c7a6ca0ee8d65 100644 (file)
@@ -24,25 +24,8 @@ public interface AttributeParser {
      * @param buffer Encoded attribute body in ByteBuf.
      * @param builder Path attributes builder. Guaranteed to contain all valid attributes whose type is numerically
      *        lower than this attribute's type.
+     * @param constraint Peer specific constraints, may be null
      */
-    void parseAttribute(@Nonnull ByteBuf buffer, @Nonnull AttributesBuilder builder)
-            throws BGPDocumentedException, BGPParsingException;
-
-    /**
-     * Invokes {@link #parseAttribute(ByteBuf, AttributesBuilder)}, so the constraint is omitted. Override for specific parser behavior.
-     *
-     * @param buffer Encoded attribute body in ByteBuf.
-     * @param builder Path attributes builder. Guaranteed to contain all valid attributes whose type is numerically
-     *        lower than this attribute's type.
-     * @param constraint Peer specific constraints.
-     * @throws BGPDocumentedException exception.
-     * @throws BGPParsingException exception.
-     */
-    default void parseAttribute(
-            @Nonnull final ByteBuf buffer,
-            @Nonnull final AttributesBuilder builder,
-            @Nullable final PeerSpecificParserConstraint constraint)
-            throws BGPDocumentedException, BGPParsingException {
-        parseAttribute(buffer, builder);
-    }
+    void parseAttribute(@Nonnull ByteBuf buffer, @Nonnull AttributesBuilder builder,
+            @Nullable PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException;
 }