BUG 4070: Add missing policy database 70/27570/2
authorClaudio D. Gasparini <cgaspari@cisco.com>
Tue, 29 Sep 2015 06:43:33 +0000 (08:43 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 29 Sep 2015 15:00:25 +0000 (15:00 +0000)
Add missing policy database for new Internal Role defined.

Change-Id: Ifc7b29f7aa8417978db845d8544774e3b71ac8eb
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/FromInternalReflectorClientImportPolicy.java [new file with mode: 0644]
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PolicyDatabase.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ToInternalReflectorClientExportPolicy.java [new file with mode: 0644]
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyTest.java

diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/FromInternalReflectorClientImportPolicy.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/FromInternalReflectorClientImportPolicy.java
new file mode 100644 (file)
index 0000000..dddf7fc
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.rib.impl;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+/**
+ * Invoked on routes which we get from our Internal peers. This is a special-case of
+ * FromInternalImportPolicy.
+ */
+final class FromInternalReflectorClientImportPolicy extends FromInternalImportPolicy {
+    FromInternalReflectorClientImportPolicy(final Ipv4Address bgpIdentifier, final ClusterIdentifier clusterIdentifier) {
+        super(bgpIdentifier, clusterIdentifier);
+    }
+
+    @Override
+    ContainerNode effectiveAttributes(final ContainerNode attributes) {
+        // TODO: (defensiveness) verify ORIGINATOR_ID (should have been set)
+
+        return super.effectiveAttributes(attributes);
+    }
+}
index 199f2c9b5df4938e502c71c3ef3e022231bc8d7e..cec9cc280397abcca17b8b5f6c15dd7bef20f724 100644 (file)
@@ -25,10 +25,12 @@ final class PolicyDatabase {
         exportPolicies.put(PeerRole.Ebgp, new ToExternalExportPolicy(localAs));
         exportPolicies.put(PeerRole.Ibgp, new ToInternalExportPolicy(bgpId, clusterId));
         exportPolicies.put(PeerRole.RrClient, new ToReflectorClientExportPolicy(bgpId, clusterId));
+        exportPolicies.put(PeerRole.Internal, new ToInternalReflectorClientExportPolicy(bgpId, clusterId));
 
         importPolicies.put(PeerRole.Ebgp, new FromExternalImportPolicy());
         importPolicies.put(PeerRole.Ibgp, new FromInternalImportPolicy(bgpId, clusterId));
         importPolicies.put(PeerRole.RrClient, new FromReflectorClientImportPolicy(bgpId, clusterId));
+        importPolicies.put(PeerRole.Internal, new FromInternalReflectorClientImportPolicy(bgpId, clusterId));
     }
 
     AbstractExportPolicy exportPolicyForRole(final PeerRole peerRole) {
diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ToInternalReflectorClientExportPolicy.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ToInternalReflectorClientExportPolicy.java
new file mode 100644 (file)
index 0000000..cf80938
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.rib.impl;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+
+/**
+ * Invoked on routes which we send to our reflector peers. This is a special-case of
+ * FromInternalImportPolicy.
+ */
+final class ToInternalReflectorClientExportPolicy extends AbstractReflectingExportPolicy {
+
+    ToInternalReflectorClientExportPolicy(final Ipv4Address originatorId, final ClusterIdentifier clusterId) {
+        super(originatorId, clusterId);
+    }
+
+    @Override
+    ContainerNode effectiveAttributes(final PeerRole sourceRole, final ContainerNode attributes) {
+        switch (sourceRole) {
+        case Ebgp:
+            // eBGP -> Client iBGP, propagate
+            return attributes;
+        case Ibgp:
+            // Non-Client iBGP -> Client iBGP, reflect
+            return reflectedAttributes(attributes);
+        case RrClient:
+            // Client iBGP -> Client iBGP, reflect
+            return reflectedAttributes(attributes);
+        case Internal:
+            // Internal Client iBGP -> Client iBGP, reflect
+            return reflectedFromInternalAttributes(attributes);
+        default:
+            throw new IllegalArgumentException("Unhandled source role " + sourceRole);
+        }
+    }
+}
\ No newline at end of file
index d74c979513c014375d60d86312012e37a4e655be..8ff07ae727923381a30490553801d0e488109bc6 100644 (file)
@@ -32,12 +32,14 @@ public class ExportPolicyTest {
     private static final long LOCAL_AS = 8;
     private static final ToExternalExportPolicy EXT_POLICY = new ToExternalExportPolicy(LOCAL_AS);
     private static final ToInternalExportPolicy INT_POLICY = new ToInternalExportPolicy(IPV4, CLUSTER);
+    private static final ToInternalReflectorClientExportPolicy INTERNAL_POLICY = new ToInternalReflectorClientExportPolicy(IPV4, CLUSTER);
 
     @Test
     public void testEbgpEffectiveAttributes() {
         final ContainerNode clusterIn = createClusterInput();
         final PeerRole peerRole = PeerRole.Ebgp;
         assertEquals(clusterIn, REF_POLICY.effectiveAttributes(peerRole, clusterIn));
+        assertEquals(clusterIn, INTERNAL_POLICY.effectiveAttributes(peerRole, clusterIn));
         assertEquals(clusterIn, INT_POLICY.effectiveAttributes(peerRole, clusterIn));
 
         final ContainerNode asPathIn = createPathInput(null);
@@ -49,6 +51,7 @@ public class ExportPolicyTest {
         final ContainerNode clusterIn = createClusterInput();
         final PeerRole peerRole = PeerRole.Ibgp;
         assertEquals(createInputWithOriginator(), REF_POLICY.effectiveAttributes(peerRole, clusterIn));
+        assertEquals(createInputWithOriginator(), INTERNAL_POLICY.effectiveAttributes(peerRole, clusterIn));
         assertEquals(null, INT_POLICY.effectiveAttributes(peerRole, clusterIn));
 
         final ContainerNode asPathIn = createPathInput(null);
@@ -60,6 +63,7 @@ public class ExportPolicyTest {
         final ContainerNode clusterIn = createClusterInput();
         final PeerRole peerRole = PeerRole.RrClient;
         assertEquals(createInputWithOriginator(), REF_POLICY.effectiveAttributes(peerRole, clusterIn));
+        assertEquals(createInputWithOriginator(), INTERNAL_POLICY.effectiveAttributes(peerRole, clusterIn));
         assertEquals(createInputWithOriginator(), INT_POLICY.effectiveAttributes(peerRole, clusterIn));
 
         final ContainerNode asPathIn = createPathInput(null);
@@ -71,6 +75,7 @@ public class ExportPolicyTest {
         final ContainerNode clusterIn = createClusterInput();
         final PeerRole peerRole = PeerRole.Internal;
         assertEquals(createInternalOutput(), REF_POLICY.effectiveAttributes(peerRole, clusterIn));
+        assertEquals(createInternalOutput(), INTERNAL_POLICY.effectiveAttributes(peerRole, clusterIn));
         assertEquals(createInternalOutput(), INT_POLICY.effectiveAttributes(peerRole, clusterIn));
 
         final ContainerNode asPathIn = createPathInput(null);