use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.get.constrained.path.input.ConstraintsBuilder 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