use of org.opendaylight.protocol.pcep.spi.PCEPDeserializerException in project bgpcep by opendaylight.
the class BandwidthUsageObjectCodec method parseObject.
@Override
public BandwidthUsage parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() % BW_LENGTH != 0) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected multiple of " + BW_LENGTH + ".");
}
final BandwidthUsageBuilder builder = new BandwidthUsageBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
final List<Bandwidth> bwSamples = new ArrayList<>(bytes.readableBytes() / BW_LENGTH);
while (bytes.isReadable()) {
bwSamples.add(new Bandwidth(ByteArray.readBytes(bytes, BW_LENGTH)));
}
builder.setBwSample(bwSamples);
return builder.build();
}
use of org.opendaylight.protocol.pcep.spi.PCEPDeserializerException in project bgpcep by opendaylight.
the class PCCEndPointIpv4ObjectParser method parseObject.
@Override
public Object parseObject(ObjectHeader header, ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final EndpointsObjBuilder builder = new EndpointsObjBuilder();
if (bytes.readableBytes() != Ipv4Util.IP4_LENGTH * 2) {
throw new PCEPDeserializerException("Wrong length of array of bytes.");
}
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
final Ipv4Builder b = new Ipv4Builder();
b.setSourceIpv4Address(Ipv4Util.addressForByteBuf(bytes));
b.setDestinationIpv4Address((Ipv4Util.addressForByteBuf(bytes)));
builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(b.build()).build());
return builder.build();
}
use of org.opendaylight.protocol.pcep.spi.PCEPDeserializerException in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testPathBindingTlvMplsLabel.
@Test
public void testPathBindingTlvMplsLabel() throws PCEPDeserializerException {
final byte[] pathBindingBytes = { 0x00, 0x1f, 0x00, 0x06, 0x00, 0x00, (byte) 0xA8, 0x0F, (byte) 0x60, 0x00, 0x00, 0x00 };
final PathBindingTlvParser parser = new PathBindingTlvParser();
final PathBindingBuilder builder = new PathBindingBuilder();
builder.setBindingTypeValue(new MplsLabelBuilder().setMplsLabel(new MplsLabel(688_374L)).build());
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(builder.build(), buff);
assertArrayEquals(pathBindingBytes, ByteArray.readAllBytes(buff));
try {
final byte[] wrong = { 0, 0x1f, 0, 4, 1, 1, 2, 3 };
parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(wrong, 4)));
fail();
} catch (final PCEPDeserializerException e) {
assertEquals("Unsupported Path Binding Type: 257", e.getMessage());
}
}
use of org.opendaylight.protocol.pcep.spi.PCEPDeserializerException in project bgpcep by opendaylight.
the class Stateful07PCUpdateRequestMessageParser method validate.
@Override
protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
Preconditions.checkArgument(objects != null, "Passed list can't be null.");
if (objects.isEmpty()) {
throw new PCEPDeserializerException("Pcup message cannot be empty.");
}
final List<Updates> updateRequests = Lists.newArrayList();
while (!objects.isEmpty()) {
final Updates upd = getValidUpdates(objects, errors);
if (upd != null) {
updateRequests.add(upd);
}
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcupdBuilder().setPcupdMessage(new PcupdMessageBuilder().setUpdates(updateRequests).build()).build();
}
use of org.opendaylight.protocol.pcep.spi.PCEPDeserializerException in project bgpcep by opendaylight.
the class Stateful07SrpObjectParser method parseObject.
@Override
public Srp parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() < MIN_SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + ".");
}
final SrpBuilder builder = new SrpBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
parseFlags(builder, bytes);
builder.setOperationId(new SrpIdNumber(bytes.readUnsignedInt()));
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
builder.setTlvs(tlvsBuilder.build());
return builder.build();
}
Aggregations