use of org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy 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;
}
use of org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy in project bgpcep by opendaylight.
the class ActionsRegistryImpl method registerBgpActionAugmentationPolicy.
public AbstractRegistration registerBgpActionAugmentationPolicy(final Class<? extends Augmentation<BgpActions>> bgpActionPolicyClass, final BgpActionAugPolicy bgpActionPolicy) {
synchronized (this.bgpAugActionsRegistry) {
final BgpActionAugPolicy prev = this.bgpAugActionsRegistry.putIfAbsent(bgpActionPolicyClass, bgpActionPolicy);
Preconditions.checkState(prev == null, "Action Policy %s already registered %s", bgpActionPolicyClass, prev);
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
synchronized (ActionsRegistryImpl.this.bgpAugActionsRegistry) {
ActionsRegistryImpl.this.bgpAugActionsRegistry.remove(bgpActionPolicyClass);
}
}
};
}
}
use of org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.action.BgpActionAugPolicy 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;
}
Aggregations