<?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

      https://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:driver-testsuite xmlns:test="https://plc4x.apache.org/schemas/driver-testsuite.xsd"
                       byteOrder="LITTLE_ENDIAN">

  <name>EIP</name>

  <protocolName>eip</protocolName>
  <outputFlavor>read-write</outputFlavor>

  <driver-name>eip</driver-name>

  <setup>
    <!-- First the driver is expected to send a RegisterSession connection request -->
    <outgoing-plc-message name="Send connection request">
      <EipPacket>
        <command dataType="uint" bitLength="16">101</command>
        <len dataType="uint" bitLength="16">4</len>
        <sessionHandle dataType="uint" bitLength="32">0</sessionHandle>
        <status dataType="uint" bitLength="32">0</status>
        <senderContext isList="true">
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
        </senderContext>
        <options dataType="uint" bitLength="32">0</options>
        <EipConnectionRequest>
          <protocolVersion dataType="uint" bitLength="16">1</protocolVersion>
          <flags dataType="uint" bitLength="16">0</flags>
        </EipConnectionRequest>
      </EipPacket>
    </outgoing-plc-message>
    <!-- The PLC will send the connection response with a sender context and session handle-->
    <incoming-plc-message name="Receive connection response">
      <EipPacket>
        <command dataType="uint" bitLength="16">101</command>
        <len dataType="uint" bitLength="16">4</len>
        <sessionHandle dataType="uint" bitLength="32">1</sessionHandle>
        <status dataType="uint" bitLength="32">0</status>
        <senderContext isList="true">
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">0</value>
          <value dataType="uint" bitLength="8">2</value>
        </senderContext>
        <options dataType="uint" bitLength="32">0</options>
        <EipConnectionRequest>
          <protocolVersion dataType="uint" bitLength="16">1</protocolVersion>
          <flags dataType="uint" bitLength="16">0</flags>
        </EipConnectionRequest>
      </EipPacket>

    </incoming-plc-message>
  </setup>
  <testcase>
    <name>Single element read request</name>
    <steps>
      <api-request name="Receive Read Request from application">
        <TestReadRequest>
          <fields>
            <field className="org.apache.plc4x.test.driver.internal.api.TestField">
              <name>hurz</name>
              <address>%rate</address>
            </field>
          </fields>
        </TestReadRequest>
      </api-request>
      <outgoing-plc-message name="Send CipReadRequest to PLC">
        <EipPacket>
          <command dataType="uint" bitLength="16">111</command>
          <len dataType="uint" bitLength="16">40</len>
          <sessionHandle dataType="uint" bitLength="32">1</sessionHandle>
          <status dataType="uint" bitLength="32">0</status>
          <senderContext isList="true">
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
          </senderContext>
          <options dataType="uint" bitLength="32">0</options>
          <CipRRData>
            <reserved dataType="uint" bitLength="32">0</reserved>
            <reserved dataType="uint" bitLength="16">0</reserved>
            <exchange>
              <CipExchange>
                <itemCount dataType="uint" bitLength="16">2</itemCount>
                <nullPtr dataType="uint" bitLength="32">0</nullPtr>
                <unconnectedData dataType="uint" bitLength="16">178</unconnectedData>
                <size dataType="uint" bitLength="16">24</size>
                <service>
                  <CipService>
                    <service dataType="uint" bitLength="8">82</service>
                    <CipUnconnectedRequest>
                      <reserved dataType="uint" bitLength="8">2</reserved>
                      <reserved dataType="uint" bitLength="8">32</reserved>
                      <reserved dataType="uint" bitLength="8">6</reserved>
                      <reserved dataType="uint" bitLength="8">36</reserved>
                      <reserved dataType="uint" bitLength="8">1</reserved>
                      <reserved dataType="uint" bitLength="16">40197</reserved>
                      <messageSize dataType="uint" bitLength="16">10</messageSize>
                      <unconnectedService>
                        <CipService>
                          <service dataType="uint" bitLength="8">76</service>
                          <CipReadRequest>
                            <requestPathSize dataType="int" bitLength="8">3</requestPathSize>
                            <tag dataType="byte" bitLength="48">0x910472617465</tag>
                            <elementNb dataType="uint" bitLength="16">1</elementNb>
                          </CipReadRequest>
                        </CipService>
                      </unconnectedService>
                      <route dataType="uint" bitLength="16">1</route>
                      <backPlane dataType="int" bitLength="8">0</backPlane>
                      <slot dataType="int" bitLength="8">0</slot>
                    </CipUnconnectedRequest>
                  </CipService>
                </service>
              </CipExchange>
            </exchange>
          </CipRRData>
        </EipPacket>
      </outgoing-plc-message>
      <incoming-plc-message name="Get CipReadResponse from PLC">
        <EipPacket>
          <command dataType="uint" bitLength="16">111</command>
          <len dataType="uint" bitLength="16">26</len>
          <sessionHandle dataType="uint" bitLength="32">1</sessionHandle>
          <status dataType="uint" bitLength="32">0</status>
          <senderContext isList="true">
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">0</value>
            <value dataType="uint" bitLength="8">2</value>
          </senderContext>
          <options dataType="uint" bitLength="32">0</options>
          <CipRRData>
            <reserved dataType="uint" bitLength="32">0</reserved>
            <reserved dataType="uint" bitLength="16">0</reserved>
            <exchange>
              <CipExchange>
                <itemCount dataType="uint" bitLength="16">2</itemCount>
                <nullPtr dataType="uint" bitLength="32">0</nullPtr>
                <unconnectedData dataType="uint" bitLength="16">178</unconnectedData>
                <size dataType="uint" bitLength="16">10</size>
                <service>
                  <CipService>
                    <service dataType="uint" bitLength="8">204</service>
                    <CipReadResponse>
                      <reserved dataType="uint" bitLength="8">0</reserved>
                      <status dataType="uint" bitLength="8">0</status>
                      <extStatus dataType="uint" bitLength="8">0</extStatus>
                      <dataType>
                        <CIPDataTypeCode dataType="uint" bitLength="16" stringRepresentation="DINT">196
                        </CIPDataTypeCode>
                      </dataType>
                      <data dataType="byte" bitLength="32">0x00000216</data>
                    </CipReadResponse>
                  </CipService>
                </service>
              </CipExchange>
            </exchange>
          </CipRRData>
        </EipPacket>
      </incoming-plc-message>
      <api-response name="Report Read Response to application">
        <PlcReadResponse>
          <PlcReadRequest>
            <fields>
              <hurz>
                <EipField>
                  <node dataType="string" bitLength="32" encoding="UTF-8">rate</node>
                  <elementNb dataType="uint" bitLength="16">0</elementNb>
                  <defaultJavaType dataType="string" bitLength="128" encoding="UTF-8">java.lang.Object</defaultJavaType>
                </EipField>
              </hurz>
            </fields>
          </PlcReadRequest>
          <values>
            <hurz>
              <ResponseItem>
                <result dataType="string" bitLength="16" encoding="UTF-8">OK</result>
                <PlcDINT dataType="int" bitLength="64">369229824</PlcDINT>
              </ResponseItem>
            </hurz>
          </values>
        </PlcReadResponse>
      </api-response>
    </steps>
  </testcase>

</test:driver-testsuite>