Full Transcript

Computer Networks COE768 Lecture 02 Network Software Dr. Khalid A. Hafeez Fall, 2024 Outline Protocol layers » Design issues for the layers » Connection-oriented vs. connectionless service » Service primitives » Relationship of services to protocols »...

Computer Networks COE768 Lecture 02 Network Software Dr. Khalid A. Hafeez Fall, 2024 Outline Protocol layers » Design issues for the layers » Connection-oriented vs. connectionless service » Service primitives » Relationship of services to protocols » 2 Network Software Layer Architecture  Networking requires the co-operation of many different tasks  Raw data transfer over a physical channel  Error and flow control  Switching  Routing  Traffic control  Network Security  And many more … 3 Protocol Layers Protocol layering is the main structuring method used to divide up network functionality.  Each protocol instance talks virtually to its peer  Each layer communicates only by using the one below  Lower layer services are accessed by an interface  At bottom, messages are carried by the medium 4 Protocol Layers Each protocol at different layers serves a different purpose Each lower layer adds its own header (with control information) to the message to transmit and removes it on receive Layers may also split and join messages, etc. Sam Sally Mother Mother Father Father Brother Brother 5 Protocol Layers Organization of Networking Functions in a computing device User Space Network Application Kernal Space TCP/UDP TCP ≜ Transmission Control Protocol UDP ≜ User Datagram Protocol Operating System IP IP ≜ Internet Protocol Driver Driver Ethernet WiFi 6 Connection-Oriented vs. Connectionless Layers can offer two types of service to the layers above them:  Connection-oriented: a connection must be set up for ongoing use (and torn down after use), e.g., phone call  Connectionless: messages are handled separately, e.g., postal delivery (each message (letter) carries the full destination address and routed independently) Each kind of service can further be characterized by its reliability:  Reliability means, the message is acknowledged. 7 Service Primitives A service is provided to the layer above as primitives (operations) If the protocol stack is located in the operating system, as it often is, the primitives are normally system calls.  These calls cause a trap to kernel mode, which then turns control of the machine over to the operating system to send the necessary packets. 8 Relationship of Services to Protocols A service is a set of primitives (operations) that a layer provides to the layer above it.:  A layer provides a service to the one above it [vertical] A protocol, in contrast, is a set of rules governing the format and meaning of the packets, or messages that are exchanged by the peer entities within a layer.  A layer talks to its peer using a protocol [horizontal] 9 Reference Models Reference models describe the layers in a network architecture  OSI (Open Systems Interconnection) reference model » – Developed by the International Standard Organization (ISO)  TCP/IP reference model »  Model used for this text »  Critique of OSI and TCP/IP » 10 OSI Reference Model A principled, international standard, seven layer model to connect different systems – Provides functions needed by users – Converts different representations – Manages task dialogs – Provides end-to-end delivery – Sends packets over multiple links – Sends frames of information – Sends bits as signals over the channel 11 OSI Reference Model Physical Layer:  bits “on the wire”.  Determines the specs for all physical components – Cabling: Twisted Pair, Fiber Optic, Coax Cable – Interconnect methods (topology / devices) – Data encoding (bits to signals) application – Electrical properties presentation – Examples: session » Ethernet (IEEE 802.3) » Token Ring (IEEE 802.5) transport » Wireless (IEEE 802.11n, ac) network link  What are the Physical Layer components on computer? physical – NIC: Network Interface Card – It has a MAC Address/Physical address of a computer 12 OSI Reference Model Link Layer:  Data transfer between neighboring network elements – Moving frames from one hop (node) to another  Provides error detection/correction capability – Using acknowledgement – FEC (Forward Error Correction) application  Control access to the shared channel. presentation – MAC: Medium Access Control sublayer session transport network link physical 13 OSI Reference Model Link Layer:  Sub-layers of the Data Link Layer – MAC (Media Access Control) » Gives data to the NIC » Controls access to the media through: application » CSMA/CD Carrier Sense Multiple Access/Collision Detection presentation » Token passing – LLC (Logical Link Layer) session » Manages the data link interface (or Service Access Points (SAPs)) transport » Can detect some transmission errors using a Cyclic Redundancy Check (CRC). network LLC » If the packet is bad, the LLC will request the sender to resend it. MAC physical 14 OSI Reference Model Network Layer:  Controls the operation of the subnet – Provides network-wide addressing and a mechanism to move packets between networks (routing) » routing of datagrams (packets) from source to destination  Handling congestion in conjunction with higher layers  Examples: IP, routing protocols application presentation End system Virtual communication End system session Upper PDU Upper Layers Routers/switches Layers transport Network Network Network Network network Data-link Data-link Data-link Data-link link Physical Physical Physical Physical physical Actual communication 15 OSI Reference Model Transport Layer:  Process-Process data transfer  Provides reliable data delivery  Receives info from upper layers and segments it into packets  Provides end-to-end error control and flow control application  Examples: – TCP, UDP presentation End system End system session Upper Upper transport layers layers Error control, flow control network Transport Transport Network Network link Data-link Network Data-link physical Physical Physical 16 OSI Reference Model Transport Layer:  Differences between Data-Link and Transport layers in terms of Error Control Data-link Layer...... Error Control over a application physical link Data-Link Data-Link presentation Physical Physical session transport Transport Layer network...... Error Control over an End-to-end network link Transport connection Transport Network Network physical Network 17 OSI Reference Model Session Layer:  Allows applications to maintain an ongoing session  Synchronization, checkpointing to allow users to pick up from where they left off in the event of a crash and subsequent recovery  Examples: – Operating systems, Scheduling application – Remote Procedure Call (RPC) presentation session transport network link physical 18 OSI Reference Model Presentation Layer: Data representation  Allow applications to interpret meaning of data, e.g., encryption, compression, machine-specific conventions  Examples: – ASCII/EBCDIC, JPEG, MP3  Why presentation layer? application – Example: what is the value of 10010001 ? presentation – Answer: It depends on how you want to interpret it. » If it is interpreted as unsigned integer: 145 session » If it is interpreted as signed integer: -111 transport » If it is interpreted as ASCII (odd parity): H network link physical 19 OSI Reference Model Application Layer: supporting network applications  Gives end-user applications access to network resources  Where is it on my computer? – Workstation or Server Service in MS Windows  Examples: – FTP, SMTP, HTTP, Telnet, VoIP, Secure Shell application presentation session transport network link physical 20 OSI Reference Model How all layers work together?  Each layer contains a Protocol Data Unit (PDU) – PDU’s are used for peer-to-peer contact between corresponding layers. – Data is handled by the top three layers, then Segmented by the Transport layer. – The Network layer places it into packets and the Data Link frames the packets for transmission. – Physical layer converts it to bits and sends it out over the media. – The receiving computer reverses the process using the information contained in the PDU 21 OSI Reference Model How all layers work together? 22 TCP/IP Reference Model A four-layer model derived from experimentation; omits some OSI layers and uses the IP as the network layer. The TCP/IP reference model. 23 TCP/IP Reference Model The link layer describes what links such as serial lines and classic Ethernet must do to meet the needs of the connectionless internet layer. The internet layer defines two protocols: IP (Internet Protocol), ICMP (Internet Control Message Protocol) to help the IP. The job of the internet layer is to deliver IP packets where they are supposed to go. 24 TCP/IP Reference Model The transport layer allows peer entities on the source and destination hosts to carry on a conversation. It defines two protocols: TCP (Transmission Control Protocol) It is a reliable connection-oriented protocol It handles flow control to make sure a fast sender cannot swamp a slow receiver UDP (User Datagram Protocol) It is an unreliable, connectionless protocol It is also widely used for one-shot, client-server-type request-reply queries and applications in which prompt delivery is more important than accurate delivery, such as transmitting speech or video. 25 TCP: Transmission Control Protocol TCP – Connection and Error Control Mechanism Overview  Applications using TCP need to establish a TCP connection before data transfer Application1 Application1 (2) Three-way handshake (1) Connection (3) connection (6) Data (4) Data Connection.request Connection.acknowledgement Acknowledgement TCP TCP (5) Data (6) Acknowledgement...... 26 UDP: User Datagram Protocol UDP  UDP is connectionless – data can be transmitted without requiring connection establishment  UDP can perform error detection but not error recovery Application1 Application1 (1) Data (3) Data (2) Data UDP UDP...... 27 Socket Programming: TCP Server Programming: 1. Socket Creation int sockfd = socket(domain, type, protocol) sockfd: socket descriptor, an integer (like a file handle) domain: integer, specifies communication domain AF_ LOCAL: used for communication between processes on the same host AF_INET: used for communication between processes on different hosts connected by IPV4 AF_INET6: used for communication between processes on different hosts connected by IPV6 type: communication type SOCK_STREAM: TCP(reliable, connection-oriented) SOCK_DGRAM: UDP(unreliable, connectionless) protocol: Protocol value for Internet Protocol(IP), which is 0 28 Socket Programming: TCP Server Programming: 2. Bind: binds the socket to the address and port number specified in addr. You can use INADDR_ANY to use any IP address on the server to receive new clients. int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); 3. Listen: It puts the server socket in a passive mode, where it waits for the client to approach the server to make a connection. int listen(int sockfd, int backlog); backlog: is the maximum length to which the queue of pending connections 4. Accept int new_socket= accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);  It extracts the first connection request on the queue of pending connections for the listening socket, sockfd, creates a new connected socket, and returns a new file descriptor referring to that socket.  At this point, the connection is established between client and server, and they are ready to transfer data. You can send and receive data, when done, close the connection: close(sockfd); 29 Socket Programming: TCP Client Programming: 1. Socket Creation ▪ The same as that of server’s socket creation int sockfd = socket(domain, type, protocol) 1. Connect int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); ▪ The connect() system call connects the socket referred to by the file descriptor sockfd to the address specified by addr. ▪ Server’s address and port is specified in addr. You can send and receive data When done, close the connection: close(sockfd); 30 Socket Programming: TCP TCP Host 1 Host2 server Client sd sd TCP TCP connection TCP IP IP Ethernet Ethernet Network Server Client sd = socket(AF_INET, SOCK_STREAM, 0); sd = socket(AF_INET, SOCK_STREAM, 0); bind(sd, (struct sockaddr *)&server, sizeof(server)); connect(sd, (struct sockaddr *)&server, sizeof(server)); listen(sd, 5); new_sd = accept(sd, (struct sockaddr *)&client, &client_len); 31 Socket Programming: TCP Protocol-Service Time Diagram Client TCP Server socket TCP connection packet exchange socket (Three-way handshake) bind listen connect accept Return from connect Return from accept...... write(sd, buf, n) n = read(sd, buf, BUFSIZ) read return ACK To send data – “write” system call To receive data – “read” system call 32 Socket Programming: TCP Server Concurrency Host 1 Host2 create create Child2 echo_server Child1 Client1 Client2 new_sd2 sd new_sd1 TCP connection TCP TCP TCP connection IP IP Ethernet Ethernet Network Server new_sd = accept(sd, (struct sockaddr *)&client, &client_len); switch (fork()){ case 0: (void) close(sd); exit(echod(new_sd)); default: (void) close(new_sd); break; case -1: fprintf(stderr, "fork: error\n"); } 33 Socket Programming: TCP Echo Server Server code for Echo server Client code for Echo server int echod(int sd) while(n=read(0, sbuf, BUFLEN)){ { write(sd, sbuf, n); char *bp, buf[BUFLEN]; printf("Receive: \n"); int n, bytes_to_read; bp = rbuf; bytes_to_read = n; while(n = read(sd, buf, BUFLEN)) write(sd, buf, n); while ((i = read(sd, bp, bytes_to_read)) > 0){ bp += i; close(sd); bytes_to_read -=i; return(0); write(1, rbuf, n); } printf(“Transmit: \n”); } } close(sd); 34 Socket Programming: TCP Protocol-Service Time diagram for Echo Service User Client TCP Server socket socket TCP connection bind listen connect accept User enters read Return from connect Return from read Return from accept a message from the read write(message) keyboard Return from read read write(message) Return from read … close socket Return from read. Time Zero data byte in the buffer indicates TCP connection TCP connection Termination termination. 35 Socket Programming: UDP server UDP is a connection-less protocol It does not require any handshaking prior to sending or receiving data Server Side: 1. Create a socket:  int socket_desc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 2. Bind socket descriptor to the server address:  bind(socket_desc, (struct sockaddr*)&server_addr, sizeof(server_addr); – Unlike TCP, the server-side does not wait for a client to connect and, therefore, does not receive the client’s address prior to sending and receiving data. – Instead, the server receives information about the client when it receives data using the recvfrom() method: 36 Socket Programming: UDP server 3. Send/receive data  recvfrom(socket_desc, client_message, sizeof(client_message), 0, (struct sockaddr*)&client_addr, &client_struct_length); – The client’s information, stored in the variable client_addr  sendto(socket_desc, server_message, strlen(server_message), 0, (struct sockaddr*)&client_addr, client_struct_length); 4. Close the socket to end the communication:  close(socket_desc); 37 Socket Programming: UDP client 1. Create a socket, and initialize the server’s address information in a variable of type sockaddr_in  int socket_desc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 2. Send and receive data:  Unlike TCP, when the client sends and receives data using sendto() and recvfrom(), the server’s information has to be given every time:  sendto(socket_desc, client_message, strlen(client_message), 0, (struct sockaddr*)&server_addr, server_struct_length);  recvfrom(socket_desc, server_message, sizeof(server_message), 0, (struct sockaddr*)&server_addr, &server_struct_length); 38 TCP/IP Reference Model The application layer contains all the higher-level protocols: TELNET, to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection FTP (File Transfer Protocol) SMTP (Simple Mail Transfer Protocol), for electronic mail DNS (Domain Name System), for mapping host names onto their network addresses HTTP (Hyper Text Transferee Protocol), for fetching pages on the World Wide Web RTP (Real Time Protocol), for delivering real-time media such as voice or movies 39 TCP/IP Reference Model Encapsulation source message M application segment Ht M transport datagram Hn Ht M network frame Hl Hn Ht M link physical link physical switch destination Hn Ht M network M application Hl Hn Ht M link Hn Ht M Ht M transport physical Hn Ht M network Hl Hn Ht M link router physical 40

Use Quizgecko on...
Browser
Browser