# sv — IEC 61850-9-2 Process-Bus Merging Unit Waveforms (0x88ba) (`sv`)

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

- **Full Protocol Name:** IEC 61850-9-2 Substation Sampled Values (Process Bus)
- **Keyword:** `sv`
- **OSI Layer & Transport:** Layer 2 · EtherType 0x88ba
- **Host Endpoint Rule:** MAC-Only or IP
- **Standards:** IEC 61850-9-2, IEC 61869-9 (9-2LE)
- **Wireshark Display Filter:** `sv`
- **Wire Encapsulation:** `Ethernet II -> IEC 61850 SV (EtherType 0x88ba)`

## Overview

Pair `sv` (`0x88ba` Merging Unit voltage/current ASDU waveforms) with `wait 208us` (4,800 Hz) and `.pcapng` nanosecond output to test digital-substation process-bus sensors offline.

Sampled Values (`sv`, IEC 61850-9-2 / 9-2LE) streams digitized three-phase current and voltage waveforms from substation Merging Units (`MU`) to protective relays over the IEC 61850 Process Bus (`EtherType 0x88ba`, multicast `01:0c:cd:04:00:00..ff`) at 4,000 or 4,800 frames per second (`250us` / `208us` intervals). Each frame carries an 8-byte header (`APPID 0x4000..0x7fff`, `Length`, `Reserved1`, `Reserved2`) wrapping an ASN.1 BER `savPdu` (`0x60`) containing one or more `ASDU` (`0x30`) blocks with `svID`, `smpCnt`, `confRev`, `smpSynch`, and 64-byte 9-2LE current/voltage sample arrays.

Combined with FrameAssembly v3.3.0's `repeat` block, sub-millisecond `wait 250us` timing, and nanosecond `.pcapng` output, `sv` generates precision process-bus waveforms without physical Merging Units.

## Minimal Quickstart (`sv_quickstart.frasm`)

```frameassembly
host merging_unit { mac 00:1b:21:92:00:01 }
host process_bus  { mac 01:0c:cd:04:00:01 }

compile {
    merging_unit -> process_bus sv appid 0x4001 svid "BAY01_MU01" smpcnt 0 confrev 1 smpsynch 2 vlan 300 pcp 4
}
```

### Automatic Wire Calculations

- Sets Ethernet II EtherType to `0x88ba` (IEC 61850 Sampled Values), defaults `APPID` to `0x4000`, and sets bit `0x8000` in `Reserved1` when `simulation` is present.
- Encodes the ASN.1 BER `savPdu` (`0x60`) -> `noASDU = 1` -> `seqASDU` (`0xa2`) -> `ASDU` (`0x30`) with exact BER length tags and a 64-byte 4xI + 4xV 9-2LE sample dataset.
- Targets IEC 61850-9-2 multicast destination MAC `01:0c:cd:04:00:01` automatically when `dstmac` is omitted on default hosts.

## Practical Lab Example: 250-Microsecond Merging Unit Stream With PTP Sync Loss Transition (`sv_merging_unit_stream.frasm`)

Emits 4 consecutive 50Hz 9-2LE Sampled Values frames (`wait 250us`) where the Merging Unit transitions from global PTP lock (`smpsynch 2`) to holdover (`smpsynch 0`) on sample 3.

```frameassembly
host mu_bay01  { mac 00:1b:21:92:10:01 }
host sv_mcast  { mac 01:0c:cd:04:00:01 }

compile {
    // 80 samples/cycle @ 50Hz = 250us inter-frame gap (compile to .pcapng for 1ns fidelity)
    mu_bay01 -> sv_mcast sv appid 0x4001 svid "SUB1_BAY01_MU" smpcnt 0 confrev 1 smpsynch 2 smprate 80 vlan 300 pcp 4 wait 250us
    mu_bay01 -> sv_mcast sv appid 0x4001 svid "SUB1_BAY01_MU" smpcnt 1 confrev 1 smpsynch 2 smprate 80 vlan 300 pcp 4 wait 250us
    mu_bay01 -> sv_mcast sv appid 0x4001 svid "SUB1_BAY01_MU" smpcnt 2 confrev 1 smpsynch 2 smprate 80 vlan 300 pcp 4 wait 250us
    // Merging Unit loses PTP grandmaster lock (smpsynch drops from 2 -> 0)
    mu_bay01 -> sv_mcast sv appid 0x4001 svid "SUB1_BAY01_MU" smpcnt 3 confrev 1 smpsynch 0 smprate 80 vlan 300 pcp 4
}
```

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

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

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

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

## All `sv` Keywords & Header Options

Packet line pattern: `src_host -> dst_host sv [appid <0..65535>] [svid "<text>"] [datset "<text>"] [smpcnt <0..65535>] [confrev <number>] [smpsynch <0|1|2>] [smprate <0..65535>] [simulation]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `appid <0..65535>` | 16-bit IEC 61850 SV APPID (0x4000..0x7fff) | `0x4000` | Sets bytes 0..1 of the 8-byte Sampled Values header. |
| `svid "<text>"` | Sampled Values Identifier string (10..34 chars typical) | `"MU01"` | Encodes ASDU context tag `[0]` (`svID`). |
| `datset "<text>"` | Optional dataset reference string | `Omitted unless set (per 9-2LE)` | Encodes optional ASDU context tag `[1]` (`datSet`). |
| `smpcnt <0..65535>` | 16-bit Sample Counter (0..3999 or 0..4799) | `0` | Encodes ASDU context tag `[2]` (`smpCnt`, resets to `0` on each 1-PPS second boundary). |
| `confrev <number>` | 32-bit Configuration Revision | `1` | Encodes ASDU context tag `[3]` (`confRev`). |
| `smpsynch <0\|1\|2>` | Clock sync state (0=None, 1=Local, 2=Global PTP) | `2 (Global synchronized)` | Encodes ASDU context tag `[5]` (`smpSynch` synchronization status byte). |
| `smprate <0..65535>` | Samples per nominal period (e.g. 80 or 256) | `Omitted unless set` | Encodes optional ASDU context tag `[6]` (`smpRate`). |
| `simulation` | Boolean test-mode flag | `Unset` | Sets bit 15 (`0x8000`) of `Reserved1` in the 8-byte IEC 61850 SV header. |

## Cross-Layer Options Valid with `sv`

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

## Common Mistakes & Quick Fixes

### Standard SV APPID Range Is 0x4000..0x7fff (GOOSE Uses 0x0000..0x3fff)

- **Avoid:** `mu1 -> bus sv app_id 0x1000 smp_cnt 1`
- **Valid v3.3.0 Syntax:** `mu1 -> bus sv appid 0x4001 smpcnt 1`

Use strict lowercase `appid`, `svid`, `smpcnt`, `smpsynch`, `smprate`, and `confrev` without underscores, and keep `appid` in `0x4000..0x7fff` so substation switches classify SV traffic properly.

### smpsynch Accepts 0, 1, or 2

- **Avoid:** `mu1 -> bus sv smpsynch 5`
- **Valid v3.3.0 Syntax:** `mu1 -> bus sv smpsynch 2`

IEC 61850-9-2 defines `0` (not synchronized), `1` (synchronized by local area clock), and `2` (synchronized by global area clock).
