From: Claudio D. Gasparini Date: Tue, 29 Sep 2015 06:43:33 +0000 (+0200) Subject: BUG 4070: Add missing policy database X-Git-Tag: release/beryllium~154 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=6835149570cdc6021748ac0580bf91989f33ab18;p=bgpcep.git BUG 4070: Add missing policy database Add missing policy database for new Internal Role defined. Change-Id: Ifc7b29f7aa8417978db845d8544774e3b71ac8eb Signed-off-by: Claudio D. Gasparini --- 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 index 0000000000..dddf7fc3e2 --- /dev/null +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/FromInternalReflectorClientImportPolicy.java @@ -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); + } +} diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PolicyDatabase.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PolicyDatabase.java index 199f2c9b5d..cec9cc2803 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PolicyDatabase.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/PolicyDatabase.java @@ -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 index 0000000000..cf8093803f --- /dev/null +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/ToInternalReflectorClientExportPolicy.java @@ -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 diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyTest.java index d74c979513..8ff07ae727 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ExportPolicyTest.java @@ -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);