Pass PathIds to StaleBestRoute
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / protocol / bgp / rib / spi / entry / StaleBestPathRoute.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 package org.opendaylight.protocol.bgp.rib.spi.entry;
9
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.stream.Collectors;
13 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
18 import org.opendaylight.yangtools.yang.binding.ChildOf;
19 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.Identifiable;
22 import org.opendaylight.yangtools.yang.binding.Identifier;
23
24 /**
25  * Routes to be removed from Data Store.
26  *
27  * @author Claudio D. Gasparini
28  */
29 public final class StaleBestPathRoute<C extends Routes & DataObject & ChoiceIn<Tables>,
30         S extends ChildOf<? super C>,
31         R extends Route & ChildOf<? super S> & Identifiable<I>,
32         I extends Identifier<R>> {
33     private final I nonAddPathRouteKeyIdentifier;
34     private final List<I> addPathRouteKeyIdentifier;
35     private final boolean isNonAddPathBestPathNew;
36     private final List<I> staleRouteKeyIdentifier;
37
38     public StaleBestPathRoute(
39             final RIBSupport<C, S, R, I> ribSupport,
40             final String routeKey,
41             final List<PathId> staleRoutesPathIds,
42             final List<PathId> withdrawalRoutePathIds,
43             final boolean isNonAddPathBestPathNew) {
44         this.isNonAddPathBestPathNew = isNonAddPathBestPathNew;
45
46         this.staleRouteKeyIdentifier = staleRoutesPathIds.stream()
47                 .map(pathId -> ribSupport.createRouteListKey(pathId, routeKey)).collect(Collectors.toList());
48         if (withdrawalRoutePathIds != null) {
49             this.addPathRouteKeyIdentifier = withdrawalRoutePathIds.stream()
50                     .map(pathId -> ribSupport.createRouteListKey(pathId, routeKey)).collect(Collectors.toList());
51         } else {
52             this.addPathRouteKeyIdentifier = Collections.emptyList();
53         }
54         this.nonAddPathRouteKeyIdentifier = ribSupport.createRouteListKey(routeKey);
55     }
56
57     public I getNonAddPathRouteKeyIdentifier() {
58         return this.nonAddPathRouteKeyIdentifier;
59     }
60
61     /**
62      * Route Identifier List of withdrawn routes to advertize peers supporting additional Path.
63      *
64      * @return Route Identifier List
65      */
66     public List<I> getStaleRouteKeyIdentifiers() {
67         return this.staleRouteKeyIdentifier;
68     }
69
70     /**
71      * Route Identifier List of withdrawn routes to advertize peers supporting additional Path.
72      *
73      * @return Route Identifier List
74      */
75     public List<I> getAddPathRouteKeyIdentifiers() {
76         return this.addPathRouteKeyIdentifier;
77     }
78
79     /**
80      * Route Identifier of withdrawn routes to advertize peers no supporting additional Path.
81      *
82      * @return Route Identifier
83      */
84     public boolean isNonAddPathBestPathNew() {
85         return this.isNonAddPathBestPathNew;
86     }
87 }