23、移动网络 SCTP协议

 学习内容来自趣谈网络协议-像小说一样的网络协议入门课    第23讲 | 移动网络:去巴塞罗那,手机也上不了脸书

一、移动网络发展

2G:手机通过发无线信号连接基站;基站一面朝前接无线,一面朝后接核心网;核心网一面朝前接基站请求,一是判断是否合   法,二是判断是不是本地号,有没有钱,一面通过网关连接电话网络;

3G:

4G:

23、移动网络 SCTP协议

23、移动网络 SCTP协议


SCTP 的第一个特点是多宿主。一台机器可以有多个网卡,而对...

极客时间版权所有: https://time.geekbang.org/column/article/10534

今天早上路上正好听看了一节课23、移动网络 SCTP协议,其中印象最深的就是SCTP协议;先来一段维基百科流控制传输协议:

串流控制传输协议英语:Stream Control Transmission Protocol简写 SCTP)是在2000年由 IETFSIGTRAN 工作组定义的一个传输层协议。RFC 4960 详细地定义了 SCTP,介绍性的文档是RFC 3286

作为一个传输层协议,SCTP 可以理解为和 TCPUDP 相类似的。它提供的服务有点像 TCP,又同时将 UDP 的一些优点相结合。是一种提供了可靠、高效、有序的数据传输协议。相比之下 TCP 是面向字节的,而 SCTP 是针对成帧的消息。

SCTP 主要的贡献是对多重联外线路的支持,一个端点可以由多于一个 IP地址 组成,使得传输可在主机间或网卡间做到透明的网络容错备援。

SCTP 最初是被设计用于在 IP 上传输电话协议(SS7),把 SS7 信令网络的一些可靠特性引入 IP。IETF 的这方面的工作称为信令传输 SIGTRAN。

SCTP将资料传给应用层的方式,是将资料视为message(bytes的集合),SCTP的特征是message-oriented,意思就是说它传送的是一串message(每一个message是byte为单位的集合),相对于TCP是以byte为单位,传送的是破碎的串流。在SCTP发送端用一个动作送出讯息,接收端也是用一个动作取出讯息传给对应的应用程序。相较于TCP,是一个串流导向的协定,可靠地且有顺序地传送以bytes为单位的串流。然而TCP并不允许接收端知道发送端的应用程序呼叫送出bytes集合的次数。在发送端TCP只是简单的附加更多bytes在queue里等待着送到网络上,而SCTP是将要送出的outband message都保有自己独立的queue。

再翻RFC 4960,

SCTPoffers the following services to its users:

  --  acknowledged error-free non-duplicated transfer of user data, 无错误 无重复传输

   --  data fragmentation to conform to discovered path MTU size,    以最大传输单元的大小 数据分片

   --  sequenced delivery of user messages within multiple streams, with
       an option for order-of-arrival delivery of individual user messages, 多个流

   --  optional bundling of multiple user messages into a single SCTP packet, and  多个user messages绑定到一个SCTP包传输

   --  network-level fault tolerance through supporting of multi-homing  通过多宿主连接支持网络故障容错
       at either or both ends of an association.

Motivation of SCTP:当然是因为原有的TCP和UDP有缺陷

However, an increasing number of recent applications have found TCP too limiting, and have
   incorporated their own reliable data transfer protocol on top of UDP
   [RFC0768].  The limitations that users have wished to bypass include
   the following:

   -- TCP provides both reliable data transfer and strict order-of-
      transmission delivery of data.  Some applications need reliable
      transfer without sequence maintenance, while others would be
      satisfied with partial ordering of the data.  In both of these
      cases, the head-of-line blocking offered by TCP causes unnecessary
      delay. 可靠、有序(这里应该有马哲的声音:论事物的两面性)

   -- The stream-oriented nature of TCP is often an inconvenience.
      Applications must add their own record marking to delineate 勾画,描述their
      messages, and must make explicit use of the push facility to
      ensure that a complete message is transferred in a reasonable
      time.  基于流的特性,数据要完整及时

   -- The limited scope of TCP sockets complicates the task of providing
      highly-available data transfer capability using multi-homed hosts. TCP套接字范围有限,不能使用多宿主连接提供高可用数据传输

   -- TCP is relatively vulnerable to denial-of-service attacks, such as 皮薄血脆,容易受到DOS攻击
      SYN attacks.
       _____________                                      _____________
      |  SCTP User  |                                    |  SCTP User  |
      | Application |                                    | Application |
      |-------------|                                    |-------------|
      |    SCTP     |                                    |    SCTP     |
      |  Transport  |                                    |  Transport  |
      |   Service   |                                    |   Service   |
      |-------------|                                    |-------------|
      |             |One or more    ----      One or more|             |
      | IP Network  |IP address      \/        IP address| IP Network  |
      |   Service   |appearances     /\       appearances|   Service   |
      |_____________|               ----                 |_____________|

        SCTP Node A |<-------- Network transport ------->| SCTP Node B

                         Figure 1: An SCTP Association

1.3 Key Terms 术语

  o  Active destination transport address: A transport address on a
      peer endpoint that a transmitting endpoint considers available for
      receiving user messages.

   o  Bundling: An optional multiplexing operation, whereby more than
      one user message may be carried in the same SCTP packet.  Each
      user message occupies its own DATA chunk.

   o  Chunk: A unit of information within an SCTP packet, consisting of
      a chunk header and chunk-specific content.

   o  Congestion window (cwnd): An SCTP variable that limits the data,  拥塞窗口
      in number of bytes, a sender can send to a particular destination
      transport address before receiving an acknowledgement.

   o  Cumulative TSN Ack Point: The TSN of the last DATA chunk
      acknowledged via the Cumulative TSN Ack field of a SACK.
      TSN:Transmission Sequence Number,传输队列号,是Mac-hs PDU的6比特的头结构。
      ***累积通知

  o  Idle destination address: An address that has not had user
      messages sent to it within some length of time, normally the
      HEARTBEAT interval or greater.

   o  Inactive destination transport address: An address that is
      considered inactive due to errors and unavailable to transport
      user messages.

   o  Message = user message: Data submitted to SCTP by the Upper Layer
      Protocol (ULP).

   o  Message Authentication Code (MAC): An integrity check mechanism
      based on cryptographic hash functions using a secret key.
      Typically, message authentication codes are used between two
      parties that share a secret key in order to validate information
      transmitted between these parties.  In SCTP, it is used by an
      endpoint to validate the State Cookie information that is returned
      from the peer in the COOKIE ECHO chunk.  The term "MAC" has
      different meanings in different contexts.  SCTP uses this term
      with the same meaning as in [RFC2104].

   o  Network Byte Order: Most significant byte first, a.k.a., big
      endian.

   o  Ordered Message: A user message that is delivered in order with
      respect to all previous user messages sent within the stream on
      which the message was sent.

   o  Outstanding TSN (at an SCTP endpoint): A TSN (and the associated
      DATA chunk) that has been sent by the endpoint but for which it
      has not yet received an acknowledgement.

   o  Path: The route taken by the SCTP packets sent by one SCTP
      endpoint to a specific destination transport address of its peer
      SCTP endpoint.  Sending to different destination transport
      addresses does not necessarily guarantee getting separate paths.

   o  Primary Path: The primary path is the destination and source
      address that will be put into a packet outbound to the peer
      endpoint by default.  The definition includes the source address
      since an implementation MAY wish to specify both destination and
      source address to better control the return path taken by reply
      chunks and on which interface the packet is transmitted when the
      data sender is multi-homed.

   o  Receiver Window (rwnd): An SCTP variable a data sender uses to
      store the most recently calculated receiver window of its peer, in
      number of bytes.  This gives the sender an indication of the space
      available in the receiver's inbound buffer.

   o  SCTP association: A protocol relationship between SCTP endpoints,
      composed of the two SCTP endpoints and protocol state information
      including Verification Tags and the currently active set of
      Transmission Sequence Numbers (TSNs), etc.  An association can be
      uniquely identified by the transport addresses used by the
      endpoints in the association.  Two SCTP endpoints MUST NOT have
      more than one SCTP association between them at any given time.

   o  SCTP endpoint: The logical sender/receiver of SCTP packets.  On a
      multi-homed host, an SCTP endpoint is represented to its peers as
      a combination of a set of eligible destination transport addresses
      to which SCTP packets can be sent and a set of eligible source
      transport addresses from which SCTP packets can be received.  All
      transport addresses used by an SCTP endpoint must use the same
      port number, but can use multiple IP addresses.  A transport
      address used by an SCTP endpoint must not be used by another SCTP
      endpoint.  In other words, a transport address is unique to an
      SCTP endpoint.

   o  SCTP packet (or packet): The unit of data delivery across the
      interface between SCTP and the connectionless packet network
      (e.g., IP).  An SCTP packet includes the common SCTP header,
      possible SCTP control chunks, and user data encapsulated within
      SCTP DATA chunks.

   o  SCTP user application (SCTP user): The logical higher-layer
      application entity which uses the services of SCTP, also called
      the Upper-Layer Protocol (ULP).

   o  Slow-Start Threshold (ssthresh): An SCTP variable.  This is the 慢启动阈值
      threshold that the endpoint will use to determine whether to
      perform slow start or congestion avoidance on a particular
      destination transport address.  Ssthresh is in number of bytes.

   o  Stream: A unidirectional logical channel established from one to
      another associated SCTP endpoint, within which all user messages
      are delivered in sequence except for those submitted to the
      unordered delivery service.

 SCTP User Application

            -----------------------------------------------------
             _____________                  ____________________
            |             |                | Sequenced Delivery |
            | Association |                |   within Streams   |
            |             |                |____________________|
            |   Startup   |
            |             |         ____________________________
            |     and     |        |    User Data Fragmentation |
            |             |        |____________________________|
            |   Takedown  |
            |             |         ____________________________
            |             |        |     Acknowledgement        |
            |             |        |          and               |
            |             |        |    Congestion Avoidance    |拥塞避免
            |             |        |____________________________|
            |             |
            |             |         ____________________________
            |             |        |       Chunk Bundling       |
            |             |        |____________________________|
            |             |
            |             |     ________________________________
            |             |    |      Packet Validation         |
            |             |    |________________________________|
            |             |
            |             |     ________________________________
            |             |    |     Path Management            |
            |_____________|    |________________________________|

              Figure 2: Functional View of the SCTP Transport Service
The SCTP packet format is shown below:

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

   Multiple chunks can be bundled into one SCTP packet up to the MTU
   size, except for the INIT, INIT ACK, and SHUTDOWN COMPLETE chunks.
 SCTP Common Header Format

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

看到一篇好的文章  SCTP协议详解

先这样 干活去了23、移动网络 SCTP协议