Search in sources :

Example 1 with FixedPcapConfig

use of org.apache.metron.pcap.config.FixedPcapConfig in project metron by apache.

the class PcapJobTest method setup.

@BeforeEach
public void setup() throws IOException {
    MockitoAnnotations.initMocks(this);
    basePath = new Path("basepath");
    baseOutPath = new Path("outpath");
    startTime = 100;
    endTime = 200;
    numReducers = 5;
    numRecordsPerFile = 5;
    fixedFields = new HashMap<>();
    fixedFields.put("ip_src_addr", "192.168.1.1");
    hadoopConfig = new Configuration();
    fileSystem = FileSystem.get(hadoopConfig);
    finalOutputPath = new Path("finaloutpath");
    when(jobId.toString()).thenReturn(jobIdVal);
    when(mrStatus.getJobID()).thenReturn(jobId);
    when(mrJob.getJobID()).thenReturn(jobId);
    pageableResult = new PcapPages();
    timer = new TestTimer();
    // handles setting the file name prefix under the hood
    config = new FixedPcapConfig(clock -> "clockprefix");
    PcapOptions.HADOOP_CONF.put(config, hadoopConfig);
    PcapOptions.FILESYSTEM.put(config, FileSystem.get(hadoopConfig));
    PcapOptions.BASE_PATH.put(config, basePath);
    PcapOptions.BASE_INTERIM_RESULT_PATH.put(config, baseOutPath);
    PcapOptions.START_TIME_NS.put(config, startTime);
    PcapOptions.END_TIME_NS.put(config, endTime);
    PcapOptions.NUM_REDUCERS.put(config, numReducers);
    PcapOptions.FIELDS.put(config, fixedFields);
    PcapOptions.FILTER_IMPL.put(config, new FixedPcapFilter.Configurator());
    PcapOptions.NUM_RECORDS_PER_FILE.put(config, numRecordsPerFile);
    PcapOptions.FINAL_OUTPUT_PATH.put(config, finalOutputPath);
    testJob = new TestJob<>(mrJob);
    testJob.setStatusInterval(1);
    testJob.setCompleteCheckInterval(1);
    testJob.setTimer(timer);
}
Also used : Path(org.apache.hadoop.fs.Path) FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) FixedPcapFilter(org.apache.metron.pcap.filter.fixed.FixedPcapFilter) FileSystem(org.apache.hadoop.fs.FileSystem) Pageable(org.apache.metron.job.Pageable) Mock(org.mockito.Mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) PcapFilterConfigurator(org.apache.metron.pcap.filter.PcapFilterConfigurator) LongWritable(org.apache.hadoop.io.LongWritable) TimestampConverters(org.apache.metron.common.utils.timestamp.TimestampConverters) MockitoAnnotations(org.mockito.MockitoAnnotations) State(org.apache.metron.job.JobStatus.State) PcapOptions(org.apache.metron.pcap.config.PcapOptions) Long.toUnsignedString(java.lang.Long.toUnsignedString) Configuration(org.apache.hadoop.conf.Configuration) Path(org.apache.hadoop.fs.Path) BytesWritable(org.apache.hadoop.io.BytesWritable) Statusable(org.apache.metron.job.Statusable) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) JobID(org.apache.hadoop.mapreduce.JobID) IOException(java.io.IOException) Finalizer(org.apache.metron.job.Finalizer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) Job(org.apache.hadoop.mapreduce.Job) JobStatus(org.apache.metron.job.JobStatus) PcapPages(org.apache.metron.pcap.PcapPages) Configuration(org.apache.hadoop.conf.Configuration) PcapPages(org.apache.metron.pcap.PcapPages) FixedPcapFilter(org.apache.metron.pcap.filter.fixed.FixedPcapFilter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with FixedPcapConfig

use of org.apache.metron.pcap.config.FixedPcapConfig in project metron by apache.

the class PcapTopologyIntegrationTest method setup.

/**
 * This is executed before each individual test.
 */
@BeforeEach
public void setup() throws IOException {
    configuration = new FixedPcapConfig(PcapCli.PREFIX_STRATEGY);
    Configuration hadoopConf = new Configuration();
    PcapOptions.JOB_NAME.put(configuration, "jobName");
    PcapOptions.HADOOP_CONF.put(configuration, hadoopConf);
    PcapOptions.FILESYSTEM.put(configuration, FileSystem.get(hadoopConf));
    PcapOptions.BASE_PATH.put(configuration, new Path(inputDir.getAbsolutePath()));
    PcapOptions.BASE_INTERIM_RESULT_PATH.put(configuration, new Path(interimResultDir.getAbsolutePath()));
    PcapOptions.NUM_REDUCERS.put(configuration, 10);
    PcapOptions.NUM_RECORDS_PER_FILE.put(configuration, 1);
    PcapOptions.FINAL_OUTPUT_PATH.put(configuration, new Path(outputDir.getAbsolutePath()));
    PcapOptions.FINALIZER_THREADPOOL_SIZE.put(configuration, 4);
}
Also used : FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with FixedPcapConfig

use of org.apache.metron.pcap.config.FixedPcapConfig in project metron by apache.

the class PcapCliTest method runs_fixed_pcap_filter_job_with_default_argument_list.

@Test
public void runs_fixed_pcap_filter_job_with_default_argument_list() throws Exception {
    String[] args = { "fixed", "-start_time", "500", "-ip_src_addr", "192.168.1.1", "-ip_dst_addr", "192.168.1.2", "-ip_src_port", "8081", "-ip_dst_port", "8082", "-protocol", "6", "-packet_filter", "`casey`" };
    HashMap<String, String> query = new HashMap<String, String>() {

        {
            put(Constants.Fields.SRC_ADDR.getName(), "192.168.1.1");
            put(Constants.Fields.DST_ADDR.getName(), "192.168.1.2");
            put(Constants.Fields.SRC_PORT.getName(), "8081");
            put(Constants.Fields.DST_PORT.getName(), "8082");
            put(Constants.Fields.PROTOCOL.getName(), "6");
            put(Constants.Fields.INCLUDES_REVERSE_TRAFFIC.getName(), "false");
            put(PcapHelper.PacketFields.PACKET_FILTER.getName(), "`casey`");
        }
    };
    FixedPcapConfig config = new FixedPcapConfig(prefixStrategy);
    PcapOptions.BASE_PATH.put(config, BASE_INPUT_PATH_DEFAULT);
    PcapOptions.BASE_INTERIM_RESULT_PATH.put(config, BASE_INTERIM_RESULT_PATH_DEFAULT);
    PcapOptions.FIELDS.put(config, query);
    PcapOptions.NUM_REDUCERS.put(config, 10);
    PcapOptions.START_TIME_MS.put(config, 500L);
    when(jobRunner.submit(isA(Finalizer.class), argThat(mapContaining(config)))).thenReturn(jobRunner);
    PcapCli cli = new PcapCli(jobRunner, prefixStrategy);
    assertThat("Expect no errors on run", cli.run(args), equalTo(0));
    verify(jobRunner).get();
}
Also used : FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) HashMap(java.util.HashMap) Finalizer(org.apache.metron.job.Finalizer) Test(org.junit.jupiter.api.Test)

Example 4 with FixedPcapConfig

use of org.apache.metron.pcap.config.FixedPcapConfig in project metron by apache.

the class PcapCliTest method runs_query_pcap_filter_job_with_full_argument_list.

@Test
public void runs_query_pcap_filter_job_with_full_argument_list() throws Exception {
    String[] args = { "query", "-start_time", "500", "-end_time", "1000", "-num_reducers", "10", "-base_path", "/base/path", "-base_output_path", "/base/output/path", "-query", "some query string", "-records_per_file", "1000", "-finalizer_threads", "10" };
    String query = "some query string";
    FixedPcapConfig config = new FixedPcapConfig(prefixStrategy);
    PcapOptions.BASE_PATH.put(config, "/base/path");
    PcapOptions.BASE_INTERIM_RESULT_PATH.put(config, "/base/output/path");
    PcapOptions.FIELDS.put(config, query);
    PcapOptions.NUM_REDUCERS.put(config, 10);
    // needed bc defaults in config
    PcapOptions.START_TIME_MS.put(config, 500L);
    // needed bc defaults in config
    PcapOptions.END_TIME_MS.put(config, 1000L);
    PcapOptions.NUM_RECORDS_PER_FILE.put(config, 1000);
    PcapOptions.PRINT_JOB_STATUS.put(config, true);
    PcapOptions.FINALIZER_THREADPOOL_SIZE.put(config, "10");
    when(jobRunner.submit(isA(Finalizer.class), argThat(mapContaining(config)))).thenReturn(jobRunner);
    PcapCli cli = new PcapCli(jobRunner, prefixStrategy);
    assertThat("Expect no errors on run", cli.run(args), equalTo(0));
    verify(jobRunner).get();
}
Also used : FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) Finalizer(org.apache.metron.job.Finalizer) Test(org.junit.jupiter.api.Test)

Example 5 with FixedPcapConfig

use of org.apache.metron.pcap.config.FixedPcapConfig in project metron by apache.

the class FixedCliParser method parse.

/**
 * Parses fixed pcap filter options and required parameters common to all filter types.
 *
 * @param args command line arguments to parse
 * @return Configuration tailored to fixed pcap queries
 * @throws ParseException
 */
public FixedPcapConfig parse(String[] args) throws ParseException, java.text.ParseException {
    CommandLine commandLine = getParser().parse(fixedOptions, args);
    FixedPcapConfig config = new FixedPcapConfig(prefixStrategy);
    super.parse(commandLine, config);
    config.putFixedField(Constants.Fields.SRC_ADDR.getName(), commandLine.getOptionValue("ip_src_addr"));
    config.putFixedField(Constants.Fields.DST_ADDR.getName(), commandLine.getOptionValue("ip_dst_addr"));
    config.putFixedField(Constants.Fields.SRC_PORT.getName(), commandLine.getOptionValue("ip_src_port"));
    config.putFixedField(Constants.Fields.DST_PORT.getName(), commandLine.getOptionValue("ip_dst_port"));
    config.putFixedField(Constants.Fields.PROTOCOL.getName(), commandLine.getOptionValue("protocol"));
    config.putFixedField(Constants.Fields.INCLUDES_REVERSE_TRAFFIC.getName(), Boolean.toString(commandLine.hasOption("include_reverse")));
    config.putFixedField(PcapHelper.PacketFields.PACKET_FILTER.getName(), commandLine.getOptionValue("packet_filter"));
    if (commandLine.hasOption("prefix")) {
        config.setFinalFilenamePrefix(commandLine.getOptionValue("prefix"));
    }
    return config;
}
Also used : FixedPcapConfig(org.apache.metron.pcap.config.FixedPcapConfig) CommandLine(org.apache.commons.cli.CommandLine)

Aggregations

FixedPcapConfig (org.apache.metron.pcap.config.FixedPcapConfig)9 Finalizer (org.apache.metron.job.Finalizer)6 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)3 Configuration (org.apache.hadoop.conf.Configuration)3 Path (org.apache.hadoop.fs.Path)3 IOException (java.io.IOException)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 TimestampConverters (org.apache.metron.common.utils.timestamp.TimestampConverters)2 Pageable (org.apache.metron.job.Pageable)2 PcapOptions (org.apache.metron.pcap.config.PcapOptions)2 FixedPcapFilter (org.apache.metron.pcap.filter.fixed.FixedPcapFilter)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Long.toUnsignedString (java.lang.Long.toUnsignedString)1 MethodHandles (java.lang.invoke.MethodHandles)1 java.util (java.util)1 Arrays (java.util.Arrays)1 UUID (java.util.UUID)1 CommandLine (org.apache.commons.cli.CommandLine)1 ParseException (org.apache.commons.cli.ParseException)1