2 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
9 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.SetLocalAddressAsNextHop;
23 * Local Address shall be set as next Hop.
24 * https://tools.ietf.org/html/rfc4684
26 * @author Claudio D. Gasparini
28 public final class SetLocalAddressAsNextHopHandler implements BgpActionAugPolicy<SetLocalAddressAsNextHop> {
29 private static final SetLocalAddressAsNextHopHandler INSTANCE = new SetLocalAddressAsNextHopHandler();
31 private SetLocalAddressAsNextHopHandler() {
35 public static SetLocalAddressAsNextHopHandler getInstance() {
40 public Attributes applyImportAction(
41 final RouteEntryBaseAttributes routeEntryInfo,
42 final BGPRouteEntryImportParameters routeBaseParameters,
43 final Attributes attributes,
44 final SetLocalAddressAsNextHop actions) {
45 return setNextHop(attributes, routeEntryInfo.getOriginatorId());
48 private Attributes setNextHop(final Attributes attributes, final Ipv4Address localAddress) {
49 return new AttributesBuilder(attributes)
50 .setCNextHop(new Ipv4NextHopCaseBuilder()
51 .setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(localAddress).build())
56 public Attributes applyExportAction(
57 final RouteEntryBaseAttributes routeEntryInfo,
58 final BGPRouteEntryExportParameters exportParameters,
59 final Attributes attributes,
60 final SetLocalAddressAsNextHop actions) {
61 return setNextHop(attributes, routeEntryInfo.getOriginatorId());