BGP-4826: Evpn Extended Communities Handlers Tests 92/37592/3
authorClaudio D. Gasparini <cgaspari@cisco.com>
Wed, 6 Apr 2016 09:52:48 +0000 (11:52 +0200)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 18 Apr 2016 10:46:04 +0000 (10:46 +0000)
Evpn Extended Communities Handlers Tests

Change-Id: I158374c44b0a842d8e68b90175880acc6e468d15
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnTestUtil.java
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/DefaultGatewayExtComTest.java [new file with mode: 0644]
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESILabelExtComTest.java [new file with mode: 0644]
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESImpRouteTargetExtComTest.java [new file with mode: 0644]
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtComTest.java [new file with mode: 0644]

index ab969e2c186a6125744cce949afb2cc1e4295e2e..d2f585ec00e443643aa1867dd105f41e7812307e 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.evpn.impl;
 
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
@@ -24,6 +25,8 @@ public final class EvpnTestUtil {
     public static final long AS_MODEL = 16843009;
     public static final AsNumber AS_NUMBER = new AsNumber(AS_MODEL);
     public static final Integer PORT = 514;
+    public static final MplsLabel MPLS_LABEL = new MplsLabel(24001L);
+    public static final int COMMUNITY_VALUE_SIZE = 6;
 
     public static DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> createContBuilder(final YangInstanceIdentifier
         .NodeIdentifier nid) {
diff --git a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/DefaultGatewayExtComTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/DefaultGatewayExtComTest.java
new file mode 100644 (file)
index 0000000..27f325a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.evpn.impl.extended.communities;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.COMMUNITY_VALUE_SIZE;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321._default.gateway.extended.community.DefaultGatewayExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+
+public class DefaultGatewayExtComTest {
+    private static final byte[] RESULT = {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
+    private DefaultGatewayExtCom parser;
+
+    @Before
+    public void setUp() {
+        this.parser = new DefaultGatewayExtCom();
+    }
+
+    @Test
+    public void parserTest() throws BGPParsingException, BGPDocumentedException {
+        final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
+
+        final DefaultGatewayExtendedCommunityCase expected = new DefaultGatewayExtendedCommunityCaseBuilder().setDefaultGatewayExtendedCommunity(
+            new DefaultGatewayExtendedCommunityBuilder().build()).build();
+        this.parser.serializeExtendedCommunity(expected, buff);
+        assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+        final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
+        assertEquals(expected, result);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void wrongCaseTest() {
+        this.parser.serializeExtendedCommunity(new EsiLabelExtendedCommunityCaseBuilder().build(), null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void wrongSizeTest() throws BGPParsingException, BGPDocumentedException {
+        this.parser.parseExtendedCommunity(Unpooled.buffer(8));
+    }
+
+    @Test
+    public void testSubtype() {
+        assertEquals(13, this.parser.getSubType());
+    }
+}
\ No newline at end of file
diff --git a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESILabelExtComTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESILabelExtComTest.java
new file mode 100644 (file)
index 0000000..39dc7ca
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.evpn.impl.extended.communities;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.COMMUNITY_VALUE_SIZE;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MPLS_LABEL;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.esi.label.extended.community.EsiLabelExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+
+public class ESILabelExtComTest {
+    private static final byte[] RESULT = {(byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0xdc, (byte) 0x10};
+    private ESILabelExtCom parser;
+
+    @Before
+    public void setUp() {
+        this.parser = new ESILabelExtCom();
+    }
+
+    @Test
+    public void parserTest() throws BGPParsingException, BGPDocumentedException {
+        final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
+
+        final EsiLabelExtendedCommunityCase expected = new EsiLabelExtendedCommunityCaseBuilder().setEsiLabelExtendedCommunity(
+            new EsiLabelExtendedCommunityBuilder().setSingleActiveMode(true).setEsiLabel(MPLS_LABEL).build()).build();
+        this.parser.serializeExtendedCommunity(expected, buff);
+        assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+        final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
+        assertEquals(expected, result);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void wrongCaseTest() {
+        this.parser.serializeExtendedCommunity(new DefaultGatewayExtendedCommunityCaseBuilder().build(), null);
+    }
+
+    @Test
+    public void testSubtype() {
+        assertEquals(1, this.parser.getSubType());
+    }
+}
\ No newline at end of file
diff --git a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESImpRouteTargetExtComTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/ESImpRouteTargetExtComTest.java
new file mode 100644 (file)
index 0000000..d1d3be6
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.evpn.impl.extended.communities;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.COMMUNITY_VALUE_SIZE;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MAC;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.es._import.route.extended.community.EsImportRouteExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsImportRouteExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsImportRouteExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+
+public class ESImpRouteTargetExtComTest {
+    private static final byte[] RESULT = {(byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7};
+    private ESImpRouteTargetExtCom parser;
+
+    @Before
+    public void setUp() {
+        this.parser = new ESImpRouteTargetExtCom();
+    }
+
+    @Test
+    public void parserTest() throws BGPParsingException, BGPDocumentedException {
+        final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
+
+        final EsImportRouteExtendedCommunityCase expected = new EsImportRouteExtendedCommunityCaseBuilder().setEsImportRouteExtendedCommunity(
+            new EsImportRouteExtendedCommunityBuilder().setEsImport(MAC).build()).build();
+        this.parser.serializeExtendedCommunity(expected, buff);
+        assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+        final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
+        assertEquals(expected, result);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void wrongCaseTest() {
+        this.parser.serializeExtendedCommunity(new DefaultGatewayExtendedCommunityCaseBuilder().build(), null);
+    }
+
+    @Test
+    public void testSubtype() {
+        assertEquals(2, this.parser.getSubType());
+    }
+}
\ No newline at end of file
diff --git a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtComTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/extended/communities/MACMobExtComTest.java
new file mode 100644 (file)
index 0000000..533ba63
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.evpn.impl.extended.communities;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.COMMUNITY_VALUE_SIZE;
+import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.LD;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.mac.mobility.extended.community.MacMobilityExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+
+public class MACMobExtComTest {
+    private static final byte[] RESULT = {(byte) 0x01, (byte) 0x00, (byte) 0x02, (byte) 0x02, (byte) 0x02, (byte) 0x02};
+    private MACMobExtCom parser;
+
+    @Before
+    public void setUp() {
+        this.parser = new MACMobExtCom();
+    }
+
+    @Test
+    public void parserTest() throws BGPParsingException, BGPDocumentedException {
+        final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
+
+        final MacMobilityExtendedCommunityCase expected = new MacMobilityExtendedCommunityCaseBuilder().setMacMobilityExtendedCommunity(
+            new MacMobilityExtendedCommunityBuilder().setStatic(true).setSeqNumber(LD).build()).build();
+        this.parser.serializeExtendedCommunity(expected, buff);
+        assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+        final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
+        assertEquals(expected, result);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void wrongCaseTest() {
+        this.parser.serializeExtendedCommunity(new DefaultGatewayExtendedCommunityCaseBuilder().build(), null);
+    }
+
+    @Test
+    public void testSubtype() {
+        assertEquals(0, this.parser.getSubType());
+    }
+}
\ No newline at end of file