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/plc4x.git
commit b0fe0380cd8139a79b610f6e2123536ee1de15e0 Author: Christofer Dutz <[email protected]> AuthorDate: Tue Aug 27 10:33:41 2019 +0200 - First steps to implementing the Allen Bradley ETH protocol. --- .../protocol/test/ProtocolTestsuiteRunner.java | 5 + protocols/ab-eth/pom.xml | 43 ++++++ .../apache/plc4x/protocol/abeth/ABETHProtocol.java | 46 ++++++ ...e.plc4x.plugins.codegenerator.protocol.Protocol | 19 +++ .../main/resources/protocols/abeth/ab-eth.mspec | 85 +++++++++++ protocols/pom.xml | 3 +- sandbox/pom.xml | 1 + sandbox/test-java-ab-eth-driver/pom.xml | 92 ++++++++++++ .../org/apache/plc4x/protocol/abeth/AbEthTest.java | 30 ++++ .../test/resources/testsuite/AbEthTestsuite.xml | 163 +++++++++++++++++++++ 10 files changed, 486 insertions(+), 1 deletion(-) diff --git a/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java b/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java index 50dbc41..7e1f299 100644 --- a/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java +++ b/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java @@ -109,11 +109,16 @@ public class ProtocolTestsuiteRunner { String xmlString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(msg); Diff diff = DiffBuilder.compare(referenceXml).withTest(xmlString).ignoreWhitespace().build(); if(diff.hasDifferences()) { + System.out.println(xmlString); throw new ProtocolTestsuiteException("Differences were found after parsing.\n" + diff.toString()); } WriteBuffer writeBuffer = new WriteBuffer(((SizeAware) msg).getLengthInBytes(), testSuite.isLittleEndian()); messageIO.serialize(writeBuffer, msg); byte[] data = writeBuffer.getData(); + if(testcase.getRaw().length != data.length) { + LOGGER.info("Expected a byte array with a length of " + testcase.getRaw().length + + " but got one with " + data.length); + } if(!Arrays.equals(testcase.getRaw(), data)) { int i; for(i = 0; i < data.length; i++) { diff --git a/protocols/ab-eth/pom.xml b/protocols/ab-eth/pom.xml new file mode 100644 index 0000000..deafab0 --- /dev/null +++ b/protocols/ab-eth/pom.xml @@ -0,0 +1,43 @@ +<?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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.plc4x</groupId> + <artifactId>plc4x-protocols</artifactId> + <version>0.5.0-SNAPSHOT</version> + </parent> + + <artifactId>plc4x-protocols-ab-eth</artifactId> + + <name>Protocols: AB-ETH</name> + <description>Base protocol specifications for the AB ETH protocol</description> + + <dependencies> + <dependency> + <groupId>org.apache.plc4x</groupId> + <artifactId>plc4x-build-utils-protocol-base-mspec</artifactId> + <version>0.5.0-SNAPSHOT</version> + </dependency> + </dependencies> + +</project> \ No newline at end of file diff --git a/protocols/ab-eth/src/main/java/org/apache/plc4x/protocol/abeth/ABETHProtocol.java b/protocols/ab-eth/src/main/java/org/apache/plc4x/protocol/abeth/ABETHProtocol.java new file mode 100644 index 0000000..5f72f06 --- /dev/null +++ b/protocols/ab-eth/src/main/java/org/apache/plc4x/protocol/abeth/ABETHProtocol.java @@ -0,0 +1,46 @@ +/* + * 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.protocol.abeth; + +import org.apache.plc4x.plugins.codegenerator.language.mspec.parser.MessageFormatParser; +import org.apache.plc4x.plugins.codegenerator.protocol.Protocol; +import org.apache.plc4x.plugins.codegenerator.types.definitions.ComplexTypeDefinition; +import org.apache.plc4x.plugins.codegenerator.types.exceptions.GenerationException; + +import java.io.InputStream; +import java.util.Map; + +public class ABETHProtocol implements Protocol { + + @Override + public String getName() { + return "ab-eth"; + } + + @Override + public Map<String, ComplexTypeDefinition> getTypeDefinitions() throws GenerationException { + InputStream schemaInputStream = ABETHProtocol.class.getResourceAsStream("/protocols/abeth/ab-eth.mspec"); + if(schemaInputStream == null) { + throw new GenerationException("Error loading message-format schema for protocol '" + getName() + "'"); + } + return new MessageFormatParser().parse(schemaInputStream); + } + +} diff --git a/protocols/ab-eth/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol b/protocols/ab-eth/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol new file mode 100644 index 0000000..6f20f62 --- /dev/null +++ b/protocols/ab-eth/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol @@ -0,0 +1,19 @@ +# +# 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. +# +org.apache.plc4x.protocol.abeth.ABETHProtocol \ No newline at end of file diff --git a/protocols/ab-eth/src/main/resources/protocols/abeth/ab-eth.mspec b/protocols/ab-eth/src/main/resources/protocols/abeth/ab-eth.mspec new file mode 100644 index 0000000..a279bdb --- /dev/null +++ b/protocols/ab-eth/src/main/resources/protocols/abeth/ab-eth.mspec @@ -0,0 +1,85 @@ +// +// 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. +// + +[discriminatedType 'CIPEncapsulationPacket' + [discriminator uint 16 'commandType'] + [implicit uint 16 'len' 'lengthInBytes - 28'] + [simple uint 32 'sessionHandle'] + [simple uint 32 'status'] + [array uint 8 'senderContext' count '8'] + [simple uint 32 'options'] + [reserved uint 32 '0x00000000'] + [typeSwitch 'commandType' + ['0x0101' CIPEncapsulationConnectionRequest + ] + ['0x0201' CIPEncapsulationConnectionResponse + ] + ['0x0107' CIPEncapsulationReadRequest + [simple DF1RequestMessage 'request'] + ] + ['0x0207' CIPEncapsulationReadResponse [uint 16 'len'] + [simple DF1ResponseMessage 'response' ['len']] + ] + ] +] + +[discriminatedType 'DF1RequestMessage' + [simple uint 8 'destinationAddress'] + [simple uint 8 'sourceAddress'] + [reserved uint 16 '0x0000'] + [discriminator uint 8 'commandCode'] + [simple uint 8 'status'] + [simple uint 16 'transactionCounter'] + [typeSwitch 'commandCode' + ['0x0F' DF1CommandRequestMessage + [simple DF1RequestCommand 'command'] + ] + ] +] + +[discriminatedType 'DF1ResponseMessage' [uint 16 'payloadLength'] + [reserved uint 8 '0x00'] + [simple uint 8 'destinationAddress'] + [simple uint 8 'sourceAddress'] + [reserved uint 8 '0x00'] + [discriminator uint 8 'commandCode'] + [simple uint 8 'status'] + [simple uint 16 'transactionCounter'] + [typeSwitch 'commandCode' + ['0x4F' DF1CommandResponseMessageProtectedTypedLogicalRead [uint 8 'status'] + [array uint 8 'data' length 'payloadLength - 8'] + [optional uint 8 'extendedStatus' 'status != 0'] + ] + ] +] + +[discriminatedType 'DF1RequestCommand' + [discriminator uint 8 'functionCode'] + [typeSwitch 'functionCode' + ['0xA2' DF1RequestProtectedTypedLogicalRead + [simple uint 8 'byteSize'] + [simple uint 8 'fileNumber'] + [simple uint 8 'fileType'] + [simple uint 8 'elementNumber'] + [simple uint 8 'subElementNumber'] + ] + ] +] + + diff --git a/protocols/pom.xml b/protocols/pom.xml index 8f59a67..1022cea 100644 --- a/protocols/pom.xml +++ b/protocols/pom.xml @@ -190,9 +190,10 @@ </build> <modules> + <module>ab-eth</module> + <module>df1</module> <module>knxnetip</module> <module>s7</module> - <module>df1</module> </modules> <profiles> diff --git a/sandbox/pom.xml b/sandbox/pom.xml index f4f5422..b3dc0ab 100644 --- a/sandbox/pom.xml +++ b/sandbox/pom.xml @@ -36,6 +36,7 @@ <modules> <module>code-gen</module> + <module>test-java-ab-eth-driver</module> <module>test-java-knxnetip-driver</module> <module>test-java-s7-driver</module> <module>test-java-passive-s7-driver</module> diff --git a/sandbox/test-java-ab-eth-driver/pom.xml b/sandbox/test-java-ab-eth-driver/pom.xml new file mode 100644 index 0000000..136aeae --- /dev/null +++ b/sandbox/test-java-ab-eth-driver/pom.xml @@ -0,0 +1,92 @@ +<?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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.plc4x.sandbox</groupId> + <artifactId>plc4x-sandbox</artifactId> + <version>0.5.0-SNAPSHOT</version> + </parent> + + <artifactId>test-java-ab-eth-driver</artifactId> + + <name>Sandbox: Test Generated AB-ETH Driver</name> + + <build> + <plugins> + <plugin> + <groupId>org.apache.plc4x.plugins</groupId> + <artifactId>plc4x-maven-plugin</artifactId> + <executions> + <execution> + <id>test</id> + <phase>generate-sources</phase> + <goals> + <goal>generate-driver</goal> + </goals> + <configuration> + <protocolName>ab-eth</protocolName> + <languageName>java</languageName> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.apache.plc4x</groupId> + <artifactId>plc4j-utils-driver-base-java</artifactId> + <version>0.5.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-annotations</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.plc4x</groupId> + <artifactId>plc4j-utils-protocol-test-utils</artifactId> + <version>0.5.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.plc4x</groupId> + <artifactId>plc4x-build-utils-language-java</artifactId> + <version>0.5.0-SNAPSHOT</version> + <!-- Scope is 'provided' as this way it's not shipped with the driver --> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.plc4x</groupId> + <artifactId>plc4x-protocols-ab-eth</artifactId> + <version>0.5.0-SNAPSHOT</version> + <!-- Scope is 'provided' as this way it's not shipped with the driver --> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> diff --git a/sandbox/test-java-ab-eth-driver/src/test/java/org/apache/plc4x/protocol/abeth/AbEthTest.java b/sandbox/test-java-ab-eth-driver/src/test/java/org/apache/plc4x/protocol/abeth/AbEthTest.java new file mode 100644 index 0000000..39b275f --- /dev/null +++ b/sandbox/test-java-ab-eth-driver/src/test/java/org/apache/plc4x/protocol/abeth/AbEthTest.java @@ -0,0 +1,30 @@ +/* + 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.protocol.abeth; + +import org.apache.plc4x.protocol.test.ProtocolTestsuiteRunner; + +public class AbEthTest extends ProtocolTestsuiteRunner { + + public AbEthTest() { + super("/testsuite/AbEthTestsuite.xml"); + } + +} diff --git a/sandbox/test-java-ab-eth-driver/src/test/resources/testsuite/AbEthTestsuite.xml b/sandbox/test-java-ab-eth-driver/src/test/resources/testsuite/AbEthTestsuite.xml new file mode 100644 index 0000000..b9b13f7 --- /dev/null +++ b/sandbox/test-java-ab-eth-driver/src/test/resources/testsuite/AbEthTestsuite.xml @@ -0,0 +1,163 @@ +<?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. + --> +<test:testsuite xmlns:test="https://plc4x.apache.org/schemas/testsuite.xsd" + bigEndian="false"> + + <name>Allen-Bradley ETH</name> + + <testcase> + <name>Connection Request</name> + <raw>01010000000000000000000000040005000000000000000000000000</raw> + <root-type>CIPEncapsulationPacket</root-type> + <xml> + <CIPEncapsulationConnectionRequest className="org.apache.plc4x.java.abeth.CIPEncapsulationConnectionRequest"> + <sessionHandle>0</sessionHandle> + <status>0</status> + <senderContext> + <senderContext>0</senderContext> + <senderContext>4</senderContext> + <senderContext>0</senderContext> + <senderContext>5</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + </senderContext> + <options>0</options> + </CIPEncapsulationConnectionRequest> + </xml> + </testcase> + + <testcase> + <name>Connection Response</name> + <raw>02010000000003320000000000040005000000000000000000000000</raw> + <root-type>CIPEncapsulationPacket</root-type> + <xml> + <CIPEncapsulationConnectionResponse className="org.apache.plc4x.java.abeth.CIPEncapsulationConnectionResponse"> + <sessionHandle>818</sessionHandle> + <status>0</status> + <senderContext> + <senderContext>0</senderContext> + <senderContext>4</senderContext> + <senderContext>0</senderContext> + <senderContext>5</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + </senderContext> + <options>0</options> + </CIPEncapsulationConnectionResponse> + </xml> + </testcase> + + <testcase> + <name>Protected Typed Logical Read Request</name> + <raw>0107000e000003320000000040000000000000000000000000000000080500000f000401a21800640000</raw> + <root-type>CIPEncapsulationPacket</root-type> + <xml> + <CIPEncapsulationReadRequest className="org.apache.plc4x.java.abeth.CIPEncapsulationReadRequest"> + <sessionHandle>818</sessionHandle> + <status>0</status> + <senderContext> + <senderContext>64</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + </senderContext> + <options>0</options> + <request className="org.apache.plc4x.java.abeth.DF1CommandRequestMessage"> + <destinationAddress>8</destinationAddress> + <sourceAddress>5</sourceAddress> + <status>0</status> + <transactionCounter>1025</transactionCounter> + <command className="org.apache.plc4x.java.abeth.DF1RequestProtectedTypedLogicalRead"> + <byteSize>24</byteSize> + <fileNumber>0</fileNumber> + <fileType>100</fileType> + <elementNumber>0</elementNumber> + <subElementNumber>0</subElementNumber> + </command> + </request> + </CIPEncapsulationReadRequest> + </xml> + </testcase> + + <testcase> + <name>Protected Typed Logical Read Response</name> + <raw>02070020000003320000000040000000000000000000000000000000000508004f000401910101000900040405001f02010003000404050000024000</raw> + <root-type>CIPEncapsulationPacket</root-type> + <xml> + <CIPEncapsulationReadResponse className="org.apache.plc4x.java.abeth.CIPEncapsulationReadResponse"> + <sessionHandle>818</sessionHandle> + <status>0</status> + <senderContext> + <senderContext>64</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + <senderContext>0</senderContext> + </senderContext> + <options>0</options> + <response className="org.apache.plc4x.java.abeth.DF1CommandResponseMessageProtectedTypedLogicalRead"> + <destinationAddress>5</destinationAddress> + <sourceAddress>8</sourceAddress> + <status>0</status> + <transactionCounter>1025</transactionCounter> + <data> + <data>145</data> + <data>1</data> + <data>1</data> + <data>0</data> + <data>9</data> + <data>0</data> + <data>4</data> + <data>4</data> + <data>5</data> + <data>0</data> + <data>31</data> + <data>2</data> + <data>1</data> + <data>0</data> + <data>3</data> + <data>0</data> + <data>4</data> + <data>4</data> + <data>5</data> + <data>0</data> + <data>0</data> + <data>2</data> + <data>64</data> + <data>0</data> + </data> + <extendedStatus/> + </response> + </CIPEncapsulationReadResponse> + </xml> + </testcase> + +</test:testsuite> \ No newline at end of file
