跳到主要内容

3. SCTP 分组格式

SCTP 分组由公共头部和 chunk 组成. Chunk 包含控制信息或用户数据.

SCTP 分组格式如下:

     0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Common Header |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Chunk #1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Chunk #n |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

多个 chunk 可被捆绑到一个 SCTP 分组中, 直到 MTU 大小为止, 但 INIT,INIT ACK 和 SHUTDOWN COMPLETE chunk 除外. 这些 chunk 不得与任何其他 chunk 捆绑在同一分组中. Chunk 捆绑的更多细节见 Section 6.10.

如果用户数据消息无法放入一个 SCTP 分组, 可使用 Section 6.9 中定义的过程将其分片为多个 chunk.

除非另有说明, SCTP 分组中的所有整数字段必须以网络字节序传输.

3.1. SCTP 公共头部字段说明

SCTP 公共头部格式

     0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port Number | Destination Port Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Verification Tag |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Source Port Number: 16 bits (unsigned integer)

这是 SCTP 发送方的端口号. 接收方可将其与源 IP 地址,SCTP 目的端口以及可能的目的 IP 地址结合使用, 以标识该分组所属的关联. 端口号 0 不得使用.

Destination Port Number: 16 bits (unsigned integer)

这是该分组发往的 SCTP 端口号. 接收主机会使用该端口号将 SCTP 分组解复用到正确的接收端点/应用. 端口号 0 不得使用.

Verification Tag: 32 bits (unsigned integer)

该分组的接收方使用 Verification Tag 验证此 SCTP 分组的发送方. 发送时, 此 Verification Tag 的值必须设置为关联初始化期间从对等端点收到的 Initiate Tag 值, 但以下例外:

  • 包含 INIT chunk 的分组必须具有零 Verification Tag.

  • 包含设置了 T bit 的 SHUTDOWN COMPLETE chunk 的分组必须从带有 SHUTDOWN ACK chunk 的分组中复制 Verification Tag.

  • 包含 ABORT chunk 的分组可从导致发送该 ABORT 的分组中复制 verification tag. 详细信息见 Section 8.4 和 Section 8.5.

INIT chunk 必须是承载它的 SCTP 分组中的唯一 chunk.

Checksum: 32 bits (unsigned integer)

该字段包含此 SCTP 分组的校验和. 其计算见 Section 6.8. SCTP 使用 Appendix B 中描述的 CRC32c 算法计算校验和.

3.2. Chunk 字段说明

下图说明 SCTP 分组中要传输的 chunk 的字段格式. 每个 chunk 由 Chunk Type 字段,chunk 特定的 Flag 字段,Chunk Length 字段和 Value 字段组成.

     0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Chunk Type | Chunk Flags | Chunk Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\ \
/ Chunk Value /
\ \
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Chunk Type: 8 bits (unsigned integer)

该字段标识 Chunk Value 字段中包含的信息类型. 取值范围为 0 到 254. 值 255 保留用于将来的扩展字段.

Chunk Type 的值定义如下:

ID Value    Chunk Type
----- ----------
0 - Payload Data (DATA)
1 - Initiation (INIT)
2 - Initiation Acknowledgement (INIT ACK)
3 - Selective Acknowledgement (SACK)
4 - Heartbeat Request (HEARTBEAT)
5 - Heartbeat Acknowledgement (HEARTBEAT ACK)
6 - Abort (ABORT)
7 - Shutdown (SHUTDOWN)
8 - Shutdown Acknowledgement (SHUTDOWN ACK)
9 - Operation Error (ERROR)
10 - State Cookie (COOKIE ECHO)
11 - Cookie Acknowledgement (COOKIE ACK)
12 - Reserved for Explicit Congestion Notification Echo (ECNE)
13 - Reserved for Congestion Window Reduced (CWR)
14 - Shutdown Complete (SHUTDOWN COMPLETE)
15 to 62 - available
63 - reserved for IETF-defined Chunk Extensions
64 to 126 - available
127 - reserved for IETF-defined Chunk Extensions
128 to 190 - available
191 - reserved for IETF-defined Chunk Extensions
192 to 254 - available
255 - reserved for IETF-defined Chunk Extensions

Chunk Type 的编码方式使最高 2 bit 指定处理端点不识别该 Chunk Type 时必须采取的动作.

00 - Stop processing this SCTP packet and discard it, do not
process any further chunks within it.

01 - Stop processing this SCTP packet and discard it, do not
process any further chunks within it, and report the
unrecognized chunk in an 'Unrecognized Chunk Type'.

10 - Skip this chunk and continue processing.

11 - Skip this chunk and continue processing, but report in an
ERROR chunk using the 'Unrecognized Chunk Type' cause of error.

注: ECNE 和 CWR chunk type 保留用于将来的 Explicit Congestion Notification (ECN); 见 Appendix A.

Chunk Flags: 8 bits

这些 bit 的用法取决于 Chunk Type 字段给出的 chunk type. 除非另有说明, 发送时将其设置为 0, 接收时忽略.

Chunk Length: 16 bits (unsigned integer)

该值表示 chunk 的字节大小, 包括 Chunk Type,Chunk Flags,Chunk Length 和 Chunk Value 字段. 因此, 如果 Chunk Value 字段长度为零, Length 字段将设置为 4. Chunk Length 字段不计入任何 chunk 填充.

发送方使用全零字节将 chunk (包括 Type,Length 和 Value 字段) 填充到 4 字节整数倍长度. 此填充总计不得超过 3 字节. Chunk Length 值不包括 chunk 末尾填充. 但它包括 chunk 中除最后一个参数外任何可变长度参数的填充. 接收方必须忽略填充.

注: 健壮的实现应接受无论最终填充是否包含在 Chunk Length 中的 chunk.

Chunk Value: variable length

Chunk Value 字段包含要在 chunk 中传输的实际信息. 该字段的用法和格式取决于 Chunk Type.

Chunk 的总长度 (包括 Type,Length 和 Value 字段) 必须是 4 字节的整数倍. 如果 chunk 长度不是 4 字节的整数倍, 发送方必须使用全零字节填充该 chunk, 且此填充不包含在 Chunk Length 字段中. 发送方不得填充超过 3 字节. 接收方必须忽略填充字节.

SCTP 定义的 chunk 在 Section 3.3 中详细描述. IETF 定义 chunk 扩展的指南见本文档 Section 14.1.

3.2.1. 可选/可变长度参数格式

SCTP 控制 chunk 的 chunk value 由 chunk type 特定的必需字段头部组成, 后跟零个或多个参数. Chunk 中包含的可选和可变长度参数采用 Type-Length-Value 格式定义, 如下所示.

     0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Parameter Type | Parameter Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\ \
/ Parameter Value /
\ \
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Chunk Parameter Type: 16 bits (unsigned integer)

Type 字段是 16 位参数类型标识符. 取值范围为 0 到 65534.

值 65535 保留给 IETF 定义的扩展. 除特定 SCTP chunk 描述中定义的值外, 其他值均保留给 IETF 使用.

Chunk Parameter Length: 16 bits (unsigned integer)

Parameter Length 字段包含参数的字节大小, 包括 Parameter Type,Parameter Length 和 Parameter Value 字段. 因此, Parameter Value 字段长度为零的参数, 其 Length 字段为 4. Parameter Length 不包括任何填充字节.

Chunk Parameter Value: variable length

Parameter Value 字段包含要在参数中传输的实际信息.

参数的总长度 (包括 Type,Parameter Length 和 Value 字段) 必须是 4 字节的整数倍. 如果参数长度不是 4 字节的整数倍, 发送方在参数末尾 (即 Parameter Value 字段之后) 使用全零字节填充该参数. 填充长度不包含在 Parameter Length 字段中. 发送方不得填充超过 3 字节. 接收方必须忽略填充字节.

Parameter Type 的编码方式使最高 2 bit 指定处理端点不识别该 Parameter Type 时必须采取的动作.

00 - Stop processing this parameter; do not process any further
parameters within this chunk.

01 - Stop processing this parameter, do not process any further
parameters within this chunk, and report the unrecognized
parameter in an 'Unrecognized Parameter', as described in Section 3.2.2.

10 - Skip this parameter and continue processing.

11 - Skip this parameter and continue processing but report the
unrecognized parameter in an 'Unrecognized Parameter', as
described in Section 3.2.2.

请注意, 在以上四种情况下都会发送 INIT ACK 或 COOKIE ECHO chunk. 在 00 或 01 情况下, 未知参数之后的参数处理被取消, 但已经完成的处理不会回滚.

实际 SCTP 参数在具体的 SCTP chunk 小节中定义. IETF 定义参数扩展的规则见 Section 14.2. 注意, 参数类型必须在所有 chunk 中保持唯一. 例如, 参数类型 '5' 用于表示 IPv4 地址 (见 Section 3.3.2.1). 因此值 '5' 在所有 chunk 中均保留用于表示 IPv4 地址,不得在任何其他 chunk 中以不同含义重用.

3.2.2. 未识别参数的报告

如果 INIT chunk 的接收方检测到未识别参数, 并且根据 Section 3.2.1 必须报告它们, 它必须将 'Unrecognized Parameter' 参数放入响应 INIT chunk 而发送的 INIT ACK chunk 中. 请注意, 如果 INIT chunk 的接收方不打算建立关联 (例如由于资源不足), 则发送给 INIT 发送方的任何 ABORT 中不会包含 'Unrecognized Parameter'.

如果 INIT ACK chunk 的接收方检测到未识别参数, 并且根据 Section 3.2.1 必须报告它们, 它应该将包含 'Unrecognized Parameters' 错误原因的 ERROR chunk 与响应 INIT ACK chunk 而发送的 COOKIE ECHO chunk 捆绑. 如果 INIT ACK 的接收方无法将 COOKIE ECHO chunk 与 ERROR chunk 捆绑, ERROR chunk 可以单独发送, 但不得早于收到 COOKIE ACK.

注: 每当 COOKIE ECHO 在分组中发送时, 它必须是第一个 chunk.

3.3. SCTP Chunk 定义

本节定义不同 SCTP chunk type 的格式.

: 由于 Section 3.3 包含大量小节 (3.3.1 到 3.3.13), 详细说明各种 chunk type (DATA,INIT,INIT ACK,SACK 等), 这些内容将在后续文档中继续.