View | Details | Raw Unified | Return to bug 421063 | Differences between
and this patch

Collapse All | Expand All

(-)/home/jumbo/Downloads/ecf-master/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/AdvertiserImpl.java (+16 lines)
Lines 11-16 Link Here
11
 *    Markus Alexander Kuppe - enhancements and bug fixes
11
 *    Markus Alexander Kuppe - enhancements and bug fixes
12
 *
12
 *
13
*****************************************************************************/
13
*****************************************************************************/
14
15
/****************************************************************************
16
 * Copyright (c) 2013 Md.Jamal MohiUddin,
17
 * Ubiquitous Computing, C-DAC Hyderabad.
18
 * All rights reserved. This program and the accompanying materials
19
 * are made available under the terms of the Eclipse Public License v1.0
20
 * which accompanies this distribution, and is available at
21
 * http://www.eclipse.org/legal/epl-v10.html
22
 *
23
 * Contributors:
24
 *    Md.Jamal MohiUddin - Updation to IPv6
25
 *    P Sowjanya  	 - Updation to IPv6
26
 *
27
*****************************************************************************/
28
14
package ch.ethz.iks.slp.impl;
29
package ch.ethz.iks.slp.impl;
15
30
16
import java.net.InetAddress;
31
import java.net.InetAddress;
Lines 112-117 Link Here
112
				.getServiceType(), scopes, SLPUtils.dictToAttrList(attributes),
127
				.getServiceType(), scopes, SLPUtils.dictToAttrList(attributes),
113
				locale);
128
				locale);
114
		try {
129
		try {
130
			SLPCore.initMulticastSocket(url.toString());
115
			reg.address = InetAddress.getLocalHost();
131
			reg.address = InetAddress.getLocalHost();
116
		} catch (UnknownHostException e) {
132
		} catch (UnknownHostException e) {
117
			reg.address = SLPCore.getMyIP();
133
			reg.address = SLPCore.getMyIP();
(-)/home/jumbo/Downloads/ecf-master/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPCore.java (-13 / +154 lines)
Lines 12-17 Link Here
12
 *
12
 *
13
*****************************************************************************/
13
*****************************************************************************/
14
14
15
/****************************************************************************
16
 * Copyright (c) 2013 Md.Jamal MohiUddin,
17
 * Ubiquitous Computing, C-DAC Hyderabad.
18
 * All rights reserved. This program and the accompanying materials
19
 * are made available under the terms of the Eclipse Public License v1.0
20
 * which accompanies this distribution, and is available at
21
 * http://www.eclipse.org/legal/epl-v10.html
22
 *
23
 * Contributors:
24
 *    Md.Jamal MohiUddin - Updation to IPv6
25
 *    P Sowjanya  	 - Updation to IPv6
26
 *
27
*****************************************************************************/
28
15
package ch.ethz.iks.slp.impl;
29
package ch.ethz.iks.slp.impl;
16
30
17
import java.io.ByteArrayInputStream;
31
import java.io.ByteArrayInputStream;
Lines 77-86 Link Here
77
	 */
91
	 */
78
	static final String SLP_MCAST_ADDRESS = "239.255.255.253";
92
	static final String SLP_MCAST_ADDRESS = "239.255.255.253";
79
93
94
	
95
	/**
96
	 * SVRLOC multicast group id is for receiving
97
	 * Attribute Request and Service Type Request
98
	 * Messages	
99
	 */
100
101
	static final String SLP_SVRLOC = "FF02::123";
102
103
	/**
104
	 * 
105
	 */
106
107
	static final InetAddress SVRLOC=null;
108
109
110
	/**
111
	 * SVRLOC-DA group  is used for receiving
112
	 * DA Advertisements
113
         */
114
115
116
	static final String SLP_SVRLOC_DA="FF02::116";
117
80
	/**
118
	/**
81
	 * 
119
	 * 
82
	 */
120
	 */
83
	static final InetAddress MCAST_ADDRESS;
121
122
	
123
124
	static final InetAddress DA_ADDRESS;
125
126
	static final InetAddress SVRLOC_ADDRESS;
127
128
129
	/**
130
	 *Service Request Multicast Group Id
131
	 */
132
133
	static final String SLP_ServiceRqst="";
134
135
	/**
136
	 * 
137
	 */
138
139
	static InetAddress ServiceRqst=null;
140
84
141
85
	/**
142
	/**
86
	 * the SLP configuration.
143
	 * the SLP configuration.
Lines 257-270 Link Here
257
		// initialize the XID with a random number
314
		// initialize the XID with a random number
258
		nextXid = (short) Math.round(Math.random() * Short.MAX_VALUE);
315
		nextXid = (short) Math.round(Math.random() * Short.MAX_VALUE);
259
316
260
		InetAddress mcast = null;
317
		InetAddress SVRLOC=null;
318
		InetAddress SVRLOC_DA=null;
261
		try {
319
		try {
262
			mcast = InetAddress.getByName(SLPCore.SLP_MCAST_ADDRESS);
320
			SVRLOC    = InetAddress.getByName(SLPCore.SLP_SVRLOC); 
321
 			SVRLOC_DA = InetAddress.getByName(SLPCore.SLP_SVRLOC_DA);
263
		} catch (UnknownHostException e1) {
322
		} catch (UnknownHostException e1) {
264
			e1.printStackTrace();
323
			e1.printStackTrace();
265
		}
324
		}
266
325
267
		MCAST_ADDRESS = mcast;
326
		DA_ADDRESS=SVRLOC_DA;
327
		SVRLOC_ADDRESS=SVRLOC;
268
	}
328
	}
269
329
270
	protected static void init() {
330
	protected static void init() {
Lines 327-335 Link Here
327
	}
387
	}
328
388
329
	// a pure UA doesn't need a multicast listener which is only required by a SA or DA
389
	// a pure UA doesn't need a multicast listener which is only required by a SA or DA
330
	protected static void initMulticastSocket() {
390
	protected static void initMulticastSocket(String URL) {
331
		if(isMulticastSocketInitialized) {
391
		if(isMulticastSocketInitialized) {
332
			return;
392
			try{
393
			
394
			ServiceRqst= slp_hash(URL.toString(),URL.toString().length());
395
			System.out.println("joining the group service request "+ServiceRqst);
396
			mtcSocket.joinGroup(ServiceRqst);
397
			
398
		   }catch(Exception e){
399
				e.printStackTrace();
400
		  }
401
		return;
333
		}
402
		}
334
		isMulticastSocketInitialized = true;
403
		isMulticastSocketInitialized = true;
335
		
404
		
Lines 343-349 Link Here
343
					platform.logDebug("Setting multicast socket interface to " + myIPs[0] + " failed.",t);
412
					platform.logDebug("Setting multicast socket interface to " + myIPs[0] + " failed.",t);
344
				}
413
				}
345
			}
414
			}
346
			mtcSocket.joinGroup(MCAST_ADDRESS);
415
			mtcSocket.joinGroup(SVRLOC_ADDRESS);
416
			mtcSocket.joinGroup(DA_ADDRESS);
417
			ServiceRqst= slp_hash(URL.toString(),URL.toString().length());
418
			mtcSocket.joinGroup(ServiceRqst);
347
		} catch (BindException be) {
419
		} catch (BindException be) {
348
			platform.logError(be.getMessage(), be);
420
			platform.logError(be.getMessage(), be);
349
			throw new RuntimeException("You have to be root to open port "
421
			throw new RuntimeException("You have to be root to open port "
Lines 614-624 Link Here
614
						SLP_DA_TYPE), scopes, null, SLPCore.DEFAULT_LOCALE);
686
						SLP_DA_TYPE), scopes, null, SLPCore.DEFAULT_LOCALE);
615
				sreq.xid = SLPCore.nextXid();
687
				sreq.xid = SLPCore.nextXid();
616
				sreq.scopeList = scopes;
688
				sreq.scopeList = scopes;
617
				sreq.address = MCAST_ADDRESS;
689
				sreq.address = DA_ADDRESS;
618
				sreq.multicast = true;
690
				sreq.multicast = true;
619
				byte[] bytes = sreq.getBytes();
691
				byte[] bytes = sreq.getBytes();
620
				DatagramPacket d = new DatagramPacket(bytes, bytes.length,
692
				DatagramPacket d = new DatagramPacket(bytes, bytes.length,
621
						MCAST_ADDRESS, SLP_PORT);
693
						DA_ADDRESS, SLP_PORT);
622
				platform.logTraceMessage("SENT " + sreq + "(udp multicast)");
694
				platform.logTraceMessage("SENT " + sreq + "(udp multicast)");
623
				setupReceiverThread(socket, CONFIG.getWaitTime(), sreq);
695
				setupReceiverThread(socket, CONFIG.getWaitTime(), sreq);
624
				try {
696
				try {
Lines 762-768 Link Here
762
		try {
834
		try {
763
835
764
			long start = System.currentTimeMillis();
836
			long start = System.currentTimeMillis();
765
837
			InetAddress Destination;
766
			List replyQueue = new ArrayList();
838
			List replyQueue = new ArrayList();
767
			List responders = new ArrayList();
839
			List responders = new ArrayList();
768
			List responses = new ArrayList();
840
			List responses = new ArrayList();
Lines 791-798 Link Here
791
					throw e;
863
					throw e;
792
				}
864
				}
793
			}
865
			}
866
			byte type=SLPMessage.getMessageType(msg);
867
			switch(type)
868
			{
869
				case SLPMessage.SRVRQST:
870
					ServiceRequest srq=(ServiceRequest)msg;
871
					msg.address=slp_hash(srq.serviceType.toString(),srq.serviceType.toString().length());
872
					Destination=msg.address;
873
					break;
874
875
				case SLPMessage.ATTRRQST:
876
				case SLPMessage.SRVTYPERQST:
877
					msg.address=SVRLOC_ADDRESS;
878
					Destination=msg.address;
879
					break;
880
881
				default:
882
					System.out.println("\n Unknown request Message has been received"+SLPMessage.getType(type));		
883
					return null;
884
				
794
885
795
			msg.address = MCAST_ADDRESS;
886
887
			}
796
			ReplyMessage reply;
888
			ReplyMessage reply;
797
889
798
			for (int i = 0; i < myIPs.length; i++) {
890
			for (int i = 0; i < myIPs.length; i++) {
Lines 833-840 Link Here
833
925
834
					// send the message
926
					// send the message
835
					DatagramPacket p = new DatagramPacket(message,
927
					DatagramPacket p = new DatagramPacket(message,
836
							message.length, InetAddress
928
							message.length, Destination, SLP_PORT);
837
									.getByName(SLP_MCAST_ADDRESS), SLP_PORT);
838
929
839
					try {
930
					try {
840
						socket.send(p);
931
						socket.send(p);
Lines 921-926 Link Here
921
		return false;
1012
		return false;
922
	}
1013
	}
923
1014
1015
	/*Hash Algorithm for SLP Service Type String(RFC 3111)*/
1016
1017
        static InetAddress slp_hash( String pc, int len)
1018
	{
1019
		String ip="FF02::1:1";
1020
		InetAddress Service_ip=null;//= InetAddress.getByName("FF02::1:1000");
1021
		/*An unsigned 32-bit value v is initialized to 0.Each byte of the character is considered consecutively*/
1022
		 int h=0;
1023
		String Extract= extract_Service(pc);
1024
1025
		for(int i=0;i<Extract.length();i++)
1026
		{	
1027
			/*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*/
1028
			h*=33;
1029
			h+=Extract.charAt(i);
1030
		}
1031
		/*The result is contained in the low order 10 bits of v*/
1032
		int j=(0x3ff&h);
1033
		//Concatenating the value with the IP
1034
		ip=ip+Integer.toHexString(j);
1035
		try{
1036
			Service_ip = InetAddress.getByName(ip);
1037
		}
1038
		catch(Exception e)
1039
		{
1040
			e.printStackTrace();
1041
		}
1042
		return Service_ip;
1043
1044
1045
	}
1046
1047
1048
	static String extract_Service(String url)
1049
	{
1050
		
1051
		int position=url.indexOf(':',0);
1052
		if(position==-1)
1053
			return url;
1054
		position=url.indexOf(':', position+1);
1055
		if(position==-1)
1056
			return url;
1057
		String substring= url.substring(0, position);
1058
			return substring;
1059
1060
	}
1061
1062
	
1063
1064
924
	/**
1065
	/**
925
	 * setup a new receiver thread for a socket.
1066
	 * setup a new receiver thread for a socket.
926
	 * 
1067
	 * 
(-)/home/jumbo/Downloads/ecf-master/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/impl/SLPMessage.java (+27 lines)
Lines 11-16 Link Here
11
 *    Markus Alexander Kuppe - enhancements and bug fixes
11
 *    Markus Alexander Kuppe - enhancements and bug fixes
12
 *
12
 *
13
*****************************************************************************/
13
*****************************************************************************/
14
15
16
/****************************************************************************
17
 * Copyright (c) 2013 Md.Jamal MohiUddin,
18
 * Ubiquitous Computing, C-DAC Hyderabad.
19
 * All rights reserved. This program and the accompanying materials
20
 * are made available under the terms of the Eclipse Public License v1.0
21
 * which accompanies this distribution, and is available at
22
 * http://www.eclipse.org/legal/epl-v10.html
23
 *
24
 * Contributors:
25
 *    Md.Jamal MohiUddin - Updation to IPv6
26
 *    P Sowjanya  	 - Updation to IPv6
27
 *
28
*****************************************************************************/
29
14
package ch.ethz.iks.slp.impl;
30
package ch.ethz.iks.slp.impl;
15
31
16
import java.io.ByteArrayOutputStream;
32
import java.io.ByteArrayOutputStream;
Lines 493-496 Link Here
493
		rule.visit(visitor);
510
		rule.visit(visitor);
494
		return visitor.getAttributes();
511
		return visitor.getAttributes();
495
	}
512
	}
513
514
	/**
515
	 *Returns the Type of The Request Message
516
	 *
517
	 */
518
519
	static byte getMessageType(RequestMessage msg)
520
	{
521
		return msg.funcID;
522
523
	}
496
}
524
}
(-)/home/jumbo/Downloads/ecf-master/protocols/bundles/ch.ethz.iks.slp/standalone/inclusions/ch/ethz/iks/slp/ServiceLocationManager.java (-1 / +17 lines)
Lines 11-16 Link Here
11
 *    Markus Alexander Kuppe - enhancements and bug fixes
11
 *    Markus Alexander Kuppe - enhancements and bug fixes
12
 *
12
 *
13
*****************************************************************************/
13
*****************************************************************************/
14
15
/****************************************************************************
16
 * Copyright (c) 2013 Md.Jamal MohiUddin,
17
 * Ubiquitous Computing, C-DAC Hyderabad.
18
 * All rights reserved. This program and the accompanying materials
19
 * are made available under the terms of the Eclipse Public License v1.0
20
 * which accompanies this distribution, and is available at
21
 * http://www.eclipse.org/legal/epl-v10.html
22
 *
23
 * Contributors:
24
 *    Md.Jamal MohiUddin - Updation to IPv6
25
 *    P Sowjanya  	 - Updation to IPv6
26
 *
27
*****************************************************************************/
28
29
14
package ch.ethz.iks.slp;
30
package ch.ethz.iks.slp;
15
31
16
import java.util.Locale;
32
import java.util.Locale;
Lines 65-70 Link Here
65
		init();
81
		init();
66
		if (locator != null) {
82
		if (locator != null) {
67
			try {
83
			try {
84
				//TODO::We have to Initialize the Multicast Socket for UA also for receiving DA Advt Messages
68
				return (Locator) locator.newInstance(new Object[] { locale });
85
				return (Locator) locator.newInstance(new Object[] { locale });
69
			} catch (Exception e) {
86
			} catch (Exception e) {
70
				throw new ServiceLocationException(
87
				throw new ServiceLocationException(
Lines 90-96 Link Here
90
	public static Advertiser getAdvertiser(final Locale locale)
107
	public static Advertiser getAdvertiser(final Locale locale)
91
			throws ServiceLocationException {
108
			throws ServiceLocationException {
92
		init();
109
		init();
93
		SLPCore.initMulticastSocket();
94
		if (advertiser != null) {
110
		if (advertiser != null) {
95
			try {
111
			try {
96
				return (Advertiser) advertiser
112
				return (Advertiser) advertiser

Return to bug 421063