views:

55

answers:

1

I have a number of traceroutes that i need to compare against each other but i dont know the best way to do it, ive been told that hash maps are a good technique but i dont know how to implement them on my code.

so far i have:

FileInputStream fstream = new FileInputStream("traceroute.log");


// Get the object of DataInputStream

DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));

String strLine;


// reads lines in
while ((strLine = br.readLine()) != null) {

System.out.println(strLine);

and the output looks like this:

Wed Mar 31 01:00:03 BST 2010

traceroute to www.bbc.co.uk (212.58.251.195), 30 hops max, 40 byte packets
 1  139.222.0.1 (139.222.0.1)  0.873 ms  1.074 ms  1.162 ms 
 2  core-from-cmp.uea.ac.uk (10.0.0.1)  0.312 ms  0.350 ms  0.463 ms
 3  ueaha1btm-from-uea1 (172.16.0.34)  0.791 ms  0.772 ms  1.238 ms
 4  bound-from-ueahatop.uea.ac.uk (193.62.92.71)  5.094 ms  4.451 ms  4.441 ms
 5  gi0-3.norw-rbr1.eastnet.ja.net (193.60.0.21)  4.426 ms  5.014 ms  4.389 ms
 6  gi3-0-2.chel-rbr1.eastnet.ja.net (193.63.107.114)  6.055 ms  6.039 ms *
 7  lond-sbr1.ja.net (146.97.40.45)  6.994 ms  7.493 ms  7.457 ms
 8  so-6-0-0.lond-sbr4.ja.net (146.97.33.154)  8.206 ms  8.187 ms  8.234 ms
 9  po1.lond-ban4.ja.net (146.97.35.110)  8.673 ms  6.294 ms  7.668 ms
10  bbc.lond-sbr4.ja.net (193.62.157.178)  6.303 ms  8.118 ms  8.107 ms
11  212.58.238.153 (212.58.238.153)  6.245 ms  8.066 ms  6.541 ms
12  212.58.239.62 (212.58.239.62)  7.023 ms  8.419 ms  7.068 ms

what i need to do is compare this trace against another one just like it and look for the changes and time differences etc, then print a stats page.

A: 

I would define a data class (TraceEntry) that encapsulates a single entry info: serial number, host name, ip and time durations. Then I would define the equals() method according to the matching criteria (ip I suppose?), and implement hashCode() accordingly.

Now, it is possible to add all entries of one trace into a hashset, and then scan the other trace, looking for matches in the hashset. Whenever a match is found you can check the differences in the fields other than the ip.

I hope I understood well your comparison model.

Eyal Schneider
yeah this would work, but how do i encapsulate a single entry?
@ben-casey: which part is not clear and you want to focus on? parsing of the trace text, implementation of TraceEntry, or the usage of the HashSet?
Eyal Schneider