55MulticastNetworks
Download
Report
Transcript 55MulticastNetworks
Multicast Sockets
• What is a multicast socket?
– unicast sockets provide a point to point
connection. There is one sender and one
receiver.
– Multicast sockets have one sender and many
receivers
Unicast vs. Multicast
sender
receiver
One-to-one communication or unicast
Group communication or multicast
Why doesn’t everyone use Mcast
sockets?
• Not all routers will pass Multicast sockets.
• Multicasting may not be supported on your
network.
• TTLs limit a packets spread.
• TTL = max # of routers a packet is allowed
to cross.
What are some Applications for
Mcast?
• appliances can look for a lookup server
MCast.
– suppose I plug in a PNP printer
• MCast is good for discovery
• Unicast is good for correspondance.
• Etherswitch does a kind of routing that
protects net legs from traffic.
IP multicast service model
• RFC1112 : Host Extensions for IP Multicasting - 1989
• Senders transmit IP datagrams to a "host group"
• Members of host group could be present anywhere in
the Internet
• Members join and leave the group and indicate this to
the routers
• Senders and receivers are distinct
• Routers listen to all multicast addresses and use
multicast routing protocols to manage groups
IP multicast group address
• receivers can be anywhere
• Class D address space
– high-order three 3bits are set
– 224.0.0.0 ~ 239.255.255.255
• Some well-known address have been designated
– RFC1700
– 224.0.0.0 ~ 224.0.0.25
Link-Layer Multicast Addresses
Ethernet and other LANs using 802 addresses:
IP multicast address
1110
Group bit
28 bits
0x01005e
0000000100000000010111100
23 bits
LAN multicast address
Lower 23 bits of Class D address are inserted into the lower
23 bits of MAC address (see RFC 1112)
Multicast Announcement (Lookup
initiated discovery)
1. Announcements
(sent via UDP
Multicast)
IP Address 224.0.1.84
port:4160
Discoverer
2. Request
Message (sent via
TCP unicast)
3. Response Message
(Sent via TCP unicast)
Lookup Service
Lookup Service
Lookup Service
Service Object
Service Attributes
1. Query the
Lookup
service
2. Gets Service
Proxy
Service Provider
Client
Service Object
Service Attributes
3. Interact with
service
Source distribution tree
Source
S
Notation: (S, G)
S = Source
G = Group
A
B
D
C
F
E
R
R
Receiver 1
Receiver 2
Protocol Characteristics
• Multicast UDP to IP - 224.0.1.84, port 4160
• Interval - 120 secs.
• Multicast Packet length never to exceed 512 bytes.
Etherswitch/mcast
• Etherswitch passes all mcast traffic through.
• Etherswitch isolates only unicast traffic.
• Ethernet 10 mbps – 100 mpbs 1Gbps 10
Gb/s.
• Now we can do VIDEO on the Ethernet.
Broadcast Video
• CCIR-601 Standard Video
– 720-x480 pixels at 16 bits per PEL at 30
Frames per second.
– 160 Mb/s, uncompressed.
– Suppose you don’t use a video camera to make
video!
What is video?
•
•
•
•
•
Image sequences + audio
How can I make image sequences?
Screen capture….are almost NOISE FREE.
Inter-frame coherence. Difference frames
can be coded efficiently.
Java Net Classes
Class
Description
DatagramPacket
This class represents a datagram packet.
DatagramSocket
This class represents a socket for sending and receiving
datagram packets.
InetAddress
This class represents an Internet Protocol (IP) address.
MulticastSocket
The multicast datagram socket class is useful for sending
and receiving IP multicast packets.
ServerSocket
This class implements server sockets.
Socket
This class implements client sockets (also called just
"sockets").
URL
A pointer to a "resource" on the World Wide Web.
URLConnection
The superclass of all classes that represent a
communications link between an application and a URL.
Class InetAddress
public boolean equals(Object obj);
public
public
public
public
public
byte[]
static
static
String
static
getAddress();
InetAddress[] getAllByName(String host);
InetAddress getByName(String host);
getHostName();
InetAddress getLocalHost();
public int hashCode();
public String toString();
This class represents an Internet Protocol (IP) address.
Applications should use the methods getLocalHost(), getByName(), or
getAllByName() to create a new InetAddress instance.
IP Multicast in Java
• Java has a Multicast Socket Class
• Use it to “join” a multicast group.
MulticastSocket s = null;
InetAddress group = null;
try {
group = InetAddress.getByName(“227.1.2.3”);
s = new MulticastSocket(5555);
s.joinGroup(group);
} catch (UnknownHostException e) {
} catch (IOException e)
}
{
IP Multicast in Java
• Receive DatagramPackets on a MulticastSocket
DatagramPacket recv = new DatagramPacket(buf,
buf.length);
try {
s.receive(recv);
} catch (IOException e) {
System.out.println("mcastReceive: " +
e.toString());
return;
}
// get message
String msg = new String(recv.getData(),
recv.getOffset(), recv.getLength());
IP Multicast in Java
• To send, just send a DatagramPacket to the multicast
address, port (no need to use a MulticastSocket, although
you could)
group = InetAddress.getByName(“227.1.2.3”);
s = new DatagramSocket();
DatagramPacket snd = new DatagramPacket(buf, buf.length,
group, 5555);
try {
s.send(snd);
} catch (IOException e) {
System.out.println("mcastSend: " + e.toString());
return;
}
Class Socket
// Constructors (partial list)
public Socket()
public Socket(InetAddress address, int port);
public Socket(String host, int port);
// Methods (partial list)
public void close();
public InetAddress getInetAddress();
public int getLocalPort();
public InputStream getInputStream();
public OutputStream getOutputStream();
public int getPort();
public String toString();
Class Socket
• This class implements client sockets (also called just sockets). A socket
is a end point for communication between two machines.
• The actual work of the socket is performed by an instance of the
SocketImpl class.
• It is possible to modify some TCP parameters:
– SO_LINGER
– SO_TIMEOUT
– TCP_NODELAY
– Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).
Class ServerSocket
// Constructors (partial list)
public ServerSocket(int port);
public ServerSocket(int port, int count);
// Methods (partial list)
public Socket accept();
public void close();
public InetAddress getInetAddress();
public int getLocalPort();
public String toString();
Class ServerSocket
• A ServerSocket waits for requests to come in over the network. It
performs some operation based on that request, and then possibly
returns a result to the requester.
• The actual work of the ServerSocket is performed by an instance of
the SocketImpl class.
• The abstract class SocketImpl is a common superclass of all classes
that actually implement sockets. It is used to create both client and
server sockets.
• A plain socket implements the SocketImpl methods exactly as
described, without attempting to go through a firewall or proxy.
UDP Based Applications
• UDP - unreliable packet based delivery service.
• The basic unit of transfer is called a Datagram. Datagrams are small,
fixed-length messages.
• Datagram based services do have some advantages:
– Speed
– Message-oriented service.
Datagrams
• Datagram packets - implement a connectionless, packet based, delivery
service.
• messages are routed based packet content.
• Multiple packets sent from one machine to another might be routed
differently, and might arrive in any order.
• Packets may be lost or duplicated during transit.
• The class DatagramPacket represents a datagram in Java.
Class DatagramPacket
//Constructors
public DatagramPacket(byte ibuf[], int ilength);
public DatagramPacket(
byte ibuf[], int ilength, InetAddress iaddr, int iport);
// Methods
public synchronized InetAddress getAddress();
public synchronized int getPort();
public synchornized byte[] getData();
int getLength();
void
void
void
void
setAddress(InetAddress iaddr);
setPort(int iport);
setData(byte ibuf[]);
setLength(int ilength);
Class DatagramSocket
• class represents a socket for
sending/receiving datagrams.
• Addressing information in the packet
header.
• A socket are bound to an address
• There is no special datagram server socket
class.
• packets can be lost, timeouts are important.
Class DatagramSocket
// Constructors
DatagramSocket()
DatagramSocket(int port)
DatagramSocket(int port, InetAddress iaddr)
// Methods
void close()
InetAddress getLocalAddress()
int getLocalPort()
int getSoTimeout()
void receive(DatagramPacket p)
void send(DatagramPacket p)
setSoTimeout(int timeout)
Echo Services
• A common network service is an echo server
• An echo server simply sends packets back to the sender
• A client creates a packet, sends it to the server, and waits for a
response.
• Echo services can be used to test network connectivity and
performance.
• There are typically different levels of echo services. Each provided by
a different layer in the protocol stack.
UDPEchoClient.java
import java.net.*; import java.io.*; import java.util.*;
public class UDPEchoClient {
static int echoPort = 7; static int msgLen = 16; static int timeOut=1000;
public static void main(String argv[]) {
try {
DatagramSocket sock = new DatagramSocket();
DatagramPacket pak;
byte msg[] = new byte[msgLen];
InetAddress echoHost = InetAddress.getByName(argv[0]);
pak = new DatagramPacket(msg,msgLen,echoHost,echoPort);
sock.send(pak);
sock.setSoTimeout(timeOut);
sock.receive(pak);
}
catch (InterruptedIOException e) {System.out.println("Timeout");}
catch (Exception e) {}
}}