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 2018/01/24 20:09:10 UTC
[incubator-plc4x] branch feature/PLC4X-18--raw-sockets updated
(df791fd -> e746e70)
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a change to branch feature/PLC4X-18--raw-sockets
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git.
from df791fd Added apache header
add a2a4d84 Migrate PlcDriverManagerTest to assertj
add d4fdb5b Java-Gernerify APIs
add 3d65ec7 Merge branch 'master' into refactoring/java_generify
add 51075d9 added Tests for Plc4XS7Protocol
add 88a32d3 added basic test implementation for S7Protocol
add 71fecb8 added unchecked variants of plc requests.
add d7730f0 Merge branch 'master' into refactoring/java_generify
add cead5c1 split plcRequest into single and bulk plc request
add 1eb41f8 added a checked variant of bulk requests/responses.
add 6badd3b added a couple of default methods to the interfaces
add cfe70db Introduced Optional for single elements
add 7c78c45 added missing overload methods
add fd66d1d added request build for convenient request creation.
add 99fb948 Merge branch 'master' into refactoring/java_generify
add 1c71c7b moved specific messages into a sub package to declutter the API
add 80fa0ae fix tests
add b3869eb fixed firstType builder bug; added getValue to bulk; added getValue tests
add 6a3da68 comment surefire back in
add b86dc42 fixed one more builder bug
add 85fb9cb may need a extra byte if not on byte boundry
add 06fd936 Coverage shows this should be Byte not Byte[]
add 9e04f92 Add support for Stings
add ab2c1d8 multiple string is a little broken add TODOs so don't forget
add 5378c4a support for multiple strings
add 3e19b41 chars not bytes and add another check to stop running off end of buffer
add 2267211 Merge branch 'master' into refactoring/java_generify
add d6497dc link response into request to retrieve a typed response.
add 675a108 fixed test by cleaning up the generics.
add 76f1d0b move getValue() method up to parent
add b1aa871 added indicator methods to reponses.
add 6402596 minor generic adjustments
add fc694ac small cleanup on api
add 1361a0a use list instead of array and get rid of some more suppress warnings
add 6fbc8de make single requests/responses extend from checked BulkResponse
add 3ce27ea fixed edgent test
add a643675 deprecated BulkPlc*
add 4078c58 get rid of BulkPlc*
add 3615ee4 Rename CheckedPlc* to TypeSafePlc*
add c28c5ee Deprecated SinglePlc*
add c9b36e9 get rid of SinglePlc*
add 9504a16 implement actual typesafety into TypeSafePlc*
add fd31bad polished builders and code cleanup
add be5fec1 added missing Objects.requireNonNull assertion
add ea71d93 small pre-merge fixes.
add 9b46c5e Merge branch 'master' into assertj_migration
add 9dc57dc get response from request as completable future as at access time the response might not be there yet.
add af2ca39 refactored common code of request and responses into abstract classes
add 8b89e9c added missing licences header
add b10c70d rename generic from REQUEST_TYPE to REQUEST_ITEM
add 9f6fc95 refactored much common code to a abstract class
add 1426495 disable get response tests for now due to timing issues
add 7ecbdd5 added some more top level boundaries und requests and responses
add f091908 implement double null check to avoid unnecessary waits
add 4a2d257 see https://www.ibm.com/developerworks/java/library/j-jtp05236/index.html?ca=drs-#2.1
add 0eafa62 unneeded import
add 3e9e12a use isEmpty()
add c4595a4 right order
add 4b94b85 use isEmpty()
add a0ee2e8 use isEmpty()
add 023282f add @Overrides
add 5ea1720 unneeded import
add f079d20 add @Overrides
add 52d1979 add @Overrides
add 9a62440 add private constructors to utility classes
add 5744cc3 use a checked List to avoid injection of wrong types.
add 113080f use Optional and get rid of unchecked warnings
add c9ed5f1 remove unused import
add 8a8968a small fixes: - added SafeVarargs where required - remove unnecessary SuppressWarnings - make build methods final - fixed typos
add bf41fd4 don't use optional::get without checking
add 7b771a1 added todo about declarative pipeline
add 8005b55 remove warning about unused cast
add 3bd16f5 Small improvements on IsoTPProtocolTest - get rid of Mock implementation in favor of Mockito DeepStubs - remove duplicated code by making common used items members - apply builder pattern to buffer
add 5886538 fixed timing issues on get responseItem by signaling after item has been set not before.
add 36d151f Put the await into a while loop to handle "spurious wakeup"
add 80b2ba5 no need to wrap PlcException in RuntimeException as camel allows Producer constructors to throw exceptions
add 8940cb4 log expection on connection close failure
add 37afedb transport the inner exception in PlcConnectionException
add 5dd6ab5 use parseInt instead of valueOf
add e3a7d29 use specific exceptions
add b8c0b06 fix wrong scope. Meant to be optional true
add e596961 fixed wrong default reporting path as this variable already contains target
add 38e344e fix missing coverage by switching to junit5 and make test compatible
add e1d1bb8 added some test coverage to camel-component
add 97070a1 added missing apache header
add 91df3f7 remove unused getters
add 909fd38 added some branch coverage on plc4x producer
add a8708c3 added tests for default methods
add d322d6e Added tests for (Typed)Request/Repsonses
add ef8c3d4 added one missing testcase for typed read response
add e9d0fab no need for empty constructor
add d88234a refactor to reduce complexity
add 3bf2fc7 add NOTICE file for source
add 14952b8 add incubating disclaimer
add 0e3decf wrap DISCLAIMER
add 8d1f2a5 Remove response in RequestItem
add 03239bd remove unneeded imports
add c6c50b1 fix logging so no side effects
add 79e26cd custom Tpdu message - use in test but may also be useful
add 74f4140 added unknown tdpu code
add 716ac61 fix logging so no side effects
add eb07a1b add a couple of bad path tests for unsupported tpdu codes
add 9fad062 now UNKNOWN rather than null adn null can give rise to NPEs
add 1c831ad fix logging so no side effects
add 8261951 remove unnecessary locks
add bf90e53 remove unnecessary imports
add 3b0073f Added missing Apache header
add 1149fd4 Added links to the images of the projects we're planning on providing adapters for
add 1e589ea - Some cleaning up in the site and the site-menu - Added some initial pages for important content
add 71be454 - Provide some initial content for the industry 4.0 landing page.
add 548cfd4 - Added some more content
new 75063b2 Merge branches 'feature/PLC4X-18--raw-sockets' and 'master' of https://gitbox.apache.org/repos/asf/incubator-plc4x into feature/PLC4X-18--raw-sockets
new e746e70 - Test implementation of a program sending raw icmp ip packets (ping)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
DISCLAIMER | 7 +
Jenkinsfile | 1 +
NOTICE | 8 +
integrations/apache-camel/pom.xml | 29 +-
.../java/org/apache/plc4x/camel/Constants.java | 6 +-
.../java/org/apache/plc4x/camel/PLC4XEndpoint.java | 10 +-
.../java/org/apache/plc4x/camel/PLC4XProducer.java | 34 +-
.../java/org/apache/plc4x/camel/ConstantsTest.java | 25 +-
.../org/apache/plc4x/camel/PLC4XComponentTest.java | 25 +-
.../org/apache/plc4x/camel/PLC4XEndpointTest.java | 35 +-
.../org/apache/plc4x/camel/PLC4XProducerTest.java | 111 +++
.../apache/plc4x/edgent/PlcConnectionAdapter.java | 258 ++---
.../java/org/apache/plc4x/edgent/PlcFunctions.java | 4 +
.../plc4x/edgent/PlcConnectionAdapterTest.java | 1030 ++++++++++----------
.../org/apache/plc4x/edgent/PlcFunctionsTest.java | 14 +-
.../apache/plc4x/edgent/mock/MockConnection.java | 123 ++-
.../plc4x/java/api/connection/PlcReader.java | 17 +-
.../plc4x/java/api/connection/PlcWriter.java | 18 +-
.../plc4x/java/api/messages/PlcReadRequest.java | 78 +-
.../plc4x/java/api/messages/PlcReadResponse.java | 23 +-
.../apache/plc4x/java/api/messages/PlcRequest.java | 72 +-
.../plc4x/java/api/messages/PlcResponse.java | 54 +-
.../plc4x/java/api/messages/PlcWriteRequest.java | 82 +-
.../plc4x/java/api/messages/PlcWriteResponse.java | 23 +-
.../java/api/messages/items/ReadRequestItem.java | 24 +-
.../java/api/messages/items/ReadResponseItem.java | 23 +-
.../{ReadRequestItem.java => RequestItem.java} | 21 +-
.../{WriteResponseItem.java => ResponseItem.java} | 9 +-
.../java/api/messages/items/WriteRequestItem.java | 37 +-
.../java/api/messages/items/WriteResponseItem.java | 19 +-
.../messages/specific/TypeSafePlcReadRequest.java | 86 ++
.../messages/specific/TypeSafePlcReadResponse.java | 83 ++
.../messages/specific/TypeSafePlcWriteRequest.java | 82 ++
.../specific/TypeSafePlcWriteResponse.java | 59 ++
.../plc4x/java/api/connection/PlcReaderTest.java | 36 +
.../plc4x/java/api/connection/PlcWriterTest.java | 36 +
.../plc4x/java/api/messages/APIMessageTests.java | 175 ++--
.../java/api/messages/PlcReadRequestTest.java | 88 ++
.../java/api/messages/PlcReadResponseTest.java | 45 +
.../plc4x/java/api/messages/PlcRequestTest.java | 86 ++
.../plc4x/java/api/messages/PlcResponseTest.java | 87 ++
.../java/api/messages/PlcWriteRequestTest.java | 86 ++
.../java/api/messages/PlcWriteResponseTest.java | 45 +
.../specific/TypeSafePlcReadRequestTest.java | 77 ++
.../specific/TypeSafePlcReadResponseTest.java | 76 ++
.../specific/TypeSafePlcWriteRequestTest.java | 77 ++
.../specific/TypeSafePlcWriteResponseTest.java | 62 ++
.../org/apache/plc4x/java/PlcDriverManager.java | 2 +-
.../apache/plc4x/java/PlcDriverManagerTest.java | 52 +-
plc4j/pom.xml | 2 +-
.../apache/plc4x/java/s7/utils/PcapGenerator.java | 22 +-
.../java/isoontcp/netty/IsoOnTcpProtocol.java | 4 +-
.../plc4x/java/isotp/netty/IsoTPProtocol.java | 45 +-
...{DisconnectConfirmTpdu.java => CustomTpdu.java} | 6 +-
.../plc4x/java/isotp/netty/model/tpdus/Tpdu.java | 7 +-
.../java/isotp/netty/model/types/TpduCode.java | 8 +-
.../java/org/apache/plc4x/java/s7/S7PlcDriver.java | 4 +-
.../plc4x/java/s7/connection/S7PlcConnection.java | 6 +-
.../plc4x/java/s7/netty/Plc4XS7Protocol.java | 460 +++++----
.../org/apache/plc4x/java/s7/netty/S7Protocol.java | 356 ++++---
.../java/s7/netty/model/messages/S7Message.java | 13 +-
.../netty/model/params/CpuServicesParameter.java | 4 -
.../netty/model/types/DataTransportErrorCode.java | 9 +-
.../java/s7/netty/model/types/ParameterType.java | 7 +-
.../plc4x/java/isotp/netty/IsoTPProtocolTest.java | 460 ++++-----
.../apache/plc4x/java/isotp/netty/MockChannel.java | 243 -----
.../isotp/netty/MockChannelHandlerContext.java | 234 -----
.../java/isotp/netty/MockChannelPipeline.java | 354 -------
.../isotp/netty/model/tpdus/IsotpModelTests.java | 8 +-
.../isotp/netty/model/types/IsotpTypeTests.java | 5 +-
.../apache/plc4x/java/s7/S7PlcReaderSample.java | 15 +-
.../org/apache/plc4x/java/s7/S7PlcScanner.java | 20 +-
.../org/apache/plc4x/java/s7/S7PlcTestConsole.java | 16 +-
.../apache/plc4x/java/s7/S7PlcWriterSample.java | 13 +-
.../plc4x/java/s7/netty/Plc4XS7ProtocolTest.java | 27 +-
.../s7/netty/model/messages/S7MessageTests.java | 8 +-
.../org/apache/plc4x/java/utils/PcapngUtils.java | 4 +
plc4j/utils/raw-sockets/pom.xml | 11 +-
plc4j/utils/raw-sockets/src/test/java/Test.java | 307 ++++++
pom.xml | 4 +-
.../{development => developers}/building.adoc | 2 +-
.../asciidoc/{development => developers}/ci.adoc | 9 +
.../{development => developers}/contributing.adoc | 0
.../contributing.adoc => developers/issues.adoc} | 3 +-
.../contributing.adoc => developers/sonar.adoc} | 3 +-
.../{development => developers}/website.adoc | 0
.../contributing.adoc => developers/wiki.adoc} | 3 +-
src/site/asciidoc/index.adoc | 4 +-
.../ci.adoc => users/gettingstarted.adoc} | 4 +-
src/site/asciidoc/users/industry40.adoc | 124 +++
src/site/site.xml | 23 +-
91 files changed, 3859 insertions(+), 2558 deletions(-)
create mode 100644 DISCLAIMER
create mode 100644 NOTICE
copy plc4j/api/src/test/java/org/apache/plc4x/java/api/authentication/PlcUsernamePasswordAuthenticationTest.java => integrations/apache-camel/src/test/java/org/apache/plc4x/camel/ConstantsTest.java (58%)
copy plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/netty/events/S7StateTests.java => integrations/apache-camel/src/test/java/org/apache/plc4x/camel/PLC4XEndpointTest.java (53%)
create mode 100644 integrations/apache-camel/src/test/java/org/apache/plc4x/camel/PLC4XProducerTest.java
copy plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/{ReadRequestItem.java => RequestItem.java} (70%)
copy plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/{WriteResponseItem.java => ResponseItem.java} (82%)
create mode 100644 plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadRequest.java
create mode 100644 plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
create mode 100644 plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java
create mode 100644 plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteResponse.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/connection/PlcReaderTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/connection/PlcWriterTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcReadRequestTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcReadResponseTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcRequestTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcResponseTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcWriteRequestTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/PlcWriteResponseTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadRequestTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponseTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequestTest.java
create mode 100644 plc4j/api/src/test/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteResponseTest.java
copy plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/{DisconnectConfirmTpdu.java => CustomTpdu.java} (77%)
delete mode 100644 plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/MockChannel.java
delete mode 100644 plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/MockChannelHandlerContext.java
delete mode 100644 plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/MockChannelPipeline.java
create mode 100644 plc4j/utils/raw-sockets/src/test/java/Test.java
rename src/site/asciidoc/{development => developers}/building.adoc (98%)
copy src/site/asciidoc/{development => developers}/ci.adoc (62%)
copy src/site/asciidoc/{development => developers}/contributing.adoc (100%)
copy src/site/asciidoc/{development/contributing.adoc => developers/issues.adoc} (92%)
copy src/site/asciidoc/{development/contributing.adoc => developers/sonar.adoc} (92%)
rename src/site/asciidoc/{development => developers}/website.adoc (100%)
rename src/site/asciidoc/{development/contributing.adoc => developers/wiki.adoc} (93%)
rename src/site/asciidoc/{development/ci.adoc => users/gettingstarted.adoc} (96%)
create mode 100644 src/site/asciidoc/users/industry40.adoc
--
To stop receiving notification emails like this one, please contact
cdutz@apache.org.
[incubator-plc4x] 02/02: - Test implementation of a program sending
raw icmp ip packets (ping)
Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/PLC4X-18--raw-sockets
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit e746e70d21196a45aff3cc8a0bbfa09d363632f1
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Jan 24 21:09:02 2018 +0100
- Test implementation of a program sending raw icmp ip packets (ping)
---
plc4j/pom.xml | 2 +-
plc4j/utils/raw-sockets/pom.xml | 11 +-
plc4j/utils/raw-sockets/src/test/java/Test.java | 307 ++++++++++++++++++++++++
3 files changed, 316 insertions(+), 4 deletions(-)
diff --git a/plc4j/pom.xml b/plc4j/pom.xml
index 40e4c07..cb8d750 100644
--- a/plc4j/pom.xml
+++ b/plc4j/pom.xml
@@ -39,7 +39,7 @@
<module>api</module>
<module>core</module>
<module>protocols</module>
- <!--module>utils</module-->
+ <module>utils</module>
</modules>
<dependencies>
diff --git a/plc4j/utils/raw-sockets/pom.xml b/plc4j/utils/raw-sockets/pom.xml
index befae2a..1363933 100644
--- a/plc4j/utils/raw-sockets/pom.xml
+++ b/plc4j/utils/raw-sockets/pom.xml
@@ -46,9 +46,14 @@
<version>4.1.17.Final</version>
</dependency>
<dependency>
- <groupId>com.github.mlaccetti</groupId>
- <artifactId>rocksaw</artifactId>
- <version>1.1.0</version>
+ <groupId>org.pcap4j</groupId>
+ <artifactId>pcap4j-core</artifactId>
+ <version>1.7.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.pcap4j</groupId>
+ <artifactId>pcap4j-packetfactory-static</artifactId>
+ <version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
diff --git a/plc4j/utils/raw-sockets/src/test/java/Test.java b/plc4j/utils/raw-sockets/src/test/java/Test.java
new file mode 100644
index 0000000..d6b2dbe
--- /dev/null
+++ b/plc4j/utils/raw-sockets/src/test/java/Test.java
@@ -0,0 +1,307 @@
+/*
+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 org.pcap4j.core.*;
+import org.pcap4j.core.PcapNetworkInterface.PromiscuousMode;
+import org.pcap4j.packet.*;
+import org.pcap4j.packet.namednumber.*;
+import org.pcap4j.util.ByteArrays;
+import org.pcap4j.util.LinkLayerAddress;
+import org.pcap4j.util.MacAddress;
+
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.concurrent.*;
+
+public class Test {
+
+ private static final int SNAPLEN = 65536;
+ private static final int READ_TIMEOUT = 10;
+
+ public static void main(String[] args) throws Exception {
+ // ICMP has the IP protocol number 1
+ int protocolNumber = 1;
+ String hostName = "10.10.56.1";
+ InetAddress hostIpAddress = InetAddress.getByName(hostName);
+
+ InetAddress localAddress = getLocalNetworkAddress(hostIpAddress);
+ if(localAddress == null) {
+ System.out.println("Unable to connect to the remote host " + hostName);
+ return;
+ }
+ PcapNetworkInterface nif = Pcaps.getDevByAddress(localAddress);
+
+ /////////////////////////////////////////////////////////////////////////
+ // Setup handling incoming packets.
+ /////////////////////////////////////////////////////////////////////////
+
+ ExecutorService pool = Executors.newSingleThreadExecutor();
+ // Set the filter to only accept packets of the same protocol and
+ // addresses at the same MAC address.
+
+ // Filter packets to contain only the ip protocol number of the current protocol.
+ StringBuilder ab = new StringBuilder("ip protochain ").append(protocolNumber);
+ MacAddress srcMacAddress = null;
+ ArrayList<LinkLayerAddress> linkLayerAddresses = nif.getLinkLayerAddresses();
+ // Restrict the filter to only replies from the mac address
+ // we will be sending to the current devices mac address.
+ if(!linkLayerAddresses.isEmpty()) {
+ ab.append(" and( ");
+ Iterator<LinkLayerAddress> deviceIterator = nif.getLinkLayerAddresses().iterator();
+ while(deviceIterator.hasNext()) {
+ LinkLayerAddress linkLayerAddress = deviceIterator.next();
+ srcMacAddress = MacAddress.getByName(linkLayerAddress.toString(), ":");
+ ab.append("ether dst ").append(linkLayerAddress.toString());
+ if(deviceIterator.hasNext()) {
+ ab.append(" or ");
+ }
+ }
+ ab.append(")");
+ }
+ // Create a receive handle for incoming packets
+ PcapHandle receiveHandle = nif.openLive(SNAPLEN, PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
+ // Set the filter.
+ receiveHandle.setFilter(ab.toString(), BpfProgram.BpfCompileMode.OPTIMIZE);
+ // Create a listener to simply output the response on the console.
+ CompletableFuture<Packet> result = new CompletableFuture<>();
+ PacketListener listener
+ = result::complete;
+ // Create a task to listen for incoming packets.
+ Task t = new Task(receiveHandle, listener);
+ pool.execute(t);
+
+ /////////////////////////////////////////////////////////////////////////
+ // Send an outgoing packet.
+ /////////////////////////////////////////////////////////////////////////
+
+ MacAddress hostMacAddress = getMacAddress(nif, srcMacAddress, localAddress, hostIpAddress);
+ if(hostMacAddress == null) {
+ throw new RuntimeException("Unable to lookup mac address for host " + hostIpAddress.getHostAddress());
+ }
+ PcapHandle sendHandle = nif.openLive(SNAPLEN, PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
+
+ ///////////////////////////////////////////////////////////////////
+ // Version using pcap4j built in datatypes
+ ///////////////////////////////////////////////////////////////////
+ /*byte[] echoData = new byte[10];
+ for (int i = 0; i < echoData.length; i++) {
+ echoData[i] = (byte)i;
+ }
+
+ IcmpV4EchoPacket.Builder echoBuilder = new IcmpV4EchoPacket.Builder();
+ echoBuilder.identifier((short)1)
+ .payloadBuilder(new UnknownPacket.Builder().rawData(echoData));
+
+
+ IcmpV4CommonPacket.Builder icmpV4CommonBuilder = new IcmpV4CommonPacket.Builder();
+ icmpV4CommonBuilder
+ .type(IcmpV4Type.ECHO)
+ .code(IcmpV4Code.NO_CODE)
+ .payloadBuilder(echoBuilder)
+ .correctChecksumAtBuild(true);*/
+
+ ///////////////////////////////////////////////////////////////////
+ // Version with hand-crafted icmp byte data
+ ///////////////////////////////////////////////////////////////////
+ UnknownPacket.Builder packetBuilder = new UnknownPacket.Builder();
+ byte[] rawData = new byte[] {
+ // Type (ICMP Ping Request) & Code (just 0)
+ (byte) 0x08, (byte) 0x00,
+ // Checksum
+ (byte) 0xe3, (byte) 0xe5,
+ // Identifier
+ (byte) 0x00, (byte) 0x01,
+ // Sequence Number
+ (byte) 0x00, (byte) 0x00,
+ // Payload (Just random data that was used to fit to the checksum)
+ (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09};
+ packetBuilder.rawData(rawData);
+
+ IpV4Packet.Builder ipV4Builder = new IpV4Packet.Builder();
+ try {
+ ipV4Builder
+ .version(IpVersion.IPV4)
+ .tos(IpV4Rfc791Tos.newInstance((byte)0))
+ .ttl((byte)100)
+ .protocol(new IpNumber((byte) protocolNumber, "test")/*IpNumber.ICMPV4*/)
+ .srcAddr((Inet4Address)InetAddress.getByName(localAddress.getHostAddress()))
+ .dstAddr((Inet4Address) hostIpAddress)
+ .payloadBuilder(packetBuilder)
+ .correctChecksumAtBuild(true)
+ .correctLengthAtBuild(true);
+ } catch (UnknownHostException e1) {
+ throw new IllegalArgumentException(e1);
+ }
+ ipV4Builder.identification((short)1);
+
+ EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
+ etherBuilder.dstAddr(hostMacAddress)
+ .srcAddr(srcMacAddress)
+ .type(EtherType.IPV4)
+ .paddingAtBuild(true);
+ etherBuilder.payloadBuilder(
+ new AbstractPacket.AbstractBuilder() {
+ @Override
+ public Packet build() {
+ return ipV4Builder.build();
+ }
+ }
+ );
+
+ Packet p = etherBuilder.build();
+ System.out.println(p.toString());
+ sendHandle.sendPacket(p);
+
+ Packet packet = result.get();
+ System.out.println(packet.toString());
+ }
+
+ /**
+ * Iterate through all devices and find the first that would be able to connect to the given address.
+ *
+ * @param remoteAddress address we want to connect to.
+ * @return PcapNetworkInterface interface that should be able to connect to the given address.
+ * @throws Exception something went wrong.
+ */
+ protected static InetAddress getLocalNetworkAddress(InetAddress remoteAddress) throws Exception {
+ byte[] remoteIp = remoteAddress.getAddress();
+ // Iterate over all network interfaces.
+ for(PcapNetworkInterface dev : Pcaps.findAllDevs()) {
+ System.out.println(dev.getName());
+ // Iterate over all addresses configured for this interface.
+ for(PcapAddress addr : dev.getAddresses()) {
+ // Only check addresses matching the IP-version of the remote address.
+ if(remoteAddress.getClass().equals(addr.getAddress().getClass())) {
+ byte[] localIp = addr.getAddress().getAddress();
+ byte[] netMask = addr.getNetmask().getAddress();
+ boolean matches = true;
+ // Iterate over all bytes of the address and see if they match
+ // after applying the net mask filter.
+ for(int i = 0; i < localIp.length; i++) {
+ if((localIp[i] & netMask[i]) != (remoteIp[i] & netMask[i])) {
+ matches = false;
+ break;
+ }
+ }
+ // If the current address would be able to connect to the remote
+ // address, return this device.
+ if(matches) {
+ return addr.getAddress();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ protected static MacAddress getMacAddress(PcapNetworkInterface nif, MacAddress localMacAddress, InetAddress localIpAddress, InetAddress remoteIpAddress) throws Exception {
+ PcapHandle receiveHandle
+ = nif.openLive(SNAPLEN, PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
+ PcapHandle sendHandle
+ = nif.openLive(SNAPLEN, PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
+
+ ExecutorService pool = Executors.newSingleThreadExecutor();
+
+ try {
+ receiveHandle.setFilter(
+ "arp and src host " + remoteIpAddress.getHostAddress()
+ + " and dst host " + localIpAddress.getHostAddress()
+ + " and ether dst " + Pcaps.toBpfString(localMacAddress),
+ BpfProgram.BpfCompileMode.OPTIMIZE
+ );
+
+ CompletableFuture<MacAddress> resolvedAddress = new CompletableFuture<>();
+ PacketListener listener
+ = packet -> {
+ if (packet.contains(ArpPacket.class)) {
+ ArpPacket arp = packet.get(ArpPacket.class);
+ if (arp.getHeader().getOperation().equals(ArpOperation.REPLY)) {
+ resolvedAddress.complete(arp.getHeader().getSrcHardwareAddr());
+ }
+ }
+ };
+
+ Task t = new Task(receiveHandle, listener);
+ pool.execute(t);
+
+ ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
+ arpBuilder
+ .hardwareType(ArpHardwareType.ETHERNET)
+ .protocolType(EtherType.IPV4)
+ .hardwareAddrLength((byte)MacAddress.SIZE_IN_BYTES)
+ .protocolAddrLength((byte) ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
+ .operation(ArpOperation.REQUEST)
+ .srcHardwareAddr(localMacAddress)
+ .srcProtocolAddr(localIpAddress)
+ .dstHardwareAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
+ .dstProtocolAddr(remoteIpAddress);
+
+ EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
+ etherBuilder.dstAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
+ .srcAddr(localMacAddress)
+ .type(EtherType.ARP)
+ .payloadBuilder(arpBuilder)
+ .paddingAtBuild(true);
+
+ Packet p = etherBuilder.build();
+ sendHandle.sendPacket(p);
+ try {
+ return resolvedAddress.get(10000, TimeUnit.MILLISECONDS);
+ } catch (TimeoutException e) {
+ return null;
+ }
+ } finally {
+ /*if (receiveHandle.isOpen()) {
+ receiveHandle.close();
+ }
+ if (sendHandle.isOpen()) {
+ sendHandle.close();
+ }
+ if (!pool.isShutdown()) {
+ pool.shutdownNow();
+ }*/
+ }
+ }
+
+ private static class Task implements Runnable {
+
+ private PcapHandle handle;
+ private PacketListener listener;
+
+ public Task(PcapHandle handle, PacketListener listener) {
+ this.handle = handle;
+ this.listener = listener;
+ }
+
+ @Override
+ public void run() {
+ try {
+ handle.loop(-1, listener);
+ } catch (PcapNativeException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ } catch (NotOpenException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
cdutz@apache.org.
[incubator-plc4x] 01/02: Merge branches
'feature/PLC4X-18--raw-sockets' and 'master' of
https://gitbox.apache.org/repos/asf/incubator-plc4x into
feature/PLC4X-18--raw-sockets
Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/PLC4X-18--raw-sockets
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit 75063b2fc1d473c09c81163eee6341778df424dd
Merge: df791fd 548cfd4
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Jan 21 12:13:40 2018 +0100
Merge branches 'feature/PLC4X-18--raw-sockets' and 'master' of https://gitbox.apache.org/repos/asf/incubator-plc4x into feature/PLC4X-18--raw-sockets
DISCLAIMER | 7 +
Jenkinsfile | 1 +
NOTICE | 8 +
integrations/apache-camel/pom.xml | 29 +-
.../java/org/apache/plc4x/camel/Constants.java | 6 +-
.../java/org/apache/plc4x/camel/PLC4XEndpoint.java | 10 +-
.../java/org/apache/plc4x/camel/PLC4XProducer.java | 34 +-
.../org/apache/plc4x/camel/ConstantsTest.java} | 24 +-
.../org/apache/plc4x/camel/PLC4XComponentTest.java | 25 +-
.../org/apache/plc4x/camel/PLC4XEndpointTest.java | 41 +-
.../org/apache/plc4x/camel/PLC4XProducerTest.java | 111 +++
.../apache/plc4x/edgent/PlcConnectionAdapter.java | 258 ++---
.../java/org/apache/plc4x/edgent/PlcFunctions.java | 4 +
.../plc4x/edgent/PlcConnectionAdapterTest.java | 1030 ++++++++++----------
.../org/apache/plc4x/edgent/PlcFunctionsTest.java | 14 +-
.../apache/plc4x/edgent/mock/MockConnection.java | 123 ++-
.../plc4x/java/api/connection/PlcReader.java | 17 +-
.../plc4x/java/api/connection/PlcWriter.java | 18 +-
.../plc4x/java/api/messages/PlcReadRequest.java | 78 +-
.../plc4x/java/api/messages/PlcReadResponse.java | 23 +-
.../apache/plc4x/java/api/messages/PlcRequest.java | 72 +-
.../plc4x/java/api/messages/PlcResponse.java | 54 +-
.../plc4x/java/api/messages/PlcWriteRequest.java | 82 +-
.../plc4x/java/api/messages/PlcWriteResponse.java | 23 +-
.../java/api/messages/items/ReadRequestItem.java | 24 +-
.../java/api/messages/items/ReadResponseItem.java | 23 +-
.../{ReadRequestItem.java => RequestItem.java} | 21 +-
.../{WriteResponseItem.java => ResponseItem.java} | 9 +-
.../java/api/messages/items/WriteRequestItem.java | 37 +-
.../java/api/messages/items/WriteResponseItem.java | 19 +-
.../messages/specific/TypeSafePlcReadRequest.java | 86 ++
.../messages/specific/TypeSafePlcReadResponse.java | 83 ++
.../messages/specific/TypeSafePlcWriteRequest.java | 82 ++
.../specific/TypeSafePlcWriteResponse.java | 59 ++
.../plc4x/java/api/connection/PlcReaderTest.java | 36 +
.../plc4x/java/api/connection/PlcWriterTest.java | 36 +
.../plc4x/java/api/messages/APIMessageTests.java | 175 ++--
.../java/api/messages/PlcReadRequestTest.java | 88 ++
.../java/api/messages/PlcReadResponseTest.java | 45 +
.../plc4x/java/api/messages/PlcRequestTest.java | 86 ++
.../plc4x/java/api/messages/PlcResponseTest.java | 87 ++
.../java/api/messages/PlcWriteRequestTest.java | 86 ++
.../java/api/messages/PlcWriteResponseTest.java | 45 +
.../specific/TypeSafePlcReadRequestTest.java | 77 ++
.../specific/TypeSafePlcReadResponseTest.java | 76 ++
.../specific/TypeSafePlcWriteRequestTest.java | 77 ++
.../specific/TypeSafePlcWriteResponseTest.java | 62 ++
.../org/apache/plc4x/java/PlcDriverManager.java | 2 +-
.../apache/plc4x/java/PlcDriverManagerTest.java | 52 +-
.../apache/plc4x/java/s7/utils/PcapGenerator.java | 22 +-
.../java/isoontcp/netty/IsoOnTcpProtocol.java | 4 +-
.../plc4x/java/isotp/netty/IsoTPProtocol.java | 45 +-
.../netty/model/tpdus/CustomTpdu.java} | 18 +-
.../plc4x/java/isotp/netty/model/tpdus/Tpdu.java | 7 +-
.../java/isotp/netty/model/types/TpduCode.java | 8 +-
.../java/org/apache/plc4x/java/s7/S7PlcDriver.java | 4 +-
.../plc4x/java/s7/connection/S7PlcConnection.java | 6 +-
.../plc4x/java/s7/netty/Plc4XS7Protocol.java | 460 +++++----
.../org/apache/plc4x/java/s7/netty/S7Protocol.java | 356 ++++---
.../java/s7/netty/model/messages/S7Message.java | 13 +-
.../netty/model/params/CpuServicesParameter.java | 4 -
.../netty/model/types/DataTransportErrorCode.java | 9 +-
.../java/s7/netty/model/types/ParameterType.java | 7 +-
.../plc4x/java/isotp/netty/IsoTPProtocolTest.java | 460 ++++-----
.../apache/plc4x/java/isotp/netty/MockChannel.java | 243 -----
.../isotp/netty/MockChannelHandlerContext.java | 234 -----
.../java/isotp/netty/MockChannelPipeline.java | 354 -------
.../isotp/netty/model/tpdus/IsotpModelTests.java | 8 +-
.../isotp/netty/model/types/IsotpTypeTests.java | 5 +-
.../apache/plc4x/java/s7/S7PlcReaderSample.java | 15 +-
.../org/apache/plc4x/java/s7/S7PlcScanner.java | 20 +-
.../org/apache/plc4x/java/s7/S7PlcTestConsole.java | 16 +-
.../apache/plc4x/java/s7/S7PlcWriterSample.java | 13 +-
.../plc4x/java/s7/netty/Plc4XS7ProtocolTest.java | 27 +-
.../s7/netty/model/messages/S7MessageTests.java | 8 +-
.../org/apache/plc4x/java/utils/PcapngUtils.java | 4 +
pom.xml | 4 +-
.../{development => developers}/building.adoc | 2 +-
.../asciidoc/{development => developers}/ci.adoc | 9 +
.../{development => developers}/contributing.adoc | 0
.../contributing.adoc => developers/issues.adoc} | 3 +-
.../contributing.adoc => developers/sonar.adoc} | 3 +-
.../{development => developers}/website.adoc | 0
.../contributing.adoc => developers/wiki.adoc} | 3 +-
src/site/asciidoc/index.adoc | 4 +-
.../ci.adoc => users/gettingstarted.adoc} | 4 +-
src/site/asciidoc/users/industry40.adoc | 124 +++
src/site/site.xml | 23 +-
88 files changed, 3554 insertions(+), 2560 deletions(-)
--
To stop receiving notification emails like this one, please contact
cdutz@apache.org.