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