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.actions;
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.message.rev180329.path.attributes.attributes.OriginatorIdBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180329.SetOriginatorIdPrepend;
22 * Prepend Originator Id.
24 public final class SetOriginatorIdPrependHandler implements BgpActionAugPolicy<SetOriginatorIdPrepend> {
25 private static final SetOriginatorIdPrependHandler INSTANCE = new SetOriginatorIdPrependHandler();
27 private SetOriginatorIdPrependHandler() {
31 public static SetOriginatorIdPrependHandler getInstance() {
36 public Attributes applyImportAction(
37 final RouteEntryBaseAttributes routeEntryInfo,
38 final BGPRouteEntryImportParameters routeEntryImportParameters,
39 final Attributes attributes,
40 final SetOriginatorIdPrepend bgpActions) {
42 final Ipv4Address defOri = bgpActions.getSetOriginatorIdPrepend().getOriginatorId();
43 return prependOriginatorId(attributes, defOri == null
44 ? routeEntryInfo.getOriginatorId() : defOri);
47 private static Attributes prependOriginatorId(final Attributes attributes, final Ipv4Address originatorId) {
48 if (attributes.getOriginatorId() != null) {
51 final AttributesBuilder newAtt = new AttributesBuilder(attributes);
52 return newAtt.setOriginatorId(new OriginatorIdBuilder().setOriginator(originatorId).build()).build();
56 public Attributes applyExportAction(
57 final RouteEntryBaseAttributes routeEntryInfo,
58 final BGPRouteEntryExportParameters routeEntryExportParameters,
59 final Attributes attributes,
60 final SetOriginatorIdPrepend bgpActions) {
61 final Ipv4Address defOri = bgpActions.getSetOriginatorIdPrepend().getOriginatorId();
62 return prependOriginatorId(attributes, defOri == null
63 ? routeEntryInfo.getOriginatorId() : defOri);