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 PCEPObjectParserTest method testBandwidthObject.
@Test
public void testBandwidthObject() throws IOException, PCEPDeserializerException {
final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser();
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin"));
final BandwidthBuilder builder = new BandwidthBuilder();
builder.setProcessingRule(true);
builder.setIgnore(true);
builder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
try {
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
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 computeEro.
@Override
public Ero computeEro(final EndpointsObj endpoints, final Bandwidth bandwidth, final ClassType classType, final List<Metrics> metrics, final boolean segmentRouting) {
VertexKey source = getSourceVertexKey(endpoints);
VertexKey destination = getDestinationVertexKey(endpoints);
if (source == null) {
return null;
}
if (destination == null) {
return null;
}
/* Create new Constraints Object from the request */
PathConstraints cts = getConstraints(endpoints, bandwidth, classType, metrics, segmentRouting);
/* Determine Path Computation Algorithm according to parameters */
AlgorithmType algoType;
if (cts.getTeMetric() == null && cts.getDelay() == null && cts.getBandwidth() == null) {
algoType = AlgorithmType.Spf;
} else if (cts.getDelay() == null) {
algoType = AlgorithmType.Cspf;
} else {
algoType = AlgorithmType.Samcra;
}
PathComputationAlgorithm algo = algoProvider.getPathComputationAlgorithm(tedGraph, algoType);
if (algo == null) {
return null;
}
/*
* Request Path Computation for given source, destination and
* constraints
*/
final ConstrainedPath cpath = algo.computeP2pPath(source, destination, cts);
LOG.info("Computed ERO: {}", cpath.getPathDescription());
/* Check if we got a valid Path and return appropriate ERO */
if (cpath.getStatus() == ComputationStatus.Completed) {
return MessagesUtil.getEro(cpath.getPathDescription());
} else {
return null;
}
}
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 NodeChangedListenerTest method createNode.
private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final Uint32 lspId, final String dstIpv4Address) throws InterruptedException, ExecutionException {
final NodeBuilder nodeBuilder = new NodeBuilder();
nodeBuilder.withKey(new NodeKey(nodeId));
nodeBuilder.setNodeId(nodeId);
final PathBuilder pathBuilder = new PathBuilder();
pathBuilder.withKey(new PathKey(new LspId(lspId)));
pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(new Bandwidth(new byte[] { 0x00, 0x00, (byte) 0xff, (byte) 0xff })).build());
pathBuilder.addAugmentation(new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4AddressNoZone(ipv4Address)).setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4AddressNoZone(dstIpv4Address)).build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
final ReportedLsp reportedLps = new ReportedLspBuilder().withKey(new ReportedLspKey(lspName)).setPath(BindingMap.of(pathBuilder.build())).build();
final Node1Builder node1Builder = new Node1Builder();
node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(BindingMap.of(reportedLps)).setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone(ipv4Address))).build());
nodeBuilder.addAugmentation(node1Builder.build());
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
wTx.commit().get();
}
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 BandwidthObjectParser method localParseObject.
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
final BasicBandwidthObjectBuilder builder = new BasicBandwidthObjectBuilder();
final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
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 BandwidthObjectParser method localSerializeObject.
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
Preconditions.checkArgument(teLspObject instanceof BasicBandwidthObject, "BandwidthObject is mandatory.");
final BasicBandwidthObject bandObject = (BasicBandwidthObject) teLspObject;
serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
final Bandwidth band = bandObject.getBandwidth();
output.writeBytes(Unpooled.wrappedBuffer(band.getValue()));
}
Aggregations