bfc1e76e2641ad50297b1acc026d74995b02a715
[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.message.rev171207.path.attributes.Attributes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
24
25 public abstract class AbstractRouteEntry<T extends BestPath> implements RouteEntry {
26     protected static final Attributes[] EMPTY_ATTRIBUTES = new Attributes[0];
27     protected static final Route[] EMPTY_VALUES = new Route[0];
28     protected final BGPPeerTracker peerTracker;
29
30     public AbstractRouteEntry(final BGPPeerTracker peerTracker) {
31         this.peerTracker = requireNonNull(peerTracker);
32     }
33
34     /**
35      * Create new Route with route jey created from passed parameters.
36      */
37     public abstract Route createRoute(@Nonnull RIBSupport ribSup, @Nonnull String routeKey, long pathId, T path);
38
39     /**
40      * Returns true if route can be send.
41      */
42     protected boolean filterRoutes(final PeerId fromPeer, final Peer toPeer, final TablesKey localTK) {
43         return !(toPeer == null
44                 || !toPeer.supportsTable(localTK)
45                 || PeerRole.Internal.equals(toPeer.getRole()))
46                 && !fromPeer.equals(toPeer.getPeerId());
47     }
48 }