System-Level I/O.

Slides:



Advertisements
Similar presentations
Chapter 17 Networking Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Advertisements

IP: The Internet Protocol
Networks and Network Programming June 2, 2008 Topics Client-server programming model Networks A programmer’s view of the Internet.
Protocols and the TCP/IP Suite
CS335 Networking & Network Administration Tuesday April 27, 2010.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 Communicating over the Network Network Fundamentals – Chapter 2.
Lecture slides prepared for “Business Data Communications”, 7/e, by William Stallings and Tom Case, Chapter 8 “TCP/IP”.
Recitation 11: I/O Problems Andrew Faulring Section A 18 November 2002.
Protocols and the TCP/IP Suite Chapter 4. Multilayer communication. A series of layers, each built upon the one below it. The purpose of each layer is.
Internetworking Topics Client-server programming model Networks Internetworks Global IP Internet IP addresses Domain names Connections CS 105 “Tour of.
Chapter 2 The Infrastructure. Copyright © 2003, Addison Wesley Understand the structure & elements As a business student, it is important that you understand.
The Network Layer. Network Projects Must utilize sockets programming –Client and Server –Any platform Please submit one page proposal Can work individually.
Lecture 2 TCP/IP Protocol Suite Reference: TCP/IP Protocol Suite, 4 th Edition (chapter 2) 1.
Computer Networks. IP Addresses Before we communicate with a computer on the network we have to be able to identify it. Every computer on a network must.
1 Internetworking: Concepts, Architecture, and Protocols.
Protocols and the TCP/IP Suite
Chapter 1: Introduction to Web Applications. This chapter gives an overview of the Internet, and where the World Wide Web fits in. It then outlines the.
Input and Output Topics I/O hardware Unix file abstraction Robust I/O File sharing io.ppt CS 105 “Tour of the Black Holes of Computing”
Carnegie Mellon Introduction to Computer Systems /18-243, spring nd Lecture, Apr. 9 th Instructors: Gregory Kesden and Markus Püschel.
FALL, 2005CSI Part 2.3 Internetworking & Addressing (Concept, IP Addressing, IP Routing, IP Datagrams, Address Resolution Robert L. Probert, SITE,
Lect1..ppt - 01/06/05 CDA 6505 Network Architecture and Client/Server Computing Lecture 2 Protocols and the TCP/IP Suite by Zornitza Genova Prodanoff.
Chapter 17 - Internetworking: Concepts, Architecture, and Protocols 1. Internetworking concepts 2. Router 3. protocol for internetworking 4. TCP/ IP layering.
I. Basic Network Concepts. I.1 Networks Network Node Address Packet Protocol.
Recitation 11: 11/18/02 Outline Robust I/O Chapter 11 Practice Problems Annie Luo Office Hours: Thursday 6:00 – 7:00 Wean.
1 Networking Chapter Distributed Capabilities Communications architectures –Software that supports a group of networked computers Network operating.
Internetworking Internet: A network among networks, or a network of networks Allows accommodation of multiple network technologies Universal Service Routers.
Internetworking Internet: A network among networks, or a network of networks Allows accommodation of multiple network technologies Universal Service Routers.
CSE 6590 Department of Computer Science & Engineering York University 111/9/ :26 AM.
CMPE 80N - Introduction to Networks and the Internet 1 CMPE 80N Winter 2004 Lecture 16 Introduction to Networks and the Internet.
IP1 The Underlying Technologies. What is inside the Internet? Or What are the key underlying technologies that make it work so successfully? –Packet Switching.
Internetworking Topics Client-server programming model Networks Internetworks Global IP Internet IP addresses Domain names Connections CS 105 “Tour of.
System-Level I/O.
1 Chapter 4. Protocols and the TCP/IP Suite Wen-Shyang Hwang KUAS EE.
1 System-Level I/O. 2 Outline Unix I/O Reading File Metadata Sharing Files & I/O redirection Robust I/O Standard I/O Suggested Reading –10.1~10.3, 10.5~10.7,
1 Network Communications A Brief Introduction. 2 Network Communications.
Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work.
Relevant Computer Info. The Computer Consists of: Hardware –The CPU and motherboard (and bus) –Storage Devices (hard disk, memory, …) –Input Devices (keyboard,
Ad Hoc – Wireless connection between two devices Backbone – The hardware used in networking Bandwidth – The speed at which the network is capable of sending.
The Concept of Universal Service
Chapter Objectives In this chapter, you will learn:
Computer Networks.
Transport Protocols Relates to Lab 5. An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Instructors: Gregory Kesden
Robust I/O package Chapter 11 practice problems
A quick intro to networking
CS 105 “Tour of the Black Holes of Computing”
Scaling the Network: The Internet Protocol
Operating Systems (CS 340 D)
Layered Architectures
CS 105 “Tour of the Black Holes of Computing”
Lecture 6: TCP/IP Networking By: Adal Alashban
CS703 - Advanced Operating Systems
Network Architecture Introductory material
Internetworking & Address Resolution
Net431:advanced net services
Internet Topics Client-server programming model Networks in general
Protocols and the TCP/IP Suite
“The course that gives CMU its Zip!”
Topic 5: Communication and the Internet
Review of Important Networking Concepts
I. Basic Network Concepts
Network Programming Chapter 12
TCP/IP Protocol Suite: Review
Lecture 2: Overview of TCP/IP protocol
1 TRANSMISSION CONTROL PROTOCOL / INTERNET PROTOCOL (TCP/IP) K. PALANIVEL Systems Analyst, Computer Centre Pondicherry University, Puducherry –
Scaling the Network: The Internet Protocol
Protocols and the TCP/IP Suite
Internetworking April 17, 2003
Computer Networks DA2402.
Lecture 23: Networking and IP
Presentation transcript:

System-Level I/O

Outline RIO Suggested Reading 11.4

Buffered Input and Output Robust I/O Buffered Input and Output Efficiently read text lines and binary data from a file whose contents are cached in an application-level buffer #include "csapp.h" void rio_readinitb(rio_t *rp, int fd) ; ssize_t readlineb(rio_t *rp, void *usrbuf, size t maxlen); ssize_t readnb(rio_t *rp, void *usrbuf, size t maxlen); returns: number of bytes read (0 if EOF), -1 on error

Robust I/O #define RIO_BUFSIZE 8192 typedef struct { int rio_fd; int rio_cnt; char *rio_bufptr; char rio_buf[RIO_BUFSIZE]; } rio_t ; void rio_readinitb(rio_t *rp, int fd) { rp->rio_fd = fd ; rp->rio_cnt = 0 ; rp->rio_bufptr = rio_buf ; }

Robust I/O #include “csapp.h” int main(int argc, char **argv) { int n; rio_t rio; char buf[MAXLINE]; rio_readinitb(&rio, STDIN_FILENO); while((n = rio_readlineb(&rio, buf, MAXLINE)) != 0 ) rio_writen(STDOUT_FILENO, buf, n) ; }

1 static ssize_t rio_read(rio_t *rp, char *usrbuf, size_t n) 2 { 3 int cnt = 0; 4 /* refill if buf is empty */ 5 while (rp->rio_cnt <= 0) { rp->rio_cnt = read(rp->rio_fd, rp->rio_buf, sizeof(rp->rio_buf)); 8 if (rp->rio_cnt < 0) { 9 if (errno != EINTR) 10 return -1 ; 11 } 12 else if (rp->rio_cnt == 0) /* EOF */ 13 return 0; 14 else 15 rp->rio_bufptr = rp->rio_buf; /* reset buffer ptr */ } 17

18. /. Copy min(n, rp->rio_cnt) bytes from internal buf to user buf 19 cnt = n ; if ( rp->rio_cnt < n) cnt = rp->rio_cnt ; memcpy(usrbuf, rp->rio_bufptr, cnt) ; rp->rio_buffer += cnt ; rp->rio_cnt -= cnt ; return cnt ; }

ssize_t rio_readlineb (rio_t *rp, void *usrbuf, size_t maxlen) { int n, rc; char c, *bufp = usrbuf ; for (n=1; n < maxlen; n++) {

if ((rc = rio_read(rp, &c, 1)) == 1) { *bufp++ = c ; if (c == ‘\n’) break ; } else if (rc == 0) { if (n == 1) return 0; /* EOF, no data read*/ else } else return –1 ; /* error */ } *bufp = 0 ; return n ;

ssize_t rio_readnb(rio_t *rp, void *usrbuf, size_t n) { size_t nleft = n ; ssize_t nread ; char *bufp = usrbuf; while (nleft > 0) {

if ((nread = rio_read(rp, bufp, nleft)) < 0) { if (errno = EINTR) /* interrupted by sig handler return */ nread = 0 ; else return –1 ; } else if (nread == 0) break ; nleft -= nread ; bufp += nread ; return (n – nleft );

Networking Programming

Outline Networks Suggested Reading: 12.2

Hardware organization of a network host main memory I/O bridge MI ALU register file system bus memory bus disk controller graphics adapter USB mouse keyboard monitor I/O bus Expansion slots network CPU chip

Computer networks A network is a hierarchical system of boxes and wires organized by geographical proximity LAN (local area network) spans a building or campus. Ethernet is most prominent example. WAN (wide-area network) spans country or world. typically high-speed point-to-point phone lines.

An internetwork (internet) is an interconnected set of networks. Computer networks An internetwork (internet) is an interconnected set of networks. The IP Internet is the most famous example of an internetwork. Let’s see how we would build an internetwork from the ground up.

Lowest level: Ethernet segment Ethernet segment consists of a collection of hosts connected by wires (twisted pairs) to a hub. Spans room or floor in a building. host hub 100 Mb/s ports

Lowest level: Ethernet segment Operation Each Ethernet adapter has a unique 48-bit address. Hosts send bits to any other host in chunks called frames. Hub slavishly copies each bit from each port to every other port. every host sees every bit.

Next level: Bridged Ethernet segment Spans building or campus Bridges cleverly learn which hosts are reachable from which ports and then selectively copy frames from port to port

Next level: Bridged Ethernet segment host hub bridge 100 Mb/s 1 Gb/s A B C X Y

Conceptual view of LANs For simplicity, hubs, bridges, and wires are often shown as a collection of hosts attached to a single wire: host ...

Next level: internets Multiple incompatible LANs can be physically connected by specialized computers called routers. The connected networks are called an internet.

Next level: internets host LAN 1 ... LAN 2 router WAN LAN 1 and LAN 2 might be completely different, totally incompatible LANs

Client-Server Programming Model Global IP Internet Suggested Reading: Outline Client-Server Programming Model Global IP Internet Suggested Reading: 12.1、12.3

A client-server transaction Every network application is based on the client-server model: a server process and one or more client processes server manages some resource. server provides service by manipulating resource for clients.

A client-server transaction process server 1. client sends request 2. server handles request 3. server sends response 4. client response resource Note: clients and servers are processes running on hosts (can be the same or different hosts).

The notion of an internet protocol How is it possible to send bits across incompatible LANs and WANs? Solution: protocol software running on each host and router smoothes out the differences between the different networks.

The notion of an internet protocol Implements an internet protocol (i.e., set of rules) that governs how hosts and routers should cooperate when they transfer data from network to network. TCP/IP is the protocol for the global IP Internet.

What does an internet protocol do? Naming scheme The internet protocol defines a uniform format for host addresses. Each host (and router) is assigned at least one of these internet addresses that uniquely identifies it.

What does an internet protocol do? Delivery mechanism The internet protocol defines a standard transfer unit (packet) Packet consists of header and payload header: contains info such as packet size, source and destination addresses. payload: contains data bits sent from source host.

Transferring data over an internet protocol software client LAN1 adapter Host A data PH FH1 FH2 LAN2 (1) (2) (3) (4) (5) (6) (7) (8) internet packet LAN2 frame Router LAN1 frame server Host B

We are glossing over a number of important questions: Other issues We are glossing over a number of important questions: What if different networks have different maximum frame sizes? (segmentation) How do routers know where to forward frames? How are routers informed when the network topology changes? What if packets get lost?

Other issues These questions form the heart of the area of computer systems known as networking.

Most famous example of an internet. Global IP Internet Most famous example of an internet. Based on the TCP/IP protocol family. IP (Internet protocol) : provides basic naming scheme and unreliable delivery capability of packets (datagrams) from host-to-host.

Based on the TCP/IP protocol family. Global IP Internet Based on the TCP/IP protocol family. UDP (Unreliable Datagram Protocol) uses IP to provide unreliable datagram delivery from process-to-process. TCP (Transmission Control Protocol) uses IP to provide reliable byte streams (like files) from process-to-process. Accessed via a mix of Unix file I/O and functions from the Berkeley sockets interface.

Hardware and software organization of an Internet application Internet client host Internet server host client server user code sockets interface (system calls) TCP/IP TCP/IP kernel code hardware interface (interrupts) network adapter network adapter hardware Global IP Internet

Programmer’s view of the Internet Hosts are mapped to a set of 32-bit IP addresses. 128.2.203.179 The set of IP addresses is mapped to a set of identifiers called Internet domain names. 128.2.203.179 is mapped to www.cs.cmu.edu A process on one host communicates with a process on another host over a connection.

Dotted decimal notation By convention, each by in a 32-bit IP address is represented by its decimal value and separated by a period IP address 0x8002C2F2 = 128.2.194.242

Dotted decimal notation Functions for converting between binary IP addresses and dotted decimal strings: inet_aton: converts a dotted decimal string to an IP address in network byte order. inet_ntoa: converts an IP address in network by order to its corresponding dotted decimal string. “n” denotes network representation. “a” denotes application representation.