Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일

(시리즈 글이 8개 있습니다.)
개발 환경 구성: 533. Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 리눅스 환경
; https://www.sysnet.pe.kr/2/0/12527

개발 환경 구성: 534. Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 윈도우 환경
; https://www.sysnet.pe.kr/2/0/12528

개발 환경 구성: 535. Wireshark + C#으로 확인하는 TCP 통신의 MIN RTO
; https://www.sysnet.pe.kr/2/0/12529

개발 환경 구성: 536. Wireshark + C#으로 확인하는 TCP 통신의 Receive Window
; https://www.sysnet.pe.kr/2/0/12530

개발 환경 구성: 538. Wireshark + C#으로 확인하는 ReceiveBufferSize(SO_RCVBUF), SendBufferSize(SO_SNDBUF)
; https://www.sysnet.pe.kr/2/0/12532

개발 환경 구성: 539. Wireshark + C/C++로 확인하는 TCP 연결에서의 shutdown 동작
; https://www.sysnet.pe.kr/2/0/12533

개발 환경 구성: 540. Wireshark + C/C++로 확인하는 TCP 연결에서의 closesocket 동작
; https://www.sysnet.pe.kr/2/0/12534

개발 환경 구성: 541.  Wireshark로 확인하는 LSO(Large Send Offload), RSC(Receive Segment Coalescing) 옵션
; https://www.sysnet.pe.kr/2/0/12535




Wireshark + C#으로 확인하는 TCP 통신의 MSS(Maximum Segment Size) - 리눅스 환경

지난 글에서 살펴 본,

이더넷(Ethernet) 환경의 TCP 통신에서 MSS(Maximum Segment Size) 확인
; https://www.sysnet.pe.kr/2/0/12521


MSS를 실제 C# Socket과 Wireshark를 통해 ^^ 확인해 보겠습니다. C# 소스 코드는 테스트 용도이므로 다음과 같이 간단하게 서버와 클라이언트를 구성할 수 있습니다.

// 서버 - Oracle Cloud VM Ubuntu 20.04
using System;
using System.Net;
using System.Net.Sockets;

class Program
{
    static void Main(string[] args)
    {
        Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        server.Bind(new IPEndPoint(IPAddress.Any, 15000));
        server.Listen(5);

        while (true)
        {
            Console.WriteLine("Accepting...");
            Socket client = server.Accept();

            do
            {
                string text = Console.ReadLine();

                if (string.IsNullOrEmpty(text) == true)
                {
                    break;
                }

                int readLen = int.Parse(text);
                byte[] buf = new byte[readLen];
                readLen = client.Receive(buf, 0, buf.Length, SocketFlags.None);
                Console.WriteLine($"read: {readLen}");
            } while (true);

            client.Close();
        }
    }
}

// 클라이언트 - 물리 머신 Ubuntu 20.04
using System;
using System.Net.Sockets;

unsafe class Program
{
    static void Main(string[] args)
    {
        {
            Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            client.Connect("...serverip...", 15000);

            while (true)
            {
                string text = Console.ReadLine();

                if (string.IsNullOrEmpty(text) == true)
                {
                    break;
                }

                int sendSize = int.Parse(text);
                byte[] buffer = new byte[sendSize];

                client.Send(buffer, 0, buffer.Length, SocketFlags.None);
            }

            client.Close();
        }
    }
}

하는 일은 매우 간단합니다. 서버는 연결 하나를 받지만 recv를 사용자가 원하는 크기를 지정할 때까지 호출하지 않습니다. 또한 클라이언트 측도 마찬가지로 연결만 해두고 이후 send는 사용자가 원하는 크기를 지정할 때까지 호출하지 않습니다.

이제 서버를 띄워놓고 클라이언트에서 접속할 때 Wireshark로 패킷을 캡처하면 다음과 같은 결과가 나옵니다.

...client_ip...	...svr_ip... TCP 74 32912 → 15000 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM=1 TSval=3363140511 TSecr=0 WS=128
...svr_ip... ...client_ip..  TCP 74 15000 → 32912 [SYN, ACK] Seq=0 Ack=1 Win=62636 Len=0 MSS=8960 SACK_PERM=1 TSval=1612454569 TSecr=3363140511 WS=128
...client_ip...	...svr_ip... TCP 66 32912 → 15000 [ACK] Seq=1 Ack=1 Win=64256 Len=0 TSval=3363140514 TSecr=1612454569

보는 바와 같이 클라이언트에서 서버로 전송할 때는 MSS=1460이고, 서버에서 클라이언트로 보낼 때는 8960이라고 나옵니다. 이전에 설명했듯이, 1460은 일반적인 설정의 MSS 값이고, 8960은 Jumbo Frame이 설정된 환경의 값입니다.

어쨌든, 클라이언트는 1460을, 서버는 8960을 보냈으므로,

TCP/IP performance tuning for Azure VMs
; https://learn.microsoft.com/en-us/azure/virtual-network/virtual-network-tcpip-performance-tuning

This setting is agreed to in the TCP three-way handshake when a TCP session is set up between a source and a destination. Both sides send an MSS value, and the lower of the two is used for the TCP connection.


둘 중의 작은 값인 1460이 해당 TCP 통신에서의 MSS 값이 됩니다.




자, 그럼 이제 소스 코드에 작성한 대로 임의의 데이터를 서버로 전송해 볼 텐데요, 우선 협의된 MSS 값보다 1이 큰 데이터를 서버로 보냈을 때의 Wireshark 캡처는 다음과 같이 나옵니다.

..client_ip... ...serverip... TCP 1514    32912 → 15000 [ACK] Seq=1 Ack=1 Win=64256 Len=1448 TSval=3445313658 TSecr=1693752398
..client_ip... ...serverip... TCP 79  32912 → 15000 [PSH, ACK] Seq=1449 Ack=1 Win=64256 Len=13 TSval=3445313658 TSecr=1693752398
...serverip... ..client_ip... TCP 66  15000 → 32912 [ACK] Seq=1 Ack=1462 Win=61184 Len=0 TSval=1694627715 TSecr=3445313658

예상했던 것처럼 2개의 패킷이 서버로 전송되긴 했지만, 크기가 1460이 아닌, 1448로 나와 있습니다. 왜 그런 것일까요? 그 이유는 TCP 헤더가 20바이트가 아닌, TSval, TSecr 정보에 해당하는 12 바이트를 더 점유하고 있기 때문입니다. 실제로 저 상황에서의 TCP 데이터를 보면,

Transmission Control Protocol, Src Port: 15000, Dst Port: 33544, Seq: 1, Ack: 1462, Len: 0
    Source Port: 15000
    Destination Port: 33544
    [Stream index: 3]
    [TCP Segment Len: 0]
    Sequence number: 1    (relative sequence number)
    Sequence number (raw): 2415159352
    [Next sequence number: 1    (relative sequence number)]
    Acknowledgment number: 1462    (relative ack number)
    Acknowledgment number (raw): 2123235886
    1000 .... = Header Length: 32 bytes (8)
    Flags: 0x010 (ACK)
    Window size value: 478
    [Calculated window size: 61184]
    [Window size scaling factor: 128]
    Checksum: 0x5672 [unverified]
    [Checksum Status: Unverified]
    Urgent pointer: 0
    Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
        TCP Option - No-Operation (NOP)
            Kind: No-Operation (1)
        TCP Option - No-Operation (NOP)
            Kind: No-Operation (1)
        TCP Option - Timestamps: TSval 1694627715, TSecr 3445313658
            Kind: Time Stamp Option (8)
            Length: 10
            Timestamp value: 1694627715
            Timestamp echo reply: 3445313658
    [SEQ/ACK analysis]
        [This is an ACK to the segment in frame: 49156]
        [The RTT to ACK the segment was: 0.003061175 seconds]
        [iRTT: 0.003105376 seconds]
    [Timestamps]

헤더 크기가 32로 나옵니다. 따라서, IP MTU(1500) - IPHeader(20) - TCPHeader(32) = 1448이 TCP 데이터로 보낼 수 있는 최대 크기가 됩니다. 따라서, 클라이언트에서 1448을 보내도록 다시 테스트를 해보면,

..client_ip...    ...serverip...  TCP 1514    33544 → 15000 [PSH, ACK] Seq=1462 Ack=1 Win=64256 Len=1448 TSval=3445823525 TSecr=1694627715
...serverip...  ..client_ip...    TCP 66  15000 → 33544 [ACK] Seq=1 Ack=2910 Win=59776 Len=0 TSval=1695137582 TSecr=3445823525

정확히 1개의 전송 패킷과, 1개의 ACK 패킷만을 확인할 수 있습니다. (단일 패킷 전송/ACK인 경우 전송 측의 Seq=1462와 Ack 패킷의 Ack=2910의 번호 차이도 1,448만큼 나오는 것이 우연은 아닙니다.)

(첨부 파일은 이 글의 예제 코드를 포함합니다.)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 1/23/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13528정성태1/14/20242033Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20241961오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242051닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20242021오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20242066오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20241889오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
13522정성태1/11/20242030닷넷: 2200. C# - HttpClient.PostAsJsonAsync 호출 시 "Transfer-Encoding: chunked" 대신 "Content-Length" 헤더 처리
13521정성태1/11/20242110닷넷: 2199. C# - 한국투자증권 KIS Developers OpenAPI의 WebSocket Ping, Pong 처리
13520정성태1/10/20241858오류 유형: 888. C# - Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`....'
13519정성태1/10/20241939닷넷: 2198. C# - Reflection을 이용한 ClientWebSocket의 Ping 호출파일 다운로드1
13518정성태1/9/20242174닷넷: 2197. C# - ClientWebSocket의 Ping, Pong 처리
13517정성태1/8/20242017스크립트: 63. Python - 공개 패키지를 이용한 위성 이미지 생성 (pystac_client, odc.stac)
13516정성태1/7/20242104닷넷: 2196. IIS - AppPool의 "Disable Overlapped Recycle" 옵션의 부작용
13515정성태1/6/20242376닷넷: 2195. async 메서드 내에서 C# 7의 discard 구문 활용 사례 [1]
13514정성태1/5/20242065개발 환경 구성: 702. IIS - AppPool의 "Disable Overlapped Recycle" 옵션
13513정성태1/5/20242006닷넷: 2194. C# - WebActivatorEx / System.Web의 PreApplicationStartMethod 특성
13512정성태1/4/20241979개발 환경 구성: 701. IIS - w3wp.exe 프로세스의 ASP.NET 런타임을 항상 Warmup 모드로 유지하는 preload Enabled 설정
13511정성태1/4/20241997닷넷: 2193. C# - ASP.NET Web Application + OpenAPI(Swashbuckle) 스펙 제공
13510정성태1/3/20241937닷넷: 2192. C# - 특정 실행 파일이 있는지 확인하는 방법 (Linux)
13509정성태1/3/20241966오류 유형: 887. .NET Core 2 이하의 프로젝트에서 System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0.
13508정성태1/3/20242016오류 유형: 886. ORA-28000: the account is locked
13507정성태1/2/20242701닷넷: 2191. C# - IPGlobalProperties를 이용해 netstat처럼 사용 중인 Socket 목록 구하는 방법파일 다운로드1
13506정성태12/29/20232191닷넷: 2190. C# - 닷넷 코어/5+에서 달라지는 System.Text.Encoding 지원
13505정성태12/27/20232707닷넷: 2189. C# - WebSocket 클라이언트를 닷넷으로 구현하는 예제 (System.Net.WebSockets)파일 다운로드1
13504정성태12/27/20232322닷넷: 2188. C# - ASP.NET Core SignalR로 구현하는 채팅 서비스 예제파일 다운로드1
13503정성태12/27/20232191Linux: 67. WSL 환경 + mlocate(locate) 도구의 /mnt 디렉터리 검색 문제
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...