use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.AttributesBuilder in project bgpcep by opendaylight.
the class AsPathLengthTest method testASPathLengthGe.
@Test
public void testASPathLengthGe() {
final AsPathBuilder asPath = new AsPathBuilder();
asPath.setSegments(Collections.singletonList(new SegmentsBuilder().setAsSequence(Arrays.asList(AsNumber.getDefaultInstance("1"), AsNumber.getDefaultInstance("2"), AsNumber.getDefaultInstance("3"))).build()));
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("as-path-ge-length-test")).findFirst().get();
RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setAsPath(asPath.build()).build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
assertNull(result.getAttributes());
asPath.setSegments(Collections.singletonList(new SegmentsBuilder().setAsSequence(Collections.singletonList(AsNumber.getDefaultInstance("3"))).build()));
attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setAsPath(asPath.build()).build());
result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
assertNotNull(result.getAttributes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.AttributesBuilder in project bgpcep by opendaylight.
the class NonTransitiveAttributesFilterHandler method filterAttributes.
private Attributes filterAttributes(final Attributes attributes) {
final AttributesBuilder builder = new AttributesBuilder();
builder.setCNextHop(attributes.getCNextHop());
builder.setOrigin(attributes.getOrigin());
builder.setAsPath(attributes.getAsPath());
builder.setCommunities(attributes.getCommunities());
final List<UnrecognizedAttributes> oldAtt = attributes.getUnrecognizedAttributes();
if (oldAtt != null) {
builder.setUnrecognizedAttributes(attributes.getUnrecognizedAttributes().stream().filter(UnrecognizedAttributes::isTransitive).collect(Collectors.toList()));
}
final List<ExtendedCommunities> oldExt = attributes.getExtendedCommunities();
if (oldExt != null) {
builder.setExtendedCommunities(oldExt.stream().filter(ExtendedCommunity::isTransitive).collect(Collectors.toList()));
}
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.AttributesBuilder in project bgpcep by opendaylight.
the class SetClusterIdPrependHandler method prependClusterId.
private Attributes prependClusterId(final Attributes attributes, final ClusterIdentifier clusterId) {
final AttributesBuilder newAtt = new AttributesBuilder(attributes);
final List<ClusterIdentifier> newClusterList = new ArrayList<>();
newClusterList.add(clusterId);
if (attributes.getClusterId() != null && !attributes.getClusterId().getCluster().isEmpty()) {
final List<ClusterIdentifier> oldList = attributes.getClusterId().getCluster();
newClusterList.addAll(oldList);
}
return newAtt.setClusterId(new ClusterIdBuilder().setCluster(newClusterList).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.AttributesBuilder 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.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.AttributesBuilder in project bgpcep by opendaylight.
the class AppendActionTest method testAppend.
@Test
public void testAppend() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("multiple-append-test")).findFirst().get();
final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
final Attributes expected = new AttributesBuilder().setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build()).setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("4.5.6.7")).build()).build()).setLocalPref(new LocalPrefBuilder().setPref(100L).build()).setMultiExitDisc(new MultiExitDiscBuilder().setMed(15L).build()).build();
assertEquals(expected, result.getAttributes());
}
Aggregations