use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bnc.object.branch.node.type.BranchNodeCaseBuilder in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method insertP2MPObject.
private static P2MPState insertP2MPObject(final P2MPState p2MPState, final Queue<Object> objects, final P2mpBuilder builder, final List<EndpointRroPair> epRros, final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.requests.segment.computation.p2mp.Metric> metrics, final List<Message> errors, final Rp rp) {
final Object obj = objects.element();
switch(p2MPState) {
case RP:
if (obj instanceof EndpointsObj) {
final EndpointRroPairBuilder rroPairBuilder = new EndpointRroPairBuilder();
if (obj.getProcessingRule()) {
rroPairBuilder.setEndpointsObj((EndpointsObj) obj);
} else {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
}
epRros.add(rroPairBuilder.setRros(new ArrayList<>()).build());
return P2MPState.ENDPOINT;
}
// fallthrough
case ENDPOINT:
if (obj instanceof Rro || obj instanceof Srro) {
if (obj.getProcessingRule()) {
final int lastIndex = epRros.size() - 1;
final EndpointRroPair endpointRroPair = epRros.get(lastIndex);
List<Rros> rros = endpointRroPair.getRros();
if (rros == null) {
rros = new ArrayList<>();
}
if (obj instanceof Rro) {
rros.add(new RrosBuilder().setRouteObject(new ReportedRouteObjectCaseBuilder().setRro((Rro) obj).build()).build());
} else {
rros.add(new RrosBuilder().setRouteObject(new SecondaryReportedRouteObjectCaseBuilder().setSrro((Srro) obj).build()).build());
}
epRros.remove(lastIndex);
epRros.add(lastIndex, new EndpointRroPairBuilder(endpointRroPair).setRros(rros).build());
}
return P2MPState.ENDPOINT;
}
// fallthrough
case RRO_SRRO:
if (obj instanceof ReoptimizationBandwidth) {
final int lastIndex = epRros.size() - 1;
final EndpointRroPair endpointRroPair = epRros.get(lastIndex);
epRros.remove(lastIndex);
epRros.add(lastIndex, new EndpointRroPairBuilder(endpointRroPair).setReoptimizationBandwidth((ReoptimizationBandwidth) obj).build());
return P2MPState.BANDWIDTH;
}
// fallthrough
case BANDWIDTH:
if (obj instanceof EndpointsObj) {
return P2MPState.RP;
}
if (obj instanceof Of) {
builder.setOf((Of) obj);
return P2MPState.OF_IN;
}
// fallthrough
case OF_IN:
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
return P2MPState.LSPA_IN;
}
// fallthrough
case LSPA_IN:
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
return P2MPState.BANDWIDTH_IN;
}
// fallthrough
case BANDWIDTH_IN:
if (obj instanceof Metric) {
metrics.add(new MetricBuilder().setMetric((Metric) obj).build());
return P2MPState.BANDWIDTH_IN;
}
// fallthrough
case METRIC_IN:
if (obj instanceof Iro) {
builder.setIroBncChoice(new IroCaseBuilder().setIro((Iro) obj).build());
return P2MPState.IRO_BNC_IN;
}
if (obj instanceof BranchNodeList) {
builder.setIroBncChoice(new BncCaseBuilder().setBranchNodeType(new BranchNodeCaseBuilder().setBranchNodeList((BranchNodeList) obj).build()).build());
return P2MPState.IRO_BNC_IN;
}
if (obj instanceof NonBranchNodeList) {
builder.setIroBncChoice(new BncCaseBuilder().setBranchNodeType(new NonBranchNodeCaseBuilder().setNonBranchNodeList((NonBranchNodeList) obj).build()).build());
return P2MPState.IRO_BNC_IN;
}
// fallthrough
case IRO_BNC_IN:
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
return P2MPState.LOAD_BIN;
}
// fallthrough
case LOAD_BIN:
case END:
default:
return P2MPState.END;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bnc.object.branch.node.type.BranchNodeCaseBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testRequestMsg.
@Test
public void testRequestMsg() throws IOException, PCEPDeserializerException {
final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry);
final PcreqMessageBuilder builder = new PcreqMessageBuilder();
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Requests> reqs1 = new ArrayList<>();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder();
rBuilder.setRp(this.rpTrue);
rBuilder.setSegmentComputation(new SegmentComputationBuilder().setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).build()).build());
reqs1.add(rBuilder.build());
builder.setRequests(reqs1);
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPRequestMessage1.bin"));
assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCReq.3.bin"));
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Requests> reqs2 = new ArrayList<>();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder();
rBuilder1.setRp(this.rpTrue);
final P2pBuilder p2pBuilder = new P2pBuilder().setEndpointsObj(this.endpoints).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro);
rBuilder1.setSegmentComputation(new SegmentComputationBuilder().setP2p(p2pBuilder.build()).build());
reqs2.add(rBuilder1.build());
builder.setRequests(reqs2).setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.SvecBuilder().setSvec(this.svec).build()));
assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCReq.9.bin"));
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.Requests> reqs3 = new ArrayList<>();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder rBuilder2 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcreq.message.pcreq.message.RequestsBuilder();
rBuilder2.setRp(new RpBuilder(this.rpTrue).setP2mp(true).build());
final EndpointsObjBuilder epBuilder = new EndpointsObjBuilder().setIgnore(false).setProcessingRule(true).setAddressFamily(new P2mpIpv4CaseBuilder().setP2mpIpv4(new P2mpIpv4Builder().setP2mpLeaves(P2mpLeaves.NewLeavesToAdd).setSourceIpv4Address(new Ipv4AddressNoZone("255.255.255.255")).setDestinationIpv4Address(Arrays.asList(new Ipv4AddressNoZone("255.255.255.254"), new Ipv4AddressNoZone("255.255.255.253"))).build()).build());
final P2mpBuilder p2mpBuilder = new P2mpBuilder();
p2mpBuilder.setEndpointRroPair(Collections.singletonList(new EndpointRroPairBuilder().setEndpointsObj(epBuilder.build()).setRros(Arrays.asList(new RrosBuilder().setRouteObject(new ReportedRouteObjectCaseBuilder().setRro(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.RroBuilder().setIgnore(false).setProcessingRule(true).setSubobject(Arrays.asList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder().setProtectionAvailable(false).setProtectionInUse(false).setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.252/32"))).build()).build()).build())).build()).build()).build(), new RrosBuilder().setRouteObject(new SecondaryReportedRouteObjectCaseBuilder().setSrro(new SrroBuilder().setIgnore(false).setProcessingRule(true).setSubobject(Arrays.asList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.secondary.reported.route.object.srro.SubobjectBuilder().setProtectionInUse(false).setProtectionAvailable(false).setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.251/32"))).build()).build()).build())).build()).build()).build())).build()));
p2mpBuilder.setIroBncChoice(new BncCaseBuilder().setBranchNodeType(new BranchNodeCaseBuilder().setBranchNodeList(new BranchNodeListBuilder().setIgnore(false).setProcessingRule(true).setSubobject(Arrays.asList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bnc.SubobjectBuilder().setLoose(false).setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.252/32"))).build())).build()).build()).build());
rBuilder2.setSegmentComputation(new SegmentComputationBuilder().setP2mp(p2mpBuilder.build()).build());
reqs3.add(rBuilder2.build());
builder.setRequests(reqs3).setSvec(null);
assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
try {
parser.serializeMessage(new PcreqBuilder().setPcreqMessage(new PcreqMessageBuilder().build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Requests cannot be null or empty.", e.getMessage());
}
try {
parser.serializeMessage(new PcreqBuilder().setPcreqMessage(new PcreqMessageBuilder().setRequests(Collections.emptyList()).build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Requests cannot be null or empty.", e.getMessage());
}
}
Aggregations