BUG-2383: split out policies into separate files
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / ToReflectorClientExportPolicy.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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
14
15 /**
16  * Invoked on routes which we send to our reflector peers. This is a special-case of
17  * FromInternalImportPolicy.
18  */
19 final class ToReflectorClientExportPolicy extends AbstractReflectingExportPolicy {
20
21     ToReflectorClientExportPolicy(final Ipv4Address originatorId, final ClusterIdentifier clusterId) {
22         super(originatorId, clusterId);
23     }
24
25     @Override
26     ContainerNode effectiveAttributes(final PeerRole sourceRole, final ContainerNode attributes) {
27         switch (sourceRole) {
28         case Ebgp:
29             // eBGP -> Client iBGP, propagate
30             return attributes;
31         case Ibgp:
32             // Non-Client iBGP -> Client iBGP, reflect
33             return reflectedAttributes(attributes);
34         case RrClient:
35             // Client iBGP -> Client iBGP, reflect
36             return reflectedAttributes(attributes);
37         default:
38             throw new IllegalArgumentException("Unhandled source role " + sourceRole);
39         }
40     }
41 }