use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class ClientAttributePrependHandlerTest method testPreprendClientAttribute.
@Test
public void testPreprendClientAttribute() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("client-attribute-append-test")).findFirst().get();
final Attributes att = new AttributesBuilder().setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(IPV4).build()).build()).build();
final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(att);
doReturn(Collections.emptyList()).when(this.exportParameters).getClientRouteTargetContrainCache();
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertEquals(att, result.getAttributes());
final Attributes expected = new AttributesBuilder().setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("2.2.2.2")).build()).build()).build();
final String rk = "testRoute";
final Route rtRoute = new RouteTargetConstrainRouteBuilder().setRouteKey(rk).setPathId(new PathId(Uint32.ZERO)).setAttributes(expected).build();
doReturn(Collections.singletonList(rtRoute)).when(this.exportParameters).getClientRouteTargetContrainCache();
doReturn(rk).when(this.exportParameters).getRouteKey();
result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertEquals(expected, result.getAttributes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class OriginAttributeParser method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
final int readable = buffer.readableBytes();
if (readable != 1) {
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "ORIGIN attribute is expected to have size 1, but has %s", readable);
}
final byte rawOrigin = buffer.readByte();
final BgpOrigin borigin = BgpOrigin.forValue(UnsignedBytes.toInt(rawOrigin));
if (borigin == null) {
throw errorHandling.reportError(BGPError.ORIGIN_ATTR_NOT_VALID, "Unknown ORIGIN type %s", rawOrigin);
}
switch(borigin) {
case Egp:
builder.setOrigin(EGP);
return;
case Igp:
builder.setOrigin(IGP);
return;
case Incomplete:
builder.setOrigin(INC);
return;
default:
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class UnrecognizedAttributesSerializer method serializeAttribute.
@Override
public void serializeAttribute(final Attributes attributes, final ByteBuf byteAggregator) {
final Map<UnrecognizedAttributesKey, UnrecognizedAttributes> unrecognizedAttrs = attributes.getUnrecognizedAttributes();
if (unrecognizedAttrs == null) {
return;
}
for (final UnrecognizedAttributes unrecognizedAttr : unrecognizedAttrs.values()) {
LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType());
int flags = AttributeUtil.OPTIONAL;
if (unrecognizedAttr.getPartial()) {
flags |= AttributeUtil.PARTIAL;
}
if (unrecognizedAttr.getTransitive()) {
flags |= AttributeUtil.TRANSITIVE;
}
AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType().toJava(), Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class CommunitiesAttributeParser method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
final int readable = buffer.readableBytes();
if (readable == 0 && errorHandling != RevisedErrorHandling.NONE) {
throw new BGPTreatAsWithdrawException(BGPError.ATTR_LENGTH_ERROR, "Empty Community attribute");
}
if (readable % COMMUNITY_LENGTH != 0) {
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "Community attribute length must be a multiple of %s, have %s", COMMUNITY_LENGTH, readable);
}
final int count = readable / COMMUNITY_LENGTH;
final List<Communities> set = new ArrayList<>(count);
for (int i = 0; i < count; ++i) {
set.add((Communities) parseCommunity(this.refCache, buffer.readSlice(COMMUNITY_LENGTH)));
}
builder.setCommunities(set);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class ExtendedCommunitiesAttributeParser method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
final int readable = buffer.readableBytes();
if (errorHandling != RevisedErrorHandling.NONE) {
if (readable == 0) {
throw new BGPTreatAsWithdrawException(BGPError.ATTR_LENGTH_ERROR, "Empty Extended Community attribute");
}
}
if (readable % 8 != 0) {
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "Extended Community attribute length must be a multiple of 8, have %s", readable);
}
final List<ExtendedCommunities> set = new ArrayList<>(readable / 8);
while (buffer.isReadable()) {
final ExtendedCommunities exComm;
try {
// FIXME: BGPCEP-359: revise API contract here
exComm = this.ecReg.parseExtendedCommunity(buffer);
} catch (BGPParsingException e) {
throw errorHandling.reportError(BGPError.MALFORMED_ATTR_LIST, e, "Failed to parse extended community");
}
if (exComm != null) {
set.add(exComm);
}
}
builder.setExtendedCommunities(set);
}
Aggregations