BGPCEP-754: Start using default import policy 98/68898/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 26 Feb 2018 11:01:55 +0000 (12:01 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 26 Feb 2018 11:01:55 +0000 (12:01 +0100)
configuration with configurable rib policies.

Change-Id: I6aeb4c4261aafb7faf1ff0a08edfefb443590830
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
36 files changed:
bgp/bgp-artifacts/pom.xml
bgp/config-example/pom.xml
bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupport.java
bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java
bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnRIBSupport.java
bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java
bgp/openconfig-rp-statement/pom.xml
bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/AbstractStatementRegistryConsumerTest.java
bgp/rib-impl/pom.xml
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ApplicationPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPRouteEntryImportParametersImpl.java [new file with mode: 0644]
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBSupportContextRegistryImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/RibImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/RoutingPolicyUtil.java [new file with mode: 0644]
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/RIB.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/RIBSupportContextRegistry.java
bgp/rib-impl/src/main/resources/org/opendaylight/blueprint/bgp-rib.xml
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/DefaultRibPoliciesMockTest.java [new file with mode: 0644]
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationAndExceptionTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/AbstractConfig.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/AppPeerTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpDeployerImplTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/RIBTestsUtil.java [new file with mode: 0644]
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/RibImplTest.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupport.java
features/bgp/odl-bgpcep-bgp-rib-impl/pom.xml

index b420ad74a413ee4cab721886eb23120aabd26c47..c18162dbdd85e536e95cad239177272240af0ab6 100644 (file)
                 <artifactId>bgp-config-example</artifactId>
                 <version>${project.version}</version>
             </dependency>
                 <artifactId>bgp-config-example</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>bgp-config-example</artifactId>
+                <version>${project.version}</version>
+                <type>test-jar</type>
+                <scope>test</scope>
+            </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>bgp-config-example</artifactId>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>bgp-config-example</artifactId>
index 6fa8c868759e9367133421d6faaf83a61a61fb64..103953ddc3010c563cb16a0c2f55a20d286fe892 100644 (file)
@@ -55,6 +55,7 @@
                     <includes>
                         <include>**/network-topology-config.xml</include>
                         <include>**/protocols-config.xml</include>
                     <includes>
                         <include>**/network-topology-config.xml</include>
                         <include>**/protocols-config.xml</include>
+                        <include>**/routing-policy-config.xml</include>
                     </includes>
                 </configuration>
             </plugin>
                     </includes>
                 </configuration>
             </plugin>
                     </execution>
                 </executions>
             </plugin>
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 
         </plugins>
     </build>
 
index 7f96c1a707328561e21fb4e543fcaf9e09d8182b..a88c67168d55566dd1546a4ecf6b48b1ca87bf86 100644 (file)
@@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
 final class EvpnRibSupport extends AbstractRIBSupport {
     private static final EvpnRibSupport SINGLETON = new EvpnRibSupport();
     private static final Logger LOG = LoggerFactory.getLogger(EvpnRibSupport.class);
 final class EvpnRibSupport extends AbstractRIBSupport {
     private static final EvpnRibSupport SINGLETON = new EvpnRibSupport();
     private static final Logger LOG = LoggerFactory.getLogger(EvpnRibSupport.class);
-    private static final QName ROUTE_KEY = QName.create(EvpnRoute.QNAME, "route-key").intern();
+    private static final QName ROUTE_KEY_QNAME = QName.create(EvpnRoute.QNAME, ROUTE_KEY).intern();
     private static final NodeIdentifier NLRI_ROUTES_LIST = NodeIdentifier.create(EvpnDestination.QNAME);
 
     private EvpnRibSupport() {
     private static final NodeIdentifier NLRI_ROUTES_LIST = NodeIdentifier.create(EvpnDestination.QNAME);
 
     private EvpnRibSupport() {
@@ -123,7 +123,7 @@ final class EvpnRibSupport extends AbstractRIBSupport {
         final ByteBuf buffer = Unpooled.buffer();
         final EvpnDestination dest = EvpnNlriParser.extractRouteKeyDestination(evpn);
         EvpnNlriParser.serializeNlri(Collections.singletonList(dest), buffer);
         final ByteBuf buffer = Unpooled.buffer();
         final EvpnDestination dest = EvpnNlriParser.extractRouteKeyDestination(evpn);
         EvpnNlriParser.serializeNlri(Collections.singletonList(dest), buffer);
-        return new NodeIdentifierWithPredicates(routeQName(), ROUTE_KEY, ByteArray.encodeBase64(buffer));
+        return new NodeIdentifierWithPredicates(routeQName(), ROUTE_KEY_QNAME, ByteArray.encodeBase64(buffer));
     }
 
 }
     }
 
 }
index bafebd74c6762dc1596cba9b40b09e168cfd3fef..24d8eecdd409230140265ca6fcef9582b9a661d6 100644 (file)
@@ -45,7 +45,7 @@ public abstract class AbstractFlowspecRIBSupport<T extends AbstractFlowspecNlriP
         final QName dstContainerClassQName,
         final T nlriParser
     ) {
         final QName dstContainerClassQName,
         final T nlriParser
     ) {
-        super(cazeClass, containerClass, listClass, afiClass, safiClass, "route-key", dstContainerClassQName);
+        super(cazeClass, containerClass, listClass, afiClass, safiClass, ROUTE_KEY, dstContainerClassQName);
 
         this.nlriParser = requireNonNull(nlriParser);
     }
 
         this.nlriParser = requireNonNull(nlriParser);
     }
index 413d63ba79df6150f87ba7c969ee54d7bb4e56a3..2a4f826b8c47080a4ad89bb2521b731595daf771 100644 (file)
@@ -75,7 +75,7 @@ public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport {
         super(cazeClass, containerClass, listClass, afiClass,
                 MplsLabeledVpnSubsequentAddressFamily.class, vpnDstContainerClassQname);
         final QName classQname = BindingReflections.findQName(containerClass).intern();
         super(cazeClass, containerClass, listClass, afiClass,
                 MplsLabeledVpnSubsequentAddressFamily.class, vpnDstContainerClassQname);
         final QName classQname = BindingReflections.findQName(containerClass).intern();
-        this.routeKey = QName.create(routeQName(), "route-key").intern();
+        this.routeKey = QName.create(routeQName(), ROUTE_KEY).intern();
         final QName vpnDstClassQname = QName.create(classQname, VpnDestination.QNAME.getLocalName());
         this.nlriRoutesListNid = NodeIdentifier.create(vpnDstClassQname);
         this.prefixTypeNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "prefix").intern());
         final QName vpnDstClassQname = QName.create(classQname, VpnDestination.QNAME.getLocalName());
         this.nlriRoutesListNid = NodeIdentifier.create(vpnDstClassQname);
         this.prefixTypeNid = NodeIdentifier.create(QName.create(vpnDstClassQname, "prefix").intern());
index b58000423e59097a44fb03e41e5d0003030ad475..822dc9e8a9cbe4f5f2e7d5e7b5c10db84a2dbe9f 100644 (file)
@@ -69,7 +69,7 @@ abstract class AbstractLabeledUnicastRIBSupport extends MultiPathAbstractRIBSupp
     AbstractLabeledUnicastRIBSupport(final Class<? extends Routes> cazeClass, final Class<? extends DataObject> containerClass,
         final Class<? extends Route> listClass, final Class<? extends AddressFamily> addressFamilyClass,
         final Class<? extends SubsequentAddressFamily> safiClass, final QName destinationQname) {
     AbstractLabeledUnicastRIBSupport(final Class<? extends Routes> cazeClass, final Class<? extends DataObject> containerClass,
         final Class<? extends Route> listClass, final Class<? extends AddressFamily> addressFamilyClass,
         final Class<? extends SubsequentAddressFamily> safiClass, final QName destinationQname) {
-        super(cazeClass, containerClass, listClass, addressFamilyClass, safiClass, "route-key", destinationQname);
+        super(cazeClass, containerClass, listClass, addressFamilyClass, safiClass, ROUTE_KEY, destinationQname);
     }
 
     @Override
     }
 
     @Override
index 1ee205b90877e1ff1abb3306149102a7984a556f..edbba00ca6d303601e211250392653ca93c7e8ba 100644 (file)
@@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
 
 public final class LinkstateRIBSupport extends AbstractRIBSupport {
     private static final Logger LOG = LoggerFactory.getLogger(LinkstateRIBSupport.class);
 
 public final class LinkstateRIBSupport extends AbstractRIBSupport {
     private static final Logger LOG = LoggerFactory.getLogger(LinkstateRIBSupport.class);
-    private static final QName ROUTE_KEY = QName.create(LinkstateRoute.QNAME, "route-key").intern();
+    private static final QName ROUTE_KEY_QNAME = QName.create(LinkstateRoute.QNAME, ROUTE_KEY).intern();
     private static final LinkstateRIBSupport SINGLETON = new LinkstateRIBSupport();
     private final NodeIdentifier route = new NodeIdentifier(LinkstateRoute.QNAME);
     private final NodeIdentifier nlriRoutesList = new NodeIdentifier(CLinkstateDestination.QNAME);
     private static final LinkstateRIBSupport SINGLETON = new LinkstateRIBSupport();
     private final NodeIdentifier route = new NodeIdentifier(LinkstateRoute.QNAME);
     private final NodeIdentifier nlriRoutesList = new NodeIdentifier(CLinkstateDestination.QNAME);
@@ -106,7 +106,7 @@ public final class LinkstateRIBSupport extends AbstractRIBSupport {
         final CLinkstateDestination cLinkstateDestination = LinkstateNlriParser.extractLinkstateDestination(linkstate);
         SimpleNlriTypeRegistry.getInstance().serializeNlriType(cLinkstateDestination, buffer);
 
         final CLinkstateDestination cLinkstateDestination = LinkstateNlriParser.extractLinkstateDestination(linkstate);
         SimpleNlriTypeRegistry.getInstance().serializeNlriType(cLinkstateDestination, buffer);
 
-        return new NodeIdentifierWithPredicates(LinkstateRoute.QNAME, ROUTE_KEY, ByteArray.readAllBytes(buffer));
+        return new NodeIdentifierWithPredicates(LinkstateRoute.QNAME, ROUTE_KEY_QNAME, ByteArray.readAllBytes(buffer));
     }
 
     @Nonnull
     }
 
     @Nonnull
index 3be0071295b84d8c766071fbee11477fe03077c2..e5c395cd1e0965bb3a19ce2b19561d58437c4590 100644 (file)
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-openconfig-rp-spi</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
     </dependencies>
 
     <build>
index b87c8d6a210a15ba5521067ba150acb4c0aa76ec..8ca584a25c28a044a6ddd9d90d84255e39f28861 100644 (file)
@@ -12,16 +12,16 @@ import static org.opendaylight.bgpcep.config.loader.routing.policy.OpenconfigRou
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import org.junit.Before;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import org.junit.Before;
-import org.opendaylight.bgpcep.config.loader.routing.policy.AbstractOpenconfigRoutingPolicyLoaderTest;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.AbstractStatementRegistryTest;
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.StatementRegistry;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.PolicyDefinitions;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.PolicyDefinition;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.PolicyDefinitionKey;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
 
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.StatementRegistry;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.PolicyDefinitions;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.PolicyDefinition;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.PolicyDefinitionKey;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
 
-public class AbstractStatementRegistryConsumerTest extends AbstractOpenconfigRoutingPolicyLoaderTest {
+public class AbstractStatementRegistryConsumerTest extends AbstractStatementRegistryTest {
     protected StatementRegistry statementRegistry;
 
     @Before
     protected StatementRegistry statementRegistry;
 
     @Before
index 07d5efccc5b11d3b397ffa1f7a1d65356f6d5822..0d47cc1640799c7b01bb236b3e7d8bd20bbab8bb 100644 (file)
             <groupId>${project.groupId}</groupId>
             <artifactId>config-loader-spi</artifactId>
         </dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>config-loader-spi</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-openconfig-api</artifactId>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-openconfig-spi</artifactId>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-openconfig-spi</artifactId>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-path-selection-mode</artifactId>
         </dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-path-selection-mode</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-openconfig-rp-spi</artifactId>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-inet</artifactId>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-inet</artifactId>
             <classifier>linux-x86_64</classifier>
         </dependency>
         <!-- Testing dependencies -->
             <classifier>linux-x86_64</classifier>
         </dependency>
         <!-- Testing dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-openconfig-rp-impl</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-openconfig-rp-impl</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-rib-spi</artifactId>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>bgp-rib-spi</artifactId>
             <artifactId>yang-test-util</artifactId>
             <scope>test</scope>
         </dependency>
             <artifactId>yang-test-util</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>routing-policy-config-loader</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>routing-policy-config-loader</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-openconfig-rp-statement</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-openconfig-rp-statement</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-openconfig-rp-spi</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>bgp-config-example</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
     </dependencies>
 
     <build>
index 264e04662fa6a923d4e275bc68d326737522c747..f8333d8e5f1e2f0923bda0e506ddceace81dd821 100644 (file)
@@ -145,8 +145,8 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
         this.adjRibInWriter = this.adjRibInWriter.transform(this.peerId, context, localTables, Collections.emptyMap(),
                 registerAppPeerListener);
         this.effectiveRibInWriter = EffectiveRibInWriter
         this.adjRibInWriter = this.adjRibInWriter.transform(this.peerId, context, localTables, Collections.emptyMap(),
                 registerAppPeerListener);
         this.effectiveRibInWriter = EffectiveRibInWriter
-                .create(this.rib.getService(), this.rib.createPeerChain(this), this.peerIId,
-                this.rib.getImportPolicyPeerTracker(), context, PeerRole.Internal,
+                .create(this.rib, this.rib.createPeerChain(this), this.peerIId,
+                this.rib.getImportPolicyPeerTracker(), PeerRole.Internal,
                 localTables);
         this.bgpSessionState.registerMessagesCounter(this);
         this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
                 localTables);
         this.bgpSessionState.registerMessagesCounter(this);
         this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
index a1d4043947db0ccba8814ed19b3df56c8a529966..c5d55cae9adb4e3d09773757b5466dd039447768 100644 (file)
@@ -327,10 +327,9 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
         }
         addBgp4Support();
 
         }
         addBgp4Support();
 
-        this.effRibInWriter = EffectiveRibInWriter.create(this.rib.getService(),
+        this.effRibInWriter = EffectiveRibInWriter.create(this.rib,
                 this.rib.createPeerChain(this),
                 this.peerIId, this.rib.getImportPolicyPeerTracker(),
                 this.rib.createPeerChain(this),
                 this.peerIId, this.rib.getImportPolicyPeerTracker(),
-                this.rib.getRibSupportContext(),
                 this.peerRole,
                 this.tables);
         registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
                 this.peerRole,
                 this.tables);
         registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPRouteEntryImportParametersImpl.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPRouteEntryImportParametersImpl.java
new file mode 100644 (file)
index 0000000..0ef61a9
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.impl;
+
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+
+public class BGPRouteEntryImportParametersImpl implements BGPRouteEntryImportParameters {
+    private final PeerId peerId;
+    private final NodeIdentifierWithPredicates routeId;
+    private final PeerRole fromPeerRole;
+
+    public BGPRouteEntryImportParametersImpl(
+            final NodeIdentifierWithPredicates routeId,
+            final PeerId peerId,
+            final PeerRole fromPeerRole) {
+        this.routeId = routeId;
+        this.peerId = peerId;
+        this.fromPeerRole = fromPeerRole;
+    }
+
+    @Override
+    public NodeIdentifierWithPredicates getRouteId() {
+        return this.routeId;
+    }
+
+    @Override
+    public PeerId getFromPeerId() {
+        return this.peerId;
+    }
+
+    @Override
+    public PeerRole getFromPeerRole() {
+        return this.fromPeerRole;
+    }
+
+}
index 8a8b22cd5d598c3c7fbd5fe4df07c71d937495ca..e39e6f9e015cd935f12bd52d7181cb237c212542 100644 (file)
@@ -21,18 +21,24 @@ import javax.annotation.Nonnull;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
 import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
 import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
+import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesInstalledCounters;
 import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesReceivedCounters;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesInstalledCounters;
 import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesReceivedCounters;
+import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
+import org.opendaylight.protocol.bgp.rib.spi.entry.AttributeBindingCodecSerializer;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.peer.AdjRibIn;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.peer.EffectiveRibIn;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.peer.AdjRibIn;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.peer.EffectiveRibIn;
@@ -46,7 +52,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
@@ -78,21 +83,29 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn
         private final DOMTransactionChain chain;
         private final Map<TablesKey, LongAdder> prefixesReceived;
         private final Map<TablesKey, LongAdder> prefixesInstalled;
         private final DOMTransactionChain chain;
         private final Map<TablesKey, LongAdder> prefixesReceived;
         private final Map<TablesKey, LongAdder> prefixesInstalled;
-
-        AdjInTracker(final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry,
-                final DOMTransactionChain chain, final YangInstanceIdentifier peerIId,
+        private final BGPRibRoutingPolicy ribPolicies;
+        private final BGPPeerTracker peerTracker;
+        private final AttributeBindingCodecSerializer attBindingCodecSerializer;
+        private final PeerId peerId;
+
+        AdjInTracker(final RIB rib,
+                final DOMTransactionChain chain,
+                final YangInstanceIdentifier peerIId,
                 @Nonnull final Set<TablesKey> tables) {
                 @Nonnull final Set<TablesKey> tables) {
-            this.registry = requireNonNull(registry);
+            this.registry = requireNonNull(rib.getRibSupportContext());
             this.chain = requireNonNull(chain);
             this.peerIId = requireNonNull(peerIId);
             this.effRibTables = this.peerIId.node(EffectiveRibIn.QNAME).node(Tables.QNAME);
             this.prefixesInstalled = buildPrefixesTables(tables);
             this.prefixesReceived = buildPrefixesTables(tables);
             this.chain = requireNonNull(chain);
             this.peerIId = requireNonNull(peerIId);
             this.effRibTables = this.peerIId.node(EffectiveRibIn.QNAME).node(Tables.QNAME);
             this.prefixesInstalled = buildPrefixesTables(tables);
             this.prefixesReceived = buildPrefixesTables(tables);
-
+            this.ribPolicies = requireNonNull(rib.getRibPolicies());
+            this.peerTracker = requireNonNull(rib.getPeerTracker());
+            this.attBindingCodecSerializer = rib;
+            this.peerId = IdentifierUtils.peerId((NodeIdentifierWithPredicates) peerIId.getLastPathArgument());
             final DOMDataTreeIdentifier treeId = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
                     this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME));
             LOG.debug("Registered Effective RIB on {}", this.peerIId);
             final DOMDataTreeIdentifier treeId = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
                     this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME));
             LOG.debug("Registered Effective RIB on {}", this.peerIId);
-            this.reg = service.registerDataTreeChangeListener(treeId, this);
+            this.reg = requireNonNull(rib.getService()).registerDataTreeChangeListener(treeId, this);
         }
 
         private Map<TablesKey, LongAdder> buildPrefixesTables(final Set<TablesKey> tables) {
         }
 
         private Map<TablesKey, LongAdder> buildPrefixesTables(final Set<TablesKey> tables) {
@@ -119,22 +132,38 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn
                 case APPEARED:
                 case SUBTREE_MODIFIED:
                 case WRITE:
                 case APPEARED:
                 case SUBTREE_MODIFIED:
                 case WRITE:
-                    tx.put(LogicalDatastoreType.OPERATIONAL, routeId, route.getDataAfter().get());
+                    final NormalizedNode<?, ?> advRoute = route.getDataAfter().get();
+                    tx.put(LogicalDatastoreType.OPERATIONAL, routeId, advRoute);
                     CountersUtil.increment(this.prefixesReceived.get(tablesKey), tablesKey);
                     // Lookup per-table attributes from RIBSupport
                     CountersUtil.increment(this.prefixesReceived.get(tablesKey), tablesKey);
                     // Lookup per-table attributes from RIBSupport
-                    final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(route.getDataAfter(), ribSupport.routeAttributesIdentifier()).orElse(null);
-                    final ContainerNode effectiveAttrs;
 
 
-                    if (advertisedAttrs != null) {
-                        effectiveAttrs = policy.effectiveAttributes(advertisedAttrs);
+                    final NodeIdentifierWithPredicates routeIdentifier = ribSupport
+                            .createRouteKeyPathArgument((NodeIdentifierWithPredicates) route.getIdentifier());
+                    Optional<Attributes> advertisedAttrs = this.attBindingCodecSerializer
+                            .getAttributes(ribSupport, routeIdentifier, advRoute);
+
+                    final Optional<Attributes> effectiveAttrs;
+                    if (advertisedAttrs.isPresent()) {
+                        final PeerRole peerRole = this.peerTracker.getRole(this.peerId);
+                        final BGPRouteEntryImportParameters ribPolicyParameters =
+                                new BGPRouteEntryImportParametersImpl(
+                                        (NodeIdentifierWithPredicates) route.getIdentifier(), this.peerId, peerRole);
+                        effectiveAttrs = this.ribPolicies
+                                .applyImportPolicies(ribPolicyParameters, advertisedAttrs.get());
+                        LOG.debug("Route {} effective attributes {} towards {}", route.getIdentifier(), effectiveAttrs,
+                                routeId);
+
                     } else {
                     } else {
-                        effectiveAttrs = null;
+                        effectiveAttrs = Optional.empty();
                     }
 
                     LOG.debug("Route {} effective attributes {} towards {}", route.getIdentifier(), effectiveAttrs, routeId);
 
                     }
 
                     LOG.debug("Route {} effective attributes {} towards {}", route.getIdentifier(), effectiveAttrs, routeId);
 
-                    if (effectiveAttrs != null) {
-                        tx.put(LogicalDatastoreType.OPERATIONAL, routeId.node(ribSupport.routeAttributesIdentifier()), effectiveAttrs);
+                    final Optional<ContainerNode> normEffAtt = this.attBindingCodecSerializer
+                            .toNormalizedNodeAttribute(ribSupport, routeIdentifier, effectiveAttrs);
+                    if (normEffAtt.isPresent()) {
+                        tx.put(LogicalDatastoreType.OPERATIONAL,
+                                routeId.node(ribSupport.routeAttributesIdentifier()), normEffAtt.get());
                         if (route.getModificationType() == ModificationType.WRITE) {
                             CountersUtil.increment(this.prefixesInstalled.get(tablesKey), tablesKey);
                         }
                         if (route.getModificationType() == ModificationType.WRITE) {
                             CountersUtil.increment(this.prefixesInstalled.get(tablesKey), tablesKey);
                         }
@@ -334,26 +363,20 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn
     private final AdjInTracker adjInTracker;
     private final AbstractImportPolicy importPolicy;
 
     private final AdjInTracker adjInTracker;
     private final AbstractImportPolicy importPolicy;
 
-    static EffectiveRibInWriter create(@Nonnull final DOMDataTreeChangeService service,
+    static EffectiveRibInWriter create(@Nonnull final RIB rib,
             @Nonnull final DOMTransactionChain chain,
             @Nonnull final YangInstanceIdentifier peerIId,
             @Nonnull final ImportPolicyPeerTracker importPolicyPeerTracker,
             @Nonnull final DOMTransactionChain chain,
             @Nonnull final YangInstanceIdentifier peerIId,
             @Nonnull final ImportPolicyPeerTracker importPolicyPeerTracker,
-            @Nonnull final RIBSupportContextRegistry registry,
             final PeerRole peerRole,
             @Nonnull final Set<TablesKey> tables) {
             final PeerRole peerRole,
             @Nonnull final Set<TablesKey> tables) {
-        return new EffectiveRibInWriter(service, chain, peerIId, importPolicyPeerTracker, registry, peerRole, tables);
+        return new EffectiveRibInWriter(rib, chain, peerIId, importPolicyPeerTracker, peerRole, tables);
     }
 
     }
 
-    private EffectiveRibInWriter(final DOMDataTreeChangeService service,
-            final DOMTransactionChain chain,
-            final YangInstanceIdentifier peerIId,
-            final ImportPolicyPeerTracker importPolicyPeerTracker,
-            final RIBSupportContextRegistry registry,
-            final PeerRole peerRole,
-            @Nonnull final Set<TablesKey> tables) {
+    private EffectiveRibInWriter(final RIB rib, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId,
+            final ImportPolicyPeerTracker importPolicyPeerTracker, final PeerRole peerRole, @Nonnull final Set<TablesKey> tables) {
         importPolicyPeerTracker.peerRoleChanged(peerIId, peerRole);
         this.importPolicy = importPolicyPeerTracker.policyFor(IdentifierUtils.peerId((NodeIdentifierWithPredicates) peerIId.getLastPathArgument()));
         importPolicyPeerTracker.peerRoleChanged(peerIId, peerRole);
         this.importPolicy = importPolicyPeerTracker.policyFor(IdentifierUtils.peerId((NodeIdentifierWithPredicates) peerIId.getLastPathArgument()));
-        this.adjInTracker = new AdjInTracker(service, registry, chain, peerIId, tables);
+        this.adjInTracker = new AdjInTracker(rib, chain, peerIId, tables);
     }
 
     @Override
     }
 
     @Override
index 637f3baf5bfcf9260486d61b2897fa45c2ce780b..038b217f6b37a06773f7d5d677ae69ddb6b2dcf4 100755 (executable)
@@ -35,6 +35,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
@@ -50,6 +51,7 @@ import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
@@ -97,6 +99,7 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
     private final DOMDataBroker domDataBroker;
     private final RIBExtensionConsumerContext extensions;
     private final YangInstanceIdentifier yangRibId;
     private final DOMDataBroker domDataBroker;
     private final RIBExtensionConsumerContext extensions;
     private final YangInstanceIdentifier yangRibId;
+    private final YangInstanceIdentifier yangTables;
     private final RIBSupportContextRegistryImpl ribContextRegistry;
     private final CodecsRegistryImpl codecsRegistry;
     @GuardedBy("this")
     private final RIBSupportContextRegistryImpl ribContextRegistry;
     private final CodecsRegistryImpl codecsRegistry;
     @GuardedBy("this")
@@ -107,7 +110,10 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
     private final ImportPolicyPeerTracker importPolicyPeerTracker;
     private final RibId ribId;
     private final BGPPeerTracker peerTracker;
     private final ImportPolicyPeerTracker importPolicyPeerTracker;
     private final RibId ribId;
     private final BGPPeerTracker peerTracker;
+    private final BGPRibRoutingPolicy ribPolicies;
     private final Map<TablesKey, ExportPolicyPeerTracker> exportPolicyPeerTrackerMap;
     private final Map<TablesKey, ExportPolicyPeerTracker> exportPolicyPeerTrackerMap;
+    private final BindingNormalizedNodeSerializer bindingSerializer;
+
     @GuardedBy("this")
     private DOMTransactionChain domChain;
     @GuardedBy("this")
     @GuardedBy("this")
     private DOMTransactionChain domChain;
     @GuardedBy("this")
@@ -121,9 +127,12 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
             final BGPDispatcher dispatcher,
             final CodecsRegistryImpl codecsRegistry,
             final DOMDataBroker domDataBroker,
             final BGPDispatcher dispatcher,
             final CodecsRegistryImpl codecsRegistry,
             final DOMDataBroker domDataBroker,
+            final BGPRibRoutingPolicy ribPolicies,
             final BGPPeerTracker bgpPeerTracker,
             final List<BgpTableType> localTables,
             final BGPPeerTracker bgpPeerTracker,
             final List<BgpTableType> localTables,
-            @Nonnull final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies) {
+            final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies,
+            final BindingNormalizedNodeSerializer bindingSerializer
+    ) {
         super(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(requireNonNull(ribId))),
                 localBgpId, localAs);
         this.localAs = requireNonNull(localAs);
         super(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(requireNonNull(ribId))),
                 localBgpId, localAs);
         this.localAs = requireNonNull(localAs);
@@ -134,11 +143,13 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
         this.domDataBroker = requireNonNull(domDataBroker);
         this.service = this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
         this.extensions = requireNonNull(extensions);
         this.domDataBroker = requireNonNull(domDataBroker);
         this.service = this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
         this.extensions = requireNonNull(extensions);
+        this.ribPolicies = requireNonNull(ribPolicies);
         this.peerTracker = requireNonNull(bgpPeerTracker);
         this.codecsRegistry = codecsRegistry;
         this.ribContextRegistry = RIBSupportContextRegistryImpl.create(extensions, this.codecsRegistry);
         final InstanceIdentifierBuilder yangRibIdBuilder = YangInstanceIdentifier.builder().node(BgpRib.QNAME).node(Rib.QNAME);
         this.yangRibId = yangRibIdBuilder.nodeWithKey(Rib.QNAME, RIB_ID_QNAME, ribId.getValue()).build();
         this.peerTracker = requireNonNull(bgpPeerTracker);
         this.codecsRegistry = codecsRegistry;
         this.ribContextRegistry = RIBSupportContextRegistryImpl.create(extensions, this.codecsRegistry);
         final InstanceIdentifierBuilder yangRibIdBuilder = YangInstanceIdentifier.builder().node(BgpRib.QNAME).node(Rib.QNAME);
         this.yangRibId = yangRibIdBuilder.nodeWithKey(Rib.QNAME, RIB_ID_QNAME, ribId.getValue()).build();
+        this.yangTables = this.yangRibId.node(LocRib.QNAME).node(Tables.QNAME);
         this.bestPathSelectionStrategies = requireNonNull(bestPathSelectionStrategies);
         final ClusterIdentifier cId = clusterId == null ? new ClusterIdentifier(localBgpId) : clusterId;
         this.ribId = ribId;
         this.bestPathSelectionStrategies = requireNonNull(bestPathSelectionStrategies);
         final ClusterIdentifier cId = clusterId == null ? new ClusterIdentifier(localBgpId) : clusterId;
         this.ribId = ribId;
@@ -152,6 +163,7 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
             exportPolicies.put(key, new ExportPolicyPeerTrackerImpl(policyDatabase, key));
         }
         this.exportPolicyPeerTrackerMap = exportPolicies.build();
             exportPolicies.put(key, new ExportPolicyPeerTrackerImpl(policyDatabase, key));
         }
         this.exportPolicyPeerTrackerMap = exportPolicies.build();
+        this.bindingSerializer = requireNonNull(bindingSerializer);
     }
 
     private synchronized void startLocRib(final TablesKey key) {
     }
 
     private synchronized void startLocRib(final TablesKey key) {
@@ -266,6 +278,11 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
         return this.localTablesKeys.contains(tableKey);
     }
 
         return this.localTablesKeys.contains(tableKey);
     }
 
+    @Override
+    public BGPRibRoutingPolicy getRibPolicies() {
+        return this.ribPolicies;
+    }
+
     @Override
     public BGPPeerTracker getPeerTracker() {
         return this.peerTracker;
     @Override
     public BGPPeerTracker getPeerTracker() {
         return this.peerTracker;
@@ -381,7 +398,10 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
         if (!attributes.isPresent()) {
             return Optional.empty();
         }
         if (!attributes.isPresent()) {
             return Optional.empty();
         }
-        return Optional.empty();
+        final InstanceIdentifier<Attributes> yii
+                = (InstanceIdentifier<Attributes>) this.bindingSerializer
+                .fromYangInstanceIdentifier(ribSupport.buildRouteAttributeYii(this.yangTables, routeIdentifier));
+        return Optional.of((ContainerNode) this.bindingSerializer.toNormalizedNode(yii, attributes.get()).getValue());
     }
 
     @Override
     }
 
     @Override
@@ -395,6 +415,8 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
             return Optional.empty();
         }
 
             return Optional.empty();
         }
 
-        return Optional.empty();
+        return Optional.ofNullable((Attributes) this.bindingSerializer
+                .fromNormalizedNode(ribSupport.buildRouteAttributeYii(this.yangTables, routeIdentifier),
+                        advertisedAttrs).getValue());
     }
 }
     }
 }
index 84ed7f8086a15607911ed8124174adfb1576dfe6..7e3ef252f3cf177f59880c648bb8e2125a21528f 100644 (file)
@@ -46,10 +46,19 @@ final class RIBSupportContextRegistryImpl implements RIBSupportContextRegistry {
         return new RIBSupportContextImpl(support, this.codecs);
     }
 
         return new RIBSupportContextImpl(support, this.codecs);
     }
 
+    @Override
+    public RIBSupport getRIBSupport(final TablesKey key) {
+        final RIBSupportContext ribSupport = getRIBSupportContext(key);
+        if (ribSupport != null) {
+            return ribSupport.getRibSupport();
+        }
+        return null;
+    }
+
     @Override
     public RIBSupportContext getRIBSupportContext(final TablesKey key) {
         final RIBSupport ribSupport = this.extensionContext.getRIBSupport(key);
     @Override
     public RIBSupportContext getRIBSupportContext(final TablesKey key) {
         final RIBSupport ribSupport = this.extensionContext.getRIBSupport(key);
-        if(ribSupport != null) {
+        if (ribSupport != null) {
             return this.contexts.getUnchecked(ribSupport);
         }
         return null;
             return this.contexts.getUnchecked(ribSupport);
         }
         return null;
@@ -58,7 +67,7 @@ final class RIBSupportContextRegistryImpl implements RIBSupportContextRegistry {
     @Override
     public RIBSupportContext getRIBSupportContext(final NodeIdentifierWithPredicates key) {
         final RIBSupport ribSupport = this.extensionContext.getRIBSupport(key);
     @Override
     public RIBSupportContext getRIBSupportContext(final NodeIdentifierWithPredicates key) {
         final RIBSupport ribSupport = this.extensionContext.getRIBSupport(key);
-        if(ribSupport != null) {
+        if (ribSupport != null) {
             return this.contexts.getUnchecked(ribSupport);
         }
         return null;
             return this.contexts.getUnchecked(ribSupport);
         }
         return null;
index f6eccdc545b6922c5e033965b95fb4fc5b0d9b7f..fe2bd8aba863141ccec04dbb45e546c899fd3e8d 100644 (file)
@@ -25,8 +25,10 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.BGPRibRoutingPolicyFactory;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
 import org.opendaylight.protocol.bgp.rib.impl.BGPPeerTrackerImpl;
 import org.opendaylight.protocol.bgp.rib.impl.CodecsRegistryImpl;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
 import org.opendaylight.protocol.bgp.rib.impl.BGPPeerTrackerImpl;
 import org.opendaylight.protocol.bgp.rib.impl.CodecsRegistryImpl;
@@ -40,6 +42,7 @@ import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBStateConsumer;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBStateConsumer;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
@@ -75,6 +78,8 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
     private final BindingCodecTreeFactory codecTreeFactory;
     private final DOMDataBroker domBroker;
     private final DOMSchemaService domSchemaService;
     private final BindingCodecTreeFactory codecTreeFactory;
     private final DOMDataBroker domBroker;
     private final DOMSchemaService domSchemaService;
+    private final BGPRibRoutingPolicyFactory policyProvider;
+    private final BindingNormalizedNodeSerializer bindingSerializer;
     private RIBImpl ribImpl;
     private ServiceRegistration<?> serviceRegistration;
     private ListenerRegistration<SchemaContextListener> schemaContextRegistration;
     private RIBImpl ribImpl;
     private ServiceRegistration<?> serviceRegistration;
     private ListenerRegistration<SchemaContextListener> schemaContextRegistration;
@@ -84,14 +89,22 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
 
     private ClusterIdentifier clusterId;
 
 
     private ClusterIdentifier clusterId;
 
-    public RibImpl(final RIBExtensionConsumerContext contextProvider, final BGPDispatcher dispatcher,
-            final BindingCodecTreeFactory codecTreeFactory, final DOMDataBroker domBroker,
-            final DOMSchemaService domSchemaService) {
+    public RibImpl(
+            final RIBExtensionConsumerContext contextProvider,
+            final BGPDispatcher dispatcher,
+            final BGPRibRoutingPolicyFactory policyProvider,
+            final BindingCodecTreeFactory codecTreeFactory,
+            final DOMDataBroker domBroker,
+            final DOMSchemaService domSchemaService,
+            final BindingNormalizedNodeSerializer bindingSerializer
+    ) {
         this.extensions = contextProvider;
         this.dispatcher = dispatcher;
         this.codecTreeFactory = codecTreeFactory;
         this.domBroker = domBroker;
         this.domSchemaService = domSchemaService;
         this.extensions = contextProvider;
         this.dispatcher = dispatcher;
         this.codecTreeFactory = codecTreeFactory;
         this.domBroker = domBroker;
         this.domSchemaService = domSchemaService;
+        this.policyProvider = policyProvider;
+        this.bindingSerializer = bindingSerializer;
     }
 
     void start(final Global global, final String instanceName, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
     }
 
     void start(final Global global, final String instanceName, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
@@ -223,6 +236,11 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
         return this.ribImpl.supportsTable(tableKey);
     }
 
         return this.ribImpl.supportsTable(tableKey);
     }
 
+    @Override
+    public BGPRibRoutingPolicy getRibPolicies() {
+        return this.ribImpl.getRibPolicies();
+    }
+
     @Override
     public BGPPeerTracker getPeerTracker() {
         return this.ribImpl.getPeerTracker();
     @Override
     public BGPPeerTracker getPeerTracker() {
         return this.ribImpl.getPeerTracker();
@@ -242,7 +260,6 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
         this.asNumber = globalConfig.getAs();
         this.routerId = globalConfig.getRouterId();
         this.clusterId = getClusterIdentifier(globalConfig);
         this.asNumber = globalConfig.getAs();
         this.routerId = globalConfig.getRouterId();
         this.clusterId = getClusterIdentifier(globalConfig);
-
         final BGPPeerTrackerImpl peerTracker = new BGPPeerTrackerImpl();
         final Map<TablesKey, PathSelectionMode> pathSelectionModes = OpenConfigMappingUtil
                 .toPathSelectionMode(this.afiSafi, tableTypeRegistry, peerTracker).entrySet()
         final BGPPeerTrackerImpl peerTracker = new BGPPeerTrackerImpl();
         final Map<TablesKey, PathSelectionMode> pathSelectionModes = OpenConfigMappingUtil
                 .toPathSelectionMode(this.afiSafi, tableTypeRegistry, peerTracker).entrySet()
@@ -250,6 +267,8 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
                 .collect(Collectors.toMap(entry ->
                         new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
 
                 .collect(Collectors.toMap(entry ->
                         new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
 
+        final BGPRibRoutingPolicy ribPolicy = this.policyProvider.buildBGPRibPolicy(this.asNumber.getValue(),
+                this.routerId, this.clusterId, RoutingPolicyUtil.getApplyPolicy(global.getApplyPolicy()));
         final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(codecTreeFactory,
                 this.extensions.getClassLoadingStrategy());
 
         final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(codecTreeFactory,
                 this.extensions.getClassLoadingStrategy());
 
@@ -262,9 +281,11 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
                 this.dispatcher,
                 codecsRegistry,
                 this.domBroker,
                 this.dispatcher,
                 codecsRegistry,
                 this.domBroker,
+                ribPolicy,
                 peerTracker,
                 toTableTypes(this.afiSafi, tableTypeRegistry),
                 peerTracker,
                 toTableTypes(this.afiSafi, tableTypeRegistry),
-                pathSelectionModes);
+                pathSelectionModes,
+                this.bindingSerializer);
     }
 
     @Override
     }
 
     @Override
diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/RoutingPolicyUtil.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/RoutingPolicyUtil.java
new file mode 100644 (file)
index 0000000..e92358f
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.impl.config;
+
+import static org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.DefaultPolicyType.ACCEPTROUTE;
+
+import java.util.Collections;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.apply.policy.group.ApplyPolicy;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.apply.policy.group.apply.policy.Config;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.apply.policy.group.apply.policy.ConfigBuilder;
+
+public final class RoutingPolicyUtil {
+
+    private static final Config DEFAULT_POLICY = new ConfigBuilder().setDefaultImportPolicy(ACCEPTROUTE)
+            .setDefaultExportPolicy(ACCEPTROUTE).setImportPolicy(Collections.emptyList())
+            .setExportPolicy(Collections.emptyList()).build();
+
+    private RoutingPolicyUtil() {
+        throw new UnsupportedOperationException();
+    }
+
+    public static Config getApplyPolicy(final ApplyPolicy applyPolicy) {
+        if (applyPolicy == null) {
+            return DEFAULT_POLICY;
+        }
+        return applyPolicy.getConfig();
+    }
+}
index ceb3270469a00238626a6e597503ab5e169a2128..3282d462d1c00728c44743d0bdf473082cf3a825 100755 (executable)
@@ -17,6 +17,7 @@ import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bgp.rib.spi.entry.AttributeBindingCodecSerializer;
 import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bgp.rib.spi.entry.AttributeBindingCodecSerializer;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
@@ -110,6 +111,13 @@ public interface RIB extends AttributeBindingCodecSerializer, RibReference {
 
     Set<TablesKey> getLocalTablesKeys();
 
 
     Set<TablesKey> getLocalTablesKeys();
 
+    /**
+     * Return Policies Container.
+     *
+     * @return policies
+     */
+    BGPRibRoutingPolicy getRibPolicies();
+
     /**
      * Returns peer tracker for the rib.
      *
     /**
      * Returns peer tracker for the rib.
      *
index d120f8b57a9497bcd3716bf1c8290f9a3bdc09bd..eb7e871a9d7090eae57430aa6d134fce27c045bd 100644 (file)
@@ -8,24 +8,39 @@
 package org.opendaylight.protocol.bgp.rib.impl.spi;
 
 import javax.annotation.Nullable;
 package org.opendaylight.protocol.bgp.rib.impl.spi;
 
 import javax.annotation.Nullable;
+import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 
 public interface RIBSupportContextRegistry {
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 
 public interface RIBSupportContextRegistry {
 
+    /**
+     * Acquire a RIB Support for a AFI/SAFI combination.
+     *
+     * @param key AFI/SAFI key
+     * @return RIBSupport instance, or null if the AFI/SAFI is
+     * not implemented.
+     */
+    @Nullable
+    RIBSupport getRIBSupport(TablesKey key);
+
     /**
      * Acquire a RIB Support Context for a AFI/SAFI combination.
     /**
      * Acquire a RIB Support Context for a AFI/SAFI combination.
+     *
      * @param key AFI/SAFI key
      * @return RIBSupport instance, or null if the AFI/SAFI is
      * @param key AFI/SAFI key
      * @return RIBSupport instance, or null if the AFI/SAFI is
-     *         not implemented.
-    */
-    @Nullable RIBSupportContext getRIBSupportContext(TablesKey key);
+     * not implemented.
+     */
+    @Nullable
+    RIBSupportContext getRIBSupportContext(TablesKey key);
 
     /**
      * Acquire a RIB Support Context for a AFI/SAFI combination.
 
     /**
      * Acquire a RIB Support Context for a AFI/SAFI combination.
+     *
      * @param key Tables key with AFI/SAFI key
      * @return RIBSupport instance, or null if the AFI/SAFI is
      * @param key Tables key with AFI/SAFI key
      * @return RIBSupport instance, or null if the AFI/SAFI is
-     *         not implemented.
-    */
-    @Nullable RIBSupportContext getRIBSupportContext(NodeIdentifierWithPredicates key);
+     * not implemented.
+     */
+    @Nullable
+    RIBSupportContext getRIBSupportContext(NodeIdentifierWithPredicates key);
 }
 }
index 6047545cd666ad888c2f0c74a14c50a23dbc59ce..fc2cb6678943922d7508d39f9d225aa965b82539 100644 (file)
     <argument ref="bgpTableTypeRegistry"/>
   </bean>
 
     <argument ref="bgpTableTypeRegistry"/>
   </bean>
 
+  <reference id="policiesProvider" interface="org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.BGPRibRoutingPolicyFactory"/>
+  <reference id="bindingNormalizedNodeSerializer" interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer" />
   <bean id="ribImpl" class="org.opendaylight.protocol.bgp.rib.impl.config.RibImpl" scope="prototype">
     <argument ref="globalBgpExtensions"/>
     <argument ref="BGPDispatcher"/>
   <bean id="ribImpl" class="org.opendaylight.protocol.bgp.rib.impl.config.RibImpl" scope="prototype">
     <argument ref="globalBgpExtensions"/>
     <argument ref="BGPDispatcher"/>
+    <argument ref="policiesProvider"/>
     <argument ref="codecTreeFactory"/>
     <argument ref="domDataBroker"/>
     <argument ref="domSchemaService"/>
     <argument ref="codecTreeFactory"/>
     <argument ref="domDataBroker"/>
     <argument ref="domSchemaService"/>
+    <argument ref="bindingNormalizedNodeSerializer"/>
   </bean>
 
   <bean id="bgpPeer" class="org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer" scope="prototype">
   </bean>
 
   <bean id="bgpPeer" class="org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer" scope="prototype">
index 4f603808fa6400e745bb79db6f61ebf51c3f8ebc..950b30042f24657cc2add7661a59a73b081a7b5b 100644 (file)
@@ -30,8 +30,6 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.junit.Before;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
 import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec;
 import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator;
 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
 import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec;
 import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator;
 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
@@ -110,7 +108,7 @@ import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public abstract class AbstractAddPathTest extends AbstractConcurrentDataBrokerTest {
+public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest {
     private static final int RETRY_TIMER = 10;
     static final String RIB_ID = "127.0.0.1";
     static final BgpId BGP_ID = new BgpId(RIB_ID);
     private static final int RETRY_TIMER = 10;
     static final String RIB_ID = "127.0.0.1";
     static final BgpId BGP_ID = new BgpId(RIB_ID);
@@ -120,7 +118,7 @@ public abstract class AbstractAddPathTest extends AbstractConcurrentDataBrokerTe
     static final Ipv4Address PEER4 = new Ipv4Address("127.0.0.5");
     static final Ipv4Address PEER5 = new Ipv4Address("127.0.0.6");
     static final Ipv4Address PEER6 = new Ipv4Address("127.0.0.7");
     static final Ipv4Address PEER4 = new Ipv4Address("127.0.0.5");
     static final Ipv4Address PEER5 = new Ipv4Address("127.0.0.6");
     static final Ipv4Address PEER6 = new Ipv4Address("127.0.0.7");
-    static final AsNumber AS_NUMBER = new AsNumber(72L);
+    static final AsNumber AS_NUMBER = new AsNumber(AS);
     static final int PORT = InetSocketAddressUtil.getRandomPort();
     static final Ipv4Prefix PREFIX1 = new Ipv4Prefix("1.1.1.1/32");
     private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier(RIB_ID);
     static final int PORT = InetSocketAddressUtil.getRandomPort();
     static final Ipv4Prefix PREFIX1 = new Ipv4Prefix("1.1.1.1/32");
     private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier(RIB_ID);
@@ -157,7 +155,7 @@ public abstract class AbstractAddPathTest extends AbstractConcurrentDataBrokerTe
 
     @Before
     public void setUp() throws Exception {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+        super.setUp();
         this.ribActivator = new RIBActivator();
         this.ribExtension = new SimpleRIBExtensionProviderContext();
 
         this.ribActivator = new RIBActivator();
         this.ribExtension = new SimpleRIBExtensionProviderContext();
 
index 03fc23604d9fcc61055b1d67f18afe8815d700a9..1dd972e6622179349808c1525c2a7a7dc0d5dcaa 100644 (file)
@@ -95,12 +95,10 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class AbstractRIBTestSetup {
+public class AbstractRIBTestSetup extends DefaultRibPoliciesMockTest {
 
     protected static final Class<? extends AddressFamily> AFI = Ipv4AddressFamily.class;
     protected static final Class<? extends SubsequentAddressFamily> SAFI = UnicastSubsequentAddressFamily.class;
 
     protected static final Class<? extends AddressFamily> AFI = Ipv4AddressFamily.class;
     protected static final Class<? extends SubsequentAddressFamily> SAFI = UnicastSubsequentAddressFamily.class;
-    protected static final QName AFI_QNAME = BindingReflections.findQName(AFI).intern();
-    protected static final QName SAFI_QNAME = BindingReflections.findQName(SAFI).intern();
     protected static final TablesKey KEY = new TablesKey(AFI, SAFI);
     protected static final QName PREFIX_QNAME = QName.create(Ipv4Route.QNAME, "prefix").intern();
     private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier("128.0.0.1");
     protected static final TablesKey KEY = new TablesKey(AFI, SAFI);
     protected static final QName PREFIX_QNAME = QName.create(Ipv4Route.QNAME, "prefix").intern();
     private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier("128.0.0.1");
@@ -162,6 +160,7 @@ public class AbstractRIBTestSetup {
 
     @Before
     public void setUp() throws Exception {
 
     @Before
     public void setUp() throws Exception {
+        super.setUp();
         mockRib();
     }
 
         mockRib();
     }
 
@@ -183,9 +182,11 @@ public class AbstractRIBTestSetup {
         doReturn(mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider)
                 .registerClusterSingletonService(any(ClusterSingletonService.class));
         this.rib = new RIBImpl(new RibId("test"), new AsNumber(5L), RIB_ID, CLUSTER_ID, context,
         doReturn(mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider)
                 .registerClusterSingletonService(any(ClusterSingletonService.class));
         this.rib = new RIBImpl(new RibId("test"), new AsNumber(5L), RIB_ID, CLUSTER_ID, context,
-                this.dispatcher, codecsRegistry, this.dom, this.peerTracker, localTables,
+                this.dispatcher, codecsRegistry, this.dom, this.policies, this.peerTracker, localTables,
                 Collections.singletonMap(new TablesKey(AFI, SAFI),
                 Collections.singletonMap(new TablesKey(AFI, SAFI),
-                        BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker)));
+                        BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker)),
+                this.mappingService
+                );
         this.rib.onGlobalContextUpdated(schemaContext);
         this.ribSupport = getRib().getRibSupportContext().getRIBSupportContext(KEY).getRibSupport();
     }
         this.rib.onGlobalContextUpdated(schemaContext);
         this.ribSupport = getRib().getRibSupportContext().getRIBSupportContext(KEY).getRibSupport();
     }
index a4173326f086198824eabb3cee980c43ae39ced2..234f407e275cce6a7fbb778cf6040e1fddd5df57 100644 (file)
@@ -57,7 +57,7 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"), AS_NUMBER, BGP_ID, null,
                 this.ribExtension, this.serverDispatcher, this.codecsRegistry,
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"), AS_NUMBER, BGP_ID, null,
                 this.ribExtension, this.serverDispatcher, this.codecsRegistry,
-            getDomBroker(), this.peerTracker, TABLES_TYPE, pathTables);
+            getDomBroker(), this.policies, this.peerTracker, TABLES_TYPE, pathTables, this.mappingService);
 
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
 
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
index 15ffd7e1b99690c8de19d51260e90909abe40b9f..3a31761d0e501ef15c05cc7c893455fbe5d2dca4 100644 (file)
@@ -44,8 +44,8 @@ public class AddPathBasePathsTest extends AbstractAddPathTest {
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"),
             AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"),
             AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
-            this.codecsRegistry, getDomBroker(), this.peerTracker, TABLES_TYPE, pathTables
-        );
+            this.codecsRegistry, getDomBroker(), this.policies, this.peerTracker, TABLES_TYPE, pathTables,
+                this.mappingService);
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
         final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT));
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
         final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT));
index 5bff0fcc52053c4a2ceea63195507e9571e20148..c87ac6e4ae8b77de98d9981973699fe59155c1bb 100644 (file)
@@ -44,7 +44,7 @@ public class AddPathNPathsTest extends AbstractAddPathTest {
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"),
             AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"),
             AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
-            this.codecsRegistry, getDomBroker(), this.peerTracker, TABLES_TYPE, pathTables);
+            this.codecsRegistry, getDomBroker(), this.policies, this.peerTracker, TABLES_TYPE,  pathTables, this.mappingService);
 
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
 
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/DefaultRibPoliciesMockTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/DefaultRibPoliciesMockTest.java
new file mode 100644 (file)
index 0000000..049da68
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.impl;
+
+import static org.mockito.Mockito.doReturn;
+
+import java.util.Collections;
+import org.junit.Before;
+import org.mockito.Mock;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.BGPRibRoutingPolicyFactoryImpl;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.BGPRibRoutingPolicyFactory;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.AbstractStatementRegistryConsumerTest;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.DefaultPolicyType;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.apply.policy.group.apply.policy.Config;
+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.types.rev130919.BgpId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
+
+public class DefaultRibPoliciesMockTest extends AbstractStatementRegistryConsumerTest {
+    protected static final long AS = 64496;
+    private final Ipv4Address bgpID = new BgpId(new Ipv4Address("127.0.0.1"));
+    private final ClusterIdentifier ci = new ClusterIdentifier(new Ipv4Address("127.0.0.1"));
+    protected BGPRibRoutingPolicy policies;
+    protected BGPRibRoutingPolicyFactory policyProvider;
+    @Mock
+    private Config config;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        doReturn(DefaultPolicyType.REJECTROUTE).when(this.config).getDefaultImportPolicy();
+        doReturn(DefaultPolicyType.REJECTROUTE).when(this.config).getDefaultExportPolicy();
+        doReturn(Collections.singletonList("default-odl-import-policy")).when(this.config).getImportPolicy();
+        doReturn(Collections.singletonList("default-odl-export-policy")).when(this.config).getExportPolicy();
+
+        this.policyProvider = new BGPRibRoutingPolicyFactoryImpl(getDataBroker(), this.statementRegistry);
+        this.policies = this.policyProvider.buildBGPRibPolicy(AS, this.bgpID, this.ci, this.config);
+    }
+}
index 2bc8de4c6cade7fc1215b646ec22f28f735b31c0..e3596a3504273e76c8954619df993d5ae31cf5f4 100755 (executable)
@@ -22,19 +22,13 @@ import java.net.InetSocketAddress;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTestCustomizer;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
 import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.protocol.bgp.inet.RIBActivator;
 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.inet.RIBActivator;
 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
@@ -49,11 +43,8 @@ import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser;
 import org.opendaylight.protocol.concepts.KeyMapping;
 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.protocol.concepts.KeyMapping;
 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.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.ipv4.routes.Ipv4Route;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.routes.ipv6.routes.Ipv6Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.routes.linkstate.routes.LinkstateRoute;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.BgpRib;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.BgpRib;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
@@ -65,10 +56,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 
 
-public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
+public class ParserToSalTest extends DefaultRibPoliciesMockTest {
 
     private static final String TEST_RIB_ID = "testRib";
     private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
 
     private static final String TEST_RIB_ID = "testRib";
     private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
@@ -80,16 +69,12 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
 
     @Mock
     private BGPDispatcher dispatcher;
 
     @Mock
     private BGPDispatcher dispatcher;
-    private BindingCodecTreeFactory codecFactory;
-
-    private DOMSchemaService schemaService;
     private BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
     private CodecsRegistryImpl codecsRegistry;
 
     @Before
     public void setUp() throws Exception {
     private BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
     private CodecsRegistryImpl codecsRegistry;
 
     @Before
     public void setUp() throws Exception {
-        super.setup();
-        MockitoAnnotations.initMocks(this);
+        super.setUp();
         final String hexMessages = "/bgp_hex.txt";
         final List<byte[]> bgpMessages = HexDumpBGPFileParser
                 .parseMessages(ParserToSalTest.class.getResourceAsStream(hexMessages));
         final String hexMessages = "/bgp_hex.txt";
         final List<byte[]> bgpMessages = HexDumpBGPFileParser
                 .parseMessages(ParserToSalTest.class.getResourceAsStream(hexMessages));
@@ -107,26 +92,10 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
 
         this.baseact.startRIBExtensionProvider(this.ext1);
         this.lsact.startRIBExtensionProvider(this.ext2);
 
         this.baseact.startRIBExtensionProvider(this.ext1);
         this.lsact.startRIBExtensionProvider(this.ext2);
-        this.codecsRegistry = CodecsRegistryImpl.create(this.codecFactory,
+        this.codecsRegistry = CodecsRegistryImpl.create(this.bindingCodecTreeFactory,
                 GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
     }
 
                 GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
     }
 
-    @Override
-    protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
-        return ImmutableList.of(
-                BindingReflections.getModuleInfo(Ipv4Route.class),
-                BindingReflections.getModuleInfo(Ipv6Route.class),
-                BindingReflections.getModuleInfo(LinkstateRoute.class));
-    }
-
-    @Override
-    protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
-        final AbstractDataBrokerTestCustomizer customizer = super.createDataBrokerTestCustomizer();
-        this.codecFactory = customizer.getBindingToNormalized();
-        this.schemaService = customizer.getSchemaService();
-        return customizer;
-    }
-
     @After
     public void tearDown() {
         this.lsact.close();
     @After
     public void tearDown() {
         this.lsact.close();
@@ -134,15 +103,15 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
     }
 
     @Test
     }
 
     @Test
-    public void testWithLinkstate() throws InterruptedException, ExecutionException, ReadFailedException {
+    public void testWithLinkstate() throws ReadFailedException {
         final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(LinkstateAddressFamily.class,
                 LinkstateSubsequentAddressFamily.class));
 
         final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID),
                 AS_NUMBER, new BgpId("127.0.0.1"), null, this.ext2, this.dispatcher,
         final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(LinkstateAddressFamily.class,
                 LinkstateSubsequentAddressFamily.class));
 
         final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID),
                 AS_NUMBER, new BgpId("127.0.0.1"), null, this.ext2, this.dispatcher,
-                this.codecsRegistry, getDomBroker(),this.peerTracker, tables,
+                this.codecsRegistry, getDomBroker(), this.policies, this.peerTracker, tables,
                 Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory
                 Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory
-                        .createBestPathSelectionStrategy(this.peerTracker)));
+                        .createBestPathSelectionStrategy(this.peerTracker)), this.mappingService);
         rib.instantiateServiceInstance();
         assertTablesExists(tables);
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
         rib.instantiateServiceInstance();
         assertTablesExists(tables);
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
@@ -154,14 +123,14 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
     }
 
     @Test
     }
 
     @Test
-    public void testWithoutLinkstate() throws InterruptedException, ExecutionException, ReadFailedException {
+    public void testWithoutLinkstate() throws ReadFailedException {
         final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class,
                 UnicastSubsequentAddressFamily.class));
         final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID,
                 null, this.ext1, this.dispatcher, this.codecsRegistry, getDomBroker(),
         final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class,
                 UnicastSubsequentAddressFamily.class));
         final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID,
                 null, this.ext1, this.dispatcher, this.codecsRegistry, getDomBroker(),
-                this.peerTracker, tables,
+                this.policies, this.peerTracker, tables,
                 Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory
                 Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory
-                        .createBestPathSelectionStrategy(this.peerTracker)));
+                        .createBestPathSelectionStrategy(this.peerTracker)), this.mappingService);
         rib.instantiateServiceInstance();
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
         assertTablesExists(tables);
         rib.instantiateServiceInstance();
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
         assertTablesExists(tables);
@@ -182,8 +151,7 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
         });
     }
 
         });
     }
 
-    private void assertTablesExists(final List<BgpTableType> expectedTables)
-            throws InterruptedException, ExecutionException, ReadFailedException {
+    private void assertTablesExists(final List<BgpTableType> expectedTables) throws ReadFailedException {
         readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
             final List<Tables> tables = bgpRib.getRib().get(0).getLocRib().getTables();
             assertFalse(tables.isEmpty());
         readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
             final List<Tables> tables = bgpRib.getRib().get(0).getLocRib().getTables();
             assertFalse(tables.isEmpty());
index 0cc82b6b17200d0511e57f597fcd8c7ec32de565..92cff2a11260712443f64edbee13ab2ea80277c4 100644 (file)
@@ -204,12 +204,13 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest {
     }
 
     @Test
     }
 
     @Test
-    public void testHandleMessageAfterException() throws InterruptedException {
+    public void testHandleMessageAfterException() {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
             BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker));
         final RIBImpl ribImpl = new RIBImpl( new RibId(RIB_ID), AS_NUMBER,
             new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.codecsRegistry,
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
             BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker));
         final RIBImpl ribImpl = new RIBImpl( new RibId(RIB_ID), AS_NUMBER,
             new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.codecsRegistry,
-            this.domBroker, this.peerTracker, ImmutableList.of(this.ipv4tt), pathTables);
+            this.domBroker, this.policies, this.peerTracker, ImmutableList.of(this.ipv4tt), pathTables,
+                this.mappingService);
         ribImpl.instantiateServiceInstance();
         ribImpl.onGlobalContextUpdated(this.schemaContext);
 
         ribImpl.instantiateServiceInstance();
         ribImpl.onGlobalContextUpdated(this.schemaContext);
 
@@ -252,12 +253,13 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest {
     }
 
     @Test
     }
 
     @Test
-    public void testUseCase1() throws InterruptedException {
+    public void testUseCase1() {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
             BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker));
         final RIBImpl ribImpl = new RIBImpl( new RibId(RIB_ID), AS_NUMBER,
             new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.codecsRegistry,
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
             BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker));
         final RIBImpl ribImpl = new RIBImpl( new RibId(RIB_ID), AS_NUMBER,
             new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.codecsRegistry,
-            this.domBroker, this.peerTracker, ImmutableList.of(this.ipv4tt), pathTables);
+            this.domBroker, this.policies, this.peerTracker, ImmutableList.of(this.ipv4tt), pathTables,
+                this.mappingService);
         ribImpl.instantiateServiceInstance();
         ribImpl.onGlobalContextUpdated(this.schemaContext);
 
         ribImpl.instantiateServiceInstance();
         ribImpl.onGlobalContextUpdated(this.schemaContext);
 
index 3fef90d95dcbf2562650c7af93f5aaf3b23cdd1b..c2695274dc32b27651c076a5b5a78eedaaf92bd7 100644 (file)
@@ -24,7 +24,6 @@ import java.util.concurrent.Executor;
 import org.junit.Before;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.junit.Before;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
@@ -33,6 +32,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.rib.impl.BGPPeerTrackerImpl;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.rib.impl.BGPPeerTrackerImpl;
+import org.opendaylight.protocol.bgp.rib.impl.DefaultRibPoliciesMockTest;
 import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
@@ -62,9 +62,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.osgi.framework.ServiceRegistration;
 
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.osgi.framework.ServiceRegistration;
 
-class AbstractConfig {
-    static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+class AbstractConfig extends DefaultRibPoliciesMockTest {
     protected static final AsNumber AS = new AsNumber(72L);
     protected static final AsNumber AS = new AsNumber(72L);
+    protected static final RibId RIB_ID = new RibId("test");
+    static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
     @Mock
     protected RIB rib;
     @Mock
     @Mock
     protected RIB rib;
     @Mock
@@ -87,12 +88,11 @@ class AbstractConfig {
     private ImportPolicyPeerTracker importPolicyPeerTracker;
     @Mock
     private DOMDataTreeChangeService dataTreeChangeService;
     private ImportPolicyPeerTracker importPolicyPeerTracker;
     @Mock
     private DOMDataTreeChangeService dataTreeChangeService;
-    protected static final RibId RIB_ID = new RibId("test");
     private BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
 
     @Before
     public void setUp() throws Exception {
     private BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+        super.setUp();
         doReturn(InstanceIdentifier.create(BgpRib.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight
                 .params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.Rib.class, new RibKey(RIB_ID))).when(this.rib)
                 .getInstanceIdentifier();
         doReturn(InstanceIdentifier.create(BgpRib.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight
                 .params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.Rib.class, new RibKey(RIB_ID))).when(this.rib)
                 .getInstanceIdentifier();
@@ -147,6 +147,7 @@ class AbstractConfig {
         doReturn("registry").when(this.bgpPeerRegistry).toString();
         doNothing().when(this.listener).close();
         doReturn(this.bgpPeerRegistry).when(this.dispatcher).getBGPPeerRegistry();
         doReturn("registry").when(this.bgpPeerRegistry).toString();
         doNothing().when(this.listener).close();
         doReturn(this.bgpPeerRegistry).when(this.dispatcher).getBGPPeerRegistry();
-        doReturn(peerTracker).when(this.rib).getPeerTracker();
+        doReturn(this.peerTracker).when(this.rib).getPeerTracker();
+        doReturn(this.policies).when(this.rib).getRibPolicies();
     }
     }
-}
+}
\ No newline at end of file
index bed3355531fdce87b43eda0c120ea47e2d179c46..c5efcc4b96778c50ee71739c80e03f751ce65988 100644 (file)
@@ -38,7 +38,7 @@ public class AppPeerTest extends AbstractConfig {
     }
 
     @Test
     }
 
     @Test
-    public void testAppPeer() throws Exception {
+    public void testAppPeer() {
         APP_PEER.start(this.rib, this.neighbor, this.tableTypeRegistry);
         Mockito.verify(this.rib).getYangRibId();
         Mockito.verify(this.rib).getService();
         APP_PEER.start(this.rib, this.neighbor, this.tableTypeRegistry);
         Mockito.verify(this.rib).getYangRibId();
         Mockito.verify(this.rib).getService();
@@ -46,7 +46,7 @@ public class AppPeerTest extends AbstractConfig {
 
         APP_PEER.instantiateServiceInstance();
         Mockito.verify(this.rib, times(2)).getYangRibId();
 
         APP_PEER.instantiateServiceInstance();
         Mockito.verify(this.rib, times(2)).getYangRibId();
-        Mockito.verify(this.rib).getRibSupportContext();
+        Mockito.verify(this.rib, times(2)).getRibSupportContext();
         Mockito.verify(this.rib, times(2)).getLocalTablesKeys();
         Mockito.verify(this.domTx).newWriteOnlyTransaction();
 
         Mockito.verify(this.rib, times(2)).getLocalTablesKeys();
         Mockito.verify(this.domTx).newWriteOnlyTransaction();
 
index 8dd5d97612a30e30a66505a6d4881be1c0c1cedd..5acfc5ae3a2f2b3779bd38d7cc9f88ce729fe0a4 100644 (file)
@@ -8,46 +8,29 @@
 
 package org.opendaylight.protocol.bgp.rib.impl.config;
 
 
 package org.opendaylight.protocol.bgp.rib.impl.config;
 
-import static org.junit.Assert.assertEquals;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.DELETE;
-import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.WRITE;
 import static org.opendaylight.protocol.bgp.rib.impl.config.AbstractConfig.TABLES_KEY;
 import static org.opendaylight.protocol.bgp.rib.impl.config.AbstractConfig.TABLES_KEY;
-import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createAddPath;
-import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createConfig;
-import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createRR;
-import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createTimers;
-import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createTransport;
-import static org.powermock.api.mockito.PowerMockito.spy;
-import static org.powermock.api.mockito.PowerMockito.verifyPrivate;
-
-import com.google.common.primitives.Shorts;
-import com.google.common.util.concurrent.CheckedFuture;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
+import static org.opendaylight.protocol.bgp.rib.impl.config.RIBTestsUtil.createGlobalIpv4;
+import static org.opendaylight.protocol.bgp.rib.impl.config.RIBTestsUtil.createGlobalIpv6;
+import static org.opendaylight.protocol.bgp.rib.impl.config.RIBTestsUtil.createNeighbors;
+import static org.opendaylight.protocol.bgp.rib.impl.config.RIBTestsUtil.createNeighborsNoRR;
+import static org.opendaylight.protocol.util.CheckUtil.checkPresentConfiguration;
+
 import java.util.Dictionary;
 import java.util.Optional;
 import java.util.Dictionary;
 import java.util.Optional;
+import java.util.concurrent.ExecutionException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
@@ -56,43 +39,22 @@ import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvid
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.rib.impl.DefaultRibPoliciesMockTest;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.InstanceType;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.InstanceType;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
-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.AfiSafis;
-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.global.base.Config;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.ConfigBuilder;
-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.top.Bgp;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
 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.bgp.Global;
-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.Neighbors;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.AfiSafiType;
-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.network.instance.rev151018.network.instance.top.NetworkInstances;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.NetworkInstances;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstanceBuilder;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstanceKey;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstanceKey;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
-import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.ProtocolsBuilder;
 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.ProtocolKey;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP;
 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.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.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.Protocol1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.Protocol1;
-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.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 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.concepts.ListenerRegistration;
@@ -101,34 +63,28 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.container.BlueprintContainer;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.container.BlueprintContainer;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({BgpDeployerImpl.class})
-public class BgpDeployerImplTest {
-    private static final String NETWORK_INSTANCE_NAME = "network-test";
-    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());
+public class BgpDeployerImplTest extends DefaultRibPoliciesMockTest {
     private static final BgpTableType TABLE_TYPE = new BgpTableTypeImpl(Ipv4AddressFamily.class,
             UnicastSubsequentAddressFamily.class);
     private static final BgpTableType TABLE_TYPE = new BgpTableTypeImpl(Ipv4AddressFamily.class,
             UnicastSubsequentAddressFamily.class);
+    private static final String NETWORK_INSTANCE_NAME = "network-test";
+    private static final KeyedInstanceIdentifier<NetworkInstance, NetworkInstanceKey> NETWORK_II =
+            InstanceIdentifier.create(NetworkInstances.class)
+                    .child(NetworkInstance.class, new NetworkInstanceKey(NETWORK_INSTANCE_NAME));
+    private static final String KEY = "bgp";
+    private static final InstanceIdentifier<Bgp> BGP_II = NETWORK_II.child(Protocols.class)
+            .child(Protocol.class, new ProtocolKey(BGP.class, KEY))
+            .augmentation(Protocol1.class).child(Bgp.class);
+    private static final InstanceIdentifier<Global> GLOBAL_II = BGP_II.child(Global.class);
+    private static final InstanceIdentifier<Neighbors> NEIGHBORS_II = BGP_II.child(Neighbors.class);
 
 
-    private static final short SHORT = 0;
-
-    @Mock
-    private DataObjectModification<?> dObject;
     @Mock
     private BlueprintContainer blueprintContainer;
     @Mock
     private BundleContext bundleContext;
     @Mock
     @Mock
     private BlueprintContainer blueprintContainer;
     @Mock
     private BundleContext bundleContext;
     @Mock
-    private DataBroker dataBroker;
-    @Mock
     private BGPTableTypeRegistryConsumer tableTypeRegistry;
     @Mock
     private BGPTableTypeRegistryConsumer tableTypeRegistry;
     @Mock
-    private WriteTransaction wTx;
-    @Mock
     private DataTreeModification<Bgp> modification;
     @Mock
     private ListenerRegistration<?> dataTreeRegistration;
     private DataTreeModification<Bgp> modification;
     @Mock
     private ListenerRegistration<?> dataTreeRegistration;
@@ -136,247 +92,139 @@ public class BgpDeployerImplTest {
     private ServiceRegistration<?> registration;
     @Mock
     private ClusterSingletonServiceProvider singletonServiceProvider;
     private ServiceRegistration<?> registration;
     @Mock
     private ClusterSingletonServiceProvider singletonServiceProvider;
-
-    private Collection<DataTreeModification<Bgp>> collection = Collections.singleton(this.modification);
-
-    private static Neighbor createNeighborExpected(final Class<? extends AfiSafiType> afi) {
-        return new NeighborBuilder()
-                .setAfiSafis(createAfiSafi(afi))
-                .setConfig(createConfig())
-                .setNeighborAddress(IPADDRESS)
-                .setRouteReflector(createRR())
-                .setTimers(createTimers())
-                .setTransport(createTransport())
-                .setAddPaths(createAddPath())
-                .build();
-    }
-
-    private static org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafis createAfiSafi(final Class<? extends AfiSafiType> afi) {
-        return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder()
-                .setAfiSafi(Collections.singletonList(new AfiSafiBuilder().setAfiSafiName(afi)
-                        .addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(true).setSendMax(SHORT).build()).build())).build();
-    }
+    private BgpDeployerImpl deployer;
 
     @Before
     public void setUp() throws Exception {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-        final DOMDataBroker domDataBroker = mock(DOMDataBroker.class);
+        super.setUp();
 
 
-        doReturn(this.wTx).when(this.dataBroker).newWriteOnlyTransaction();
         doReturn("mapping").when(this.tableTypeRegistry).toString();
         doReturn("mapping").when(this.tableTypeRegistry).toString();
-
-        doReturn(null).when(domDataBroker).createTransactionChain(any());
-        doReturn(Collections.singletonMap(DOMDataTreeChangeService.class, mock(DOMDataBrokerExtension.class)))
-                .when(domDataBroker).getSupportedExtensions();
-
         doReturn(Optional.of(TABLE_TYPE)).when(this.tableTypeRegistry).getTableType(any());
         doReturn(Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
         doReturn(Optional.of(TABLE_TYPE)).when(this.tableTypeRegistry).getTableType(any());
         doReturn(Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
-        Mockito.doNothing().when(this.registration).unregister();
-        doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any()
-                , any(Dictionary.class));
-        doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()), any()
-                , any(Dictionary.class));
-
-
-        Mockito.doNothing().when(this.wTx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
-                any(NetworkInstance.class));
-        final CheckedFuture<?, ?> future = mock(CheckedFuture.class);
-        doReturn(future).when(this.wTx).submit();
-        Mockito.doNothing().when(future).addListener(any(), any());
-        doReturn(this.dataTreeRegistration).when(this.dataBroker).registerDataTreeChangeListener(any(), any());
-        Mockito.doNothing().when(this.dataTreeRegistration).close();
-
-        final InstanceIdentifier<Bgp> bgpIID = InstanceIdentifier.create(NetworkInstances.class)
-                .child(NetworkInstance.class, new NetworkInstanceKey(NETWORK_INSTANCE_NAME)).child(Protocols.class)
-                .child(Protocol.class, new ProtocolKey(BGP.class, "bgp"))
-                .augmentation(Protocol1.class).child(Bgp.class);
-
-        doReturn(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, bgpIID))
-                .when(this.modification).getRootPath();
-        doReturn(this.dObject).when(this.modification).getRootNode();
-        doReturn("bgpPeer").when(this.modification).toString();
-
-        doReturn(Collections.singleton(this.dObject)).when(this.dObject).getModifiedChildren();
-        doReturn("dObject").when(this.dObject).toString();
+        doNothing().when(this.registration).unregister();
+        doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()),
+                any(), any(Dictionary.class));
+        doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()),
+                any(), any(Dictionary.class));
 
 
+        doNothing().when(this.dataTreeRegistration).close();
+        doReturn("bgpPeer").when(this.modification).toString();
         final RIBExtensionConsumerContext extension = mock(RIBExtensionConsumerContext.class);
         final RIBExtensionConsumerContext extension = mock(RIBExtensionConsumerContext.class);
-        doReturn(mock(GeneratedClassLoadingStrategy.class)).when(extension).getClassLoadingStrategy();
+        doReturn(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()).when(extension).getClassLoadingStrategy();
 
         final ClusterSingletonServiceRegistration serviceRegistration = mock(ClusterSingletonServiceRegistration.class);
         doReturn(serviceRegistration).when(this.singletonServiceProvider).registerClusterSingletonService(any());
 
         final ClusterSingletonServiceRegistration serviceRegistration = mock(ClusterSingletonServiceRegistration.class);
         doReturn(serviceRegistration).when(this.singletonServiceProvider).registerClusterSingletonService(any());
-        Mockito.doNothing().when(serviceRegistration).close();
+        doNothing().when(serviceRegistration).close();
 
         final DOMSchemaService schemaService = mock(DOMSchemaService.class);
 
         final DOMSchemaService schemaService = mock(DOMSchemaService.class);
-        Mockito.doNothing().when(this.dataTreeRegistration).close();
+        doNothing().when(this.dataTreeRegistration).close();
 
         doReturn(this.dataTreeRegistration).when(schemaService).registerSchemaContextListener(any());
 
 
         doReturn(this.dataTreeRegistration).when(schemaService).registerSchemaContextListener(any());
 
-        final RibImpl ribImpl = new RibImpl(extension, mock(BGPDispatcher.class), mock(BindingCodecTreeFactory.class),
-                domDataBroker, schemaService);
+        final RibImpl ribImpl = new RibImpl(extension, mock(BGPDispatcher.class), this.policyProvider,
+                mock(BindingCodecTreeFactory.class), getDomBroker(), schemaService, this.mappingService);
         doReturn(ribImpl).when(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
 
         doReturn(ribImpl).when(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
 
-        final BgpPeer bgpPeer = new BgpPeer(mock(RpcProviderRegistry.class));
-        doReturn(bgpPeer).when(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
-        this.collection = Collections.singleton(this.modification);
+        doReturn(new BgpPeer(mock(RpcProviderRegistry.class)))
+                .when(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
+
+        this.deployer = new BgpDeployerImpl(NETWORK_INSTANCE_NAME, this.singletonServiceProvider,
+                this.blueprintContainer, this.bundleContext, getDataBroker(), this.tableTypeRegistry);
     }
 
     @Test
     public void testDeployerRib() throws Exception {
     }
 
     @Test
     public void testDeployerRib() throws Exception {
-        doReturn(Global.class).when(this.dObject).getDataType();
-        final BgpDeployerImpl deployer = new BgpDeployerImpl(NETWORK_INSTANCE_NAME, this.singletonServiceProvider,
-                this.blueprintContainer, this.bundleContext, this.dataBroker, this.tableTypeRegistry);
-        final BgpDeployerImpl spyDeployer = spy(deployer);
         deployer.init();
         deployer.init();
-        configureGlobal(IPV4UNICAST.class);
-        doReturn(WRITE).when(this.dObject).getModificationType();
-
-        final KeyedInstanceIdentifier<NetworkInstance, NetworkInstanceKey> networkInstanceIId =
-                InstanceIdentifier.create(NetworkInstances.class)
-                        .child(NetworkInstance.class, new NetworkInstanceKey(NETWORK_INSTANCE_NAME));
-        final NetworkInstance netII = new NetworkInstanceBuilder()
-                .setName(networkInstanceIId.firstKeyOf(NetworkInstance.class).getName())
-                .setProtocols(new ProtocolsBuilder().build()).build();
-        verify(this.wTx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), eq(netII));
-        verify(this.dataBroker).registerDataTreeChangeListener(any(DataTreeIdentifier.class),
-                any(BgpDeployerImpl.class));
-
-        assertEquals(this.tableTypeRegistry, spyDeployer.getTableTypeRegistry());
-
-        spyDeployer.onDataTreeChanged(this.collection);
-        verifyPrivate(spyDeployer).invoke("onGlobalChanged", any(DataObjectModification.class),
-                any(InstanceIdentifier.class));
+        checkPresentConfiguration(getDataBroker(), NETWORK_II);
+        createRib(createGlobalIpv4());
+
         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
         verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
         verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
-        verify(spyDeployer).onDataTreeChanged(any(Collection.class));
 
         //change with same rib already existing
 
         //change with same rib already existing
-        spyDeployer.onDataTreeChanged(this.collection);
-        verifyPrivate(spyDeployer, times(2)).invoke("onGlobalChanged",
-                any(DataObjectModification.class), any(InstanceIdentifier.class));
+        createRib(createGlobalIpv4());
         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
         verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
         verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
-        verify(spyDeployer, times(2)).onDataTreeChanged(any(Collection.class));
 
         //Update for existing rib
 
         //Update for existing rib
-        configureGlobal(IPV6UNICAST.class);
-        spyDeployer.onDataTreeChanged(this.collection);
-        verifyPrivate(spyDeployer, times(3)).invoke("onGlobalChanged",
-                any(DataObjectModification.class), any(InstanceIdentifier.class));
+        createRib(createGlobalIpv6());
+
         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
         verify(this.bundleContext, times(2)).registerService(eq(InstanceType.RIB.getServices()),
                 any(), any(Dictionary.class));
         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
         verify(this.bundleContext, times(2)).registerService(eq(InstanceType.RIB.getServices()),
                 any(), any(Dictionary.class));
-        verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
         verify(this.dataTreeRegistration).close();
         verify(this.registration).unregister();
         verify(this.dataTreeRegistration).close();
         verify(this.registration).unregister();
-        verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
 
         //Delete for existing rib
 
         //Delete for existing rib
-        doReturn(DELETE).when(this.dObject).getModificationType();
+        deleteRib();
 
 
-        spyDeployer.onDataTreeChanged(this.collection);
-        verifyPrivate(spyDeployer, times(4)).invoke("onGlobalChanged",
-                any(DataObjectModification.class), any(InstanceIdentifier.class));
         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
         verify(this.bundleContext, times(2))
                 .registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
         verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
         verify(this.bundleContext, times(2))
                 .registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
-        verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
         verify(this.dataTreeRegistration, times(2)).close();
         verify(this.registration, times(2)).unregister();
         verify(this.dataTreeRegistration, times(2)).close();
         verify(this.registration, times(2)).unregister();
-        verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
 
         deployer.close();
     }
 
 
         deployer.close();
     }
 
-    private void configureGlobal(final Class<? extends AfiSafiType> afi) {
-        final Config config = new ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build();
-        final ArrayList<AfiSafi> afiSafiList = new ArrayList<>();
-        afiSafiList.add(new AfiSafiBuilder().setAfiSafiName(afi).addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true)
-                .setSendMax(Shorts.checkedCast(0L)).build()).build());
-        final AfiSafis afiSafi = new AfiSafisBuilder().setAfiSafi(afiSafiList).build();
-        doReturn(new GlobalBuilder().setConfig(config).setAfiSafis(afiSafi).build()).when(this.dObject).getDataAfter();
-    }
-
     /**
      * Test create Rib
      */
     @Test
     public void testDeployerCreateNeighbor() throws Exception {
     /**
      * Test create Rib
      */
     @Test
     public void testDeployerCreateNeighbor() throws Exception {
-
-        final BgpDeployerImpl deployer = new BgpDeployerImpl(NETWORK_INSTANCE_NAME, this.singletonServiceProvider,
-                this.blueprintContainer, this.bundleContext, this.dataBroker, this.tableTypeRegistry);
-        final BgpDeployerImpl spyDeployer = spy(deployer);
         deployer.init();
         deployer.init();
-        //First create Rib
-        doReturn(Global.class).when(this.dObject).getDataType();
-        doReturn(WRITE).when(this.dObject).getModificationType();
-        configureGlobal(IPV4UNICAST.class);
-
-        spyDeployer.onDataTreeChanged(this.collection);
-        verifyPrivate(spyDeployer).invoke("onGlobalChanged", any(DataObjectModification.class),
-                any(InstanceIdentifier.class));
-        verify(this.blueprintContainer).getComponentInstance(eq("ribImpl"));
-        verify(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any(), any(Dictionary.class));
-        verify(spyDeployer).onDataTreeChanged(any(Collection.class));
-
-        doReturn(Neighbors.class).when(this.dObject).getDataType();
-        doReturn(WRITE).when(this.dObject).getModificationType();
-        configureNeighbor(IPV4UNICAST.class);
-
-        final KeyedInstanceIdentifier<NetworkInstance, NetworkInstanceKey> networkInstanceIId =
-                InstanceIdentifier.create(NetworkInstances.class)
-                        .child(NetworkInstance.class, new NetworkInstanceKey(NETWORK_INSTANCE_NAME));
-        final NetworkInstance netII = new NetworkInstanceBuilder()
-                .setName(networkInstanceIId.firstKeyOf(NetworkInstance.class).getName())
-                .setProtocols(new ProtocolsBuilder().build()).build();
-        verify(this.wTx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), eq(netII));
-        verify(this.dataBroker)
-                .registerDataTreeChangeListener(any(DataTreeIdentifier.class), any(BgpDeployerImpl.class));
-
-        assertEquals(this.tableTypeRegistry, spyDeployer.getTableTypeRegistry());
-
-        spyDeployer.onDataTreeChanged(this.collection);
-        verify(spyDeployer, times(2)).onDataTreeChanged(any(Collection.class));
-        verifyPrivate(spyDeployer).invoke("onNeighborsChanged",
-                any(DataObjectModification.class), any(InstanceIdentifier.class));
+        checkPresentConfiguration(getDataBroker(), NETWORK_II);
+
+        createRib(createGlobalIpv4());
+        createNeighbor(createNeighbors());
         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
         verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()),
                 any(BgpPeer.class), any(Dictionary.class));
 
         //change with same peer already existing
         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
         verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()),
                 any(BgpPeer.class), any(Dictionary.class));
 
         //change with same peer already existing
-        spyDeployer.onDataTreeChanged(this.collection);
-        verify(spyDeployer, times(3)).onDataTreeChanged(any(Collection.class));
-        verifyPrivate(spyDeployer, times(2)).invoke("onNeighborsChanged",
-                any(DataObjectModification.class), any(InstanceIdentifier.class));
+        createNeighbor(createNeighbors());
         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
         verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()),
                 any(BgpPeer.class), any(Dictionary.class));
 
         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
         verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()),
                 any(BgpPeer.class), any(Dictionary.class));
 
-        //Update for existing rib
-        configureNeighbor(IPV6UNICAST.class);
-        spyDeployer.onDataTreeChanged(this.collection);
-        verify(spyDeployer, times(4)).onDataTreeChanged(any(Collection.class));
-        verifyPrivate(spyDeployer, times(3)).invoke("onNeighborsChanged",
-                any(DataObjectModification.class), any(InstanceIdentifier.class));
+        //Update for peer
+        createNeighbor(createNeighborsNoRR());
+
         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
         verify(this.bundleContext, times(2))
                 .registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
         verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
         verify(this.bundleContext, times(2))
                 .registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
+        verify(this.registration).unregister();
 
 
+        deleteNeighbors();
         //Delete existing Peer
         //Delete existing Peer
-        doReturn(DELETE).when(this.dObject).getModificationType();
-
-        spyDeployer.onDataTreeChanged(this.collection);
-        verify(spyDeployer, times(5)).onDataTreeChanged(any(Collection.class));
-        verify(this.dObject).getDataBefore();
-        verifyPrivate(spyDeployer, times(4)).invoke("onNeighborsChanged",
-                any(DataObjectModification.class), any(InstanceIdentifier.class));
         verify(this.bundleContext, times(2))
                 .registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
         verify(this.bundleContext, times(2))
                 .registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
+        verify(this.registration, times(2)).unregister();
 
         deployer.close();
     }
 
 
         deployer.close();
     }
 
-    private void configureNeighbor(final Class<? extends AfiSafiType> afi) {
-        doReturn(createNeighborExpected(afi)).when(this.dObject).getDataAfter();
-        doReturn(createNeighborExpected(afi)).when(this.dObject).getDataBefore();
+    private void createRib(final Global global) throws ExecutionException, InterruptedException {
+        final WriteTransaction wr = getDataBroker().newWriteOnlyTransaction();
+        wr.put(LogicalDatastoreType.CONFIGURATION, GLOBAL_II, global, true);
+        wr.submit().get();
+    }
+
+    private void deleteRib() throws ExecutionException, InterruptedException {
+        final WriteTransaction wr = getDataBroker().newWriteOnlyTransaction();
+        wr.delete(LogicalDatastoreType.CONFIGURATION, BGP_II);
+        wr.submit().get();
+    }
+
+    private void createNeighbor(final Neighbors neighbors) throws ExecutionException, InterruptedException {
+        final WriteTransaction wr = getDataBroker().newWriteOnlyTransaction();
+        wr.put(LogicalDatastoreType.CONFIGURATION, NEIGHBORS_II, neighbors, true);
+        wr.submit().get();
+    }
+
+    private void deleteNeighbors() throws ExecutionException, InterruptedException {
+        final WriteTransaction wr = getDataBroker().newWriteOnlyTransaction();
+        wr.delete(LogicalDatastoreType.CONFIGURATION, NEIGHBORS_II);
+        wr.submit().get();
     }
 }
\ No newline at end of file
     }
 }
\ No newline at end of file
diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/RIBTestsUtil.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/RIBTestsUtil.java
new file mode 100644 (file)
index 0000000..e426b6a
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.impl.config;
+
+import static org.opendaylight.protocol.bgp.rib.impl.config.AbstractConfig.AS;
+import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.NEIGHBOR_ADDRESS;
+import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createAddPath;
+import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createAfiSafi;
+import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createConfig;
+import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createNeighborExpected;
+import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createTimers;
+import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createTransport;
+
+import com.google.common.primitives.Shorts;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+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.global.base.ConfigBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.StateBuilder;
+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.top.bgp.Global;
+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.Neighbors;
+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.types.rev151009.IPV4UNICAST;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
+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.openconfig.extensions.rev171207.AfiSafi2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.AfiSafi2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
+
+public final class RIBTestsUtil {
+    static final Ipv4Address BGP_ID = new BgpId(new Ipv4Address("127.0.0.1"));
+    private static final List<AfiSafi> AFISAFIS_IPV4 = new ArrayList<>();
+    private static final List<AfiSafi> AFISAFIS_IPV6 = new ArrayList<>();
+    private static final Long ALL_PATHS = 0L;
+
+    static {
+        AFISAFIS_IPV4.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+                .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true)
+                        .setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+    }
+
+    static {
+        AFISAFIS_IPV6.add(new AfiSafiBuilder().setAfiSafiName(IPV6UNICAST.class)
+                .addAugmentation(AfiSafi2.class, new AfiSafi2Builder().setReceive(true)
+                        .setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
+    }
+
+    private RIBTestsUtil() {
+        throw new UnsupportedOperationException();
+    }
+
+
+    public static Global createGlobalIpv4() {
+        return new GlobalBuilder()
+                .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS_IPV4).build())
+                .setConfig(new ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build())
+                .setState(new StateBuilder().setAs(AS).build())
+                .build();
+    }
+
+    public static Global createGlobalIpv6() {
+        return new GlobalBuilder()
+                .setAfiSafis(new AfiSafisBuilder().setAfiSafi(AFISAFIS_IPV6).build())
+                .setConfig(new ConfigBuilder().setAs(AS).setRouterId(BGP_ID).build())
+                .setState(new StateBuilder().setAs(AS).build())
+                .build();
+    }
+
+    public static Neighbors createNeighbors() {
+        return new NeighborsBuilder()
+                .setNeighbor(Collections.singletonList(createNeighbor()))
+                .build();
+    }
+
+    private static Neighbor createNeighbor() {
+        return createNeighborExpected(NEIGHBOR_ADDRESS);
+    }
+
+    public static Neighbors createNeighborsNoRR() {
+        return new NeighborsBuilder()
+                .setNeighbor(Collections.singletonList(createNeighborNoRR()))
+                .build();
+    }
+
+    private static Neighbor createNeighborNoRR() {
+        return new NeighborBuilder()
+                .setAfiSafis(createAfiSafi())
+                .setConfig(createConfig())
+                .setNeighborAddress(NEIGHBOR_ADDRESS)
+                .setTimers(createTimers())
+                .setTransport(createTransport())
+                .setAddPaths(createAddPath())
+                .build();
+    }
+}
index 8a779ba34adbae8ea4941655d881db083d7ba2a4..500b0eab0c05b1cbbd938eeb4b8ed344622ac037 100644 (file)
@@ -106,9 +106,15 @@ public class RibImplTest extends AbstractConfig {
     }
 
     @Test
     }
 
     @Test
-    public void testRibImpl() throws Exception {
-        final RibImpl ribImpl = new RibImpl(this.extension, this.dispatcher,
-                this.bindingCodecTreeFactory, this.domDataBroker, this.domSchemaService);
+    public void testRibImpl() {
+        final RibImpl ribImpl = new RibImpl(
+                this.extension,
+                this.dispatcher,
+                this.policyProvider,
+                this.bindingCodecTreeFactory,
+                this.domDataBroker,
+                this.domSchemaService,
+                this.mappingService);
         ribImpl.setServiceRegistration(this.serviceRegistration);
         ribImpl.start(createGlobal(), "rib-test", this.tableTypeRegistry);
         verify(this.extension).getClassLoadingStrategy();
         ribImpl.setServiceRegistration(this.serviceRegistration);
         ribImpl.start(createGlobal(), "rib-test", this.tableTypeRegistry);
         verify(this.extension).getClassLoadingStrategy();
index 0a7bebcbfe648e31b98163355bc632a7092b40c7..37caa026088cd03fab32e9fcafbd38a51f7a39e2 100644 (file)
@@ -61,13 +61,13 @@ import org.slf4j.LoggerFactory;
 
 @Beta
 public abstract class AbstractRIBSupport implements RIBSupport {
 
 @Beta
 public abstract class AbstractRIBSupport implements RIBSupport {
+    public static final String ROUTE_KEY = "route-key";
     private static final Logger LOG = LoggerFactory.getLogger(AbstractRIBSupport.class);
     private static final NodeIdentifier ADVERTISED_ROUTES = new NodeIdentifier(AdvertizedRoutes.QNAME);
     private static final NodeIdentifier WITHDRAWN_ROUTES = new NodeIdentifier(WithdrawnRoutes.QNAME);
     private static final NodeIdentifier DESTINATION_TYPE = new NodeIdentifier(DestinationType.QNAME);
     private static final NodeIdentifier ROUTES = new NodeIdentifier(Routes.QNAME);
     private static final ApplyRoute DELETE_ROUTE = new DeleteRoute();
     private static final Logger LOG = LoggerFactory.getLogger(AbstractRIBSupport.class);
     private static final NodeIdentifier ADVERTISED_ROUTES = new NodeIdentifier(AdvertizedRoutes.QNAME);
     private static final NodeIdentifier WITHDRAWN_ROUTES = new NodeIdentifier(WithdrawnRoutes.QNAME);
     private static final NodeIdentifier DESTINATION_TYPE = new NodeIdentifier(DestinationType.QNAME);
     private static final NodeIdentifier ROUTES = new NodeIdentifier(Routes.QNAME);
     private static final ApplyRoute DELETE_ROUTE = new DeleteRoute();
-    public static final String ROUTE_KEY = "route-key";
     private final NodeIdentifier routesContainerIdentifier;
     private final NodeIdentifier routesListIdentifier;
     private final NodeIdentifier routeAttributesIdentifier;
     private final NodeIdentifier routesContainerIdentifier;
     private final NodeIdentifier routesListIdentifier;
     private final NodeIdentifier routeAttributesIdentifier;
@@ -178,7 +178,7 @@ public abstract class AbstractRIBSupport implements RIBSupport {
      * Build MpReachNlri object from DOM representation.
      *
      * @param routes Collection of MapEntryNode DOM representation of routes
      * Build MpReachNlri object from DOM representation.
      *
      * @param routes Collection of MapEntryNode DOM representation of routes
-     * @param hop CNextHop as it was parsed from Attributes, to be included in MpReach object
+     * @param hop    CNextHop as it was parsed from Attributes, to be included in MpReach object
      * @return MpReachNlri
      */
     private MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
      * @return MpReachNlri
      */
     private MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
@@ -234,13 +234,13 @@ public abstract class AbstractRIBSupport implements RIBSupport {
     /**
      * Given the destination as ContainerNode, implementation needs to parse the DOM model
      * from this point onward:
     /**
      * Given the destination as ContainerNode, implementation needs to parse the DOM model
      * from this point onward:
-     *
+     * <p>
      * {@code /bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type}
      * and delete the routes from its RIBs.
      *
      * {@code /bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type}
      * and delete the routes from its RIBs.
      *
-     * @param tx DOMDataWriteTransaction to be passed into implementation
-     * @param tablePath YangInstanceIdentifier to be passed into implementation
-     * @param destination ContainerNode DOM representation of NLRI in Update message
+     * @param tx           DOMDataWriteTransaction to be passed into implementation
+     * @param tablePath    YangInstanceIdentifier to be passed into implementation
+     * @param destination  ContainerNode DOM representation of NLRI in Update message
      * @param routesNodeId NodeIdentifier
      */
     private void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
      * @param routesNodeId NodeIdentifier
      */
     private void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
@@ -251,18 +251,18 @@ public abstract class AbstractRIBSupport implements RIBSupport {
     /**
      * Given the destination as ContainerNode, implementation needs to parse the DOM model
      * from this point onward:
     /**
      * Given the destination as ContainerNode, implementation needs to parse the DOM model
      * from this point onward:
-     *
+     * <p>
      * {@code /bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type}
      * and put the routes to its RIBs.
      *
      * {@code /bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type}
      * and put the routes to its RIBs.
      *
-     * @param tx DOMDataWriteTransaction to be passed into implementation
-     * @param tablePath YangInstanceIdentifier to be passed into implementation
-     * @param destination ContainerNode DOM representation of NLRI in Update message
-     * @param attributes ContainerNode to be passed into implementation
+     * @param tx           DOMDataWriteTransaction to be passed into implementation
+     * @param tablePath    YangInstanceIdentifier to be passed into implementation
+     * @param destination  ContainerNode DOM representation of NLRI in Update message
+     * @param attributes   ContainerNode to be passed into implementation
      * @param routesNodeId NodeIdentifier
      */
     private void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
      * @param routesNodeId NodeIdentifier
      */
     private void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
-        final ContainerNode destination, final ContainerNode attributes, final NodeIdentifier routesNodeId) {
+            final ContainerNode destination, final ContainerNode attributes, final NodeIdentifier routesNodeId) {
         processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
     }
 
         processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
     }
 
index c14b0e6581c3162733157768c813102e301cf8cd..f1e0c8fbcee62d26c1b39de7d5c948bfb8a4b963 100644 (file)
             <type>xml</type>
             <classifier>features</classifier>
         </dependency>
             <type>xml</type>
             <classifier>features</classifier>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>odl-bgpcep-bgp-openconfig-rp-impl</artifactId>
+            <type>xml</type>
+            <classifier>features</classifier>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>odl-mdsal-broker</artifactId>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>odl-mdsal-broker</artifactId>