You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "Łukasz Dywicki (Jira)" <ji...@apache.org> on 2022/07/26 14:00:00 UTC

[jira] [Commented] (PLC4X-352) Issue with create PCCC connection problem

    [ https://issues.apache.org/jira/browse/PLC4X-352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17571446#comment-17571446 ] 

Łukasz Dywicki commented on PLC4X-352:
--------------------------------------

Hello [~susliks], can you try with 0.10.0-SNAPSHOT? As far I remember [~hutcheb] worked recently on some improvements to get ENIP working.

> Issue with create PCCC connection problem
> -----------------------------------------
>
>                 Key: PLC4X-352
>                 URL: https://issues.apache.org/jira/browse/PLC4X-352
>             Project: Apache PLC4X
>          Issue Type: Bug
>          Components: Driver-Ethernet/IP
>    Affects Versions: 0.9.1
>            Reporter: susliks
>            Priority: Critical
>         Attachments: EtherNetIP_PCCC_CM.pcapng, decodeerror.png
>
>
> Hello,I want to register PCCC connection manager after registering the session of ethernet/ip.But I cant receive the response with PCCC connection manager.
> I create the pccc cm request in EtherNet/IP connectResponse's handle just like S7Driver.
> {quote} 
> @Override
>     public void onConnect(ConversationContext<ENipPacket> context) {
>         logger.debug("Sending RegisterSession ENIP Package");
>         System.out.println("Sending RegisterSession ENIP Package");
>         ENipConnectionRequest connectionRequest =
>             new ENipConnectionRequest(0L, 0L, emptySenderContext, 0L);
>         context.sendRequest(connectionRequest)
>             .expectResponse(ENipPacket.class, REQUEST_TIMEOUT)
>             .check(q -> q instanceof ENipConnectionRequest)
>             .handle(enipConnectionRequest -> {
>                 if (enipConnectionRequest.getStatus() == 0L) {
>                     long sessionHandle = enipConnectionRequest.getSessionHandle();
>                     short[] b = enipConnectionRequest.getSenderContext();
>                     enipDriverContext.setSessionHandle(sessionHandle);
>                     enipDriverContext.setSenderContext(b);
>                     logger.debug("Got assigned with Session {}", sessionHandle);
>                     System.out.println(enipDriverContext.getSessionHandle());
>                     enipDriverContext.setOtoTconnectionID(0x8000000f);
>                     enipDriverContext.setTtoOconnectionID(0x80fe000e);
>                     enipDriverContext.setConnectionSerialID(0x000f);
>                     ENipCipRRData CM_ConnectRequest =
>                         new ENipCipRRData(enipDriverContext.getSessionHandle(),0L,enipDriverContext.getSenderContext(),0L,0x0014,
>                             new CipExchange(new NullAddressItem(),
>                                 new UnconnectedDataItem(new CipForwardOpenRequest(
>                                     new ForwardOpenRequest(enipDriverContext.getOtoTconnectionID(),enipDriverContext.getTtoOconnectionID(),enipDriverContext.getConnectionSerialID())
>                                 ))));
>                     System.out.println("Sending CM ENIP Package");
>                     context.sendRequest(CM_ConnectRequest)
>                         .expectResponse(ENipPacket.class, REQUEST_TIMEOUT)
>                         .check(p -> p instanceof ENipCipRRData)
>                         .unwrap(p -> (ENipCipRRData) p)
>                         .check(p-> p.getExchange().getItem_0() instanceof NullAddressItem)
>                         .check(p-> p.getExchange().getItem_1() instanceof UnconnectedDataItem)
>                         .unwrap(p -> (UnconnectedDataItem) p.getExchange().getItem_1())
>                         .check(p -> p.getService() instanceof CipForwardOpenResponse)
>                         .unwrap(p -> (CipForwardOpenResponse) p.getService())
>                         .check(p -> p.getOpenResponse() instanceof ForwardOpenResponse)
>                         .handle(p -> {                           
> System.out.println("get OtoTconnectionID");                                          enipDriverContext.setOtoTconnectionID(p.getOpenResponse().getOtoT_ConnectionID());                            System.out.println(enipDriverContext.getOtoTconnectionID());                            context.fireConnected();                        }
> );
>                 } else {
>                     logger.warn("Got status code [{}]", enipConnectionRequest.getStatus());
>                 }
>             })
> {quote}
> Now I find some problem but I dont know what cause it.In Plc4xNetttyWarpper decode function,It cant receive the second response.Wireshark captured the correct packet.
> Here is my driver code
> {quote}package org.apache.plc4x.java.enip;
> import io.netty.buffer.ByteBuf;
> import org.apache.plc4x.java.api.metadata.PlcDriverMetadata;
> import org.apache.plc4x.java.enip.context.EnipDriverContext;
> import org.apache.plc4x.java.spi.connection.GeneratedDriverBase;
> import org.apache.plc4x.java.spi.configuration.Configuration;
> import org.apache.plc4x.java.spi.connection.PlcFieldHandler;
> import org.apache.plc4x.java.spi.connection.ProtocolStackConfigurer;
> import org.apache.plc4x.java.spi.connection.SingleProtocolStackConfigurer;
> import org.apache.plc4x.java.enip.configuration.ENIPConfiguration;
> import org.apache.plc4x.java.enip.field.ENipFieldHandler;
> import org.apache.plc4x.java.api.value.PlcValueHandler;
> import org.apache.plc4x.java.spi.values.IEC61131ValueHandler;
> import org.apache.plc4x.java.enip.protocol.ENipProtocolLogic;
> import org.apache.plc4x.java.enip.readwrite.*;
> import org.apache.plc4x.java.enip.readwrite.io.*;
> import java.util.function.Consumer;
> import java.util.function.ToIntFunction;
> public class ENIPDriver extends GeneratedDriverBase<ENipPacket>
> Unknown macro: \{     public static final int PORT = 44818;     @Override     public String getProtocolCode(){return "enip";}
>     @Override
>     public String getProtocolName()
> Unknown macro: \{         return "EthernetIP";     }
>     @Override
>     protected Class<? extends Configuration> getConfigurationType()
> Unknown macro: \{         return ENIPConfiguration.class;     }
>     @Override
>     protected PlcFieldHandler getFieldHandler()
> Unknown macro: \{         return new ENipFieldHandler();     }
>     @Override
>     protected PlcValueHandler getValueHandler()
> Unknown macro: \{         return new IEC61131ValueHandler();     }
>     @Override
>     protected String getDefaultTransport()
> Unknown macro: \{         return "tcp";     }
>     /** Estimate the Length of a Packet */
>     public static class ByteLengthEstimator implements ToIntFunction<ByteBuf> {
>         @Override
>         public int applyAsInt(ByteBuf byteBuf) {
>             if (byteBuf.readableBytes() >= 4)
> Unknown macro: \{                 //Second byte for the size and then add the header size 24                 int size = byteBuf.getUnsignedShort(byteBuf.readerIndex()+1)+24;                 return size;             }
>             return -1;
>         }
>     }
>     @Override
>     public PlcDriverMetadata getMetadata() {
>         return new PlcDriverMetadata() {
>             @Override
>             public boolean canDiscover()
> Unknown macro: \{                 return true;             }
>         };
>     }
>     @Override
>     protected ProtocolStackConfigurer<ENipPacket> getStackConfigurer()
> Unknown macro: \{         return SingleProtocolStackConfigurer.builder(ENipPacket.class, ENipPacketIO.class)                 .withProtocol(ENipProtocolLogic.class)                 .withDriverContext(EnipDriverContext.class)                 .withPacketSizeEstimator(ByteLengthEstimator.class)                 .littleEndian()                 .build();     }
>     @Override
>     protected boolean canRead()
> Unknown macro: \{         return true;     }
>     @Override
>     protected boolean canWrite()
> }
> {quote}
> Here is error message
> {quote}set Driver Context
> Sending RegisterSession ENIP Package
> completed
> DecodingENipConnectionRequest[sessionHandle=1604640755,status=0,senderContext=
> Unknown macro: \{0,0,0,0,0,0,0,0}
> ,options=0]
> 1604640755
> Sending CM ENIP Package
> 7月 26, 2022 5:36:26 下午 io.netty.channel.DefaultChannelPipeline onUnhandledInboundException
> 警告: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
> java.io.IOException: 连接被对方重设
> at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method)
> at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
> at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
> at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:233)
> at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223)
> at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:356)
> at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
> at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132)
> at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
> at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
> at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
> at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
> at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
> at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
> at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
> at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
> at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
> at java.base/java.lang.Thread.run(Thread.java:829)
> Exception in thread "main" org.apache.plc4x.java.api.exceptions.PlcConnectionException: java.util.concurrent.ExecutionException: org.apache.plc4x.java.api.exceptions.PlcIoException: Connection terminated by remote
> at org.apache.plc4x.java.spi.connection.DefaultNettyPlcConnection.connect(DefaultNettyPlcConnection.java:142)
> at org.apache.plc4x.java.PlcDriverManager.getConnection(PlcDriverManager.java:74)
> at org.apache.plc4x.java.examples.enip.test.EnipExample.main(EnipExample.java:15)
> Caused by: java.util.concurrent.ExecutionException: org.apache.plc4x.java.api.exceptions.PlcIoException: Connection terminated by remote
> at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
> at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
> at org.apache.plc4x.java.spi.connection.DefaultNettyPlcConnection.connect(DefaultNettyPlcConnection.java:133)
> ... 2 more
> Caused by: org.apache.plc4x.java.api.exceptions.PlcIoException: Connection terminated by remote
> at org.apache.plc4x.java.spi.connection.DefaultNettyPlcConnection.lambda$connect$1(DefaultNettyPlcConnection.java:124)
> at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
> at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:552)
> at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
> at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
> at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:605)
> at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
> at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
> at io.netty.channel.AbstractChannel$CloseFuture.setClosed(AbstractChannel.java:1182)
> at io.netty.channel.AbstractChannel$AbstractUnsafe.doClose0(AbstractChannel.java:773)
> at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:749)
> at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:620)
> at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.closeOnRead(AbstractNioByteChannel.java:105)
> at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.handleReadException(AbstractNioByteChannel.java:130)
> at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:177)
> at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
> at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
> at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
> at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
> at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
> at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
> at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
> at java.base/java.lang.Thread.run(Thread.java:829)
> {quote}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)