2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import java.util.EnumMap;
12 import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
18 * Policy database attached to a particular RIB instance. Acts as the unified
21 final class PolicyDatabase {
22 private final Map<PeerRole, AbstractExportPolicy> exportPolicies = new EnumMap<>(PeerRole.class);
23 private final Map<PeerRole, AbstractImportPolicy> importPolicies = new EnumMap<>(PeerRole.class);
25 PolicyDatabase(final Long localAs, final Ipv4Address bgpId, final ClusterIdentifier clusterId) {
26 this.exportPolicies.put(PeerRole.Ebgp, new ToExternalExportPolicy(localAs));
27 this.exportPolicies.put(PeerRole.Ibgp, new ToInternalExportPolicy(bgpId, clusterId));
28 this.exportPolicies.put(PeerRole.RrClient, new ToReflectorClientExportPolicy(bgpId, clusterId));
29 this.exportPolicies.put(PeerRole.Internal, new ToInternalReflectorClientExportPolicy(bgpId, clusterId));
31 this.importPolicies.put(PeerRole.Ebgp, new FromExternalImportPolicy());
32 this.importPolicies.put(PeerRole.Ibgp, new FromInternalImportPolicy(bgpId, clusterId));
33 this.importPolicies.put(PeerRole.RrClient, new FromReflectorClientImportPolicy(bgpId, clusterId));
34 this.importPolicies.put(PeerRole.Internal, new FromInternalReflectorClientImportPolicy(bgpId, clusterId));
37 AbstractExportPolicy exportPolicyForRole(final PeerRole peerRole) {
38 return this.exportPolicies.get(peerRole);
41 AbstractImportPolicy importPolicyForRole(final PeerRole peerRole) {
43 * TODO: this solution does not share equivalent attributes across
44 * multiple peers. If we need to do that, consider carefully:
45 * - whether the interner should be shared with RIBSupportContextImpl.writeRoutes()
46 * - lookup/update contention of both the cache and the interner
47 * - ability to share resulting attributes across import policies
48 * - ability to share resulting attributes with export policies
50 return new CachingImportPolicy(importPolicies.get(peerRole));