You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/01/22 09:51:52 UTC
[incubator-plc4x] branch develop updated: - Added a first test to
the cotp protocol testsuite - Aligned the cotp schema with the tpkt
protocol structure
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new db108f7 - Added a first test to the cotp protocol testsuite - Aligned the cotp schema with the tpkt protocol structure
db108f7 is described below
commit db108f778fac1771acce86a282caaa4d60062b5e
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Jan 22 10:51:47 2019 +0100
- Added a first test to the cotp protocol testsuite
- Aligned the cotp schema with the tpkt protocol structure
---
.../apache/plc4x/protocols/cotp-protocol.dfdl.xsd | 98 ++++++++++++----------
.../apache/plc4x/protocols/CotpProtocolTest.java | 31 +++++++
.../org/apache/plc4x/protocols/cotp-protocol.tdml | 93 ++++++++++++++++++++
.../org/apache/plc4x/protocols/tpkt-protocol.tdml | 2 +-
4 files changed, 181 insertions(+), 43 deletions(-)
diff --git a/protocols/src/main/dfdl/org/apache/plc4x/protocols/cotp-protocol.dfdl.xsd b/protocols/src/main/dfdl/org/apache/plc4x/protocols/cotp-protocol.dfdl.xsd
index e179712..6792c74 100644
--- a/protocols/src/main/dfdl/org/apache/plc4x/protocols/cotp-protocol.dfdl.xsd
+++ b/protocols/src/main/dfdl/org/apache/plc4x/protocols/cotp-protocol.dfdl.xsd
@@ -24,19 +24,22 @@
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:defineVariable name="messageType" type="xs:string"/>
- <dfdl:format representation="binary"
- binaryNumberRep="binary"
- byteOrder="bigEndian"
- lengthKind="implicit" lengthUnits="bytes" length="0"
- occursCountKind="implicit"
- textOutputMinLength="0"
- alignment="1" alignmentUnits="bits"
- leadingSkip="0" trailingSkip="0"
- textPadKind="none" ignoreCase="no"
- encoding="utf-8" truncateSpecifiedLengthString="no"
- initiator="" terminator=""
- sequenceKind="ordered" separator=""
- escapeSchemeRef="" initiatedContent="no"/>
+ <dfdl:defineFormat name="cotpFormat">
+ <dfdl:format representation="binary"
+ binaryNumberRep="binary"
+ byteOrder="bigEndian"
+ lengthKind="implicit" lengthUnits="bytes" length="0"
+ occursCountKind="implicit"
+ textOutputMinLength="0"
+ alignment="1" alignmentUnits="bits"
+ leadingSkip="0" trailingSkip="0"
+ textPadKind="none" ignoreCase="no"
+ encoding="utf-8" truncateSpecifiedLengthString="no"
+ initiator="" terminator=""
+ sequenceKind="ordered" separator=""
+ escapeSchemeRef="" initiatedContent="no"/>
+ </dfdl:defineFormat>
+ <dfdl:format ref="cotp:cotpFormat"/>
</xs:appinfo>
</xs:annotation>
@@ -60,27 +63,27 @@
-->
- <xs:element name="CotpTPDU">
- <xs:complexType>
- <xs:sequence>
- <!-- Length of the COTP header data -->
- <xs:element name="headerLength" type="cotp:byte"/>
- <xs:element name="type" type="cotp:byte"/>
- <xs:choice dfdl:choiceDispatchKey="{type}">
- <xs:element dfdl:choiceBranchKey="224" ref="cotp:CotpTpduConnectionRequest"/>
- <xs:element dfdl:choiceBranchKey="208" ref="cotp:CotpTpduConnectionResponse"/>
- <xs:element dfdl:choiceBranchKey="128" ref="cotp:CotpTpduDisconnectRequest"/>
- <xs:element dfdl:choiceBranchKey="192" ref="cotp:CotpTpduDisconnectResponse"/>
- <xs:element dfdl:choiceBranchKey="112" ref="cotp:CotpTpduError"/>
- <xs:element dfdl:choiceBranchKey="240" ref="cotp:CotpTpduData"/>
- </xs:choice>
- <!-- TODO: add the entire rest of the input to the user-data -->
- <xs:element name="userData" type="xs:hexBinary"
- dfdl:byteOrder="bigEndian" dfdl:lengthUnits="bytes" dfdl:lengthKind="explicit"
- dfdl:length="{totalInputSize - (2 + 1 + ../headerLength}"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
+ <xs:element name="CoTpTPDU" type="cotp:CotpMessageType"/>
+
+ <xs:complexType name="CotpMessageType">
+ <xs:sequence>
+ <!-- Length of the COTP header data -->
+ <xs:element name="headerLength" type="cotp:byte"/>
+ <xs:element name="type" type="cotp:byte"/>
+ <xs:choice dfdl:choiceDispatchKey="{type}">
+ <xs:element dfdl:choiceBranchKey="224" ref="cotp:CotpTpduConnectionRequest"/>
+ <xs:element dfdl:choiceBranchKey="208" ref="cotp:CotpTpduConnectionResponse"/>
+ <xs:element dfdl:choiceBranchKey="128" ref="cotp:CotpTpduDisconnectRequest"/>
+ <xs:element dfdl:choiceBranchKey="192" ref="cotp:CotpTpduDisconnectResponse"/>
+ <xs:element dfdl:choiceBranchKey="112" ref="cotp:CotpTpduError"/>
+ <xs:element dfdl:choiceBranchKey="240" ref="cotp:CotpTpduData"/>
+ </xs:choice>
+ <!-- TODO: add the entire rest of the input to the user-data -->
+ <xs:element name="userData" type="xs:hexBinary"
+ dfdl:byteOrder="bigEndian" dfdl:lengthUnits="bytes" dfdl:lengthKind="explicit"
+ dfdl:length="0"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:element name="CotpTpduConnectionRequest">
<xs:complexType>
@@ -88,7 +91,9 @@
<xs:element name="destinationReference" type="cotp:short"/>
<xs:element name="sourceReference" type="cotp:short"/>
<xs:element name="protocolClass" type="cotp:byte"/>
- <xs:element ref="cotp:parameters"/>
+ <xs:element ref="cotp:parameters" minOccurs="0"
+ dfdl:lengthKind="explicit" dfdl:lengthUnits="bytes" dfdl:length="{../../headerLength - 6}"
+ dfdl:occursCountKind="expression" dfdl:occursCount="{if(../../headerLength gt 6) then 1 else 0}"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -99,7 +104,9 @@
<xs:element name="destinationReference" type="cotp:short"/>
<xs:element name="sourceReference" type="cotp:short"/>
<xs:element name="protocolClass" type="cotp:byte"/>
- <xs:element ref="cotp:parameters"/>
+ <xs:element ref="cotp:parameters" minOccurs="0"
+ dfdl:lengthKind="explicit" dfdl:lengthUnits="bytes" dfdl:length="{../../headerLength - 6}"
+ dfdl:occursCountKind="expression" dfdl:occursCount="{if(../../headerLength gt 6) then 1 else 0}"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -110,7 +117,9 @@
<xs:element name="destinationReference" type="cotp:short"/>
<xs:element name="sourceReference" type="cotp:short"/>
<xs:element name="disconnectReason" type="cotp:byte"/>
- <xs:element ref="cotp:parameters"/>
+ <xs:element ref="cotp:parameters" minOccurs="0"
+ dfdl:lengthKind="explicit" dfdl:lengthUnits="bytes" dfdl:length="{../../headerLength - 6}"
+ dfdl:occursCountKind="expression" dfdl:occursCount="{if(../../headerLength gt 6) then 1 else 0}"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -120,7 +129,9 @@
<xs:sequence>
<xs:element name="destinationReference" type="cotp:short"/>
<xs:element name="sourceReference" type="cotp:short"/>
- <xs:element ref="cotp:parameters"/>
+ <xs:element ref="cotp:parameters" minOccurs="0"
+ dfdl:lengthKind="explicit" dfdl:lengthUnits="bytes" dfdl:length="{../../headerLength - 5}"
+ dfdl:occursCountKind="expression" dfdl:occursCount="{if(../../headerLength gt 5) then 1 else 0}"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -130,7 +141,9 @@
<xs:sequence>
<xs:element name="destinationReference" type="cotp:short"/>
<xs:element name="rejectCause" type="cotp:byte"/>
- <xs:element ref="cotp:parameters"/>
+ <xs:element ref="cotp:parameters" minOccurs="0"
+ dfdl:lengthKind="explicit" dfdl:lengthUnits="bytes" dfdl:length="{../../headerLength - 3}"
+ dfdl:occursCountKind="expression" dfdl:occursCount="{if(../../headerLength gt 3) then 1 else 0}"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -149,7 +162,7 @@
<xs:element name="parameters">
<xs:complexType>
<xs:sequence>
- <xs:element name="parameter">
+ <xs:element name="parameter" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="type" type="cotp:byte"/>
@@ -159,7 +172,8 @@
<xs:element dfdl:choiceBranchKey="193" ref="cotp:CotpParameterCallingTsap"/>
<xs:element dfdl:choiceBranchKey="194" ref="cotp:CotpParameterCalledTsap"/>
<xs:element dfdl:choiceBranchKey="195" ref="cotp:CotpParameterChecksum"/>
- <xs:element dfdl:choiceBranchKey="224" ref="cotp:CotpParameterDisconnectAdditionalInformation"/>
+ <xs:element dfdl:choiceBranchKey="224"
+ ref="cotp:CotpParameterDisconnectAdditionalInformation"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
@@ -205,7 +219,7 @@
<xs:sequence>
<xs:element name="data" type="xs:hexBinary"
dfdl:byteOrder="bigEndian" dfdl:lengthUnits="bytes" dfdl:lengthKind="explicit"
- dfdl:length="{../../../parameterLength}"/>
+ dfdl:length="{../../parameterLength}"/>
</xs:sequence>
</xs:complexType>
</xs:element>
diff --git a/protocols/src/test/java/org/apache/plc4x/protocols/CotpProtocolTest.java b/protocols/src/test/java/org/apache/plc4x/protocols/CotpProtocolTest.java
new file mode 100644
index 0000000..507e65c
--- /dev/null
+++ b/protocols/src/test/java/org/apache/plc4x/protocols/CotpProtocolTest.java
@@ -0,0 +1,31 @@
+/*
+ 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.protocols;
+
+/**
+ * Executes all tests for the ISO on TCP / TPKT protocol.
+ */
+public class CotpProtocolTest extends AbstractProtocolTest {
+
+ public CotpProtocolTest() {
+ super("org/apache/plc4x/protocols/cotp-protocol.tdml");
+ }
+
+}
diff --git a/protocols/src/test/resources/org/apache/plc4x/protocols/cotp-protocol.tdml b/protocols/src/test/resources/org/apache/plc4x/protocols/cotp-protocol.tdml
new file mode 100644
index 0000000..486bcb6
--- /dev/null
+++ b/protocols/src/test/resources/org/apache/plc4x/protocols/cotp-protocol.tdml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<testSuite xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:test="plc4x-protocol-test"
+ xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:cotp="http://plc4x.apache.org/cotp"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ suiteName="COTP protocol (ISOTp)"
+ description="Testsuite for the COTP protocol"
+ defaultRoundTrip="true">
+
+ <tdml:defineSchema name="cotpSchema" elementFormDefault="unqualified">
+ <!-- Import the Schema -->
+ <xs:import namespace="http://plc4x.apache.org/cotp"
+ schemaLocation="cotp-protocol.dfdl.xsd"/>
+
+ <!-- Import the format settings -->
+ <dfdl:format ref="cotp:cotpFormat"/>
+
+ <!-- Define the root element name and type -->
+ <xs:element name="cotpMessage" type="cotp:CotpMessageType"/>
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase name="minimalCotpMessage"
+ root="cotpMessage"
+ model="cotpSchema"
+ description="Minimal valid COTP Message">
+ <!-- Define the input -->
+ <tdml:document>
+ <tdml:documentPart type="byte">11D00001000200C00109C1020100C2020102</tdml:documentPart>
+ </tdml:document>
+
+ <!-- Define the expected output -->
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <test:cotpMessage>
+ <headerLength>17</headerLength>
+ <type>208</type>
+ <CotpTpduConnectionResponse>
+ <destinationReference>1</destinationReference>
+ <sourceReference>2</sourceReference>
+ <protocolClass>0</protocolClass>
+ <parameters>
+ <parameter>
+ <type>192</type>
+ <parameterLength>1</parameterLength>
+ <CotpParameterTpduSize>
+ <tpduSize>9</tpduSize>
+ </CotpParameterTpduSize>
+ </parameter>
+ <parameter>
+ <type>193</type>
+ <parameterLength>2</parameterLength>
+ <CotpParameterCallingTsap>
+ <tsapId>256</tsapId>
+ </CotpParameterCallingTsap>
+ </parameter>
+ <parameter>
+ <type>194</type>
+ <parameterLength>2</parameterLength>
+ <CotpParameterCalledTsap>
+ <tsapId>258</tsapId>
+ </CotpParameterCalledTsap>
+ </parameter>
+ </parameters>
+ </CotpTpduConnectionResponse>
+ <userData/>
+ </test:cotpMessage>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ </tdml:parserTestCase>
+
+</testSuite>
+
+
diff --git a/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml b/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml
index 1881ecb..e713497 100644
--- a/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml
+++ b/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml
@@ -23,7 +23,7 @@
xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
xmlns:tpkt="http://plc4x.apache.org/tpkt"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
- suiteName="plc4x-tpkt"
+ suiteName="TPKT protocol (ISO-on-TCP)"
description="Testsuite for the TPKT protocol"
defaultRoundTrip="true">