You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by ld...@apache.org on 2020/10/15 16:32:26 UTC
[plc4x] 01/02: Fix route request and add tests.
This is an automated email from the ASF dual-hosted git repository.
ldywicki pushed a commit to branch feature/beckhoff-discovery
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 6118f7b604daeda2eb4fffb40ff214da231a623e
Author: Ćukasz Dywicki <lu...@code-house.org>
AuthorDate: Tue Oct 13 00:17:19 2020 +0200
Fix route request and add tests.
---
.../testsuite/AdsDiscoverySerializerTest.xml | 150 +++++++++++++++++++++
.../resources/protocols/ads/ads-discovery.mspec | 25 ++--
2 files changed, 159 insertions(+), 16 deletions(-)
diff --git a/plc4j/drivers/ads/src/test/resources/testsuite/AdsDiscoverySerializerTest.xml b/plc4j/drivers/ads/src/test/resources/testsuite/AdsDiscoverySerializerTest.xml
new file mode 100644
index 0000000..a8d2dc4
--- /dev/null
+++ b/plc4j/drivers/ads/src/test/resources/testsuite/AdsDiscoverySerializerTest.xml
@@ -0,0 +1,150 @@
+<?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/parser-serializer-testsuite.xsd"
+ bigEndian="true">
+
+ <name>Beckhoff ADS/AMS Discovery</name>
+
+ <testcase>
+ <name>ADS Discovery Request from 10.10.10.10.1.1</name>
+ <raw>0366147100000000010000000a0a0a0a0101102700000000</raw>
+ <root-type>AdsDiscovery</root-type>
+ <xml>
+ <DiscoveryRequest className="org.apache.plc4x.java.ads.discovery.readwrite.DiscoveryRequest">
+ <operation>DISCOVERY</operation>
+ <direction>REQUEST</direction>
+ <amsNetId className="org.apache.plc4x.java.ads.discovery.readwrite.AmsNetId">
+ <octet1>10</octet1>
+ <octet2>10</octet2>
+ <octet3>10</octet3>
+ <octet4>10</octet4>
+ <octet5>1</octet5>
+ <octet6>1</octet6>
+ </amsNetId>
+ </DiscoveryRequest>
+ </xml>
+ </testcase>
+
+ <testcase>
+ <name>ADS Discovery Response from 192.168.2.221.1.1</name>
+ <raw>036614710000000001000080c0a802dd01011027040000000500</raw>
+ <root-type>AdsDiscovery</root-type>
+ <xml>
+ <DiscoveryResponse className="org.apache.plc4x.java.ads.discovery.readwrite.DiscoveryResponse">
+ <operation>DISCOVERY</operation>
+ <direction>RESPONSE</direction>
+ <amsNetId className="org.apache.plc4x.java.ads.discovery.readwrite.AmsNetId">
+ <octet1>192</octet1>
+ <octet2>168</octet2>
+ <octet3>2</octet3>
+ <octet4>221</octet4>
+ <octet5>1</octet5>
+ <octet6>1</octet6>
+ </amsNetId>
+ </DiscoveryResponse>
+ </xml>
+ </testcase>
+
+ <testcase>
+ <name>ADS Route Request from 10.10.10.10.1.1 via 10.10.10.10 with user='username' and pwd='password'</name>
+ <raw>0366147100000000060000000a0a0a0a01011027050000000c000c0031302e31302e31302e313000070006000a0a0a0a01010d000900757365726e616d65000200090070617373776f72640005000c0031302e31302e31302e313000</raw>
+ <root-type>AdsDiscovery</root-type>
+ <xml>
+ <RouteRequest className="org.apache.plc4x.java.ads.discovery.readwrite.RouteRequest">
+ <operation>ROUTE</operation>
+ <direction>REQUEST</direction>
+ <sender className="org.apache.plc4x.java.ads.discovery.readwrite.AmsNetId">
+ <octet1>10</octet1>
+ <octet2>10</octet2>
+ <octet3>10</octet3>
+ <octet4>10</octet4>
+ <octet5>1</octet5>
+ <octet6>1</octet6>
+ </sender>
+ <address className="org.apache.plc4x.java.ads.discovery.readwrite.AmsMagicString">
+ <text>MTAuMTAuMTAuMTA=</text>
+ </address>
+ <target className="org.apache.plc4x.java.ads.discovery.readwrite.AmsNetId">
+ <octet1>10</octet1>
+ <octet2>10</octet2>
+ <octet3>10</octet3>
+ <octet4>10</octet4>
+ <octet5>1</octet5>
+ <octet6>1</octet6>
+ </target>
+ <username className="org.apache.plc4x.java.ads.discovery.readwrite.AmsMagicString">
+ <text>dXNlcm5hbWU=</text>
+ </username>
+ <password className="org.apache.plc4x.java.ads.discovery.readwrite.AmsMagicString">
+ <text>cGFzc3dvcmQ=</text>
+ </password>
+ <routeName className="org.apache.plc4x.java.ads.discovery.readwrite.AmsMagicString">
+ <text>MTAuMTAuMTAuMTA=</text>
+ </routeName>
+ </RouteRequest>
+ </xml>
+ </testcase>
+
+ <testcase>
+ <name>ADS Route Response with Success status</name>
+ <raw>036614710000000006000080c0a802dd01011027010000000100040000000000</raw>
+ <root-type>AdsDiscovery</root-type>
+ <xml>
+ <RouteResponse className="org.apache.plc4x.java.ads.discovery.readwrite.RouteResponse">
+ <operation>ROUTE</operation>
+ <direction>RESPONSE</direction>
+ <amsNetId className="org.apache.plc4x.java.ads.discovery.readwrite.AmsNetId">
+ <octet1>192</octet1>
+ <octet2>168</octet2>
+ <octet3>2</octet3>
+ <octet4>221</octet4>
+ <octet5>1</octet5>
+ <octet6>1</octet6>
+ </amsNetId>
+ <status>SUCCESS</status>
+ </RouteResponse>
+
+ </xml>
+ </testcase>
+
+ <testcase>
+ <name>ADS Route Response with Failure status</name>
+ <raw>036614710000000006000080c0a802dd01011027010000000100000407000000</raw>
+ <root-type>AdsDiscovery</root-type>
+ <xml>
+ <RouteResponse className="org.apache.plc4x.java.ads.discovery.readwrite.RouteResponse">
+ <operation>ROUTE</operation>
+ <direction>RESPONSE</direction>
+ <amsNetId className="org.apache.plc4x.java.ads.discovery.readwrite.AmsNetId">
+ <octet1>192</octet1>
+ <octet2>168</octet2>
+ <octet3>2</octet3>
+ <octet4>221</octet4>
+ <octet5>1</octet5>
+ <octet6>1</octet6>
+ </amsNetId>
+ <status>FAILURE</status>
+ </RouteResponse>
+ </xml>
+ </testcase>
+
+
+
+</test:testsuite>
\ No newline at end of file
diff --git a/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec b/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
index 3dabd91..74506ea 100644
--- a/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
+++ b/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
@@ -53,16 +53,17 @@
[simple AmsNetId 'sender']
[reserved uint 16 '0x1027']
[reserved uint 16 '0x0500']
- [reserved uint 24 '0x0C00']
- [simple AmsMagicString 'ip' ]
- [reserved uint 16 '0x0007']
+ [reserved uint 24 '0x000C']
+ [simple AmsMagicString 'address' ]
+ [reserved uint 16 '0x0700']
[implicit uint 8 'amsSize' 'target.lengthInBytes']
+ [const uint 8 'targetPrefix' '0x00']
[simple AmsNetId 'target']
- [const uint 16 'usernamePrefix' '0x000D']
+ [const uint 8 'usernamePrefix' '0x0D']
[simple AmsMagicString 'username']
- [const uint 16 'passwordPrefix' '0x0002']
+ [const uint 8 'passwordPrefix' '0x02']
[simple AmsMagicString 'password']
- [const uint 16 'routePrefix' '0x0005']
+ [const uint 8 'routePrefix' '0x05']
[simple AmsMagicString 'routeName']
]
@@ -83,20 +84,12 @@
]
[type 'AmsMagicString'
- [implicit uint 8 'len' 'COUNT(text)']
+ [implicit uint 16 'len' 'COUNT(text) + 1']
[reserved uint 8 '0x00']
- [array int 8 'text' COUNT 'len']
+ [array int 8 'text' COUNT 'len - 1']
[reserved uint 8 '0x00']
]
-[type 'IPv4Address'
- [simple uint 8 'octet1' ]
- [simple uint 8 'octet2' ]
- [simple uint 8 'octet3' ]
- [simple uint 8 'octet4' ]
-]
-
-
[type 'AmsNetId'
[simple uint 8 'octet1' ]
[simple uint 8 'octet2' ]