use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsage in project bgpcep by opendaylight.
the class BandwidthUsageObjectCodec method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof BandwidthUsage, "Wrong instance of PCEPObject. Passed %s. Needed BandwidthUsage.", object.getClass());
final List<Bandwidth> bwSample = ((BandwidthUsage) object).getBwSample();
final ByteBuf body = Unpooled.buffer(bwSample.size() * BW_LENGTH);
for (final Bandwidth bw : bwSample) {
writeFloat32(bw, body);
}
ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.getProcessingRule(), object.getIgnore(), body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsage in project bgpcep by opendaylight.
the class PcRptMessageCodec method getValidReports.
@Override
protected Reports getValidReports(final Queue<Object> objects, final List<Message> errors) {
final Optional<Object> find = Iterables.tryFind(objects, Predicates.instanceOf(BandwidthUsage.class));
final Object object;
if (find.isPresent()) {
object = find.get();
objects.remove(object);
} else {
object = null;
}
final Reports validReports = super.getValidReports(objects, errors);
if (object != null && validReports != null) {
final Path path = validReports.getPath();
if (path != null) {
return new ReportsBuilder(validReports).setPath(new PathBuilder(path).setBandwidth(setBandwidthUsage(path.getBandwidth(), (BandwidthUsage) object)).build()).build();
}
}
return validReports;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsage 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().setIgnore(header.getIgnore()).setProcessingRule(header.getProcessingRule());
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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsage in project bgpcep by opendaylight.
the class PcRptMessageCodec method setBandwidthUsage.
private static Bandwidth setBandwidthUsage(final Bandwidth bandwidth, final BandwidthUsage bwUsage) {
final BandwidthBuilder bandwidthBuilder;
if (bandwidth != null) {
bandwidthBuilder = new BandwidthBuilder(bandwidth);
} else {
bandwidthBuilder = new BandwidthBuilder();
}
bandwidthBuilder.addAugmentation(Bandwidth1.class, new Bandwidth1Builder().setBwSample(bwUsage.getBwSample()).build()).build();
return bandwidthBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsage in project bgpcep by opendaylight.
the class PcRptMessageCodec method getValidReports.
@Override
protected Reports getValidReports(final List<Object> objects, final List<Message> errors) {
final Optional<Object> find = Iterables.tryFind(objects, Predicates.instanceOf(BandwidthUsage.class));
final Object object;
if (find.isPresent()) {
object = find.get();
objects.remove(object);
} else {
object = null;
}
final Reports validReports = super.getValidReports(objects, errors);
if (object != null && validReports != null) {
final Path path = validReports.getPath();
if (path != null) {
return new ReportsBuilder(validReports).setPath(new PathBuilder(path).setBandwidth(setBandwidthUsage(path.getBandwidth(), (BandwidthUsage) object)).build()).build();
}
}
return validReports;
}
Aggregations