use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonrepBuilder in project bgpcep by opendaylight.
the class PCEPMonitoringReplyMessageParser 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("Pcmonrep message cannot be empty.");
}
if (!(objects.get(0) instanceof Monitoring)) {
errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.absent()));
return null;
}
final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder();
builder.setMonitoring((Monitoring) objects.get(0));
objects.remove(0);
if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
builder.setPccIdReq((PccIdReq) objects.get(0));
objects.remove(0);
}
validateSpecificMetrics(objects, builder);
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonrepBuilder in project bgpcep by opendaylight.
the class PCEPMonitoringReplyMessageParser method validate.
@Override
protected Message validate(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
checkArgument(objects != null, "Passed list can't be null.");
final Object monitoring = objects.poll();
if (monitoring == null) {
throw new PCEPDeserializerException("Pcmonrep message cannot be empty.");
}
if (!(monitoring instanceof Monitoring)) {
errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.empty()));
return null;
}
final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder().setMonitoring((Monitoring) monitoring);
final Object obj = objects.peek();
if (obj instanceof PccIdReq) {
builder.setPccIdReq((PccIdReq) obj);
objects.remove();
}
validateSpecificMetrics(objects, builder);
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcmonrepBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testMonRepMsg.
@Test
public void testMonRepMsg() throws PCEPDeserializerException, IOException {
final PCEPMonitoringReplyMessageParser parser = new PCEPMonitoringReplyMessageParser(this.objectRegistry);
final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder();
builder.setMonitoring(this.monitoring).setMonitoringMetricsList(new GeneralMetricsListBuilder().setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())).build());
final byte[] msgBytes = { 0x20, 0x09, 0x00, 0x18, /* monitoring object */
0x13, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, /* pce-id object */
0x19, 0x10, 0x00, 0x08, 0x7f, 0x00, 0x00, 0x02 };
ByteBuf result = Unpooled.wrappedBuffer(msgBytes);
assertEquals(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
builder.setMonitoring(this.monitoring);
builder.setPccIdReq(this.pccIdReq);
final SpecificMetricsBuilder smBuilder = new SpecificMetricsBuilder();
smBuilder.setRp(this.rpTrue);
final List<MetricPce> metricPces = new ArrayList<>();
metricPces.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).setProcTime(this.procTime).build());
metricPces.add(new MetricPceBuilder().setPceId(this.pceId).setProcTime(this.procTime).build());
smBuilder.setMetricPce(metricPces);
final SpecificMetricsBuilder smBuilder2 = new SpecificMetricsBuilder();
final List<MetricPce> metricPces2 = new ArrayList<>();
smBuilder2.setRp(this.rpTrue);
metricPces2.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).build());
smBuilder2.setMetricPce(metricPces2);
builder.setMonitoringMetricsList(new SpecificMetricsListBuilder().setSpecificMetrics(Lists.newArrayList(smBuilder.build(), smBuilder2.build())).build());
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonRep.bin"));
assertEquals(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
Aggregations