use of com.google.storage.v2.Object 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 com.google.storage.v2.Object in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method insertObject.
private static State insertObject(final State state, final List<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
final Object obj = objects.get(0);
switch(state) {
case INIT:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
objects.remove(0);
final Object nextObj = objects.get(0);
if (nextObj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
builder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) nextObj);
}
return State.REPORTED_IN;
}
case REPORTED_IN:
if (obj instanceof VendorInformationObject) {
viObjects.add((VendorInformationObject) obj);
return State.REPORTED_IN;
}
case VENDOR_INFO_LIST:
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
return State.LOAD_BIN;
}
case LOAD_BIN:
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
return State.LSPA_IN;
}
case LSPA_IN:
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
return State.BANDWIDTH_IN;
}
case BANDWIDTH_IN:
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
return State.BANDWIDTH_IN;
}
case METRIC_IN:
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
return State.IRO_IN;
}
case IRO_IN:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
return State.RRO_IN;
}
case RRO_IN:
if (obj instanceof Xro) {
builder.setXro((Xro) obj);
return State.XRO_IN;
}
case XRO_IN:
if (obj instanceof Of) {
builder.setOf((Of) obj);
return State.OF_IN;
}
case OF_IN:
if (obj instanceof ClassType) {
final ClassType classType = (ClassType) obj;
if (!classType.isProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
} else {
builder.setClassType(classType);
}
return State.CT_IN;
}
case CT_IN:
case END:
return State.END;
default:
return state;
}
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class PCEPCloseMessageParser method validate.
@Override
protected Close validate(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
checkArgument(objects != null, "Passed list can't be null.");
final Object o = objects.poll();
if (!(o instanceof CClose)) {
throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
}
final CCloseMessage msg = new CCloseMessageBuilder().setCClose((CClose) o).build();
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new CloseBuilder().setCCloseMessage(msg).build();
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class AbstractMessageParser method parseObjects.
private Queue<Object> parseObjects(final ByteBuf bytes) throws PCEPDeserializerException {
final Queue<Object> objs = new ArrayDeque<>();
while (bytes.isReadable()) {
if (bytes.readableBytes() < COMMON_OBJECT_HEADER_LENGTH) {
throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + COMMON_OBJECT_HEADER_LENGTH + ".");
}
final int objClass = bytes.readUnsignedByte();
final byte flagsByte = bytes.readByte();
final BitArray flags = BitArray.valueOf(flagsByte);
final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(flagsByte, OT_SF_OFFSET, OT_SF_LENGTH));
final int objLength = bytes.readUnsignedShort();
if (bytes.readableBytes() < objLength - COMMON_OBJECT_HEADER_LENGTH) {
throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + objLength + ".");
}
// copy bytes for deeper parsing
final ByteBuf bytesToPass = bytes.readSlice(objLength - COMMON_OBJECT_HEADER_LENGTH);
final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED));
if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) {
final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(ByteBufUtils.readUint32(bytesToPass));
this.registry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass).ifPresent(objs::add);
} else {
// parseObject is required to return null for P=0 errored objects
final Object o = this.registry.parseObject(objClass, objType, header, bytesToPass);
if (o != null) {
objs.add(o);
}
}
}
return objs;
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class StatefulErrorMessageParser method validate.
@Override
protected PcerrMessage validate(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
checkArgument(objects != null, "Passed list can't be null.");
final Object first = objects.peek();
if (first == null) {
throw new PCEPDeserializerException("Error message is empty.");
}
final List<Rps> requestParameters = new ArrayList<>();
final List<Srps> srps = new ArrayList<>();
final List<Errors> errorObjects = new ArrayList<>();
final PcerrMessageBuilder b = new PcerrMessageBuilder();
State state = State.INIT;
if (first instanceof ErrorObject) {
errorObjects.add(new ErrorsBuilder().setErrorObject((ErrorObject) first).build());
state = State.ERROR_IN;
} else if (first instanceof Rp) {
final Rp rp = (Rp) first;
if (rp.getProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.empty()));
return null;
}
requestParameters.add(new RpsBuilder().setRp(rp).build());
state = State.RP_IN;
} else if (first instanceof Srp) {
srps.add(new SrpsBuilder().setSrp((Srp) first).build());
state = State.SRP_IN;
}
if (state != State.INIT) {
objects.remove();
}
for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
if (obj instanceof UnknownObject) {
return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build();
}
state = insertObject(state, obj, errorObjects, requestParameters, srps, b);
if (state == State.END) {
break;
}
objects.remove();
}
if (errorObjects.isEmpty()) {
throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
if (!requestParameters.isEmpty()) {
b.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(requestParameters).build()).build());
}
if (!srps.isEmpty()) {
b.setErrorType(new StatefulCaseBuilder().setStateful(new StatefulBuilder().setSrps(srps).build()).build());
}
return new PcerrBuilder().setPcerrMessage(b.setErrors(errorObjects).build()).build();
}
Aggregations