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

비밀번호

댓글 작성자
 




... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12399정성태11/5/202011453.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/20209984오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/202010159.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/20208449VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/20209794오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/20208186오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/20208686오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202012795.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202011037디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
12389정성태11/1/202010775.NET Framework: 958. C# 9.0 - (8) 정적 익명 함수 (static anonymous functions)파일 다운로드1
12388정성태10/29/202010228오류 유형: 674. 어느 순간부터 닷넷 응용 프로그램 실행 시 System.Configuration.ConfigurationErrorsException 예외가 발생한다면?
12387정성태10/28/202011016.NET Framework: 957. C# - static 필드의 정보가 GC Heap에 저장될까요? [3]파일 다운로드1
12386정성태10/28/202011260Linux: 34. 사용자 정보를 함께 출력하는 리눅스의 ps 명령어 사용 방법
12385정성태10/28/20209075오류 유형: 673. openssl - req: No value provided for Subject Attribute CN, skipped
12384정성태10/27/202010294오류 유형: 672. AllowPartiallyTrustedCallers 특성이 적용된 어셈블리의 struct 멤버 메서드를 재정의하면 System.Security.VerificationException 예외 발생
12383정성태10/27/202011180.NET Framework: 956. C# 9.0 - (7) 패턴 일치 개선 사항(Pattern matching enhancements) [3]파일 다운로드1
12382정성태10/26/20208895오류 유형: 671. dotnet build - The local source '...' doesn't exist
12381정성태10/26/202010565VC++: 137. C++ stl map의 사용자 정의 타입을 key로 사용하는 방법 [1]파일 다운로드1
12380정성태10/26/20207972오류 유형: 670. Visual Studio - Squash_FailureCommitsReset
12379정성태10/21/202010986.NET Framework: 955. .NET 메서드의 Signature 바이트 코드 분석 [1]파일 다운로드2
12378정성태10/15/202010396.NET Framework: 954. C# - x86/x64 환경에 따라 달라지는 P/Invoke 함수의 export 이름파일 다운로드1
12377정성태10/15/202011691디버깅 기술: 172. windbg - 파일 열기 시점에 bp를 걸어 파일명 알아내는 방법(Managed/Unmanaged)
12376정성태10/15/20208406오류 유형: 669. windbg - sos의 name2ee 명령어 실행 시 "Failed to request module list." 오류
12375정성태10/15/20209791Windows: 177. 윈도우 탐색기에서 띄우는 cmd.exe 창의 디렉터리 구분 문자가 'Yen(¥)' 기호로 나오는 경우 [1]
12374정성태10/14/202014416.NET Framework: 953. C# 9.0 - (6) 함수 포인터(Function pointers) [1]파일 다운로드2
12373정성태10/14/20209694.NET Framework: 952. OpCodes.Box와 관련해 IL 형식으로 직접 코딩 시 유의할 점
... 46  47  48  49  [50]  51  52  53  54  55  56  57  58  59  60  ...