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 AttributesEqualTests method testOriginEq.
@Test
public void testOriginEq() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("origin-eq-test")).findFirst().get();
RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build()).build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
assertNotNull(result.getAttributes());
attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build()).build());
result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
assertNull(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 AttributesEqualTests method testNextHopIn.
@Test
public void testNextHopIn() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("nexthop-in-test")).findFirst().get();
RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCNextHop(new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).build()).build()).build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
assertNotNull(result.getAttributes());
attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("42.42.42.42")).build()).build()).build());
result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
assertNull(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 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.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.AttributesBuilder in project bgpcep by opendaylight.
the class SetCommunityHandler method inlineSetComm.
private Attributes inlineSetComm(final Attributes attributes, final List<Communities> actionCommunities, final BgpSetCommunityOptionType options) {
final AttributesBuilder newAtt = new AttributesBuilder(attributes);
if (options.equals(BgpSetCommunityOptionType.REPLACE)) {
return newAtt.setCommunities(actionCommunities).build();
}
final List<Communities> actualComm;
if (attributes.getCommunities() != null) {
actualComm = new ArrayList<>(attributes.getCommunities());
} else {
actualComm = new ArrayList<>();
}
switch(options) {
case ADD:
actualComm.addAll(actionCommunities);
break;
case REMOVE:
actualComm.removeAll(actionCommunities);
break;
default:
throw new IllegalArgumentException("Option Type not Recognized!");
}
return newAtt.setCommunities(actualComm).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 SetExtCommunityHandler method inlineSetExtComm.
private Attributes inlineSetExtComm(final Attributes attributes, final List<ExtendedCommunities> actionExtCommunities, final BgpSetCommunityOptionType options) {
final AttributesBuilder newAtt = new AttributesBuilder(attributes);
if (options.equals(BgpSetCommunityOptionType.REPLACE)) {
return newAtt.setExtendedCommunities(actionExtCommunities).build();
}
final List<ExtendedCommunities> actualComm;
if (attributes.getCommunities() != null) {
actualComm = new ArrayList<>(attributes.getExtendedCommunities());
} else {
actualComm = new ArrayList<>();
}
switch(options) {
case ADD:
actualComm.addAll(actionExtCommunities);
break;
case REMOVE:
actualComm.removeAll(actionExtCommunities);
break;
default:
throw new IllegalArgumentException("Option Type not Recognized!");
}
return newAtt.setExtendedCommunities(actualComm).build();
}
Aggregations