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

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  37  38  39  40  41  [42]  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12587정성태4/6/202111861개발 환경 구성: 564. Windows 10 - ClickOnce 배포처럼 사용할 수 있는 MSIX 설치 파일 [1]
12586정성태4/5/20219544오류 유형: 710. Windows - Restart-Computer / shutdown 명령어 수행 시 Access is denied(E_ACCESSDENIED)
12585정성태4/5/20219306개발 환경 구성: 563. 기본 생성된 kubeconfig 파일의 내용을 새롭게 생성한 인증서로 구성하는 방법
12584정성태4/1/202110001개발 환경 구성: 562. kubeconfig 파일 없이 kubectl 옵션만으로 실행하는 방법
12583정성태3/29/202111483개발 환경 구성: 561. kubectl 수행 시 다른 k8s 클러스터로 접속하는 방법
12582정성태3/29/202110194오류 유형: 709. Visual C++ - 컴파일 에러 error C2059: syntax error: '__stdcall'
12581정성태3/28/202110105.NET Framework: 1031. WinForm/WPF에서 Console 창을 띄워 출력하는 방법 (2) - Output 디버깅 출력을 AllocConsole로 우회 [2]
12580정성태3/28/20218837오류 유형: 708. SQL Server Management Studio - Execution Timeout Expired.
12579정성태3/28/20218942오류 유형: 707. 중첩 가상화(Nested Virtualization) - The virtual machine could not be started because this platform does not support nested virtualization.
12578정성태3/27/20219204개발 환경 구성: 560. Docker Desktop for Windows 기반의 Kubernetes 구성 (2) - WSL 2 인스턴스에 kind가 구성한 k8s 서비스 위치
12577정성태3/26/202111256개발 환경 구성: 559. Docker Desktop for Windows 기반의 Kubernetes 구성 - WSL 2 인스턴스에 kind 도구로 k8s 클러스터 구성
12576정성태3/25/20219046개발 환경 구성: 558. Docker Desktop for Windows에서 DockerDesktopVM 기반의 Kubernetes 구성 (2) - k8s 서비스 위치
12575정성태3/24/20218126개발 환경 구성: 557. Docker Desktop for Windows에서 DockerDesktopVM 기반의 Kubernetes 구성
12574정성태3/23/202112153.NET Framework: 1030. C# Socket의 Close/Shutdown 동작 (동기 모드)
12573정성태3/22/20219977개발 환경 구성: 556. WSL 인스턴스 초기 설정 명령어 [1]
12572정성태3/22/20219515.NET Framework: 1029. C# - GC 호출로 인한 메모리 압축(Compaction)을 확인하는 방법파일 다운로드1
12571정성태3/21/20218659오류 유형: 706. WSL 2 기반으로 "Enable Kubernetes" 활성화 시 초기화 실패 [1]
12570정성태3/19/202112950개발 환경 구성: 555. openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법
12569정성태3/18/202111849개발 환경 구성: 554. WSL 인스턴스 export/import 방법 및 단축 아이콘 설정 방법
12568정성태3/18/20217428오류 유형: 705. C# 빌드 - Couldn't process file ... due to its being in the Internet or Restricted zone or having the mark of the web on the file.
12567정성태3/17/20218852개발 환경 구성: 553. Docker Desktop for Windows를 위한 k8s 대시보드 활성화 [1]
12566정성태3/17/20219164개발 환경 구성: 552. Kubernetes - kube-apiserver와 REST API 통신하는 방법 (Docker Desktop for Windows 환경)
12565정성태3/17/20216628오류 유형: 704. curl.exe 실행 시 dll not found 오류
12564정성태3/16/20217127VS.NET IDE: 160. 새 프로젝트 창에 C++/CLI 프로젝트 템플릿이 없는 경우
12563정성태3/16/20219100개발 환경 구성: 551. C# - JIRA REST API 사용 정리 (3) jira-oauth-cli 도구를 이용한 키 관리
12562정성태3/15/202110256개발 환경 구성: 550. C# - JIRA REST API 사용 정리 (2) JIRA OAuth 토큰으로 API 사용하는 방법파일 다운로드1
... 31  32  33  34  35  36  37  38  39  40  41  [42]  43  44  45  ...