Bump versions to 0.21.8-SNAPSHOT
[bgpcep.git] / bgp / extensions / route-target / src / main / java / org / opendaylight / protocol / bgp / route / targetcontrain / impl / route / policy / ClientAttributePrependHandler.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.route.targetcontrain.impl.route.policy;
10
11 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes;
12 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy;
13 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
14 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.ClientAttributePrepend;
18
19 public final class ClientAttributePrependHandler implements BgpActionAugPolicy<ClientAttributePrepend> {
20     private static final ClientAttributePrependHandler INSTANCE = new ClientAttributePrependHandler();
21
22     private ClientAttributePrependHandler() {
23         // Hidden on purpose
24     }
25
26     public static ClientAttributePrependHandler getInstance() {
27         return INSTANCE;
28     }
29
30     @Override
31     public Attributes applyImportAction(final RouteEntryBaseAttributes routeEntryInfo,
32             final BGPRouteEntryImportParameters routeBaseParameters,
33             final Attributes attributes,
34             final ClientAttributePrepend actions) {
35         return attributes;
36     }
37
38     @Override
39     public Attributes applyExportAction(final RouteEntryBaseAttributes routeEntryInfo,
40             final BGPRouteEntryExportParameters exportParameters,
41             final Attributes attributes,
42             final ClientAttributePrepend actions) {
43         return exportParameters.getClientRouteTargetContrainCache().stream()
44             .filter(rt -> rt.getRouteKey().equals(exportParameters.getRouteKey()))
45             .findFirst()
46             .map(Route::getAttributes)
47             .orElse(attributes);
48     }
49 }