use of org.opendaylight.protocol.bgp.parser.BGPParsingException in project bgpcep by opendaylight.
the class BgpTestActivator method startImpl.
@Override
protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
initMock();
final List<AutoCloseable> regs = Lists.newArrayList();
regs.add(context.registerAttributeParser(TYPE, this.attrParser));
regs.add(context.registerAttributeSerializer(DataObject.class, this.attrSerializer));
regs.add(context.registerParameterParser(TYPE, this.paramParser));
regs.add(context.registerParameterSerializer(BgpParameters.class, this.paramSerializer));
regs.add(context.registerCapabilityParser(TYPE, this.capaParser));
regs.add(context.registerCapabilitySerializer(CParameters.class, this.capaSerializer));
regs.add(context.registerBgpPrefixSidTlvParser(TYPE, this.sidTlvParser));
regs.add(context.registerBgpPrefixSidTlvSerializer(BgpPrefixSidTlv.class, this.sidTlvSerializer));
regs.add(context.registerMessageParser(TYPE, this.msgParser));
regs.add(context.registerMessageSerializer(Notification.class, this.msgSerializer));
regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
this.nextHopParserSerializer = new NextHopParserSerializer() {
@Override
public CNextHop parseNextHop(final ByteBuf buffer) throws BGPParsingException {
return new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.0.0.1")).build()).build();
}
@Override
public void serializeNextHop(final CNextHop cNextHop, final ByteBuf byteAggregator) {
final byte[] mpReachBytes = { 0x7f, 0x00, 0x00, 0x01 };
byteAggregator.writeBytes(mpReachBytes);
}
};
regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv4NextHopCase.class));
regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv6NextHopCase.class));
regs.add(context.registerNlriSerializer(DataObject.class, this.nlriSerializer));
regs.add(context.registerExtendedCommunityParser(0, 0, this.exParser));
regs.add(context.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, this.exSerializer));
return regs;
}
use of org.opendaylight.protocol.bgp.parser.BGPParsingException in project bgpcep by opendaylight.
the class SimpleNlriRegistry method getAfi.
private Class<? extends AddressFamily> getAfi(final ByteBuf buffer) throws BGPParsingException {
final int afiVal = buffer.readUnsignedShort();
final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
if (afi == null) {
throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
}
return afi;
}
use of org.opendaylight.protocol.bgp.parser.BGPParsingException in project bgpcep by opendaylight.
the class SimpleNlriRegistry method getSafi.
private Class<? extends SubsequentAddressFamily> getSafi(final ByteBuf buffer) throws BGPParsingException {
final int safiVal = buffer.readUnsignedByte();
final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
if (safi == null) {
throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
}
return safi;
}
use of org.opendaylight.protocol.bgp.parser.BGPParsingException in project bgpcep by opendaylight.
the class PeerDownHandler method parseBgpNotificationMessage.
private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.Notification parseBgpNotificationMessage(final ByteBuf bytes) throws BmpDeserializationException {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder notificationCBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder notificationBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder();
try {
final Notification not = this.msgRegistry.parseMessage(bytes, null);
requireNonNull(not, "Notify message may not be null.");
Preconditions.checkArgument(not instanceof NotifyMessage, "An instance of NotifyMessage is required");
notificationBuilder.fieldsFrom((NotifyMessage) not);
notificationCBuilder.setNotification(notificationBuilder.build());
} catch (final BGPDocumentedException | BGPParsingException e) {
throw new BmpDeserializationException("Error while parsing BGP Notification message.", e);
}
return notificationCBuilder.build();
}
use of org.opendaylight.protocol.bgp.parser.BGPParsingException in project bgpcep by opendaylight.
the class BGPUpdateMessageParser method parseMessageBody.
/**
* Parse Update message from buffer.
* Calls {@link #checkMandatoryAttributesPresence(Update)} to check for presence of mandatory attributes.
*
* @param buffer Encoded BGP message in ByteBuf
* @param messageLength Length of the BGP message
* @param constraint Peer specific constraints
* @return Parsed Update message body
*/
@Override
public Update parseMessageBody(final ByteBuf buffer, final int messageLength, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Buffer cannot be null or empty.");
final UpdateBuilder builder = new UpdateBuilder();
final boolean isMultiPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
final int withdrawnRoutesLength = buffer.readUnsignedShort();
if (withdrawnRoutesLength > 0) {
final List<WithdrawnRoutes> withdrawnRoutes = new ArrayList<>();
final ByteBuf withdrawnRoutesBuffer = buffer.readBytes(withdrawnRoutesLength);
while (withdrawnRoutesBuffer.isReadable()) {
final WithdrawnRoutesBuilder withdrawnRoutesBuilder = new WithdrawnRoutesBuilder();
if (isMultiPathSupported) {
withdrawnRoutesBuilder.setPathId(PathIdUtil.readPathId(withdrawnRoutesBuffer));
}
withdrawnRoutesBuilder.setPrefix(Ipv4Util.prefixForByteBuf(withdrawnRoutesBuffer));
withdrawnRoutes.add(withdrawnRoutesBuilder.build());
}
builder.setWithdrawnRoutes(withdrawnRoutes);
}
final int totalPathAttrLength = buffer.readUnsignedShort();
if (withdrawnRoutesLength == 0 && totalPathAttrLength == 0) {
return builder.build();
}
if (totalPathAttrLength > 0) {
try {
final Attributes attributes = this.reg.parseAttributes(buffer.readSlice(totalPathAttrLength), constraint);
builder.setAttributes(attributes);
} catch (final RuntimeException | BGPParsingException e) {
// Catch everything else and turn it into a BGPDocumentedException
throw new BGPDocumentedException("Could not parse BGP attributes.", BGPError.MALFORMED_ATTR_LIST, e);
}
}
final List<Nlri> nlri = new ArrayList<>();
while (buffer.isReadable()) {
final NlriBuilder nlriBuilder = new NlriBuilder();
if (isMultiPathSupported) {
nlriBuilder.setPathId(PathIdUtil.readPathId(buffer));
}
nlriBuilder.setPrefix(Ipv4Util.prefixForByteBuf(buffer));
nlri.add(nlriBuilder.build());
}
if (!nlri.isEmpty()) {
builder.setNlri(nlri);
}
final Update msg = builder.build();
checkMandatoryAttributesPresence(msg);
LOG.debug("BGP Update message was parsed {}.", msg);
return msg;
}
Aggregations