Route Constrain policies
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / RTCClientRouteCache.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.impl;
10
11 import com.google.common.collect.ImmutableList;
12 import java.util.ArrayList;
13 import java.util.List;
14 import javax.annotation.concurrent.GuardedBy;
15 import org.opendaylight.protocol.bgp.rib.spi.policy.RTCCache;
16 import org.opendaylight.protocol.bgp.route.targetcontrain.spi.ClientRouteTargetContrainCache;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRoute;
19
20 public final class RTCClientRouteCache implements ClientRouteTargetContrainCache, RTCCache {
21     @GuardedBy("this")
22     private final List<RouteTargetConstrainRoute> rtCache = new ArrayList<>();
23
24     @Override
25     public synchronized void cacheRoute(final Route route) {
26         if (!(route instanceof RouteTargetConstrainRoute)) {
27             return;
28         }
29         this.rtCache.add((RouteTargetConstrainRoute) route);
30     }
31
32     @Override
33     public synchronized void uncacheRoute(final Route route) {
34         if (!(route instanceof RouteTargetConstrainRoute)) {
35             return;
36         }
37         this.rtCache.remove(route);
38     }
39
40     @Override
41     public synchronized List<Route> getClientRouteTargetContrainCache() {
42         return ImmutableList.copyOf(this.rtCache);
43     }
44 }