public class PacketCount {
public static class Map extends Mapper< LongWritable, BytesWritable, Text, IntWritable > {
private final static IntWritable one = new IntWritable(1);
PacketStatsWritable ps = new PacketStatsWritable();
public void map(LongWritable key, BytesWritable value, Context context) {
if(value.getBytes().length<MIN_PKT_SIZE) return;
ps.parse(value.getBytes()); // 패킷 각 필드 추출
context.write(p.getSrc_ip(), one);
}
}
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
context.write( key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf, "wordcount");
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setInputFormatClass(PcapInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true);
}
}
'System > Linux' 카테고리의 다른 글
리눅스에서 파일 작업 (0) | 2012.09.17 |
---|---|
하둡 기반의 규모 확장성 있는 트래픽.pdf (0) | 2012.08.12 |
하둡 관련 링크 (0) | 2012.08.10 |
우분투 eclipse 실행 오류(jdk 연동 안될 때) (0) | 2012.07.16 |
Fedora16 설치(2/2) - Windows7 멀티부팅으로 페도라 설치 (2) | 2012.07.13 |