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 PCEPRequestMessageParser method insertObject.
private static State insertObject(final State state, final List<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
final Object obj = objects.get(0);
switch(state) {
case INIT:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
objects.remove(0);
final Object nextObj = objects.get(0);
if (nextObj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
builder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) nextObj);
}
return State.REPORTED_IN;
}
case REPORTED_IN:
if (obj instanceof VendorInformationObject) {
viObjects.add((VendorInformationObject) obj);
return State.REPORTED_IN;
}
case VENDOR_INFO_LIST:
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
return State.LOAD_BIN;
}
case LOAD_BIN:
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
return State.LSPA_IN;
}
case LSPA_IN:
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
return State.BANDWIDTH_IN;
}
case BANDWIDTH_IN:
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
return State.BANDWIDTH_IN;
}
case METRIC_IN:
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
return State.IRO_IN;
}
case IRO_IN:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
return State.RRO_IN;
}
case RRO_IN:
if (obj instanceof Xro) {
builder.setXro((Xro) obj);
return State.XRO_IN;
}
case XRO_IN:
if (obj instanceof Of) {
builder.setOf((Of) obj);
return State.OF_IN;
}
case OF_IN:
if (obj instanceof ClassType) {
final ClassType classType = (ClassType) obj;
if (!classType.isProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
} else {
builder.setClassType(classType);
}
return State.CT_IN;
}
case CT_IN:
case END:
return State.END;
default:
return state;
}
}
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 PCEPBandwidthObjectParser method serializeObject.
@Override
public void serializeObject(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object object, final ByteBuf buffer) {
Preconditions.checkArgument(object instanceof Bandwidth, "Wrong instance of PCEPObject. Passed %s. Needed BandwidthObject.", object.getClass());
final ByteBuf body = Unpooled.buffer();
writeFloat32(((Bandwidth) object).getBandwidth(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
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 PCEPBandwidthObjectParser method parseObject.
@Override
public Bandwidth parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() != BANDWIDTH_F_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: " + BANDWIDTH_F_LENGTH + ".");
}
final BandwidthBuilder builder = new BandwidthBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
builder.setBandwidth(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(ByteArray.getAllBytes(bytes)));
return builder.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 AbstractPathComputation method pruneEdge.
/**
* Check if Edge need to be prune regarding all constraints including
* address family.
*
* @return True if Edge must be prune, False if Edge must be keep
*/
protected boolean pruneEdge(final ConnectedEdge edge, final CspfPath path) {
/* Check that Constraints are initialized */
if (constraints == null) {
LOG.warn("Constraints not set");
return true;
}
/* Edge could point to an unknown Vertex e.g. with inter-domain link */
if (edge.getDestination() == null || edge.getDestination().getVertex() == null) {
LOG.debug("No Destination");
return true;
}
/* Check that Edge have attributes */
EdgeAttributes attributes = edge.getEdge() != null ? edge.getEdge().getEdgeAttributes() : null;
if (attributes == null) {
LOG.debug("No attributes");
return true;
}
/* Check that Edge belongs to the requested address family */
switch(constraints.getAddressFamily()) {
case Ipv4:
if (attributes.getRemoteAddress() == null || attributes.getRemoteAddress().getIpv4Address() == null) {
LOG.debug("No Ipv4 address");
return true;
}
break;
case Ipv6:
if (attributes.getRemoteAddress() == null || attributes.getRemoteAddress().getIpv6Address() == null) {
LOG.debug("No Ipv6 address");
return true;
}
break;
case SrIpv4:
if (getIpv4NodeSid(edge.getDestination()) == null) {
LOG.debug("No Node-SID for IPv4");
return true;
}
if (attributes.getAdjSid() == null) {
LOG.debug("No Adjacency-SID");
return true;
}
break;
case SrIpv6:
if (getIpv6NodeSid(edge.getDestination()) == null) {
LOG.debug("No Node-SID for IPv6");
return true;
}
if (attributes.getAdjSid() == null) {
LOG.debug("No SR Adjacency-SID");
return true;
}
break;
default:
return true;
}
/* Skip checking other Constraints for simple SPF algorithm */
if (this instanceof ShortestPathFirst) {
LOG.trace("Edge {} is valid for Simple Path Computation", edge);
return false;
}
/*
* If specified, check that total TE Metric up to this edge respects the
* initial constraints
*/
if (constraints.getTeMetric() != null) {
if (attributes.getTeMetric() == null) {
return true;
} else {
int totalCost = attributes.getTeMetric().intValue() + path.getCost();
if (totalCost > constraints.getTeMetric().intValue()) {
LOG.debug("TeMetric {} exceed constraint {}", totalCost, constraints.getTeMetric().intValue());
return true;
}
}
}
/*
* If specified, check that total Delay up to this edge respects the
* initial constraints
*/
if (constraints.getDelay() != null) {
if (attributes.getDelay() == null) {
return true;
} else {
int totalDelay = attributes.getDelay().getValue().intValue() + path.getDelay();
if (totalDelay > constraints.getDelay().getValue().intValue()) {
LOG.debug("Delay {} exceed constraint {}", totalDelay, constraints.getDelay().getValue().intValue());
return true;
}
}
}
/* Check that Edge respect Loss constraint */
if (constraints.getLoss() != null) {
if (attributes.getLoss() == null || attributes.getLoss().getValue().intValue() > constraints.getLoss().getValue().intValue()) {
return true;
}
}
/* Check that Edge meet Bandwidth constraint */
int cos = 0;
if (constraints.getClassType() != null) {
cos = constraints.getClassType().intValue();
}
if (constraints.getBandwidth() != null) {
if (attributes.getMaxLinkBandwidth() == null || attributes.getMaxResvLinkBandwidth() == null || attributes.getUnreservedBandwidth() == null || attributes.getUnreservedBandwidth().get(cos) == null) {
return true;
} else {
Long bandwidth = constraints.getBandwidth().getValue().longValue();
Long unrsv = 0L;
for (UnreservedBandwidth unResBw : attributes.getUnreservedBandwidth()) {
if (unResBw.getClassType().intValue() == cos) {
unrsv = unResBw.getBandwidth().getValue().longValue();
break;
}
}
if (unrsv < bandwidth || attributes.getMaxLinkBandwidth().getValue().longValue() < bandwidth || attributes.getMaxResvLinkBandwidth().getValue().longValue() < bandwidth) {
LOG.debug("Bandwidth constraint is not met");
return true;
}
}
}
/* Check that Edge belongs to admin group */
if (constraints.getAdminGroup() != null && !constraints.getAdminGroup().equals(attributes.getAdminGroup())) {
LOG.debug("Not in the requested admin-group");
return true;
}
/*
* OK. All is fine. We can consider this Edge valid, so not to be prune
*/
LOG.trace("Edge {} is valid for Constrained Path Computation", edge);
return false;
}
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 ConstrainedShortestPathFirst method computeP2pPath.
@Override
public ConstrainedPath computeP2pPath(final VertexKey src, final VertexKey dst, final PathConstraints cts) {
LOG.info("Start CSPF Path Computation from {} to {} with constraints {}", src, dst, cts);
/* Initialize algorithm */
this.constraints = cts;
ConstrainedPathBuilder cpathBuilder = initializePathComputation(src, dst);
if (cpathBuilder.getStatus() == ComputationStatus.Failed) {
return cpathBuilder.build();
}
cpathBuilder.setBandwidth(cts.getBandwidth()).setClassType(cts.getClassType());
visitedVertices.clear();
/* Process all Connected Vertex until priority queue becomes empty. Connected Vertices are added into the
* priority queue when processing the next Connected Vertex: see relaxMC() method */
int currentCost = Integer.MAX_VALUE;
while (priorityQueue.size() != 0) {
CspfPath currentPath = priorityQueue.poll();
visitedVertices.put(currentPath.getVertexKey(), currentPath);
LOG.debug("Got path to Vertex {} from Priority Queue", currentPath.getVertex());
List<ConnectedEdge> edges = currentPath.getVertex().getOutputConnectedEdges();
for (ConnectedEdge edge : edges) {
/* Skip Connected Edges that must be prune i.e. Edges that not satisfy the given constraints,
* in particular the Bandwidth, TE Metric and Delay. */
if (pruneEdge(edge, currentPath)) {
LOG.trace(" Prune Edge {}", edge);
continue;
}
if (relaxMultiConstraints(edge, currentPath) && pathDestination.getCost() < currentCost) {
currentCost = pathDestination.getCost();
cpathBuilder.setPathDescription(getPathDescription(pathDestination.getPath())).setMetric(Uint32.valueOf(pathDestination.getCost())).setStatus(ComputationStatus.Active);
LOG.debug(" Found a valid path up to destination {}", cpathBuilder.getPathDescription());
}
}
}
/* The priority queue is empty => all the possible (vertex, path) elements have been explored
* The "ConstrainedPathBuilder" object contains the optimal path if it exists
* Otherwise an empty path with status failed is returned
*/
if (cpathBuilder.getStatus() == ComputationStatus.InProgress || cpathBuilder.getPathDescription().size() == 0) {
cpathBuilder.setStatus(ComputationStatus.Failed);
} else {
cpathBuilder.setStatus(ComputationStatus.Completed);
}
return cpathBuilder.build();
}
Aggregations