ServerSocket H. Fauconnier 1-1 M2-Internet Java. Principe 1. Création dun ServerSocket par constructeur 2. Association (bind) de la socket à une adresse.

Slides:



Advertisements
Similar presentations
CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Advertisements

Network Programming and Java Sockets
Socket UDP H. Fauconnier 1-1 M2-Internet Java. UDP H. Fauconnier M2-Internet Java 2.
SOCKET PROGRAMMING WITH MOBILE SOCKET CLIENT DEARTMENT OF COMPUTER SCIENCE IOWA STATE UNIVERSITY.
Inter-Process Communication: Network Programming using TCP Java Sockets Dr. Rajkumar Buyya Cloud Computing and Distributed Systems (CLOUDS) Laboratory.
1 Network Programming and Java Sockets Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software.
2: Application Layer1 DNS: Domain Name System People: many identifiers: m SSN, name, Passport # Internet hosts, routers: m IP address (32 bit) - used for.
CSCI Java Networking1 Java Net Classes ClassDescription DatagramPacketThis class represents a datagram packet. DatagramSocketThis class represents.
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r Sockets are explicitly created, used, released by applications.
Network Programming and Java Sockets
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
Prepared By E. Musa Alyaman1 User Datagram Protocol (UDP) Chapter 5.
2: Application Layer1 Data Communication and Networks Lecture 12 Java Sockets November 30, 2006.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming February 8, 2005 Arthur Goldberg Computer Science Department.
Lecture 11 Java Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Joonbok Lee.
Socket programming with UDP and TCP. Socket Programming with TCP Connection oriented – Handshaking procedure Reliable byte-stream.
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
1 Network Layers Application Transport Network Data-Link Physical bits.
Protocols Rules for communicating between two entities (e.g., a client and a server) “A protocol definition specifies how distributed system elements interact.
2: Application Layer 1 Socket Programming Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley,
2: Application Layer 1 Socket Programming TCP and UDP.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
ECE5650: Network Programming
1 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 2 nd edition. Jim Kurose, Keith Ross.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
CS 3830 Day 11 Introduction : Application Layer 2 Server-client vs. P2P: example Client upload rate = u, F/u = 1 hour, u s = 10u, d min ≥ u s.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
Application Layer 2-1 ESERCITAZIONE SOCKET PROGRAMMING.
Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April A note on the use.
Winter 2002Suprakash Datta1 Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
-1- Georgia State UniversitySensorweb Research Laboratory CSC4220/6220 Computer Networks Dr. WenZhan Song Associate Professor, Computer Science.
Socket Programming Lee, Sooyong
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
UDP vs TCP UDP Low-level, connectionless No reliability guarantee TCP Connection-oriented Not as efficient as UDP.
Socket Programming Tutorial. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Java Sockets Programming
Java Socket programming. Socket programming with TCP.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Socket-Programming.  Establish contact (connection).  Exchange information (bi-directional).  Terminate contact.
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
1 CSCD 330 Network Programming Spring 2014 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 7 Application.
1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
Java Programming II Java Network (I) Java Programming II.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
Java.net CS-328 Dick Steflik.
Object-Orientated Analysis, Design and Programming
Socket Programming Socket Programming Overview
Socket programming with TCP
Chapter 2: outline 2.1 principles of network applications
Socket programming - Java
CSCD 330 Network Programming
Socket Programming Socket Programming Overview
Socket Programming.
CSCD 330 Network Programming
NETWORK PROGRAMMING CNET 441
Java Socket Programming
Socket Programming 2: Application Layer.
CPSC 441 UDP Socket Programming
Chapter 2: Application layer
Socket Programming with UDP
Presentation transcript:

ServerSocket H. Fauconnier 1-1 M2-Internet Java

Principe 1. Création dun ServerSocket par constructeur 2. Association (bind) de la socket à une adresse et un port ((1) et (2) peuvent être simultanés) 3. Écoute et connexion par accept 1. Communication getInputStream et getOutputStream 2. close (par le client ou le serveur ou les deux) 4. Aller en (2) (en général 3 est dans une thread) H. Fauconnier M2-Internet Java 2

Constructeurs public ServerSocket(int port) throws BindException, IOException public ServerSocket(int port, int queueLength) throws BindException, IOException public ServerSocket(int port, int queueLength, InetAddress bindAddress) throws IOException Ces constructeurs associent un port et une adresse au ServerSocket lusage du port est exclusif et si le port est déjà occupé une exception est lancéeServerSocket public ServerSocket( ) throws IOException H. Fauconnier M2-Internet Java 3

Exemple public static void portsLibres() { for (int port = 1; port <= 65535; port++) { try { // exception si le port est utilisé ServerSocket server = new ServerSocket(port); } catch (IOException ex) { System.out.println("serveur sur port" + port ); } H. Fauconnier M2-Internet Java 4

Remarques port 0: choisi par le système on peut donner une taille sur la file des connexions en attente on peut choisir une adresse particulière sur la machine locale En java >1.4 on peut faire un "bind" explicite: public void bind(SocketAddress endpoint) throws IOException public void bind(SocketAddress endpoint, int queueLength) throws IOException H. Fauconnier M2-Internet Java 5

Exemple public static void portQuelconque() { try { ServerSocket server = new ServerSocket(0); System.out.println("Le port obtenu est " + server.getLocalPort()); } catch (IOException ex) { System.err.println(ex); } H. Fauconnier M2-Internet Java 6

Connexion accept() crée et retourne une nouvelle socket pour la connexion associée (IP, port)(IP, port) H. Fauconnier M2-Internet Java 7

Exemple ServerSocket server = new ServerSocket(5776); while (true) { Socket connection = server.accept( ); OutputStreamWriter out = new OutputStreamWriter( connection.getOutputStream( )); out.write("Connecté:" +connection+"\r\n"); connection.close( ); } H. Fauconnier M2-Internet Java 8

Exemple plus complet public final static int DEFAULT_PORT = 13; public static void dayTime(){ dayTime(DEFAULT_PORT); } public static void dayTime(int port) { if (port = 65536) { System.out.println("Erreur port:"); return; } try { ServerSocket server = new ServerSocket(port); Socket connection = null; H. Fauconnier M2-Internet Java 9

Exemple suite while (true) { try { connection = server.accept(); Writer out = new OutputStreamWriter( connection.getOutputStream()); Date now = new Date(); out.write(now.toString() +"\r\n"); out.flush(); connection.close(); } catch (IOException ex) {} finally { try { if (connection != null) connection.close(); } catch (IOException ex) {} } } catch (IOException ex) { System.err.println(ex); } H. Fauconnier M2-Internet Java 10

Fermeture public void close( ) throws IOException Ferme le ServerSocket et toutes les connexions créées par accept sur la ServerSocket H. Fauconnier M2-Internet Java 11

Serveur echo public static void serveurEcho(int port) { try { ServerSocket server = new ServerSocket(port,100); System.out.println("Serveur:"+server+" en écoute sur le port: " + server.getLocalPort()+" est lancé"); while (true) { Socket connection = server.accept(); System.out.println("Serveur connexion avec: " + connection); Thread echo=new EchoThread(connection); echo.start(); } catch (IOException ex) { System.out.println("le port" + port + " est occupé"); System.out.println("On suppose donc que le service estlancé"); } } H. Fauconnier M2-Internet Java 12

serveur echo: EchoThread class EchoThread extends Thread { BufferedReader in; PrintWriter out; Socket connection; public EchoThread(Socket connection) { try{ this.connection=connection; InputStream in=connection.getInputStream(); OutputStream out=connection.getOutputStream(); this.in = new BufferedReader(new InputStreamReader(in)); this.out = new PrintWriter(out); } catch (IOException ex) { System.err.println(ex); } H. Fauconnier M2-Internet Java 13

run public void run() { try { while (true) { String st; st = in.readLine(); if (st.equals(".")) in.close(); out.close(); break; } System.out.println("Serveur a reçu:"+st+" de "+connection); out.println(st); out.flush(); } } catch (SocketException ex) { ex.printStackTrace(); } catch (IOException ex) { System.err.println(ex); } try { in.close(); out.close(); } catch (IOException ex) { ex.printStackTrace();} } H. Fauconnier M2-Internet Java 14

Remarques utilisation des threads pour traiter le service et éviter de faire attendre les clients on peut aussi utiliser des entrées/sorties non bloquantes H. Fauconnier M2-Internet Java 15

Autres méthodes public InetAddress getInetAddress( ) public int getLocalPort( ) H. Fauconnier M2-Internet Java 16

Options SO_TIMEOUT SO_REUSEADDR SO_RCVBUF public void setPerformancePreferences(int connectionTime, int latency, int bandwidth H. Fauconnier M2-Internet Java 17

Socket UDP H. Fauconnier 1-18 M2-Internet Java

UDP H. Fauconnier M2-Internet Java 19

M2-Internet Java 20 Socket programming with UDP UDP: no connection between client and server no handshaking sender explicitly attaches IP address and port of destination to each segment OS attaches IP address and port of sending socket to each segment Server can extract IP address, port of sender from received segment application viewpoint UDP provides unreliable transfer of groups of bytes (datagrams) between client and server Note: the official terminology for a UDP packet is datagram. In this class, we instead use UDP segment. H. Fauconnier

Running example Client: User types line of text Client program sends line to server Server: Server receives line of text Capitalizes all the letters Sends modified line to client Client: Receives line of text Displays M2-Internet Java 21 H. Fauconnier

M2-Internet Java 22 Client/server socket interaction: UDP Server (running on hostid ) close clientSocket read datagram from clientSocket create socket, clientSocket = DatagramSocket() Client Create datagram with server IP and port=x; send datagram via clientSocket create socket, port= x. serverSocket = DatagramSocket() read datagram from serverSocket write reply to serverSocket specifying client address, port number H. Fauconnier

M2-Internet Java 23 Example: Java client (UDP) Output: sends packet (recall that TCP sent byte stream) Input: receives packet (recall thatTCP received byte stream) Client process client UDP socket H. Fauconnier

M2-Internet Java 24 Example: Java client (UDP) import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); Create input stream Create client socket Translate hostname to IP address using DNS H. Fauconnier

M2-Internet Java 25 Example: Java client (UDP), cont. DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } Create datagram with data-to-send, length, IP addr, port Send datagram to server Read datagram from server H. Fauconnier

M2-Internet Java 26 Example: Java server (UDP) import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Create datagram socket at port 9876 Create space for received datagram Receive datagram H. Fauconnier

M2-Internet Java 27 Example: Java server (UDP), cont String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } Get IP addr port #, of sender Write out datagram to socket End of while loop, loop back and wait for another datagram Create datagram to send to client H. Fauconnier

UDP observations & questions Both client server use DatagramSocket Dest IP and port are explicitly attached to segment. What would happen if change both clientSocket and serverSocket to mySocket? Can the client send a segment to server without knowing the servers IP address and/or port number? Can multiple clients use the server? M2-Internet Java 28 H. Fauconnier

DatagramPacket Un paquet contient au plus 65,507 bytes Pour construire les paquet public DatagramPacket(byte[] buffer, int length) public DatagramPacket(byte[] buffer, int offset, int length) Pour construire et envoyer public DatagramPacket(byte[] data, int length, InetAddress destination, int port) public DatagramPacket(byte[] data, int offset, int length, InetAddress destination, int port) public DatagramPacket(byte[] data, int length, SocketAddress destination, int port) public DatagramPacket(byte[] data, int offset, int length, SocketAddress destination, int port) H. Fauconnier M2-Internet Java 29

Exemple String s = "On essaie…"; byte[] data = s.getBytes("ASCII"); try { InetAddress ia = InetAddress.getByName(" "); int port = 7;// existe-t-il? DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); } catch (IOException ex) } H. Fauconnier M2-Internet Java 30

Méthodes Adresses public InetAddress getAddress( )InetAddress public int getPort( ) public SocketAddress getSocketAddress( )SocketAddress public void setAddress(InetAddress remote) public void setPort(int port) public void setAddress(SocketAddress remote) H. Fauconnier M2-Internet Java 31

Méthodes (suite) Manipulation des données: public byte[] getData( ) public int getLength( ) public int getOffset( ) public void setData(byte[] data) public void setData(byte[] data, int offset, int length ) public void setLength(int length) H. Fauconnier M2-Internet Java 32

Exemple import java.net.*; public class DatagramExample { public static void main(String[] args) { String s = "Essayons."; byte[] data = s.getBytes( ); try { InetAddress ia = InetAddress.getByName(" int port =7; DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); System.out.println(" Un packet pour" + dp.getAddress( ) + " port " + dp.getPort( )); System.out.println("il y a " + dp.getLength( ) + " bytes dans le packet"); System.out.println( new String(dp.getData( ), dp.getOffset( ), dp.getLength( ))); } catch (UnknownHostException e) { System.err.println(e); } H. Fauconnier M2-Internet Java 33

DatagramSocket Constructeurs public DatagramSocket( ) throws SocketException public DatagramSocket(int port) throws SocketException public DatagramSocket(int port, InetAddress interface) throws SocketException public DatagramSocket(SocketAddress interface) throws SocketException (protected DatagramSocket(DatagramSocketImpl impl) throws SocketException) H. Fauconnier M2-Internet Java 34

Exemple java.net.*; public class UDPPortScanner { public static void main(String[] args) { for (int port = 1024; port <= 65535; port++) { try { // exception si utilisé DatagramSocket server = new DatagramSocket(port); server.close( ); } catch (SocketException ex) { System.out.println("Port occupé" + port + "."); } // end try } // end for } H. Fauconnier M2-Internet Java 35

Envoyer et recevoir public void send(DatagramPacket dp) throws IOException public void receive(DatagramPacket dp) throws IOException H. Fauconnier M2-Internet Java 36

Un exemple: Echo UDPServeur UDPEchoServeur UDPEchoClient SenderThread ReceiverThread H. Fauconnier M2-Internet Java 37

Echo: UDPServeur import java.net.*; import java.io.*; public abstract class UDPServeur extends Thread { private int bufferSize; protected DatagramSocket sock; public UDPServeur(int port, int bufferSize) throws SocketException { this.bufferSize = bufferSize; this.sock = new DatagramSocket(port); } public UDPServeur(int port) throws SocketException { this(port, 8192); } public void run() { byte[] buffer = new byte[bufferSize]; while (true) { DatagramPacket incoming = new DatagramPacket(buffer, buffer.length); try { sock.receive(incoming); this.respond(incoming); } catch (IOException e) { System.err.println(e); } } // end while } public abstract void respond(DatagramPacket request); } H. Fauconnier M2-Internet Java 38

UDPEchoServeur public class UDPEchoServeur extends UDPServeur { public final static int DEFAULT_PORT = 2222; public UDPEchoServeur() throws SocketException { super(DEFAULT_PORT); } public void respond(DatagramPacket packet) { try { byte[] data = new byte[packet.getLength()]; System.arraycopy(packet.getData(), 0, data, 0, packet.getLength()); try { String s = new String(data, "8859_1"); System.out.println(packet.getAddress() + " port " + packet.getPort() + " reçu " + s); } catch (java.io.UnsupportedEncodingException ex) {} DatagramPacket outgoing = new DatagramPacket(packet.getData(), packet.getLength(), packet.getAddress(), packet.getPort()); sock.send(outgoing); } catch (IOException ex) { System.err.println(ex); } H. Fauconnier M2-Internet Java 39

Client: UDPEchoClient public class UDPEchoClient { public static void lancer(String hostname, int port) { try { InetAddress ia = InetAddress.getByName(hostname); SenderThread sender = new SenderThread(ia, port); sender.start(); Thread receiver = new ReceiverThread(sender.getSocket()); receiver.start(); } catch (UnknownHostException ex) { System.err.println(ex); } catch (SocketException ex) { System.err.println(ex); } } // end lancer } H. Fauconnier M2-Internet Java 40

ReceiverThread class ReceiverThread extends Thread { DatagramSocket socket; private boolean stopped = false; public ReceiverThread(DatagramSocket ds) throws SocketException { this.socket = ds; } public void halt() { this.stopped = true; } public DatagramSocket getSocket(){ return socket; } public void run() { byte[] buffer = new byte[65507]; while (true) { if (stopped) return; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); try { socket.receive(dp); String s = new String(dp.getData(), 0, dp.getLength()); System.out.println(s); Thread.yield(); } catch (IOException ex) {System.err.println(ex); } } H. Fauconnier M2-Internet Java 41

SenderThread public class SenderThread extends Thread { private InetAddress server; private DatagramSocket socket; private boolean stopped = false; private int port; public SenderThread(InetAddress address, int port) throws SocketException { this.server = address; this.port = port; this.socket = new DatagramSocket(); this.socket.connect(server, port); } public void halt() { this.stopped = true; } //… H. Fauconnier M2-Internet Java 42

SenderThread //… public DatagramSocket getSocket() { return this.socket; } public void run() { try { BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in)); while (true) { if (stopped) return; String theLine = userInput.readLine(); if (theLine.equals(".")) break; byte[] data = theLine.getBytes(); DatagramPacket output = new DatagramPacket(data, data.length, server, port); socket.send(output); Thread.yield(); } } // end try catch (IOException ex) {System.err.println(ex); } } // end run } H. Fauconnier M2-Internet Java 43

Autres méthodes public void close( ) public int getLocalPort( ) public InetAddress getLocalAddress( ) public SocketAddress getLocalSocketAddress( ) public void connect(InetAddress host, int port) public void disconnect( ) public int getPort( ) public InetAddress getInetAddress( ) public InetAddress getRemoteSocketAddress( ) H. Fauconnier M2-Internet Java 44

Options SO_TIMEOUT public synchronized void setSoTimeout(int timeout) throws SocketException public synchronized int getSoTimeout( ) throws IOException SO_RCVBUF public void setReceiveBufferSize(int size) throws SocketException public int getReceiveBufferSize( ) throws SocketException SO_SNDBUF public void setSendBufferSize(int size) throws SocketException int getSendBufferSize( ) throws SocketException SO_REUSEADDR (plusieurs sockets sur la même adresse) public void setReuseAddress(boolean on) throws SocketException boolean getReuseAddress( ) throws SocketException SO_BROADCAST public void setBroadcast(boolean on) throws SocketException public boolean getBroadcast( ) throws SocketException H. Fauconnier M2-Internet Java 45

Multicast 46 H. Fauconnier M2-Internet Java

4- 47 R1 R2 R3R4 source duplication R1 R2 R3R4 in-network duplication duplicate creation/transmission duplicate Broadcast Routing Deliver packets from srce to all other nodes Source duplication is inefficient: r Source duplication: how does source determine recipient addresses H. Fauconnier

M2-Internet Java In-network duplication Flooding: when node receives brdcst pckt, sends copy to all neighbors Problems: cycles & broadcast storm Controlled flooding: node only brdcsts pkt if it hasnt brdcst same packet before Node keeps track of pckt ids already brdcsted Or reverse path forwarding (RPF): only forward pckt if it arrived on shortest path between node and source Spanning tree No redundant packets received by any node H. Fauconnier

M2-Internet Java A B G D E c F A B G D E c F (a) Broadcast initiated at A (b) Broadcast initiated at D Spanning Tree First construct a spanning tree Nodes forward copies only along spanning tree H. Fauconnier

M2-Internet Java A B G D E c F (a)Stepwise construction of spanning tree A B G D E c F (b) Constructed spanning tree Spanning Tree: Creation Center node Each node sends unicast join message to center node Message forwarded until it arrives at a node already belonging to spanning tree H. Fauconnier

Multicast Groupe: adresse IP de classe D Un hôte peut joindre un groupe Protocole pour établir les groupes (IGMP) Protocole et algorithme pour le routage M2-Internet Java H. Fauconnier

IGMP IGMP (internet Group Management Protocol Entre un hôte et son routeur (multicast) Membership_query: du routeur vers tous les hôtes pour déterminer quels hôtes appartiennent à quels groupes Membership_report: des hôtes vers le routeur Membership_leave: pour quitter un groupe (optionnel) M2-Internet Java H. Fauconnier

Multicast Routing: Problem Statement Goal: find a tree (or trees) connecting routers having local mcast group members tree: not all paths between routers used source-based: different tree from each sender to rcvrs shared-tree: same tree used by all group members Shared tree Source-based trees H. Fauconnier M2-Internet Java

Approaches for building mcast trees Approaches: source-based tree: one tree per source shortest path trees reverse path forwarding group-shared tree: group uses one tree minimal spanning (Steiner) center-based trees …we first look at basic approaches, then specific protocols adopting these approaches H. Fauconnier M2-Internet Java

Shortest Path Tree mcast forwarding tree: tree of shortest path routes from source to all receivers Dijkstras algorithm R1 R2 R3 R4 R5 R6 R i router with attached group member router with no attached group member link used for forwarding, i indicates order link added by algorithm LEGEND S: source H. Fauconnier M2-Internet Java

Reverse Path Forwarding if (mcast datagram received on incoming link on shortest path back to center) then flood datagram onto all outgoing links else ignore datagram rely on routers knowledge of unicast shortest path from it to sender each router has simple forwarding behavior: H. Fauconnier M2-Internet Java

Reverse Path Forwarding: example result is a source-specific reverse SPT –may be a bad choice with asymmetric links R1 R2 R3 R4 R5 R6 R7 router with attached group member router with no attached group member datagram will be forwarded LEGEND S: source datagram will not be forwarded H. Fauconnier M2-Internet Java

Reverse Path Forwarding: pruning forwarding tree contains subtrees with no mcast group members no need to forward datagrams down subtree prune msgs sent upstream by router with no downstream group members R1 R2 R3 R4 R5 R6 R7 router with attached group member router with no attached group member prune message LEGEND S: source links with multicast forwarding P P P H. Fauconnier M2-Internet Java

Shared-Tree: Steiner Tree Steiner Tree: minimum cost tree connecting all routers with attached group members problem is NP-complete excellent heuristics exists not used in practice: computational complexity information about entire network needed monolithic: rerun whenever a router needs to join/leave H. Fauconnier M2-Internet Java

Center-based trees single delivery tree shared by all one router identified as center of tree to join: edge router sends unicast join-msg addressed to center router join-msg processed by intermediate routers and forwarded towards center join-msg either hits existing tree branch for this center, or arrives at center path taken by join-msg becomes new branch of tree for this router H. Fauconnier M2-Internet Java

Center-based trees: an example Suppose R6 chosen as center: R1 R2 R3 R4 R5 R6 R7 router with attached group member router with no attached group member path order in which join messages generated LEGEND H. Fauconnier 1-61 M2-Internet Java

Internet Multicasting Routing: DVMRP DVMRP: distance vector multicast routing protocol, RFC1075 flood and prune: reverse path forwarding, source-based tree RPF tree based on DVMRPs own routing tables constructed by communicating DVMRP routers no assumptions about underlying unicast initial datagram to mcast group flooded everywhere via RPF routers not wanting group: send upstream prune msgs H. Fauconnier M2-Internet Java

DVMRP: continued… soft state: DVMRP router periodically (1 min.) forgets branches are pruned: mcast data again flows down unpruned branch downstream router: reprune or else continue to receive data routers can quickly regraft to tree following IGMP join at leaf odds and ends commonly implemented in commercial routers Mbone routing done using DVMRP H. Fauconnier M2-Internet Java

Tunneling Q: How to connect islands of multicast routers in a sea of unicast routers? mcast datagram encapsulated inside normal (non-multicast- addressed) datagram normal IP datagram sent thru tunnel via regular IP unicast to receiving mcast router receiving mcast router unencapsulates to get mcast datagram physical topology logical topology H. Fauconnier M2-Internet Java

PIM: Protocol Independent Multicast not dependent on any specific underlying unicast routing algorithm (works with all) two different multicast distribution scenarios : Dense: group members densely packed, in close proximity. bandwidth more plentiful Sparse: # networks with group members small wrt # interconnected networks group members widely dispersed bandwidth not plentiful H. Fauconnier M2-Internet Java

Consequences of Sparse-Dense Dichotomy: Dense group membership by routers assumed until routers explicitly prune data-driven construction on mcast tree (e.g., RPF) bandwidth and non- group-router processing profligate Sparse : no membership until routers explicitly join receiver- driven construction of mcast tree (e.g., center-based) bandwidth and non-group- router processing conservative H. Fauconnier M2-Internet Java

PIM- Dense Mode flood-and-prune RPF, similar to DVMRP but underlying unicast protocol provides RPF info for incoming datagram less complicated (less efficient) downstream flood than DVMRP reduces reliance on underlying routing algorithm has protocol mechanism for router to detect it is a leaf- node router H. Fauconnier M2-Internet Java

PIM - Sparse Mode center-based approach router sends join msg to rendezvous point (RP) intermediate routers update state and forward join after joining via RP, router can switch to source-specific tree increased performance: less concentration, shorter paths R1 R2 R3 R4 R5 R6 R7 join all data multicast from rendezvous point rendezvous point H. Fauconnier M2-Internet Java

PIM - Sparse Mode sender(s): unicast data to RP, which distributes down RP-rooted tree RP can extend mcast tree upstream to source RP can send stop msg if no attached receivers no one is listening! R1 R2 R3 R4 R5 R6 R7 join all data multicast from rendezvous point rendezvous point H. Fauconnier M2-Internet Java

Multicast Géré par les routeurs Pas de garantie… Importance du ttl (Évaluation) –Local:0 –Sous-réseau local:1 –Pays:48 –Continent:64 –Le monde:255 M2-Internet Java H. Fauconnier

Multicast Un groupe est identifié par une adresse IP (classe D) entre et Une adresse multicast peut avoir un nom Exemple ntp.mcast.net M2-Internet Java H. Fauconnier

Sockets multicast Extension de DatagramSocket public class MulticastSocket extends DatagramSocket Principe: Créer une MulticastSocket Rejoindre un group: joinGroup() Créer DatagramPacket –Receive() leaveGroup() Close() H. Fauconnier M2-Internet Java 72

Création try { MulticastSocket ms = new MulticastSocket( ); // send datagrams... }catch (SocketException se){System.err.println(se);} try { SocketAddress address = new InetSocketAddress(" ", 4000); MulticastSocket ms = new MulticastSocket(address); // receive datagrams... }catch (SocketException ex) {System.err.println(ex);} H. Fauconnier M2-Internet Java 73

Création try { MulticastSocket ms = new MulticastSocket(null); ms.setReuseAddress(false); SocketAddress address = new InetSocketAddress(4000); ms.bind(address); // receive datagrams... }catch (SocketException ex) { System.err.println(ex);} H. Fauconnier M2-Internet Java 74

Rejoindre… try { MulticastSocket ms = new MulticastSocket(4000); InetAddress ia = InetAddress.getByName(" "); ms.joinGroup(ia); byte[] buffer = new byte[8192]; while (true) { DatagramPacket dp = new DatagramPacket(buffer, buffer.length); ms.receive(dp); String s = new String(dp.getData( ), "8859_1"); System.out.println(s); } }catch (IOException ex) { System.err.println(ex);} H. Fauconnier M2-Internet Java 75

send try { InetAddress ia = InetAddress.getByName("experiment.mcast.net "); byte[] data = "un packet…\r\n".getBytes( ); int port = 4000; DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); MulticastSocket ms = new MulticastSocket( ); ms.send(dp,64); }catch (IOException ex) {System.err.println(ex);} H. Fauconnier M2-Internet Java 76