use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReq 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.pcc.id.req.object.PccIdReq in project bgpcep by opendaylight.
the class AbstractPccIdReqObjectParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
checkArgument(object instanceof PccIdReq, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.", object.getClass());
final PccIdReq pccIdReq = (PccIdReq) object;
if (pccIdReq.getIpAddress().getIpv4AddressNoZone() != null) {
final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
Ipv4Util.writeIpv4Address(pccIdReq.getIpAddress().getIpv4AddressNoZone(), body);
ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.getProcessingRule(), object.getIgnore(), body, buffer);
} else if (pccIdReq.getIpAddress().getIpv6AddressNoZone() != null) {
final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
Ipv6Util.writeIpv6Address(pccIdReq.getIpAddress().getIpv6AddressNoZone(), body);
ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.getProcessingRule(), object.getIgnore(), body, buffer);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReq 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.pcc.id.req.object.PccIdReq in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testPccIdReqIPv6Object.
@Test
public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
final byte[] pccIdReqBytes = { /* object header */
0x14, 0x20, 0x00, 0x14, /* ipv6 address */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv6AddressNoZone("::1"))).build();
final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
parser.serializeObject(pccIdReq, buf);
assertArrayEquals(pccIdReqBytes, buf.array());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcc.id.req.object.PccIdReq in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testPccIdReqIPv4Object.
@Test
public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
final byte[] pccIdReqBytes = { /* object header */
0x14, 0x10, 0x00, 0x08, /* ipv4 address */
0x7f, 0x00, 0x00, 0x01 };
final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1"))).build();
final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
parser.serializeObject(pccIdReq, buf);
assertArrayEquals(pccIdReqBytes, buf.array());
}
Aggregations