Bump versions by x.y.(z+1)
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / ToExternalExportPolicy.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 com.google.common.base.Preconditions;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
12 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
13
14 /**
15  * Invoked on routes which we send outside of our home AS.
16  */
17 final class ToExternalExportPolicy extends AbstractExportPolicy {
18     private final Long localAs;
19
20     ToExternalExportPolicy(final Long localAs) {
21         this.localAs = Preconditions.checkNotNull(localAs);
22     }
23
24     @Override
25     ContainerNode effectiveAttributes(final PeerRole sourceRole, final ContainerNode attributes) {
26         final ContainerNode ret = AttributeOperations.getInstance(attributes).exportedAttributes(attributes, this.localAs);
27
28         switch (sourceRole) {
29         case Ebgp:
30             // eBGP -> eBGP, propagate
31             return ret;
32         case Ibgp:
33             // Non-Client iBGP -> eBGP, propagate
34             return ret;
35         case RrClient:
36             // Client iBGP -> eBGP, propagate
37             return ret;
38         case Internal:
39             // Internal iBGP -> eBGP, propagate
40             return ret;
41         default:
42             throw new IllegalArgumentException("Unhandled source role " + sourceRole);
43         }
44     }
45 }