Bug 2893 - Make ClusterIdentifier configurable 52/17152/4
authorLadislav Borak <lborak@cisco.com>
Thu, 26 Mar 2015 12:37:38 +0000 (13:37 +0100)
committerLadislav Borak <lborak@cisco.com>
Thu, 26 Mar 2015 15:39:03 +0000 (16:39 +0100)
Change-Id: I4c47517087ae632a9f174f5334df486a1ad69ae2
Signed-off-by: Ladislav Borak <lborak@cisco.com>
bgp/controller-config/src/main/resources/initial/41-bgp-example.xml
bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/RIBImplModule.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
bgp/rib-impl/src/main/yang/odl-bgp-rib-impl-cfg.yang
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/AbstractRIBImplModuleTest.java
bgp/rib-impl/src/test/java/org/opendaylight/controller/config/yang/bgp/rib/impl/RIBImplModuleTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ApplicationPeerTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/ParserToSalTest.java

index d33d6e6a322f34419dc7602397bfaeb1681c5663..ecade95933e64549a8e355a27dad85846ad2ef38 100644 (file)
                     <rib-id>example-bgp-rib</rib-id>
                     <local-as>64496</local-as>
                     <bgp-rib-id>192.0.2.2</bgp-rib-id>
+                    <!-- if cluster-id is not present, it's value is the same as bgp-id -->
+                    <!-- <cluster-id>192.0.2.3</cluster-id> -->
                     <local-table>
                         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:bgp:rib:impl">prefix:bgp-table-type</type>
                         <name>ipv4-unicast</name>
index 4822b8e58ddcc0a6c9a77a0a1420fb0defb154e0..ec69224bb87dd5592dadb643868a6aea0aa5ed12 100644 (file)
@@ -47,11 +47,12 @@ public final class RIBImplModule extends org.opendaylight.controller.config.yang
         JmxAttributeValidationException.checkNotNull(getTcpReconnectStrategy(), IS_NOT_SET, tcpReconnectStrategyJmxAttribute);
         JmxAttributeValidationException.checkNotNull(getSessionReconnectStrategy(), IS_NOT_SET, sessionReconnectStrategyJmxAttribute);
         JmxAttributeValidationException.checkNotNull(getLocalTable(), IS_NOT_SET, localTableJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getClusterId(), IS_NOT_SET, clusterIdJmxAttribute);
     }
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        return new RIBImpl(getRibId(), new AsNumber(getLocalAs()), getBgpRibId(), getExtensionsDependency(),
+        return new RIBImpl(getRibId(), new AsNumber(getLocalAs()), getBgpRibId(), getClusterId(), getExtensionsDependency(),
             getBgpDispatcherDependency(), getTcpReconnectStrategyDependency(), getCodecTreeFactoryDependency(), getSessionReconnectStrategyDependency(),
             getDataProviderDependency(), getDomDataProviderDependency(), getLocalTableDependency());
     }
index 73a53fca8b62dfa144bb235345bb67a256fc2ffc..b6c100e979e04018b0b58b27c0a7a745e6616586 100644 (file)
@@ -117,6 +117,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
     private final BindingTransactionChain chain;
     private final AsNumber localAs;
     private final Ipv4Address bgpIdentifier;
+    private final Ipv4Address clusterId;
     private final Set<BgpTableType> localTables;
     private final RIBTables tables;
     private final BlockingQueue<Peer> peers;
@@ -155,7 +156,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
         }
     };
 
-    public RIBImpl(final RibId ribId, final AsNumber localAs, final Ipv4Address localBgpId, final RIBExtensionConsumerContext extensions,
+    public RIBImpl(final RibId ribId, final AsNumber localAs, final Ipv4Address localBgpId, final Ipv4Address clusterId, final RIBExtensionConsumerContext extensions,
         final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory, final BindingCodecTreeFactory codecFactory,
         final ReconnectStrategyFactory sessionStrategyFactory, final DataBroker dps, final DOMDataBroker domDataBroker, final List<BgpTableType> localTables) {
         super(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))));
@@ -163,6 +164,7 @@ public final class RIBImpl extends DefaultRibReference implements AutoCloseable,
         this.localAs = Preconditions.checkNotNull(localAs);
         this.comparator = new BGPObjectComparator(localAs);
         this.bgpIdentifier = Preconditions.checkNotNull(localBgpId);
+        this.clusterId = clusterId == null ? localBgpId : clusterId;
         this.dispatcher = Preconditions.checkNotNull(dispatcher);
         this.sessionStrategyFactory = Preconditions.checkNotNull(sessionStrategyFactory);
         this.tcpStrategyFactory = Preconditions.checkNotNull(tcpStrategyFactory);
index 1623b9a456d7fcb9473af0705bf51944eac2bb26..e08ec756c5ac2f4ae25f0ba30de8e2dc99feb969 100644 (file)
@@ -682,6 +682,12 @@ module odl-bgp-rib-impl-cfg {
                 type rib:rib-id;
                 mandatory true;
             }
+
+            leaf cluster-id {
+                description "IBGP identifier. Needed by route reflection.";
+                reference "https://tools.ietf.org/html/rfc4456#section-7";
+                type inet:ipv4-address;
+            }
         }
     }
 }
index 68b59296dcbcdf70a13de93b62e6bfc7fc4cdc21..639979562dd21992e2d9ea7c95f3863b7b988c94 100644 (file)
@@ -86,6 +86,7 @@ public abstract class AbstractRIBImplModuleTest extends AbstractConfigTest {
 
     protected static final RibId RIB_ID = new RibId("test");
     protected static final Ipv4Address BGP_ID = new Ipv4Address("192.168.1.1");
+    protected static final Ipv4Address CLUSTER_ID = new Ipv4Address("192.168.1.2");
 
     private static final String SESSION_RS_INSTANCE_NAME = "session-reconnect-strategy-factory";
     private static final String TCP_RS_INSTANCE_NAME = "tcp-reconnect-strategy-factory";
@@ -216,14 +217,14 @@ public abstract class AbstractRIBImplModuleTest extends AbstractConfigTest {
         return transaction.commit();
     }
 
-    protected CommitStatus createRIBImplModuleInstance(final RibId ribId, final Long localAs, final Ipv4Address bgpId) throws Exception {
+    protected CommitStatus createRIBImplModuleInstance(final RibId ribId, final Long localAs, final Ipv4Address bgpId, final Ipv4Address clusterId) throws Exception {
         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
-        createRIBImplModuleInstance(transaction, ribId, localAs, bgpId, createAsyncDataBrokerInstance(transaction));
+        createRIBImplModuleInstance(transaction, ribId, localAs, bgpId, clusterId, createAsyncDataBrokerInstance(transaction));
         return transaction.commit();
     }
 
     private ObjectName createRIBImplModuleInstance(final ConfigTransactionJMXClient transaction, final RibId ribId, final Long localAs,
-            final Ipv4Address bgpId, final ObjectName dataBroker) throws Exception {
+            final Ipv4Address bgpId, final Ipv4Address clusterId, final ObjectName dataBroker) throws Exception {
         final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
         final RIBImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, RIBImplModuleMXBean.class);
         final ObjectName reconnectObjectName = TimedReconnectStrategyModuleTest.createInstance(transaction, SESSION_RS_INSTANCE_NAME);
@@ -238,17 +239,18 @@ public abstract class AbstractRIBImplModuleTest extends AbstractConfigTest {
         mxBean.setRibId(ribId);
         mxBean.setLocalAs(localAs);
         mxBean.setBgpRibId(bgpId);
+        mxBean.setClusterId(clusterId);
         return nameCreated;
     }
 
     protected ObjectName createRIBImplModuleInstance(final ConfigTransactionJMXClient transaction) throws Exception {
-        return createRIBImplModuleInstance(transaction, RIB_ID, 5000L, BGP_ID,
+        return createRIBImplModuleInstance(transaction, RIB_ID, 5000L, BGP_ID, CLUSTER_ID,
                 createAsyncDataBrokerInstance(transaction));
     }
 
     public ObjectName createRIBImplModuleInstance(final ConfigTransactionJMXClient transaction, final ObjectName dataBroker)
             throws Exception {
-        return createRIBImplModuleInstance(transaction, RIB_ID, 5000L, BGP_ID, dataBroker);
+        return createRIBImplModuleInstance(transaction, RIB_ID, 5000L, BGP_ID, CLUSTER_ID, dataBroker);
     }
 
     public ObjectName createAsyncDataBrokerInstance(final ConfigTransactionJMXClient transaction) throws InstanceAlreadyExistsException, InstanceNotFoundException {
index 7505b940517054cab4e9894ebc8eeb96bb592fe8..35f59518c306796f6bbe76bac63f69849c70147d 100644 (file)
@@ -22,7 +22,7 @@ public class RIBImplModuleTest extends AbstractRIBImplModuleTest {
     @Test
     public void testValidationExceptionRibIdNotSet() throws Exception {
         try {
-            createRIBImplModuleInstance(null, 500L, BGP_ID);
+            createRIBImplModuleInstance(null, 500L, BGP_ID, CLUSTER_ID);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("RibId is not set."));
@@ -32,7 +32,7 @@ public class RIBImplModuleTest extends AbstractRIBImplModuleTest {
     @Test
     public void testValidationExceptionLocalAsNotSet() throws Exception {
         try {
-            createRIBImplModuleInstance(RIB_ID, null, BGP_ID);
+            createRIBImplModuleInstance(RIB_ID, null, BGP_ID, CLUSTER_ID);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("LocalAs is not set."));
@@ -42,13 +42,23 @@ public class RIBImplModuleTest extends AbstractRIBImplModuleTest {
     @Test
     public void testValidationExceptionBgpIdNotSet() throws Exception {
         try {
-            createRIBImplModuleInstance(RIB_ID, 500L, null);
+            createRIBImplModuleInstance(RIB_ID, 500L, null, CLUSTER_ID);
             fail();
         } catch (final ValidationException e) {
             assertTrue(e.getMessage().contains("BgpRibId is not set."));
         }
     }
 
+    @Test
+    public void testValidationExceptionBgpClusterIdNotSet() throws Exception {
+        try {
+            createRIBImplModuleInstance(RIB_ID, 500L, BGP_ID, null);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("ClusterId is not set."));
+        }
+    }
+
     @Test
     public void testCreateBean() throws Exception {
         final CommitStatus status = createInstance();
index c63b153d2395e82c95fe9211d807d892e3e97219..b961982595ffcfde4c9ae72c197f40295ba2b4e1 100644 (file)
@@ -231,7 +231,7 @@ public class ApplicationPeerTest {
             }
         }).when(this.transWrite).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(InstanceIdentifier.class));
         this.r = new RIBImpl(new RibId("test"), new AsNumber(5L), new Ipv4Address("127.0.0.1"),
-            context , this.dispatcher, this.tcpStrategyFactory, this.codecFactory, this.tcpStrategyFactory, this.dps, this.dom, localTables);
+            new Ipv4Address("128.0.0.1"), context , this.dispatcher, this.tcpStrategyFactory, this.codecFactory, this.tcpStrategyFactory, this.dps, this.dom, localTables);
         this.peer = new ApplicationPeer(new ApplicationRibId("t"), new Ipv4Address("127.0.0.1"), this.r);
         final ReadOnlyTransaction readTx = Mockito.mock(ReadOnlyTransaction.class);
         Mockito.doReturn(readTx).when(this.dps).newReadOnlyTransaction();
index e89a79c79b08005371eec1f6cdbc25852a8a4b37..e43f88ea5dec2819a861c04c65ab1ba6f391ef0f 100644 (file)
@@ -109,7 +109,7 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
     }
 
     private void runTestWithTables(final List<BgpTableType> tables) {
-        final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), new AsNumber(72L), new Ipv4Address("127.0.0.1"), this.ext, this.dispatcher, this.tcpStrategyFactory, this.codecFactory, this.sessionStrategy, getDataBroker(), getDomBroker(), tables);
+        final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), new AsNumber(72L), new Ipv4Address("127.0.0.1"), null, this.ext, this.dispatcher, this.tcpStrategyFactory, this.codecFactory, this.sessionStrategy, getDataBroker(), getDomBroker(), tables);
         final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib);
 
         final ListenerRegistration<?> reg = this.mock.registerUpdateListener(peer);