BGPCEP-564: Support multiple cluster IDs 42/70042/4
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 22 Mar 2018 11:41:02 +0000 (12:41 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 29 Mar 2018 12:11:48 +0000 (14:11 +0200)
Change-Id: I7e50b3ff7e9a4299b70bcfa6e1fa24ba970a795b
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
13 files changed:
bgp/openconfig-api/src/main/yang/bgp-openconfig-extensions.yang
bgp/openconfig-rp-impl/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/impl/BGPRibPolicyImpl.java
bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/actions/SetClusterIdPrependHandler.java
bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/conditions/MatchClusterIdSetHandler.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BGPRouteEntryExportParametersImpl.java
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/config/BgpPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/OpenConfigMappingUtil.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/RibImpl.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/OpenConfigMappingUtilTest.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/PeerTrackerInformation.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/policy/BGPRouteEntryImportParameters.java

index 34164dda8bf7b7544016ee652af8c0d4fb637ddc..935695aebd2b5d1e72aa5e22a5959e2f01b8e882 100644 (file)
@@ -87,6 +87,15 @@ module bgp-openconfig-extensions {
         }
     }
 
+    grouping route-reflector-cluster-id-config {
+        leaf route-reflector-cluster-id {
+            type bgp-types:rr-cluster-id-type;
+            description
+              "Route-reflector cluster id to use when local router is
+              configured as a route reflector.";
+        }
+    }
+
     augment /netinst:network-instances/netinst:network-instance/netinst:protocols/netinst:protocol {
         ext:augment-identifier network-instance-protocol;
         uses openconfig-bgp:bgp-top {
@@ -113,14 +122,13 @@ module bgp-openconfig-extensions {
                      peer-group";
                 uses openconfig-bgp:bgp-neighbor-peer-group_config;
             }
+            augment bgp/neighbors/neighbor/config {
+                ext:augment-identifier neighbor-cluster-id-config;
+                uses route-reflector-cluster-id-config;
+            }
             augment bgp/global/config {
                 ext:augment-identifier global-config-augmentation;
-                leaf route-reflector-cluster-id {
-                    type bgp-types:rr-cluster-id-type;
-                    description
-                      "Route-reflector cluster id to use when local router is
-                      configured as a route reflector.";
-                  }
+                uses route-reflector-cluster-id-config;
             }
             augment bgp/neighbors/neighbor/state {
                 ext:augment-identifier neighbor_state-augmentation;
@@ -174,6 +182,10 @@ module bgp-openconfig-extensions {
                 ext:augment-identifier peer-group-transport-config;
                 uses transport-config;
             }
+            augment bgp/peer-groups/peer-group/config {
+                ext:augment-identifier peer-group-cluster-id-config;
+                uses route-reflector-cluster-id-config;
+            }
         }
     }
 
index 8ecfb4493bb95a844a70b13a2a7078e26a4b3ac1..b609dc945636d323173ce37cf9eb7db67c6b5d50 100644 (file)
@@ -43,7 +43,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 final class BGPRibPolicyImpl implements BGPRibRoutingPolicy {
     private static final InstanceIdentifier<RoutingPolicy> ROUTING_POLICY_IID
             = InstanceIdentifier.create(RoutingPolicy.class);
-    private static final List<String> EMPTY_POLICY = Collections.emptyList();
+    private static final List<String> DEFAULT_IMPORT_POLICY = Collections.singletonList("default-odl-import-policy");
+    private static final List<String> DEFAULT_EXPORT_POLICY = Collections.singletonList("default-odl-export-policy");
     private final DefaultPolicyType defaultExportPolicy;
     private final DefaultPolicyType defaultImportPolicy;
     private final List<String> exportPolicy;
@@ -69,11 +70,11 @@ final class BGPRibPolicyImpl implements BGPRibRoutingPolicy {
 
         List<String> epolicy = policyConfig.getExportPolicy();
         if (epolicy == null) {
-            epolicy = EMPTY_POLICY;
+            epolicy = DEFAULT_EXPORT_POLICY;
         }
         List<String> ipolicy = policyConfig.getImportPolicy();
         if (ipolicy == null) {
-            ipolicy = EMPTY_POLICY;
+            ipolicy = DEFAULT_IMPORT_POLICY;
         }
 
         this.defaultExportPolicy = requireNonNull(policyConfig.getDefaultExportPolicy());
index e9c75f67375594a78c8614d461f5efbb9f865584..dde238573e4e3f40a1f79356c9f1cbdb103fc51a 100644 (file)
@@ -26,10 +26,12 @@ public final class SetClusterIdPrependHandler implements BgpActionAugPolicy<SetC
     @Override
     public Attributes applyImportAction(
             final RouteEntryBaseAttributes routeEntryInfo,
-            final BGPRouteEntryImportParameters routeEntryImportParameters,
+            final BGPRouteEntryImportParameters importParameters,
             final Attributes attributes,
             final SetClusterIdPrepend bgpActions) {
-        return prependClusterId(attributes, routeEntryInfo.getClusterId());
+        final ClusterIdentifier clusterIdLocal = importParameters.getFromClusterId() == null
+                ? routeEntryInfo.getClusterId() : importParameters.getFromClusterId();
+        return prependClusterId(attributes, clusterIdLocal);
     }
 
     private Attributes prependClusterId(final Attributes attributes, final ClusterIdentifier clusterId) {
@@ -46,9 +48,11 @@ public final class SetClusterIdPrependHandler implements BgpActionAugPolicy<SetC
     @Override
     public Attributes applyExportAction(
             final RouteEntryBaseAttributes routeEntryInfo,
-            final BGPRouteEntryExportParameters routeEntryExportParameters,
+            final BGPRouteEntryExportParameters exportParameters,
             final Attributes attributes,
             final SetClusterIdPrepend bgpActions) {
-        return prependClusterId(attributes, routeEntryInfo.getClusterId());
+        final ClusterIdentifier clusterIdLocal = exportParameters.getFromClusterId() == null
+                ? routeEntryInfo.getClusterId() : exportParameters.getFromClusterId();
+        return prependClusterId(attributes, clusterIdLocal);
     }
 }
index e6b76f4081fd3c97b295e41c1059e8347c13a7cd..f7c56404d4840e6b98a506f3cea3e729b795ceef 100644 (file)
@@ -73,21 +73,24 @@ public final class MatchClusterIdSetHandler
     @Override
     public boolean matchImportCondition(
             final RouteEntryBaseAttributes routeEntryInfo,
-            final BGPRouteEntryImportParameters routeEntryImportParameters,
-            final ClusterId clusterId,
+            final BGPRouteEntryImportParameters importParameters,
+            final ClusterId clusterIdAtt,
             final MatchClusterIdSetCondition conditions) {
-
-        return matchClusterIdCondition(routeEntryInfo.getClusterId(), clusterId,
+        final ClusterIdentifier clusterIdLocal = importParameters.getFromClusterId() == null
+                ? routeEntryInfo.getClusterId() : importParameters.getFromClusterId();
+        return matchClusterIdCondition(clusterIdLocal, clusterIdAtt,
                 conditions.getMatchClusterIdSetCondition());
     }
 
     @Override
     public boolean matchExportCondition(
             final RouteEntryBaseAttributes routeEntryInfo,
-            final BGPRouteEntryExportParameters routeEntryExportParameters,
-            final ClusterId clusterId,
+            final BGPRouteEntryExportParameters exportParameters,
+            final ClusterId clusterIdAtt,
             final MatchClusterIdSetCondition conditions) {
-        return matchClusterIdCondition(routeEntryInfo.getClusterId(), clusterId,
+        final ClusterIdentifier clusterIdLocal = exportParameters.getFromClusterId() == null
+                ? routeEntryInfo.getClusterId() : exportParameters.getFromClusterId();
+        return matchClusterIdCondition(clusterIdLocal, clusterIdAtt,
                 conditions.getMatchClusterIdSetCondition());
     }
 
index 84e3602807093ecbede528df0f215809d895117d..e3439c9c89e159a6e6253de6af88baa2bc120f29 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.protocol.bgp.rib.spi.Peer;
 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
 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.types.rev130919.ClusterIdentifier;
 
 public final class BGPRouteEntryExportParametersImpl implements BGPRouteEntryExportParameters {
     private final Peer fromPeer;
@@ -31,6 +32,11 @@ public final class BGPRouteEntryExportParametersImpl implements BGPRouteEntryExp
         return this.fromPeer.getPeerId();
     }
 
+    @Override
+    public ClusterIdentifier getFromClusterId() {
+        return this.fromPeer.getClusterId();
+    }
+
     @Override
     public PeerRole getToPeerRole() {
         return this.toPeer.getRole();
index cd4b446eb1fef4357a34f8f63a93902399d4e14f..c1d10ca41c98e84c03b9925869505074f315919b 100644 (file)
@@ -21,6 +21,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
@@ -56,6 +58,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.peer.AdjRibOut;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
@@ -321,6 +324,11 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
         return PeerRole.Internal;
     }
 
+    @Override
+    public ClusterIdentifier getClusterId() {
+        return null;
+    }
+
     @Override
     public KeyedInstanceIdentifier<Tables, TablesKey> getRibOutIId(final TablesKey tablesKey) {
         return this.tablesIId.getUnchecked(tablesKey);
@@ -372,4 +380,9 @@ public class ApplicationPeer extends BGPPeerStateImpl implements org.opendayligh
     public PeerId getFromPeerId() {
         return getPeerId();
     }
+
+    @Override
+    public ClusterIdentifier getFromClusterId() {
+        return getClusterId();
+    }
 }
index 812c9a87ff98246640bc59cefc45799716c9421b..8e45ad153a08e0d4a8bd455353383465bea39201 100644 (file)
@@ -31,6 +31,7 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
+import javax.annotation.Nullable;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
@@ -88,6 +89,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
@@ -104,6 +106,7 @@ import org.slf4j.LoggerFactory;
 public class BGPPeer extends BGPPeerStateImpl implements BGPRouteEntryImportParameters,
         BGPSessionListener, Peer, TransactionChainListener {
     private static final Logger LOG = LoggerFactory.getLogger(BGPPeer.class);
+    private final ClusterIdentifier clusterId;
 
     private Set<TablesKey> tables = Collections.emptySet();
     private final RIB rib;
@@ -144,6 +147,7 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPRouteEntryImportPara
             final String peerGroupName,
             final RIB rib,
             final PeerRole role,
+            final ClusterIdentifier clusterId,
             final RpcProviderRegistry rpcRegistry,
             final Set<TablesKey> afiSafisAdvertized,
             final Set<TablesKey> afiSafisGracefulAdvertized) {
@@ -151,6 +155,7 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPRouteEntryImportPara
                 afiSafisGracefulAdvertized);
         this.peerRole = role;
         this.rib = requireNonNull(rib);
+        this.clusterId = clusterId;
         this.name = Ipv4Util.toStringIP(neighborAddress);
         this.rpcRegistry = rpcRegistry;
         this.peerId = RouterIds.createPeerId(neighborAddress);
@@ -160,14 +165,14 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPRouteEntryImportPara
         this.chain = rib.createPeerDOMChain(this);
     }
 
-    public BGPPeer(
+    BGPPeer(
             final IpAddress neighborAddress,
             final RIB rib,
             final PeerRole role,
             final RpcProviderRegistry rpcRegistry,
             final Set<TablesKey> afiSafisAdvertized,
             final Set<TablesKey> afiSafisGracefulAdvertized) {
-        this(neighborAddress, null, rib, role, rpcRegistry, afiSafisAdvertized,
+        this(neighborAddress, null, rib, role, null, rpcRegistry, afiSafisAdvertized,
                 afiSafisGracefulAdvertized);
     }
 
@@ -497,6 +502,11 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPRouteEntryImportPara
         return this.peerRole;
     }
 
+    @Override
+    public ClusterIdentifier getClusterId() {
+        return this.clusterId;
+    }
+
     @Override
     public KeyedInstanceIdentifier<Tables, TablesKey> getRibOutIId(final TablesKey tablesKey) {
         return this.tablesIId.getUnchecked(tablesKey);
@@ -567,4 +577,9 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPRouteEntryImportPara
     public PeerId getFromPeerId() {
         return getPeerId();
     }
+
+    @Override
+    public ClusterIdentifier getFromClusterId() {
+        return getClusterId();
+    }
 }
index 74c3acb5e961f125c39fa06e9ee37f412ea03ff6..3189e6f7ef44f877b7ff96c6402c5cce60ea596e 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.protocol.bgp.rib.impl.config;
 
 import static java.util.Objects.requireNonNull;
+import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getGlobalClusterIdentifier;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
@@ -60,6 +61,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborPeerGroupConfig;
 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.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
@@ -250,9 +252,11 @@ public final class BgpPeer implements PeerBean, BGPPeerStateConsumer {
                     .toTableKey(afisSAfis.getAfiSafi(), tableTypeRegistry);
 
             final PeerRole role = OpenConfigMappingUtil.toPeerRole(neighbor, peerGroup);
+            final ClusterIdentifier clusterId = OpenConfigMappingUtil
+                    .getNeighborClusterIdentifier(neighbor.getConfig());
 
-            this.bgpPeer = new BGPPeer(this.neighborAddress, peerGroupName, rib, role, BgpPeer.this.rpcRegistry,
-                    afiSafisAdvertized, Collections.emptySet());
+            this.bgpPeer = new BGPPeer(this.neighborAddress, peerGroupName, rib, role, clusterId,
+                    BgpPeer.this.rpcRegistry, afiSafisAdvertized, Collections.emptySet());
 
             final List<BgpParameters> bgpParameters = getBgpParameters(afisSAfis, rib, tableTypeRegistry);
             final KeyMapping keyMapping = OpenConfigMappingUtil.getNeighborKey(neighbor);
index 6fb14b5ef6f427ac193a9fa176ea05b50e87fa3c..d4bd0f6c412b0ceb650b1b158bad46004d404e41 100644 (file)
@@ -54,9 +54,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.GlobalAddPathsConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.GlobalConfigAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborAddPathsConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborClusterIdConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborPeerGroupConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborTransportConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.PeerGroupTransportConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.RouteReflectorClusterIdConfig;
 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.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
@@ -183,16 +185,28 @@ public final class OpenConfigMappingUtil {
         return afiSafi;
     }
 
-    public static ClusterIdentifier getClusterIdentifier(final org.opendaylight.yang.gen.v1.http.openconfig.net.yang
-            .bgp.rev151009.bgp.global.base.Config globalConfig) {
-        final GlobalConfigAugmentation globalConfigAugmentation
+    public static ClusterIdentifier getGlobalClusterIdentifier(final org.opendaylight.yang.gen.v1.http.openconfig.net
+            .yang.bgp.rev151009.bgp.global.base.Config globalConfig) {
+        final RouteReflectorClusterIdConfig configAug
                 = globalConfig.getAugmentation(GlobalConfigAugmentation.class);
-        if (globalConfigAugmentation != null && globalConfigAugmentation.getRouteReflectorClusterId() != null) {
-            return new ClusterIdentifier(globalConfigAugmentation.getRouteReflectorClusterId().getIpv4Address());
+        if (configAug != null && configAug.getRouteReflectorClusterId() != null) {
+            return new ClusterIdentifier(configAug.getRouteReflectorClusterId().getIpv4Address());
         }
         return new ClusterIdentifier(globalConfig.getRouterId());
     }
 
+    @Nullable
+    public static ClusterIdentifier getNeighborClusterIdentifier(@Nullable final org.opendaylight.yang.gen.v1.http
+            .openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Config config) {
+        if (config != null) {
+            final RouteReflectorClusterIdConfig configAug = config.getAugmentation(NeighborClusterIdConfig.class);
+            if (configAug != null && configAug.getRouteReflectorClusterId() != null) {
+                return new ClusterIdentifier(configAug.getRouteReflectorClusterId().getIpv4Address());
+            }
+        }
+        return null;
+    }
+
     public static Map<BgpTableType, PathSelectionMode> toPathSelectionMode(final List<AfiSafi> afiSafis,
             final BGPTableTypeRegistryConsumer tableTypeRegistry, final BGPPeerTracker peerTracker) {
         final Map<BgpTableType, PathSelectionMode> pathSelectionModes = new HashMap<>();
index e750ad3a652bbc70996eaef63b4655eed4235b71..44f9a241ffdf7dc7c833690b6d3b13eb5cad243b 100644 (file)
@@ -9,7 +9,7 @@
 package org.opendaylight.protocol.bgp.rib.impl.config;
 
 import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getAfiSafiWithDefault;
-import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getClusterIdentifier;
+import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getGlobalClusterIdentifier;
 import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.toTableTypes;
 
 import com.google.common.base.Preconditions;
@@ -112,7 +112,7 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
         final Config globalConfig = global.getConfig();
         final AsNumber globalAs = globalConfig.getAs();
         final Ipv4Address globalRouterId = global.getConfig().getRouterId();
-        final ClusterIdentifier globalClusterId = getClusterIdentifier(globalConfig);
+        final ClusterIdentifier globalClusterId = getGlobalClusterIdentifier(globalConfig);
         return this.afiSafi.containsAll(globalAfiSafi) && globalAfiSafi.containsAll(this.afiSafi)
                 && globalAs.equals(this.asNumber)
                 && globalRouterId.getValue().equals(this.routerId.getValue())
@@ -252,7 +252,7 @@ public final class RibImpl implements RIB, BGPRibStateConsumer, AutoCloseable {
         final Config globalConfig = global.getConfig();
         this.asNumber = globalConfig.getAs();
         this.routerId = globalConfig.getRouterId();
-        this.clusterId = getClusterIdentifier(globalConfig);
+        this.clusterId = getGlobalClusterIdentifier(globalConfig);
         final BGPPeerTrackerImpl peerTracker = new BGPPeerTrackerImpl();
         final Map<TablesKey, PathSelectionMode> pathSelectionModes = OpenConfigMappingUtil
                 .toPathSelectionMode(this.afiSafi, tableTypeRegistry, peerTracker).entrySet()
index 517ac208297a96703849a5b0185a37fcf38c315a..c11358a266c0ebc98e09f9112f8f58b8a7303d1f 100644 (file)
@@ -87,6 +87,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.open
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.GlobalConfigAugmentationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborAddPathsConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborAddPathsConfigBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborClusterIdConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborClusterIdConfigBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborPeerGroupConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborPeerGroupConfigBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborTransportConfig;
@@ -330,18 +332,31 @@ public class OpenConfigMappingUtilTest {
     }
 
     @Test
-    public void testGetClusterIdentifier() {
+    public void testGetGlobalClusterIdentifier() {
         final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base
                 .ConfigBuilder configBuilder = new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009
                 .bgp.global.base.ConfigBuilder();
         configBuilder.setRouterId(ROUTER_ID);
         assertEquals(ROUTER_ID.getValue(),
-                OpenConfigMappingUtil.getClusterIdentifier(configBuilder.build()).getValue());
+                OpenConfigMappingUtil.getGlobalClusterIdentifier(configBuilder.build()).getValue());
 
         configBuilder.addAugmentation(GlobalConfigAugmentation.class, new GlobalConfigAugmentationBuilder()
                 .setRouteReflectorClusterId(new RrClusterIdType(CLUSTER_ID)).build()).build();
         assertEquals(CLUSTER_ID.getValue(),
-                OpenConfigMappingUtil.getClusterIdentifier(configBuilder.build()).getValue());
+                OpenConfigMappingUtil.getGlobalClusterIdentifier(configBuilder.build()).getValue());
+    }
+
+    @Test
+    public void testGetNeighborClusterIdentifier() {
+        assertNull(OpenConfigMappingUtil.getNeighborClusterIdentifier(null));
+
+        final ConfigBuilder configBuilder = new ConfigBuilder();
+        assertNull(OpenConfigMappingUtil.getNeighborClusterIdentifier(configBuilder.build()));
+
+        configBuilder.addAugmentation(NeighborClusterIdConfig.class, new NeighborClusterIdConfigBuilder()
+                .setRouteReflectorClusterId(new RrClusterIdType(CLUSTER_ID)).build()).build();
+        assertEquals(CLUSTER_ID.getValue(),
+                OpenConfigMappingUtil.getNeighborClusterIdentifier(configBuilder.build()).getValue());
     }
 
     @Test
index 33adfda959fbe67ef10bf9b789bae29118d9adbd..05e3cd1f37d77b42d3f1ec8845e22c65048b672f 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.
 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.rib.Tables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 
 /**
@@ -74,4 +75,12 @@ public interface PeerTrackerInformation {
      */
     @Nonnull
     PeerRole getRole();
+
+    /**
+     * Returns Cluster Id.
+     *
+     * @return Cluster Id
+     */
+    @Nullable
+    ClusterIdentifier getClusterId();
 }
index a7cf420ab0e64677c6c6e6781bd7f9458dac89f1..422adb061049f2af2bb746f8959154143685159a 100644 (file)
@@ -8,8 +8,10 @@
 package org.opendaylight.protocol.bgp.rib.spi.policy;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 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.types.rev130919.ClusterIdentifier;
 
 /**
  * Contains Peer destiny information for import route entry.
@@ -30,4 +32,12 @@ public interface BGPRouteEntryImportParameters {
      */
     @Nonnull
     PeerId getFromPeerId();
+
+    /**
+     * Peer id of Peer route entry announcer.
+     *
+     * @return peer Id of announcer Peer
+     */
+    @Nullable
+    ClusterIdentifier getFromClusterId();
 }