Home / Function/ writePcapGreaterThan4Gb() — netty Function Reference

writePcapGreaterThan4Gb() — netty Function Reference

Architecture documentation for the writePcapGreaterThan4Gb() function in PcapWriteHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  a9d69f29_7cda_7943_ffb0_c38af67018e1["writePcapGreaterThan4Gb()"]
  e9f4993c_4935_9405_4fab_0bbc9030a673["PcapWriteHandlerTest"]
  a9d69f29_7cda_7943_ffb0_c38af67018e1 -->|defined in| e9f4993c_4935_9405_4fab_0bbc9030a673
  201e7e9e_c23c_b328_ecb1_117026fc1c03["InetSocketAddress()"]
  a9d69f29_7cda_7943_ffb0_c38af67018e1 -->|calls| 201e7e9e_c23c_b328_ecb1_117026fc1c03
  ff4daf19_fd95_137a_41fb_211667c3aaa3["record()"]
  a9d69f29_7cda_7943_ffb0_c38af67018e1 -->|calls| ff4daf19_fd95_137a_41fb_211667c3aaa3
  0f8afeab_bf89_b1f6_38aa_f68ed17d8421["reset()"]
  a9d69f29_7cda_7943_ffb0_c38af67018e1 -->|calls| 0f8afeab_bf89_b1f6_38aa_f68ed17d8421
  01e5d0fc_496a_76ab_e7c3_dc46e7a39a9d["recordedBytes()"]
  a9d69f29_7cda_7943_ffb0_c38af67018e1 -->|calls| 01e5d0fc_496a_76ab_e7c3_dc46e7a39a9d
  fd600aac_354d_5162_7fc4_3b9f4ad34776["bytesWritten()"]
  a9d69f29_7cda_7943_ffb0_c38af67018e1 -->|calls| fd600aac_354d_5162_7fc4_3b9f4ad34776
  d3cfaa8b_8ac2_24f3_97d5_6f3a794d3ad8["verifyTcpCapture()"]
  a9d69f29_7cda_7943_ffb0_c38af67018e1 -->|calls| d3cfaa8b_8ac2_24f3_97d5_6f3a794d3ad8
  22ba8e46_dc77_3860_b834_c8c13b6f8820["write()"]
  a9d69f29_7cda_7943_ffb0_c38af67018e1 -->|calls| 22ba8e46_dc77_3860_b834_c8c13b6f8820
  style a9d69f29_7cda_7943_ffb0_c38af67018e1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java lines 882–978

    @Test
    public void writePcapGreaterThan4Gb() {
        InetSocketAddress serverAddr = new InetSocketAddress("1.1.1.1", 1234);
        InetSocketAddress clientAddr = new InetSocketAddress("2.2.2.2", 3456);

        class RecordingOutputStream extends OutputStream {
            private long bytesWritten;
            private ByteArrayOutputStream out;
            @Override
            public void write(int b) {
                bytesWritten++;
                if (out != null) {
                    out.write(b);
                }
            }

            @Override
            public void write(byte[] b, int off, int len) {
                bytesWritten += len;
                if (out != null) {
                    out.write(b, off, len);
                }
            }

            void record() {
                out = new ByteArrayOutputStream();
            }

            void reset() {
                out = null;
            }

            byte[] recordedBytes() {
                return out.toByteArray();
            }

            long bytesWritten() {
                return bytesWritten;
            }
        }

        RecordingOutputStream outputStream = new RecordingOutputStream();
        EmbeddedChannel embeddedChannel = new EmbeddedChannel(
                new DiscardingWritesAndFlushesHandler(), //Discard writes/flushes
                PcapWriteHandler.builder()
                                .forceTcpChannel(serverAddr, clientAddr, true)
                                .build(outputStream),
                new DiscardingReadsHandler() //Discard reads
        );

        int chunkSize = 0xFFFF - 40; // 40 bytes for header data
        String payloadString = new String(new char[chunkSize]).replace('\0', 'X');
        final ByteBuf payload = Unpooled.wrappedBuffer(payloadString.getBytes());

        try {
            long fourGB = 0xFFFFFFFFL;

            // Let's send 4 GiB inbound, ...
            long msgCount = (fourGB / chunkSize) + 2;
            for (int i = 0; i < msgCount; i++) {
                //Only store the last data/ack
                if (i == msgCount - 1) {
                    outputStream.record();
                }
                embeddedChannel.writeInbound(payload.retainedDuplicate());
            }

            //Validate the wrapped number
            long sequenceNumber = ((msgCount - 1) * chunkSize) - fourGB;
            long ackNumber = 1;
            ByteBuf buf = Unpooled.wrappedBuffer(outputStream.recordedBytes());
            verifyTcpCapture(buf, payload, serverAddr, clientAddr, sequenceNumber, ackNumber);
            buf.release();
            outputStream.reset();

            // ... and 4 GiB outbound.
            for (int i = 0; i < msgCount; i++) {
                //Only store the last data/ack
                if (i == msgCount - 1) {
                    outputStream.record();
                }

Domain

Subdomains

Frequently Asked Questions

What does writePcapGreaterThan4Gb() do?
writePcapGreaterThan4Gb() is a function in the netty codebase, defined in handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java.
Where is writePcapGreaterThan4Gb() defined?
writePcapGreaterThan4Gb() is defined in handler/src/test/java/io/netty/handler/pcap/PcapWriteHandlerTest.java at line 882.
What does writePcapGreaterThan4Gb() call?
writePcapGreaterThan4Gb() calls 7 function(s): InetSocketAddress, bytesWritten, record, recordedBytes, reset, verifyTcpCapture, write.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free