summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMohammad Jamal MohiUddin2013-11-06 02:34:20 (EST)
committer Markus Alexander Kuppe2013-11-25 03:57:51 (EST)
commitc2ef22b6f41caf6b9503b73cbd7ea56f0fa89e4e (patch)
tree0fc0f09f3405c905f864c09c6f2277f5e4fe4a5a
parentf08d394caa00c3b15b62e2dadd6024be7a3ae589 (diff)
downloadorg.eclipse.ecf-c2ef22b6f41caf6b9503b73cbd7ea56f0fa89e4e.zip
org.eclipse.ecf-c2ef22b6f41caf6b9503b73cbd7ea56f0fa89e4e.tar.gz
org.eclipse.ecf-c2ef22b6f41caf6b9503b73cbd7ea56f0fa89e4e.tar.bz2
bug 421063: Implementation of IPv6 to jslp 421063
https://bugs.eclipse.org/bugs/show_bug.cgi?id=421063 Change-Id: Ia02153f4e47bb12cd0b10f232c1dad9525d836f4 Signed-off-by: Mohammad Jamal MohiUddin <mjmohiuddin@cdac.in>
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/Activator.java3
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AdvertiserImpl.java3
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java89
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java10
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java52
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/standalone/inclusions/ch/ethz/iks/slp/ServiceLocationManager.java4
6 files changed, 146 insertions, 15 deletions
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/Activator.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/Activator.java
index d85b755..e35af12 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/Activator.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/Activator.java
@@ -9,6 +9,8 @@
* Contributors:
* Jan S. Rellermeyer - initial API and implementation
* Markus Alexander Kuppe - enhancements and bug fixes
+ * Md.Jamal MohiUddin (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
+ * P Sowjanya (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
*
*****************************************************************************/
@@ -40,7 +42,6 @@ public class Activator implements BundleActivator {
context.registerService("ch.ethz.iks.slp.Advertiser", new ServiceFactory() {
public Object getService(Bundle bundle, ServiceRegistration registration) {
SLPCore.init();
- SLPCore.initMulticastSocket();
return new AdvertiserImpl();
}
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AdvertiserImpl.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AdvertiserImpl.java
index 8d5d5d3..7cf242e 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AdvertiserImpl.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AdvertiserImpl.java
@@ -9,6 +9,8 @@
* Contributors:
* Jan S. Rellermeyer - initial API and implementation
* Markus Alexander Kuppe - enhancements and bug fixes
+ * Md.Jamal MohiUddin (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
+ * P Sowjanya (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
*
*****************************************************************************/
package ch.ethz.iks.slp.impl;
@@ -112,6 +114,7 @@ public final class AdvertiserImpl implements Advertiser {
.getServiceType(), scopes, SLPUtils.dictToAttrList(attributes),
locale);
try {
+ SLPCore.initMulticastSocket(url);
reg.address = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
reg.address = SLPCore.getMyIP();
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java
index a33c136..7c25bdb 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java
@@ -9,6 +9,8 @@
* Contributors:
* Jan S. Rellermeyer - initial API and implementation
* Markus Alexander Kuppe - enhancements and bug fixes
+ * Md.Jamal MohiUddin (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
+ * P Sowjanya (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
*
*****************************************************************************/
@@ -41,6 +43,7 @@ import java.util.Map;
import ch.ethz.iks.slp.ServiceLocationException;
import ch.ethz.iks.slp.ServiceType;
+import ch.ethz.iks.slp.ServiceURL;
/**
* the core class of the jSLP implementation.
@@ -77,10 +80,40 @@ public abstract class SLPCore {
*/
static final String SLP_MCAST_ADDRESS = "239.255.255.253";
+
+ /**
+ * SVRLOC multicast group id is for receiving
+ * Attribute Request and Service Type Request
+ * Messages
+ */
+ static final String SLP_SVRLOC = "FF02::123";
+
/**
*
*/
- static final InetAddress MCAST_ADDRESS;
+ static final InetAddress SVRLOC = null;
+
+ /**
+ * SVRLOC-DA group is used for receiving DA Advertisements
+ */
+ static final String SLP_SVRLOC_DA = "FF02::116";
+
+ /**
+ *
+ */
+ static final InetAddress DA_ADDRESS;
+
+ static final InetAddress SVRLOC_ADDRESS;
+
+ /**
+ * Service Request Multicast Group Id
+ */
+ static final String SLP_ServiceRqst = "";
+
+ /**
+ *
+ */
+ static InetAddress serviceRqst = null;
/**
* the SLP configuration.
@@ -257,14 +290,17 @@ public abstract class SLPCore {
// initialize the XID with a random number
nextXid = (short) Math.round(Math.random() * Short.MAX_VALUE);
- InetAddress mcast = null;
+ InetAddress SVRLOC=null;
+ InetAddress SVRLOC_DA=null;
try {
- mcast = InetAddress.getByName(SLPCore.SLP_MCAST_ADDRESS);
+ SVRLOC = InetAddress.getByName(SLPCore.SLP_SVRLOC);
+ SVRLOC_DA = InetAddress.getByName(SLPCore.SLP_SVRLOC_DA);
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
- MCAST_ADDRESS = mcast;
+ DA_ADDRESS=SVRLOC_DA;
+ SVRLOC_ADDRESS=SVRLOC;
}
protected static void init() {
@@ -327,8 +363,14 @@ public abstract class SLPCore {
}
// a pure UA doesn't need a multicast listener which is only required by a SA or DA
- protected static void initMulticastSocket() {
+ protected static void initMulticastSocket(ServiceURL aUrl) {
if(isMulticastSocketInitialized) {
+ try {
+ serviceRqst = InetAddress.getByName(SLPUtils.hash(aUrl));
+ mtcSocket.joinGroup(serviceRqst);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
return;
}
isMulticastSocketInitialized = true;
@@ -343,7 +385,10 @@ public abstract class SLPCore {
platform.logDebug("Setting multicast socket interface to " + myIPs[0] + " failed.",t);
}
}
- mtcSocket.joinGroup(MCAST_ADDRESS);
+ mtcSocket.joinGroup(SVRLOC_ADDRESS);
+ mtcSocket.joinGroup(DA_ADDRESS);
+ serviceRqst = InetAddress.getByName(SLPUtils.hash(aUrl));
+ mtcSocket.joinGroup(serviceRqst);
} catch (BindException be) {
platform.logError(be.getMessage(), be);
throw new RuntimeException("You have to be root to open port "
@@ -614,11 +659,11 @@ public abstract class SLPCore {
SLP_DA_TYPE), scopes, null, SLPCore.DEFAULT_LOCALE);
sreq.xid = SLPCore.nextXid();
sreq.scopeList = scopes;
- sreq.address = MCAST_ADDRESS;
+ sreq.address = DA_ADDRESS;
sreq.multicast = true;
byte[] bytes = sreq.getBytes();
DatagramPacket d = new DatagramPacket(bytes, bytes.length,
- MCAST_ADDRESS, SLP_PORT);
+ DA_ADDRESS, SLP_PORT);
platform.logTraceMessage("SENT " + sreq + "(udp multicast)");
setupReceiverThread(socket, CONFIG.getWaitTime(), sreq);
try {
@@ -762,7 +807,7 @@ public abstract class SLPCore {
try {
long start = System.currentTimeMillis();
-
+ InetAddress destination;
List replyQueue = new ArrayList();
List responders = new ArrayList();
List responses = new ArrayList();
@@ -791,8 +836,27 @@ public abstract class SLPCore {
throw e;
}
}
-
- msg.address = MCAST_ADDRESS;
+ byte type = SLPMessage.getMessageType(msg);
+ switch (type) {
+ case SLPMessage.SRVRQST:
+ ServiceRequest srq = (ServiceRequest) msg;
+ msg.address = InetAddress.getByName(SLPUtils
+ .hash(srq.serviceType));
+ destination = msg.address;
+ break;
+
+ case SLPMessage.ATTRRQST:
+ case SLPMessage.SRVTYPERQST:
+ msg.address = SVRLOC_ADDRESS;
+ destination = msg.address;
+ break;
+
+ default:
+ System.out
+ .println("\n Unknown request Message has been received"
+ + SLPMessage.getType(type));
+ return null;
+ }
ReplyMessage reply;
for (int i = 0; i < myIPs.length; i++) {
@@ -833,8 +897,7 @@ public abstract class SLPCore {
// send the message
DatagramPacket p = new DatagramPacket(message,
- message.length, InetAddress
- .getByName(SLP_MCAST_ADDRESS), SLP_PORT);
+ message.length, destination, SLP_PORT);
try {
socket.send(p);
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java
index b68f8fa..22b38b1 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java
@@ -9,6 +9,8 @@
* Contributors:
* Jan S. Rellermeyer - initial API and implementation
* Markus Alexander Kuppe - enhancements and bug fixes
+ * Md.Jamal MohiUddin (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
+ * P Sowjanya (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
*
*****************************************************************************/
package ch.ethz.iks.slp.impl;
@@ -493,4 +495,12 @@ public abstract class SLPMessage {
rule.visit(visitor);
return visitor.getAttributes();
}
+
+ /**
+ * Returns the Type of The Request Message
+ *
+ */
+ static byte getMessageType(RequestMessage msg) {
+ return msg.funcID;
+ }
}
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java
index cc9a939..8d5d931 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPUtils.java
@@ -9,6 +9,8 @@
* Contributors:
* Jan S. Rellermeyer - initial API and implementation
* Markus Alexander Kuppe - enhancements and bug fixes
+ * Md.Jamal MohiUddin (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
+ * P Sowjanya (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
*
*****************************************************************************/
package ch.ethz.iks.slp.impl;
@@ -23,6 +25,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import ch.ethz.iks.slp.ServiceType;
+import ch.ethz.iks.slp.ServiceURL;
+
/**
* Utility class.
*
@@ -244,4 +249,51 @@ final class SLPUtils {
: equalsWithWildcard(val, ++valIndex, attr, ++attrIndex);
}
}
+
+ static String hash(ServiceURL aURL) {
+ String service = extractService(aURL.toString());
+ return hash(service);
+ }
+
+ static String hash(ServiceType aType) {
+ String service = extractService(aType.toString());
+ return hash(service);
+ }
+
+ /* Hash Algorithm for SLP Service Type String(RFC 3111) */
+ private static String hash(String pc) {
+ String ip = "FF02::1:1";
+
+ /*
+ * An unsigned 32-bit value v is initialized to 0.Each byte of the
+ * character is considered consecutively
+ */
+ int h = 0;
+
+ for (int i = 0; i < pc.length(); i++) {
+ /*
+ * The current value v is multiplied by 33.then the value of the
+ * current string byte is added ,Each byte in the service type
+ * string is processed in this manner
+ */
+ h *= 33;
+ h += pc.charAt(i);
+ }
+ /* The result is contained in the low order 10 bits of v */
+ int j = (0x3ff & h);
+ // Concatenating the value with the IP
+ return ip + Integer.toHexString(j);
+ }
+
+ private static String extractService(String url) {
+ int position = url.indexOf(':', 0);
+ if (position == -1) {
+ return url;
+ }
+ position = url.indexOf(':', position + 1);
+ if (position == -1) {
+ return url;
+ }
+ return url.substring(0, position);
+ }
}
diff --git a/protocols/bundles/ch.ethz.iks.slp/standalone/inclusions/ch/ethz/iks/slp/ServiceLocationManager.java b/protocols/bundles/ch.ethz.iks.slp/standalone/inclusions/ch/ethz/iks/slp/ServiceLocationManager.java
index 6482852..515cf27 100644
--- a/protocols/bundles/ch.ethz.iks.slp/standalone/inclusions/ch/ethz/iks/slp/ServiceLocationManager.java
+++ b/protocols/bundles/ch.ethz.iks.slp/standalone/inclusions/ch/ethz/iks/slp/ServiceLocationManager.java
@@ -9,6 +9,8 @@
* Contributors:
* Jan S. Rellermeyer - initial API and implementation
* Markus Alexander Kuppe - enhancements and bug fixes
+ * Md.Jamal MohiUddin (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
+ * P Sowjanya (Ubiquitous Computing, C-DAC Hyderabad) - IPv6 support
*
*****************************************************************************/
package ch.ethz.iks.slp;
@@ -65,6 +67,7 @@ public final class ServiceLocationManager extends SLPCore {
init();
if (locator != null) {
try {
+ //TODO::We have to Initialize the Multicast Socket for UA also for receiving DA Advt Messages
return (Locator) locator.newInstance(new Object[] { locale });
} catch (Exception e) {
throw new ServiceLocationException(
@@ -90,7 +93,6 @@ public final class ServiceLocationManager extends SLPCore {
public static Advertiser getAdvertiser(final Locale locale)
throws ServiceLocationException {
init();
- SLPCore.initMulticastSocket();
if (advertiser != null) {
try {
return (Advertiser) advertiser