use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder in project bgpcep by opendaylight.
the class Util method createErrorMessage.
public static Message createErrorMessage(final PCEPErrors e, final Open t) {
final PcerrBuilder errMessageBuilder = new PcerrBuilder();
final ErrorObject err = new ErrorObjectBuilder().setType(e.getErrorType()).setValue(e.getErrorValue()).build();
if (t == null) {
return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject(err).build())).build()).build();
}
final ErrorType type = new SessionCaseBuilder().setSession(new SessionBuilder().setOpen(t).build()).build();
return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.singletonList(new ErrorsBuilder().setErrorObject(err).build())).setErrorType(type).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testErrorMsg.
@Test
public void testErrorMsg() throws IOException, PCEPDeserializerException {
ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.5.bin"));
ErrorObject error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3).setValue((short) 1).build();
final PCEPErrorMessageParser parser = new PCEPErrorMessageParser(this.ctx.getObjectHandlerRegistry());
List<Errors> innerErr = new ArrayList<>();
final PcerrMessageBuilder builder = new PcerrMessageBuilder();
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.Rps> rps = Lists.newArrayList();
rps.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder().setRp(this.rpFalse).build());
innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());
builder.setErrors(innerErr);
builder.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(rps).build()).build());
assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCErr.3.bin"));
error1 = new ErrorObjectBuilder().setIgnore(false).setProcessingRule(false).setType((short) 3).setValue((short) 1).build();
innerErr = new ArrayList<>();
innerErr.add(new ErrorsBuilder().setErrorObject(error1).build());
builder.setErrors(innerErr);
builder.setErrorType(new SessionCaseBuilder().setSession(new SessionBuilder().setOpen(this.open).build()).build());
assertEquals(new PcerrBuilder().setPcerrMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(new PcerrBuilder().setPcerrMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
try {
parser.serializeMessage(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Errors should not be empty.", e.getMessage());
}
try {
parser.serializeMessage(new PcerrBuilder().setPcerrMessage(new PcerrMessageBuilder().setErrors(Collections.emptyList()).build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Errors should not be empty.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder in project bgpcep by opendaylight.
the class PCEPErrorObjectParser method parseObject.
@Override
public ErrorObject 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.");
final ErrorObjectBuilder builder = new ErrorObjectBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
bytes.skipBytes(FLAGS_F_LENGTH + RESERVED);
builder.setType(bytes.readUnsignedByte());
builder.setValue(bytes.readUnsignedByte());
parseTlvs(builder, bytes.slice());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder in project bgpcep by opendaylight.
the class AbstractMessageParserTest method setUp.
@Before
public void setUp() throws PCEPDeserializerException {
MockitoAnnotations.initMocks(this);
this.object = new ErrorObjectBuilder().setType((short) 1).setValue((short) 1).build();
this.viObject = new VendorInformationObjectBuilder().setEnterpriseNumber(EN).build();
Mockito.doNothing().when(this.registry).serializeVendorInformationObject(Mockito.any(VendorInformationObject.class), Mockito.any(ByteBuf.class));
Mockito.doReturn(Optional.of(this.viObject)).when(this.registry).parseVendorInformationObject(Mockito.eq(EN), Mockito.eq(new ObjectHeaderImpl(true, true)), Mockito.any(ByteBuf.class));
Mockito.doNothing().when(this.registry).serializeObject(Mockito.any(Object.class), Mockito.any(ByteBuf.class));
Mockito.doReturn(this.object).when(this.registry).parseObject(13, 1, new ObjectHeaderImpl(true, true), Unpooled.wrappedBuffer(new byte[] { 0, 0, 1, 1 }));
}
Aggregations