Skip to Content.
Sympa Menu

perfsonar-dev - nmwg: r370 - trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie

Subject: perfsonar development work

List archive

nmwg: r370 - trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie


Chronological Thread 
  • From:
  • To: ,
  • Subject: nmwg: r370 - trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie
  • Date: Mon, 7 Jul 2008 10:32:53 -0400

Author: mac
Date: 2008-07-07 10:32:53 -0400 (Mon, 07 Jul 2008)
New Revision: 370

Modified:
trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/IPAddress.java
trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/SummarizeIpAddrs.java
trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/TrieNode.java
Log:
Small changes in the code.
SummarizeIpAddrs now contains extracted method to be used in java gLS

Modified: trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/IPAddress.java
===================================================================
--- trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/IPAddress.java
2008-07-04 14:55:54 UTC (rev 369)
+++ trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/IPAddress.java
2008-07-07 14:32:53 UTC (rev 370)
@@ -31,10 +31,10 @@
try {
temp = Long.parseLong(aSplitIP);
} catch (Exception e) {
- throw new InvalidIPAddressException("IP address is not
valid");
+ throw new InvalidIPAddressException("IP address is not
valid"+ip);
}
if (temp < 0 || temp > 256) {
- throw new InvalidIPAddressException("IP address is not
valid");
+ throw new InvalidIPAddressException("IP address is not
valid: "+ip);
}
ipInLong = (ipInLong << 8) + temp;
}
@@ -55,10 +55,10 @@
try {
temp = Long.parseLong(aSplitIP);
} catch (Exception e) {
- throw new InvalidIPAddressException("IP address is not
valid");
+ throw new InvalidIPAddressException("IP address is not
valid: "+ip);
}
if (temp < 0 || temp > 256) {
- throw new InvalidIPAddressException("IP address is not
valid");
+ throw new InvalidIPAddressException("IP address is not
valid "+ip);
}
ipInLong = (ipInLong << 8) + temp;
}

Modified:
trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/SummarizeIpAddrs.java
===================================================================
--- trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/SummarizeIpAddrs.java
2008-07-04 14:55:54 UTC (rev 369)
+++ trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/SummarizeIpAddrs.java
2008-07-07 14:32:53 UTC (rev 370)
@@ -2,44 +2,61 @@

import java.io.IOException;
import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;

public class SummarizeIpAddrs {
+
+ public static Set<String> getSummary(Collection<String> ipAddresses) {
+
+ final TrieNode ROOTNODE = new TrieNode(-1, Constants.MAX_KEY_LENGTH);
+ Trie trie = new Trie(ROOTNODE);
+
+ for (String newIpAddr : ipAddresses) {
+ try {
+ IPAddress newIp = new IPAddress(newIpAddr);
+ long aLongValue = newIp.getAddrAsLong();
+ trie = trie.Add(aLongValue, Constants.MAX_KEY_LENGTH, newIp);
+ } catch (InvalidIPAddressException e) {
+ System.err.println("Ignoring address: " + newIpAddr);
+ }
+ }
+
+ IpTrie ipTrie = new IpTrie(trie);
+ ArrayList<IpTrieNode> nodeList = ipTrie.getSummary();
+
+ Set<String> output = new HashSet<String>();
+ for (IpTrieNode node : nodeList) {
+ output.add(node.addrString);
+ }
+ return output;
+
+ }
+
+
/**
* @param args
*/
- public static void main(String[] args) throws
InvalidIPAddressException, IOException {
- String inputFile;
- if (args.length > 0) {
- inputFile = args[0];
- }
- else {
- inputFile = Constants.FILENAME;
- }
+ public static void main(String[] args) throws InvalidIPAddressException,
+ IOException {

- final TrieNode ROOTNODE = new TrieNode(-1,
Constants.MAX_KEY_LENGTH);
- Trie trie = new Trie(ROOTNODE);
+ String inputFile;
+ if (args.length > 0) {
+ inputFile = args[0];
+ } else {
+ inputFile = "IPAddressList.txt";
+ }

- String[] splitIPAddressInString =
StringBufferUtilities.getContents(inputFile).split("\n");
+ String[] splitIPAddressInString = StringBufferUtilities.getContents(
+ inputFile).split("\n");
+ Collection<String> ipAddresses =
Arrays.asList(splitIPAddressInString);

- ArrayList<IPAddress> listOfIpAddresses = new
ArrayList<IPAddress>();
- for (String newIpAddr : splitIPAddressInString) {
- IPAddress newIp = new IPAddress(newIpAddr);
- listOfIpAddresses.add(newIp);
- long aLongValue = newIp.getAddrAsLong();
- trie = trie.Add(aLongValue, Constants.MAX_KEY_LENGTH,
newIp);
- }
+ Set<String> result = getSummary(ipAddresses);

- String dotFilename = inputFile.replace(".txt", ".dot");
- trie.printDot(dotFilename);
-
- IpTrie ipTrie = new IpTrie(trie);
- ArrayList<IpTrieNode> nodelist = ipTrie.getSummary();
- Iterator<IpTrieNode> it = nodelist.iterator();
- for ( IpTrieNode node; it.hasNext(); ) {
- node = it.next();
- System.out.println(node.addrString);
- }
- }
+ System.out.println(result);

+ }
+
}

Modified: trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/TrieNode.java
===================================================================
--- trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/TrieNode.java
2008-07-04 14:55:54 UTC (rev 369)
+++ trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie/TrieNode.java
2008-07-07 14:32:53 UTC (rev 370)
@@ -171,7 +171,7 @@
if(newNode.childOne == null && newNode.childZero == null){
this.childCount++;
if(newNode.childCount > 1) {
- System.out.println("confusion");
+ //System.out.println("--confusion--");
}
newNode.childCount = 0;
}



  • nmwg: r370 - trunk/nmwg/doc/dLS/gLS/examples/java/src/iptrie, svnlog, 07/07/2008

Archive powered by MHonArc 2.6.16.

Top of Page