This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/master by this push:
     new 3fa35b9  - Decoupled the layers of the S7 protocol driver - 
Implemented error handling (Exceptions are translated to channel error events 
and result in dedicated exceptions in the completable future) - Added detection 
of exceeded PDU sizes on IsoTP and S7 layer - Linked the Netty messages 
(Messages now can have a "parent" property. This was needed in order to make it 
possible for higher level protocol layers to react on errors in lower layers)
3fa35b9 is described below

commit 3fa35b91ee82ff4c7d16dfc4e6b11c4b62f5a116
Author: Christofer Dutz <christofer.d...@c-ware.de>
AuthorDate: Thu Apr 12 13:53:11 2018 +0200

    - Decoupled the layers of the S7 protocol driver
    - Implemented error handling (Exceptions are translated to channel error 
events and result in dedicated exceptions in the completable future)
    - Added detection of exceeded PDU sizes on IsoTP and S7 layer
    - Linked the Netty messages (Messages now can have a "parent" property. 
This was needed in order to make it possible for higher level protocol layers 
to react on errors in lower layers)
---
 .../PlcProtocolPayloadTooBigException.java         |  53 ++++++
 .../java/api/messages/PlcRequestContainer.java     |  12 +-
 .../plc4x/java/api/messages/ProtocolMessage.java}  |   9 +-
 plc4j/protocols/driver-bases/base/pom.xml          |  13 ++
 .../plc4x/java/base/PlcMessageToMessageCodec.java  |  55 ++++++
 .../plc4x/java/base/events/ConnectEvent.java}      |  18 +-
 .../plc4x/java/base/events/ConnectedEvent.java}    |  20 +--
 .../plc4x/java/base/messages/RawMessage.java}      |  18 +-
 plc4j/protocols/s7/pom.xml                         |   4 -
 .../java/isoontcp/netty/IsoOnTcpProtocol.java      |   8 +-
 .../java/isoontcp/netty/model/IsoOnTcpMessage.java |   4 +-
 .../plc4x/java/isotp/netty/IsoTPProtocol.java      | 199 +++++++++++----------
 .../netty/events/IsoTPConnectedEvent.java}         |  10 +-
 .../plc4x/java/isotp/netty/model/IsoTPMessage.java |   4 +-
 .../java/isotp/netty/model/tpdus/DataTpdu.java     |   7 +-
 .../plc4x/java/isotp/netty/model/tpdus/Tpdu.java   |  11 +-
 .../plc4x/java/s7/connection/S7PlcConnection.java  |   9 +-
 .../plc4x/java/s7/netty/Plc4XS7Protocol.java       |  41 ++++-
 .../org/apache/plc4x/java/s7/netty/S7Protocol.java |  65 ++++---
 .../netty/events/S7ConnectedEvent.java}            |  10 +-
 .../java/s7/netty/model/messages/S7Message.java    |  15 +-
 .../s7/netty/model/messages/S7RequestMessage.java  |   6 +-
 .../messages/SetupCommunicationRequestMessage.java |   6 +-
 .../plc4x/java/isotp/netty/IsoTPProtocolTest.java  |  56 +++---
 .../plc4x/java/netty/events/S7StateTests.java      |  47 -----
 .../org/apache/plc4x/java/s7/PcapGenerator.java    |   2 +-
 .../java/s7/connection/S7PlcTestConnection.java    |   4 +-
 .../apache/plc4x/java/s7/netty/S7ProtocolTest.java |   4 +-
 .../s7/netty/model/messages/S7MessageTests.java    |  45 ++---
 29 files changed, 443 insertions(+), 312 deletions(-)

diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/exceptions/PlcProtocolPayloadTooBigException.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/exceptions/PlcProtocolPayloadTooBigException.java
new file mode 100644
index 0000000..6374c3c
--- /dev/null
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/exceptions/PlcProtocolPayloadTooBigException.java
@@ -0,0 +1,53 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.java.api.exceptions;
+
+public class PlcProtocolPayloadTooBigException extends PlcProtocolException {
+
+    private String protocolName;
+    private int maxSize;
+    private int actualSize;
+    private Object payload;
+
+    public PlcProtocolPayloadTooBigException(String protocolName, int maxSize, 
int actualSize, Object payload) {
+        super("Payload for protocol '" + protocolName + "' with size " + 
actualSize +
+            " exceeded allowed maximum of " + maxSize);
+        this.protocolName = protocolName;
+        this.maxSize = maxSize;
+        this.actualSize = actualSize;
+        this.payload = payload;
+    }
+
+    public String getProtocolName() {
+        return protocolName;
+    }
+
+    public int getMaxSize() {
+        return maxSize;
+    }
+
+    public int getActualSize() {
+        return actualSize;
+    }
+
+    public Object getPayload() {
+        return payload;
+    }
+
+}
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequestContainer.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequestContainer.java
index 2038399..6443c36 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequestContainer.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequestContainer.java
@@ -21,7 +21,7 @@ package org.apache.plc4x.java.api.messages;
 import java.util.Objects;
 import java.util.concurrent.CompletableFuture;
 
-public class PlcRequestContainer<T extends PlcRequest, R extends PlcResponse> {
+public class PlcRequestContainer<T extends PlcRequest, R extends PlcResponse> 
implements ProtocolMessage {
 
     private final T request;
     private final CompletableFuture<R> responseFuture;
@@ -41,4 +41,14 @@ public class PlcRequestContainer<T extends PlcRequest, R 
extends PlcResponse> {
         return responseFuture;
     }
 
+    /**
+     * {@link PlcRequestContainer} objects don't have parents.
+     *
+     * @return null
+     */
+    @Override
+    public ProtocolMessage getParent() {
+        return null;
+    }
+
 }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/ProtocolMessage.java
similarity index 83%
copy from 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
copy to 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/ProtocolMessage.java
index dfe1dc3..7e2bf09 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/ProtocolMessage.java
@@ -1,4 +1,4 @@
-/*
+package org.apache.plc4x.java.api.messages;/*
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
@@ -16,12 +16,9 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.java.netty.events;
 
-public enum S7ConnectionState {
+public interface ProtocolMessage {
 
-    INITIAL,
-    ISO_TP_CONNECTION_RESPONSE_RECEIVED,
-    SETUP_COMPLETE
+    ProtocolMessage getParent();
 
 }
diff --git a/plc4j/protocols/driver-bases/base/pom.xml 
b/plc4j/protocols/driver-bases/base/pom.xml
index 3c54e11..2dcbd0e 100644
--- a/plc4j/protocols/driver-bases/base/pom.xml
+++ b/plc4j/protocols/driver-bases/base/pom.xml
@@ -40,6 +40,19 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-buffer</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-codec</artifactId>
+    </dependency>
+    <dependency>
       <groupId>io.netty</groupId>
       <artifactId>netty-transport</artifactId>
     </dependency>
diff --git 
a/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/PlcMessageToMessageCodec.java
 
b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/PlcMessageToMessageCodec.java
new file mode 100644
index 0000000..68a9954
--- /dev/null
+++ 
b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/PlcMessageToMessageCodec.java
@@ -0,0 +1,55 @@
+package org.apache.plc4x.java.base;/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageCodec;
+import org.apache.commons.lang3.reflect.FieldUtils;
+
+import java.lang.reflect.Field;
+
+public abstract class PlcMessageToMessageCodec<INBOUND_IN, OUTBOUND_IN>
+    extends MessageToMessageCodec<INBOUND_IN, OUTBOUND_IN> {
+
+    private volatile ChannelHandler prevChannelHandler = null;
+
+    public PlcMessageToMessageCodec() {
+    }
+
+    public PlcMessageToMessageCodec(Class<? extends INBOUND_IN> 
inboundMessageType,
+                                    Class<? extends OUTBOUND_IN> 
outboundMessageType) {
+        super(inboundMessageType, outboundMessageType);
+    }
+
+    protected ChannelHandler getPrevChannelHandler(ChannelHandlerContext ctx) {
+        if(prevChannelHandler == null) {
+            try {
+                Field prevField = FieldUtils.getField(ctx.getClass(), "prev", 
true);
+                if(prevField != null) {
+                    ChannelHandlerContext prevContext = 
(ChannelHandlerContext) prevField.get(ctx);
+                    prevChannelHandler = prevContext.handler();
+                }
+            } catch(Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return prevChannelHandler;
+    }
+
+}
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/Message.java 
b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/events/ConnectEvent.java
similarity index 73%
copy from 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/Message.java
copy to 
plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/events/ConnectEvent.java
index a9c39fb..fdd240b 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/Message.java
+++ 
b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/events/ConnectEvent.java
@@ -1,4 +1,4 @@
-/*
+package org.apache.plc4x.java.base.events;/*
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
@@ -16,20 +16,6 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.java.netty;
-
-import io.netty.buffer.ByteBuf;
-
-public class Message {
-
-    private final ByteBuf userData;
-
-    public Message(ByteBuf userData) {
-        this.userData = userData;
-    }
-
-    public ByteBuf getUserData() {
-        return userData;
-    }
 
+public class ConnectEvent {
 }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionEvent.java
 
b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/events/ConnectedEvent.java
similarity index 67%
rename from 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionEvent.java
rename to 
plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/events/ConnectedEvent.java
index a81ba6a..f85feda 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionEvent.java
+++ 
b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/events/ConnectedEvent.java
@@ -1,4 +1,4 @@
-/*
+package org.apache.plc4x.java.base.events;/*
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
@@ -16,22 +16,6 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.java.netty.events;
-
-public class S7ConnectionEvent {
-
-    private final S7ConnectionState state;
-
-    public S7ConnectionEvent() {
-        this(S7ConnectionState.INITIAL);
-    }
-
-    public S7ConnectionEvent(S7ConnectionState state) {
-        this.state = state;
-    }
-
-    public S7ConnectionState getState() {
-        return state;
-    }
 
+public class ConnectedEvent {
 }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/Message.java 
b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/RawMessage.java
similarity index 67%
rename from 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/Message.java
rename to 
plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/RawMessage.java
index a9c39fb..500bfe6 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/Message.java
+++ 
b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/RawMessage.java
@@ -16,20 +16,32 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.java.netty;
+package org.apache.plc4x.java.base.messages;
 
 import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.api.messages.ProtocolMessage;
 
-public class Message {
+public class RawMessage implements ProtocolMessage {
 
     private final ByteBuf userData;
+    private final ProtocolMessage parent;
 
-    public Message(ByteBuf userData) {
+    public RawMessage(ByteBuf userData) {
+        this(userData, null);
+    }
+
+    public RawMessage(ByteBuf userData, ProtocolMessage parent) {
         this.userData = userData;
+        this.parent = parent;
     }
 
     public ByteBuf getUserData() {
         return userData;
     }
 
+    @Override
+    public ProtocolMessage getParent() {
+        return null;
+    }
+
 }
diff --git a/plc4j/protocols/s7/pom.xml b/plc4j/protocols/s7/pom.xml
index 40c5c7e..4565cba 100644
--- a/plc4j/protocols/s7/pom.xml
+++ b/plc4j/protocols/s7/pom.xml
@@ -61,10 +61,6 @@
     </dependency>
     <dependency>
       <groupId>io.netty</groupId>
-      <artifactId>netty-codec</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>io.netty</groupId>
       <artifactId>netty-transport</artifactId>
     </dependency>
 
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isoontcp/netty/IsoOnTcpProtocol.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isoontcp/netty/IsoOnTcpProtocol.java
index 03eff35..2a330e8 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isoontcp/netty/IsoOnTcpProtocol.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isoontcp/netty/IsoOnTcpProtocol.java
@@ -22,15 +22,15 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToMessageCodec;
 import org.apache.plc4x.java.api.exceptions.PlcProtocolException;
+import org.apache.plc4x.java.base.PlcMessageToMessageCodec;
 import org.apache.plc4x.java.isoontcp.netty.model.IsoOnTcpMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.List;
 
-public class IsoOnTcpProtocol extends MessageToMessageCodec<ByteBuf, 
IsoOnTcpMessage> {
+public class IsoOnTcpProtocol extends PlcMessageToMessageCodec<ByteBuf, 
IsoOnTcpMessage> {
 
     public static final byte ISO_ON_TCP_MAGIC_NUMBER = 0x03;
 
@@ -38,7 +38,7 @@ public class IsoOnTcpProtocol extends 
MessageToMessageCodec<ByteBuf, IsoOnTcpMes
 
     @Override
     protected void encode(ChannelHandlerContext ctx, IsoOnTcpMessage in, 
List<Object> out) throws Exception {
-        logger.debug("ISO on TCP Message sent");
+        logger.debug("ISO on TCP RawMessage sent");
         // At this point of processing all higher levels have already 
serialized their payload.
         // This data is passed to the lower levels in form of an IoBuffer.
         final ByteBuf userData = in.getUserData();
@@ -72,7 +72,7 @@ public class IsoOnTcpProtocol extends 
MessageToMessageCodec<ByteBuf, IsoOnTcpMes
         // and get the packet length. Only if the available amount of readable 
bytes is larger or
         // equal to this, continue processing the rest.
         if(in.readableBytes() >= 4) {
-            logger.debug("ISO on TCP Message received");
+            logger.debug("ISO on TCP RawMessage received");
             // The ISO on TCP protocol is really simple and in this case the 
buffer length
             // will take care of the higher levels not reading more than is in 
the packet.
             // So we just gobble up the header and continue reading in higher 
levels.
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isoontcp/netty/model/IsoOnTcpMessage.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isoontcp/netty/model/IsoOnTcpMessage.java
index 9c95db2..58e1847 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isoontcp/netty/model/IsoOnTcpMessage.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isoontcp/netty/model/IsoOnTcpMessage.java
@@ -19,9 +19,9 @@ under the License.
 package org.apache.plc4x.java.isoontcp.netty.model;
 
 import io.netty.buffer.ByteBuf;
-import org.apache.plc4x.java.netty.Message;
+import org.apache.plc4x.java.base.messages.RawMessage;
 
-public class IsoOnTcpMessage extends Message {
+public class IsoOnTcpMessage extends RawMessage {
 
     public IsoOnTcpMessage(ByteBuf userData) {
         super(userData);
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/IsoTPProtocol.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/IsoTPProtocol.java
index 71bdcaa..b295db6 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/IsoTPProtocol.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/IsoTPProtocol.java
@@ -21,15 +21,18 @@ package org.apache.plc4x.java.isotp.netty;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToMessageCodec;
+import org.apache.plc4x.java.api.exceptions.PlcProtocolPayloadTooBigException;
+import org.apache.plc4x.java.base.PlcMessageToMessageCodec;
+import org.apache.plc4x.java.base.events.ConnectEvent;
+import org.apache.plc4x.java.isoontcp.netty.IsoOnTcpProtocol;
 import org.apache.plc4x.java.isoontcp.netty.model.IsoOnTcpMessage;
+import org.apache.plc4x.java.isotp.netty.events.IsoTPConnectedEvent;
 import org.apache.plc4x.java.isotp.netty.model.IsoTPMessage;
 import org.apache.plc4x.java.isotp.netty.model.params.*;
 import org.apache.plc4x.java.isotp.netty.model.tpdus.*;
 import org.apache.plc4x.java.isotp.netty.model.types.*;
-import org.apache.plc4x.java.netty.events.S7ConnectionEvent;
-import org.apache.plc4x.java.netty.events.S7ConnectionState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,7 +40,7 @@ import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
 
-public class IsoTPProtocol extends MessageToMessageCodec<IsoOnTcpMessage, 
Tpdu> {
+public class IsoTPProtocol extends PlcMessageToMessageCodec<IsoOnTcpMessage, 
Tpdu> {
 
     private static final Logger logger = 
LoggerFactory.getLogger(IsoTPProtocol.class);
 
@@ -56,9 +59,11 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
 
     @Override
     public void userEventTriggered(ChannelHandlerContext ctx, Object evt) 
throws Exception {
+        ChannelHandler prevHandler = getPrevChannelHandler(ctx);
+
         // If the connection has just been established, start setting up the 
connection
         // by sending a connection request to the plc.
-        if (evt instanceof S7ConnectionEvent && ((S7ConnectionEvent) 
evt).getState() == S7ConnectionState.INITIAL) {
+        if ((prevHandler instanceof IsoOnTcpProtocol) && (evt instanceof 
ConnectEvent)) {
             logger.debug("ISO Transport Protocol Sending Connection Request");
             // Open the session on ISO Transport Protocol first.
             ConnectionRequestTpdu connectionRequest = new 
ConnectionRequestTpdu(
@@ -74,9 +79,12 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
         }
     }
 
+    
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
     @Override
     protected void encode(ChannelHandlerContext ctx, Tpdu in, List<Object> 
out) {
-        logger.debug("ISO Transport Protocol Message sent");
+        logger.debug("ISO Transport Protocol RawMessage sent");
 
         if (in == null) {
             return;
@@ -113,14 +121,20 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
         // Add the user-data itself.
         buf.writeBytes(in.getUserData());
 
-        out.add(new IsoOnTcpMessage(buf));
+        // Check if the message doesn't exceed the negotiated maximum size.
+        if(buf.writerIndex() > tpduSize.getValue()) {
+            ctx.fireExceptionCaught(new PlcProtocolPayloadTooBigException(
+                "iso-tp", tpduSize.getValue(), buf.writerIndex(), in));
+        } else {
+            out.add(new IsoOnTcpMessage(buf));
+        }
     }
 
     private void encodeError(Tpdu in, ByteBuf buf) {
         ErrorTpdu errorTpdu = (ErrorTpdu) in;
         buf.writeShort(errorTpdu.getDestinationReference());
         buf.writeByte(errorTpdu.getRejectCause().getCode());
-        outputParameters(buf, in.getParameters());
+        encodeParameters(buf, in.getParameters());
     }
 
     private void encodeDisconnect(Tpdu in, ByteBuf buf) {
@@ -131,7 +145,7 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
             DisconnectRequestTpdu disconnectRequestTpdu = 
(DisconnectRequestTpdu) disconnectTpdu;
             
buf.writeByte(disconnectRequestTpdu.getDisconnectReason().getCode());
         }
-        outputParameters(buf, in.getParameters());
+        encodeParameters(buf, in.getParameters());
     }
 
     private void encodeData(DataTpdu in, ByteBuf buf) {
@@ -145,7 +159,43 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
         buf.writeShort(connectionTpdu.getDestinationReference());
         buf.writeShort(connectionTpdu.getSourceReference());
         buf.writeByte(connectionTpdu.getProtocolClass().getCode());
-        outputParameters(buf, in.getParameters());
+        encodeParameters(buf, in.getParameters());
+    }
+
+    private void encodeParameters(ByteBuf out, List<Parameter> parameters) {
+        if (parameters == null) {
+            return;
+        }
+
+        for (Parameter parameter : parameters) {
+            out.writeByte(parameter.getType().getCode());
+            out.writeByte((byte) (getParameterLength(parameter) - 2));
+            switch (parameter.getType()) {
+                case CALLED_TSAP:
+                case CALLING_TSAP:
+                    TsapParameter tsap = (TsapParameter) parameter;
+                    out.writeByte(tsap.getDeviceGroup().getCode());
+                    out.writeByte((byte) ((tsap.getRackNumber() << 4) | 
(tsap.getSlotNumber() & 0x0F)));
+                    break;
+                case CHECKSUM:
+                    ChecksumParameter checksum = (ChecksumParameter) parameter;
+                    out.writeByte(checksum.getChecksum());
+                    break;
+                case DISCONNECT_ADDITIONAL_INFORMATION:
+                    DisconnectAdditionalInformationParameter 
disconnectAdditionalInformation = (DisconnectAdditionalInformationParameter) 
parameter;
+                    out.writeBytes(disconnectAdditionalInformation.getData());
+                    break;
+                case TPDU_SIZE:
+                    TpduSizeParameter sizeParameter = (TpduSizeParameter) 
parameter;
+                    out.writeByte(sizeParameter.getTpduSize().getCode());
+                    break;
+                default:
+                    if (logger.isErrorEnabled()) {
+                        logger.error("TDPU tarameter type {} not implemented 
yet", parameter.getType().name());
+                    }
+                    return;
+            }
+        }
     }
 
     @Override
@@ -153,7 +203,7 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
         if (logger.isTraceEnabled()) {
             logger.trace("Got Data: {}", 
ByteBufUtil.hexDump(in.getUserData()));
         }
-        logger.debug("ISO TP Message received");
+        logger.debug("ISO TP RawMessage received");
 
         if (in == null) {
             return;
@@ -195,7 +245,7 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
 
         // Read variable header parameters
         while (userData.readerIndex() < headerEnd) {
-            Parameter parameter = parseParameter(userData);
+            Parameter parameter = decodeParameter(userData);
             if (parameter != null) {
                 parameters.add(parameter);
             }
@@ -259,46 +309,55 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
 
         } else { // TpduCode.CONNECTION_CONFIRM
             tpdu = new ConnectionConfirmTpdu(destinationReference, 
sourceReference, protocolClass, parameters, userData);
-            ctx.channel().pipeline().fireUserEventTriggered(
-                new 
S7ConnectionEvent(S7ConnectionState.ISO_TP_CONNECTION_RESPONSE_RECEIVED));
-
+            ctx.channel().pipeline().fireUserEventTriggered(new 
IsoTPConnectedEvent());
         }
         return tpdu;
     }
 
-    private void outputParameters(ByteBuf out, List<Parameter> parameters) {
-        if (parameters == null) {
-            return;
+    private Parameter decodeParameter(ByteBuf out) {
+        ParameterCode parameterCode = ParameterCode.valueOf(out.readByte());
+        if (parameterCode == null) {
+            logger.error("Could not find parameter code");
+            return null;
+        }
+        byte length = out.readByte();
+        switch (parameterCode) {
+            case CALLING_TSAP:
+            case CALLED_TSAP:
+                return decodeCallParameter(out, parameterCode);
+            case CHECKSUM:
+                byte checksum = out.readByte();
+                return new ChecksumParameter(checksum);
+            case DISCONNECT_ADDITIONAL_INFORMATION:
+                byte[] data = new byte[length];
+                out.readBytes(data);
+                return new DisconnectAdditionalInformationParameter(data);
+            case TPDU_SIZE:
+                TpduSize size = TpduSize.valueOf(out.readByte());
+                return new TpduSizeParameter(size);
+            default:
+                if (logger.isErrorEnabled()) {
+                    logger.error("Parameter not implemented yet {}", 
parameterCode.name());
+                }
+                return null;
         }
+    }
 
-        for (Parameter parameter : parameters) {
-            out.writeByte(parameter.getType().getCode());
-            out.writeByte((byte) (getParameterLength(parameter) - 2));
-            switch (parameter.getType()) {
-                case CALLED_TSAP:
-                case CALLING_TSAP:
-                    TsapParameter tsap = (TsapParameter) parameter;
-                    out.writeByte(tsap.getDeviceGroup().getCode());
-                    out.writeByte((byte) ((tsap.getRackNumber() << 4) | 
(tsap.getSlotNumber() & 0x0F)));
-                    break;
-                case CHECKSUM:
-                    ChecksumParameter checksum = (ChecksumParameter) parameter;
-                    out.writeByte(checksum.getChecksum());
-                    break;
-                case DISCONNECT_ADDITIONAL_INFORMATION:
-                    DisconnectAdditionalInformationParameter 
disconnectAdditionalInformation = (DisconnectAdditionalInformationParameter) 
parameter;
-                    out.writeBytes(disconnectAdditionalInformation.getData());
-                    break;
-                case TPDU_SIZE:
-                    TpduSizeParameter sizeParameter = (TpduSizeParameter) 
parameter;
-                    out.writeByte(sizeParameter.getTpduSize().getCode());
-                    break;
-                default:
-                    if (logger.isErrorEnabled()) {
-                        logger.error("TDPU tarameter type {} not implemented 
yet", parameter.getType().name());
-                    }
-                    return;
-            }
+    private Parameter decodeCallParameter(ByteBuf out, ParameterCode 
parameterCode) {
+        DeviceGroup deviceGroup = DeviceGroup.valueOf(out.readByte());
+        byte rackAndSlot = out.readByte();
+        byte rackId = (byte) ((rackAndSlot & 0xF0) >> 4);
+        byte slotId = (byte) (rackAndSlot & 0x0F);
+        switch (parameterCode) {
+            case CALLING_TSAP:
+                return new CallingTsapParameter(deviceGroup, rackId, slotId);
+            case CALLED_TSAP:
+                return new CalledTsapParameter(deviceGroup, rackId, slotId);
+            default:
+                if (logger.isErrorEnabled()) {
+                    logger.error("Parameter not implemented yet {}", 
parameterCode.name());
+                }
+                return null;
         }
     }
 
@@ -372,52 +431,4 @@ public class IsoTPProtocol extends 
MessageToMessageCodec<IsoOnTcpMessage, Tpdu>
         }
     }
 
-    private Parameter parseParameter(ByteBuf out) {
-        ParameterCode parameterCode = ParameterCode.valueOf(out.readByte());
-        if (parameterCode == null) {
-            logger.error("Could not find parameter code");
-            return null;
-        }
-        byte length = out.readByte();
-        switch (parameterCode) {
-            case CALLING_TSAP:
-            case CALLED_TSAP:
-                return parseCallParameter(out, parameterCode);
-            case CHECKSUM:
-                byte checksum = out.readByte();
-                return new ChecksumParameter(checksum);
-            case DISCONNECT_ADDITIONAL_INFORMATION:
-                byte[] data = new byte[length];
-                out.readBytes(data);
-                return new DisconnectAdditionalInformationParameter(data);
-            case TPDU_SIZE:
-                TpduSize size = TpduSize.valueOf(out.readByte());
-                return new TpduSizeParameter(size);
-            default:
-                if (logger.isErrorEnabled()) {
-                    logger.error("Parameter not implemented yet {}", 
parameterCode.name());
-                }
-                return null;
-        }
-    }
-
-    private Parameter parseCallParameter(ByteBuf out, ParameterCode 
parameterCode) {
-        DeviceGroup deviceGroup = DeviceGroup.valueOf(out.readByte());
-        byte rackAndSlot = out.readByte();
-        byte rackId = (byte) ((rackAndSlot & 0xF0) >> 4);
-        byte slotId = (byte) (rackAndSlot & 0x0F);
-        switch (parameterCode) {
-            case CALLING_TSAP:
-                return new CallingTsapParameter(deviceGroup, rackId, slotId);
-            case CALLED_TSAP:
-                return new CalledTsapParameter(deviceGroup, rackId, slotId);
-            default:
-                if (logger.isErrorEnabled()) {
-                    logger.error("Parameter not implemented yet {}", 
parameterCode.name());
-                }
-                return null;
-        }
-    }
-
-
 }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/events/IsoTPConnectedEvent.java
similarity index 83%
copy from 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
copy to 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/events/IsoTPConnectedEvent.java
index dfe1dc3..643c5e4 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/events/IsoTPConnectedEvent.java
@@ -1,4 +1,4 @@
-/*
+package org.apache.plc4x.java.isotp.netty.events;/*
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
@@ -16,12 +16,6 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.java.netty.events;
-
-public enum S7ConnectionState {
-
-    INITIAL,
-    ISO_TP_CONNECTION_RESPONSE_RECEIVED,
-    SETUP_COMPLETE
 
+public class IsoTPConnectedEvent {
 }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/IsoTPMessage.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/IsoTPMessage.java
index 98899cf..858a0fe 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/IsoTPMessage.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/IsoTPMessage.java
@@ -19,10 +19,10 @@ under the License.
 package org.apache.plc4x.java.isotp.netty.model;
 
 import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.base.messages.RawMessage;
 import org.apache.plc4x.java.isotp.netty.model.tpdus.Tpdu;
-import org.apache.plc4x.java.netty.Message;
 
-public class IsoTPMessage extends Message {
+public class IsoTPMessage extends RawMessage {
 
     private final Tpdu tpdu;
 
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/DataTpdu.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/DataTpdu.java
index 5eb280d..6680331 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/DataTpdu.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/DataTpdu.java
@@ -19,6 +19,7 @@ under the License.
 package org.apache.plc4x.java.isotp.netty.model.tpdus;
 
 import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.api.messages.ProtocolMessage;
 import org.apache.plc4x.java.isotp.netty.model.params.Parameter;
 import org.apache.plc4x.java.isotp.netty.model.types.TpduCode;
 
@@ -30,7 +31,11 @@ public class DataTpdu extends Tpdu {
     private final byte tpduRef;
 
     public DataTpdu(boolean eot, byte tpduRef, List<Parameter> parameters, 
ByteBuf userData) {
-        super(TpduCode.DATA, parameters, userData);
+        this(eot, tpduRef, parameters, userData, null);
+    }
+
+    public DataTpdu(boolean eot, byte tpduRef, List<Parameter> parameters, 
ByteBuf userData, ProtocolMessage parent) {
+        super(TpduCode.DATA, parameters, userData, parent);
         this.eot = eot;
         this.tpduRef = tpduRef;
     }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/Tpdu.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/Tpdu.java
index 08ca6a2..75d8aa5 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/Tpdu.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/Tpdu.java
@@ -19,20 +19,25 @@ under the License.
 package org.apache.plc4x.java.isotp.netty.model.tpdus;
 
 import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.api.messages.ProtocolMessage;
+import org.apache.plc4x.java.base.messages.RawMessage;
 import org.apache.plc4x.java.isotp.netty.model.params.Parameter;
 import org.apache.plc4x.java.isotp.netty.model.types.TpduCode;
-import org.apache.plc4x.java.netty.Message;
 
 import java.util.List;
 import java.util.Optional;
 
-public abstract class Tpdu extends Message {
+public abstract class Tpdu extends RawMessage {
 
     private final TpduCode tpduCode;
     private final List<Parameter> parameters;
 
     public Tpdu(TpduCode tpduCode, List<Parameter> parameters, ByteBuf 
userData) {
-        super(userData);
+        this(tpduCode, parameters, userData, null);
+    }
+
+    public Tpdu(TpduCode tpduCode, List<Parameter> parameters, ByteBuf 
userData, ProtocolMessage parent) {
+        super(userData, parent);
         this.tpduCode = tpduCode;
         this.parameters = parameters;
     }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
index 6581abf..e224544 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
@@ -29,13 +29,13 @@ import org.apache.plc4x.java.api.model.Address;
 import org.apache.plc4x.java.base.connection.AbstractPlcConnection;
 import org.apache.plc4x.java.base.connection.ChannelFactory;
 import org.apache.plc4x.java.base.connection.TcpSocketChannelFactory;
+import org.apache.plc4x.java.base.events.ConnectEvent;
+import org.apache.plc4x.java.base.events.ConnectedEvent;
 import org.apache.plc4x.java.isoontcp.netty.IsoOnTcpProtocol;
 import org.apache.plc4x.java.isotp.netty.IsoTPProtocol;
 import org.apache.plc4x.java.isotp.netty.model.tpdus.DisconnectRequestTpdu;
 import org.apache.plc4x.java.isotp.netty.model.types.DisconnectReason;
 import org.apache.plc4x.java.isotp.netty.model.types.TpduSize;
-import org.apache.plc4x.java.netty.events.S7ConnectionEvent;
-import org.apache.plc4x.java.netty.events.S7ConnectionState;
 import org.apache.plc4x.java.s7.model.S7Address;
 import org.apache.plc4x.java.s7.model.S7BitAddress;
 import org.apache.plc4x.java.s7.model.S7DataBlockAddress;
@@ -129,8 +129,7 @@ public class S7PlcConnection extends AbstractPlcConnection 
implements PlcReader,
                 pipeline.addLast(new ChannelInboundHandlerAdapter() {
                     @Override
                     public void userEventTriggered(ChannelHandlerContext ctx, 
Object evt) throws Exception {
-                        if (evt instanceof S7ConnectionEvent &&
-                            ((S7ConnectionEvent) evt).getState() == 
S7ConnectionState.SETUP_COMPLETE) {
+                        if (evt instanceof ConnectedEvent) {
                             sessionSetupCompleteFuture.complete(null);
                         } else {
                             super.userEventTriggered(ctx, evt);
@@ -148,7 +147,7 @@ public class S7PlcConnection extends AbstractPlcConnection 
implements PlcReader,
     @Override
     protected void sendChannelCreatedEvent() {
         // Send an event to the pipeline telling the Protocol filters what's 
going on.
-        channel.pipeline().fireUserEventTriggered(new S7ConnectionEvent());
+        channel.pipeline().fireUserEventTriggered(new ConnectEvent());
     }
 
     public int getRack() {
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
index 750ed62..f5c12f9 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/Plc4XS7Protocol.java
@@ -19,9 +19,9 @@ under the License.
 package org.apache.plc4x.java.s7.netty;
 
 import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToMessageCodec;
 import org.apache.plc4x.java.api.exceptions.PlcException;
 import org.apache.plc4x.java.api.exceptions.PlcProtocolException;
+import org.apache.plc4x.java.api.exceptions.PlcProtocolPayloadTooBigException;
 import org.apache.plc4x.java.api.messages.*;
 import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
 import org.apache.plc4x.java.api.messages.items.ReadResponseItem;
@@ -33,9 +33,12 @@ import 
org.apache.plc4x.java.api.messages.specific.TypeSafePlcWriteRequest;
 import org.apache.plc4x.java.api.messages.specific.TypeSafePlcWriteResponse;
 import org.apache.plc4x.java.api.model.Address;
 import org.apache.plc4x.java.api.types.ResponseCode;
+import org.apache.plc4x.java.base.PlcMessageToMessageCodec;
+import org.apache.plc4x.java.base.events.ConnectedEvent;
 import org.apache.plc4x.java.s7.model.S7Address;
 import org.apache.plc4x.java.s7.model.S7BitAddress;
 import org.apache.plc4x.java.s7.model.S7DataBlockAddress;
+import org.apache.plc4x.java.s7.netty.events.S7ConnectedEvent;
 import org.apache.plc4x.java.s7.netty.model.messages.S7Message;
 import org.apache.plc4x.java.s7.netty.model.messages.S7RequestMessage;
 import org.apache.plc4x.java.s7.netty.model.messages.S7ResponseMessage;
@@ -52,7 +55,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import static org.apache.plc4x.java.s7.netty.util.S7TypeDecoder.decodeData;
 import static org.apache.plc4x.java.s7.netty.util.S7TypeEncoder.encodeData;
 
-public class Plc4XS7Protocol extends MessageToMessageCodec<S7Message, 
PlcRequestContainer> {
+public class Plc4XS7Protocol extends PlcMessageToMessageCodec<S7Message, 
PlcRequestContainer> {
 
     private static final AtomicInteger tpduGenerator = new AtomicInteger(1);
 
@@ -63,6 +66,15 @@ public class Plc4XS7Protocol extends 
MessageToMessageCodec<S7Message, PlcRequest
     }
 
     @Override
+    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) 
throws Exception {
+        if (evt instanceof S7ConnectedEvent) {
+            ctx.channel().pipeline().fireUserEventTriggered(new 
ConnectedEvent());
+        } else {
+            super.userEventTriggered(ctx, evt);
+        }
+    }
+
+    @Override
     protected void encode(ChannelHandlerContext ctx, PlcRequestContainer msg, 
List<Object> out) throws Exception {
         PlcRequest request = msg.getRequest();
         if (request instanceof PlcReadRequest) {
@@ -106,7 +118,7 @@ public class Plc4XS7Protocol extends 
MessageToMessageCodec<S7Message, PlcRequest
         // Assemble the request.
         S7RequestMessage s7WriteRequest = new S7RequestMessage(MessageType.JOB,
             (short) tpduGenerator.getAndIncrement(), 
Collections.singletonList(writeVarParameter),
-            Collections.singletonList(writeVarPayload));
+            Collections.singletonList(writeVarPayload), msg);
 
         requests.put(s7WriteRequest.getTpduReference(), msg);
 
@@ -123,7 +135,7 @@ public class Plc4XS7Protocol extends 
MessageToMessageCodec<S7Message, PlcRequest
         // Assemble the request.
         S7RequestMessage s7ReadRequest = new S7RequestMessage(MessageType.JOB,
             (short) tpduGenerator.getAndIncrement(), 
Collections.singletonList(readVarParameter),
-            Collections.emptyList());
+            Collections.emptyList(), msg);
 
         requests.put(s7ReadRequest.getTpduReference(), msg);
 
@@ -172,6 +184,27 @@ public class Plc4XS7Protocol extends 
MessageToMessageCodec<S7Message, PlcRequest
         }
     }
 
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) 
throws Exception {
+        if(cause instanceof PlcProtocolPayloadTooBigException) {
+            PlcProtocolPayloadTooBigException pptbe = 
(PlcProtocolPayloadTooBigException) cause;
+            if(pptbe.getPayload() instanceof S7RequestMessage) {
+                S7RequestMessage request = (S7RequestMessage) 
pptbe.getPayload();
+                if(request.getParent() instanceof PlcRequestContainer) {
+                    PlcRequestContainer requestContainer = 
(PlcRequestContainer) request.getParent();
+
+                    // Remove the current request from the unconfirmed 
requests list.
+                    if(requests.containsKey(request.getTpduReference())) {
+                        requests.remove(request.getTpduReference());
+                    }
+
+                    
requestContainer.getResponseFuture().completeExceptionally(cause);
+                }
+            }
+        }
+        super.exceptionCaught(ctx, cause);
+    }
+
     @SuppressWarnings("unchecked")
     private PlcResponse decodeWriteRequest(S7ResponseMessage responseMessage, 
PlcRequestContainer requestContainer) throws PlcProtocolException {
         PlcResponse response;
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
index 40398d0..923b820 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
@@ -21,12 +21,15 @@ package org.apache.plc4x.java.s7.netty;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToMessageCodec;
+import org.apache.plc4x.java.api.exceptions.PlcProtocolPayloadTooBigException;
+import org.apache.plc4x.java.base.PlcMessageToMessageCodec;
+import org.apache.plc4x.java.isotp.netty.IsoTPProtocol;
+import org.apache.plc4x.java.isotp.netty.events.IsoTPConnectedEvent;
 import org.apache.plc4x.java.isotp.netty.model.IsoTPMessage;
 import org.apache.plc4x.java.isotp.netty.model.tpdus.DataTpdu;
-import org.apache.plc4x.java.netty.events.S7ConnectionEvent;
-import org.apache.plc4x.java.netty.events.S7ConnectionState;
+import org.apache.plc4x.java.s7.netty.events.S7ConnectedEvent;
 import org.apache.plc4x.java.s7.netty.model.messages.S7Message;
 import org.apache.plc4x.java.s7.netty.model.messages.S7RequestMessage;
 import org.apache.plc4x.java.s7.netty.model.messages.S7ResponseMessage;
@@ -45,14 +48,12 @@ import org.slf4j.LoggerFactory;
 
 import java.util.*;
 
-public class S7Protocol extends MessageToMessageCodec<IsoTPMessage, S7Message> 
{
+public class S7Protocol extends PlcMessageToMessageCodec<IsoTPMessage, 
S7Message> {
 
     private static final byte S7_PROTOCOL_MAGIC_NUMBER = 0x32;
 
     private static final Logger logger = 
LoggerFactory.getLogger(S7Protocol.class);
 
-    private Map<Short, List<S7Message>> messageFragments = new HashMap<>();
-
     private short maxAmqCaller;
     private short maxAmqCallee;
     private short pduSize;
@@ -65,24 +66,27 @@ public class S7Protocol extends 
MessageToMessageCodec<IsoTPMessage, S7Message> {
 
     @Override
     public void userEventTriggered(ChannelHandlerContext ctx, Object evt) 
throws Exception {
-        if (evt instanceof S7ConnectionEvent &&
-            ((S7ConnectionEvent) evt).getState() == 
S7ConnectionState.ISO_TP_CONNECTION_RESPONSE_RECEIVED) {
+        ChannelHandler prevHandler = getPrevChannelHandler(ctx);
+
+        // If we are using S7 inside of IsoTP, then we need to intercept 
IsoTPs connected events.
+        if ((prevHandler instanceof IsoTPProtocol) && (evt instanceof 
IsoTPConnectedEvent)) {
             // Setup Communication
             SetupCommunicationRequestMessage setupCommunicationRequest =
-                new SetupCommunicationRequestMessage((short) 7, maxAmqCaller, 
maxAmqCallee, pduSize);
+                new SetupCommunicationRequestMessage((short) 7, maxAmqCaller, 
maxAmqCallee, pduSize, null);
 
             ctx.channel().writeAndFlush(setupCommunicationRequest);
-        } else {
+        }
+
+        else {
             super.userEventTriggered(ctx, evt);
         }
     }
 
     @Override
     protected void encode(ChannelHandlerContext ctx, S7Message in, 
List<Object> out) {
-        logger.debug("S7 Message sent");
+        logger.debug("S7 RawMessage sent");
 
-        List<S7Message> messages = splitMessage(in);
-        messageFragments.put(in.getTpduReference(), messages);
+        List<S7Message> messages = optimizeMessage(in);
 
         for (S7Message message : messages) {
             ByteBuf buf = Unpooled.buffer();
@@ -91,21 +95,34 @@ public class S7Protocol extends 
MessageToMessageCodec<IsoTPMessage, S7Message> {
             encodeParameters(message, buf);
             encodePayloads(message, buf);
 
-            out.add(new DataTpdu(true, (byte) 1, Collections.emptyList(), 
buf));
+            // Check if the message doesn't exceed the negotiated maximum size.
+            if(buf.writerIndex() > pduSize) {
+                ctx.fireExceptionCaught(new 
PlcProtocolPayloadTooBigException("s7", pduSize, buf.writerIndex(), in));
+            } else {
+                out.add(new DataTpdu(true, (byte) 1, Collections.emptyList(), 
buf, in));
+            }
         }
     }
 
     /**
-     * While a SetupCommunication message is no problem, when reading multiple
-     * addresses in one request, the size of the PDU could be exceeded, 
therefore we need
-     * to split up one incoming message. When writing, the S7 PLCs only seem 
to accept
-     * writing of single elements, so we have to break up writing of multiple 
values into
-     * multiple single-value write operations.
+     * While a SetupCommunication message is no problem, when reading or 
writing data,
+     * situations could arise that have to be handled. The following 
situations have to
+     * be handled:
+     * - The number of request items is so big, that the resulting PDU would 
exceed the
+     *   agreed upon PDU size -> The request has to be split up into multiple 
requests.
+     * - If large blocks of data are requested by request items the result of 
a request
+     *   could exceed the PDU size -> The requests has to be split up into 
multiple requests
+     *   where each requests response doesn't exceed the PDU size.
+     *
+     * The following optimizations should be implemented:
+     * - If blocks are read which are in near proximity to each other it could 
be better
+     *   to replace multiple requests by one that includes multiple blocks.
+     * - Rearranging the order of request items could reduce the number of 
needed PDUs.
      *
      * @param message incoming message
      * @return List of outgoing messages
      */
-    private List<S7Message> splitMessage(S7Message message) {
+    private List<S7Message> optimizeMessage(S7Message message) {
         // The following considerations have to be taken into account:
         // - The size of all parameters and payloads of a message cannot 
exceed the negotiated PDU size
         // - When reading data, the size of the returned data cannot exceed 
the negotiated PDU size
@@ -223,7 +240,7 @@ public class S7Protocol extends 
MessageToMessageCodec<IsoTPMessage, S7Message> {
         if (userData.readableBytes() == 0) {
             return;
         }
-        logger.debug("S7 Message received");
+        logger.debug("S7 RawMessage received");
 
         if (userData.readByte() != S7_PROTOCOL_MAGIC_NUMBER) {
             logger.warn("Expecting S7 protocol magic number.");
@@ -269,7 +286,8 @@ public class S7Protocol extends 
MessageToMessageCodec<IsoTPMessage, S7Message> {
             setupCommunications(ctx, setupCommunicationParameter);
             out.add(new S7ResponseMessage(messageType, tpduReference, 
s7Parameters, s7Payloads, errorClass, errorCode));
         } else {
-            out.add(new S7RequestMessage(messageType, tpduReference, 
s7Parameters, s7Payloads));
+            // TODO: Find out if there is any situation in which a request is 
sent from the PLC
+            out.add(new S7RequestMessage(messageType, tpduReference, 
s7Parameters, s7Payloads, null));
         }
     }
 
@@ -284,8 +302,7 @@ public class S7Protocol extends 
MessageToMessageCodec<IsoTPMessage, S7Message> {
             pduSize = setupCommunicationParameter.getPduLength();
 
             // Send an event that setup is complete.
-            ctx.channel().pipeline().fireUserEventTriggered(
-                new S7ConnectionEvent(S7ConnectionState.SETUP_COMPLETE));
+            ctx.channel().pipeline().fireUserEventTriggered(new 
S7ConnectedEvent());
         }
     }
 
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/events/S7ConnectedEvent.java
similarity index 83%
rename from 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
rename to 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/events/S7ConnectedEvent.java
index dfe1dc3..c085e8c 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/netty/events/S7ConnectionState.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/events/S7ConnectedEvent.java
@@ -1,4 +1,4 @@
-/*
+package org.apache.plc4x.java.s7.netty.events;/*
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
@@ -16,12 +16,6 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.java.netty.events;
-
-public enum S7ConnectionState {
-
-    INITIAL,
-    ISO_TP_CONNECTION_RESPONSE_RECEIVED,
-    SETUP_COMPLETE
 
+public class S7ConnectedEvent {
 }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/S7Message.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/S7Message.java
index 214aed7..7bd56c5 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/S7Message.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/S7Message.java
@@ -18,7 +18,8 @@ under the License.
 */
 package org.apache.plc4x.java.s7.netty.model.messages;
 
-import org.apache.plc4x.java.netty.Message;
+import org.apache.plc4x.java.api.messages.ProtocolMessage;
+import org.apache.plc4x.java.base.messages.RawMessage;
 import org.apache.plc4x.java.s7.netty.model.params.S7Parameter;
 import org.apache.plc4x.java.s7.netty.model.payloads.S7Payload;
 import org.apache.plc4x.java.s7.netty.model.types.MessageType;
@@ -26,15 +27,21 @@ import 
org.apache.plc4x.java.s7.netty.model.types.MessageType;
 import java.util.List;
 import java.util.Optional;
 
-public abstract class S7Message extends Message {
+public abstract class S7Message extends RawMessage {
 
     private final MessageType messageType;
     private final short tpduReference;
     private final List<S7Parameter> parameters;
     private final List<S7Payload> payloads;
 
-    protected S7Message(MessageType messageType, short tpduReference, 
List<S7Parameter> parameters, List<S7Payload> payloads) {
-        super(null);
+    protected S7Message(MessageType messageType, short tpduReference, 
List<S7Parameter> parameters,
+                        List<S7Payload> payloads) {
+        this(messageType, tpduReference, parameters, payloads, null);
+    }
+
+    protected S7Message(MessageType messageType, short tpduReference, 
List<S7Parameter> parameters,
+                        List<S7Payload> payloads, ProtocolMessage parent) {
+        super(null, parent);
         this.messageType = messageType;
         this.tpduReference = tpduReference;
         this.parameters = parameters;
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/S7RequestMessage.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/S7RequestMessage.java
index 968e6c6..93f99c5 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/S7RequestMessage.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/S7RequestMessage.java
@@ -18,6 +18,7 @@ under the License.
 */
 package org.apache.plc4x.java.s7.netty.model.messages;
 
+import org.apache.plc4x.java.api.messages.ProtocolMessage;
 import org.apache.plc4x.java.s7.netty.model.params.S7Parameter;
 import org.apache.plc4x.java.s7.netty.model.payloads.S7Payload;
 import org.apache.plc4x.java.s7.netty.model.types.MessageType;
@@ -26,8 +27,9 @@ import java.util.List;
 
 public class S7RequestMessage extends S7Message {
 
-    public S7RequestMessage(MessageType messageType, short tpduReference, 
List<S7Parameter> s7Parameters, List<S7Payload> s7Payloads) {
-        super(messageType, tpduReference, s7Parameters, s7Payloads);
+    public S7RequestMessage(MessageType messageType, short tpduReference, 
List<S7Parameter> s7Parameters,
+                            List<S7Payload> s7Payloads, ProtocolMessage 
parent) {
+        super(messageType, tpduReference, s7Parameters, s7Payloads, parent);
     }
 
 }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/SetupCommunicationRequestMessage.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/SetupCommunicationRequestMessage.java
index 4956d00..0171422 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/SetupCommunicationRequestMessage.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/messages/SetupCommunicationRequestMessage.java
@@ -18,6 +18,7 @@ under the License.
 */
 package org.apache.plc4x.java.s7.netty.model.messages;
 
+import org.apache.plc4x.java.api.messages.ProtocolMessage;
 import org.apache.plc4x.java.s7.netty.model.params.SetupCommunicationParameter;
 import org.apache.plc4x.java.s7.netty.model.types.MessageType;
 
@@ -25,9 +26,10 @@ import java.util.Collections;
 
 public class SetupCommunicationRequestMessage extends S7RequestMessage {
 
-    public SetupCommunicationRequestMessage(short tpduReference, short 
maxAmqCaller, short maxAmqCallee, short pduLength) {
+    public SetupCommunicationRequestMessage(short tpduReference, short 
maxAmqCaller, short maxAmqCallee,
+                                            short pduLength, ProtocolMessage 
parent) {
         super(MessageType.JOB, tpduReference, Collections.singletonList(
-            new SetupCommunicationParameter(maxAmqCaller, maxAmqCallee, 
pduLength)), Collections.emptyList());
+            new SetupCommunicationParameter(maxAmqCaller, maxAmqCallee, 
pduLength)), Collections.emptyList(), parent);
     }
 
 }
diff --git 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/IsoTPProtocolTest.java
 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/IsoTPProtocolTest.java
index 16b26fc..886d63d 100644
--- 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/IsoTPProtocolTest.java
+++ 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/IsoTPProtocolTest.java
@@ -74,7 +74,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -98,7 +98,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ConnectionRequestTpdu requestTpdu = (ConnectionRequestTpdu) 
((IsoTPMessage) out.get(0)).getTpdu();
 
@@ -116,7 +116,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
         assertThat(userData.writerIndex(), equalTo(7));
@@ -139,7 +139,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         DisconnectRequestTpdu requestTpdu = (DisconnectRequestTpdu) 
((IsoTPMessage) out.get(0)).getTpdu();
 
@@ -157,7 +157,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -177,7 +177,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         DataTpdu requestTpdu = (DataTpdu) ((IsoTPMessage) 
out.get(0)).getTpdu();
 
@@ -197,7 +197,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         DataTpdu requestTpdu = (DataTpdu) ((IsoTPMessage) 
out.get(0)).getTpdu();
 
@@ -214,7 +214,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -238,7 +238,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ConnectionConfirmTpdu requestTpdu = (ConnectionConfirmTpdu) 
((IsoTPMessage) out.get(0)).getTpdu();
 
@@ -256,7 +256,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -279,7 +279,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         DisconnectConfirmTpdu requestTpdu = (DisconnectConfirmTpdu) 
((IsoTPMessage) out.get(0)).getTpdu();
 
@@ -296,7 +296,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -317,7 +317,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -344,7 +344,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -369,7 +369,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -396,7 +396,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.encode(ctx, tpdu, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ByteBuf userData = ((IsoOnTcpMessage) out.get(0)).getUserData();
 
@@ -421,7 +421,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ErrorTpdu errorTpdu = (ErrorTpdu) ((IsoTPMessage) 
out.get(0)).getTpdu();
 
@@ -437,10 +437,10 @@ public class IsoTPProtocolTest {
         ConnectionRequestTpdu tpdu = null;
 
         isoTPProtocol.encode(ctx, tpdu, out);
-        assertThat("Message not decoded", out, empty());
+        assertThat("RawMessage not decoded", out, empty());
 
         isoTPProtocol.encode(ctx, null, out);
-        assertThat("Message not decoded", out, empty());
+        assertThat("RawMessage not decoded", out, empty());
     }
 
 
@@ -450,10 +450,10 @@ public class IsoTPProtocolTest {
         IsoOnTcpMessage in = new IsoOnTcpMessage(buf);
 
         isoTPProtocol.decode(ctx, in, out);
-        assertThat("Message not decoded", out, empty());
+        assertThat("RawMessage not decoded", out, empty());
 
         isoTPProtocol.decode(ctx, null, out);
-        assertThat("Message not decoded", out, empty());
+        assertThat("RawMessage not decoded", out, empty());
     }
 
     @Test
@@ -463,7 +463,7 @@ public class IsoTPProtocolTest {
         CustomTpdu tpdu = new CustomTpdu((byte) 0x7F, parmameters, buf);
 
         isoTPProtocol.encode(ctx, tpdu, out);
-        assertThat("Message not decoded", out, empty());
+        assertThat("RawMessage not decoded", out, empty());
     }
 
 
@@ -475,7 +475,7 @@ public class IsoTPProtocolTest {
             .writeByte(0x7F)
             .writeShort(0x01); // destination reference
         isoTPProtocol.decode(ctx, in, out);
-        assertThat("Message not decoded", out, empty());
+        assertThat("RawMessage not decoded", out, empty());
     }
 
     @Test
@@ -493,7 +493,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ErrorTpdu errorTpdu = (ErrorTpdu) ((IsoTPMessage) 
out.get(0)).getTpdu();
 
@@ -523,7 +523,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ErrorTpdu errorTpdu = (ErrorTpdu) ((IsoTPMessage) 
out.get(0)).getTpdu();
 
@@ -552,7 +552,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ErrorTpdu errorTpdu = (ErrorTpdu) ((IsoTPMessage) 
out.get(0)).getTpdu();
 
@@ -579,7 +579,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ErrorTpdu errorTpdu = (ErrorTpdu) ((IsoTPMessage) 
out.get(0)).getTpdu();
 
@@ -610,7 +610,7 @@ public class IsoTPProtocolTest {
 
         isoTPProtocol.decode(ctx, in, out);
 
-        assertThat("Message not decoded", out, hasSize(1));
+        assertThat("RawMessage not decoded", out, hasSize(1));
 
         ErrorTpdu errorTpdu = (ErrorTpdu) ((IsoTPMessage) 
out.get(0)).getTpdu();
 
diff --git 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/netty/events/S7StateTests.java
 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/netty/events/S7StateTests.java
deleted file mode 100644
index 1599515..0000000
--- 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/netty/events/S7StateTests.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-
-package org.apache.plc4x.java.netty.events;
-
-import org.apache.plc4x.test.FastTests;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-
-public class S7StateTests {
-
-    @Test
-    @Category(FastTests.class)
-    public void testInitialS7ConnectionEvent() {
-        S7ConnectionEvent s7event = new S7ConnectionEvent();
-
-        assertThat(s7event.getState(), equalTo(S7ConnectionState.INITIAL));
-    }
-
-    @Test
-    @Category(FastTests.class)
-    public void testS7ConnectionEvent() {
-        S7ConnectionEvent s7event = new 
S7ConnectionEvent(S7ConnectionState.SETUP_COMPLETE);
-
-        assertThat(s7event.getState(), 
equalTo(S7ConnectionState.SETUP_COMPLETE) );
-    }
-
-}
\ No newline at end of file
diff --git 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/PcapGenerator.java 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/PcapGenerator.java
index 30d00d8..cc98209 100644
--- 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/PcapGenerator.java
+++ 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/PcapGenerator.java
@@ -142,7 +142,7 @@ public class PcapGenerator {
         (byte) 0x02, (byte) 0xF0, (byte) 0x80,
         // S7 packet
         // Job header
-        (byte) 0x32, (byte) 0x01 /* Message Type [102] */,
+        (byte) 0x32, (byte) 0x01 /* RawMessage Type [102] */,
         //  Timezone
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
         (byte) 0x00, (byte) 0x0E, (byte) 0x00, (byte) 0x00,
diff --git 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcTestConnection.java
 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcTestConnection.java
index c5fc9ac..80b7da7 100644
--- 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcTestConnection.java
+++ 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcTestConnection.java
@@ -24,7 +24,7 @@ import io.netty.channel.embedded.EmbeddedChannel;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.plc4x.java.base.connection.TestChannelFactory;
-import org.apache.plc4x.java.netty.events.S7ConnectionEvent;
+import org.apache.plc4x.java.base.events.ConnectEvent;
 
 import java.io.File;
 import java.io.IOException;
@@ -66,7 +66,7 @@ public class S7PlcTestConnection extends S7PlcConnection {
         EmbeddedChannel channel = (EmbeddedChannel) getChannel();
 
         // Send an event to the pipeline telling the Protocol filters what's 
going on.
-        channel.pipeline().fireUserEventTriggered(new S7ConnectionEvent());
+        channel.pipeline().fireUserEventTriggered(new ConnectEvent());
 
         ByteBuf writtenData = channel.readOutbound();
         byte[] connectionRequest = new byte[writtenData.readableBytes()];
diff --git 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/S7ProtocolTest.java
 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/S7ProtocolTest.java
index 45c28c7..605d0dd 100644
--- 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/S7ProtocolTest.java
+++ 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/S7ProtocolTest.java
@@ -47,7 +47,7 @@ public class S7ProtocolTest extends NettyTestBase {
 
     @Before
     public void setUp() {
-        SUT = new S7Protocol((short) 1, (short) 1, (short) 1);
+        SUT = new S7Protocol((short) 1, (short) 1, (short) 256);
     }
 
     @Test
@@ -67,7 +67,7 @@ public class S7ProtocolTest extends NettyTestBase {
                     DataTransportErrorCode.OK,
                     DataTransportSize.BYTE_WORD_DWORD, new byte[]{0})
                 ))
-            )), out);
+            ), null), out);
         assertThat(out, hasSize(1));
     }
 
diff --git 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/model/messages/S7MessageTests.java
 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/model/messages/S7MessageTests.java
index 2431df0..7e87ee0 100644
--- 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/model/messages/S7MessageTests.java
+++ 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/netty/model/messages/S7MessageTests.java
@@ -33,6 +33,7 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
 import static org.hamcrest.collection.IsEmptyCollection.empty;
@@ -46,13 +47,14 @@ public class S7MessageTests {
 
     @Test
     @Category(FastTests.class)
-    public void setupCommunictionsRequestMessage() {
+    public void setupCommunicationsRequestMessage() {
         short tpduReference = 1;
         short maxAmqCaller = 4;
         short maxAmqCallee = 8;
         short pduLength = 128;
 
-        SetupCommunicationRequestMessage setupMessage = new 
SetupCommunicationRequestMessage(tpduReference, maxAmqCaller, maxAmqCallee, 
pduLength);
+        SetupCommunicationRequestMessage setupMessage = new 
SetupCommunicationRequestMessage(
+            tpduReference, maxAmqCaller, maxAmqCallee, pduLength, null);
 
         assertThat("Unexpected tpdu value", setupMessage.getTpduReference(), 
equalTo(tpduReference));
         assertThat("Unexpected message type", setupMessage.getMessageType(), 
equalTo(MessageType.JOB));
@@ -63,10 +65,9 @@ public class S7MessageTests {
     public void s7RequestMessage() {
         MessageType messageType = MessageType.USER_DATA;
         short tpduReference = 1;
-        ArrayList<S7Parameter> s7Parameters = null;
-        ArrayList<S7Payload> s7Payloads = null;
 
-        S7RequestMessage message = new S7RequestMessage(messageType, 
tpduReference, s7Parameters, s7Payloads);
+        S7RequestMessage message = new S7RequestMessage(
+            messageType, tpduReference, null, null, null);
 
         assertThat("Unexpected tpdu value", message.getTpduReference(), 
equalTo(tpduReference));
         assertThat("Unexpected message type", message.getMessageType(), 
equalTo(MessageType.USER_DATA));
@@ -79,12 +80,11 @@ public class S7MessageTests {
     public void s7ResponseMessage() {
         MessageType messageType = MessageType.USER_DATA;
         short tpduReference = 1;
-        ArrayList<S7Parameter> s7Parameters = null;
-        ArrayList<S7Payload> s7Payloads = null;
         byte errorClass = 0x1;
         byte errorCode = 0x23;
 
-        S7ResponseMessage message = new S7ResponseMessage(messageType, 
tpduReference, s7Parameters, s7Payloads, errorClass, errorCode);
+        S7ResponseMessage message = new S7ResponseMessage(
+            messageType, tpduReference, null, null, errorClass, errorCode);
 
         assertThat("Unexpected tpdu value", message.getTpduReference(), 
equalTo(tpduReference));
         assertThat("Unexpected message type", message.getMessageType(), 
equalTo(MessageType.USER_DATA));
@@ -99,10 +99,10 @@ public class S7MessageTests {
     public void s7MessageParameters() {
         MessageType messageType = MessageType.USER_DATA;
         short tpduReference = 1;
-        ArrayList<S7Parameter> s7Parameters = new ArrayList<>();
-        ArrayList<S7Payload> s7Payloads = new ArrayList<>();
+        List<S7Parameter> s7Parameters = new ArrayList<>();
+        List<S7Payload> s7Payloads = new ArrayList<>();
         ParameterType parameterType = ParameterType.READ_VAR;
-        ArrayList<VarParameterItem> parameterItems = new ArrayList<>();
+        List<VarParameterItem> parameterItems = new ArrayList<>();
         SpecificationType specificationType = 
SpecificationType.VARIABLE_SPECIFICATION;
         MemoryArea memoryArea = MemoryArea.DATA_BLOCKS;
         TransportSize transportSize = TransportSize.INT;
@@ -117,7 +117,7 @@ public class S7MessageTests {
 
         s7Parameters.add(varParameter);
 
-        S7RequestMessage message = new S7RequestMessage(messageType, 
tpduReference, s7Parameters, s7Payloads);
+        S7RequestMessage message = new S7RequestMessage(messageType, 
tpduReference, s7Parameters, s7Payloads, null);
 
         assertThat("Unexpected tpdu value", message.getTpduReference(), 
equalTo(tpduReference));
         assertThat("Unexpected message type", message.getMessageType(), 
equalTo(MessageType.USER_DATA));
@@ -134,10 +134,10 @@ public class S7MessageTests {
     public void s7MessagePayload() {
         MessageType messageType = MessageType.USER_DATA;
         short tpduReference = 1;
-        ArrayList<S7Parameter> s7Parameters = new ArrayList<>();
-        ArrayList<S7Payload> s7Payloads = new ArrayList<>();
+        List<S7Parameter> s7Parameters = new ArrayList<>();
+        List<S7Payload> s7Payloads = new ArrayList<>();
         ParameterType parameterType = ParameterType.WRITE_VAR;
-        ArrayList<VarPayloadItem> payloadItems = new ArrayList<>();
+        List<VarPayloadItem> payloadItems = new ArrayList<>();
         byte[] data = {(byte) 0x79};
         VarPayload varPayload;
 
@@ -145,13 +145,15 @@ public class S7MessageTests {
         varPayload = new VarPayload(parameterType, payloadItems);
         s7Payloads.add(varPayload);
 
-        S7RequestMessage message = new S7RequestMessage(messageType, 
tpduReference, s7Parameters, s7Payloads);
+        S7RequestMessage message = new S7RequestMessage(
+            messageType, tpduReference, s7Parameters, s7Payloads, null);
 
         assertThat("Unexpected tpdu value", message.getTpduReference(), 
equalTo(tpduReference));
         assertThat("Unexpected message type", message.getMessageType(), 
equalTo(MessageType.USER_DATA));
         assertThat("Unexpected number of payloads", message.getPayloads(), 
hasSize(1));
         assertThat("Unexpected payloads", message.getPayloads(), 
contains(varPayload));
-        assertThat("Payload missing", 
message.getPayload(VarPayload.class).get(), equalTo(varPayload));
+        assertThat("Payload missing", 
message.getPayload(VarPayload.class).isPresent(), is(true));
+        assertThat("Payload doesn't match", 
message.getPayload(VarPayload.class).get(), equalTo(varPayload));
         assertThat("Contains unexpected payload", 
message.getPayload(VarParameter.class).isPresent(), is(false)); // No other 
parameter classes
         assertThat(message.getParameters(), empty());
     }
@@ -161,10 +163,10 @@ public class S7MessageTests {
     public void s7AnyVarParameterItem() {
         MessageType messageType = MessageType.USER_DATA;
         short tpduReference = 1;
-        ArrayList<S7Parameter> s7Parameters = new ArrayList<>();
-        ArrayList<S7Payload> s7Payloads = new ArrayList<>();
+        List<S7Parameter> s7Parameters = new ArrayList<>();
+        List<S7Payload> s7Payloads = new ArrayList<>();
         ParameterType parameterType = ParameterType.READ_VAR;
-        ArrayList<VarParameterItem> parameterItems = new ArrayList<>();
+        List<VarParameterItem> parameterItems = new ArrayList<>();
         SpecificationType specificationType = 
SpecificationType.VARIABLE_SPECIFICATION;
         MemoryArea memoryArea = MemoryArea.DATA_BLOCKS;
         TransportSize transportSize = TransportSize.INT;
@@ -173,7 +175,8 @@ public class S7MessageTests {
         byte byteOffset = (byte) 0x10;
         byte bitOffset = (byte) 0x0;
 
-        S7AnyVarParameterItem parameterItem = new 
S7AnyVarParameterItem(specificationType, memoryArea, transportSize, 
numElements, dataBlock, byteOffset, bitOffset);
+        S7AnyVarParameterItem parameterItem = new S7AnyVarParameterItem(
+            specificationType, memoryArea, transportSize, numElements, 
dataBlock, byteOffset, bitOffset);
 
         assertThat("Unexpected specification type", 
parameterItem.getSpecificationType(), equalTo(specificationType));
         assertThat("Unexpected memory area", parameterItem.getMemoryArea(), 
equalTo(MemoryArea.DATA_BLOCKS));

-- 
To stop receiving notification emails like this one, please contact
cd...@apache.org.

Reply via email to