Bug 4827: MultiPathSupport implementation 70/35770/12
authorMilos Fabian <milfabia@cisco.com>
Thu, 3 Mar 2016 19:48:19 +0000 (20:48 +0100)
committerMilos Fabian <milfabia@cisco.com>
Tue, 3 May 2016 09:42:01 +0000 (11:42 +0200)
Implemented BGP Add-Path supported tables holder
suitable for holding Add-Path constraitns for a decoder.

Change-Id: Ic6380addddf02b23fd160fa8f363cceeb89af577
Signed-off-by: Milos Fabian <milfabia@cisco.com>
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/MultiPathSupportImpl.java [new file with mode: 0644]
bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/pojo/MultiPathSupportImplTest.java [new file with mode: 0644]

diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/MultiPathSupportImpl.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/MultiPathSupportImpl.java
new file mode 100644 (file)
index 0000000..e9ba00b
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.parser.spi.pojo;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
+
+public final class MultiPathSupportImpl implements MultiPathSupport {
+
+    private final Set<BgpTableType> supportedTables;
+
+    private MultiPathSupportImpl(final Set<BgpTableType> supportedTables) {
+        this.supportedTables = ImmutableSet.copyOf(supportedTables);
+    }
+
+    /**
+     * Creates instance of {@link MultiPathSupport} holder to be used
+     * as a parser constraint, hence only "send" add-path capabilities are
+     * taken into the account.
+     *
+     * @param addPathCapabilities The remote add-path capabilities list.
+     * @return MultiPathSupport instance.
+     */
+    public static MultiPathSupport createParserMultiPathSupport(@Nonnull final List<AddressFamilies> addPathCapabilities) {
+        Preconditions.checkNotNull(addPathCapabilities);
+        final Set<BgpTableType> support = addPathCapabilities
+            .stream()
+            .filter(e -> e.getSendReceive() == SendReceive.Both || e.getSendReceive() == SendReceive.Send)
+            .map(e -> new BgpTableTypeImpl(e.getAfi(), e.getSafi()))
+            .collect(Collectors.toSet());
+        return new MultiPathSupportImpl(support);
+    }
+
+    @Override
+    public boolean isTableTypeSupported(final BgpTableType tableType) {
+        return this.supportedTables.contains(tableType);
+    }
+
+}
diff --git a/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/pojo/MultiPathSupportImplTest.java b/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/pojo/MultiPathSupportImplTest.java
new file mode 100644 (file)
index 0000000..ca3e24b
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.parser.spi.pojo;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamiliesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+
+public class MultiPathSupportImplTest {
+
+    @Test(expected=NullPointerException.class)
+    public void testcreateParserMultiPathSupportNull() {
+        MultiPathSupportImpl.createParserMultiPathSupport(null);
+    }
+
+    @Test
+    public void testIsTableTypeSupported() {
+        final List<AddressFamilies> supportedTables = Lists.newArrayList();
+        final BgpTableType ipv4Unicast = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+        final BgpTableType ipv4L3vpn = new BgpTableTypeImpl(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
+        final BgpTableType ipv6Unicast = new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
+        final BgpTableType ipv6L3vpn = new BgpTableTypeImpl(Ipv6AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class);
+        supportedTables.add(createAddPathCapability(ipv4Unicast, SendReceive.Send));
+        supportedTables.add(createAddPathCapability(ipv4L3vpn, SendReceive.Receive));
+        supportedTables.add(createAddPathCapability(ipv6Unicast, SendReceive.Both));
+        final MultiPathSupport multiPathSupport = MultiPathSupportImpl.createParserMultiPathSupport(supportedTables);
+
+        Assert.assertTrue(multiPathSupport.isTableTypeSupported(ipv4Unicast));
+        Assert.assertTrue(multiPathSupport.isTableTypeSupported(ipv6Unicast));
+        Assert.assertFalse(multiPathSupport.isTableTypeSupported(ipv4L3vpn));
+        Assert.assertFalse(multiPathSupport.isTableTypeSupported(ipv6L3vpn));
+    }
+
+    private static AddressFamilies createAddPathCapability(final BgpTableType afisafi, final SendReceive mode) {
+        return new AddressFamiliesBuilder().setAfi(afisafi.getAfi()).setSafi(afisafi.getSafi()).setSendReceive(mode).build();
+    }
+
+}