use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend in project bgpcep by opendaylight.
the class AsPathPrepend method applyExportAction.
@Override
public Attributes applyExportAction(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryExportParameters exportParameters, final Attributes attributes, final SetAsPathPrepend actions) {
final List<Segments> oldSegments = attributes.getAsPath().getSegments();
/*
* We need to check the first segment.
* If it has as-set then new as-sequence with local AS is prepended.
* If it has as-sequence, we may add local AS when it has less than 255 elements.
* Otherwise we need to create new as-sequence for local AS.
*/
final ArrayList<AsNumber> newAsSequence = new ArrayList<>();
newAsSequence.add(new AsNumber(routeEntryInfo.getLocalAs()));
List<Segments> newSegments = new ArrayList<>();
if (oldSegments == null || oldSegments.isEmpty()) {
newSegments = Collections.singletonList(new SegmentsBuilder().setAsSequence(newAsSequence).build());
} else {
final Segments firstSegment = oldSegments.remove(0);
final List<AsNumber> firstAsSequence = firstSegment.getAsSequence();
if (firstAsSequence != null && firstAsSequence.size() < Values.UNSIGNED_BYTE_MAX_VALUE) {
newAsSequence.addAll(firstAsSequence);
newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
} else {
newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
newSegments.add(firstSegment);
}
newSegments.addAll(oldSegments);
}
return new AttributesBuilder(attributes).setAsPath(new AsPathBuilder().setSegments(newSegments).build()).build();
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend 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.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend 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