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 PCEPRequestMessageParser method getMonitoring.
protected MonitoringRequest getMonitoring(final Queue<Object> objects) {
final MonitoringRequestBuilder builder = new MonitoringRequestBuilder();
Object obj = objects.peek();
if (obj instanceof Monitoring) {
builder.setMonitoring((Monitoring) obj);
objects.remove();
} else {
return null;
}
obj = objects.peek();
if (obj instanceof PccIdReq) {
builder.setPccIdReq((PccIdReq) obj);
objects.remove();
obj = objects.peek();
}
final List<PceIdList> pceIdList = new ArrayList<>();
while (obj instanceof PceId) {
pceIdList.add(new PceIdListBuilder().setPceId((PceId) obj).build());
objects.remove();
obj = objects.peek();
}
if (!pceIdList.isEmpty()) {
builder.setPceIdList(pceIdList);
}
return builder.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 PCEPMonitoringObjectParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
checkArgument(object instanceof Monitoring, "Wrong instance of PCEPObject. Passed %s. Needed MonitoringObject.", object.getClass());
final Monitoring monitoring = (Monitoring) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(RESERVED);
final Flags flags = monitoring.getFlags();
final BitArray flagBits = new BitArray(FLAGS_SIZE);
flagBits.set(I_FLAG_POS, flags.getIncomplete());
flagBits.set(C_FLAG_POS, flags.getOverload());
flagBits.set(P_FLAG_POS, flags.getProcessingTime());
flagBits.set(G_FLAG_POS, flags.getGeneral());
flagBits.set(L_FLAG_POS, flags.getLiveness());
flagBits.toByteBuf(body);
ByteBufUtils.writeOrZero(body, monitoring.getMonitoringId());
serializeTlvs(monitoring.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), 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 PCEPMonitoringObjectParser method parseObject.
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
buffer.skipBytes(RESERVED);
final BitArray flagBits = BitArray.valueOf(buffer, FLAGS_SIZE);
final Flags flags = new Flags(flagBits.get(G_FLAG_POS), flagBits.get(I_FLAG_POS), flagBits.get(L_FLAG_POS), flagBits.get(C_FLAG_POS), flagBits.get(P_FLAG_POS));
final Uint32 monitoring = ByteBufUtils.readUint32(buffer);
final TlvsBuilder tbuilder = new TlvsBuilder();
parseTlvs(tbuilder, buffer.slice());
return new MonitoringBuilder().setFlags(flags).setMonitoringId(monitoring).setTlvs(tbuilder.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 testMonReqMsg.
@Test
public void testMonReqMsg() throws PCEPDeserializerException, IOException {
final PCEPMonitoringRequestMessageParser parser = new PCEPMonitoringRequestMessageParser(this.objectRegistry);
final PcreqMessageBuilder builder = new PcreqMessageBuilder();
final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder().setMonitoring(this.monitoring).setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build()));
builder.setMonitoringRequest(monReqBuilder.build());
final byte[] msgBytes = { 0x20, 0x08, 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 PcmonreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonReq.bin"));
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Requests> reqs2 = new ArrayList<>();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder();
rBuilder1.setRp(this.rpTrue);
final P2pBuilder p2pBuilder = new P2pBuilder().setEndpointsObj(this.endpoints).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro);
rBuilder1.setSegmentComputation(new SegmentComputationBuilder().setP2p(p2pBuilder.build()).build());
reqs2.add(rBuilder1.build());
builder.setRequests(reqs2).setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.SvecBuilder().setSvec(this.svec).build()));
monReqBuilder.setMonitoring(this.monitoring).setPccIdReq(this.pccIdReq);
final PceIdList pceIdList = new PceIdListBuilder().setPceId(this.pceId).build();
monReqBuilder.setPceIdList(Lists.newArrayList(pceIdList, pceIdList));
builder.setMonitoringRequest(monReqBuilder.build());
assertEquals(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
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 PCEPObjectParserTest method testMonitoringObject.
@Test
public void testMonitoringObject() throws PCEPDeserializerException {
final byte[] monitoringBytes = { /* object header */
0x13, 0x10, 0x00, 0x0C, /* flags */
0x00, 0x00, 0x00, 0x01, /* monitoring-id=16 */
0x00, 0x00, 0x00, 0x10 };
final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(Uint32.valueOf(16L)).setFlags(new Flags(false, false, true, false, false)).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.monitoring.TlvsBuilder().build()).build();
final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
parser.serializeObject(monitoring, buf);
assertArrayEquals(monitoringBytes, buf.array());
}
Aggregations