use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method insertP2PObject.
// Note: objects is expected to be non-empty and caller will remove the first object if non-empty
private static P2PState insertP2PObject(final P2PState p2PState, final Queue<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
final Object obj = objects.element();
switch(p2PState) {
case INIT:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
objects.remove();
// FIXME: should we guard against empty objects?
final Object nextObj = objects.element();
if (nextObj instanceof ReoptimizationBandwidth) {
builder.setReoptimizationBandwidth((ReoptimizationBandwidth) nextObj);
}
return P2PState.REPORTED_IN;
}
// fallthrough
case REPORTED_IN:
if (obj instanceof VendorInformationObject) {
viObjects.add((VendorInformationObject) obj);
return P2PState.REPORTED_IN;
}
// fallthrough
case VENDOR_INFO_LIST:
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
return P2PState.LOAD_BIN;
}
// fallthrough
case LOAD_BIN:
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
return P2PState.LSPA_IN;
}
// fallthrough
case LSPA_IN:
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
return P2PState.BANDWIDTH_IN;
}
// fallthrough
case BANDWIDTH_IN:
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
return P2PState.BANDWIDTH_IN;
}
// fallthrough
case METRIC_IN:
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
return P2PState.IRO_IN;
}
// fallthrough
case IRO_IN:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
return P2PState.RRO_IN;
}
// fallthrough
case RRO_IN:
if (obj instanceof Xro) {
builder.setXro((Xro) obj);
return P2PState.XRO_IN;
}
// fallthrough
case XRO_IN:
if (obj instanceof Of) {
builder.setOf((Of) obj);
return P2PState.OF_IN;
}
// fallthrough
case OF_IN:
if (obj instanceof ClassType) {
final ClassType classType = (ClassType) obj;
if (!classType.getProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
} else {
builder.setClassType(classType);
}
return P2PState.CT_IN;
}
// fallthrough
case CT_IN:
case END:
return P2PState.END;
default:
return p2PState;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType in project bgpcep by opendaylight.
the class PCEPClassTypeObjectParser method serializeObject.
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
checkArgument(object instanceof ClassType, "Wrong instance of PCEPObject. Passed %s. Needed ClassTypeObject.", object.getClass());
final ByteBuf body = Unpooled.buffer(SIZE);
body.writeZero(SIZE - 1);
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType classType = ((ClassType) object).getClassType();
checkArgument(classType != null, "ClassType is mandatory.");
ByteBufUtils.write(body, classType.getValue());
ObjectUtil.formatSubobject(TYPE, CLASS, object.getProcessingRule(), object.getIgnore(), body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType in project bgpcep by opendaylight.
the class MessagesUtil method buildPath.
private static PathsBuilder buildPath(final ConstrainedPath cpath) {
final PathsBuilder pathBuilder = new PathsBuilder();
/* Get ERO from Path Description */
pathBuilder.setEro(getEro(cpath.getPathDescription()));
/* Fulfill Computed Metrics if available */
final ArrayList<Metrics> metrics = new ArrayList<>();
if (cpath.getMetric() != null) {
final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true).setMetricType(Uint8.valueOf(IGP_METRIC)).setValue(new Float32(ByteBuffer.allocate(4).putFloat(cpath.getMetric().floatValue()).array()));
metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
}
if (cpath.getTeMetric() != null) {
final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true).setMetricType(Uint8.valueOf(TE_METRIC)).setValue(new Float32(ByteBuffer.allocate(4).putFloat(cpath.getTeMetric().floatValue()).array()));
metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
}
if (cpath.getDelay() != null) {
final MetricBuilder metricBuilder = new MetricBuilder().setComputed(true).setMetricType(Uint8.valueOf(PATH_DELAY)).setValue(new Float32(ByteBuffer.allocate(4).putFloat(cpath.getDelay().getValue().floatValue()).array()));
metrics.add(new MetricsBuilder().setMetric(metricBuilder.build()).build());
}
if (!metrics.isEmpty()) {
pathBuilder.setMetrics(metrics);
}
/* Fulfill Bandwidth and ClassType if set */
if (cpath.getBandwidth() != null) {
final BandwidthBuilder bwBuilder = new BandwidthBuilder();
bwBuilder.setBandwidth(new Bandwidth(new Float32(ByteBuffer.allocate(4).putFloat(cpath.getBandwidth().getValue().floatValue()).array())));
pathBuilder.setBandwidth(bwBuilder.build());
}
if (cpath.getClassType() != null && !cpath.getClassType().equals(Uint8.ZERO)) {
pathBuilder.setClassType(new ClassTypeBuilder().setClassType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType(cpath.getClassType())).build());
}
return pathBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType in project bgpcep by opendaylight.
the class PathComputationImpl method getConstraints.
private static PathConstraints getConstraints(final EndpointsObj endpoints, final Bandwidth bandwidth, final ClassType classType, final List<Metrics> metrics, final boolean segmentRouting) {
ConstraintsBuilder ctsBuilder = new ConstraintsBuilder();
Float convert;
/* Set Metrics if any */
if (metrics != null) {
for (Metrics metric : metrics) {
convert = ByteBuffer.wrap(metric.getMetric().getValue().getValue()).getFloat();
final long value = convert.longValue();
/* Skip Metric with value equal to 0 */
if (value == 0) {
continue;
}
switch(metric.getMetric().getMetricType().intValue()) {
case MessagesUtil.IGP_METRIC:
ctsBuilder.setMetric(Uint32.valueOf(value));
break;
case MessagesUtil.TE_METRIC:
ctsBuilder.setTeMetric(Uint32.valueOf(value));
break;
case MessagesUtil.PATH_DELAY:
ctsBuilder.setDelay(new Delay(Uint32.valueOf(value)));
break;
default:
LOG.warn("Metric {} is not handle by Path Computation Constraints", metric);
break;
}
}
}
/* Set Bandwidth and Class Type */
if (bandwidth != null) {
convert = ByteBuffer.wrap(bandwidth.getBandwidth().getValue()).getFloat();
final long value = convert.longValue();
/* Skip Bandwidth with value equal to 0 */
if (value != 0) {
ctsBuilder.setBandwidth(new DecimalBandwidth(BigDecimal.valueOf(value)));
if (classType != null) {
ctsBuilder.setClassType(classType.getClassType().getValue());
}
}
}
/* Set Address Family */
if (endpoints.getAddressFamily() instanceof Ipv4Case) {
ctsBuilder.setAddressFamily(segmentRouting ? AddressFamily.SrIpv4 : AddressFamily.Ipv4);
} else {
ctsBuilder.setAddressFamily(segmentRouting ? AddressFamily.SrIpv6 : AddressFamily.Ipv6);
}
return ctsBuilder.build();
}
Aggregations