# nvmetcp — Port 4420 NVMe/TCP ICReq/ICResp & Fabrics Capsules (`nvmetcp`)

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

- **Full Protocol Name:** NVM Express over Fabrics TCP Transport (TP 8000)
- **Keyword:** `nvmetcp`
- **OSI Layer & Transport:** Layer 7 · TCP 4420
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** NVM Express TCP Transport 1.0c, NVMe Base Spec 2.0
- **Wireshark Display Filter:** `nvme-tcp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 4420 -> NVMe/TCP (NVMe-oF)`

## Overview

Disaggregated NVMe-oF storage over standard Ethernet on TCP `4420`: `nvmetcp` emits 128-byte `icreq`/`icresp` connection handshakes plus 72-byte NVMe Submission/Completion Capsules (`nsid`, `qid`, `offset`, `count`).

NVMe over TCP (`nvmetcp`, NVM Express TCP Transport Specification) delivers disaggregated NVMe SSD block storage across standard Ethernet data centers on **TCP port `4420`** without requiring lossless RDMA NICs. Every NVMe/TCP PDU starts with an **8-byte Common Header** (`PDU Type`, `Flags`, `Header Length HL`, `Payload Data Offset PDO`, and little-endian 32-bit `Packet Length PLEN`), beginning each queue TCP connection with a 128-byte **`ICReq` (`0x00`) <-> `ICResp` (`0x01`)** Initialize Connection handshake before exchanging 64-byte **`CapsuleCmd` (`0x04`)**, **`CapsuleResp` (`0x05`)**, **`H2CData` (`0x06`)**, **`C2HData` (`0x07`)**, and **`R2T` (`0x09`)** PDUs.

FrameAssembly encodes exact little-endian NVMe/TCP headers, 128-byte `ICReq`/`ICResp` structures, 64-byte NVMe Submission Queue Entries (`NSID`, `Command ID`, `SLBA`, `NLB`), and 16-byte Completion Queue Entries (`Status`, `QID`, `Command ID`).

## Minimal Quickstart (`nvmetcp_quickstart.frasm`)

```frameassembly
host k8s_worker  { ip 10.80.44.11 }
host nvme_target { ip 10.80.44.50 }

compile {
    k8s_worker -> nvme_target tcp syn srcport 52420 dstport 4420 win 65535 mss 8960 wait 1ms
    k8s_worker <- nvme_target tcp syn ack win 65535 mss 8960 wait 1ms
    k8s_worker -> nvme_target tcp ack wait 1ms
    k8s_worker -> nvme_target nvmetcp icreq wait 1ms
    k8s_worker <- nvme_target nvmetcp icresp wait 2ms
    k8s_worker -> nvme_target nvmetcp read qid 1 reqid 10 nsid 1 offset 0 count 8 wait 1ms
    k8s_worker <- nvme_target nvmetcp response qid 1 reqid 10 status 0
}
```

### Automatic Wire Calculations

- Defaults to stateful TCP port `4420` and calculates little-endian `HL` (Header Length), `PDO` (Payload Data Offset), and 32-bit `PLEN` (Total PDU Length) automatically for every PDU type.
- Emits full 128-byte `ICReq` (`0x00`) and `ICResp` (`0x01`) connection-initialization frames (`PFFORMAT = 0`, `MAXR2T` / `MAXH2CDATA`) required by Wireshark’s `nvme-tcp` state tracker.
- Encodes 64-byte NVMe SQE capsules (`0x01` Write, `0x02` Read, `0x7f` Fabrics Connect) and 16-byte CQE responses (`Status << 1 | Phase`).

## Practical Lab Example: NVMe/TCP I/O Queue Bring-Up: ICReq/ICResp, NVMe Write (R2T + H2CData) & NVMe Read (C2HData) (`nvmetcp_io_queue_flow.frasm`)

Initializes an NVMe/TCP queue on TCP `4420`, performs a Ready-to-Transfer (`R2T`) host-to-controller write to Namespace `1`, and reads blocks back via Controller-to-Host Data (`C2HData`).

```frameassembly
host spdk_init { ip 172.29.44.10 }
host jbof_tgt  { ip 172.29.44.80 }

compile {
    spdk_init -> jbof_tgt tcp syn srcport 53420 dstport 4420 dscp 26 df wait 1ms
    spdk_init <- jbof_tgt tcp syn ack dscp 26 df wait 1ms
    spdk_init -> jbof_tgt tcp ack dscp 26 df wait 1ms
    // 1. 128-byte Initialize Connection Request (0x00) & Response (0x01)
    spdk_init -> jbof_tgt nvmetcp icreq wait 1ms
    spdk_init <- jbof_tgt nvmetcp icresp wait 2ms
    // 2. NVMe Write CapsuleCmd (Opcode 0x01) -> Target R2T (0x09) -> Host H2CData (0x06) -> CapsuleResp (0x05)
    spdk_init -> jbof_tgt nvmetcp write qid 1 reqid 101 nsid 1 offset 2048 count 8 wait 1ms
    spdk_init <- jbof_tgt nvmetcp r2t reqid 101 offset 0 count 4096 wait 1ms
    spdk_init -> jbof_tgt nvmetcp h2cdata reqid 101 offset 0 payload "NVME-4K-PAGE-PAYLOAD" flags 0x04 wait 1ms
    spdk_init <- jbof_tgt nvmetcp response qid 1 reqid 101 status 0 wait 3ms
    // 3. NVMe Read CapsuleCmd (Opcode 0x02) -> Controller C2HData (0x07, LAST_PDU|SUCCESS)
    spdk_init -> jbof_tgt nvmetcp read qid 1 reqid 102 nsid 1 offset 2048 count 8 wait 1ms
    spdk_init <- jbof_tgt nvmetcp c2hdata reqid 102 offset 0 payload "NVME-4K-PAGE-PAYLOAD" flags 0x0c wait 1ms
    spdk_init <- jbof_tgt nvmetcp response qid 1 reqid 102 status 0
}
```

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

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

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

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

## All `nvmetcp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host nvmetcp [icreq | icresp | read | write | response | h2cdata | c2hdata | r2t | msgtype "<text>" | cmd "<text>"] [opcode <0..255>] [nsid <number>] [qid <0..65535>] [reqid <0..65535>] [flags <0..255>] [status <0..65535>] [offset <number>] [count <number>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `icreq \| icresp \| read \| write \| response \| h2cdata \| c2hdata \| r2t \| msgtype "<text>" \| cmd "<text>"` | NVMe/TCP PDU Type or NVMe Command selector | `icreq (0x00)` | Selects `0x00` ICReq, `0x01` ICResp, `0x04` CapsuleCmd (`read` NVMe `0x02`, `write` NVMe `0x01`), `0x05` CapsuleResp, `0x06` H2CData, `0x07` C2HData, or `0x09` R2T. |
| `opcode <0..255>` | 8-bit NVMe SQE Opcode override | `0x02 (Read) / 0x01 (Write) / 0x06 (Identify)` | Sets byte 0 of the 64-byte NVMe Submission Queue Entry inside `CapsuleCmd`. |
| `nsid <number>` | 32-bit NVMe Namespace Identifier (`1..0xffffffff`) | `1` | Writes little-endian `NSID` in bytes 4..7 of the NVMe SQE. |
| `qid <0..65535> \| reqid <0..65535>` | 16-bit Queue ID (`0` Admin, `1+` I/O) & Command ID (`CID`) | `qid 1, reqid 1` | Writes the 16-bit `Command ID` (`CID`) and Completion `SQID` correlating capsules and data PDUs. |
| `offset <number> \| count <number>` | Starting LBA / Data Offset and Block / Byte Transfer Count | `offset 0, count 1 (or payload len)` | Sets SQE `SLBA` + `NLB` on `read`/`write`, or `DATAO` + `DATAL` on `h2cdata`/`c2hdata`/`r2t`. |
| `flags <0..255> \| status <0..65535>` | 8-bit PDU Header Flags (`0x04` LAST_PDU, `0x08` SUCCESS) & 15-bit NVMe CQE Status | `flags 0, status 0 (Success)` | Sets Common Header byte 1 (`FLAGS`) and CQE Status Field (`0` = Successful Completion). |

## Cross-Layer Options Valid with `nvmetcp`

| 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 4420` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 4420)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |
| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |
| `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` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |

## Common Mistakes & Quick Fixes

### Begin NVMe/TCP Captures with icreq and icresp for Full Wireshark Dissection

- **Valid v3.3.0 Syntax:** `init -> tgt nvmetcp icreq
init <- tgt nvmetcp icresp
init -> tgt nvmetcp read nsid 1`

Wireshark’s `nvme-tcp` dissector learns PDU alignment and digest settings from the initial `ICReq`/`ICResp` exchange on TCP `4420`.

### Keep reqid Consistent Across CapsuleCmd, R2T/Data, and CapsuleResp

- **Valid v3.3.0 Syntax:** `init -> tgt nvmetcp read reqid 7 nsid 1
init <- tgt nvmetcp response reqid 7 status 0`

`reqid` populates the 16-bit NVMe Command Identifier (`CID`) used to match asynchronous data transfers and completions.
