# rocplus — Port 4000 Emerson ROC Plus Oil & Gas Pipeline RTUs (`rocplus`)

> **FrameAssembly v3.3.0** · Protocol 122 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/rocplus

- **Full Protocol Name:** Emerson Fisher ROC Plus Oil & Gas Pipeline RTU Protocol
- **Keyword:** `rocplus`
- **OSI Layer & Transport:** Layer 7 · TCP 4000 (or UDP 4000 via transport udp)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** Emerson Fisher ROC Plus Protocol Specifications Manual (D301151X012)
- **Wireshark Display Filter:** `tcp.port == 4000 || udp.port == 4000`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 4000 (or UDP 4000 via transport udp) (transport tcp|udp) -> Emerson ROC Plus`

## Overview

Wellhead and natural-gas custody-transfer RTUs speak Emerson ROC Plus on port `4000` — `rocplus` packs unit/group addressing, TLP (`type`, `addr`, `param`) point reads/writes, and reflected CRC-16 trailers.

Emerson Fisher ROC Plus (`rocplus`) is a core **upstream wellhead, custody-transfer flow computer (`FloBoss`), and midstream natural-gas/crude pipeline RTU (`ROC800`, `FB1000`/`FB2000`)** SCADA protocol on **TCP or UDP port `4000`**. Every ROC Plus frame consists of a **6-byte Header** (`Destination Unit`/`Destination Group`, `Source Unit`/`Source Group`, `Opcode`, and `Data Length`), **Type-Length-Parameter (`TLP`: `Point Type`, `Logical/Point Number addr`, `Parameter Number param`)** data bytes, and a trailing **little-endian reflected 16-bit CRC-16 (`poly 0xa001`, init `0x0000`)**.

FrameAssembly computes `Data Length` and the trailing **ROC CRC-16 (`0xa001`)** automatically (or lets you override `crc` to test pipeline SCADA gateway error counters).

## Minimal Quickstart (`rocplus_quickstart.frasm`)

```frameassembly
host cygnet_host { ip 10.40.1.10 }
host roc800_rtu  { ip 10.40.20.1 }

compile {
    cygnet_host -> roc800_rtu tcp syn srcport 54000 dstport 4000 wait 1ms
    cygnet_host <- roc800_rtu tcp syn ack wait 1ms
    cygnet_host -> roc800_rtu tcp ack wait 1ms
    cygnet_host -> roc800_rtu rocplus read dst 1 group 2 src 3 type 3 addr 0 param 14 wait 5ms
    cygnet_host <- roc800_rtu rocplus read isresponse dst 3 group 0 src 1 type 3 addr 0 param 14 value 850
}
```

### Automatic Wire Calculations

- Defaults to stateful TCP port `4000` (`transport udp` switches to UDP `4000`) and calculates byte 5 (`Data Length`) automatically.
- Maps `read` to ROC Plus Opcode `180` (`Single/Multiple TLP Read`), `write` to Opcode `181` (`TLP Write`), and `error` to Opcode `255` (`Error Indicator`).
- Appends the exact 2-byte little-endian reflected **ROC CRC-16 (`0xa001`, init `0x0000`)** over Header + Data unless `crc` is overridden.

## Practical Lab Example: Midstream Pipeline Station Poll: ROC800 Analog Pressure TLP Read, Valve Setpoint Write & Error Response (`rocplus_pipeline_rtu_tlp.frasm`)

Polls discharge pressure TLP `(3, 0, 14)` on `ROC800` Unit `1` Group `2`, writes a regulator setpoint (`Opcode 181`), and tests an invalid-TLP error response (`Opcode 255`).

```frameassembly
host pipeline_scada { ip 172.23.40.5 }
host station_roc800 { ip 172.23.40.101 }

compile {
    pipeline_scada -> station_roc800 tcp syn srcport 52400 dstport 4000 wait 1ms
    pipeline_scada <- station_roc800 tcp syn ack wait 1ms
    pipeline_scada -> station_roc800 tcp ack wait 1ms
    // 1. Opcode 180: Read 1 TLP parameter (Point Type 3 Analog Input, Point 0, Param 14 Filtered EU)
    pipeline_scada -> station_roc800 rocplus read dst 1 group 2 src 10 type 3 addr 0 param 14 wait 6ms
    pipeline_scada <- station_roc800 rocplus read isresponse dst 10 group 0 src 1 type 3 addr 0 param 14 value 1120 wait 15ms
    // 2. Opcode 181: Write TLP Setpoint (Point Type 4 Analog Output, Point 0, Param 2)
    pipeline_scada -> station_roc800 rocplus write dst 1 group 2 src 10 type 4 addr 0 param 2 value 950 wait 6ms
    pipeline_scada <- station_roc800 rocplus write isresponse dst 10 group 0 src 1 wait 10ms
    // 3. Out-of-range TLP poll triggering ROC Error Indicator (Opcode 255)
    pipeline_scada -> station_roc800 rocplus read dst 1 group 2 src 10 type 99 addr 99 param 99 wait 6ms
    pipeline_scada <- station_roc800 rocplus error isresponse dst 10 group 0 src 1
}
```

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

# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'
frameassembly rocplus_pipeline_rtu_tlp.frasm rocplus_pipeline_rtu_tlp.pcap
frameassembly rocplus_pipeline_rtu_tlp.frasm rocplus_pipeline_rtu_tlp.pcapng

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

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

## All `rocplus` Keywords & Header Options

Packet line pattern: `src_host -> dst_host rocplus [read | write | error | opcode "<text_or_num>" | func "<text_or_num>"] [dst <0..255>] [group <0..255>] [src <0..255>] [type <0..255>] [addr <0..255>] [param <0..255>] [value <number>] [isresponse] [crc <0..65535>] [transport <tcp|udp>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `read \| write \| error \| opcode "<text_or_num>" \| func "<text_or_num>" \| [isresponse]` | 8-bit ROC Plus Opcode (`180` Read TLP, `181` Write TLP, `7` Read Clock, `8` Set Clock, `17` Logon, `255` Error) | `read (Opcode 180)` | Sets byte 4 (`Opcode`) of the 6-byte ROC Plus header and formats request vs `isresponse` TLP payloads. |
| `dst <0..255> \| group <0..255> \| src <0..255>` | 8-bit ROC Unit Address (`dst`, `src`) & Device Group (`group`) | `dst 1, group 2, src 3` | Writes bytes 0..3 (`ROC Unit`, `ROC Group`, `Host Unit`, `Host Group`) of the ROC Plus header. |
| `type <0..255> \| addr <0..255> \| param <0..255>` | 3-byte ROC `TLP` (`Point Type`, `Logical/Point Number`, `Parameter Number`) | `type 3, addr 0, param 0` | Encodes the 3-octet `(Type, Location/Number, Parameter)` tuple identifying a specific RTU variable. |
| `value <number>` | 32-bit little-endian TLP parameter value | `0` | Writes the 4-byte value inside `write` (`181`) requests or `read isresponse` (`180`) replies. |
| `crc <0..65535> \| transport <tcp\|udp>` | Optional 16-bit ROC CRC-16 override & L4 transport | `Auto 0xa001 CRC-16, transport tcp` | Overrides the trailing 2-byte little-endian CRC-16 or switches between TCP `4000` and UDP `4000`. |

## Cross-Layer Options Valid with `rocplus`

| 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). |
| `comment "<text>"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"`, `"de:ad:be:ef"`, or `"\x01\x02"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType 0..65535 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or standalone Layer 2 16-bit EtherType. |
| `fcs \| badfcs` | Ethernet CRC-32 trailer flags (choose one) | `Omitted` | `fcs` appends a valid IEEE 802.3 4-byte CRC-32 Frame Check Sequence trailer; `badfcs` XOR-corrupts the CRC-32 for NIC/tap negative tests. |
| `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>]` | Repeatable label stack (0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255) | `Unlabeled (auto bos=0 on outer labels, bos=1 on bottom)` | Prepends one or more 32-bit MPLS label shims (`0x8847`, e.g. `mpls 16000 mpls 24010`) ahead of Layer 2 EoMPLS or Layer 3 payloads. |
| `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>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 4000 (or UDP 4000 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport <tcp\|udp\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |
| `badchecksum \| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO 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`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |

## Common Mistakes & Quick Fixes

### Swap dst and src Unit Addresses and Add isresponse on RTU Replies

- **Valid v3.3.0 Syntax:** `host_scada -> rtu rocplus read dst 1 group 2 src 10 type 3 addr 0 param 14
host_scada <- rtu rocplus read isresponse dst 10 group 0 src 1 type 3 addr 0 param 14 value 500`

In ROC Plus, the replying RTU echoes the same `Opcode` (`180` on Read) while swapping `(Unit, Group)` addresses and returning the TLP data bytes (`isresponse`).

### ROC Plus Addresses (dst, group, src, type, addr, param) Are 8-Bit (0..255)

- **Avoid:** `host_scada -> rtu rocplus read dst 300`
- **Valid v3.3.0 Syntax:** `host_scada -> rtu rocplus read dst 1 group 2 src 10`

ROC unit/group and TLP coordinates are single octets (`0..=255`); combine `dst` (`Unit`) and `group` (`Group`) to address up to 65,000 RTUs.
