199f2c9b5df4938e502c71c3ef3e022231bc8d7e
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / PolicyDatabase.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl;
9
10 import java.util.EnumMap;
11 import java.util.Map;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
15
16 /**
17  * Policy database attached to a particular RIB instance. Acts as the unified
18  * lookup point.
19  */
20 final class PolicyDatabase {
21     private final Map<PeerRole, AbstractExportPolicy> exportPolicies = new EnumMap<>(PeerRole.class);
22     private final Map<PeerRole, AbstractImportPolicy> importPolicies = new EnumMap<>(PeerRole.class);
23
24     PolicyDatabase(final Long localAs, final Ipv4Address bgpId, final ClusterIdentifier clusterId) {
25         exportPolicies.put(PeerRole.Ebgp, new ToExternalExportPolicy(localAs));
26         exportPolicies.put(PeerRole.Ibgp, new ToInternalExportPolicy(bgpId, clusterId));
27         exportPolicies.put(PeerRole.RrClient, new ToReflectorClientExportPolicy(bgpId, clusterId));
28
29         importPolicies.put(PeerRole.Ebgp, new FromExternalImportPolicy());
30         importPolicies.put(PeerRole.Ibgp, new FromInternalImportPolicy(bgpId, clusterId));
31         importPolicies.put(PeerRole.RrClient, new FromReflectorClientImportPolicy(bgpId, clusterId));
32     }
33
34     AbstractExportPolicy exportPolicyForRole(final PeerRole peerRole) {
35         return exportPolicies.get(peerRole);
36     }
37
38     AbstractImportPolicy importPolicyForRole(final PeerRole peerRole) {
39         return importPolicies.get(peerRole);
40     }
41 }