Propagate depreferenced status through AbstractAdvertizedRoute
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / protocol / bgp / rib / spi / entry / AbstractAdvertizedRoute.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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
9 package org.opendaylight.protocol.bgp.rib.spi.entry;
10
11 import static com.google.common.base.Verify.verifyNotNull;
12 import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID_VALUE;
13
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
21 import org.opendaylight.yangtools.yang.binding.ChildOf;
22 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.Identifiable;
25 import org.opendaylight.yangtools.yang.binding.Identifier;
26
27 /**
28  * Preexistent routes to be advertized before process any route advertized by the peer.
29  *
30  * @author Claudio D. Gasparini
31  */
32 public abstract class AbstractAdvertizedRoute<C extends Routes & DataObject & ChoiceIn<Tables>,
33         S extends ChildOf<? super C>,
34         R extends Route & ChildOf<? super S> & Identifiable<I>,
35         I extends Identifier<R>> implements RouteKeyIdentifier<R,I> {
36     private final PeerId fromPeerId;
37     private final R route;
38     private final Attributes attributes;
39     private final I nonAddPathRouteKeyIdentifier;
40     private final I addPathRouteKeyIdentifier;
41     private final boolean depreferenced;
42
43     AbstractAdvertizedRoute(final RIBSupport<C, S, R, I> ribSupport, final R route, final PeerId fromPeerId,
44             final Attributes attributes, final boolean depreferenced) {
45         this.fromPeerId = fromPeerId;
46         this.route = route;
47         this.attributes = attributes;
48         this.depreferenced = depreferenced;
49
50         final @NonNull String routeKey = verifyNotNull(route.getRouteKey());
51         this.nonAddPathRouteKeyIdentifier = ribSupport.createRouteListKey(NON_PATH_ID_VALUE, routeKey);
52         this.addPathRouteKeyIdentifier = ribSupport.createRouteListKey(route.getPathId().getValue(), routeKey);
53     }
54
55     public final PeerId getFromPeerId() {
56         return this.fromPeerId;
57     }
58
59     public final R getRoute() {
60         return route;
61     }
62
63     public final Attributes getAttributes() {
64         return attributes;
65     }
66
67     public final boolean isDepreferenced() {
68         return depreferenced;
69     }
70
71     @Override
72     public final I getNonAddPathRouteKeyIdentifier() {
73         return this.nonAddPathRouteKeyIdentifier;
74     }
75
76     @Override
77     public final I getAddPathRouteKeyIdentifier() {
78         return this.addPathRouteKeyIdentifier;
79     }
80 }