use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method serializeMessage.
@Override
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof Pcrep, "Wrong instance of Message. Passed instance of %s. Need Pcrep.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessage repMsg = ((Pcrep) message).getPcrepMessage();
Preconditions.checkArgument(repMsg.getReplies() != null && !repMsg.getReplies().isEmpty(), "Replies cannot be null or empty.");
final ByteBuf buffer = Unpooled.buffer();
for (final Replies reply : repMsg.getReplies()) {
Preconditions.checkArgument(reply.getRp() != null, "Reply must contain RP object.");
serializeReply(reply, buffer);
}
MessageUtil.formatMessage(TYPE, buffer, out);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method validate.
@Override
protected Pcrep 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 List<Replies> replies = new ArrayList<>();
while (!objects.isEmpty()) {
final Replies r = this.getValidReply(objects, errors);
if (r != null) {
replies.add(r);
}
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
return new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().setReplies(replies).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method getValidReply.
protected Replies getValidReply(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
Object object = objects.remove(0);
if (!(object instanceof Rp)) {
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.absent()));
return null;
}
final Rp rp = (Rp) object;
final RepliesBuilder repliesBuilder = new RepliesBuilder();
if (!objects.isEmpty() && objects.get(0) instanceof Monitoring) {
repliesBuilder.setMonitoring((Monitoring) objects.get(0));
objects.remove(0);
}
if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
repliesBuilder.setPccIdReq((PccIdReq) objects.get(0));
objects.remove(0);
}
final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
Result res = null;
if (!objects.isEmpty()) {
if (objects.get(0) instanceof NoPath) {
res = handleNoPath((NoPath) objects.get(0), objects);
} else if (objects.get(0) instanceof Ero) {
res = handleEro((Ero) objects.get(0), objects);
}
}
final List<MetricPce> metricPceList = new ArrayList<>();
if (!objects.isEmpty() && objects.get(0) instanceof PceId) {
while (!objects.isEmpty()) {
metricPceList.add(Util.validateMonitoringMetrics(objects));
}
}
if (!vendorInfo.isEmpty()) {
repliesBuilder.setVendorInformationObject(vendorInfo);
}
if (!metricPceList.isEmpty()) {
repliesBuilder.setMetricPce(metricPceList);
}
return repliesBuilder.setRp(rp).setResult(res).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method getRequests.
protected List<Requests> getRequests(final List<Object> objects, final List<Message> errors) {
final List<Requests> requests = new ArrayList<>();
while (!objects.isEmpty()) {
final RequestsBuilder rBuilder = new RequestsBuilder();
Rp rpObj = null;
if (!(objects.get(0) instanceof Rp)) {
// if RP obj is missing return error only
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.absent()));
return null;
}
rpObj = (Rp) objects.get(0);
objects.remove(0);
if (!rpObj.isProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.absent()));
} else {
rBuilder.setRp(rpObj);
}
final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
if (!vendorInfo.isEmpty()) {
rBuilder.setVendorInformationObject(vendorInfo);
}
// expansion
if (rpObj.isPathKey() && objects.get(0) instanceof PathKey) {
rBuilder.setPathKeyExpansion(new PathKeyExpansionBuilder().setPathKey((PathKey) objects.get(0)).build());
}
final P2pBuilder p2pBuilder = new P2pBuilder();
if (!objects.isEmpty() && objects.get(0) instanceof EndpointsObj) {
final EndpointsObj ep = (EndpointsObj) objects.get(0);
objects.remove(0);
if (!ep.isProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rpObj)));
} else {
p2pBuilder.setEndpointsObj(ep);
}
} else {
errors.add(createErrorMsg(PCEPErrors.END_POINTS_MISSING, Optional.of(rpObj)));
return null;
}
// p2p
if (!rpObj.isP2mp()) {
final SegmentComputation segm = getSegmentComputation(p2pBuilder, objects, errors, rpObj);
if (segm != null) {
rBuilder.setSegmentComputation(segm);
}
}
requests.add(rBuilder.build());
}
return requests;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.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();
}
Aggregations