perfsonar-dev - perfsonar: r4347 - in branches/perfsonarui/src/org/perfsonar/perfsonarui: ls test/ls
Subject: perfsonar development work
List archive
perfsonar: r4347 - in branches/perfsonarui/src/org/perfsonar/perfsonarui: ls test/ls
Chronological Thread
- From:
- To:
- Subject: perfsonar: r4347 - in branches/perfsonarui/src/org/perfsonar/perfsonarui: ls test/ls
- Date: Thu, 7 Aug 2008 02:54:56 -0400
Author: nina
Date: 2008-08-07 02:54:55 -0400 (Thu, 07 Aug 2008)
New Revision: 4347
Added:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/IpSubnetTest.java
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/ls/IpSubnetTester.java
branches/perfsonarui/src/org/perfsonar/perfsonarui/ls/LSDiscoveryQuery.java
Log:
Added check for more specific subnet masks.
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/ls/IpSubnetTester.java
===================================================================
--- branches/perfsonarui/src/org/perfsonar/perfsonarui/ls/IpSubnetTester.java
2008-08-07 06:06:08 UTC (rev 4346)
+++ branches/perfsonarui/src/org/perfsonar/perfsonarui/ls/IpSubnetTester.java
2008-08-07 06:54:55 UTC (rev 4347)
@@ -42,7 +42,7 @@
* @param dbMask
* @return
*/
- public static boolean testSubnet(String lookForIP, String dbIP, String
dbMask) throws Exception {
+ public static boolean testSubnet(String lookForIP, String dbIP, int
dbMask) throws Exception {
/*
System.out.print(lookForIP);
System.out.print(' ');
@@ -52,7 +52,7 @@
System.out.print(' ');
*/
long numIp = getNumericalIP(lookForIP);
- long numMask = getNumericalMask(Integer.parseInt(dbMask));
+ long numMask = getNumericalMask(dbMask);
long numIpSubNet = numIp & numMask;
boolean result = (numIpSubNet == getNumericalIP(dbIP));
@@ -60,60 +60,33 @@
return result;
}
-
-
-
/**
- * Sample algorithm
+ *
+ * @param newMask e.g. 32
+ * @param oldMask e.g 23
+ * @return true if newMask is more specific than oldMask
*/
- public static void main(String[] args) {
-
- //IP address to be found from UI
- String lookForIP = "10.129.27.100";
-
- //query LS for list of ips/netmasks
-
- /*
- for $n in //*:network/*:subnet
- let $ip := $n/*:address/text()
- let $mask := $n/*:netmask/text()
- return concat($ip,"/",$mask)
- */
-
- //results, for instance -- for testing you may use those:
- String[] dbResults = {
- "10.0.0.0/8",
- "10.128.0.0/9",
- "10.129.27.100/32",
- "133.0.0.0/12",
- };
-
-
- //for all IPs
- for (int i=0; i<dbResults.length; i++) {
-
- try {
- //split by "/"
- String[] s = dbResults[i].split("\\/");
- //assign IP
- String dbIP = s[0];
- //assign and convert mask
- String dbMask = s[1];
- boolean result = IpSubnetTester.testSubnet(lookForIP, dbIP,
dbMask);
-
- if (result==true) { /* add to list */ }
-
- System.out.println(
- "Does "+lookForIP+" belong to "+
- dbIP+" / "+dbMask+" == "+result);
- } catch (Exception ex) {
- //do nothing, omit this ip
- //for testing print stack trace (to be removed)
- ex.printStackTrace();
- }
-
+ public static boolean isMoreSpecific(int newMask, int oldMask) {
+ return newMask > oldMask;
+ }
+ /**
+ *
+ * @param newMask
+ * @param oldMask
+ * @return same as
{@link
#isMoreSpecific(int, int)}, but returns true, if oldMask is null or not an
integer
+ */
+ public static boolean isMoreSpecific(int newMask, String oldMask) {
+ if (oldMask == null) return true;
+ int mask = -1;
+ try {
+ mask = Integer.parseInt(oldMask);
+ } catch (Exception x) {
+ return true;
}
+ return isMoreSpecific(newMask, mask);
+ }
- }
-
+
+
+
} //IpSubnetTester
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/ls/LSDiscoveryQuery.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/ls/LSDiscoveryQuery.java
2008-08-07 06:06:08 UTC (rev 4346)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/ls/LSDiscoveryQuery.java
2008-08-07 06:54:55 UTC (rev 4347)
@@ -204,28 +204,24 @@
if (network.item(k).getNodeType() ==
Node.ELEMENT_NODE) {
IUserData data =
getTopoElement((Element)network.item(k));
if (data != null) {
- boolean found = false;
- for (int j=0; j <
topoelements.size();j++)
+ for (int j=0; j <
topoelements.size();j++) {
+ int subnetmask =
Integer.parseInt(data.getResponse(IUserData.C_SUBNETMASK));
if
(IpSubnetTester.testSubnet(
topoelements.get(j).getQuery(IUserData.C_IFADDRESS),
data.getResponse(IUserData.C_SUBNETIFADDRESS),
-
data.getResponse(IUserData.C_SUBNETMASK))) {
- /*
- if
(data.getResponse(IUserData.C_IFADDRESS).equals(
-
topoelements.get(j).getQuery(IUserData.C_IFADDRESS))) {
-
*/
-
data.setQuery(IUserData.C_IFADDRESS,topoelements.get(j).getQuery(IUserData.C_IFADDRESS));
-
data.setResponse(IUserData.C_IFADDRESS,topoelements.get(j).getResponse(IUserData.C_IFADDRESS));
-
topoelements.get(j).assign(data);
-
topoelements.get(j).setEndpoint(endpoint);
- found
= true;
- }
- /*
- if (!found) {
-
data.setEndpoint(endpoint);
-
topoelements.add(data);
- }
- */
+
subnetmask))
+
logger.debug(topoelements.get(j).getQuery(IUserData.C_IFADDRESS) + " matches
" + data.getResponse(IUserData.C_SUBNETIFADDRESS) +
"/"+data.getResponse(IUserData.C_SUBNETMASK));
+ if
(IpSubnetTester.isMoreSpecific(subnetmask,
topoelements.get(j).getResponse(IUserData.C_SUBNETMASK))) {
+
data.setQuery(IUserData.C_IFADDRESS,topoelements.get(j).getQuery(IUserData.C_IFADDRESS));
+
data.setResponse(IUserData.C_IFADDRESS,topoelements.get(j).getResponse(IUserData.C_IFADDRESS));
+
topoelements.get(j).assign(data);
+
topoelements.get(j).setEndpoint(endpoint);
+ } else {
+ logger.debug("Skipped - more
specific subnet exists "+data.getResponse(IUserData.C_SUBNETMASK));
+ }
+
+ }
+
}
}
}
Added:
branches/perfsonarui/src/org/perfsonar/perfsonarui/test/ls/IpSubnetTest.java
- perfsonar: r4347 - in branches/perfsonarui/src/org/perfsonar/perfsonarui: ls test/ls, svnlog, 08/07/2008
Archive powered by MHonArc 2.6.16.