Search in sources :

Example 11 with PcapReader

use of net.ripe.hadoop.pcap.PcapReader in project hadoop-pcap by RIPE-NCC.

the class PcapReversedHeaderRecordReaderTest method startup.

@Before
public void startup() throws IOException {
    JobConf config = new JobConf();
    FileSystem fs = FileSystem.get(config);
    FSDataInputStream is = fs.open(new Path(TEST_FILE.getParent(), TEST_FILE.getName()));
    recordReader = new PcapRecordReader(new PcapReader(is), 0L, TEST_FILE.length(), is, is, new TestableTaskAttemptContext(config));
}
Also used : Path(org.apache.hadoop.fs.Path) PcapReader(net.ripe.hadoop.pcap.PcapReader) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) PcapRecordReader(net.ripe.hadoop.pcap.io.reader.PcapRecordReader) JobConf(org.apache.hadoop.mapred.JobConf) Before(org.junit.Before)

Example 12 with PcapReader

use of net.ripe.hadoop.pcap.PcapReader in project hadoop-pcap by RIPE-NCC.

the class PcapReaderTest method findIPStartEN10MBUnknownType.

@Test
public void findIPStartEN10MBUnknownType() {
    byte[] packet = new byte[20];
    PcapReader xreader = new PcapReader(PcapReader.LinkType.EN10MB);
    packet[12] = -1;
    packet[13] = -1;
    assertEquals(-1, xreader.findIPStart(packet));
}
Also used : PcapReader(net.ripe.hadoop.pcap.PcapReader) Test(org.junit.Test)

Example 13 with PcapReader

use of net.ripe.hadoop.pcap.PcapReader in project hadoop-pcap by RIPE-NCC.

the class PcapReaderTest method findIPStartRAW.

@Test
public void findIPStartRAW() {
    PcapReader xreader = new PcapReader(PcapReader.LinkType.RAW);
    assertEquals(0, xreader.findIPStart(null));
}
Also used : PcapReader(net.ripe.hadoop.pcap.PcapReader) Test(org.junit.Test)

Example 14 with PcapReader

use of net.ripe.hadoop.pcap.PcapReader in project hadoop-pcap by RIPE-NCC.

the class PcapReaderTest method findIPStartLOOP.

@Test
public void findIPStartLOOP() {
    PcapReader xreader = new PcapReader(PcapReader.LinkType.LOOP);
    assertEquals(4, xreader.findIPStart(null));
}
Also used : PcapReader(net.ripe.hadoop.pcap.PcapReader) Test(org.junit.Test)

Example 15 with PcapReader

use of net.ripe.hadoop.pcap.PcapReader in project hadoop-pcap by RIPE-NCC.

the class PcapReaderTest method assembledWithPush.

@Test
public void assembledWithPush() throws IOException {
    for (String file : new String[] { "src/test/resources/tcp-stream-v4.pcap", "src/test/resources/tcp-stream-v6.pcap" }) {
        PcapReader reader = new PcapReader(new DataInputStream(new FileInputStream(file))) {

            public int counter = 1;

            @Override
            protected void processPacketPayload(Packet packet, byte[] payload) {
                Integer fragments = (Integer) packet.get(Packet.REASSEMBLED_TCP_FRAGMENTS);
                if (fragments != null) {
                    assertTrue(1 == fragments);
                    switch(counter) {
                        case 1:
                            assertEquals("part1\n", new String(payload));
                            break;
                        case 2:
                            assertEquals("part2\n", new String(payload));
                            break;
                    }
                    counter++;
                }
            }

            @Override
            protected boolean isReassembleTcp() {
                return true;
            }

            @Override
            protected boolean isPush() {
                return true;
            }
        };
        assertEquals(10, Iterables.size(reader));
    }
}
Also used : Packet(net.ripe.hadoop.pcap.packet.Packet) PcapReader(net.ripe.hadoop.pcap.PcapReader) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

PcapReader (net.ripe.hadoop.pcap.PcapReader)15 Test (org.junit.Test)9 DataInputStream (java.io.DataInputStream)5 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 PcapRecordReader (net.ripe.hadoop.pcap.io.reader.PcapRecordReader)4 FileInputStream (java.io.FileInputStream)3 Packet (net.ripe.hadoop.pcap.packet.Packet)3 Path (org.apache.hadoop.fs.Path)3 JobConf (org.apache.hadoop.mapred.JobConf)3 Before (org.junit.Before)3 CompressionCodec (org.apache.hadoop.io.compress.CompressionCodec)2 CompressionCodecFactory (org.apache.hadoop.io.compress.CompressionCodecFactory)2 Joiner (com.google.common.base.Joiner)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 PcapRecordReader (net.ripe.hadoop.pcap.mr1.io.reader.PcapRecordReader)1 Configuration (org.apache.hadoop.conf.Configuration)1