use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Svec in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method getValidSvec.
private static Svec getValidSvec(final SvecBuilder builder, final List<Object> objects) {
Preconditions.checkArgument(objects != null && !objects.isEmpty(), "Passed list can't be null or empty.");
if (objects.get(0) instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) {
builder.setSvec((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) objects.get(0));
objects.remove(0);
} else {
return null;
}
final List<Metrics> metrics = new ArrayList<>();
final List<VendorInformationObject> viObjects = new ArrayList<>();
Object obj = null;
SvecState state = SvecState.INIT;
while (!objects.isEmpty() && !state.equals(SvecState.END)) {
obj = objects.get(0);
state = insertObject(state, obj, builder, metrics, viObjects);
if (!state.equals(SvecState.END)) {
objects.remove(0);
}
}
if (!viObjects.isEmpty()) {
builder.setVendorInformationObject(viObjects);
}
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Svec in project bgpcep by opendaylight.
the class PCEPRequestMessageParser 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("Pcrep message cannot be empty.");
}
final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder();
mBuilder.setMonitoringRequest(getMonitoring(objects));
final List<Svec> svecs = getSvecs(objects);
if (!svecs.isEmpty()) {
mBuilder.setSvec(svecs);
}
final List<Requests> requests = getRequests(objects, errors);
if (requests != null) {
mBuilder.setRequests(requests);
} else {
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.absent()));
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcreqBuilder().setPcreqMessage(mBuilder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Svec in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method getSvecs.
protected List<Svec> getSvecs(final List<Object> objects) {
final List<Svec> svecList = new ArrayList<>();
while (!objects.isEmpty()) {
final SvecBuilder sBuilder = new SvecBuilder();
final Svec svecComp = getValidSvec(sBuilder, objects);
if (svecComp == null) {
break;
}
svecList.add(svecComp);
}
return svecList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Svec in project bgpcep by opendaylight.
the class PCEPSvecObjectParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof Svec, "Wrong instance of PCEPObject. Passed %s. Needed SvecObject.", object.getClass());
final Svec svecObj = (Svec) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(FLAGS_F_OFFSET);
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(L_FLAG_OFFSET, svecObj.isLinkDiverse());
flags.set(N_FLAG_OFFSET, svecObj.isNodeDiverse());
flags.set(S_FLAG_OFFSET, svecObj.isSrlgDiverse());
flags.toByteBuf(body);
final List<RequestId> requestIDs = svecObj.getRequestsIds();
assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids.";
for (final RequestId requestId : requestIDs) {
writeUnsignedInt(requestId.getValue(), body);
}
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Svec in project bgpcep by opendaylight.
the class PCEPMonitoringRequestMessageParser 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("Pcmonreq message cannot be empty.");
}
final MonitoringRequest monReq = getMonitoring(objects);
if (monReq == null) {
errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.absent()));
}
final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder();
mBuilder.setMonitoringRequest(monReq);
final List<Svec> svecs = getSvecs(objects);
if (!svecs.isEmpty()) {
mBuilder.setSvec(svecs);
}
final List<Requests> requests = getRequests(objects, errors);
if (requests != null && !requests.isEmpty()) {
mBuilder.setRequests(requests);
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcmonreqBuilder().setPcreqMessage(mBuilder.build()).build();
}
Aggregations