BUG-2383: split out policies into separate files
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / ToInternalExportPolicy.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 normal home AS peers.
17  */
18 final class ToInternalExportPolicy extends AbstractReflectingExportPolicy {
19     ToInternalExportPolicy(final Ipv4Address originatorId, final ClusterIdentifier clusterId) {
20         super(originatorId, clusterId);
21     }
22
23     @Override
24     ContainerNode effectiveAttributes(final PeerRole sourceRole, final ContainerNode attributes) {
25         switch (sourceRole) {
26         case Ebgp:
27             // eBGP -> Non-Client iBGP, propagate
28             return attributes;
29         case Ibgp:
30             // Non-Client iBGP -> Non-Client iBGP, block
31             return null;
32         case RrClient:
33             // Client iBGP -> Non-Client iBGP, reflect
34             return reflectedAttributes(attributes);
35         default:
36             throw new IllegalArgumentException("Unhandled source role " + sourceRole);
37         }
38     }
39 }