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
8 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions;
10 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes;
11 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy;
12 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
13 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginatorIdBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.SetOriginatorIdPrepend;
21 * Prepend Originator Id.
23 public final class SetOriginatorIdPrependHandler implements BgpActionAugPolicy<SetOriginatorIdPrepend> {
24 private static final SetOriginatorIdPrependHandler INSTANCE = new SetOriginatorIdPrependHandler();
26 private SetOriginatorIdPrependHandler() {
30 public static SetOriginatorIdPrependHandler getInstance() {
35 public Attributes applyImportAction(
36 final RouteEntryBaseAttributes routeEntryInfo,
37 final BGPRouteEntryImportParameters routeEntryImportParameters,
38 final Attributes attributes,
39 final SetOriginatorIdPrepend bgpActions) {
41 final Ipv4AddressNoZone defOri = bgpActions.getSetOriginatorIdPrepend().getOriginatorId();
42 return prependOriginatorId(attributes, defOri == null
43 ? routeEntryInfo.getOriginatorId() : defOri);
46 private static Attributes prependOriginatorId(final Attributes attributes, final Ipv4AddressNoZone originatorId) {
47 if (attributes.getOriginatorId() != null) {
50 final AttributesBuilder newAtt = new AttributesBuilder(attributes);
51 return newAtt.setOriginatorId(new OriginatorIdBuilder().setOriginator(originatorId).build()).build();
55 public Attributes applyExportAction(
56 final RouteEntryBaseAttributes routeEntryInfo,
57 final BGPRouteEntryExportParameters routeEntryExportParameters,
58 final Attributes attributes,
59 final SetOriginatorIdPrepend bgpActions) {
60 final Ipv4AddressNoZone defOri = bgpActions.getSetOriginatorIdPrepend().getOriginatorId();
61 return prependOriginatorId(attributes, defOri == null
62 ? routeEntryInfo.getOriginatorId() : defOri);