use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method handleEros.
private Result handleEros(final Queue<Object> objects) {
final SuccessBuilder builder = new SuccessBuilder();
final List<Paths> paths = new ArrayList<>();
for (Object obj = objects.peek(); obj != null && !(obj instanceof PceId); obj = objects.peek()) {
final PathsBuilder pBuilder = new PathsBuilder();
if (obj instanceof Ero) {
pBuilder.setEro((Ero) obj);
objects.remove();
}
final List<VendorInformationObject> vendorInfoObjects = addVendorInformationObjects(objects);
if (!vendorInfoObjects.isEmpty()) {
builder.setVendorInformationObject(vendorInfoObjects);
}
this.parsePath(pBuilder, objects);
paths.add(pBuilder.build());
}
builder.setPaths(paths);
return new SuccessCaseBuilder().setSuccess(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder in project bgpcep by opendaylight.
the class PCEPReplyMessageParser method parsePath.
protected void parsePath(final PathsBuilder builder, final Queue<Object> objects) {
final List<Metrics> pathMetrics = new ArrayList<>();
State state = State.INIT;
for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
state = insertObject(state, obj, builder, pathMetrics);
if (state == State.END) {
break;
}
objects.remove();
}
if (!pathMetrics.isEmpty()) {
builder.setMetrics(pathMetrics);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testReplyMsgWithTwoEros.
@Test
public void testReplyMsgWithTwoEros() throws IOException, PCEPDeserializerException {
// Success Reply with two EROs: the first one is followed by Bandwidth Object and one Metric Object
final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
final PcrepMessageBuilder builder = new PcrepMessageBuilder();
final List<Replies> replies = new ArrayList<>();
final BandwidthBuilder bwBuilder = new BandwidthBuilder();
bwBuilder.setIgnore(false);
bwBuilder.setProcessingRule(false);
bwBuilder.setBandwidth(new Bandwidth(new byte[] { (byte) 0x47, (byte) 0x74, (byte) 0x24, (byte) 0x00 }));
RepliesBuilder repliesBuilder = new RepliesBuilder();
repliesBuilder = new RepliesBuilder();
repliesBuilder.setRp(this.rpTrue);
final List<Paths> paths = new ArrayList<>();
final PathsBuilder paBuilder1 = new PathsBuilder().setEro(this.ero).setBandwidth(bwBuilder.build()).setMetrics(Lists.newArrayList(this.metrics));
paths.add(paBuilder1.build());
final PathsBuilder paBuilder2 = new PathsBuilder();
paBuilder2.setEro(this.ero);
paths.add(paBuilder2.build());
repliesBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
replies.add(repliesBuilder.build());
builder.setReplies(replies);
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.7.bin"));
assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testRepWithMonitoring.
@Test
public void testRepWithMonitoring() throws IOException, PCEPDeserializerException {
final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
final PcrepMessageBuilder builder = new PcrepMessageBuilder();
RepliesBuilder repliesBuilder = new RepliesBuilder();
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRepMon.5.bin"));
final List<Replies> replies4 = new ArrayList<>();
repliesBuilder = new RepliesBuilder().setRp(this.rpTrue).setMonitoring(this.monitoring).setPccIdReq(this.pccIdReq).setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build()));
final List<Paths> paths = new ArrayList<>();
final PathsBuilder paBuilder = new PathsBuilder().setEro(this.ero).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro).setOf(this.of);
paths.add(paBuilder.build());
repliesBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
replies4.add(repliesBuilder.build());
builder.setReplies(replies4);
assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
final ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder 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;
}
Aggregations