BUG-6647 Increase code coverage and clean up III 07/46207/3
authorClaudio D. Gasparini <cgaspari@cisco.com>
Wed, 7 Sep 2016 17:55:51 +0000 (19:55 +0200)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Wed, 28 Sep 2016 07:32:42 +0000 (09:32 +0200)
-Implement Openconfig Tests
-Implement testtool-util tests
-Implemet Rib-spi test

Change-Id: I85d45ef84f37b8e00249e3a462c8ee9c9c5f5a60
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
25 files changed:
bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/spi/pojo/SimpleEvpnNlriRegistryTest.java
bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRIBSupport.java
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/BGPOpenConfigMappingServiceImpl.java
bgp/openconfig-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtil.java
bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/BGPOpenConfigMappingServiceImplTest.java [new file with mode: 0644]
bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/util/OpenConfigUtilTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/IdentifierUtils.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupport.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivator.java
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupportTest.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/IdentifierUtilsTest.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupportTest.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/PeerExportGroupTest.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/PeerRoleUtilTest.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RibSupportUtilsTest.java
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivatorTest.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Prefixes.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Route.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Routes.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4RoutesCase.java [new file with mode: 0644]
bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/MultiPathAbstractTest.java [new file with mode: 0644]
parent/pom.xml
testtool-util/src/test/java/org/opendaylight/protocol/util/InetSocketAddressUtilTest.java
testtool-util/src/test/java/org/opendaylight/protocol/util/LoggerUtilTest.java [new file with mode: 0644]

index 0600942b725ba30064de4e51d1cfb6ef0210a170..738537c1b987132fee47a2269b356dd607c4c249 100644 (file)
@@ -38,10 +38,10 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContaine
 public final class SimpleEvpnNlriRegistryTest {
     public static final YangInstanceIdentifier.NodeIdentifier EVPN_NID = new YangInstanceIdentifier.NodeIdentifier(EvpnChoice.QNAME);
 
-    private class notRegistered implements EvpnChoice {
+    private class NotRegistered implements EvpnChoice {
         @Override
         public Class<? extends DataContainer> getImplementedInterface() {
-            return notRegistered.class;
+            return NotRegistered.class;
         }
     }
 
@@ -71,7 +71,7 @@ public final class SimpleEvpnNlriRegistryTest {
     @Test
     public void registryNullTest() {
         final ByteBuf body = Unpooled.buffer();
-        SimpleEvpnNlriRegistry.getInstance().serializeEvpn(new notRegistered(), body);
+        SimpleEvpnNlriRegistry.getInstance().serializeEvpn(new NotRegistered(), body);
         assertEquals(0, body.readableBytes());
     }
 
index 9e9a604867b885c3579c1ce7dcdfe9b30fe0fe3b..d6498cddebd4a85d6c26d82dc6b6e21af5c726d0 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.protocol.bgp.inet;
 
+import com.google.common.annotations.Beta;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableCollection;
@@ -35,6 +36,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Common {@link org.opendaylight.protocol.bgp.rib.spi.RIBSupport} class for IPv4 and IPv6 addresses.
  */
+@Beta
 abstract class AbstractIPRIBSupport extends MultiPathAbstractRIBSupport {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractIPRIBSupport.class);
     private final NodeIdentifier prefixNid;
index 614161b20b11b0b7a61c0ca0ccb6e8c3b5c033e3..fea18cb0fefe635ca34e304beba3b60a01617586 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.protocol.bgp.openconfig.impl;
 
 import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.APPLICATION_PEER_GROUP_NAME;
+import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.toPeerType;
 
 import com.google.common.base.Optional;
 import java.math.BigDecimal;
@@ -191,7 +192,7 @@ public final class BGPOpenConfigMappingServiceImpl implements BGPOpenConfigMappi
                 new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder()
                 .setAuthPassword(password != null ? password.getValue() : null)
                 .setPeerAs(remoteAs)
-                .setPeerType(toPeerTye(peerRole))
+                .setPeerType(toPeerType(peerRole))
                 .setSendCommunity(CommunityType.NONE)
                 .setRouteFlapDamping(Boolean.FALSE)
                 .build());
@@ -208,21 +209,6 @@ public final class BGPOpenConfigMappingServiceImpl implements BGPOpenConfigMappi
         return neighborBuilder.build();
     }
 
-    private static PeerType toPeerTye(final PeerRole peerRole) {
-        switch (peerRole) {
-        case Ibgp:
-        case RrClient:
-            return PeerType.INTERNAL;
-        case Ebgp:
-            return PeerType.EXTERNAL;
-        case Internal:
-            break;
-        default:
-            break;
-        }
-        return null;
-    }
-
     @Override
     public Neighbor fromApplicationPeer(final ApplicationRibId applicationRibId, final BgpId bgpId) {
         final NeighborBuilder neighborBuilder = new NeighborBuilder();
index e93547288bb7817de1bc1811714f58bc34817ec5..06c50f9bd511ed0894f251ff835e4800018e98ce 100644 (file)
@@ -166,7 +166,7 @@ public final class OpenConfigUtil {
     }
 
     public static AfiSafi toGlobalAfiSafiAddPath(final AfiSafi afiSafi, final BgpTableType tableType,
-            final Map<TablesKey, PathSelectionMode> multiPathTables) {
+        final Map<TablesKey, PathSelectionMode> multiPathTables) {
         final PathSelectionMode pathSelection = multiPathTables.get(new TablesKey(tableType.getAfi(), tableType.getSafi()));
         if (pathSelection == null) {
             return afiSafi;
@@ -178,27 +178,28 @@ public final class OpenConfigUtil {
             maxPaths = 0L;
         }
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2 addPath = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2Builder()
-        .setReceive(false)
-        .setSendMax(Shorts.checkedCast(maxPaths))
-        .build();
+            .setReceive(true)
+            .setSendMax(Shorts.checkedCast(maxPaths))
+            .build();
         return new AfiSafiBuilder(afiSafi)
-        .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2.class,
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2.class,
                 addPath).build();
     }
 
     public static AfiSafi toNeighborAfiSafiAddPath(final AfiSafi afiSafi, final BgpTableType tableType, final List<AddressFamilies> capabilities) {
-        final Optional<AddressFamilies> capability = Iterables.tryFind(capabilities, af -> af.getAfi().equals(tableType.getAfi()) && af.getSafi().equals(tableType.getSafi()));
+        final Optional<AddressFamilies> capability = Iterables.tryFind(capabilities,
+            af -> af.getAfi().equals(tableType.getAfi()) && af.getSafi().equals(tableType.getSafi()));
         if (!capability.isPresent()) {
             return afiSafi;
         }
         return new AfiSafiBuilder(afiSafi)
-        .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
                 fromSendReceiveMode(capability.get().getSendReceive())).build();
     }
 
     private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1 fromSendReceiveMode(final SendReceive mode) {
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder builder =
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder();
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder();
         switch (mode) {
         case Both:
             builder.setReceive(true).setSendMax((short) 0);
@@ -241,6 +242,21 @@ public final class OpenConfigUtil {
         return PeerRole.Ibgp;
     }
 
+    public static PeerType toPeerType(final PeerRole peerRole) {
+        switch (peerRole) {
+        case Ibgp:
+        case RrClient:
+            return PeerType.INTERNAL;
+        case Ebgp:
+            return PeerType.EXTERNAL;
+        case Internal:
+            break;
+        default:
+            break;
+        }
+        return null;
+    }
+
     private static boolean isRrClient(final Neighbor neighbor) {
         final RouteReflector routeReflector = neighbor.getRouteReflector();
         if (routeReflector != null && routeReflector.getConfig() != null) {
diff --git a/bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/BGPOpenConfigMappingServiceImplTest.java b/bgp/openconfig-impl/src/test/java/org/opendaylight/protocol/bgp/openconfig/impl/BGPOpenConfigMappingServiceImplTest.java
new file mode 100644 (file)
index 0000000..a125cf8
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+ * 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.openconfig.impl;
+
+import static junit.framework.TestCase.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.APPLICATION_PEER_GROUP_NAME;
+
+import com.google.common.primitives.Shorts;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
+import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
+import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.AfiSafisBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.RouteReflectorBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.TimersBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.TransportBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.BgpBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.GlobalBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.NeighborsBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.PeerGroupsBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.CommunityType;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.PeerType;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
+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.openconfig.extensions.rev160614.AfiSafi1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.IPV6FLOW;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
+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.UnicastSubsequentAddressFamily;
+
+public class BGPOpenConfigMappingServiceImplTest {
+    private static final Long ALL_PATHS = 0L;
+    private static final Long N_PATHS = 2L;
+    private static final PathSelectionMode ADD_PATH_BEST_N_PATH_SELECTION = new AddPathBestNPathSelection(N_PATHS);
+    private static final PathSelectionMode ADD_PATH_BEST_ALL_PATH_SELECTION = new AllPathSelection();
+    private static final BGPOpenConfigMappingServiceImpl OPENCONFIG = new BGPOpenConfigMappingServiceImpl();
+    private static final AsNumber AS = new AsNumber(72L);
+    private static final IpAddress IPADDRESS = new IpAddress(new Ipv4Address("127.0.0.1"));
+    private static final BgpId BGP_ID = new BgpId(IPADDRESS.getIpv4Address());
+    private static final RibId RIB_ID = new RibId("bgp");
+    private static final List<AddressFamilies> FAMILIES;
+    private static final List<BgpTableType> TABLE_TYPES;
+    private static final List<AfiSafi> AFISAFIS = new ArrayList<>();
+    private static final BigDecimal DEFAULT_TIMERS = BigDecimal.valueOf(30);
+    private static final PortNumber PORT_NUMBER = new PortNumber(179);
+
+    static {
+        FAMILIES = new ArrayList<>();
+        FAMILIES.add(new AddressFamiliesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+            .setSendReceive(SendReceive.Both).build());
+        FAMILIES.add(new AddressFamiliesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+            .setSendReceive(SendReceive.Send).build());
+        FAMILIES.add(new AddressFamiliesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(FlowspecSubsequentAddressFamily.class)
+            .setSendReceive(SendReceive.Receive).build());
+        TABLE_TYPES = new ArrayList<>();
+        TABLE_TYPES.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+        TABLE_TYPES.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
+        AFISAFIS.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+            .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true).setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
+        AFISAFIS.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+            .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+    }
+
+    @Test
+    public void toTableTypes() {
+        final List<AfiSafi> families = new ArrayList<>();
+        families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).build());
+        families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class).build());
+        final List<BgpTableType> result = OPENCONFIG.toTableTypes(families);
+        assertEquals(TABLE_TYPES, result);
+    }
+
+    @Test
+    public void toPathSelectionMode() {
+        final List<AfiSafi> families = new ArrayList<>();
+        families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+            .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
+        families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+            .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+        final Map<BgpTableType, PathSelectionMode> result = OPENCONFIG.toPathSelectionMode(families);
+        final Map<BgpTableType, PathSelectionMode> expected = new HashMap<>();
+        expected.put(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_N_PATH_SELECTION);
+        expected.put(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_ALL_PATH_SELECTION);
+        assertEquals(expected.get(0), result.get(0));
+        assertEquals(expected.get(1), result.get(1));
+    }
+
+    @Test
+    public void isApplicationPeer() {
+        assertFalse(OPENCONFIG.isApplicationPeer(new NeighborBuilder().setConfig(new ConfigBuilder().build()).build()));
+        final Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder()
+            .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build())
+            .build()).build();
+        assertTrue(OPENCONFIG.isApplicationPeer(neighbor));
+    }
+
+    @Test
+    public void toPeerRole() {
+        Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().setPeerType(PeerType.EXTERNAL).build()).build();
+        PeerRole peerRoleResult = OPENCONFIG.toPeerRole(neighbor);
+        Assert.assertEquals(PeerRole.Ebgp, peerRoleResult);
+
+        neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().setPeerType(PeerType.INTERNAL).build()).build();
+        peerRoleResult = OPENCONFIG.toPeerRole(neighbor);
+        Assert.assertEquals(PeerRole.Ibgp, peerRoleResult);
+
+        neighbor = new NeighborBuilder()
+            .setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
+                .neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(true).build()).build()).build();
+        peerRoleResult = OPENCONFIG.toPeerRole(neighbor);
+        Assert.assertEquals(PeerRole.RrClient, peerRoleResult);
+    }
+
+    @Test
+    public void toAddPathCapability() {
+        final List<AfiSafi> families = new ArrayList<>();
+        families.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+                    .setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+        families.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+                    .setReceive(false).setSendMax(Shorts.checkedCast(N_PATHS)).build()).build());
+        families.add(new AfiSafiBuilder().setAfiSafiName(IPV6FLOW.class)
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+                    .setReceive(false).build()).build());
+        final List<AddressFamilies> result = OPENCONFIG.toAddPathCapability(families);
+        assertEquals(FAMILIES, result);
+    }
+
+    @Test
+    public void toSendReceiveMode() {
+        final Map<TablesKey, PathSelectionMode> bgpTableKeyPsm = new HashMap<>();
+        bgpTableKeyPsm.put(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_N_PATH_SELECTION);
+        bgpTableKeyPsm.put(new TablesKey(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class), ADD_PATH_BEST_ALL_PATH_SELECTION);
+
+        final Protocol result = OPENCONFIG.fromRib(BGP_ID, new ClusterIdentifier("192.168.1.2"), RIB_ID, AS, TABLE_TYPES, bgpTableKeyPsm);
+        final Bgp globalBgp = new BgpBuilder()
+            .setGlobal(new GlobalBuilder()
+                .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS).build())
+                .setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base
+                    .ConfigBuilder()
+                    .setAs(AS).setRouterId(BGP_ID).build()).build())
+            .setPeerGroups(new PeerGroupsBuilder().setPeerGroup(Collections.singletonList(new PeerGroupBuilder().setPeerGroupName("application-peers").build())).build())
+            .setNeighbors(new NeighborsBuilder().build())
+            .build();
+        final Protocol expected = new ProtocolBuilder()
+            .setKey(new ProtocolKey(BGP.class, RIB_ID.getValue())).addAugmentation(Protocol1.class, new Protocol1Builder().setBgp(globalBgp).build()).build();
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void fromBgpPeer() {
+        final Neighbor result = OPENCONFIG.fromBgpPeer(FAMILIES, TABLE_TYPES, 30, IPADDRESS, true, null, PORT_NUMBER, 30, AS, PeerRole.Ibgp, null);
+        final List<AfiSafi> afisafis = new ArrayList<>();
+        afisafis.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+            .addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+        afisafis.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+            .addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(false).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+        final Neighbor expected = new NeighborBuilder()
+            .setAfiSafis(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder().setAfiSafi(afisafis).build())
+            .setConfig(new ConfigBuilder().setPeerAs(AS).setPeerType(PeerType.INTERNAL).setRouteFlapDamping(false).setSendCommunity(CommunityType.NONE).build())
+            .setNeighborAddress(IPADDRESS)
+            .setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
+                .neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(false).build()).build())
+            .setTimers(new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
+                .timers.ConfigBuilder().setHoldTime(DEFAULT_TIMERS).setMinimumAdvertisementInterval(DEFAULT_TIMERS)
+                .setKeepaliveInterval(DEFAULT_TIMERS).setConnectRetry(DEFAULT_TIMERS).build()).build())
+            .setTransport(new TransportBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor
+                .group.transport.ConfigBuilder().setMtuDiscovery(false).setPassiveMode(false).addAugmentation(Config1.class, new Config1Builder()
+                .setRemotePort(new PortNumber(179)).build()).build()).build())
+            .build();
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void fromApplicationPeer() {
+        final ApplicationRibId app = new ApplicationRibId("app");
+        final Neighbor result = OPENCONFIG.fromApplicationPeer(app, BGP_ID);
+        final Neighbor expected = new NeighborBuilder().setConfig(new ConfigBuilder().setDescription(app.getValue())
+            .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build()).build())
+            .setNeighborAddress(IPADDRESS).build();
+        assertEquals(expected, result);
+    }
+}
\ No newline at end of file
index 9e7addb9fdaa10e570a7094fa8160cb01e9eed2e..83df5d09e05bf835e536d1502750aba6956db01d 100644 (file)
@@ -8,18 +8,22 @@
 
 package org.opendaylight.protocol.bgp.openconfig.impl.util;
 
+import static junit.framework.TestCase.assertFalse;
 import static org.junit.Assert.assertEquals;
-import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.getModuleName;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.APPLICATION_PEER_GROUP_NAME;
 import static org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.toAfiSafi;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
+import com.google.common.primitives.Shorts;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Collections;
 import java.util.List;
 import org.junit.Assert;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
 import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
@@ -28,35 +32,49 @@ import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.r
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.use.multiple.paths.UseMultiplePaths;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.AfiSafi1;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.AfiSafi2;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.RouteReflectorBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.PeerType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.L2vpnAddressFamily;
 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.AddressFamiliesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 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.UnicastSubsequentAddressFamily;
 
 public class OpenConfigUtilTest {
-
+    private static final Long ALL_PATHS = 0L;
+    private static final Long N_PATHS = 2L;
+    private static final PathSelectionMode ADD_PATH_BEST_N_PATH_SELECTION = new AddPathBestNPathSelection(N_PATHS);
+    private static final PathSelectionMode ADD_PATH_BEST_ALL_PATH_SELECTION = new AllPathSelection();
     private static final BgpTableType BGP_TABLE_TYPE_IPV4 = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+    private static final BgpTableType BGP_TABLE_TYPE_IPV6 = new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
     private static final AfiSafi AFISAFI_IPV4 = new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).build();
     private static final String TEST = "/modules/module[type='dom-concurrent-data-broker'][name='concurrent-data-broker']";
+    private static final TablesKey K4 = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
 
     @Test
-    public void test() {
-        final String moduleName = getModuleName(TEST);
-        assertEquals("concurrent-data-broker", moduleName);
-    }
-
-    @Test
-    public void testGetModuleType() {
-        final String moduleType = OpenConfigUtil.getModuleType(TEST);
-        assertEquals("dom-concurrent-data-broker", moduleType);
+    public void testToAfiSafi() {
+        assertEquals(AFISAFI_IPV4, toAfiSafi(BGP_TABLE_TYPE_IPV4).get());
+        assertEquals(Optional.absent(), toAfiSafi(new BgpTableTypeImpl(L2vpnAddressFamily.class, UnicastSubsequentAddressFamily.class)));
     }
 
     @Test
-    public void testToAfiSafi() {
-        assertEquals(toAfiSafi(BGP_TABLE_TYPE_IPV4).get(), AFISAFI_IPV4);
+    public void isAppNeighbor() {
+        assertFalse(OpenConfigUtil.isAppNeighbor(new NeighborBuilder().setConfig(new ConfigBuilder().build()).build()));
+        final Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder()
+            .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build())
+            .build()).build();
+        assertTrue(OpenConfigUtil.isAppNeighbor(neighbor));
     }
 
     @Test
@@ -72,42 +90,84 @@ public class OpenConfigUtilTest {
     }
 
     @Test
-    public void toNeigborAfiSafiMultiPathMatch() {
-        final AfiSafi afiSafi = OpenConfigUtil.toNeigborAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
-            Lists.newArrayList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV4).setSendReceive(SendReceive.Both).build()));
-        Assert.assertTrue(afiSafi.getAugmentation(AfiSafi2.class).getUseMultiplePaths().getConfig().isEnabled());
+    public void toPeerRole() {
+        Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().setPeerType(PeerType.EXTERNAL).build()).build();
+        PeerRole peerRoleResult = OpenConfigUtil.toPeerRole(neighbor);
+        Assert.assertEquals(PeerRole.Ebgp, peerRoleResult);
+
+        neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().setPeerType(PeerType.INTERNAL).build()).build();
+        peerRoleResult = OpenConfigUtil.toPeerRole(neighbor);
+        Assert.assertEquals(PeerRole.Ibgp, peerRoleResult);
+
+        neighbor = new NeighborBuilder()
+            .setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
+                .neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(true).build()).build()).build();
+        peerRoleResult = OpenConfigUtil.toPeerRole(neighbor);
+        Assert.assertEquals(PeerRole.RrClient, peerRoleResult);
     }
 
     @Test
-    public void toNeigborAfiSafiMultiPathNoMatch() {
-        final AfiSafi afiSafi = OpenConfigUtil.toNeigborAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyList());
-        Assert.assertEquals(AFISAFI_IPV4, afiSafi);
+    public void toPeerType() {
+        Assert.assertEquals(PeerType.EXTERNAL, OpenConfigUtil.toPeerType(PeerRole.Ebgp));
+        Assert.assertEquals(PeerType.INTERNAL, OpenConfigUtil.toPeerType(PeerRole.Ibgp));
+        Assert.assertNull(OpenConfigUtil.toPeerType(PeerRole.Internal));
+        Assert.assertEquals(PeerType.INTERNAL, OpenConfigUtil.toPeerType(PeerRole.RrClient));
     }
 
     @Test
-    public void toGlobalAfiSafiMultiPathNPaths() {
-        final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
-            Collections.singletonMap(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), new AddPathBestNPathSelection(5L)));
-        final UseMultiplePaths multiplePaths = afiSafi.getAugmentation(AfiSafi1.class).getUseMultiplePaths();
-        Assert.assertTrue(multiplePaths.getConfig().isEnabled());
-        Assert.assertEquals(5, multiplePaths.getIbgp().getConfig().getMaximumPaths().intValue());
-        Assert.assertEquals(5, multiplePaths.getEbgp().getConfig().getMaximumPaths().intValue());
-    }
+    public void toNeighborAfiSafiAddPath() {
+        final AfiSafi afiSafi = OpenConfigUtil.toNeighborAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyList());
+        Assert.assertEquals(AFISAFI_IPV4, afiSafi);
 
-    @Test
-    public void toGlobalAfiSafiMultiPathAllPaths() {
-        final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
-            Collections.singletonMap(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class), new AllPathSelection()));
-        final UseMultiplePaths multiplePaths = afiSafi.getAugmentation(AfiSafi1.class).getUseMultiplePaths();
-        Assert.assertTrue(multiplePaths.getConfig().isEnabled());
-        Assert.assertNull(multiplePaths.getIbgp());
-        Assert.assertNull(multiplePaths.getEbgp());
+        final AfiSafi afisafiIpv6Both = new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+                    .setSendMax(Shorts.checkedCast(ALL_PATHS)).setReceive(true).build()).build();
+        final AfiSafi afiSafi6 = OpenConfigUtil.toNeighborAfiSafiAddPath(afisafiIpv6Both, BGP_TABLE_TYPE_IPV6,
+            Collections.singletonList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV6).setSendReceive(SendReceive.Both).build()));
+        Assert.assertEquals(afisafiIpv6Both, afiSafi6);
+
+        final AfiSafi afisafiIpv6ReceiveExpected = new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+                    .setReceive(true).build()).build();
+        final AfiSafi afiSafi6ReceiveResult = OpenConfigUtil.toNeighborAfiSafiAddPath(afisafiIpv6ReceiveExpected, BGP_TABLE_TYPE_IPV6,
+            Collections.singletonList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV6).setSendReceive(SendReceive.Receive).build()));
+        Assert.assertEquals(afisafiIpv6ReceiveExpected, afiSafi6ReceiveResult);
+
+        final AfiSafi afisafiIpv6SendExpected = new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1.class,
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi1Builder()
+                    .setSendMax(Shorts.checkedCast(ALL_PATHS)).setReceive(false).build()).build();
+        final AfiSafi afiSafi6SendResult = OpenConfigUtil.toNeighborAfiSafiAddPath(afisafiIpv6ReceiveExpected, BGP_TABLE_TYPE_IPV6,
+            Collections.singletonList(new AddressFamiliesBuilder(BGP_TABLE_TYPE_IPV6).setSendReceive(SendReceive.Send).build()));
+        Assert.assertEquals(afisafiIpv6SendExpected, afiSafi6SendResult);
     }
 
     @Test
-    public void toGlobalAfiSafiMultiPathNoMatch() {
-        final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiMultiPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyMap());
+    public void toGlobalAfiSafiAddPath() {
+        final AfiSafi afiSafi = OpenConfigUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.emptyMap());
         Assert.assertEquals(AFISAFI_IPV4, afiSafi);
+
+        final AfiSafi afiSafiResult = OpenConfigUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4, Collections.singletonMap(K4,
+            ADD_PATH_BEST_N_PATH_SELECTION));
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2 addPath =
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2Builder()
+                .setSendMax(Shorts.checkedCast(N_PATHS)).setReceive(true).build();
+        final AfiSafi afisafiIpv4Psm2 = new AfiSafiBuilder(afiSafi)
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2.class,
+                addPath).build();
+        Assert.assertEquals(afisafiIpv4Psm2, afiSafiResult);
+
+        final AfiSafi afiSafiAllResult = OpenConfigUtil.toGlobalAfiSafiAddPath(AFISAFI_IPV4, BGP_TABLE_TYPE_IPV4,
+            Collections.singletonMap(K4, ADD_PATH_BEST_ALL_PATH_SELECTION));
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2 addPathAll =
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2Builder()
+                .setSendMax(Shorts.checkedCast(ALL_PATHS)).setReceive(true).build();
+        final AfiSafi afiAll = new AfiSafiBuilder(afiSafi)
+            .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.AfiSafi2.class,
+                addPathAll).build();
+        Assert.assertEquals(afiAll, afiSafiAllResult);
     }
 
     @Test(expected = UnsupportedOperationException.class)
index d082574606bb17ac65d039d3d30df86e941034cb..da6e9eac59671e4a34b2d3a23ae0b263aa3e1366 100644 (file)
@@ -9,21 +9,15 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
-import static org.opendaylight.protocol.bgp.rib.spi.RouterIds.createPeerId;
 
 import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.net.InetAddresses;
 import io.netty.bootstrap.Bootstrap;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelOption;
-import io.netty.channel.SimpleChannelInboundHandler;
 import io.netty.channel.epoll.Epoll;
 import io.netty.channel.epoll.EpollEventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
@@ -55,7 +49,6 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
-import org.opendaylight.protocol.concepts.KeyMapping;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -95,7 +88,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
@@ -114,44 +106,35 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class AbstractAddPathTest extends AbstractDataBrokerTest {
+class AbstractAddPathTest extends AbstractDataBrokerTest {
 
     protected static final String RIB_ID = "127.0.0.1";
-    private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier(RIB_ID);
     protected static final Ipv4Address PEER1 = new Ipv4Address("127.0.0.2");
     protected static final Ipv4Address PEER2 = new Ipv4Address("127.0.0.3");
     protected static final Ipv4Address PEER3 = new Ipv4Address("127.0.0.4");
     protected static final Ipv4Address PEER4 = new Ipv4Address("127.0.0.5");
     protected static final Ipv4Address PEER5 = new Ipv4Address("127.0.0.6");
-
-    protected static final PeerId PEER1_ID = createPeerId(PEER1);
-    protected static final PeerId PEER2_ID = createPeerId(PEER2);
-    protected static final PeerId PEER3_ID = createPeerId(PEER3);
-    protected static final PeerId PEER4_ID = createPeerId(PEER4);
-    protected static final PeerId PEER5_ID = createPeerId(PEER5);
-
     protected static final AsNumber AS_NUMBER = new AsNumber(72L);
-    protected static final int HOLDTIMER = 180;
-
     protected static final int PORT = InetSocketAddressUtil.getRandomPort();
-
     protected static final Ipv4Prefix PREFIX1 = new Ipv4Prefix("1.1.1.1/32");
-    protected static final Ipv4Address NH1 = new Ipv4Address("2.2.2.2");
-    protected static final Update UPD_100 = createSimpleUpdate(PREFIX1, new PathId(1l), CLUSTER_ID, 100);
-    protected static final Update UPD_50 = createSimpleUpdate(PREFIX1, new PathId(2l), CLUSTER_ID, 50);
-    protected static final Update UPD_200 = createSimpleUpdate(PREFIX1, new PathId(3l), CLUSTER_ID, 200);
-    protected static final Update UPD_20 = createSimpleUpdate(PREFIX1, new PathId(1l), CLUSTER_ID, 20);
+    private static final int HOLDTIMER = 180;
+    private static final Ipv4Address NH1 = new Ipv4Address("2.2.2.2");
+    private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier(RIB_ID);
+    protected static final Update UPD_100 = createSimpleUpdate(PREFIX1, new PathId(1L), CLUSTER_ID, 100);
+    protected static final Update UPD_50 = createSimpleUpdate(PREFIX1, new PathId(2L), CLUSTER_ID, 50);
+    protected static final Update UPD_200 = createSimpleUpdate(PREFIX1, new PathId(3L), CLUSTER_ID, 200);
+    protected static final Update UPD_20 = createSimpleUpdate(PREFIX1, new PathId(1L), CLUSTER_ID, 20);
 
     protected BindingToNormalizedNodeCodec mappingService;
     protected BGPDispatcherImpl dispatcher;
     protected RIBExtensionProviderContext ribExtension;
     protected BGPExtensionProviderContext context;
     protected SchemaContext schemaContext;
+    protected ClusterSingletonServiceProvider clusterSingletonServiceProvider;
     private RIBActivator ribActivator;
     private BGPActivator bgpActivator;
     private NioEventLoopGroup worker;
     private NioEventLoopGroup boss;
-    protected ClusterSingletonServiceProvider clusterSingletonServiceProvider;
     private org.opendaylight.protocol.bgp.inet.BGPActivator inetActivator;
 
     @Before
@@ -168,7 +151,7 @@ public class AbstractAddPathTest extends AbstractDataBrokerTest {
         this.inetActivator.start(this.context);
 
         this.mappingService = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(),
-                new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
+            new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
         final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
         moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(BgpParameters.class));
         moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(MultiprotocolCapability.class));
@@ -199,32 +182,8 @@ public class AbstractAddPathTest extends AbstractDataBrokerTest {
         this.bgpActivator.close();
     }
 
-    void checkRibOut(final int nAddPathRoutesExpected) throws ExecutionException, InterruptedException {
-        final ReadOnlyTransaction rTx = getDataBroker().newReadOnlyTransaction();
-        final BgpRib bgpRib = rTx.read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(BgpRib.class)).get().get();
-        rTx.close();
-
-        //check peer's rib-out
-        for (final Peer peer : bgpRib.getRib().get(0).getPeer()) {
-            final int ribOut = getPeerRibOutSize(peer);
-            if (peer.getPeerId().equals(PEER1_ID)) {
-                Assert.assertEquals(0, ribOut);
-            } else if (peer.getPeerId().equals(PEER2_ID)) {
-                Assert.assertEquals(0, ribOut);
-            } else if (peer.getPeerId().equals(PEER3_ID)) {
-                Assert.assertEquals(0, ribOut);
-            } else if (peer.getPeerId().equals(PEER4_ID)) {
-                Assert.assertEquals(1, ribOut);
-            } else if (peer.getPeerId().equals(PEER5_ID)) {
-                Assert.assertEquals(nAddPathRoutesExpected, ribOut);
-            } else {
-                Assert.fail("Failed to verify " + peer);
-            }
-        }
-    }
-
     void sendRouteAndCheckIsOnDS(final Channel session, final Ipv4Prefix prefix, final long localPreference, final int expectedRoutesOnDS)
-            throws InterruptedException, ExecutionException {
+        throws InterruptedException, ExecutionException {
         session.writeAndFlush(createSimpleUpdate(prefix, null, null, localPreference));
         Thread.sleep(2000);
 
@@ -247,9 +206,9 @@ public class AbstractAddPathTest extends AbstractDataBrokerTest {
     }
 
     Channel createPeerSession(final Ipv4Address peer, final PeerRole peerRole, final BgpParameters nonAddPathParams, final RIBImpl ribImpl,
-            final BGPHandlerFactory hf, final SimpleSessionListener sessionListsner) throws InterruptedException, ExecutionException {
+        final BGPHandlerFactory hf, final SimpleSessionListener sessionListsner) throws InterruptedException, ExecutionException {
         configurePeer(peer, ribImpl, nonAddPathParams, peerRole);
-        return connectPeer(peer, ribImpl, nonAddPathParams, this.dispatcher, hf, sessionListsner);
+        return connectPeer(peer, nonAddPathParams, this.dispatcher, hf, sessionListsner);
     }
 
     private static int getPeerRibOutSize(final Peer peer) {
@@ -257,10 +216,10 @@ public class AbstractAddPathTest extends AbstractDataBrokerTest {
     }
 
     private static ChannelFuture createClient(final BGPDispatcherImpl dispatcher, final InetSocketAddress remoteAddress,
-            final BGPPeerRegistry registry, final InetSocketAddress localAddress, final BGPHandlerFactory hf) throws InterruptedException {
+        final BGPPeerRegistry registry, final InetSocketAddress localAddress, final BGPHandlerFactory hf) throws InterruptedException {
         final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(registry);
 
-        final Bootstrap bootstrap = dispatcher.createClientBootStrap(Optional.<KeyMapping>absent(), Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup());
+        final Bootstrap bootstrap = dispatcher.createClientBootStrap(Optional.absent(), Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup());
         bootstrap.localAddress(localAddress);
         bootstrap.option(ChannelOption.SO_REUSEADDR, true);
         bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@@ -280,17 +239,17 @@ public class AbstractAddPathTest extends AbstractDataBrokerTest {
         final BGPPeer bgpPeer = new BGPPeer(inetAddress.getHostAddress(), ribImpl, peerRole, null);
         final List<BgpParameters> tlvs = Lists.newArrayList(bgpParameters);
         StrictBGPPeerRegistry.GLOBAL.addPeer(new IpAddress(new Ipv4Address(inetAddress.getHostAddress())), bgpPeer,
-                new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID),
-                        AS_NUMBER,  tlvs, Optional.<byte[]>absent()));
+            new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID),
+                AS_NUMBER, tlvs, Optional.absent()));
         bgpPeer.instantiateServiceInstance();
     }
 
-    private static Channel connectPeer(final Ipv4Address localAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters,
-            final BGPDispatcherImpl dispatcherImpl, final BGPHandlerFactory hf, final BGPSessionListener sessionListsner) throws InterruptedException, ExecutionException {
+    private static Channel connectPeer(final Ipv4Address localAddress, final BgpParameters bgpParameters,
+        final BGPDispatcherImpl dispatcherImpl, final BGPHandlerFactory hf, final BGPSessionListener sessionListsner) throws InterruptedException {
         final BGPPeerRegistry peerRegistry = new StrictBGPPeerRegistry();
         peerRegistry.addPeer(new IpAddress(new Ipv4Address(RIB_ID)), sessionListsner,
-                new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(localAddress),
-                        AS_NUMBER, Lists.newArrayList(bgpParameters),Optional.<byte[]>absent()));
+            new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(localAddress),
+                AS_NUMBER, Lists.newArrayList(bgpParameters), Optional.absent()));
 
         final ChannelFuture createClient = createClient(dispatcherImpl, new InetSocketAddress(RIB_ID, PORT), peerRegistry, new InetSocketAddress(localAddress.getValue(), PORT), hf);
         Thread.sleep(1000);
@@ -299,30 +258,30 @@ public class AbstractAddPathTest extends AbstractDataBrokerTest {
 
     protected static BgpParameters createParameter(final boolean addPath) {
         final OptionalCapabilities mp = new OptionalCapabilitiesBuilder().setCParameters(
-                new CParametersBuilder().addAugmentation(CParameters1.class,
-                        new CParameters1Builder().setMultiprotocolCapability(
-                                new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
-                                .build()).build()).build()).build();
+            new CParametersBuilder().addAugmentation(CParameters1.class,
+                new CParameters1Builder().setMultiprotocolCapability(
+                    new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+                        .build()).build()).build()).build();
         final List<OptionalCapabilities> capabilities = Lists.newArrayList(mp);
         if (addPath) {
             final OptionalCapabilities addPathCapa = new OptionalCapabilitiesBuilder().setCParameters(
-                    new CParametersBuilder().addAugmentation(CParameters1.class,
-                            new CParameters1Builder().setAddPathCapability(
-                                    new AddPathCapabilityBuilder().setAddressFamilies(Lists.newArrayList(
-                                            new AddressFamiliesBuilder()
-                                            .setAfi(Ipv4AddressFamily.class)
-                                            .setSafi(UnicastSubsequentAddressFamily.class)
-                                            .setSendReceive(SendReceive.Both)
-                                            .build()))
-                                            .build()).build()).build()).build();
+                new CParametersBuilder().addAugmentation(CParameters1.class,
+                    new CParameters1Builder().setAddPathCapability(
+                        new AddPathCapabilityBuilder().setAddressFamilies(Lists.newArrayList(
+                            new AddressFamiliesBuilder()
+                                .setAfi(Ipv4AddressFamily.class)
+                                .setSafi(UnicastSubsequentAddressFamily.class)
+                                .setSendReceive(SendReceive.Both)
+                                .build()))
+                            .build()).build()).build()).build();
             capabilities.add(addPathCapa);
         }
         return new BgpParametersBuilder().setOptionalCapabilities(capabilities).build();
     }
 
     private static Update createSimpleUpdate(final Ipv4Prefix prefix, final PathId pathId, final ClusterIdentifier clusterId,
-            final long localPreference) {
-     final AttributesBuilder attBuilder = new AttributesBuilder();
+        final long localPreference) {
+        final AttributesBuilder attBuilder = new AttributesBuilder();
         attBuilder.setLocalPref(new LocalPrefBuilder().setPref(localPreference).build());
         attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
         attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
@@ -332,17 +291,17 @@ public class AbstractAddPathTest extends AbstractDataBrokerTest {
         }
         attBuilder.setUnrecognizedAttributes(Collections.emptyList());
         attBuilder.addAugmentation(Attributes1.class,
-                new Attributes1Builder().setMpReachNlri(
-                        new MpReachNlriBuilder()
-                        .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1).build()).build())
-                        .setAfi(Ipv4AddressFamily.class)
-                        .setSafi(UnicastSubsequentAddressFamily.class)
-                        .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
-                                new DestinationIpv4CaseBuilder().setDestinationIpv4(
-                                        new DestinationIpv4Builder().setIpv4Prefixes(Collections.singletonList(
-                                                new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build())).build())
-                                                .build()).build())
-                                                .build()).build());
+            new Attributes1Builder().setMpReachNlri(
+                new MpReachNlriBuilder()
+                    .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1).build()).build())
+                    .setAfi(Ipv4AddressFamily.class)
+                    .setSafi(UnicastSubsequentAddressFamily.class)
+                    .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+                        new DestinationIpv4CaseBuilder().setDestinationIpv4(
+                            new DestinationIpv4Builder().setIpv4Prefixes(Collections.singletonList(
+                                new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build())).build())
+                            .build()).build())
+                    .build()).build());
         return new UpdateBuilder().setAttributes(attBuilder.build()).build();
     }
 }
index af9195bd671d06d0b2af2293979116387c363553..d543b9875b176a6f598243fa78f142f7a99b3408 100644 (file)
@@ -20,7 +20,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum
 
 public final class IdentifierUtils {
     private static final Predicate<PathArgument> IS_PEER = input -> input instanceof NodeIdentifierWithPredicates && Peer.QNAME.equals(input.getNodeType());
-    private static final Predicate<PathArgument> IS_TABLES = input -> Tables.QNAME.equals(input.getNodeType());
+    private static final Predicate<PathArgument> IS_TABLES = input -> input instanceof NodeIdentifierWithPredicates && Tables.QNAME.equals(input.getNodeType());
     private static final QName PEER_ID = QName.create(Peer.QNAME, "peer-id").intern();
 
     private IdentifierUtils() {
index 3cf305ece593f14d794ab3824bbd2cebe990c1c5..9939a17062ea4ae38639a240c29c4ea01e9a605a 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.protocol.bgp.rib.spi;
 
+import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableMap;
 import javax.annotation.Nonnull;
 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
@@ -25,6 +26,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 /**
  * Implements common methods for Advertisement of Multiple Paths on ribSupport
  */
+@Beta
 public abstract class MultiPathAbstractRIBSupport extends AbstractRIBSupport {
     private final QName routeKeyQname;
     private final QName pathIdQname;
@@ -53,7 +55,7 @@ public abstract class MultiPathAbstractRIBSupport extends AbstractRIBSupport {
         this.pathIdNid = new NodeIdentifier(this.pathIdQname);
     }
 
-    public final NodeIdentifier routePathIdNid() {
+    protected final NodeIdentifier routePathIdNid() {
         return this.pathIdNid;
     }
 
index 4a0329a0ec42dfced97df6c2351c5534336b5243..732320dae9aa292b56f2996a0e487123f9bf9277 100644 (file)
@@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author Thomas Pantelis
  */
-public class SimpleRIBExtensionProviderContextActivator implements AutoCloseable {
+public final class SimpleRIBExtensionProviderContextActivator implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(SimpleRIBExtensionProviderContextActivator.class);
 
     private final RIBExtensionProviderContext providerContext;
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupportTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupportTest.java
new file mode 100644 (file)
index 0000000..fa406d5
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.rib.spi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+
+public class AddPathRibSupportTest {
+
+    private static final NodeIdentifier QNAME = new NodeIdentifier(QName.create("test").intern());
+    private static class AddPathRibSupportLocalTest implements AddPathRibSupport{}
+
+    @Test
+    public void defaultAddPathRibSupport() {
+        final AddPathRibSupportLocalTest test = new AddPathRibSupportLocalTest();
+        assertEquals((Long) NON_PATH_ID, test.extractPathId(null));
+        assertNull(test.getRouteIdAddPath(NON_PATH_ID, null));
+        assertEquals(QNAME, test.createRouteKeyPathArgument(QNAME));
+    }
+}
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/IdentifierUtilsTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/IdentifierUtilsTest.java
new file mode 100644 (file)
index 0000000..ebde8f0
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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.rib.spi;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.ImmutableMap;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.LocRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+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.UnicastSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+
+public class IdentifierUtilsTest {
+    private static final QName PEER_ID_QNAME = QName.create(Peer.QNAME, "peer-id").intern();
+    private static final QName TABLES_KEY_QNAME = QName.create(Tables.QNAME, "tables-key").intern();
+    private static final TablesKey TK = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+    private static final PeerId PEER_ID = new PeerId("127.0.0.1");
+    private static final NodeIdentifierWithPredicates NIWP_PEER = new NodeIdentifierWithPredicates(Peer.QNAME, ImmutableMap.of(PEER_ID_QNAME, PEER_ID.getValue()));
+    private static final NodeIdentifierWithPredicates NIWP_TABLE = new NodeIdentifierWithPredicates(Tables.QNAME, ImmutableMap.of(TABLES_KEY_QNAME, TK));
+    private static final YangInstanceIdentifier YII_PEER;
+    private static final YangInstanceIdentifier YII_TABLE;
+
+    static {
+        YII_PEER = YangInstanceIdentifier.builder().node(BgpRib.QNAME).node(Peer.QNAME).nodeWithKey(Peer.QNAME, PEER_ID_QNAME, PEER_ID.getValue()).build();
+        YII_TABLE = YangInstanceIdentifier.builder().node(LocRib.QNAME).node(Tables.QNAME).nodeWithKey(Tables.QNAME, TABLES_KEY_QNAME, TK).build();
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testPrivateConstructor() throws Throwable {
+        final Constructor<IdentifierUtils> c = IdentifierUtils.class.getDeclaredConstructor();
+        c.setAccessible(true);
+        try {
+            c.newInstance();
+        } catch (final InvocationTargetException e) {
+            throw e.getCause();
+        }
+    }
+
+    @Test
+    public void testPeerPath() throws Exception {
+        final YangInstanceIdentifier result = IdentifierUtils.peerPath(YII_PEER);
+        assertEquals(YII_PEER, result);
+    }
+
+    @Test
+    public void testPeerKey() throws Exception {
+        final NodeIdentifierWithPredicates result = IdentifierUtils.peerKey(YII_PEER);
+        assertEquals(NIWP_PEER, result);
+    }
+
+    @Test
+    public void testPeerId() throws Exception {
+        final PeerId result = IdentifierUtils.peerId(NIWP_PEER);
+        assertEquals(PEER_ID, result);
+    }
+
+    @Test
+    public void testPeerKeyToPeerId() throws Exception {
+        final PeerId result = IdentifierUtils.peerKeyToPeerId(YII_PEER);
+        assertEquals(PEER_ID, result);
+    }
+
+    @Test
+    public void testTableKey() throws Exception {
+        final NodeIdentifierWithPredicates result = IdentifierUtils.tableKey(YII_TABLE);
+        assertEquals(NIWP_TABLE, result);
+    }
+
+    @Test
+    public void testDomPeerId() throws Exception {
+        final NodeIdentifierWithPredicates result = IdentifierUtils.domPeerId(PEER_ID);
+        assertEquals(NIWP_PEER, result);
+    }
+
+}
\ No newline at end of file
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupportTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupportTest.java
new file mode 100644 (file)
index 0000000..bc48aa9
--- /dev/null
@@ -0,0 +1,291 @@
+/*
+ * 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.rib.spi;
+
+import static junit.framework.TestCase.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Prefixes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4RoutesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.MultiPathAbstractTest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.LocRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
+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.UnicastSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeSchemaAwareBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
+
+public class MultiPathAbstractRIBSupportTest {
+    private final static long PATH_ID = 0;
+    private final static String ROUTE_KEY = "prefix";
+    private static final String PREFIX = "1.2.3.4/32";
+    private static final QName PATH_ID_QNAME = QName.create(Ipv4Route.QNAME, "path-id").intern();
+    private static final QName PREFIX_QNAME = QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern();
+    private static final NodeIdentifierWithPredicates PREFIX_NII = new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
+        ImmutableMap.of(QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern(), PREFIX));
+    private static final MultiPathAbstractTest MULTI_PATH_ABSTRACT_TEST = new MultiPathAbstractTest();
+    private static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+    private static final YangInstanceIdentifier LOC_RIB_TARGET = YangInstanceIdentifier.create(YangInstanceIdentifier.of(BgpRib.QNAME)
+        .node(LocRib.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).getPathArguments());
+    private static final NodeIdentifier ROUTES_IDENTIFIER = new NodeIdentifier(Routes.QNAME);
+    private static final NodeIdentifier IPV4_ROUTES_IDENTIFIER = new NodeIdentifier(Ipv4Routes.QNAME);
+    private DataTreeCandidateNode emptyTree;
+    private DataTreeCandidateNode emptySubTree;
+    private DataTreeCandidateNode subTree;
+    private DOMDataWriteTransaction tx;
+    private ContainerNode nlri;
+    private Map<YangInstanceIdentifier, NormalizedNode<?, ?>> routes;
+    private ContainerNode attributes;
+    private MapEntryNode mapEntryNode;
+
+    @Before
+    public void setUp() {
+        this.routes = new HashMap<>();
+        MockitoAnnotations.initMocks(this);
+        this.emptyTree = Mockito.mock(DataTreeCandidateNode.class);
+        this.emptySubTree = Mockito.mock(DataTreeCandidateNode.class);
+        this.subTree = Mockito.mock(DataTreeCandidateNode.class);
+        final DataTreeCandidateNode emptyNode = Mockito.mock(DataTreeCandidateNode.class);
+        final DataTreeCandidateNode node = Mockito.mock(DataTreeCandidateNode.class);
+        doReturn(null).when(this.emptyTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
+
+        doReturn(emptyNode).when(this.emptySubTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
+        doReturn(null).when(emptyNode).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
+
+        doReturn(node).when(this.subTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
+        doReturn(node).when(node).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
+        final Collection<DataTreeCandidateNode> emptyCollection = new HashSet<>();
+        doReturn(emptyCollection).when(node).getChildNodes();
+
+        this.tx = Mockito.mock(DOMDataWriteTransaction.class);
+        this.nlri = Mockito.mock(ContainerNode.class);
+        this.attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME
+            .getLocalName().intern()))).build();
+        final ContainerNode destination = Mockito.mock(ContainerNode.class);
+        final ContainerNode route = Mockito.mock(ContainerNode.class);
+        final Optional optional = Mockito.mock(Optional.class);
+        final Optional destinationOptional = Mockito.mock(Optional.class);
+        final Optional destinationsOptional = Mockito.mock(Optional.class);
+        final ChoiceNode destinations = Mockito.mock(ChoiceNode.class);
+
+        doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(WithdrawnRoutes.QNAME));
+        doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(AdvertizedRoutes.QNAME));
+        doReturn(true).when(optional).isPresent();
+        doReturn(destination).when(optional).get();
+        doReturn(destinationOptional).when(destination).getChild(new NodeIdentifier(DestinationType.QNAME));
+        doReturn(true).when(destinationOptional).isPresent();
+        doReturn(destinations).when(destinationOptional).get();
+        doReturn(destinationsOptional).when(destinations).getChild(new NodeIdentifier(Ipv4Prefixes.QNAME));
+        doReturn(true).when(destinationsOptional).isPresent();
+        doReturn(route).when(destinationsOptional).get();
+        doReturn(emptyCollection).when(route).getValue();
+
+        doAnswer(invocation -> {
+            final Object[] args = invocation.getArguments();
+            MultiPathAbstractRIBSupportTest.this.routes.remove(args[1]);
+            return args[1];
+        }).when(this.tx).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(YangInstanceIdentifier.class));
+        doAnswer(invocation -> {
+            final Object[] args = invocation.getArguments();
+            final NormalizedNode<?, ?> node1 = (NormalizedNode<?, ?>) args[2];
+            MultiPathAbstractRIBSupportTest.this.routes.put((YangInstanceIdentifier) args[1], node1);
+            return args[1];
+        }).when(this.tx).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class));
+
+        this.mapEntryNode = Mockito.mock(MapEntryNode.class);
+    }
+
+    @Test
+    public void pathIdQName() {
+        final MultiPathAbstractTest multiPath = MULTI_PATH_ABSTRACT_TEST;
+        assertEquals(PATH_ID_QNAME, multiPath.pathIdQName());
+    }
+
+    @Test
+    public void extractPathId() {
+        final NodeIdentifier nii = new NodeIdentifier(PATH_ID_QNAME);
+        final ContainerNode cont = ImmutableContainerNodeSchemaAwareBuilder.create().withNodeIdentifier(nii).
+            addChild(new ImmutableLeafNodeBuilder<>().withNodeIdentifier(nii).withValue(PATH_ID).build()).build();
+        assertEquals((Long) PATH_ID, MULTI_PATH_ABSTRACT_TEST.extractPathId(cont));
+    }
+
+    @Test
+    public void getRouteIdAddPath() {
+        final NodeIdentifierWithPredicates routeIdPa =
+            new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(PATH_ID_QNAME, PATH_ID, PREFIX_QNAME, PREFIX));
+        assertEquals(routeIdPa, MULTI_PATH_ABSTRACT_TEST.getRouteIdAddPath(PATH_ID, PREFIX_NII));
+
+    }
+
+    @Test
+    public void createRouteKeyPathArgument() {
+        assertEquals(PREFIX_NII, MULTI_PATH_ABSTRACT_TEST.createRouteKeyPathArgument(PREFIX_NII));
+    }
+
+    @Test
+    public void routesCaseClass() throws Exception {
+        assertEquals(Ipv4RoutesCase.class, MULTI_PATH_ABSTRACT_TEST.routesCaseClass());
+    }
+
+    @Test
+    public void routesContainerClass() throws Exception {
+        assertEquals(Ipv4Routes.class, MULTI_PATH_ABSTRACT_TEST.routesContainerClass());
+    }
+
+    @Test
+    public void routesListClass() throws Exception {
+        assertEquals(Ipv4Route.class, MULTI_PATH_ABSTRACT_TEST.routesListClass());
+    }
+
+    @Test
+    public void routeQName() throws Exception {
+        assertEquals(Ipv4Route.QNAME, MULTI_PATH_ABSTRACT_TEST.routeQName());
+    }
+
+    @Test
+    public void emptyRoutes() throws Exception {
+        final ChoiceNode emptyRoutes = Builders.choiceBuilder().withNodeIdentifier(ROUTES_IDENTIFIER).addChild(Builders.containerBuilder()
+            .withNodeIdentifier(IPV4_ROUTES_IDENTIFIER).withChild(ImmutableNodes.mapNodeBuilder(MULTI_PATH_ABSTRACT_TEST.routeQName()
+            ).build()).build())
+            .build();
+        assertEquals(emptyRoutes, MULTI_PATH_ABSTRACT_TEST.emptyRoutes());
+    }
+
+    @Test
+    public void routeNid() throws Exception {
+        assertEquals(new NodeIdentifier(Ipv4Route.QNAME), MULTI_PATH_ABSTRACT_TEST.routeNid());
+    }
+
+    @Test
+    public void getAfi() throws Exception {
+        assertEquals(Ipv4AddressFamily.class, MULTI_PATH_ABSTRACT_TEST.getAfi());
+    }
+
+    @Test
+    public void getSafi() throws Exception {
+        assertEquals(UnicastSubsequentAddressFamily.class, MULTI_PATH_ABSTRACT_TEST.getSafi());
+    }
+
+    @Test
+    public void routesContainerIdentifier() throws Exception {
+        assertEquals(IPV4_ROUTES_IDENTIFIER, MULTI_PATH_ABSTRACT_TEST.routesContainerIdentifier());
+
+    }
+
+    @Test
+    public void routeAttributesIdentifier() throws Exception {
+        assertEquals(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME.getLocalName().intern())), MULTI_PATH_ABSTRACT_TEST.routeAttributesIdentifier());
+    }
+
+    @Test
+    public void routePath() throws Exception {
+        Assert.assertEquals(LOC_RIB_TARGET.node(ROUTES_IDENTIFIER).node(Ipv4Routes.QNAME).node(Ipv4Route.QNAME).node(PREFIX_NII),
+            MULTI_PATH_ABSTRACT_TEST.routePath(LOC_RIB_TARGET.node(Routes.QNAME), PREFIX_NII));
+    }
+
+    @Test
+    public void changedRoutes() throws Exception {
+        Assert.assertTrue(MULTI_PATH_ABSTRACT_TEST.changedRoutes(this.emptyTree).isEmpty());
+        Assert.assertTrue(MULTI_PATH_ABSTRACT_TEST.changedRoutes(this.emptySubTree).isEmpty());
+        Assert.assertNotNull(MULTI_PATH_ABSTRACT_TEST.changedRoutes(this.subTree));
+    }
+
+    @Test
+    public void putRoutes() throws Exception {
+        MULTI_PATH_ABSTRACT_TEST.putRoutes(this.tx, LOC_RIB_TARGET, this.nlri, this.attributes);
+        assertFalse(this.routes.isEmpty());
+    }
+
+    @Test
+    public void deleteRoutes() throws Exception {
+        MULTI_PATH_ABSTRACT_TEST.deleteRoutes(this.tx, LOC_RIB_TARGET, this.nlri);
+        assertTrue(this.routes.isEmpty());
+    }
+
+
+    @Test
+    public void buildUpdate() throws Exception {
+        final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(
+            new Ipv4Address("10.0.0.2")).build()).build();
+        final Attributes attr = new AttributesBuilder().setCNextHop(nextHop).build();
+        final Collection<MapEntryNode> routes = new HashSet<>();
+
+        assertEquals(new UpdateBuilder().setAttributes(new AttributesBuilder().build()).build(),
+            MULTI_PATH_ABSTRACT_TEST.buildUpdate(routes, routes, attr));
+
+        routes.add(this.mapEntryNode);
+        final MpReachNlri mpReach = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+            .setCNextHop(nextHop).setAdvertizedRoutes(new AdvertizedRoutesBuilder().build()).build();
+
+        final Attributes attMpR = new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReach).build())
+            .build();
+        assertEquals(new UpdateBuilder().setAttributes(attMpR).build(), MULTI_PATH_ABSTRACT_TEST.buildUpdate(routes, Collections.emptySet(), attr));
+
+        final MpUnreachNlri mpUnreach = new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+            .setWithdrawnRoutes(new WithdrawnRoutesBuilder().build()).build();
+
+        final Attributes attMpU = new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mpUnreach)
+            .build()).build();
+        assertEquals(new UpdateBuilder().setAttributes(attMpU).build(), MULTI_PATH_ABSTRACT_TEST.buildUpdate(Collections.emptySet(), routes, attr));
+    }
+}
\ No newline at end of file
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/PeerExportGroupTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/PeerExportGroupTest.java
new file mode 100644 (file)
index 0000000..073aca9
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.rib.spi;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+public class PeerExportGroupTest {
+    @Test
+    public void defaultPeerExportGroupTest() {
+        final  PeerExportGroup.PeerExporTuple peerExportGroup = new PeerExportGroup.PeerExporTuple(YangInstanceIdentifier.EMPTY, PeerRole.Ebgp);
+        assertEquals(PeerRole.Ebgp, peerExportGroup.getRole());
+        assertEquals(YangInstanceIdentifier.EMPTY, peerExportGroup.getYii());
+    }
+}
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/PeerRoleUtilTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/PeerRoleUtilTest.java
new file mode 100644 (file)
index 0000000..ac1f9a9
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.rib.spi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import com.google.common.base.Optional;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
+
+public class PeerRoleUtilTest {
+    @Test(expected = UnsupportedOperationException.class)
+    public void testPrivateConstructor() throws Throwable {
+        final Constructor<PeerRoleUtil> c = PeerRoleUtil.class.getDeclaredConstructor();
+        c.setAccessible(true);
+        try {
+            c.newInstance();
+        } catch (final InvocationTargetException e) {
+            throw e.getCause();
+        }
+    }
+
+    @Test
+    public void roleForChange() {
+        assertNull(PeerRoleUtil.roleForChange(Optional.fromNullable(null)));
+        assertEquals(PeerRole.Ebgp, PeerRoleUtil.roleForChange(Optional.of(new ImmutableLeafNodeBuilder<>()
+            .withNodeIdentifier(PeerRoleUtil.PEER_ROLE_NID).withValue("ebgp").build())));
+    }
+
+    @Test
+    public void roleForString() {
+        assertEquals("ebgp",PeerRoleUtil.roleForString(PeerRole.Ebgp));
+        assertEquals("ibgp",PeerRoleUtil.roleForString(PeerRole.Ibgp));
+        assertEquals("rr-client",PeerRoleUtil.roleForString(PeerRole.RrClient));
+        assertEquals("internal",PeerRoleUtil.roleForString(PeerRole.Internal));
+    }
+}
\ No newline at end of file
index 6f9b772bf604559a25590eddb8bf1d0046cc1eae..7fd770fbd6387393eb7f7ae14055a1d017f4e90a 100644 (file)
@@ -11,10 +11,13 @@ package org.opendaylight.protocol.bgp.rib.spi;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+
+import com.google.common.collect.ImmutableMap;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Map;
 import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.peer.SupportedTables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
@@ -27,6 +30,23 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 
 public class RibSupportUtilsTest {
+    private final static NodeIdentifierWithPredicates NII;
+    private final static NodeIdentifierWithPredicates NII_PATH;
+    final Class<? extends AddressFamily> AFI = Ipv4AddressFamily.class;
+    final Class<? extends SubsequentAddressFamily> SAFI = UnicastSubsequentAddressFamily.class;
+    private static final TablesKey TABLE_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+    static {
+        final QName afi = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-rib?revision=2013-09-25", "afi");
+        final QName safi = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-rib?revision=2013-09-25", "safi");
+        NII = new NodeIdentifierWithPredicates(SupportedTables.QNAME, ImmutableMap.of(afi, Ipv4AddressFamily.QNAME, safi, UnicastSubsequentAddressFamily.QNAME));
+        NII_PATH = new NodeIdentifierWithPredicates(SupportedTables.QNAME,
+            ImmutableMap.of(
+                QName.create("urn:opendaylight:params:xml:ns:yang:bgp-multiprotocol?revision=2013-09-19", "afi"),
+                Ipv4AddressFamily.QNAME,
+                QName.create("urn:opendaylight:params:xml:ns:yang:bgp-multiprotocol?revision=2013-09-19", "safi"),
+                UnicastSubsequentAddressFamily.QNAME)
+        );
+    }
 
     @Test(expected=UnsupportedOperationException.class)
     public void testPrivateConstructor() throws Throwable {
@@ -41,27 +61,33 @@ public class RibSupportUtilsTest {
 
     @Test
     public void testYangTablesKey() {
-        final Class<? extends AddressFamily> afi = Ipv4AddressFamily.class;
-        final Class<? extends SubsequentAddressFamily> safi = UnicastSubsequentAddressFamily.class;
-        final TablesKey k = new TablesKey(afi, safi);
-        final NodeIdentifierWithPredicates p = RibSupportUtils.toYangTablesKey(k);
+        final NodeIdentifierWithPredicates p = RibSupportUtils.toYangTablesKey(TABLE_KEY);
         final Map<QName, Object> m = p.getKeyValues();
         assertFalse(m.isEmpty());
         assertEquals(Tables.QNAME, p.getNodeType());
-        assertTrue(m.containsValue(BindingReflections.findQName(afi)));
-        assertTrue(m.containsValue(BindingReflections.findQName(safi)));
+        assertTrue(m.containsValue(BindingReflections.findQName(AFI)));
+        assertTrue(m.containsValue(BindingReflections.findQName(SAFI)));
     }
 
     @Test
     public void testYangKey() {
-        final Class<? extends AddressFamily> afi = Ipv4AddressFamily.class;
-        final Class<? extends SubsequentAddressFamily> safi = UnicastSubsequentAddressFamily.class;
-        final TablesKey k = new TablesKey(afi, safi);
-        final NodeIdentifierWithPredicates p = RibSupportUtils.toYangKey(SupportedTables.QNAME, k);
+        final NodeIdentifierWithPredicates p = RibSupportUtils.toYangKey(SupportedTables.QNAME, TABLE_KEY);
         final Map<QName, Object> m = p.getKeyValues();
         assertFalse(m.isEmpty());
         assertEquals(SupportedTables.QNAME, p.getNodeType());
-        assertTrue(m.containsValue(BindingReflections.findQName(afi)));
-        assertTrue(m.containsValue(BindingReflections.findQName(safi)));
+        assertTrue(m.containsValue(BindingReflections.findQName(AFI)));
+        assertTrue(m.containsValue(BindingReflections.findQName(SAFI)));
+    }
+
+    @Test
+    public void toYangPathKey() {
+        final NodeIdentifierWithPredicates result = RibSupportUtils.toYangPathKey(SupportedTables.QNAME, AFI, SAFI);
+        assertEquals(NII_PATH.toString(), result.toString());
+
+    }
+    @Test
+    public void toYangKey() {
+        final NodeIdentifierWithPredicates result = RibSupportUtils.toYangKey(SupportedTables.QNAME, TABLE_KEY);
+        assertEquals(NII.toString(), result.toString());
     }
 }
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivatorTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivatorTest.java
new file mode 100644 (file)
index 0000000..f0e33bc
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.rib.spi;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.List;
+import org.junit.Test;
+
+public class SimpleRIBExtensionProviderContextActivatorTest {
+    private static boolean RIBACTIVATED;
+
+    private static class RibActivator extends AbstractRIBExtensionProviderActivator {
+        @Override
+        protected List<AutoCloseable> startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) {
+            RIBACTIVATED = true;
+            return Collections.singletonList(() -> RIBACTIVATED = false);
+        }
+    }
+
+    @Test
+    public void test() throws Exception {
+        final List<RIBExtensionProviderActivator> extensionActivators = Collections.singletonList(new RibActivator());
+        final SimpleRIBExtensionProviderContextActivator activator =
+            new SimpleRIBExtensionProviderContextActivator(new SimpleRIBExtensionProviderContext(), extensionActivators);
+        activator.start();
+        assertTrue(RIBACTIVATED);
+        activator.close();
+        assertFalse(RIBACTIVATED);
+    }
+}
\ No newline at end of file
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Prefixes.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Prefixes.java
new file mode 100644 (file)
index 0000000..438bc16
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface Ipv4Prefixes {
+    public static final QName QNAME = org.opendaylight.yangtools.yang.common.QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+        "2015-03-05", "ipv4-prefixes").intern();
+}
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Route.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Route.java
new file mode 100644 (file)
index 0000000..eabe0b5
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface Ipv4Route extends Route {
+    public static final QName QNAME = org.opendaylight.yangtools.yang.common.QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+        "2015-03-05", "ipv4-route").intern();
+}
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Routes.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Routes.java
new file mode 100644 (file)
index 0000000..de93bb6
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface Ipv4Routes extends DataObject {
+    public static final QName QNAME = org.opendaylight.yangtools.yang.common.QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+        "2015-03-05", "ipv4-routes").intern();
+}
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4RoutesCase.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4RoutesCase.java
new file mode 100644 (file)
index 0000000..32df8d5
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public interface Ipv4RoutesCase extends Routes {
+    public static final QName QNAME = org.opendaylight.yangtools.yang.common.QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+        "2015-03-05", "ipv4-routes-case").intern();
+}
diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/MultiPathAbstractTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/MultiPathAbstractTest.java
new file mode 100644 (file)
index 0000000..1b8bfd9
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes;
+
+import com.google.common.collect.ImmutableCollection;
+import com.google.common.collect.ImmutableMap;
+import java.util.Collection;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.protocol.bgp.rib.spi.MultiPathAbstractRIBSupport;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
+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.UnicastSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+
+public final class MultiPathAbstractTest extends MultiPathAbstractRIBSupport {
+    private final static String ROUTE_KEY = "prefix";
+    private static final String PREFIX = "1.2.3.4/32";
+
+    private static final NodeIdentifierWithPredicates PREFIX_NII = new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
+        ImmutableMap.of(QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern(), PREFIX));
+
+    public MultiPathAbstractTest() {
+        super(Ipv4RoutesCase.class, Ipv4Routes.class, Ipv4Route.class, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, ROUTE_KEY, Ipv4Prefixes.QNAME);
+    }
+
+    @Nonnull
+    @Override
+    protected DestinationType buildDestination(@Nonnull final Collection<MapEntryNode> routes) {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    protected DestinationType buildWithdrawnDestination(@Nonnull final Collection<MapEntryNode> routes) {
+        return null;
+    }
+
+    @Override
+    protected void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, final ContainerNode destination,
+        final ContainerNode attributes, final ApplyRoute applyFunction) {
+        applyFunction.apply(tx, routesPath.node(Ipv4Route.QNAME), PREFIX_NII, destination, attributes);
+    }
+
+    @Nonnull
+    @Override
+    public ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
+        return null;
+    }
+
+    @Override
+    public boolean isComplexRoute() {
+        return false;
+    }
+}
\ No newline at end of file
index b5110197974e2fccb0aa7a230ab15420d410f860..25b5814b8d573f9b0574e303b72779cd5bd07d24 100644 (file)
                     <sourceDirectory>${project.basedir}</sourceDirectory>
                     <includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat,**\/*.yang</includes>
                     <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/src/main/yang-gen-config\/,**\/src/main/yang-gen-sal\/,**\/
-                        .m2repo\/,**\/org/opendaylight/protocol/util/LoggerUtil.java</excludes>
+                        .m2repo\/,**\/org/opendaylight/protocol/util/LoggerUtil.java,**\/org/opendaylight/protocol/util/LoggerUtilTest.java</excludes>
                 </configuration>
                 <dependencies>
                     <dependency>
index 526b16588e7d1fa9c22edd6bd7660932b5c5e28e..71ec3e4bc1e1cccb8d20618857ce4a20fd98ab3f 100644 (file)
@@ -12,6 +12,9 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 
+import com.google.common.net.HostAndPort;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.net.InetSocketAddress;
 import java.util.Arrays;
 import java.util.List;
@@ -19,13 +22,24 @@ import org.junit.Assert;
 import org.junit.Test;
 
 public class InetSocketAddressUtilTest {
-    private static String ADDRESS1 = "1.1.1.1";
-    private static String ADDRESS2 = "2.2.2.2";
-    private static int PORT1 = 123;
-    private static int PORT2 = 321;
-    private static String ADDRESSES_WO_PORT = ADDRESS1 + "," + ADDRESS2;
-    private static String ADDRESSES = ADDRESS1 + ":" + PORT1 + "," + ADDRESS2 + ":" + PORT2;
-    private static int DEFAULT_PORT = 179;
+    private static final String ADDRESS1 = "1.1.1.1";
+    private static final String ADDRESS2 = "2.2.2.2";
+    private static final int PORT1 = 123;
+    private static final int PORT2 = 321;
+    private static final String ADDRESSES_WO_PORT = ADDRESS1 + "," + ADDRESS2;
+    private static final String ADDRESSES = ADDRESS1 + ":" + PORT1 + "," + ADDRESS2 + ":" + PORT2;
+    private static final int DEFAULT_PORT = 179;
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testPrivateConstructor() throws Throwable {
+        final Constructor<InetSocketAddressUtil> c = InetSocketAddressUtil.class.getDeclaredConstructor();
+        c.setAccessible(true);
+        try {
+            c.newInstance();
+        } catch (final InvocationTargetException e) {
+            throw e.getCause();
+        }
+    }
 
     @Test
     public void parseAddresses() throws Exception {
@@ -33,6 +47,13 @@ public class InetSocketAddressUtilTest {
         Assert.assertEquals(Arrays.asList(new InetSocketAddress(ADDRESS1, PORT1), new InetSocketAddress(ADDRESS2, PORT2)), actualResult);
     }
 
+    @Test
+    public void toHostAndPort() throws Exception {
+        final HostAndPort actualResult = InetSocketAddressUtil.toHostAndPort(new InetSocketAddress(ADDRESS2, PORT2));
+        final HostAndPort expected = HostAndPort.fromString("2.2.2.2:321");
+        Assert.assertEquals(expected, actualResult);
+    }
+
     @Test
     public void parseAddressesDefaultPort() throws Exception {
         final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES_WO_PORT, DEFAULT_PORT);
diff --git a/testtool-util/src/test/java/org/opendaylight/protocol/util/LoggerUtilTest.java b/testtool-util/src/test/java/org/opendaylight/protocol/util/LoggerUtilTest.java
new file mode 100644 (file)
index 0000000..ed600de
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.util;
+
+import static org.junit.Assert.assertEquals;
+
+import ch.qos.logback.classic.Level;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LoggerUtilTest {
+
+    @Test(expected=UnsupportedOperationException.class)
+    public void testPrivateConstructor() throws Throwable {
+        final Constructor<LoggerUtil> c = LoggerUtil.class.getDeclaredConstructor();
+        c.setAccessible(true);
+        try {
+            c.newInstance();
+        } catch (final InvocationTargetException e) {
+            throw e.getCause();
+        }
+    }
+
+    @Test
+    public void initiateLogger() {
+        LoggerUtil.initiateLogger(() -> Level.DEBUG);
+        final ch.qos.logback.classic.Logger protocolLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.opendaylight.protocol");
+        assertEquals(protocolLogger.getLevel(), Level.DEBUG);
+
+        final ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+        assertEquals(logger.getLevel(), Level.OFF);
+    }
+}
\ No newline at end of file