use of com.google.storage.v2.Object 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;
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method insertP2MPObject.
private static P2MPState insertP2MPObject(final P2MPState p2MPState, final Queue<Object> objects, final P2mpBuilder builder, final List<EndpointRroPair> epRros, 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, final List<Message> errors, final Rp rp) {
final Object obj = objects.element();
switch(p2MPState) {
case RP:
if (obj instanceof EndpointsObj) {
final EndpointRroPairBuilder rroPairBuilder = new EndpointRroPairBuilder();
if (obj.getProcessingRule()) {
rroPairBuilder.setEndpointsObj((EndpointsObj) obj);
} else {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
}
epRros.add(rroPairBuilder.setRros(new ArrayList<>()).build());
return P2MPState.ENDPOINT;
}
// fallthrough
case ENDPOINT:
if (obj instanceof Rro || obj instanceof Srro) {
if (obj.getProcessingRule()) {
final int lastIndex = epRros.size() - 1;
final EndpointRroPair endpointRroPair = epRros.get(lastIndex);
List<Rros> rros = endpointRroPair.getRros();
if (rros == null) {
rros = new ArrayList<>();
}
if (obj instanceof Rro) {
rros.add(new RrosBuilder().setRouteObject(new ReportedRouteObjectCaseBuilder().setRro((Rro) obj).build()).build());
} else {
rros.add(new RrosBuilder().setRouteObject(new SecondaryReportedRouteObjectCaseBuilder().setSrro((Srro) obj).build()).build());
}
epRros.remove(lastIndex);
epRros.add(lastIndex, new EndpointRroPairBuilder(endpointRroPair).setRros(rros).build());
}
return P2MPState.ENDPOINT;
}
// fallthrough
case RRO_SRRO:
if (obj instanceof ReoptimizationBandwidth) {
final int lastIndex = epRros.size() - 1;
final EndpointRroPair endpointRroPair = epRros.get(lastIndex);
epRros.remove(lastIndex);
epRros.add(lastIndex, new EndpointRroPairBuilder(endpointRroPair).setReoptimizationBandwidth((ReoptimizationBandwidth) obj).build());
return P2MPState.BANDWIDTH;
}
// fallthrough
case BANDWIDTH:
if (obj instanceof EndpointsObj) {
return P2MPState.RP;
}
if (obj instanceof Of) {
builder.setOf((Of) obj);
return P2MPState.OF_IN;
}
// fallthrough
case OF_IN:
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
return P2MPState.LSPA_IN;
}
// fallthrough
case LSPA_IN:
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
return P2MPState.BANDWIDTH_IN;
}
// fallthrough
case BANDWIDTH_IN:
if (obj instanceof Metric) {
metrics.add(new MetricBuilder().setMetric((Metric) obj).build());
return P2MPState.BANDWIDTH_IN;
}
// fallthrough
case METRIC_IN:
if (obj instanceof Iro) {
builder.setIroBncChoice(new IroCaseBuilder().setIro((Iro) obj).build());
return P2MPState.IRO_BNC_IN;
}
if (obj instanceof BranchNodeList) {
builder.setIroBncChoice(new BncCaseBuilder().setBranchNodeType(new BranchNodeCaseBuilder().setBranchNodeList((BranchNodeList) obj).build()).build());
return P2MPState.IRO_BNC_IN;
}
if (obj instanceof NonBranchNodeList) {
builder.setIroBncChoice(new BncCaseBuilder().setBranchNodeType(new NonBranchNodeCaseBuilder().setNonBranchNodeList((NonBranchNodeList) obj).build()).build());
return P2MPState.IRO_BNC_IN;
}
// fallthrough
case IRO_BNC_IN:
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
return P2MPState.LOAD_BIN;
}
// fallthrough
case LOAD_BIN:
case END:
default:
return P2MPState.END;
}
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method getValidSvec.
// Note: objects is expected to be non-empty
private static Svec getValidSvec(final SvecBuilder builder, final Queue<Object> objects) {
final Object svec = objects.element();
if (svec instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.svec.object.Svec) {
builder.setSvec((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.svec.object.Svec) svec);
objects.remove();
} else {
return null;
}
// FIXME: this list is not retained anywhere
final List<Metrics> metrics = new ArrayList<>();
final List<VendorInformationObject> viObjects = new ArrayList<>();
SvecState state = SvecState.INIT;
for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
state = insertP2PObject(state, obj, builder, metrics, viObjects);
if (state == SvecState.END) {
break;
}
objects.remove();
}
if (!viObjects.isEmpty()) {
builder.setVendorInformationObject(viObjects);
}
return builder.build();
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class PcRptMessageCodecTest method testGetValidReportsPositive.
@Test
public void testGetValidReportsPositive() {
final PcRptMessageCodec codec = new PcRptMessageCodec(this.ctx.getObjectHandlerRegistry());
final BandwidthUsage bw = new BandwidthUsageBuilder().setBwSample(BW).build();
final Ipv4Builder builder = new Ipv4Builder();
builder.setIpv4TunnelSenderAddress(new Ipv4AddressNoZone("127.0.1.1"));
builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(new Ipv4AddressNoZone("127.0.1.2")));
builder.setIpv4TunnelEndpointAddress(new Ipv4AddressNoZone("127.0.1.3"));
final AddressFamily afiLsp = new Ipv4CaseBuilder().setIpv4(builder.build()).build();
final LspId lspId = new LspId(Uint32.ONE);
final TunnelId tunnelId = new TunnelId(Uint16.ONE);
final LspIdentifiers identifier = new LspIdentifiersBuilder().setAddressFamily(afiLsp).setLspId(lspId).setTunnelId(tunnelId).build();
final Lsp lsp = new LspBuilder().setPlspId(new PlspId(Uint32.ONE)).setTlvs(new TlvsBuilder().setLspIdentifiers(identifier).build()).build();
final Ero ero = new EroBuilder().build();
final Queue<Object> objects = new ArrayDeque<>(List.of(lsp, ero, bw));
final Reports validReports = codec.getValidReports(objects, List.of());
assertNotNull(validReports.getPath().getBandwidth().augmentation(Bandwidth1.class));
assertTrue(objects.isEmpty());
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class PcRptMessageCodecTest method testGetValidReportsNegative.
@Test
public void testGetValidReportsNegative() {
final PcRptMessageCodec codec = new PcRptMessageCodec(this.ctx.getObjectHandlerRegistry());
final BandwidthUsage bw = new BandwidthUsageBuilder().setBwSample(BW).build();
final Ipv4Builder builder = new Ipv4Builder();
builder.setIpv4TunnelSenderAddress(new Ipv4AddressNoZone("127.0.1.1"));
builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(new Ipv4AddressNoZone("127.0.1.2")));
builder.setIpv4TunnelEndpointAddress(new Ipv4AddressNoZone("127.0.1.3"));
final Lsp lsp = new LspBuilder().setPlspId(new PlspId(Uint32.ONE)).build();
final Ero ero = new EroBuilder().build();
final Queue<Object> objects = new ArrayDeque<>(List.of(lsp, ero, bw));
final Reports validReports = codec.getValidReports(objects, new ArrayList<>());
assertNull(validReports);
}
Aggregations