Presentation is loading. Please wait.

Presentation is loading. Please wait.

7.9 TCP Socket Options 7.10 SCTP Socket Options 7.11 fcntl Function 7.12 Summary 報告者 : 梁凱鈞.

Similar presentations


Presentation on theme: "7.9 TCP Socket Options 7.10 SCTP Socket Options 7.11 fcntl Function 7.12 Summary 報告者 : 梁凱鈞."— Presentation transcript:

1 7.9 TCP Socket Options 7.10 SCTP Socket Options 7.11 fcntl Function 7.12 Summary 報告者 : 梁凱鈞

2 7.9 TCP Socket Options There are two socket options for TCP. We specify the level as IPPROTO_TCP. TCP_MAXSEG Socket Option TCP_NODELAY Socket Option

3 TCP_MAXSEG Socket Option This socket option allows us to fetch or set the MSS for a TCP connection. The value returned is the maximum amount of data that our TCP will send to the other end; often, it is the MSS announced by the other end with its SYN, unless our TCP chooses to use a smaller value than the peer's announced MSS. If this value is fetched before the socket is connected, the value returned is the default value that will be used if an MSS option is not received from the other end.

4 The maximum amount of data that our TCP will send per segment can also change during the life of a connection if TCP supports path MTU discovery. If the route to the peer changes, this value can go up or down. Once the connection is established, this value is the MSS option announced by the peer, and we cannot exceed that value. Our TCP, however, can always send less than the peer's announced MSS.

5 TCP_NODELAY Socket Option If set, this option disables TCP's Nagle algorithm. By default, this algorithm is enabled. The purpose of the Nagle algorithm is to reduce the number of small packets on a WAN. The algorithm states that if a given connection has outstanding data (i.e., data that our TCP has sent, and for which it is currently awaiting an acknowledgment), then no small packets will be sent on the connection in response to a user write operation until the existing data is acknowledged.

6 the Nagle algorithm The definition of a "small" packet is any packet smaller than the MSS. TCP will always send a full-sized packet if possible; the purpose of the Nagle algorithm is to prevent a connection from having multiple small packets outstanding at any time. The two common generators of small packets are the Rlogin and Telnet clients, since they normally send each keystroke as a separate packet.

7

8

9 the delayed ACK algorithm The Nagle algorithm often interacts with another TCP algorithm: the delayed ACK algorithm. This algorithm causes TCP to not send an ACK immediately when it receives data; instead, TCP will wait some small amount of time (typically 50–200 ms) and only then send the ACK. The hope is that in this small amount of time, there will be data to send back to the peer, and the ACK can piggyback with the data, saving one TCP segment.

10 Problem The problem is with other clients whose servers do not generate traffic in the reverse direction on which ACKs can piggyback. These clients can detect noticeable delays because the client TCP will not send any data to the server until the server's delayed ACK timer expires. These clients need a way to disable the Nagle algorithm, hence the TCP_NODELAY option.

11 Another type of client Another type of client that interacts badly with the Nagle algorithm and TCP's delayed ACKs is a client that sends a single logical request to its server in small pieces. Some problem

12 Three way To solve problem 1.Use writev (Section 14.4) instead of two calls to write. A single call to writev ends up with one call to TCP output instead of two calls, resulting in one TCP segment for our example. This is the preferred solution.Section 14.4 2. Copy the 4 bytes of data and the 396 bytes of data into a single buffer and call write once for this buffer. 3. Set the TCP_NODELAY socket option and continue to call write two times. This is the least desirable solution, and is harmful to the network, so it generally should not even be considered.

13 7.10 SCTP Socket Options The relatively large number of socket options for SCTP (17 at present writing) reflects the finer grain of control SCTP provides to the application developer. We specify the level as IPPROTO_SCTP.

14 SCTP_ADAPTION_LAYER Socket Option SCTP_ASSOCINFO Socket Option SCTP_AUTOCLOSE Socket Option SCTP_DEFAULT_SEND_PARAM Socket Option SCTP_DISABLE_FRAGMENTS Socket Option SCTP_EVENTS Socket Option SCTP_GET_PEER_ADDR_INFO Socket Option SCTP_I_WANT_MAPPED_V4_ADDR Socket Option SCTP_INITMSG Socket Option SCTP_MAXBURST Socket Option

15 SCTP_MAXSEG Socket Option SCTP_NODELAY Socket Option SCTP_PEER_ADDR_PARAMS Socket Option SCTP_PRIMARY_ADDR Socket Option SCTP_RTOINFO Socket Option SCTP_SET_PEER_PRIMARY_ADDR Socket Option SCTP_STATUS Socket Option

16 SCTP_ADAPTION_LAYER Socket Option During association initialization, either endpoint may specify an adaption layer indication. This indication is a 32-bit unsigned integer that can be used by the two applications to coordinate any local application adaption layer. This option allows the caller to fetch or set the adaption layer indication that this endpoint will provide to peers. When fetching this value, the caller will only retrieve the value the local socket will provide to all future peers. To retrieve the peer's adaption layer indication, an application must subscribe to adaption layer events.

17 SCTP_ASSOCINFO Socket Option three purposes: (i) to retrieve information about an existing association, (ii) to change the parameters of an existing association, and/or (iii) to set defaults for future associations. When retrieving information about an existing association, the sctp_opt_info function should be used instead of getsockopt. This option takes as input the sctp_assocparams structure.

18 SCTP_AUTOCLOSE Socket Option This option allows us to fetch or set the autoclose time for an SCTP endpoint. Idle is defined by the SCTP stack as neither endpoint sending or receiving user data. The default is for the autoclose function to be disabled. Autoclose can be used by a server to force the closing of idle associations without the server needing to maintain additional state. A server using this feature needs to carefully assess the longest idle time expected on all its associations. Setting the autoclose value smaller than needed results in the premature closing of associations.

19 SCTP_DEFAULT_SEND_PARAM Socket Option SCTP has many optional send parameters that are often passed as ancillary data or used with the sctp_sendmsg function call (which is often implemented as a library call that passes ancillary data for the user). An application that wishes to send a large number of messages, all with the same parameters, can use this option to set up the default parameters and thus avoid using ancillary data or the sctp_sendmsg call. This option takes as input the sctp_sndrcvinfo structure.

20 SCTP_DISABLE_FRAGMENTS Socket Option SCTP normally fragments any user message that does not fit in a single SCTP packet into multiple DATA chunks. Setting this option disables this behavior on the sender. When disabled by this option, SCTP will return the error EMSGSIZE and not send the message. The default behavior is for this option to be disabled; SCTP will normally fragment user messages. This option may be used by applications that wish to control message sizes, ensuring that every user application message will fit in a single IP packet.

21 SCTP_EVENTS Socket Option This socket option allows a caller to fetch, enable, or disable various SCTP notifications. An SCTP notification is a message that the SCTP stack will send to the application. Eight different types of events can be subscribed to by using this option and passing an sctp_event_subscribe structure. 0: non-subscription 1 : subscription

22 SCTP_GET_PEER_ADDR_INFO Socket Option This option retrieves information about a peer address, including the congestion window, smoothed RTT and MTU.

23 SCTP_I_WANT_MAPPED_V4_ADD R Socket Option This flag can be used to enable or disable IPv4- mapped addresses on an AF_INET6-type socket. Note that when enabled (which is the default behavior), all IPv4 addresses will be mapped to a IPv6 address before sending to the application. If this option is disabled, the SCTP socket will not map IPv4 addresses and will instead pass them as a sockaddr_in structure.

24 SCTP_INITMSG Socket Option This option can be used to get or set the default initial parameters used on an SCTP socket when sending out the INIT message. The option uses the sctp_initmsg structure, which is defined as:

25 SCTP_MAXSEG Socket Option This socket option allows the application to fetch or set the maximum fragment size used during SCTP fragmentation. This option is similar to the TCP option TCP_MAXSEG described in Section 7.9.Section 7.9

26 SCTP_NODELAY Socket Option If set, this option disables SCTP's Nagle algorithm. This option is OFF by default (i.e., the Nagle algorithm is ON by default).

27 SCTP_PEER_ADDR_PARAMS Socket Option This socket option allows an application to fetch or set various parameters on an association. The caller provides the sctp_paddrparams structure

28 SCTP_PRIMARY_ADDR Socket Option This socket option fetches or sets the address that the local endpoint is using as primary. The primary address is used, by default, as the destination address for all messages sent to a peer. To set this value, the caller fills in the association identification and the peer's address that should be used as the primary address. The caller passes this information in a sctp_setprim structure

29 SCTP_RTOINFO Socket Option This socket option can be used to fetch or set various RTO information on a specific association or the default values used by this endpoint. When fetching, the caller should use sctp_opt_info instead of getsockopt for maximum portability. The caller provides a sctp_rtoinfo structure

30 SCTP_SET_PEER_PRIMARY_ADDR Socket Option Setting this option causes a message to be sent that requests that the peer set the specified local address as its primary address.

31 SCTP_STATUS Socket Option This socket option will retrieve the current state of an SCTP association. The caller provides an sctp_status structure, filling in the association identification field, sstat_assoc_id. The structure will be returned filled in with the information pertaining to the requested association.

32 7.11 fcntl Function fcntl stands for "file control" and this function performs various descriptor control operations.

33 The fcntl function provides the following features related to network programming: Nonblocking I/O— We can set the O_NONBLOCK file status flag using the F_SETFL command to set a socket as nonblocking. Signal-driven I/O— We can set the O_ASYNC file status flag using the F_SETFL command, which causes the SIGIO signal to be generated when the status of a socket changes. The F_SETOWN command lets us set the socket owner (the process ID or process group ID) to receive the SIGIO and SIGURG signals. The former signal is generated when signal- driven I/O is enabled for a socket (Chapter 25) and the latter signal is generated when new out-of-band data arrives for a socketChapter 25

34 Each descriptor (including a socket) has a set of file flags that is fetched with the F_GETFL command and set with the F_SETFL command. The two flags that affect a socket are O_NONBLOCK—nonblocking I/O O_ASYNC—signal-driven I/O

35

36 7.12 Summary SCTP provides 17 socket options that are used by the application to control the transport. SCTP_NODELAY and SCTP_MAXSEG are similar to TCP_NODELAY and TCP_MAXSEG and perform equivalent functions. The other 15 options give the application finer control of the SCTP stack;


Download ppt "7.9 TCP Socket Options 7.10 SCTP Socket Options 7.11 fcntl Function 7.12 Summary 報告者 : 梁凱鈞."

Similar presentations


Ads by Google