Telecooperation P4 SSDP Q&A

Download Report

Transcript Telecooperation P4 SSDP Q&A

Technische Universität Darmstadt
Telecooperation
Telecooperation P4: Internet Praktikum
Q&A Session
Fernando Lyardet
Copyrighted material; for TUD student use only
Prof. Dr. M. Mühlhäuser
Telekooperation
©
SSDP
• The SSDP protocol allows a device to announce to other peers
(in Upnp, the control points) that it has become available on
the network.
• First Step:
SSDP M_SEARCH (HTTPMU) –advertisement(ssdp:alive)
New Device
SSDP M_SEARCH (HTTPU) –description URL(ssdp:discover)
<TKn-m>:
2
Prof. Dr. M. Mühlhäuser
Telekooperation
©
HTTPMU
•
•
•
•
•
Service Advertisement
On UDP, you send datagrams – Datagrams = self-contained messages
Multicast UDP sends datagrams to a "group"
For HTTPMU, the contents of the datagram are HTTPrequests
There is no response to these multicast requests – the message may be
received by any number of clients. It is not a request-response Situation
 A request like GET http://localhost/index.html cannot be interpreted as a
request for a document
• HTTPMU is uses the syntax of HTTP while changing the semantics
• HTTPMU allows the possibility of new request types such as NOTIFY as well
as the standard HTTP requests of GET, POST, HEAD, etc
• HTTPMU was invented to support UPnP. Is not a W3C standard
<TKn-m>:
3
Prof. Dr. M. Mühlhäuser
Telekooperation
©
HTTPU
•
•
•
•
Service Discovery
HTTPU sends a single datagram over UDP to a host
Uses unicast UDP
The recipient may send a reply back to the host and port
that sent the datagram
• Again, it is not expected that standard HTTP requests be
sent, only that the syntax is obeyed
• Also no W3C Standard. HTTPU was invented for UPnP
<TKn-m>:
4
Prof. Dr. M. Mühlhäuser
Telekooperation
©
Notifications (GENA)
• Notify is multicast by HTTPMU when a device wants to advertise itself, usually at
startup
• Notify message include:
–
a statement about the device type such as
schemas-upnporg:device:BinaryLight:0.9
–
an HTTP URL for an XML description of the device
• Each device has a universally unique id (UUID) so that it can be identified even if
it's IP address changes or it leaves and revisits the network
• There is no response to a notify
NOTIFY * HTTP/1.1
HOST: 239.255.255.250:1900
CACHE-CONTROL: max-age = seconds until advertisement expires
LOCATION: URL for UPnP description for root device
NT: search target
NTS: ssdp:alive
SERVER: OS/version UPnP/1.0 product/version
USN: advertisement UUID
• A notify is also sent at graceful shutdown. The messages are distinguished by the
field NTS which is set to ssdp:alive or ssdp:byebye
<TKn-m>:
5
Prof. Dr. M. Mühlhäuser
Telekooperation
©
Multicast with Java (Sender code outline)
public void sendMsg() {
MulticastSocket UDPmc;
// Generate multicast ssdp:alive notify.
// Some methods are only to give an idea (eg. „public string getHttpVersion()“)
String aliveMsg = "";
aliveMsg = "NOTIFY * HTTP/" + getHttpVersion()+ CRLF;
aliveMsg += "LOCATION: http://" //+"....getLocalAddress().getHostAddress()“ + CRLF;
//You must complete the notification Packet here...
//Packet length should be <1500 bytes (Ethernet MTU=Maximun Transfer Unit).
// However the MTU may vary according to the underlying hardware.
//Create the datagram Packet to be sent
DatagramPacket ssdpAliveMsgPacket = new DatagramPacket(aliveMsg.getBytes(), aliveMsg.getBytes().length,
MULTICAST_GROUP, MULTICAST_PORT);
//MULTICAST GROUP addresses have a range that consists of addresses from 224.0.0.0 through to 239.255.255.255.
//(Class D addresses.) Example: the Multicast Group for upnp is: 239.255.255.250
try {
UDPmc = new MulticastSocket();
// Create Multicast Socket
UDPmc.joinGroup(InetAddress.getByName(MULTICAST_GROUP)); // Bind the multicast socket to the Multicast group
} catch (IOException e) {System.out.println("Exception creating&setting up the m-cast socket");}
//Send alive Packet
try {
UDPmc.send(aliveMsg);
} catch (IOException e) {
System.out.println("Exception attempting to send Packet");
}
}
// On closing the connection, some clean up:
UDPmc.leaveGroup(InetAddress.getByName(MULTICAST_GROUP));
UDPmc.close();
<TKn-m>:
6
Prof. Dr. M. Mühlhäuser
Telekooperation
©
Multicast with Java (Receiver outline)
public ReceivePackets() {
try {
// create an empty packet to receive data
DatagramPacket ssdpAliveMsgPacket = new DatagramPacket(ssdpAliveMsgPacket.getBytes(),
ssdpAliveMsgPacket.getBytes().length,MULTICAST_GROUP, MULTICAST_PORT);
//Create a Multicast socket
MulticastSocket UDPmc = new MulticastSocket(MULTICAST_PORT);
// Bind the socket to the Multicast group
InetAddress
group = InetAddress.getByName(MULTICAST_GROUP);
MulticastSocket UDPmc.joinGroup(group);
// wait for a packet
UDPmc.receive(dp);
// Clean up…
UDPmc.leaveGroup(ia);
UDPmc.close();
} catch (UnknownHostException e) {
logger.error(e);
} catch (IOException e) {
logger.error(e);
}
}
<TKn-m>:
7