use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.SegmentComputation 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.rev181109.pcreq.message.pcreq.message.requests.SegmentComputation in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method serializeRequest.
protected void serializeRequest(final PcreqMessage msg, final ByteBuf buffer) {
for (final Requests req : msg.nonnullRequests()) {
serializeObject(req.getRp(), buffer);
serializeVendorInformationObjects(req.getVendorInformationObject(), buffer);
if (req.getPathKeyExpansion() != null) {
serializeObject(req.getPathKeyExpansion().getPathKey(), buffer);
}
if (req.getSegmentComputation() != null) {
final SegmentComputation sc = req.getSegmentComputation();
if (sc.getP2p() != null) {
serializeP2P(buffer, sc.getP2p());
}
if (sc.getP2mp() != null) {
serializeP2MP(buffer, sc.getP2mp());
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.SegmentComputation in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method getP2MPSegmentComputation.
protected SegmentComputation getP2MPSegmentComputation(final Queue<Object> objects, final List<Message> errors, final Rp rp) {
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.segment.computation.p2mp.Metric> metrics = new ArrayList<>();
final P2mpBuilder builder = new P2mpBuilder();
final List<EndpointRroPair> epRros = new ArrayList<>();
P2MPState state = P2MPState.RP;
while (!objects.isEmpty() && state != P2MPState.END) {
state = insertP2MPObject(state, objects, builder, epRros, metrics, errors, rp);
if (!state.equals(P2MPState.END)) {
objects.remove();
}
}
if (!epRros.isEmpty()) {
builder.setEndpointRroPair(epRros);
}
if (!metrics.isEmpty()) {
builder.setMetric(metrics);
}
if (rp.getReoptimization() && builder.getBandwidth() != null) {
if (!isValidReoptimizationRro(epRros) || !isValidReoptimizationBandwidth(epRros)) {
errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, Optional.of(rp)));
}
}
return new SegmentComputationBuilder().setP2mp(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.SegmentComputation in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method getRequests.
protected List<Requests> getRequests(final Queue<Object> objects, final List<Message> errors) {
final List<Requests> requests = new ArrayList<>();
for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
if (!(obj instanceof Rp)) {
// if RP obj is missing return error only
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.empty()));
return null;
}
final RequestsBuilder rBuilder = new RequestsBuilder();
final Rp rpObj = (Rp) obj;
objects.remove();
if (rpObj.getProcessingRule()) {
rBuilder.setRp(rpObj);
} else {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.empty()));
}
final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
if (!vendorInfo.isEmpty()) {
rBuilder.setVendorInformationObject(vendorInfo);
}
// expansion
if (rpObj.getPathKey()) {
// FIXME: this can fail on malformed messages (i.e. objects.isEmpty()), add an explicit check/error
obj = objects.element();
if (obj instanceof PathKey) {
// FIXME: shouldn't we be also removing the object?
rBuilder.setPathKeyExpansion(new PathKeyExpansionBuilder().setPathKey((PathKey) obj).build());
}
}
obj = objects.peek();
if (!(obj instanceof EndpointsObj)) {
errors.add(createErrorMsg(PCEPErrors.END_POINTS_MISSING, Optional.of(rpObj)));
return null;
}
if (!rpObj.getP2mp()) {
// p2p
// FIXME: explicit check for empty/type?
final EndpointsObj ep = (EndpointsObj) objects.remove();
final P2pBuilder p2pBuilder = new P2pBuilder();
if (!ep.getProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rpObj)));
} else {
p2pBuilder.setEndpointsObj(ep);
}
final SegmentComputation segm = getP2PSegmentComputation(p2pBuilder, objects, errors, rpObj);
if (segm != null) {
rBuilder.setSegmentComputation(segm);
}
} else {
// p2mp
final SegmentComputation segm = getP2MPSegmentComputation(objects, errors, rpObj);
if (segm != null) {
rBuilder.setSegmentComputation(segm);
}
}
requests.add(rBuilder.build());
}
return requests;
}
Aggregations