Internet Protocol Chapter 5 Protocol Layering Juho Kim Graduate School of Information & Technology Sogang University Department of of Computer Science and and Engineering, Sogang University Page 1 CAD & VLSI Lab. Page Youse 1 Kim / 35
Protocol Layering The structure of the software found in hosts and routers that carries out network communication. Layering makes the internet software easier to build and trace The need for multiple protocols The conceptual layers of protocol software Functionality of the layers: ISO 7-layer reference model TCP/IP Internet layering model Difference between X.25 and internet layering Protocol layering principle Layering in the presence of network substructure Two important boundaries in the TCP/IP model Disadvantage of layering Basic idea behind multiplexing and demultiplexing Department of of Computer Science and and Engineering, Sogang University Page 2 CAD & VLSI Lab. Page Youse 2 Kim / 35
The Need For Multiple Protocols Protocol Layering Problems when machines communicate over a data network Hardware failure: A host or router => A protocol software needs to detect such failures and recover from them if possible. Network congestion: The protocol software needs to arrange ways that a congested machine can suppress further traffic. Packet delay or loss: The protocol software needs to learn or adapt to long delay Data corruption: The protocol software needs to detect and recover from errors Data duplication or sequence errors: The protocol software need to reorder or remove any duplicates. No single protocol can handle all of the problems Among layers of protocols, they must agree on formats. Department of of Computer Science and and Engineering, Sogang University Page 3 CAD & VLSI Lab. Page Youse 3 Kim / 35
Protocol Layering Conceptual Layers of Protocol Software The path of a message traversing the Internet from the sender through two intermediate machines to the receiver. Intermediate machines only send the datagram to the IP software layer. Department of of Computer Science and and Engineering, Sogang University Page 4 CAD & VLSI Lab. Page Youse 4 Kim / 35
OSI 7-Layer Reference Model Developed by the International Organization for Standardization protocol standards OSI Model (open systems interconnection) Application; provides access to OSI environment for users and also provides distributed information Presentation; provides application processes from data representation (syntax) Session; provides the control structure for communication between applications Transport; provides reliable, transparent transfer of data between end points (error recovery, flow control) Network; provides data transmission and switching techniques to connect systems Data link; provides for the reliable transfer of information across physical link Physical; transmission of unstructured bit stream over physical medium Department of of Computer Science and and Engineering, Sogang University Page 5 CAD & VLSI Lab. Page Youse 5 Kim / 35
TCP/IP Internet Layering Model Application layer ; support user application Transport layer ; transmission control protocol (TCP) provides reliability of exchanging data, flow control, and packets Internet layer ; internet protocol (IP) provides routing function across multiple networks. Encapsulating packet in an IP datagram (fills header and uses routing alg.) Network access layer ; circuit switching, packet switching (e.g., X.25), local area network (Ethernet) Physical layer ; physical interface between devices and a transmission medium or network Department of of Computer Science and and Engineering, Sogang University Page 6 CAD & VLSI Lab. Page Youse 6 Kim / 35
Layering in a TCP/IP Internet Environment Layering principle when a router is used. The frame delivered to router R is exactly the frame sent from host A, but differs from the frame sent between R and B Department of of Computer Science and and Engineering, Sogang University Page 7 CAD & VLSI Lab. Page Youse 7 Kim / 35
Layering In The Presence Of Network Substructure A set of point-to-point connections among routers Independent network: Serial Line IP (SLIP) or Point to Point Protocol (PPP) Causing too many networks (large routing table) Single IP network small routing table for intranet (a) Conceptual position of an internet protocol for point-to-point connections when IP treats them as a single IP network (b) Detailed diagram of corresponding software modules. Each arrow corresponds to one physical device. Department of of Computer Science and and Engineering, Sogang University Page 8 CAD & VLSI Lab. Page Youse 8 Kim / 35
Two Important Boundaries In The TCP/IP Model Protocol address boundary Operating system boundary Department of of Computer Science and and Engineering, Sogang University Page 9 CAD & VLSI Lab. Page Youse 9 Kim / 35
Disadvantages of Layering Strict layering prevents from the higher-level knowing the lowerlevel For example, the transport layer accepts a stream of bytes from an application program, divide the stream into packets, and send each packet across the internet. To optimize the transfer, the transport layer finds the largest packet size for that network. However, the transport layer does not know the routing and traffic. Relaxing the strict layering : passing information such as route selection, MTU (maximum transfer unit) to higher layer protocols. Department of of Computer Science and Engineering, Sogang University Page 10 CAD & VLSI Lab. Page Youse 10 / Kim 35
Demultiplexing at Network Interface Layer Demultiplexing of incoming frames based on the type field found in the frame header Department of of Computer Science and Engineering, Sogang University Page 11 CAD & VLSI Lab. Page Youse 11 / Kim 35
Demultiplexing at the Internet Layer Demultiplexing at the Internet layer. IP software chooses an appropriate procedure to handle a datagram based on the protocol type field in the datagram header Department of of Computer Science and Engineering, Sogang University Page 12 CAD & VLSI Lab. Page Youse 12 / Kim 35
User Datagram Protocol User Datagram Protocol (UDP) UDP message format UDP Encapulation and Protocol Layering UDP Multiplexing, Demultiplexing, and Ports Reserved and Available UDP Port Numbers Sockets Department of of Computer Science and Engineering, Sogang University Page 13 CAD & VLSI Lab. Page Youse 13 / Kim 35
User Datagram Protocol (UDP) Distinguishing multiple destinations within a given host: allowing multiple application programs executing on a given computer to send and receive datagrams independently. use different port number to identify different application protocol port : abstract destination port buffering port for late processing Sender needs to know both IP address and the protocol port number User Datagram Protocol : The primary mechanism that application programs use to send datagrams to other application programs. Department of of Computer Science and Engineering, Sogang University Page 14 CAD & VLSI Lab. Page Youse 14 / Kim 35
UDP Message Format UDP header UDP SOURCE PORT : optional UDP DESTINATION PORT : 16-bit protocol port number LENGTH : a count of octets in the UDP datagram (header + data) CHECKSUM : optional Department of of Computer Science and Engineering, Sogang University Page 15 CAD & VLSI Lab. Page Youse 15 / Kim 35
UDP Encapsulation and Protocol Layering The IP layer is responsible only for transferring data between a pair of hosts on an internet, while the UDP layer is responsible only for differentiating among multiple sources or destinations within one host. Department of of Computer Science and Engineering, Sogang University Page 16 CAD & VLSI Lab. Page Youse 16 / Kim 35
UDP Demultiplexing and Ports Example of demultiplexing one layer above IP. UDP uses the UDP destination port number to select an appropriate destination port for incoming datagrams. When port is full, UDP discards the incoming datagram and sends back port unreachable ICMP message back to the sender. Department of of Computer Science and Engineering, Sogang University Page 17 CAD & VLSI Lab. Page Youse 17 / Kim 35
Ports To identify different applications, tag each datagram with a port number. The UDP(or TCP) decides which application should receive the datagram by comparing the port number with ports currently in use. Each application program negotiates to obtain a protocol field and associated port number before it sends a UDP(TCP) datagram. Usually the port number points to an internal queue created by the Operating System Application as client should know in advance the port number for the particular application in the server. Application as a server can obtain the port number of the client on receiving the first request. Department of of Computer Science and Engineering, Sogang University Page 18 CAD & VLSI Lab. Page Youse 18 / Kim 35
Reserved Port Numbers Department of of Computer Science and Engineering, Sogang University Page 19 CAD & VLSI Lab. Page Youse 19 / Kim 35
Socket Interface Interface between application programs and TCP/IP protocols. Interface depends on operating systems. Socket is not considered as protocols (just an application, not standard). Used for network I/O: similar to file descriptor for file I/O in UNIX File I/O in UNIX: Open-Read-Write-Close paradigm Open returns an integer file descriptor --> user process uses the number for accessing the file Read transfers data into user process. Write transfers data from the user process to the file or device. Close is called by the user process to terminate the process. With file access application programs request the operating system to create a socket The system returns a small integer that the application program uses to reference the newly created socket. Department of of Computer Science and Engineering, Sogang University Page 20 CAD & VLSI Lab. Page Youse 20 / Kim 35
Networking with java.net Internet Address and URL InetAddress class java.lang.object + -- java.net.inetaddress public final class InetAddress extends Object implements Serializable This class represents an Internet Protocol (IP) address. Applications should use the methods getlocalhost, getbyname, or getallbyname to create a new InetAddress instance. Department of of Computer Science and Engineering, Sogang University Page 21 CAD & VLSI Lab. Page Youse 21 / Kim 35
Department of of Computer Science and Engineering, Sogang University Page 22 CAD & VLSI Lab. Page Youse 22 / Kim 35
Example) AddressTest.java import java.net.*; class AddressTest { public static void main(string args[]) } throws UnknownHostException { InetAddress Address = InetAddress.getLocalHost(); } System.out.println("Local Host Name : " + Address.getHostName()); System.out.println("Local Host IP Address : " + Address.getHostAddress()); Address = InetAddress.getByName("sogang.ac.kr"); System.out.println("sogang.ac.kr's computer name and IP Address : " + Address); InetAddress sw[] = InetAddress.getAllByName("www.ibm.com"); for (int i = 0; i < sw.length; i++) System.out.println(sw[i]); Department of of Computer Science and Engineering, Sogang University Page 23 CAD & VLSI Lab. Page Youse 23 / Kim 35
URL class Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine. More information on the types of URLs and their formats can be found at: http://www.ncsa.uiuc.edu/demoweb/url-primer.html In general, a URL can be broken into several parts. The previous example of a URL indicates that the protocol to use is http (HyperText Transport Protocol) and that the information resides on a host machine named www.ncsa.uiuc.edu. The information on that host machine is named demoweb/url-primer.html. The exact meaning of this name on the host machine is both protocol dependent and host dependent. The information normally resides in a file, but it could be generated on the fly. This component of the URL is called the file component, even though the information is not necessarily in a file. Department of of Computer Science and Engineering, Sogang University Page 24 CAD & VLSI Lab. Page Youse 24 / Kim 35
A URL can optionally specify a "port", which is the port number to which the TCP connection is made on the remote host machine. If the port is not specified, the default port for the protocol is used instead. For example, the default port for http is 80. An alternative port could be specified as: http://www.ncsa.uiuc.edu:8080/demoweb/urlprimer.html A URL may have appended to it an "anchor", also known as a "ref" or a "reference". The anchor is indicated by the sharp sign character "#" followed by more characters. For example, http://java.sun.com/index.html#chapter1 This anchor is not technically part of the URL. Rather, it indicates that after the specified resource is retrieved, the application is specifically interested in that part of the document that has the tag chapter1 attached to it. The meaning of a tag is resource specific. An application can also specify a "relative URL", which contains only enough information to reach the resource relative to another URL. Relative URLs are frequently used within HTML pages. For example, if the contents of the URL: http://java.sun.com/index.html contained within it the relative URL: FAQ.html it would be a shorthand for: http://java.sun.com/faq.html The relative URL need not specify all the components of a URL. If the protocol, host name, or port number is missing, the value is inherited from the fully specified URL. The file component must be specified. The optional anchor is not inherited. Department of of Computer Science and Engineering, Sogang University Page 25 CAD & VLSI Lab. Page Youse 25 / Kim 35
Department of of Computer Science and Engineering, Sogang University Page 26 CAD & VLSI Lab. Page Youse 26 / Kim 35
Department of of Computer Science and Engineering, Sogang University Page 27 CAD & VLSI Lab. Page Youse 27 / Kim 35
Example) urltest.java import java.net.*; class urltest { public static void main(string args[]) throws MalformedURLException { URL location = new URL("http://sogang.ac.kr"); System.out.println("protocol : " + location.getprotocol()); System.out.println("port : " + location.getport()); System.out.println("host : " + location.gethost()); System.out.println("file : " + location.getfile()); System.out.println("URL " + location.toexternalform()); } } Department of of Computer Science and Engineering, Sogang University Page 28 CAD & VLSI Lab. Page Youse 28 / Kim 35
URLConnection class The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL. The following methods are used to access the header fields and the contents after the connection is made to the remote object: getcontent getheaderfield getinputstream getoutputstream Certain header fields are accessed frequently. The methods: getcontentencoding getcontentlength getcontenttype getexpiration getdate getlastmodifed provide convenient access to these fields. The getcontenttype method is used by the getcontent method to determine the type of the remote object; subclasses may find it convenient to override the getcontenttype method. Department of of Computer Science and Engineering, Sogang University Page 29 CAD & VLSI Lab. Page Youse 29 / Kim 35
Example urlconnectiontest.java import java.util.date; class urlconnectiontest { public static void main(string args[]) throws Exception { int c; URL addr = new URL("http://www.sogang.ac.kr/wwwnew/index2.html"); URLConnection addrconnection = addr.openconnection(); System.out.println("Document Type : " + addrconnection.getcontenttype()); System.out.println("Last Modified : " + new Date(addrConnection.getLastModified())); int len = addrconnection.getcontentlength(); System.out.println("Document Length : " + len + "byte"); if (len > 0) { System.out.println(" ===== Contents ======= "); InputStream input = addrconnection.getinputstream(); int i = len; while (((c = input.read())!= -1) && (--i > 0)) { System.out.print((char) c); } input.close(); } else { System.out.println("No Contents"); } }} Department of of Computer Science and Engineering, Sogang University Page 30 CAD & VLSI Lab. Page Youse 30 / Kim 35
Department of of Computer Science and Engineering, Sogang University Page 31 CAD & VLSI Lab. Page Youse 31 / Kim 35
Department of of Computer Science and Engineering, Sogang University Page 32 CAD & VLSI Lab. Page Youse 32 / Kim 35
Socket ServerSocket class ServerSocket(int port) Creates a server socket on a specified port. ServerSocket(int port, int backlog) Creates a server socket and binds it to the specified local port number. ServerSocket(int port, int backlog, InetAddress bindaddr) Create a server with the specified port, listen backlog, and local IP address to bind to. Department of of Computer Science and Engineering, Sogang University Page 33 CAD & VLSI Lab. Page Youse 33 / Kim 35
Example) ServerSide.java import java.io.*; import java.net.*; class ServerSide { public static void main(string args[]) { try { int port = Integer.parseInt(args[0]); ServerSocket ss = new ServerSocket(port); while(true) { Socket s = ss.accept(); OutputStream os = s.getoutputstream(); DataOutputStream dos = new DataOutputStream(os); for (int i = 1; i <= 10; i++) dos.writeint(i); s.close(); }} catch(exception e) { System.out.println("Exception: " + e); }}} Department of of Computer Science and Engineering, Sogang University Page 34 CAD & VLSI Lab. Page Youse 34 / Kim 35
Example) ClientSide.java import java.io.*; import java.net.*; class ClientSide { public static void main(string args[]) { try { String server = args[0]; int port = Integer.parseInt(args[1]); Socket c = new Socket(server, port); InputStream is = c.getinputstream(); DataInputStream dis = new DataInputStream(is); for (int i = 1; i <= 10; i++) { int j = dis.readint(); System.out.println("data from server " + j); } c.close();} catch(exception e) { System.out.println("Exception: " + e); }}} Department of of Computer Science and Engineering, Sogang University Page 35 CAD & VLSI Lab. Page Youse 35 / Kim 35