import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
import org.opendaylight.protocol.concepts.Ipv4Util;
/**
* LENGTH fields, that denote the length of the fields with variable length, have fixed SIZE.
- *
+ *
* @see <a href="http://tools.ietf.org/html/rfc4271#section-4.3">BGP-4 Update Message Format</a>
- *
+ *
*/
public class BGPUpdateMessageParser implements MessageParser {
public static final int TYPE = 2;
final PathAttributes pathAttributes = this.reg.parseAttributes(buffer.slice(buffer.readerIndex(), totalPathAttrLength));
buffer.skipBytes(totalPathAttrLength);
eventBuilder.setPathAttributes(pathAttributes);
- } catch (final BGPDocumentedException e) {
- // Rethrow BGPDocumentedExceptions
- throw e;
- } catch (final Exception e) {
+ } catch (final BGPParsingException | RuntimeException e) {
// Catch everything else and turn it into a BGPDocumentedException
LOG.warn("Could not parse BGP attributes", e);
throw new BGPDocumentedException("Could not parse BGP attributes.", BGPError.MALFORMED_ATTR_LIST, e);
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.VsTlvBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.vs.tlv.VendorPayload;
-abstract public class AbstractVendorSpecificTlvParser implements TlvParser, TlvSerializer {
+public abstract class AbstractVendorSpecificTlvParser implements TlvParser, TlvSerializer {
- public static final int TYPE = 27;
+ public static final int TYPE = 27;
- protected static final int ENTERPRISE_NUM_LENGTH = 4;
+ protected static final int ENTERPRISE_NUM_LENGTH = 4;
- @Override
- public int getType() {
- return TYPE;
- }
+ @Override
+ public int getType() {
+ return TYPE;
+ }
- @Override
- public byte[] serializeTlv(Tlv tlv) {
- if (tlv == null) {
- throw new IllegalArgumentException("Vendor Specific Tlv is mandatory.");
- }
- final VsTlv vsTlv = (VsTlv) tlv;
- if (vsTlv.getEnterpriseNumber().getValue() == getEnterpriseNumber()) {
- final byte[] payloadBytes = serializeVendorPayload(vsTlv.getVendorPayload());
- final byte[] ianaNumBytes = ByteArray.longToBytes(vsTlv.getEnterpriseNumber().getValue(),
- ENTERPRISE_NUM_LENGTH);
+ @Override
+ public byte[] serializeTlv(final Tlv tlv) {
+ if (tlv == null) {
+ throw new IllegalArgumentException("Vendor Specific Tlv is mandatory.");
+ }
+ final VsTlv vsTlv = (VsTlv) tlv;
+ if (vsTlv.getEnterpriseNumber().getValue() == getEnterpriseNumber()) {
+ final byte[] payloadBytes = serializeVendorPayload(vsTlv.getVendorPayload());
+ final byte[] ianaNumBytes = ByteArray.longToBytes(vsTlv.getEnterpriseNumber().getValue(),
+ ENTERPRISE_NUM_LENGTH);
- final byte[] bytes = new byte[ianaNumBytes.length + payloadBytes.length];
- System.arraycopy(ianaNumBytes, 0, bytes, 0, ENTERPRISE_NUM_LENGTH);
- System.arraycopy(payloadBytes, 0, bytes, ENTERPRISE_NUM_LENGTH, payloadBytes.length);
- return TlvUtil.formatTlv(TYPE, bytes);
- }
- return new byte[0];
- }
+ final byte[] bytes = new byte[ianaNumBytes.length + payloadBytes.length];
+ System.arraycopy(ianaNumBytes, 0, bytes, 0, ENTERPRISE_NUM_LENGTH);
+ System.arraycopy(payloadBytes, 0, bytes, ENTERPRISE_NUM_LENGTH, payloadBytes.length);
+ return TlvUtil.formatTlv(TYPE, bytes);
+ }
+ return new byte[0];
+ }
- @Override
- public VsTlv parseTlv(byte[] valueBytes) throws PCEPDeserializerException {
- VsTlvBuilder vsTlvBuider = new VsTlvBuilder();
- if (valueBytes == null || valueBytes.length == 0) {
- throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- }
+ @Override
+ public VsTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
+ VsTlvBuilder vsTlvBuider = new VsTlvBuilder();
+ if (valueBytes == null || valueBytes.length == 0) {
+ throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+ }
- byte[] enBytes = ByteArray.subByte(valueBytes, 0, ENTERPRISE_NUM_LENGTH);
- long en = ByteArray.bytesToLong(enBytes);
- if (en == getEnterpriseNumber()) {
- vsTlvBuider.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
- int byteOffset = ENTERPRISE_NUM_LENGTH;
- int payloadLength = valueBytes.length - byteOffset;
- VendorPayload vendorPayload = null;
- if (payloadLength > 0) {
- byte[] payloadBytes = ByteArray.subByte(valueBytes, byteOffset, payloadLength);
- vendorPayload = parseVendorPayload(payloadBytes);
- if (vendorPayload != null) {
- vsTlvBuider.setVendorPayload(vendorPayload);
- }
- }
- }
- return vsTlvBuider.build();
- }
+ byte[] enBytes = ByteArray.subByte(valueBytes, 0, ENTERPRISE_NUM_LENGTH);
+ long en = ByteArray.bytesToLong(enBytes);
+ if (en == getEnterpriseNumber()) {
+ vsTlvBuider.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
+ int byteOffset = ENTERPRISE_NUM_LENGTH;
+ int payloadLength = valueBytes.length - byteOffset;
+ VendorPayload vendorPayload = null;
+ if (payloadLength > 0) {
+ byte[] payloadBytes = ByteArray.subByte(valueBytes, byteOffset, payloadLength);
+ vendorPayload = parseVendorPayload(payloadBytes);
+ if (vendorPayload != null) {
+ vsTlvBuider.setVendorPayload(vendorPayload);
+ }
+ }
+ }
+ return vsTlvBuider.build();
+ }
- abstract protected byte[] serializeVendorPayload(VendorPayload payload);
+ protected abstract byte[] serializeVendorPayload(VendorPayload payload);
- abstract protected long getEnterpriseNumber();
+ protected abstract long getEnterpriseNumber();
- abstract protected VendorPayload parseVendorPayload(byte[] payloadBytes) throws PCEPDeserializerException;
+ protected abstract VendorPayload parseVendorPayload(byte[] payloadBytes) throws PCEPDeserializerException;
- protected static int getPadding(final int length, final int padding) {
- return (padding - (length % padding)) % padding;
- }
+ protected static int getPadding(final int length, final int padding) {
+ return (padding - (length % padding)) % padding;
+ }
}
return req.getFuture();
}
- protected final synchronized void updateLsp(final DataModificationTransaction trans, final PLSPID id, String name,
+ protected final synchronized void updateLsp(final DataModificationTransaction trans, final PLSPID id, final String lspName,
final ReportedLspBuilder rlb, final boolean solicited) {
- if (name == null) {
+
+ final String name;
+ if (lspName == null) {
name = this.lsps.get(id);
if (name == null) {
LOG.error("PLSPID {} seen for the first time, not reporting the LSP", id);
return;
}
+ } else {
+ name = lspName;
}
+
LOG.debug("Saved LSP {} with name {}", id, name);
this.lsps.put(id, name);
lspData.remove(name);
}
- abstract protected void onSessionUp(PCEPSession session, PathComputationClientBuilder pccBuilder);
+ protected abstract void onSessionUp(PCEPSession session, PathComputationClientBuilder pccBuilder);
- abstract protected boolean onMessage(DataModificationTransaction trans, Message message);
+ protected abstract boolean onMessage(DataModificationTransaction trans, Message message);
protected String lookupLspName(final PLSPID id) {
Preconditions.checkNotNull(id, "ID parameter null.");