use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder in project bgpcep by opendaylight.
the class PCEPValidatorTest method testCloseMsg.
@Test
public void testCloseMsg() throws IOException, PCEPDeserializerException {
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseMessage1.bin"));
final PCEPCloseMessageParser parser = new PCEPCloseMessageParser(this.objectRegistry);
final CloseBuilder builder = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(new CCloseBuilder().setIgnore(false).setProcessingRule(false).setReason(Uint8.valueOf(5)).setTlvs(new TlvsBuilder().build()).build()).build());
assertEquals(builder.build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.emptyList()));
final ByteBuf buf = Unpooled.buffer(result.readableBytes());
parser.serializeMessage(builder.build(), buf);
assertArrayEquals(result.array(), buf.array());
try {
parser.serializeMessage(new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().build()).build(), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Close Object must be present in Close Message.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testCloseObjectWithVendorInformationTlv.
@Test
public void testCloseObjectWithVendorInformationTlv() throws PCEPDeserializerException {
final byte[] closeBytes = { 0x0f, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x05, /* vendor-information TLV */
0x00, 0x07, 0x00, 0x08, /* enterprise number */
0x00, 0x00, 0x00, 0x00, /* enterprise specific information */
0x00, 0x00, 0x00, 0x05 };
final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(Uint32.ZERO)).setEnterpriseSpecificInformation(esInfo).build();
final CCloseBuilder builder = new CCloseBuilder().setProcessingRule(false).setIgnore(false).setReason(Uint8.valueOf(5)).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.c.close.TlvsBuilder().setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder in project bgpcep by opendaylight.
the class PCEPSessionImpl method close.
/**
* Closes PCEP session, cancels all timers, returns to state Idle, sends the Close Message. KeepAlive and DeadTimer
* are cancelled if the state of the session changes to IDLE. This method is used to close the PCEP session from
* inside the session or from the listener, therefore the parent of this session should be informed.
*/
@Override
public void close(final TerminationReason reason) {
if (this.closed.getAndSet(true)) {
LOG.debug("Session is already closed.");
return;
}
// only send close message when the reason is provided
if (reason != null) {
LOG.info("Closing PCEP session with reason {}: {}", reason, this);
sendMessage(new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getUintValue()).build()).build()).build());
} else {
LOG.info("Closing PCEP session: {}", this);
}
closeChannel();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder in project bgpcep by opendaylight.
the class PCEPCloseObjectParser method parseObject.
@Override
public CClose parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
bytes.skipBytes(FLAGS_F_LENGTH + RESERVED);
final Uint8 reason = ByteBufUtils.readUint8(bytes);
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
return new CCloseBuilder().setIgnore(header.getIgnore()).setProcessingRule(header.getProcessingRule()).setReason(reason).setTlvs(tlvsBuilder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testCloseObject.
@Test
public void testCloseObject() throws IOException, PCEPDeserializerException {
final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin"));
final CCloseBuilder builder = new CCloseBuilder().setProcessingRule(false).setIgnore(false).setReason(Uint8.valueOf(5)).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.c.close.TlvsBuilder().build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), 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. Cannot 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. Cannot be null or empty.", e.getMessage());
}
}
Aggregations