use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce in project bgpcep by opendaylight.
the class PCEPMonitoringReplyMessageParser method validateSpecificMetrics.
private static void validateSpecificMetrics(final List<Object> objects, final PcmonrepMessageBuilder builder) throws PCEPDeserializerException {
final List<SpecificMetrics> specificMetrics = new ArrayList<>();
while (!objects.isEmpty()) {
final SpecificMetricsBuilder smb = new SpecificMetricsBuilder();
final List<MetricPce> metricPceList = new ArrayList<>();
if (objects.get(0) instanceof Rp) {
smb.setRp((Rp) objects.get(0));
objects.remove(0);
}
while (!objects.isEmpty() && !(objects.get(0) instanceof Rp)) {
metricPceList.add(Util.validateMonitoringMetrics(objects));
}
if (smb.getRp() != null) {
smb.setMetricPce(metricPceList);
specificMetrics.add(smb.build());
} else if (!metricPceList.isEmpty()) {
builder.setMonitoringMetricsList(new GeneralMetricsListBuilder().setMetricPce(metricPceList).build());
}
}
if (!specificMetrics.isEmpty()) {
builder.setMonitoringMetricsList(new SpecificMetricsListBuilder().setSpecificMetrics(specificMetrics).build());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method getValidReply.
protected Replies getValidReply(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
Object object = objects.remove(0);
if (!(object instanceof Rp)) {
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.absent()));
return null;
}
final Rp rp = (Rp) object;
final RepliesBuilder repliesBuilder = new RepliesBuilder();
if (!objects.isEmpty() && objects.get(0) instanceof Monitoring) {
repliesBuilder.setMonitoring((Monitoring) objects.get(0));
objects.remove(0);
}
if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
repliesBuilder.setPccIdReq((PccIdReq) objects.get(0));
objects.remove(0);
}
final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
Result res = null;
if (!objects.isEmpty()) {
if (objects.get(0) instanceof NoPath) {
res = handleNoPath((NoPath) objects.get(0), objects);
} else if (objects.get(0) instanceof Ero) {
res = handleEro((Ero) objects.get(0), objects);
}
}
final List<MetricPce> metricPceList = new ArrayList<>();
if (!objects.isEmpty() && objects.get(0) instanceof PceId) {
while (!objects.isEmpty()) {
metricPceList.add(Util.validateMonitoringMetrics(objects));
}
}
if (!vendorInfo.isEmpty()) {
repliesBuilder.setVendorInformationObject(vendorInfo);
}
if (!metricPceList.isEmpty()) {
repliesBuilder.setMetricPce(metricPceList);
}
return repliesBuilder.setRp(rp).setResult(res).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce 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);
builder.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 = Lists.newArrayList();
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 = Lists.newArrayList();
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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce in project bgpcep by opendaylight.
the class Util method validateMonitoringMetrics.
public static MetricPce validateMonitoringMetrics(final List<Object> objects) throws PCEPDeserializerException {
final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
if (!(objects.get(0) instanceof PceId)) {
throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
}
metricPceBuilder.setPceId((PceId) (objects.get(0)));
objects.remove(0);
State state = State.START;
while (!objects.isEmpty() && !state.equals(State.END)) {
final Object obj = objects.get(0);
state = insertObject(metricPceBuilder, state, obj);
if (!state.equals(State.END)) {
objects.remove(0);
}
}
return metricPceBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce in project bgpcep by opendaylight.
the class PCEPMonitoringReplyMessageParser method serializeMessage.
@Override
public void serializeMessage(final Message message, final ByteBuf buffer) {
Preconditions.checkArgument(message instanceof Pcmonrep, "Wrong instance of Message. Passed instance of %s. Need Pcmonrep.", message.getClass());
final PcmonrepMessage monRepMsg = ((Pcmonrep) message).getPcmonrepMessage();
Preconditions.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();
if (gml.getMetricPce() != null) {
for (final MetricPce metricPce : gml.getMetricPce()) {
serializeMetricPce(metricPce, body);
}
}
} else if (monRepMsg.getMonitoringMetricsList() instanceof SpecificMetricsList) {
final SpecificMetricsList sml = (SpecificMetricsList) monRepMsg.getMonitoringMetricsList();
if (sml.getSpecificMetrics() != null) {
for (final SpecificMetrics specificMetrics : sml.getSpecificMetrics()) {
serializeObject(specificMetrics.getRp(), body);
if (specificMetrics.getMetricPce() != null) {
for (final MetricPce metricPce : specificMetrics.getMetricPce()) {
serializeMetricPce(metricPce, body);
}
}
}
}
}
MessageUtil.formatMessage(TYPE, body, buffer);
}
Aggregations