# ethernetip — Rockwell CIP Sessions (44818) & UDP 2222 I/O (`ethernetip`)

> **FrameAssembly v3.2.2** · Protocol 80 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/ethernetip

- **Full Protocol Name:** ODVA EtherNet/IP & Common Industrial Protocol (Rockwell)
- **Keyword:** `ethernetip`
- **OSI Layer & Transport:** Layer 7 · TCP 44818 (Explicit) / UDP 2222 (Implicit I/O)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** ODVA EtherNet/IP, CIP Vol. 1 & Vol. 2
- **Wireshark Display Filter:** `enip || cip`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 44818 (Explicit) / UDP 2222 (Implicit I/O) (transport tcp|udp) -> EtherNet/IP (CIP)`

## Overview

Factory-floor CIP encapsulation: `ethernetip` uses TCP `44818` for explicit sessions (`registersession`, `sendrrdata`) and automatically hops to real-time UDP `2222` when you pick `sendunitdata`!

EtherNet/IP (`ethernetip`, ODVA) encapsulates the **Common Industrial Protocol (CIP)** used across Rockwell Automation / Allen-Bradley ControlLogix & CompactLogix PLCs, Omron controllers, and industrial robots. Explicit session management (`registersession`, `listidentity`, `sendrrdata`) runs over **TCP port `44818`** (`0xaf12`), while real-time cyclic I/O (`sendunitdata` or `transport udp`) runs over **UDP port `2222`**.

FrameAssembly builds the little-endian 24-byte EtherNet/IP Encapsulation Header, Common Packet Format (`CPF`) items, and EPATH-encoded CIP service requests (`cipservice`, `cipclass`, `cipinstance`, `cipattr`) automatically.

## Minimal Quickstart (`ethernetip_quickstart.frasm`)

```frameassembly
host factory_hmi { ip 192.168.20.10 }
host logix_plc   { ip 192.168.20.55 }

compile {
    factory_hmi -> logix_plc tcp syn srcport 54818 dstport 44818 wait 1ms
    factory_hmi <- logix_plc tcp syn ack wait 1ms
    factory_hmi -> logix_plc tcp ack wait 1ms
    factory_hmi -> logix_plc ethernetip registersession wait 2ms
    factory_hmi <- logix_plc ethernetip registersession sessionhandle 0x00010001 wait 2ms
    factory_hmi -> logix_plc ethernetip sendrrdata sessionhandle 0x00010001 cipservice 0x0e cipclass 0x01 cipinstance 1 cipattr 7
}
```

### Automatic Wire Calculations

- Selects TCP port `44818` for explicit encapsulation commands (`registersession`, `listidentity`, `sendrrdata`) and automatically switches to UDP port `2222` on `sendunitdata` or `transport udp`.
- Encodes the 24-byte little-endian EtherNet/IP Encapsulation Header (`Command`, `Length`, `Session Handle`, `Status`, 8-byte `Sender Context`, `Options`).
- Builds Common Packet Format (`CPF`) Null/Unconnected Data items and logical EPATH segments (`0x20` Class, `0x24` Instance, `0x30` Attribute) inside `sendrrdata` and `sendunitdata`.

## Practical Lab Example: PLC Discovery (`ListIdentity`), Session Registration, CIP Attribute Read & UDP 2222 I/O (`ethernetip_cip_cell.frasm`)

Performs a `listidentity` check, registers session `0x00010042` on TCP 44818, reads Assembly Instance `100` Attribute `3` (`Get_Attribute_Single` `0x0e`), and sends an implicit I/O packet on UDP 2222.

```frameassembly
host studio_ws { ip 10.120.10.15 }
host clx_plc   { ip 10.120.10.60 }

compile {
    studio_ws -> clx_plc tcp syn srcport 51818 dstport 44818 win 65535 mss 1460 wait 1ms
    studio_ws <- clx_plc tcp syn ack win 65535 mss 1460 wait 1ms
    studio_ws -> clx_plc tcp ack wait 1ms
    // 1. ListIdentity (0x0063) + RegisterSession (0x0065)
    studio_ws -> clx_plc ethernetip listidentity wait 2ms
    studio_ws -> clx_plc ethernetip registersession context 0x1122334455667788 wait 2ms
    studio_ws <- clx_plc ethernetip registersession sessionhandle 0x00010042 context 0x1122334455667788 status 0 wait 3ms
    // 2. SendRRData (0x006f): CIP Get_Attribute_Single (0x0e) on Assembly Object (0x04), Instance 100, Attr 3
    studio_ws -> clx_plc ethernetip sendrrdata sessionhandle 0x00010042 cipservice 0x0e cipclass 0x04 cipinstance 100 cipattr 3 wait 4ms
    // 3. Implicit CIP I/O over UDP 2222 + UnRegisterSession
    studio_ws -> clx_plc ethernetip sendunitdata sessionhandle 0x00010042 cipservice 0x0e cipclass 0x04 cipinstance 150 cipattr 3 transport udp wait 3ms
    studio_ws -> clx_plc ethernetip unregistersession sessionhandle 0x00010042
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show ethernetip_cip_cell.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly ethernetip_cip_cell.frasm ethernetip_cip_cell.pcap
frameassembly ethernetip_cip_cell.frasm ethernetip_cip_cell.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse ethernetip_cip_cell.pcap ethernetip_cip_cell_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r ethernetip_cip_cell.pcap
```

## All `ethernetip` Keywords & Header Options

Packet line pattern: `src_host -> dst_host ethernetip [nop | listservices | listidentity | listinterfaces | registersession | unregistersession | sendrrdata | sendunitdata | cmd "<text>"] [sessionhandle <hex_or_num>] [status <number>] [context <hex_or_str>] [cipservice <hex_or_num>] [cipclass <hex_or_num>] [cipinstance <number>] [cipattr <number>] [transport <tcp|udp>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `nop \| listservices \| listidentity \| listinterfaces \| registersession \| unregistersession \| sendrrdata \| sendunitdata` | EtherNet/IP encapsulation command (or `cmd "<text>"`) | `listidentity (0x0063)` | Selects Encapsulation Command `0x0000` NOP, `0x0004` ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065` RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070` SendUnitData. |
| `sessionhandle <hex_or_num> \| status <number> \| context <hex_or_str>` | 32-bit Session Handle, 32-bit Status (`0` Success), 64-bit Sender Context | `sessionhandle 0, status 0` | Populates the 24-byte EtherNet/IP Encapsulation Header fields. |
| `cipservice <hex_or_num>` | CIP Service Code (`0x01` Get_Attributes_All, `0x0e` Get_Attribute_Single, `0x10` Set_Attribute_Single, `0x4c` Read_Tag) | `0x0e (Get_Attribute_Single)` | Sets the CIP Service byte inside `sendrrdata` / `sendunitdata`. |
| `cipclass <hex_or_num> \| cipinstance <number> \| cipattr <number>` | CIP Object Class (`0x01` Identity, `0x04` Assembly, `0x6b` Symbol), Instance, and Attribute | `cipclass 0x01, cipinstance 1, cipattr 1` | Encodes the logical EPATH segments targeting the PLC CIP object. |
| `transport <tcp\|udp>` | `tcp` or `udp` | `tcp (44818), or udp (2222) on sendunitdata` | Switches Layer 4 between TCP `44818` and UDP `2222`. |

## Cross-Layer Options Valid with `ethernetip`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 44818 (Explicit) / UDP 2222 (Implicit I/O)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport <tcp\|udp>` | `tcp` or `udp` (supported on 9 dual-L4 protocols) | `transport tcp` | Switches Layer 4 transport between TCP (`psh ack` + length framing where required) and UDP. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window size, flags & RFC 7323 options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`tsval`/`tsecr`. |

## Common Mistakes & Quick Fixes

### Protocol Keyword Is ethernetip (No Slash)

- **Avoid:** `factory_hmi -> logix_plc ethernet/ip listidentity`
- **Valid v3.2.2 Syntax:** `factory_hmi -> logix_plc ethernetip listidentity`

Spell ODVA EtherNet/IP as `ethernetip` with no slash or hyphen.

### Wireshark Display Filter Uses enip and cip

- **Valid v3.2.2 Syntax:** `Wireshark display filter: enip || cip`

Wireshark dissects the 24-byte encapsulation layer under `enip` and the inner Common Industrial Protocol payload under `cip`.
