use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp in project bgpcep by opendaylight.
the class StatefulErrorMessageParser method validate.
@Override
protected PcerrMessage validate(final Queue<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
checkArgument(objects != null, "Passed list can't be null.");
final Object first = objects.peek();
if (first == null) {
throw new PCEPDeserializerException("Error message is empty.");
}
final List<Rps> requestParameters = new ArrayList<>();
final List<Srps> srps = new ArrayList<>();
final List<Errors> errorObjects = new ArrayList<>();
final PcerrMessageBuilder b = new PcerrMessageBuilder();
State state = State.INIT;
if (first instanceof ErrorObject) {
errorObjects.add(new ErrorsBuilder().setErrorObject((ErrorObject) first).build());
state = State.ERROR_IN;
} else if (first instanceof Rp) {
final Rp rp = (Rp) first;
if (rp.getProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.empty()));
return null;
}
requestParameters.add(new RpsBuilder().setRp(rp).build());
state = State.RP_IN;
} else if (first instanceof Srp) {
srps.add(new SrpsBuilder().setSrp((Srp) first).build());
state = State.SRP_IN;
}
if (state != State.INIT) {
objects.remove();
}
for (Object obj = objects.peek(); obj != null; obj = objects.peek()) {
if (obj instanceof UnknownObject) {
return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build();
}
state = insertObject(state, obj, errorObjects, requestParameters, srps, b);
if (state == State.END) {
break;
}
objects.remove();
}
if (errorObjects.isEmpty()) {
throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
}
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
if (!requestParameters.isEmpty()) {
b.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(requestParameters).build()).build());
}
if (!srps.isEmpty()) {
b.setErrorType(new StatefulCaseBuilder().setStateful(new StatefulBuilder().setSrps(srps).build()).build());
}
return new PcerrBuilder().setPcerrMessage(b.setErrors(errorObjects).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp in project bgpcep by opendaylight.
the class StatefulPCRequestMessageParser method insertP2PObject.
// Note: objects is expected to be non-empty and caller will remove the first object if non-empty
@SuppressWarnings("fallthrough")
private static P2PState insertP2PObject(final P2PState p2PState, final Queue<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
final Object obj = objects.element();
switch(p2PState) {
case INIT:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
objects.remove();
// FIXME: should we guard against empty objects?
final Object nextObj = objects.element();
if (nextObj instanceof ReoptimizationBandwidth) {
builder.setReoptimizationBandwidth((ReoptimizationBandwidth) nextObj);
}
return P2PState.REPORTED_IN;
}
// fallthrough
case REPORTED_IN:
if (obj instanceof VendorInformationObject) {
viObjects.add((VendorInformationObject) obj);
return P2PState.REPORTED_IN;
}
// fallthrough
case VENDOR_INFO_LIST:
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
return P2PState.LOAD_BIN;
}
// fallthrough
case LOAD_BIN:
if (obj instanceof Lsp) {
builder.addAugmentation(new P2p1Builder().setLsp((Lsp) obj).build());
return P2PState.LSP_IN;
}
// fallthrough
case LSP_IN:
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
return P2PState.LSPA_IN;
}
// fallthrough
case LSPA_IN:
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
return P2PState.BANDWIDTH_IN;
}
// fallthrough
case BANDWIDTH_IN:
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
return P2PState.BANDWIDTH_IN;
}
// fallthrough
case METRIC_IN:
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
return P2PState.IRO_IN;
}
// fallthrough
case IRO_IN:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
return P2PState.RRO_IN;
}
// fallthrough
case RRO_IN:
if (obj instanceof Xro) {
builder.setXro((Xro) obj);
return P2PState.XRO_IN;
}
// fallthrough
case XRO_IN:
if (obj instanceof Of) {
builder.setOf((Of) obj);
return P2PState.OF_IN;
}
// fallthrough
case OF_IN:
if (obj instanceof ClassType) {
final ClassType classType = (ClassType) obj;
if (!classType.getProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
} else {
builder.setClassType(classType);
}
return P2PState.CT_IN;
}
// fallthrough
case CT_IN:
case END:
return P2PState.END;
default:
return p2PState;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp in project bgpcep by opendaylight.
the class PCEPValidatorTest method testReplyMsg.
@Test
public void testReplyMsg() throws IOException, PCEPDeserializerException {
// only RP
final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry);
final PcrepMessageBuilder builder = new PcrepMessageBuilder();
RepliesBuilder repliesBuilder = new RepliesBuilder();
final List<Replies> replies1 = new ArrayList<>();
repliesBuilder.setRp(this.rpTrue);
replies1.add(repliesBuilder.build());
builder.setReplies(replies1);
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.1.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());
// simple Failure
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.2.bin"));
final List<Replies> replies2 = new ArrayList<>();
repliesBuilder = new RepliesBuilder();
repliesBuilder.setRp(this.rpTrue);
replies2.add(repliesBuilder.build());
final RepliesBuilder repliesBuilder2 = new RepliesBuilder();
repliesBuilder2.setRp(this.rpTrue);
repliesBuilder2.setResult(new FailureCaseBuilder().setNoPath(this.noPath).build());
replies2.add(repliesBuilder2.build());
builder.setReplies(replies2);
assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
// Failure with attributes
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.3.bin"));
final List<Replies> replies3 = new ArrayList<>();
repliesBuilder = new RepliesBuilder();
repliesBuilder.setRp(this.rpTrue);
repliesBuilder.setResult(new FailureCaseBuilder().setNoPath(this.noPath).setLspa(this.lspa).setMetrics(Lists.newArrayList(this.metrics)).setIro(this.iro).build());
replies3.add(repliesBuilder.build());
builder.setReplies(replies3);
assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
// Success
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRep.5.bin"));
final List<Replies> replies4 = new ArrayList<>();
repliesBuilder = new RepliesBuilder();
repliesBuilder.setRp(this.rpTrue);
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()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
try {
parser.serializeMessage(new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Replies cannot be null or empty.", e.getMessage());
}
try {
parser.serializeMessage(new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().setReplies(Collections.emptyList()).build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Replies cannot be null or empty.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp in project bgpcep by opendaylight.
the class MessagesUtil method createPcRepMessage.
public static Pcrep createPcRepMessage(final Rp rp, final P2p p2p, final ConstrainedPath cpath) {
/* Prepare Path Object with ERO and Object from the Request */
final ArrayList<Paths> paths = new ArrayList<>();
PathsBuilder pathBuilder = buildPath(cpath);
if (p2p.getLspa() != null) {
pathBuilder.setLspa(p2p.getLspa());
}
if (p2p.getIro() != null) {
pathBuilder.setIro(p2p.getIro());
}
if (p2p.getXro() != null) {
pathBuilder.setXro(p2p.getXro());
}
paths.add(pathBuilder.build());
/* Prepare Reply with Path Object */
final RepliesBuilder replyBuilder = new RepliesBuilder().setRp(rp).setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build());
/* Prepare PcRep Message */
final PcrepMessageBuilder msgBuilder = new PcrepMessageBuilder().setReplies(Lists.newArrayList(replyBuilder.build()));
return new PcrepBuilder().setPcrepMessage(msgBuilder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp in project bgpcep by opendaylight.
the class MessagesUtil method createNoPathMessage.
public static Pcrep createNoPathMessage(final Rp rp, final byte reason) {
/* Prepare NoPath Object */
final Flags flags = new Flags(false, false, false, false, false, false, reason == UNKNOWN_DESTINATION, reason == UNKNOWN_SOURCE);
final NoPathVectorBuilder npvBuilder = new NoPathVectorBuilder().setFlags(flags);
final TlvsBuilder tlvsBuilder = new TlvsBuilder().setNoPathVector(npvBuilder.build());
final NoPathBuilder npBuilder = new NoPathBuilder().setProcessingRule(false).setIgnore(false).setNatureOfIssue(Uint8.ZERO).setUnsatisfiedConstraints(true).setTlvs(tlvsBuilder.build());
/* Prepare Reply */
final RepliesBuilder replyBuilder = new RepliesBuilder().setRp(rp).setResult(new FailureCaseBuilder().setNoPath(npBuilder.build()).build());
/* Prepare PcRep Message */
final PcrepMessageBuilder msgBuilder = new PcrepMessageBuilder().setReplies(Lists.newArrayList(replyBuilder.build()));
return new PcrepBuilder().setPcrepMessage(msgBuilder.build()).build();
}
Aggregations