use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder in project bgpcep by opendaylight.
the class CommunitiesAttributeParserTest method testCommunitiesAttributeParser.
@Test
public void testCommunitiesAttributeParser() throws Exception {
final List<Communities> comms = new ArrayList<>();
comms.add((Communities) CommunityUtil.NO_EXPORT);
comms.add((Communities) CommunityUtil.NO_ADVERTISE);
comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
comms.add((Communities) CommunityUtil.LLGR_STALE);
comms.add((Communities) CommunityUtil.NO_LLGR);
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setCommunities(comms);
final ByteBuf actual = Unpooled.buffer();
registry.serializeAttribute(paBuilder.build(), actual);
assertArrayEquals(COMMUNITIES_BYTES, ByteArray.getAllBytes(actual));
final Attributes attributeOut = registry.parseAttributes(actual, null).getAttributes();
assertEquals(comms, attributeOut.getCommunities());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder in project bgpcep by opendaylight.
the class NextHopAttributeParserTest method testParseEmptyIpv4Attribute.
@Test
public void testParseEmptyIpv4Attribute() {
final NullPointerException ex = assertThrows(NullPointerException.class, () -> registry.serializeAttribute(new AttributesBuilder().setCNextHop(new Ipv4NextHopCaseBuilder().build()).build(), Unpooled.buffer()));
assertNull(ex.getMessage());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder in project bgpcep by opendaylight.
the class OriginatorIdAttributeParserTest method testParseEmptyAttribute.
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
registry.serializeAttribute(new AttributesBuilder().setOriginatorId(new OriginatorIdBuilder().build()).build(), actual);
assertEquals(Unpooled.buffer(), actual);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder in project bgpcep by opendaylight.
the class AsPathAttributeParserTest method testParseEmptyAttribute.
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
registry.serializeAttribute(new AttributesBuilder().setAsPath(new AsPathBuilder().build()).build(), actual);
assertEquals(Unpooled.buffer().writeBytes(EMPTY_ATTRIBUTE_BYTES), actual);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder in project bgpcep by opendaylight.
the class SimpleAttributeRegistry method parseAttributes.
@Override
public ParsedAttributes parseAttributes(final ByteBuf buffer, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
final RevisedErrorHandling errorHandling = RevisedErrorHandling.from(constraint);
final Map<Integer, RawAttribute> attributes = new TreeMap<>();
BGPTreatAsWithdrawException withdrawCause = null;
while (buffer.isReadable()) {
try {
addAttribute(buffer, errorHandling, attributes);
} catch (BGPTreatAsWithdrawException e) {
LOG.info("Failed to completely parse attributes list.");
withdrawCause = e;
break;
}
}
/*
* TreeMap guarantees that we will be invoking the parser in the order
* of increasing attribute type.
*/
// We may have multiple attribute errors, each specifying a withdraw. We need to finish parsing the message
// all attributes before we can decide whether we can discard attributes, or whether we need to terminate
// the session.
final AttributesBuilder builder = new AttributesBuilder();
for (final Entry<Integer, RawAttribute> entry : attributes.entrySet()) {
LOG.debug("Parsing attribute type {}", entry.getKey());
final RawAttribute a = entry.getValue();
try {
a.parser.parseAttribute(a.buffer, builder, errorHandling, constraint);
} catch (BGPTreatAsWithdrawException e) {
LOG.info("Attribute {} indicated treat-as-withdraw", entry.getKey(), e);
if (withdrawCause == null) {
withdrawCause = e;
} else {
withdrawCause.addSuppressed(e);
}
}
}
builder.setUnrecognizedAttributes(BindingMap.ordered(this.unrecognizedAttributes));
return new ParsedAttributes(builder.build(), withdrawCause);
}
Aggregations