Search in sources :

Example 6 with PcapReader

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

the class PcapReaderTest method findIPStartSLL.

@Test
public void findIPStartSLL() {
    byte[] packet = new byte[20];
    PcapReader xreader = new PcapReader(PcapReader.LinkType.LINUX_SLL);
    byte[] sllAddressSourceLength = PcapReaderUtil.convertShort(6);
    packet[4] = sllAddressSourceLength[0];
    packet[5] = sllAddressSourceLength[1];
    byte[] ethernetTypeIp = PcapReaderUtil.convertShort(PcapReader.ETHERNET_TYPE_IP);
    packet[16] = ethernetTypeIp[0];
    packet[17] = ethernetTypeIp[1];
    assertEquals(16, xreader.findIPStart(packet));
}
Also used : PcapReader(net.ripe.hadoop.pcap.PcapReader) Test(org.junit.Test)

Example 7 with PcapReader

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

the class PcapReaderTest method findIPStartEN10MB.

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

Example 8 with PcapReader

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

the class PcapReaderTest method findIPStartEN10MB_8021Q.

@Test
public void findIPStartEN10MB_8021Q() {
    byte[] packet = new byte[20];
    PcapReader xreader = new PcapReader(PcapReader.LinkType.EN10MB);
    byte[] ethernetType8021Q = PcapReaderUtil.convertShort(PcapReader.ETHERNET_TYPE_8021Q);
    packet[12] = ethernetType8021Q[0];
    packet[13] = ethernetType8021Q[1];
    byte[] ethernetTypeIp = PcapReaderUtil.convertShort(PcapReader.ETHERNET_TYPE_IP);
    packet[16] = ethernetTypeIp[0];
    packet[17] = ethernetTypeIp[1];
    assertEquals(18, xreader.findIPStart(packet));
}
Also used : PcapReader(net.ripe.hadoop.pcap.PcapReader) Test(org.junit.Test)

Example 9 with PcapReader

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

the class PcapReaderTest method assembled.

@Test
public void assembled() 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))) {

            @Override
            protected void processPacketPayload(Packet packet, byte[] payload) {
                Integer fragments = (Integer) packet.get(Packet.REASSEMBLED_TCP_FRAGMENTS);
                if (fragments != null) {
                    assertTrue(2 == fragments);
                    assertEquals("part1\npart2\n", new String(payload));
                }
            }

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

            @Override
            protected boolean isPush() {
                return false;
            }
        };
        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)

Example 10 with PcapReader

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

the class PcapIPv6RecordReaderTest 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)

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