Provide Add Path support for all AFI/SAFI
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / spi / AbstractRouteEntry.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.protocol.bgp.mode.spi;
10
11 import static java.util.Objects.requireNonNull;
12
13 import javax.annotation.Nonnull;
14 import org.opendaylight.protocol.bgp.mode.api.BestPath;
15 import org.opendaylight.protocol.bgp.mode.api.RouteEntry;
16 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
17 import org.opendaylight.protocol.bgp.rib.spi.Peer;
18 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
23
24 public abstract class AbstractRouteEntry<T extends BestPath> implements RouteEntry {
25     protected final BGPPeerTracker peerTracker;
26
27     public AbstractRouteEntry(final BGPPeerTracker peerTracker) {
28         this.peerTracker = requireNonNull(peerTracker);
29     }
30
31     /**
32      * Create new Route with route jey created from passed parameters.
33      */
34     public abstract Route createRoute(@Nonnull RIBSupport ribSup, @Nonnull String routeKey, long pathId, T path);
35
36     /**
37      * Returns true if route can be send.
38      */
39     protected boolean filterRoutes(final PeerId fromPeer, final Peer toPeer, final TablesKey localTK) {
40         return !(toPeer == null
41                 || !toPeer.supportsTable(localTK)
42                 || PeerRole.Internal.equals(toPeer.getRole()))
43                 && !fromPeer.equals(toPeer.getPeerId());
44     }
45 }