use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method getValidReply.
protected Replies getValidReply(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
Object obj = objects.remove();
if (!(obj instanceof Rp)) {
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.empty()));
return null;
}
final RepliesBuilder repliesBuilder = new RepliesBuilder().setRp((Rp) obj);
obj = objects.peek();
if (obj instanceof Monitoring) {
repliesBuilder.setMonitoring((Monitoring) obj);
objects.remove();
obj = objects.peek();
}
if (obj instanceof PccIdReq) {
repliesBuilder.setPccIdReq((PccIdReq) obj);
objects.remove();
// last option, no need to peek
}
// note: this may modify 'objects'
final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
if (!vendorInfo.isEmpty()) {
repliesBuilder.setVendorInformationObject(vendorInfo);
}
final Result res;
obj = objects.peek();
if (obj instanceof NoPath) {
objects.remove();
res = handleNoPath((NoPath) obj, objects);
} else if (obj instanceof Ero) {
res = handleEros(objects);
} else {
res = null;
}
if (objects.peek() instanceof PceId) {
final List<MetricPce> metricPceList = new ArrayList<>();
while (!objects.isEmpty()) {
metricPceList.add(Util.validateMonitoringMetrics(objects));
}
if (!metricPceList.isEmpty()) {
repliesBuilder.setMetricPce(metricPceList);
}
}
return repliesBuilder.setResult(res).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring in project bgpcep by opendaylight.
the class PCEPMonitoringReplyMessageParser method serializeMessage.
@Override
public void serializeMessage(final Message message, final ByteBuf buffer) {
checkArgument(message instanceof Pcmonrep, "Wrong instance of Message. Passed instance of %s. Need Pcmonrep.", message.getClass());
final PcmonrepMessage monRepMsg = ((Pcmonrep) message).getPcmonrepMessage();
checkArgument(monRepMsg.getMonitoring() != null, "MONITORING object is mandatory.");
final ByteBuf body = Unpooled.buffer();
serializeObject(monRepMsg.getMonitoring(), body);
serializeObject(monRepMsg.getPccIdReq(), body);
if (monRepMsg.getMonitoringMetricsList() instanceof GeneralMetricsList) {
final GeneralMetricsList gml = (GeneralMetricsList) monRepMsg.getMonitoringMetricsList();
for (final MetricPce metricPce : gml.nonnullMetricPce()) {
serializeMetricPce(metricPce, body);
}
} else if (monRepMsg.getMonitoringMetricsList() instanceof SpecificMetricsList) {
final SpecificMetricsList sml = (SpecificMetricsList) monRepMsg.getMonitoringMetricsList();
for (final SpecificMetrics specificMetrics : sml.nonnullSpecificMetrics()) {
serializeObject(specificMetrics.getRp(), body);
for (final MetricPce metricPce : specificMetrics.nonnullMetricPce()) {
serializeMetricPce(metricPce, body);
}
}
}
MessageUtil.formatMessage(TYPE, body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring 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.types.rev181109.monitoring.object.Monitoring 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