use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors in project bgpcep by opendaylight.
the class PcRptMessageCodec method getValidReports.
@Override
protected Reports getValidReports(final Queue<Object> objects, final List<Message> errors) {
final Optional<Object> find = Iterables.tryFind(objects, Predicates.instanceOf(BandwidthUsage.class));
final Object object;
if (find.isPresent()) {
object = find.get();
objects.remove(object);
} else {
object = null;
}
final Reports validReports = super.getValidReports(objects, errors);
if (object != null && validReports != null) {
final Path path = validReports.getPath();
if (path != null) {
return new ReportsBuilder(validReports).setPath(new PathBuilder(path).setBandwidth(setBandwidthUsage(path.getBandwidth(), (BandwidthUsage) object)).build()).build();
}
}
return validReports;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors in project bgpcep by opendaylight.
the class PCEPErrorMessageParser method insertObject.
private static State insertObject(final State state, final List<Errors> errorObjects, final Object obj, final List<Rps> requestParameters, final PcerrMessageBuilder msgBuilder) {
switch(state) {
case RP_IN:
if (obj instanceof Rp) {
final Rp o = (Rp) obj;
requestParameters.add(new RpsBuilder().setRp(o).build());
return State.RP_IN;
}
// fallthrough
case ERROR_IN:
if (obj instanceof ErrorObject) {
final ErrorObject o = (ErrorObject) obj;
errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
return State.ERROR_IN;
}
// fallthrough
case OPEN:
if (obj instanceof Open) {
msgBuilder.setErrorType(new SessionCaseBuilder().setSession(new SessionBuilder().setOpen((Open) obj).build()).build());
return State.OPEN_IN;
}
// fallthrough
case ERROR:
if (obj instanceof ErrorObject) {
final ErrorObject o = (ErrorObject) obj;
errorObjects.add(new ErrorsBuilder().setErrorObject(o).build());
return State.ERROR;
}
// fallthrough
case OPEN_IN:
case END:
return State.END;
default:
return state;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors in project bgpcep by opendaylight.
the class PCEPErrorMessageParser method serializeMessage.
@Override
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof PcerrMessage, "Wrong instance of Message. Passed instance of %s. Need PcerrMessage.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.PcerrMessage err = ((PcerrMessage) message).getPcerrMessage();
Preconditions.checkArgument(err.getErrors() != null && !err.nonnullErrors().isEmpty(), "Errors should not be empty.");
final ByteBuf buffer = Unpooled.buffer();
serializeCases(err, buffer);
for (final Errors e : err.nonnullErrors()) {
serializeObject(e.getErrorObject(), buffer);
}
if (err.getErrorType() instanceof SessionCase) {
serializeObject(((SessionCase) err.getErrorType()).getSession().getOpen(), buffer);
}
MessageUtil.formatMessage(TYPE, buffer, out);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors in project bgpcep by opendaylight.
the class PCEPErrorMessageParser 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 List<Rps> requestParameters = new ArrayList<>();
final List<Errors> errorObjects = new ArrayList<>();
final State initialState;
final Object first = objects.poll();
if (first instanceof ErrorObject) {
errorObjects.add(new ErrorsBuilder().setErrorObject((ErrorObject) first).build());
initialState = 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());
initialState = State.RP_IN;
} else if (first == null) {
throw new PCEPDeserializerException("Error message is empty.");
} else {
throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
}
final PcerrMessageBuilder msgBuilder = new PcerrMessageBuilder();
State state = initialState;
for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
if (obj instanceof UnknownObject) {
return new PcerrBuilder().setPcerrMessage(msgBuilder.setErrors(((UnknownObject) obj).getErrors()).build()).build();
}
state = insertObject(state, errorObjects, obj, requestParameters, msgBuilder);
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()) {
msgBuilder.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(requestParameters).build()).build());
}
return new PcerrBuilder().setPcerrMessage(msgBuilder.setErrors(errorObjects).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors in project bgpcep by opendaylight.
the class PCEPMonitoringRequestMessageParser method validate.
@Override
protected Message validate(final Queue<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.empty()));
}
final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder().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