pjkundert / cpppo

Communications Protocol Python Parser and Originator -- EtherNet/IP CIP
https://hardconsulting.com/products/6-cpppo-enip-api
Other
328 stars 108 forks source link

Assert fails for request-response pairs out of order #78

Open acalandra-cpr opened 4 years ago

acalandra-cpr commented 4 years ago

Hello,

We're using your library to read registers off one of our appliances and notice that sometimes we get issues because the library assumes responses received from requests are in the same order -- we're not sure if it's a library problem or a user-of-the-library problem. Here's how this problem occurs.

At a high-level, this is what we're doing:

from cpppo.server.enip.get_attribute import proxy

client = proxy(host=host, port=port, route_path=False, send_path='')
client.open_gateway()
try:
    registers = [ "VO_ERR", "VO_ERX", "VO_FLT" ]
    response = client.read(registers)
    items = list(response)
    # do something ...
except Exception as e:
    log(e)
    client.close_gateway()

# ...

This code works fine until the following happens: wireshark What's happening according to wireshark is we send read requests for our 3 registers, then in black, you can see we get a response back for the VO_ERX register, while the respone the library was expecting to receive first is in blue (VO_ERR). This happens only sometimes, but when it does, we see the following (note that this isn't the error from that specific wireshark capture but the same assert always fails):

Request:     0 (Context:        '0'/       '1') Mismatched;
op: {
    "path": [
        {
            "symbolic": "VO_ERR"
        }
    ],
    "offset": null,
    "route_path": false,
    "sender_context": "0",
    "send_path": ""
}
request: {
    "path.segment[0].symbolic": "VO_ERR",
    "read_tag.elements": 1,
    "service": 76,
    "input": "bytearray(b'L\\x04\\x91\\x06VO_ERR\\x01\\x00')"
}
reply: {
    "status": 5,
    "input": "array('c', '\\xcc\\x00\\x05\\x00')",
    "status_ext.size": 0,
    "read_tag": true,
    "service": 204
}

I'm not sure if we're using the wrong abstraction (i.e. using proxy) or if the library must have these responses appear in order. Any ideas? Thanks!