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