use of org.eclipse.milo.opcua.stack.core.channel.ChunkEncoder in project milo by eclipse.
the class ChunkSerializationTest method testSymmetric4096.
@Test
public void testSymmetric4096() throws Exception {
ChannelParameters parameters = defaultParameters;
ChunkEncoder encoder = new ChunkEncoder(parameters);
ChunkDecoder decoder = new ChunkDecoder(parameters, EncodingLimits.DEFAULT);
SecureChannel[] channels = generateChannels4096();
ClientSecureChannel clientChannel = (ClientSecureChannel) channels[0];
ServerSecureChannel serverChannel = (ServerSecureChannel) channels[1];
clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).setIfAbsent(new LongSequence(1L, UInteger.MAX_VALUE));
LongSequence requestId = clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).get();
for (int messageSize = 0; messageSize < 1024; messageSize++) {
byte[] messageBytes = new byte[messageSize];
for (int i = 0; i < messageBytes.length; i++) {
messageBytes[i] = (byte) i;
}
ByteBuf messageBuffer = BufferUtil.pooledBuffer().writeBytes(messageBytes);
List<ByteBuf> chunkBuffers = new ArrayList<>();
try {
ChunkEncoder.EncodedMessage message = encoder.encodeSymmetric(clientChannel, requestId.getAndIncrement(), messageBuffer, MessageType.OpenSecureChannel);
chunkBuffers.addAll(message.getMessageChunks());
} catch (MessageEncodeException e) {
fail("encoding error", e);
}
try {
ChunkDecoder.DecodedMessage decodedMessage = decoder.decodeSymmetric(serverChannel, chunkBuffers);
ByteBuf message = decodedMessage.getMessage();
messageBuffer.readerIndex(0);
assertEquals(message, messageBuffer);
ReferenceCountUtil.release(message);
ReferenceCountUtil.release(messageBuffer);
} catch (Throwable t) {
fail("decoding error", t);
}
}
}
use of org.eclipse.milo.opcua.stack.core.channel.ChunkEncoder in project milo by eclipse.
the class ChunkSerializationTest method testAsymmetric4096.
@Test
public void testAsymmetric4096() throws Exception {
ChannelParameters parameters = defaultParameters;
ChunkEncoder encoder = new ChunkEncoder(parameters);
ChunkDecoder decoder = new ChunkDecoder(parameters, EncodingLimits.DEFAULT);
SecureChannel[] channels = generateChannels4096();
ClientSecureChannel clientChannel = (ClientSecureChannel) channels[0];
ServerSecureChannel serverChannel = (ServerSecureChannel) channels[1];
clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).setIfAbsent(new LongSequence(1L, UInteger.MAX_VALUE));
LongSequence requestId = clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).get();
for (int messageSize = 0; messageSize < 512; messageSize++) {
byte[] messageBytes = new byte[messageSize];
for (int i = 0; i < messageBytes.length; i++) {
messageBytes[i] = (byte) i;
}
ByteBuf messageBuffer = BufferUtil.pooledBuffer().writeBytes(messageBytes);
List<ByteBuf> chunkBuffers = new ArrayList<>();
try {
ChunkEncoder.EncodedMessage message = encoder.encodeAsymmetric(clientChannel, requestId.getAndIncrement(), messageBuffer, MessageType.OpenSecureChannel);
chunkBuffers.addAll(message.getMessageChunks());
} catch (MessageEncodeException e) {
fail("encoding error", e);
}
try {
ChunkDecoder.DecodedMessage decodedMessage = decoder.decodeAsymmetric(serverChannel, chunkBuffers);
ByteBuf message = decodedMessage.getMessage();
messageBuffer.readerIndex(0);
assertEquals(message, messageBuffer);
ReferenceCountUtil.release(message);
ReferenceCountUtil.release(messageBuffer);
} catch (Throwable t) {
fail("decoding error", t);
}
}
}
use of org.eclipse.milo.opcua.stack.core.channel.ChunkEncoder in project milo by eclipse.
the class ChunkSerializationTest method testSymmetricMessage.
@Test(dataProvider = "getSymmetricSecurityParameters")
public void testSymmetricMessage(SecurityPolicy securityPolicy, MessageSecurityMode messageSecurity) throws Exception {
logger.info("Symmetric chunk serialization, " + "securityPolicy={}, messageSecurityMode={}", securityPolicy, messageSecurity);
ChannelParameters[] channelParameters = { smallParameters, defaultParameters, unlimitedChunkCountParameters, unlimitedMessageSizeParameters };
for (ChannelParameters parameters : channelParameters) {
int[] messageSizes = new int[] { 128, parameters.getRemoteMaxMessageSize() };
for (int messageSize : messageSizes) {
ChunkEncoder encoder = new ChunkEncoder(parameters);
ChunkDecoder decoder = new ChunkDecoder(parameters, EncodingLimits.DEFAULT);
SecureChannel[] channels = generateChannels(securityPolicy, messageSecurity);
ClientSecureChannel clientChannel = (ClientSecureChannel) channels[0];
ServerSecureChannel serverChannel = (ServerSecureChannel) channels[1];
clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).setIfAbsent(new LongSequence(1L, UInteger.MAX_VALUE));
LongSequence requestId = clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).get();
byte[] messageBytes = new byte[messageSize];
for (int i = 0; i < messageBytes.length; i++) {
messageBytes[i] = (byte) i;
}
ByteBuf messageBuffer = BufferUtil.pooledBuffer().writeBytes(messageBytes);
List<ByteBuf> chunkBuffers = new ArrayList<>();
try {
ChunkEncoder.EncodedMessage message = encoder.encodeSymmetric(clientChannel, requestId.getAndIncrement(), messageBuffer, MessageType.SecureMessage);
chunkBuffers.addAll(message.getMessageChunks());
} catch (MessageEncodeException e) {
fail("encoding error", e);
}
try {
ChunkDecoder.DecodedMessage decodedMessage = decoder.decodeSymmetric(serverChannel, chunkBuffers);
ByteBuf message = decodedMessage.getMessage();
messageBuffer.readerIndex(0);
assertEquals(message, messageBuffer);
ReferenceCountUtil.release(messageBuffer);
ReferenceCountUtil.release(message);
} catch (Throwable t) {
fail("decoding error", t);
}
}
}
}
use of org.eclipse.milo.opcua.stack.core.channel.ChunkEncoder in project milo by eclipse.
the class ChunkSerializationTest method testAsymmetricMessage.
@Test(dataProvider = "getAsymmetricSecurityParameters")
public void testAsymmetricMessage(SecurityPolicy securityPolicy, MessageSecurityMode messageSecurity, int messageSize) throws Exception {
logger.info("Asymmetric chunk serialization, securityPolicy={}, messageSecurityMode={}, messageSize={}", securityPolicy, messageSecurity, messageSize);
ChannelParameters[] channelParameters = { smallParameters, defaultParameters, unlimitedChunkCountParameters, unlimitedMessageSizeParameters };
for (ChannelParameters parameters : channelParameters) {
ChunkEncoder encoder = new ChunkEncoder(parameters);
ChunkDecoder decoder = new ChunkDecoder(parameters, EncodingLimits.DEFAULT);
SecureChannel[] channels = generateChannels(securityPolicy, messageSecurity);
ClientSecureChannel clientChannel = (ClientSecureChannel) channels[0];
ServerSecureChannel serverChannel = (ServerSecureChannel) channels[1];
clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).setIfAbsent(new LongSequence(1L, UInteger.MAX_VALUE));
LongSequence requestId = clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).get();
byte[] messageBytes = new byte[messageSize];
for (int i = 0; i < messageBytes.length; i++) {
messageBytes[i] = (byte) i;
}
ByteBuf messageBuffer = BufferUtil.pooledBuffer().writeBytes(messageBytes);
List<ByteBuf> chunkBuffers = new ArrayList<>();
try {
ChunkEncoder.EncodedMessage message = encoder.encodeAsymmetric(clientChannel, requestId.getAndIncrement(), messageBuffer, MessageType.OpenSecureChannel);
chunkBuffers.addAll(message.getMessageChunks());
} catch (MessageEncodeException e) {
fail("encoding error", e);
}
try {
ChunkDecoder.DecodedMessage decodedMessage = decoder.decodeAsymmetric(serverChannel, chunkBuffers);
ByteBuf message = decodedMessage.getMessage();
messageBuffer.readerIndex(0);
assertEquals(message, messageBuffer);
ReferenceCountUtil.release(message);
ReferenceCountUtil.release(messageBuffer);
} catch (Throwable t) {
fail("decoding error", t);
}
}
}
Aggregations