perfsonar-dev - perfsonar: r5399 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice/registration/summarization main/java/org/perfsonar/service/lookupservice/summarization test/java/org/perfsonar/tests/summarization
Subject: perfsonar development work
List archive
perfsonar: r5399 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice/registration/summarization main/java/org/perfsonar/service/lookupservice/summarization test/java/org/perfsonar/tests/summarization
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5399 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice/registration/summarization main/java/org/perfsonar/service/lookupservice/summarization test/java/org/perfsonar/tests/summarization
- Date: Thu, 10 Dec 2009 05:16:59 -0500
Author: trzaszcz
Date: 2009-12-10 05:16:59 -0500 (Thu, 10 Dec 2009)
New Revision: 5399
Added:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ServiceSummaryBean.java
Removed:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IPAddressConvertor.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/StringBufferUtilities.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ServiceSummary.java
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Constants.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IPAddress.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/InvalidIPAddressException.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IpTrie.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IpTrieNode.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/SummarizationHelper.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/SummarizeIpAddrs.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Trie.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/summarization/SummarizationTests.java
Log:
refactored, added javadocs, removed unused code from summarizatiom, changed
class access
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Constants.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Constants.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Constants.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -6,7 +6,11 @@
* @author swany
*
*/
-
-public interface Constants {
+interface Constants {
public final static int MAX_KEY_LENGTH = 32;
+
+ /**
+ * nr of ip segments IPv4 constists of 4 segments
+ */
+ public final static int NR_OF_IP_SEGMENTS = 4;
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IPAddress.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IPAddress.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IPAddress.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -1,100 +1,63 @@
package org.perfsonar.service.lookupservice.registration.summarization;
+
/**
- * Summarization code
*
- * Representation of the IP address
+ * Representation of the IP address, stores address IP (in string,long form)
*
* @author swany
- *
+ *
*/
-public class IPAddress {
- private String addrAsString;
+class IPAddress {
private long addrAsLong;
- private long maskAsLong;
-
- public IPAddress (String newIp) throws InvalidIPAddressException {
- addrAsString = newIp;
+
+ public IPAddress(String newIp) throws InvalidIPAddressException {
addrAsLong = this.ipToLong(newIp);
}
- public String getString() {
- return addrAsString;
- }
public long getAddrAsLong() {
return addrAsLong;
}
- public long getMaskAsLong() {
- return maskAsLong;
- }
+ /**
+ *
+ * converts IP from string to long
+ *
+ * @param ip
+ * @return
+ * @throws InvalidIPAddressException
+ */
public long ipToLong(String ip) throws InvalidIPAddressException {
-
- ip = ip.replace(".", ":");
- String[] splitIP = ip.split(":");
+
+ String[] splitIP = ip.split("\\.");
long temp;
long ipInLong = 0;
+ boolean mallformed=false;
- for (String aSplitIP : splitIP) {
- try {
- temp = Long.parseLong(aSplitIP);
- } catch (Exception e) {
- throw new InvalidIPAddressException("IP address is not
valid"+ip);
- }
- if (temp < 0 || temp > 256) {
- throw new InvalidIPAddressException("IP address is not
valid: "+ip);
- }
- ipInLong = (ipInLong << 8) + temp;
- }
-
- return ipInLong;
-
- }
- public long[] ipArrayToLongArray(String[] ip) throws
InvalidIPAddressException {
- long[] ipArray = new long[ip.length];
+ if(splitIP.length!=Constants.NR_OF_IP_SEGMENTS){
+ mallformed=true;
+ }else{
+ for (String aSplitIP : splitIP) {
+ try {
+ temp = Long.parseLong(aSplitIP);
+ } catch (NumberFormatException e) {
+ mallformed=true;
+ break;
+ }
+ if (temp < 0 || temp > 256) {
+ mallformed=true;
+ break;
+ }
+ ipInLong = (ipInLong << 8) + temp;
+ }
+ }
- for (int i = 0; i < ip.length; i++) {
+ if(mallformed){
+ throw new InvalidIPAddressException("IP address is
not valid: "+ ip);
+ }
- ip[i] = ip[i].replace(".", ":");
- String[] splitIP = ip[i].split(":");
- long temp;
- long ipInLong = 0;
- for (String aSplitIP : splitIP) {
- try {
- temp = Long.parseLong(aSplitIP);
- } catch (Exception e) {
- throw new InvalidIPAddressException("IP address is not
valid: "+ip);
- }
- if (temp < 0 || temp > 256) {
- throw new InvalidIPAddressException("IP address is not
valid "+ip);
- }
- ipInLong = (ipInLong << 8) + temp;
- }
- ipArray[i] = ipInLong;
- }
- return ipArray;
- }
-
- public String longToIP(Long ipInLong) {
-
- String ipAddress = "";
- long[] ipArrayInLong = new long[4];
- long num;
-
- for (int i = 0; i < 4; i++) {
-
- double factor = Math.pow(256, (4 - i - 1));
- num = ipInLong / (long) factor;
- ipInLong = ipInLong - (num * (long) factor);
- if (num > 255) {
- System.out.println("Invalid CONVERSION");
- }
- ipArrayInLong[i] = num;
- ipAddress = ipAddress.concat("" + ipArrayInLong[i]);
- if (i != 3) {
- ipAddress = ipAddress.concat(".");
- }
- }
- return ipAddress;
- }
+ return ipInLong;
+ }
+
+
}
\ No newline at end of file
Deleted:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IPAddressConvertor.java
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/InvalidIPAddressException.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/InvalidIPAddressException.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/InvalidIPAddressException.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -1,15 +1,14 @@
package org.perfsonar.service.lookupservice.registration.summarization;
+
/**
- * Summarization code
+ * Exception is thrown when IPAddress is incorrect
*
* @author swany
- *
*/
-
@SuppressWarnings("serial")
-public class InvalidIPAddressException extends Exception{
+public class InvalidIPAddressException extends Exception {
- InvalidIPAddressException(final String message) {
- super(message);
- }
+ InvalidIPAddressException(final String message) {
+ super(message);
+ }
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IpTrie.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IpTrie.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IpTrie.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -3,28 +3,27 @@
import java.util.ArrayList;
import java.util.Iterator;
-
/**
- * @author swany
- * This class wraps the base Trie with IP-specific semantics
- * such as shifting the current keys into the correct position.
- * For now, this will be created from a basic Trie containing
- * IP information and will provide iterator functionality
+ * This class wraps the base Trie with IP-specific semantics such
+ * as shifting the current keys into the correct position. For now, this
+ * will be created from a basic Trie containing IP information and will
+ * provide iterator functionality
+ *
+ * @author swany
*/
-public class IpTrie {
-
-
+class IpTrie {
+
private Trie trie;
private ArrayList<IpTrieNode> nodelist;
- IpTrieNode root;
-
- public IpTrie (Trie t) {
+ private IpTrieNode root;
+
+ public IpTrie(Trie t) {
// need to establish state for an iterator
trie = t;
nodelist = new ArrayList<IpTrieNode>();
this.updateNodelist();
}
-
+
/**
* this method will walk the Trie and fill in IpTrieNodes
*/
@@ -37,120 +36,44 @@
walkTree(root, startPosition, startKey);
}
- // walk the tree from node down
+ /**
+ *
+ * walk the tree from node down and build IPpTrieNodes
+ *
+ * @param node - start Node
+ * @param position
+ * @param currentKey
+ */
private void walkTree(IpTrieNode node, long position, long
currentKey) {
TrieNode tnode = node.trieNode;
TrieNode c0 = tnode.getChildZero();
TrieNode c1 = tnode.getChildOne();
-
+
if (c0 != null) {
- long c0Key = c0.getKey() << (position - c0.getKeyLength());
- long c0Position = position - c0.getKeyLength();
- c0Key = c0Key | currentKey;
- IpTrieNode c0ipTrieNode = new IpTrieNode(c0, c0Position,
c0Key);
- nodelist.add(c0ipTrieNode);
- node.setChildZero(c0ipTrieNode);
- c0ipTrieNode.setParent(node);
- walkTree(c0ipTrieNode,c0Position, c0Key);
+ long c0Key = c0.getKey() << (position -
c0.getKeyLength());
+ long c0Position = position - c0.getKeyLength();
+ c0Key = c0Key | currentKey;
+ IpTrieNode c0ipTrieNode = new IpTrieNode(c0,
c0Position, c0Key);
+ nodelist.add(c0ipTrieNode);
+ node.setChildZero(c0ipTrieNode);
+ c0ipTrieNode.setParent(node);
+ walkTree(c0ipTrieNode, c0Position, c0Key);
- }
- if (c1 != null) {
- long c1Key = c1.getKey() << (position - c1.getKeyLength());
- long c1Position = position - c1.getKeyLength();
- c1Key = c1Key | currentKey;
- IpTrieNode c1ipTrieNode = new IpTrieNode(c1, c1Position,
c1Key);
- nodelist.add(c1ipTrieNode);
- node.setChildOne(c1ipTrieNode);
- c1ipTrieNode.setParent(node);
- walkTree(c1ipTrieNode,c1Position, c1Key);
- }
-
- }
-
- public ArrayList<IpTrieNode> getNodes() {
- return nodelist;
- }
-
- public ArrayList<IpTrieNode> getInternalNodes() {
- ArrayList<IpTrieNode> alitn = new ArrayList<IpTrieNode>();
- Iterator<IpTrieNode> it = nodelist.iterator();
- for ( IpTrieNode node; it.hasNext(); ) {
- node = it.next();
- if (node.childZero != null) {
- alitn.add(node);
- }
}
- return alitn;
- }
-
- public ArrayList<IpTrieNode> getSummaryNodes() {
- ArrayList<IpTrieNode> alitn = new ArrayList<IpTrieNode>();
- Iterator<IpTrieNode> it = nodelist.iterator();
- for ( IpTrieNode node; it.hasNext(); ) {
- node = it.next();
- // evaluate what to return
- // here we say if the data pointer is null, but it
- // has one child with data, then it is on the summary
front
-
- // hackage for the root node, which might have a null
child
- // no other node does
- if (node.childOne == null || node.childZero == null)
continue;
-
- if (node.trieNode.getData() == null &&
- (node.childZero.trieNode.getData() != null ||
- node.childOne.trieNode.getData() != null) ) {
- alitn.add(node);
- }
+ if (c1 != null) {
+ long c1Key = c1.getKey() << (position -
c1.getKeyLength());
+ long c1Position = position - c1.getKeyLength();
+ c1Key = c1Key | currentKey;
+ IpTrieNode c1ipTrieNode = new IpTrieNode(c1,
c1Position, c1Key);
+ nodelist.add(c1ipTrieNode);
+ node.setChildOne(c1ipTrieNode);
+ c1ipTrieNode.setParent(node);
+ walkTree(c1ipTrieNode, c1Position, c1Key);
}
- return alitn;
+
}
-
- public ArrayList<IpTrieNode> getSummaryNodesHueristic_dumb() {
- ArrayList<IpTrieNode> alitn = new ArrayList<IpTrieNode>();
- Iterator<IpTrieNode> it = nodelist.iterator();
- for ( IpTrieNode node; it.hasNext(); ) {
- node = it.next();
- // evaluate what to return
- // here we say if the data pointer is null, but it
- // has one child with data, then it is on the summary
front
-
- // hackage for the root node, which might have a null
child
- // no other node does
- if (node.childOne == null || node.childZero == null)
continue;
-
- if (node.trieNode.getData() == null &&
- (node.childZero.trieNode.getData() != null ||
- node.childOne.trieNode.getData() != null) ) {
- alitn.add(node);
- }
- }
-
- ArrayList<IpTrieNode> alitn2 = new ArrayList<IpTrieNode>();
- it = alitn.iterator();
- for ( IpTrieNode node; it.hasNext(); ) {
- node = it.next();
- if( (node.mask - node.parent.mask) > 2) {
- alitn2.add(node);
- }
- }
-
- //sanity check
- long sum = 0;
- it = alitn2.iterator();
- for ( IpTrieNode node; it.hasNext(); ) {
- node = it.next();
- System.out.println(node.addrString + " " +
node.childCount);
- sum += node.childCount;
- }
-
- if (sum != trie.getCount()) {
- System.out.println("sum, nodeCount " + sum + " " +
trie.getCount());
- System.out.println("Heuristic failed!");
- alitn2.clear();
- }
- return alitn2;
- }
-
+
+
public ArrayList<IpTrieNode> getSummary() {
ArrayList<IpTrieNode> alitn = new ArrayList<IpTrieNode>();
if (root.childZero != null) {
@@ -159,51 +82,51 @@
if (root.childOne != null) {
walkIpTrie(alitn, root.childOne);
}
-
- //sanity check
+
+ // sanity check
long sum = 0;
Iterator<IpTrieNode> it = alitn.iterator();
- for ( IpTrieNode node; it.hasNext(); ) {
+ for (IpTrieNode node; it.hasNext();) {
node = it.next();
sum += node.childCount;
- if (node.mask == 32) sum++;
+ if (node.mask == 32)
+ sum++;
}
-
+
if (sum != trie.getCount()) {
- System.out.println("Summarization failed! (covered "
+ sum + "prefixes out of " + trie.getCount() + ")");
+ System.out.println("Summarization failed! (covered "
+ sum
+ + "prefixes out of " +
trie.getCount() + ")");
alitn.clear();
}
-
+
return alitn;
}
-
- /* this will consider whether to recurse down the tree or
- * add itself to the summary list and prune the subtree.
+
+ /**
+ *
+ * this will consider whether to recurse down the tree or add itself
to the
+ * summary list and prune the subtree.
+ *
+ * add itself to summarization result when :
+ * - childOne is null
+ * - childOne or childZero have mask less or equal than 8
+ *
+ * @param alitn
+ * @param node
*/
- private void walkIpTrie (ArrayList<IpTrieNode> alitn, IpTrieNode
node) {
+ private void walkIpTrie(ArrayList<IpTrieNode> alitn, IpTrieNode node)
{
IpTrieNode c0n = node.childZero;
IpTrieNode c1n = node.childOne;
-
- if(c0n == null) {
+
+ if (c0n == null) {
alitn.add(node);
- }
- else if((c0n.mask - node.mask > 8) || (c1n.mask - node.mask >
8)) {
+ } else if ((c0n.mask - node.mask > 8) || (c1n.mask -
node.mask > 8)) {
walkIpTrie(alitn, c0n);
walkIpTrie(alitn, c1n);
- }
- else {
+ } else {
+ //if mask of the childOne or childZero are less than
8 add this node to summary
alitn.add(node);
}
-
+
}
- /*
- public void printDot(String fileName) throws FileNotFoundException {
- FileOutputStream file = new FileOutputStream(fileName);
- PrintStream p = new PrintStream(file);
- p.println("digraph g {");
-
- p.println("}");
- p.close();
- }
- */
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IpTrieNode.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IpTrieNode.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/IpTrieNode.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -1,12 +1,15 @@
package org.perfsonar.service.lookupservice.registration.summarization;
-
/**
+ *
+ * This class contains IP-specific references to a generic Trie
+ *
+ *
* @author swany
- * This class contains IP-specific references to a
- * generic Trie
+ *
*/
-public class IpTrieNode {
+class IpTrieNode {
+
long mask;
long ipAddress;
long key;
@@ -16,7 +19,7 @@
IpTrieNode parent;
IpTrieNode childZero, childOne;
long childCount;
-
+
public IpTrieNode(TrieNode tnode, long position, long currentKey) {
SummarizationHelper helper = new SummarizationHelper();
trieNode = tnode;
@@ -26,17 +29,17 @@
addrString = keyString + "/" + mask;
childCount = tnode.getChildCount();
}
-
+
public IpTrieNode setParent(IpTrieNode newParent) {
parent = newParent;
return this;
}
-
+
public IpTrieNode setChildZero(IpTrieNode newChild) {
childZero = newChild;
return this;
}
-
+
public IpTrieNode setChildOne(IpTrieNode newChild) {
childOne = newChild;
return this;
Deleted:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/StringBufferUtilities.java
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/SummarizationHelper.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/SummarizationHelper.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/SummarizationHelper.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -1,55 +1,57 @@
package org.perfsonar.service.lookupservice.registration.summarization;
import java.util.ArrayList;
+
/**
- * Summarization code
*
- * The purpose of the Helper class is to separate the code that is not a
part of the functionality of Trie.java, but makes use of the data found there
for display purposes
+ * The purpose of the Helper class is to separate the code that is not a
part of
+ * the functionality of Trie.java, but makes use of the data found there for
+ * display purposes
*
* @author swany
- *
+ *
*/
-public class SummarizationHelper {
+class SummarizationHelper {
- public int displayElementsInKeyList(ArrayList<TrieNode> keyList) {
- long keyDifference;
- String mostDominantKey;
- int noOfNodes = 0;
+ public int displayElementsInKeyList(ArrayList<TrieNode> keyList) {
+ long keyDifference;
+ String mostDominantKey;
+ int noOfNodes = 0;
- for (TrieNode tempNode : keyList) {
- ++noOfNodes;
- keyDifference = Constants.MAX_KEY_LENGTH -
tempNode.getKeyLength();
- mostDominantKey = longToIP(tempNode.getKey());
- System.out.println("\nThe node is : " + mostDominantKey + "/" +
keyDifference);
- }
- return noOfNodes;
- }
-
- /**
- * conversion from IP in long notation to standard IP format
- *
- * @param ipInLong
- * @return string notation of the ip
- */
- public String longToIP(Long ipInLong) {
+ for (TrieNode tempNode : keyList) {
+ ++noOfNodes;
+ keyDifference = Constants.MAX_KEY_LENGTH -
tempNode.getKeyLength();
+ mostDominantKey = longToIP(tempNode.getKey());
+ System.out.println("\nThe node is : " +
mostDominantKey + "/"
+ + keyDifference);
+ }
+ return noOfNodes;
+ }
- String ipAddress = "";
- long num;
+ /**
+ * conversion from IP in long notation to standard IP format
+ *
+ * @param ipInLong
+ * @return string notation of the ip
+ */
+ public String longToIP(Long ipInLong) {
- for (int i = 0; i < 4; i++) {
+ String ipAddress = "";
+ long num;
- double factor = Math.pow(256, (4 - i - 1));
- num = ipInLong / (long) factor;
- ipInLong = ipInLong - (num * (long) factor);
- if (num > 255) {
- System.err.println("Invalid IP address ");
- }
- ipAddress = ipAddress.concat("" + num);
- if (i != 3) {
- ipAddress = ipAddress.concat(".");
- }
- }
- return ipAddress;
- }
+ for (int i = 0; i < Constants.NR_OF_IP_SEGMENTS; i++) {
+
+ double factor = Math.pow(256,
(Constants.NR_OF_IP_SEGMENTS - i - 1));
+ num = ipInLong / (long) factor;
+ ipInLong = ipInLong - (num * (long) factor);
+ if (num > 255) {
+ System.err.println("Invalid IP address ");
+ }
+ ipAddress = ipAddress.concat("" + num);
+ if (i != 3) {
+ ipAddress = ipAddress.concat(".");
+ }
+ }
+ return ipAddress;
+ }
}
-
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/SummarizeIpAddrs.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/SummarizeIpAddrs.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/SummarizeIpAddrs.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -1,14 +1,12 @@
package org.perfsonar.service.lookupservice.registration.summarization;
-import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
- * Summarization code
+ * main class that summarize IPs
*
* @author swany
* @author mac
@@ -24,6 +22,7 @@
*/
public static Set<String> getSummary(Collection<String> ipAddresses) {
+ //initialization of the root node in Tree
final TrieNode ROOTNODE = new TrieNode(-1, Constants.MAX_KEY_LENGTH);
Trie trie = new Trie(ROOTNODE);
@@ -31,7 +30,7 @@
try {
IPAddress newIp = new IPAddress(newIpAddr);
long aLongValue = newIp.getAddrAsLong();
- trie = trie.Add(aLongValue, Constants.MAX_KEY_LENGTH, newIp);
+ trie = trie.add(aLongValue, Constants.MAX_KEY_LENGTH, newIp);
} catch (InvalidIPAddressException e) {
System.err.println("Ignoring address: " + newIpAddr);
}
@@ -48,28 +47,4 @@
}
-
- /**
- * @param args
- */
- public static void main(String[] args) throws InvalidIPAddressException,
- IOException {
-
- String inputFile;
- if (args.length > 0) {
- inputFile = args[0];
- } else {
- inputFile = "IPAddressList.txt";
- }
-
- String[] splitIPAddressInString = StringBufferUtilities.getContents(
- inputFile).split("\n");
- Collection<String> ipAddresses =
Arrays.asList(splitIPAddressInString);
-
- Set<String> result = getSummary(ipAddresses);
-
- System.out.println(result);
-
- }
-
}
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Trie.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Trie.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/Trie.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -12,7 +12,7 @@
* @author swany
*
*/
-public class Trie {
+class Trie {
private int nodeCount;
private ArrayList<TrieNode> keyList = new ArrayList<TrieNode>();
@@ -31,27 +31,48 @@
return rootNode;
}
- private long firstDigit(long key, long keyLength) {
- return ((key >> (keyLength - 1)) & 1);
+ /**
+ *
+ * gets first digit from longIP
+ *
+ *
+ * @param longIp
+ * @param ipLength
+ * @return 0 or 1
+ */
+ private long firstDigit(long longIp, long ipLength) {
+ return ((longIp >> (ipLength - 1)) & 1);
}
- public Trie Add(long key, long keyLength, Object data) {
+ /**
+ *
+ * adds element to Trie. Element can be added to ChildOne or
ChildZero. It depends of the bit value
+ *
+ *
+ * @param longIP
+ * @param ipLength
+ * @param ipAddressObject
+ * @return
+ */
+ public Trie add(long longIP, long ipLength, IPAddress
ipAddressObject) {
nodeCount++;
rootNode.incrementChildCount();
- if (firstDigit(key, keyLength) == 1) {
+ if (firstDigit(longIP, ipLength) == 1) {
+ //add to childOne
if (rootNode.getChildOne() != null) {
- rootNode.getChildOne().Add(key, keyLength,
data);
+ rootNode.getChildOne().add(longIP, ipLength,
ipAddressObject);
} else {
- rootNode.setChildOne(new TrieNode(key,
keyLength));
- rootNode.getChildOne().setData(data);
+ rootNode.setChildOne(new TrieNode(longIP,
ipLength));
+
rootNode.getChildOne().setData(ipAddressObject);
}
} else {
+ //add to childZero
if (rootNode.getChildZero() != null) {
- rootNode.getChildZero().Add(key, keyLength,
data);
+ rootNode.getChildZero().add(longIP, ipLength,
ipAddressObject);
} else {
- rootNode.setChildZero(new TrieNode(key,
keyLength));
- rootNode.getChildZero().setData(data);
+ rootNode.setChildZero(new TrieNode(longIP,
ipLength));
+
rootNode.getChildZero().setData(ipAddressObject);
}
}
return this;
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/registration/summarization/TrieNode.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -4,432 +4,437 @@
import java.util.ArrayList;
/**
- * Summarization code
+ * Representation of the node, every node can have only two children
(childZero,childOne)
*
* @author swany
- *
+ *
*/
-public class TrieNode {
+class TrieNode {
- private long key;
+ private long key;
+ private long keyLength;
+ private long valueCount;
+ private long childCount;
+ private Object data;
+ private TrieNode childZero;
+ private TrieNode childOne;
+ private SummarizationHelper helper = new SummarizationHelper();
- private long keyLength;
+
+ private TrieNode(long ipAddress, long ipLength, long valueCount) {
+ this.key = ipAddress;
+ this.keyLength = ipLength;
+ this.valueCount = valueCount;
+ }
- private long valueCount;
-
- private long childCount;
-
- private Object data;
+ /**
+ *
+ * @param ipAddress
+ * @param ipLength
+ */
+ public TrieNode(long ipAddress, long ipLength) {
+ this.key = ipAddress;
+ this.keyLength = ipLength;
+ valueCount = 1;
+ childCount = 0;
+ }
+
+
+ public void incrementChildCount() {
+ this.childCount++;
+ }
- private TrieNode childZero;
+ public long getChildCount() {
+ return this.childCount;
+ }
- private TrieNode childOne;
-
- SummarizationHelper helper = new SummarizationHelper();
+ public TrieNode getChildZero() {
+ return childZero;
+ }
- public void incrementChildCount() {
- this.childCount++;
- }
-
- public long getChildCount() {
- return this.childCount;
- }
+ public void setChildZero(TrieNode childZero) {
+ this.childZero = childZero;
+ }
- public TrieNode getChildZero() {
- return childZero;
- }
+ public TrieNode getChildOne() {
+ return childOne;
+ }
- public void setChildZero(TrieNode childZero) {
- this.childZero = childZero;
- }
+ public void setChildOne(TrieNode childOne) {
+ this.childOne = childOne;
+ }
- public TrieNode getChildOne() {
- return childOne;
- }
+ public long getKey() {
+ return key;
+ }
- public void setChildOne(TrieNode childOne) {
- this.childOne = childOne;
- }
+ public long getKeyLength() {
+ return keyLength;
+ }
- public long getKey() {
- return key;
- }
+ private static long firstDigit(long key, long keyLength) {
+ return (key >> (keyLength - 1)) & 1;
+ }
- public long getKeyLength() {
- return keyLength;
- }
+ private static long[] getCommonPart(long keyA, long keyLengthA, long
keyB,
+ long keyLengthB) {
+ // truncate the keys so they are the same size (discard low
bits)
+ if (keyLengthA > keyLengthB) {
+ keyA >>= keyLengthA - keyLengthB;
+ keyLengthA = keyLengthB;
+ } else {
+ keyB >>= keyLengthB - keyLengthA;
+ }
- private TrieNode(long key, long keyLength, long valueCount) {
- this.key = key;
- this.keyLength = keyLength;
- this.valueCount = valueCount;
- }
+ long diff = keyA ^ keyB;
+ int count = 0;
+ while (diff != 0) {
+ diff >>= 1;
+ count++;
+ }
+ long keyCommon = keyA >> count;
+ long keyLengthCommon = keyLengthA - count;
- public TrieNode(long key, long keyLength) {
- this.key = key;
- this.keyLength = keyLength;
- valueCount = 1;
- childCount = 0;
- }
+ return new long[] { keyCommon, keyLengthCommon };
+ }
- private static long firstDigit(long key, long keyLength) {
- return (key >> (keyLength - 1)) & 1;
- }
+ public boolean Equals(TrieNode node) {
+ return node != null
+ && (this.key == node.key && this.keyLength ==
node.keyLength);
+ }
- private static long[] getCommonPart(long keyA, long keyLengthA, long
keyB, long keyLengthB) {
- // truncate the keys so they are the same size (discard low bits)
- if (keyLengthA > keyLengthB) {
- keyA >>= keyLengthA - keyLengthB;
- keyLengthA = keyLengthB;
- } else {
- keyB >>= keyLengthB - keyLengthA;
- }
+ public boolean isKey() {
+ return valueCount > 0;
+ }
- long diff = keyA ^ keyB;
- int count = 0;
- while (diff != 0) {
- diff >>= 1;
- count++;
- }
+ // no of times the key is repeated.
+ public long getValueCount() {
+ return valueCount;
+ }
- long keyCommon = keyA >> count;
- long keyLengthCommon = keyLengthA - count;
+ public void setValueCount(long valueCount) {
+ this.valueCount = valueCount;
+ }
- return new long[]{keyCommon, keyLengthCommon};
- }
+ public void setValueCount(Object value) {
+ data = value;
+ }
- public boolean Equals(TrieNode node) {
- return node != null && (this.key == node.key && this.keyLength ==
node.keyLength);
- }
+ public Object getData() {
+ return data;
+ }
- public boolean isKey() {
- return valueCount > 0;
- }
+ public void setData(Object data) {
+ this.data = data;
+ }
- //no of times the key is repeated.
- public long getValueCount() {
- return valueCount;
- }
+ public TrieNode add(long key, long keyLength, Object data) {
+ this.childCount++;
- public void setValueCount(long valueCount) {
- this.valueCount = valueCount;
- }
+ if (key == this.key && keyLength == this.keyLength) {
+ this.valueCount++;
+ } else {
+ long keyDiff;
+ long keyLengthDiff;
+ TrieNode newNode;
- public void setValueCount(Object value) {
- data = value;
- }
+ long[] commonKeyAndKeyLength = getCommonPart(key,
keyLength,
+ this.key, this.keyLength);
- public Object getData() {
- return data;
- }
+ long keyCommon = commonKeyAndKeyLength[0];
+ long keyLengthCommon = commonKeyAndKeyLength[1];
- public void setData(Object data) {
- this.data = data;
- }
+ keyLengthDiff = this.keyLength - keyLengthCommon;
+ keyDiff = this.key - (keyCommon << keyLengthDiff);
- public TrieNode Add(long key, long keyLength, Object data) {
- this.childCount++;
-
- if (key == this.key && keyLength == this.keyLength) {
- this.valueCount++;
- } else {
- long keyDiff;
- long keyLengthDiff;
- TrieNode newNode;
-
- long[] commonKeyAndKeyLength =
- getCommonPart(key, keyLength, this.key, this.keyLength);
+ if (keyLengthDiff > 0) {
+ newNode = new TrieNode(keyDiff,
keyLengthDiff);
+ newNode.valueCount = this.valueCount;
+ newNode.childZero = this.childZero;
+ newNode.childOne = this.childOne;
+ newNode.data = this.data;
+ newNode.childCount = this.childCount - 1;
- long keyCommon = commonKeyAndKeyLength[0];
- long keyLengthCommon = commonKeyAndKeyLength[1];
+ // update this node to hold common part
+ this.key = keyCommon;
+ this.keyLength = keyLengthCommon;
+ this.valueCount = 0;
+ this.data = null;
- keyLengthDiff = this.keyLength - keyLengthCommon;
- keyDiff = this.key - (keyCommon << keyLengthDiff);
+ // and set the new node as child of this node
+ if (firstDigit(keyDiff, keyLengthDiff) == 1) {
+ this.childZero = null;
+ this.childOne = newNode;
+ } else {
+ this.childZero = newNode;
+ this.childOne = null;
+ }
- if (keyLengthDiff > 0) {
- newNode = new TrieNode(keyDiff, keyLengthDiff);
- newNode.valueCount = this.valueCount;
- newNode.childZero = this.childZero;
- newNode.childOne = this.childOne;
- newNode.data = this.data;
- newNode.childCount = this.childCount - 1;
+ if (newNode.childOne == null &&
newNode.childZero == null) {
+ this.childCount++;
+ newNode.childCount = 0;
+ }
+ }
- // update this node to hold common part
- this.key = keyCommon;
- this.keyLength = keyLengthCommon;
- this.valueCount = 0;
- this.data = null;
+ // process diff with the new key, if any
+ if (keyLength > keyLengthCommon) {
+ // get diff with the new key
+ keyLengthDiff = keyLength - keyLengthCommon;
+ keyDiff = key - (keyCommon << keyLengthDiff);
- // and set the new node as child of this node
- if (firstDigit(keyDiff, keyLengthDiff) == 1) {
- this.childZero = null;
- this.childOne = newNode;
- } else {
- this.childZero = newNode;
- this.childOne = null;
- }
-
- if(newNode.childOne == null && newNode.childZero == null){
- this.childCount++;
- newNode.childCount = 0;
- }
- }
+ if (firstDigit(keyDiff, keyLengthDiff) == 1) {
+ if (this.childOne != null) {
+ this.childOne.add(keyDiff,
keyLengthDiff, data);
+ } else {
+ this.childOne = new
TrieNode(keyDiff, keyLengthDiff);
+ this.childOne.setData(data);
+ }
+ } else {
+ if (this.childZero != null) {
+ this.childZero.add(keyDiff,
keyLengthDiff, data);
+ } else {
+ this.childZero = new
TrieNode(keyDiff, keyLengthDiff);
+ this.childZero.setData(data);
+ }
+ }
+ } else {
+ this.valueCount = 1;
+ // this.data = data; //XXX
+ }
+ }
+ return this;
+ }
- // process diff with the new key, if any
- if (keyLength > keyLengthCommon) {
- // get diff with the new key
- keyLengthDiff = keyLength - keyLengthCommon;
- keyDiff = key - (keyCommon << keyLengthDiff);
+ public boolean FindExactMatch(long key, long keyLength) {
- if (firstDigit(keyDiff, keyLengthDiff) == 1) {
- if (this.childOne != null) {
- this.childOne.Add(keyDiff, keyLengthDiff, data);
- } else {
- this.childOne = new TrieNode(keyDiff, keyLengthDiff);
- this.childOne.setData(data);
- }
- } else {
- if (this.childZero != null) {
- this.childZero.Add(keyDiff, keyLengthDiff, data);
- } else {
- this.childZero = new TrieNode(keyDiff,
keyLengthDiff);
- this.childZero.setData(data);
- }
- }
- }
- else {
- this.valueCount = 1;
- //this.data = data; //XXX
- }
- }
- return this;
- }
+ boolean matchStatus;
+ long keyCommon;
+ long keyLengthCommon;
- public boolean FindExactMatch(long key, long keyLength) {
+ if (keyLength < this.keyLength) {
+ matchStatus = false;
+ return matchStatus;
+ } else if (key == this.key && keyLength == this.keyLength) {
+ matchStatus = true;
+ return matchStatus;
+ } else {
+ long[] keyFields = getCommonPart(key, keyLength,
this.key,
+ this.keyLength);
+ keyCommon = keyFields[0];
+ keyLengthCommon = keyFields[1];
- boolean matchStatus;
- long keyCommon;
- long keyLengthCommon;
+ long keyLengthDiff = keyLength - keyLengthCommon;
+ long keyDiff = key - (keyCommon << keyLengthDiff);
- if (keyLength < this.keyLength) {
- matchStatus = false;
- return matchStatus;
- } else if (key == this.key && keyLength == this.keyLength) {
- matchStatus = true;
- return matchStatus;
- } else {
- long[] keyFields = getCommonPart(key, keyLength, this.key,
this.keyLength);
- keyCommon = keyFields[0];
- keyLengthCommon = keyFields[1];
+ if (firstDigit(keyDiff, keyLengthDiff) == 1) {
+ if (childOne != null)
+ return
childOne.FindExactMatch(keyDiff, keyLengthDiff);
+ else {
+ matchStatus = false;
+ return matchStatus;
+ }
+ } else {
+ if (childZero != null)
+ return
childZero.FindExactMatch(keyDiff, keyLengthDiff);
+ else {
+ matchStatus = false;
+ return matchStatus;
+ }
+ }
+ }
+ }
- long keyLengthDiff = keyLength - keyLengthCommon;
- long keyDiff = key - (keyCommon << keyLengthDiff);
+ public TrieNode FindBestMatch(long key, long keyLength) {
+ // note : we don't need to worry about a node being a
terminator since
+ // at the end, we will either have
+ // - an exact match of the key, so the node will be a
terminator
+ // - the last possible node on the path matching the key
which can't be
+ // anything but a leaf, hence a terminator
- if (firstDigit(keyDiff, keyLengthDiff) == 1) {
- if (childOne != null)
- return childOne.FindExactMatch(keyDiff, keyLengthDiff);
- else {
- matchStatus = false;
- return matchStatus;
- }
- } else {
- if (childZero != null)
- return childZero.FindExactMatch(keyDiff, keyLengthDiff);
- else {
- matchStatus = false;
- return matchStatus;
- }
- }
- }
- }
+ if (keyLength < this.keyLength
+ || (key == this.key && keyLength ==
this.keyLength)) {
+ return this;
+ } else {
+ long[] keyFields = getCommonPart(key, keyLength,
this.key,
+ this.keyLength);
+ long keyCommon = keyFields[0];
+ long keyLengthCommon = keyFields[1];
- public TrieNode FindBestMatch(long key, long keyLength) {
- // note : we don't need to worry about a node being a terminator
since at the end, we will either have
- // - an exact match of the key, so the node will be a terminator
- // - the last possible node on the path matching the key which can't
be anything but a leaf, hence a terminator
+ long keyLengthDiff = keyLength - keyLengthCommon;
+ long keyDiff = key - (keyCommon << keyLengthDiff);
- if (keyLength < this.keyLength || (key == this.key && keyLength ==
this.keyLength)) {
- return this;
- } else {
- long[] keyFields = getCommonPart(key, keyLength, this.key,
this.keyLength);
- long keyCommon = keyFields[0];
- long keyLengthCommon = keyFields[1];
+ if (firstDigit(keyDiff, keyLengthDiff) == 1) {
+ if (childOne != null) {
+ return
childOne.FindBestMatch(keyDiff, keyLengthDiff);
+ } else {
+ return this;
+ }
+ } else {
+ if (childZero != null) {
+ return
childZero.FindBestMatch(keyDiff, keyLengthDiff);
+ } else {
+ return this;
+ }
+ }
+ }
+ }
- long keyLengthDiff = keyLength - keyLengthCommon;
- long keyDiff = key - (keyCommon << keyLengthDiff);
+ public TrieNode Clone() {
+ TrieNode clone = new TrieNode(this.key, this.keyLength,
this.valueCount);
+ if (this.childZero != null)
+ clone.childZero = this.childZero.Clone();
- if (firstDigit(keyDiff, keyLengthDiff) == 1) {
- if (childOne != null) {
- return childOne.FindBestMatch(keyDiff, keyLengthDiff);
- } else {
- return this;
- }
- } else {
- if (childZero != null) {
- return childZero.FindBestMatch(keyDiff, keyLengthDiff);
- } else {
- return this;
- }
- }
- }
- }
+ if (this.childOne != null)
+ clone.childOne = this.childOne.Clone();
- public TrieNode Clone() {
- TrieNode clone = new TrieNode(this.key, this.keyLength,
this.valueCount);
- if (this.childZero != null)
- clone.childZero = this.childZero.Clone();
+ return clone;
+ }
- if (this.childOne != null)
- clone.childOne = this.childOne.Clone();
+ public void printDotNode(PrintStream p, TrieNode node, long position,
+ long currentKey) {
+ TrieNode c0 = node.getChildZero();
+ TrieNode c1 = node.getChildOne();
+ long key = node.getKey();
+ long mask = Constants.MAX_KEY_LENGTH - position;
+ String keyString;
+ String addrString;
- return clone;
- }
-
- public void printDotNode(PrintStream p, TrieNode node, long position,
long currentKey) {
- TrieNode c0 = node.getChildZero();
- TrieNode c1 = node.getChildOne();
- long key = node.getKey();
- long mask = Constants.MAX_KEY_LENGTH - position;
- String keyString;
- String addrString;
-
- if (key == -1) {
- addrString = keyString = "\"" + "0.0.0.0/0" + "\"";
- currentKey = 0;
- p.println(addrString + "
[shape=record,label=\"<f0>0.0.0.0/0|<f1>"
- + node.getChildCount()
- + "\"];" + " // COUNT: " +
node.getChildCount());
- }
- else {
- key = currentKey;
- keyString = helper.longToIP(key);
- String unquotedAddrString = keyString + "/" + mask;
- addrString = "\"" + keyString + "/" + mask + "\"";
- if (node.getData() == null) {
- //p.println(addrString + " [style=filled];" + " //
COUNT: " + node.getChildCount());
- p.println(addrString + "
[style=filled,shape=record,label=\"<f0>" + unquotedAddrString
- + "|<f1>" + node.getChildCount() +
"\"]"
- + "; // COUNT: " +
node.getChildCount());
- }
- else {
- //p.println(addrString + "; // COUNT: " +
node.getChildCount());
- p.println(addrString + " [shape=record,label=\"<f0>"
+ unquotedAddrString
- + "|<f1>" + node.getChildCount() +
"\"]"
- + "; // COUNT: " +
node.getChildCount());
- }
- }
-
- if (c0 != null) {
- long c0Key = c0.getKey() << (position - c0.getKeyLength());
- long c0Position = position - c0.getKeyLength();
- long c0Mask = Constants.MAX_KEY_LENGTH - c0Position;
- c0Key = c0Key | currentKey;
- p.println(addrString + " -> \""
- + helper.longToIP(c0Key) + "/" + c0Mask
- + "\"" + "[label=" + (c0Mask - mask)
- + "];" + "// kl: " + c0.getKeyLength() + "
pos: " + position);
- printDotNode(p, c0, c0Position, c0Key);
- }
- if (c1 != null) {
- long c1Key = c1.getKey() << (position - c1.getKeyLength());
- long c1Position = position - c1.getKeyLength();
- long c1Mask = Constants.MAX_KEY_LENGTH - c1Position;
- c1Key = c1Key | currentKey;
- p.println(addrString + " -> \""
- + helper.longToIP(c1Key) + "/" + c1Mask
- + "\"" + "[label=" + (c1Mask - mask)
- + "];" + "// kl: " + c1.getKeyLength() + "
pos: " + position);
- printDotNode(p, c1, c1Position, c1Key);
- }
- }
-
- public ArrayList<String> listInternalNodes(ArrayList<String>
listOfNodes, long position, long currentKey) {
- TrieNode c0 = this.getChildZero();
- TrieNode c1 = this.getChildOne();
- long key = this.getKey();
- long mask = Constants.MAX_KEY_LENGTH - position;
- String keyString;
- String addrString;
- TrieNode node = this;
-
- if (key == -1) {
- addrString = keyString = "0.0.0.0/0";
- currentKey = 0;
- }
- else {
- key = currentKey;
- keyString = helper.longToIP(key);
- addrString = keyString + "/" + mask;
- if (node.getData() == null) {
- listOfNodes.add(addrString);
- }
- }
- if (c0 != null) {
- long c0Key = c0.getKey() << (position - c0.getKeyLength());
- long c0Position = position - c0.getKeyLength();
-// long c0Mask = Constants.MAX_KEY_LENGTH - c0Position;
- c0Key = c0Key | currentKey;
- c0.listInternalNodes(listOfNodes, c0Position, c0Key);
- }
- if (c1 != null) {
- long c1Key = c1.getKey() << (position - c1.getKeyLength());
- long c1Position = position - c1.getKeyLength();
-// long c1Mask = Constants.MAX_KEY_LENGTH - c1Position;
- c1Key = c1Key | currentKey;
- c1.listInternalNodes(listOfNodes, c1Position, c1Key);
- }
+ if (key == -1) {
+ addrString = keyString = "\"" + "0.0.0.0/0" + "\"";
+ currentKey = 0;
+ p.println(addrString + "
[shape=record,label=\"<f0>0.0.0.0/0|<f1>"
+ + node.getChildCount() + "\"];" + "
// COUNT: "
+ + node.getChildCount());
+ } else {
+ key = currentKey;
+ keyString = helper.longToIP(key);
+ String unquotedAddrString = keyString + "/" + mask;
+ addrString = "\"" + keyString + "/" + mask + "\"";
+ if (node.getData() == null) {
+ // p.println(addrString + " [style=filled];"
+ " // COUNT: " +
+ // node.getChildCount());
+ p.println(addrString
+ + "
[style=filled,shape=record,label=\"<f0>"
+ + unquotedAddrString +
"|<f1>" + node.getChildCount()
+ + "\"]" + "; // COUNT: " +
node.getChildCount());
+ } else {
+ // p.println(addrString + "; // COUNT: " +
+ // node.getChildCount());
+ p.println(addrString + "
[shape=record,label=\"<f0>"
+ + unquotedAddrString +
"|<f1>" + node.getChildCount()
+ + "\"]" + "; // COUNT: " +
node.getChildCount());
+ }
+ }
- return listOfNodes;
- }
-
- /**
- *
- * This method returns all the nodes which are necessary to summarize
all inputs.
- *
- * @param listOfNodes
- * @param position
- * @param currentKey
- * @return
- */
- public ArrayList<String> listSummaryNodes(ArrayList<String> listOfNodes,
long position, long currentKey) {
- TrieNode c0 = this.getChildZero();
- TrieNode c1 = this.getChildOne();
- long key = this.getKey();
- long mask = Constants.MAX_KEY_LENGTH - position;
- String keyString;
- String addrString;
- TrieNode node = this;
-
- if (key == -1) {
- addrString = keyString = "0.0.0.0/0";
- currentKey = 0;
- }
- else {
- key = currentKey;
- keyString = helper.longToIP(key);
- addrString = keyString + "/" + mask;
- if (node.getData() == null &&
- ( c0.getData() != null ||
- c1.getData() != null )) {
- listOfNodes.add(addrString);
- }
- }
- if (c0 != null) {
- long c0Key = c0.getKey() << (position - c0.getKeyLength());
- long c0Position = position - c0.getKeyLength();
- //long c0Mask = Constants.MAX_KEY_LENGTH - c0Position;
- c0Key = c0Key | currentKey;
- c0.listSummaryNodes(listOfNodes, c0Position, c0Key);
- }
- if (c1 != null) {
- long c1Key = c1.getKey() << (position - c1.getKeyLength());
- long c1Position = position - c1.getKeyLength();
- //long c1Mask = Constants.MAX_KEY_LENGTH - c1Position;
- c1Key = c1Key | currentKey;
- c1.listSummaryNodes(listOfNodes, c1Position, c1Key);
- }
+ if (c0 != null) {
+ long c0Key = c0.getKey() << (position -
c0.getKeyLength());
+ long c0Position = position - c0.getKeyLength();
+ long c0Mask = Constants.MAX_KEY_LENGTH - c0Position;
+ c0Key = c0Key | currentKey;
+ p.println(addrString + " -> \"" +
helper.longToIP(c0Key) + "/"
+ + c0Mask + "\"" + "[label=" + (c0Mask
- mask) + "];"
+ + "// kl: " + c0.getKeyLength() + "
pos: " + position);
+ printDotNode(p, c0, c0Position, c0Key);
+ }
+ if (c1 != null) {
+ long c1Key = c1.getKey() << (position -
c1.getKeyLength());
+ long c1Position = position - c1.getKeyLength();
+ long c1Mask = Constants.MAX_KEY_LENGTH - c1Position;
+ c1Key = c1Key | currentKey;
+ p.println(addrString + " -> \"" +
helper.longToIP(c1Key) + "/"
+ + c1Mask + "\"" + "[label=" + (c1Mask
- mask) + "];"
+ + "// kl: " + c1.getKeyLength() + "
pos: " + position);
+ printDotNode(p, c1, c1Position, c1Key);
+ }
+ }
- return listOfNodes;
- }
+ public ArrayList<String> listInternalNodes(ArrayList<String>
listOfNodes,
+ long position, long currentKey) {
+ TrieNode c0 = this.getChildZero();
+ TrieNode c1 = this.getChildOne();
+ long key = this.getKey();
+ long mask = Constants.MAX_KEY_LENGTH - position;
+ String keyString;
+ String addrString;
+ TrieNode node = this;
+
+ if (key == -1) {
+ addrString = keyString = "0.0.0.0/0";
+ currentKey = 0;
+ } else {
+ key = currentKey;
+ keyString = helper.longToIP(key);
+ addrString = keyString + "/" + mask;
+ if (node.getData() == null) {
+ listOfNodes.add(addrString);
+ }
+ }
+ if (c0 != null) {
+ long c0Key = c0.getKey() << (position -
c0.getKeyLength());
+ long c0Position = position - c0.getKeyLength();
+ // long c0Mask = Constants.MAX_KEY_LENGTH -
c0Position;
+ c0Key = c0Key | currentKey;
+ c0.listInternalNodes(listOfNodes, c0Position, c0Key);
+ }
+ if (c1 != null) {
+ long c1Key = c1.getKey() << (position -
c1.getKeyLength());
+ long c1Position = position - c1.getKeyLength();
+ // long c1Mask = Constants.MAX_KEY_LENGTH -
c1Position;
+ c1Key = c1Key | currentKey;
+ c1.listInternalNodes(listOfNodes, c1Position, c1Key);
+ }
+
+ return listOfNodes;
+ }
+
+ /**
+ *
+ * This method returns all the nodes which are necessary to summarize
all
+ * inputs.
+ *
+ * @param listOfNodes
+ * @param position
+ * @param currentKey
+ * @return
+ */
+ public ArrayList<String> listSummaryNodes(ArrayList<String>
listOfNodes,
+ long position, long currentKey) {
+ TrieNode c0 = this.getChildZero();
+ TrieNode c1 = this.getChildOne();
+ long key = this.getKey();
+ long mask = Constants.MAX_KEY_LENGTH - position;
+ String keyString;
+ String addrString;
+ TrieNode node = this;
+
+ if (key == -1) {
+ addrString = keyString = "0.0.0.0/0";
+ currentKey = 0;
+ } else {
+ key = currentKey;
+ keyString = helper.longToIP(key);
+ addrString = keyString + "/" + mask;
+ if (node.getData() == null
+ && (c0.getData() != null ||
c1.getData() != null)) {
+ listOfNodes.add(addrString);
+ }
+ }
+ if (c0 != null) {
+ long c0Key = c0.getKey() << (position -
c0.getKeyLength());
+ long c0Position = position - c0.getKeyLength();
+ // long c0Mask = Constants.MAX_KEY_LENGTH -
c0Position;
+ c0Key = c0Key | currentKey;
+ c0.listSummaryNodes(listOfNodes, c0Position, c0Key);
+ }
+ if (c1 != null) {
+ long c1Key = c1.getKey() << (position -
c1.getKeyLength());
+ long c1Position = position - c1.getKeyLength();
+ // long c1Mask = Constants.MAX_KEY_LENGTH -
c1Position;
+ c1Key = c1Key | currentKey;
+ c1.listSummaryNodes(listOfNodes, c1Position, c1Key);
+ }
+
+ return listOfNodes;
+ }
}
\ No newline at end of file
Deleted:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ServiceSummary.java
Added:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ServiceSummaryBean.java
Property changes on:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/ServiceSummaryBean.java
___________________________________________________________________
Name: svn:executable
+ *
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/summarization/SummarizationBuilder.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -42,7 +42,7 @@
// get all topology information (IPs)
logger.debug("Get services info from DB");
- Map<String, ServiceSummary> summaries = null;
+ Map<String, ServiceSummaryBean> summaries = null;
try {
summaries = getAllServicesSummaries();
@@ -53,7 +53,7 @@
// boolean doIPSummarization =
//
config.getProperty("service.ls.do_ip_summarization");
// work on the same data - summarize and store in
"summaries" structure
- for (ServiceSummary s : summaries.values()) {
+ for (ServiceSummaryBean s : summaries.values()) {
// summarize IPs
s.setIpAddresses(summarizeIPAddresses(s.getIpAddresses()));
@@ -73,7 +73,7 @@
Message msg = gen.createMessageElement();
// for every single summary get XML
- for (Entry<String, ServiceSummary> s :
summaries.entrySet()) {
+ for (Entry<String, ServiceSummaryBean> s :
summaries.entrySet()) {
Element subject =
gen.createSubjectElement(msg, s.getKey());
@@ -130,10 +130,10 @@
* @return - map - key - metadataId, value is a set of
Ip/keyword/domain
* sets
*/
- private Map<String, ServiceSummary> getAllServicesSummaries()
+ private Map<String, ServiceSummaryBean> getAllServicesSummaries()
throws PerfSONARException {
- Map<String, ServiceSummary> summaries = new HashMap<String,
ServiceSummary>();
+ Map<String, ServiceSummaryBean> summaries = new
HashMap<String, ServiceSummaryBean>();
String[] ipResults = dao.queryIpResults();
String[] domainResults = dao.queryDomainResults();
String[] eventTypeResults = dao.queryEventTypeResults();
@@ -200,7 +200,7 @@
* @param type
* type of field to be populated
*/
- private void populateSummary(Map<String, ServiceSummary> summaries,
+ private void populateSummary(Map<String, ServiceSummaryBean>
summaries,
String[] lines, SummarizationVariableType type) {
// split and store results
@@ -219,9 +219,9 @@
String content = params[1];
// get or create summary for the service
- ServiceSummary summary = summaries.get(metadataId);
+ ServiceSummaryBean summary =
summaries.get(metadataId);
if (summary == null) {
- summary = new ServiceSummary();
+ summary = new ServiceSummaryBean();
summaries.put(metadataId, summary);
}
@@ -248,11 +248,11 @@
}
@SuppressWarnings("unused")
- private void showSummary(Map<String, ServiceSummary> summaries) {
- Iterator<Entry<String, ServiceSummary>> i =
summaries.entrySet()
+ private void showSummary(Map<String, ServiceSummaryBean> summaries) {
+ Iterator<Entry<String, ServiceSummaryBean>> i =
summaries.entrySet()
.iterator();
while (i.hasNext()) {
- Map.Entry<String, ServiceSummary> e = i.next();
+ Map.Entry<String, ServiceSummaryBean> e = i.next();
logger.debug("\n==== " + e.getKey() + " ====\n");
logger.debug(e.getValue().toString());
Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/summarization/SummarizationTests.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/summarization/SummarizationTests.java
2009-12-10 08:57:55 UTC (rev 5398)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/summarization/SummarizationTests.java
2009-12-10 10:16:59 UTC (rev 5399)
@@ -5,27 +5,10 @@
import junit.framework.TestCase;
-import
org.perfsonar.service.lookupservice.registration.summarization.IPAddress;
-import
org.perfsonar.service.lookupservice.registration.summarization.InvalidIPAddressException;
-import
org.perfsonar.service.lookupservice.registration.summarization.SummarizationHelper;
import
org.perfsonar.service.lookupservice.registration.summarization.SummarizeIpAddrs;
public class SummarizationTests extends TestCase {
- public void testIpConversions() throws InvalidIPAddressException{
- SummarizationHelper sh=new SummarizationHelper();
- String ip="192.168.1.1";
- IPAddress ipAddress=new IPAddress(ip);
- long ipInLong=ipAddress.getAddrAsLong();
- assertEquals(ip, sh.longToIP(ipInLong));
-
- ip="192.168.1.666";
- try{
- ipAddress=new IPAddress(ip);
- fail();
- }catch(InvalidIPAddressException ex){
- }
- }
public void testSummarization(){
Set<String> ips=new HashSet<String>();
- perfsonar: r5399 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice/registration/summarization main/java/org/perfsonar/service/lookupservice/summarization test/java/org/perfsonar/tests/summarization, svnlog, 12/10/2009
Archive powered by MHonArc 2.6.16.