use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.Bandwidth 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.bandwidth.object.Bandwidth 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.Bandwidth in project bgpcep by opendaylight.
the class LinkBandwidthEC method parseExtendedCommunity.
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
buffer.skipBytes(AS_TRANS_LENGTH);
final LinkBandwidthExtendedCommunity lb = new LinkBandwidthExtendedCommunityBuilder().setBandwidth(new Bandwidth(ByteArray.readBytes(buffer, BANDWIDTH_SIZE))).build();
return new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(lb).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.Bandwidth in project bgpcep by opendaylight.
the class CommunitiesBuilder method createExtComm.
static List<ExtendedCommunities> createExtComm(final List<String> extCom) {
final List<ExtendedCommunities> extendedCommunities = new ArrayList<>();
for (String ec : extCom) {
ExtendedCommunity community = null;
switch(ec) {
case "as-4-generic-spec-extended-community":
community = CommunitiesBuilder.as4GenSpecBuild();
break;
case "as-4-route-target-extended-community":
community = CommunitiesBuilder.as4RTBuild();
break;
case "as-4-route-origin-extended-community":
community = CommunitiesBuilder.as4ROBuild();
break;
case "route-origin":
community = CommunitiesBuilder.rOBuild();
break;
case "route-target":
community = CommunitiesBuilder.rTBuild();
break;
case "route-origin-extended-community":
community = CommunitiesBuilder.rOECBuild();
break;
case "route-target-extended-community":
community = CommunitiesBuilder.rTECBuild();
break;
case "link-bandwidth-extended-community":
community = CommunitiesBuilder.linkBandBuild();
break;
case "opaque-extended-community":
community = CommunitiesBuilder.opaqueBuild();
break;
case "inet4-specific-extended-community":
community = CommunitiesBuilder.inet4Build();
break;
case "as-specific-extended-community":
community = CommunitiesBuilder.asSpecBuild();
break;
default:
LOG.debug("Not recognized Extended Community {}", ec);
break;
}
extendedCommunities.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(community).build());
}
return extendedCommunities;
}
Aggregations