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);
}
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);
}
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();
}
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();
}
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;
}
Aggregations