Replace Preconditions.CheckNotNull per RequireNonNull
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / AbstractReflectingExportPolicy.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 javax.annotation.Nonnull;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
16
17 /**
18  * An intermediate abstract class shared by both Client and Non-Client
19  * export policies.
20  */
21 abstract class AbstractReflectingExportPolicy extends AbstractExportPolicy {
22     private final ClusterIdentifier clusterId;
23     private final Ipv4Address originatorId;
24
25     protected AbstractReflectingExportPolicy(final Ipv4Address originatorId, final ClusterIdentifier clusterId) {
26         this.originatorId = requireNonNull(originatorId);
27         this.clusterId = requireNonNull(clusterId);
28     }
29
30     /**
31      * Modify attributes so they are updated as per RFC4456 route reflection.
32      *
33      * @param attributes Input attributes, may not be null.
34      * @return Modified (reflected) attributes.
35      */
36     @Nonnull protected final ContainerNode reflectedAttributes(@Nonnull final ContainerNode attributes) {
37         return AttributeOperations.getInstance(attributes).reflectedAttributes(attributes, this.originatorId, this.clusterId);
38     }
39
40     /**
41      * Modify attributes so they are updated as per RFC4456 route reflection, but without add ORIGINATOR_ID
42      * and CLUSTER_ID inside CLUSTER_LIST as required https://tools.ietf.org/html/rfc4456#section-8, BUG 4070.
43      *
44      * @param attributes Input attributes, may not be null.
45      * @return Modified (reflected) attributes.
46      */
47     @Nonnull protected static final ContainerNode reflectedFromInternalAttributes(@Nonnull final ContainerNode attributes) {
48         return AttributeOperations.getInstance(attributes).reflectedAttributes(attributes);
49     }
50 }