Search in sources :

Example 1 with BgpActions

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.BgpActions in project bgpcep by opendaylight.

the class ActionsRegistryImpl method applyExportAction.

@SuppressWarnings("unchecked")
Attributes applyExportAction(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryExportParameters routeEntryExportParameters, final Attributes attributes, final Actions actions) {
    requireNonNull(attributes);
    if (actions.getRouteDisposition() instanceof RejectRoute) {
        return null;
    }
    Attributes attributesUpdated = attributes;
    final Actions1 augmentation = actions.getAugmentation(Actions1.class);
    if (augmentation != null && augmentation.getBgpActions() != null) {
        final BgpActions bgpAction = augmentation.getBgpActions();
        final SetAsPathPrepend asPrependAction = bgpAction.getSetAsPathPrepend();
        final Long localPrefPrependAction = bgpAction.getSetLocalPref();
        final BgpOriginAttrType localOriginAction = bgpAction.getSetRouteOrigin();
        final BgpSetMedType medAction = bgpAction.getSetMed();
        final BgpNextHopType nhAction = bgpAction.getSetNextHop();
        final SetCommunity setCommunityAction = bgpAction.getSetCommunity();
        final SetExtCommunity setExtCommunityAction = bgpAction.getSetExtCommunity();
        if (asPrependAction != null) {
            attributesUpdated = this.bgpActions.get(SetAsPathPrepend.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, asPrependAction);
        }
        if (attributesUpdated == null) {
            return null;
        }
        if (setCommunityAction != null) {
            attributesUpdated = this.bgpActions.get(SetCommunity.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, setCommunityAction);
        }
        if (attributesUpdated == null) {
            return null;
        }
        if (setExtCommunityAction != null) {
            attributesUpdated = this.bgpActions.get(SetExtCommunity.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, setExtCommunityAction);
        }
        boolean updated = false;
        if (localPrefPrependAction != null || localOriginAction != null || medAction != null || nhAction != null) {
            updated = true;
        }
        if (updated) {
            final AttributesBuilder attributesUpdatedBuilder = new AttributesBuilder(attributes);
            if (localPrefPrependAction != null) {
                attributesUpdatedBuilder.setLocalPref(new LocalPrefBuilder().setPref(localPrefPrependAction).build());
            }
            if (localOriginAction != null) {
                attributesUpdatedBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.forValue(localOriginAction.getIntValue())).build());
            }
            if (medAction != null) {
                attributesUpdatedBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(medAction.getUint32()).build());
            }
            if (nhAction != null) {
                final IpAddress address = nhAction.getIpAddress();
                if (address != null) {
                    CNextHop nhNew;
                    if (address.getIpv4Address() != null) {
                        nhNew = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(address.getIpv4Address()).build()).build();
                    } else {
                        nhNew = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(address.getIpv6Address()).build()).build();
                    }
                    attributesUpdatedBuilder.setCNextHop(nhNew);
                }
            }
            attributesUpdated = attributesUpdatedBuilder.build();
        }
        final Map<Class<? extends Augmentation<?>>, Augmentation<?>> bgpConditionsAug = BindingReflections.getAugmentations(bgpAction);
        if (bgpConditionsAug != null) {
            for (final Map.Entry<Class<? extends Augmentation<?>>, Augmentation<?>> entry : bgpConditionsAug.entrySet()) {
                final BgpActionAugPolicy handler = this.bgpAugActionsRegistry.get(entry.getKey());
                if (handler == null) {
                    continue;
                } else if (attributesUpdated == null) {
                    return null;
                }
                attributesUpdated = handler.applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, entry.getValue());
            }
        }
    }
    if (attributesUpdated == null) {
        return null;
    }
    // Export Actions Aug
    final Map<Class<? extends Augmentation<?>>, Augmentation<?>> conditionsAug = BindingReflections.getAugmentations(actions);
    if (conditionsAug == null) {
        return attributes;
    }
    for (final Map.Entry<Class<? extends Augmentation<?>>, Augmentation<?>> entry : conditionsAug.entrySet()) {
        final ActionsAugPolicy handler = this.actionsRegistry.get(entry.getKey());
        if (attributesUpdated == null) {
            return null;
        } else if (handler == null) {
            continue;
        }
        attributesUpdated = handler.applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, (Augmentation<Actions>) entry.getValue());
    }
    return attributesUpdated;
}
Also used : LocalPrefBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPrefBuilder) SetAsPathPrepend(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend) BgpSetMedType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.BgpSetMedType) OriginBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder) MultiExitDiscBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.MultiExitDiscBuilder) RouteEntryBaseAttributes(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) ActionsAugPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.ActionsAugPolicy) RejectRoute(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.generic.actions.route.disposition.RejectRoute) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) SetCommunity(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetCommunity) Actions1(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.Actions1) BgpOriginAttrType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.BgpOriginAttrType) BgpNextHopType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.BgpNextHopType) Ipv6NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder) BgpActions(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.BgpActions) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop) Augmentation(org.opendaylight.yangtools.yang.binding.Augmentation) Ipv4NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder) BgpActionAugPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) SetExtCommunity(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetExtCommunity) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) HashMap(java.util.HashMap) Map(java.util.Map) Ipv6NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder)

Example 2 with BgpActions

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.BgpActions in project bgpcep by opendaylight.

the class ActionsRegistryImpl method applyImportAction.

@SuppressWarnings("unchecked")
Attributes applyImportAction(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryImportParameters routeParameters, final Attributes attributes, final Actions actions) {
    if (actions.getRouteDisposition() instanceof RejectRoute) {
        return null;
    }
    Attributes attributesUpdated = attributes;
    final Actions1 augmentation = actions.getAugmentation(Actions1.class);
    if (augmentation != null && augmentation.getBgpActions() != null) {
        final BgpActions bgpAction = augmentation.getBgpActions();
        final SetCommunity setCommunityAction = bgpAction.getSetCommunity();
        final SetExtCommunity setExtCommunityAction = bgpAction.getSetExtCommunity();
        final SetAsPathPrepend asPrependAction = bgpAction.getSetAsPathPrepend();
        if (asPrependAction != null) {
            attributesUpdated = this.bgpActions.get(asPrependAction.getClass()).applyImportAction(routeEntryInfo, routeParameters, attributesUpdated, asPrependAction);
        }
        if (attributesUpdated == null) {
            return null;
        }
        if (setCommunityAction != null) {
            attributesUpdated = this.bgpActions.get(SetCommunity.class).applyImportAction(routeEntryInfo, routeParameters, attributesUpdated, setCommunityAction);
        }
        if (attributesUpdated == null) {
            return null;
        }
        if (setExtCommunityAction != null) {
            attributesUpdated = this.bgpActions.get(SetExtCommunity.class).applyImportAction(routeEntryInfo, routeParameters, attributesUpdated, setExtCommunityAction);
        }
        if (attributesUpdated == null) {
            return null;
        }
        final Map<Class<? extends Augmentation<?>>, Augmentation<?>> bgpConditionsAug = BindingReflections.getAugmentations(bgpAction);
        if (bgpConditionsAug == null) {
            return attributes;
        }
        for (final Map.Entry<Class<? extends Augmentation<?>>, Augmentation<?>> entry : bgpConditionsAug.entrySet()) {
            final BgpActionAugPolicy handler = this.bgpAugActionsRegistry.get(entry.getKey());
            if (handler == null) {
                continue;
            } else if (attributesUpdated == null) {
                return null;
            }
            attributesUpdated = handler.applyImportAction(routeEntryInfo, routeParameters, attributesUpdated, entry.getValue());
        }
        if (attributesUpdated == null) {
            return null;
        }
    }
    // Augmented Actions
    final Map<Class<? extends Augmentation<?>>, Augmentation<?>> conditionsAug = BindingReflections.getAugmentations(actions);
    if (conditionsAug == null) {
        return attributesUpdated;
    }
    for (final Map.Entry<Class<? extends Augmentation<?>>, Augmentation<?>> entry : conditionsAug.entrySet()) {
        final ActionsAugPolicy handler = this.actionsRegistry.get(entry.getKey());
        if (handler == null) {
            continue;
        } else if (attributesUpdated == null) {
            return null;
        }
        attributesUpdated = handler.applyImportAction(routeEntryInfo, routeParameters, attributesUpdated, (Augmentation<Actions>) entry.getValue());
    }
    return attributesUpdated;
}
Also used : SetAsPathPrepend(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend) BgpActions(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.BgpActions) RouteEntryBaseAttributes(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) ActionsAugPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.ActionsAugPolicy) RejectRoute(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.generic.actions.route.disposition.RejectRoute) Augmentation(org.opendaylight.yangtools.yang.binding.Augmentation) SetCommunity(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetCommunity) BgpActionAugPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy) Actions1(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.Actions1) SetExtCommunity(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetExtCommunity) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 RouteEntryBaseAttributes (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes)2 ActionsAugPolicy (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.ActionsAugPolicy)2 BgpActionAugPolicy (org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy)2 Actions1 (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.Actions1)2 BgpActions (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.BgpActions)2 SetAsPathPrepend (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend)2 SetCommunity (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetCommunity)2 SetExtCommunity (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetExtCommunity)2 RejectRoute (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.generic.actions.route.disposition.RejectRoute)2 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)2 Augmentation (org.opendaylight.yangtools.yang.binding.Augmentation)2 BgpNextHopType (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.BgpNextHopType)1 BgpSetMedType (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.BgpSetMedType)1 BgpOriginAttrType (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.BgpOriginAttrType)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)1 LocalPrefBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPrefBuilder)1 MultiExitDiscBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.MultiExitDiscBuilder)1