* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Introduction
IEEE 802.1aq wikipedia , lookup
Distributed firewall wikipedia , lookup
Piggybacking (Internet access) wikipedia , lookup
Asynchronous Transfer Mode wikipedia , lookup
Serial digital interface wikipedia , lookup
Wake-on-LAN wikipedia , lookup
Computer network wikipedia , lookup
Network tap wikipedia , lookup
List of wireless community networks by region wikipedia , lookup
Zero-configuration networking wikipedia , lookup
Cracking of wireless networks wikipedia , lookup
Deep packet inspection wikipedia , lookup
Airborne Networking wikipedia , lookup
Routing in delay-tolerant networking wikipedia , lookup
Internet protocol suite wikipedia , lookup
Recursive InterNetwork Architecture (RINA) wikipedia , lookup
Chapter 1 Foundation 1 Problems How to build a scalable network that will support different applications? What is a computer network? How is a computer network different from other types of networks? What is a computer network architecture? Chapter Outline 1.1 Applications 1.2 Requirements 1.3 Network Architecture 1.4 Implementing Network Software 1.5 Performance 3 Chapter Goal Exploring the requirements that different applications and different communities place on the computer network Introducing the idea of network architecture Introducing some key elements in implementing network software Define key metrics that will be used to evaluate the performance of computer network 4 1.1 Applications Most people know about the Internet (a computer network) through applications World Wide Web Email Online social network Streaming audio video File sharing Instant messaging 5 Example of an Application A multimedia application including video-conferencing Application Protocols URL Uniform Resource Locater http://www.cs.princeton.edu/~llp/index.html HTTP Hyper Text Transfer Protocol TCP Transmission Control Protocol 17 messages for one URL request 6 to find the IP (Internet Protocol) address 3 for connection establishment of TCP 4 for HTTP request and acknowledgement Request: I got your request and I will send the data Reply: Here is the data you requested; I got the data 4 messages for tearing down TCP connection 1.2 Requirements Application programmer list the services that his application needs: delay bounded delivery of data Network designer design a cost-effective network with sharable resources Network provider list the characteristics of a system that is easy to manage 8 Requirements Building blocks Switched networks Addressing and routing Multiplexing Inter-process communication 9 Building Blocks Nodes: PC, special-purpose hardware… hosts switches Links: coax cable, optical fiber… point-to-point (a) multiple access (b) 10 Terms node a computer or a more specialized piece of hardware network switch a small hardware device that joins multiple computers together within one local area network (LAN) technically, network switches operate at layer two (data link layer) of the OSI model 11 link physical medium point-to-point two nodes share a single physical link multiple-access more than two nodes share a single physical link 12 Connectivity Need to understand the following terminologies scale link nodes point-to-point multiple access switched network circuit switched packet switched packet, message store-and-forward Switched Networks A network can be defined recursively as... two or more nodes connected by a link, or Switched network two or more networks connected by two or more nodes Interconnection of networks 14 Strategies Circuit switching original telephone network carry bit streams 15 Packet switching store-and-forward messages each node first receives a complete packet over some link stores the packet in its internal memory forwards the complete packet to the next node multiplex multiple flows of data over a single physical link example: Internet 16 Addressing and Routing Address byte-string that identifies a node usually unique (IP address, MAC address) Routing process of how to forward messages to the destination node based on its address 17 Types of address unicast: node-specific broadcast: all nodes on the network multicast: some subset of nodes on the network 18 IP address (Internet Protocol address) a unique address that certain electronic devices use in order to identify and communicate with each other on a computer network utilizing the Internet Protocol standard (IP)—in simpler terms, a computer address any participating network device—including routers, computers, servers, printers, Internet fax machines, and some telephones—can have their own unique address example: 140.119.164.54 19 MAC address (Media Access Control address) a MAC address or EHA (Ethernet Hardware Address) or hardware address or adapter address is a quasi-unique identifier attached to most network adapters (NICs) a number that acts like a name for a particular network adapter, so, e.g., the network cards (or built-in network adapters) in two different computers will have different names, or MAC addresses 20 Multiplexing Synchronous Time-Division Multiplexing (STDM) divide time into equal-sized quanta, and in a roundrobin fashion, give each flow a chance to send its data over the physical link 21 Frequency-Division Multiplexing (FDM) Multiplexing multiple logical flows over a single physical link 22 three flows of data (L1 to R1 and so on) multiplexed onto a single physical link by switch 1 demultiplexed back into separate flows by switch 2 transmit each flow over the physical link at a different frequency e.g. signals for different TV stations are transmitted at a different frequency on a physical cable TV link 23 Statistical Multiplexing Time-division & interleaved the physical link is shared over time (time-division) first data from one flow is transmitted over the physical link, then data from another flow is transmitted, and so on (interleaved) 24 On-demand data is transmitted from each flow on demand rather than during a predetermined time slot if only one flow has data to send, it gets to transmit that data without waiting for its quantum to come around and thus without having to watch the quanta assigned to the other flows go by unused this avoidance of idle time gives packet switching its efficiency 25 Schedule link on a per-packet basis once a flow begins sending data, we need some way to limit the transmission, so that the other flows can have a turn an upper bound on the size of the block of data (packet) is defined that each flow is permitted to transmit at a given time the source may need to fragment the message into several packets, with the receiver reassembling the packets back into the original message 26 each flow sends a sequence of packets over the physical link, with a decision made on a packet-bypacket basis as to which flow’s packet to send next if only one flow has data to send, then it can send a sequence of packets back-to-back should more than one of the flows have data to send, then their packets are interleaved on the link 27 Scheduling methods FIFO (First-In-First-Out) a fair scheduling method RR (Round-Robin) transmit the packets from each of the different flows that are currently sending data ensure that certain flows receive a particular share of the link bandwidth or that they never have their packets delayed in the switch for more than a certain length of time 28 QoS (Quality of Service) a network that attempts to allocate bandwidth to particular flows according service priorities 29 ■■■ Congested in the following figure, the switch has to multiplex three incoming packet streams onto one outgoing link it is possible that the switch will receive packets faster than the shared link can accommodate in this case, the switch is forced to buffer these packets in its memory should a switch receive packets faster than it can send them for an extended period of time, then the switch will eventually run out of buffer space, and some packets will have to be dropped 30 when a switch is operating in this state, it is said to be congested ■■■ A switch multiplexing packets from multiple sources onto one shared link 31 Inter-Process Communication Turn host-to-host connectivity into process-toprocess communication Fill gap between what applications expect and what the underlying technology provides Processes communicating over an abstract channel 32 Figure cloud: abstractly represent connectivity among a set of computers channel: connect one process to another view the network as providing logical channels over which application-level processes can communicate with each other, each channel provides the set of services required by that application 33 Types of Communication Channels Request/reply channel applications file transfer digital library delivery guarantee every message sent by one side is received by the other side and that only one copy of each message is delivered 34 privacy and integrity might protect the privacy and integrity of the data that flows over it unauthorized parties cannot read or modify the data being exchanged between the client and server processes 35 Message stream channel applications video-on-demand videoconferencing delivery might not need to guarantee that all messages are delivered, since a video application can operate adequately even if some video frames are not received 36 sequence need to ensure the messages are delivered arrive in the same order in which they were sent, to avoid displaying frames out of sequence privacy and integrity might want to ensure the privacy and integrity of the video data might need to support multicast, so that multiple parties can participate in the teleconference or view the video 37 What Goes Wrong in the Network? (Reliability) Bit-level errors a “1” is turned into a “0” or vice versa bit errors single bit is corrupted burst errors consecutive bits are corrupted causes (outside forces of electrical interference) lightning strikes, power surges, and microwave ovens, etc. interfere with the transmission of data 38 bit error rate one out of every 106 to 107 bits on a typical copperbased cable one out of every 1012 to 1014 bits on a typical optical fiber Packet-level errors (congestion) a complete packet is lost by the network the packet contains an uncorrectable bit error and therefore has to be discarded 39 causes one of the nodes that has to handle the packet, e.g., a switch that is forwarding it from one link to another, is so overloaded that it has no place to store the packet, and therefore is forced to drop it Node and link level failures a physical link is cut or the computer it is connected to crashes 40 causes software crashes, power failure, misconfiguration of a network device Others messages are delayed messages are deliver out-of-order third parties eavesdrop 41 1.3 Network Architecture Layering and protocols OSI architecture Internet architecture 42 Layering The services provided at the high layers implemented in terms of the services provided by the lower layers Abstraction defines a unifying model that can capture some important aspect of the system encapsulate this model in an object that provides an interface that can be manipulated by other components of the system hide the details of how the object is implemented from the users of the object 43 Use abstractions to hide complexity of the network from application writers Abstractions naturally lead to layering start with the services offered by the underlying hardware add a sequence of layers, each providing a higher (more abstract) level of service the services provided at the high layers are implemented in terms of the services provided by the low layers 44 Host-to-host connectivity attracts away the fact that there may be an arbitrarily complex network topology between any two hosts Example of a layer network system 45 Process-to-process channels builds on the available host-to-host communication service attracts away the fact that the network occasionally loses messages 46 One provides a request/reply service and one supports a message stream service at the same process-toprocess channel Layered system with alternative abstractions available at a given layer 47 Layering provides two nice features decomposes the problem of building a network into more manageable components may implement several layers, each of which solves one part of the problem provides a more modular design to add some new service, may only need to modify the functionality at one layer, reusing the functions provided at all the other layers 48 Protocols Protocol used to provide a communication service that higher-level objects (e.g. application processes, higher-level protocols) use to exchange messages e.g. request/reply protocol, message stream protocol building blocks of a network architecture 49 Each protocol object defines two different interfaces service interface defines a service interface to the other objects on the same computer that want to use its communication services defines the operations that local objects can perform on this protocol 50 examples a request/reply protocol would support operations by which an application can send and receive messages an implementation of the HTTP protocol could support an operation to fetch a page of hypertext from a remote server an application such as a web browser would invoke such an operation whenever the browser needs to obtain a new page 51 peer-to-peer interface defines a peer interface to its counterpart (peer) on another machine defines the form and meaning of messages exchanged between protocol peers 52 examples, in the case of HTTP, the protocol specification defines in detail how a "GET" command is formatted what arguments can be used with the command how a web server should respond when it receives such a command 53 summary: a protocol defines a communication service that it exports locally (the service interface) a set of rules governing the messages that the protocol exchanges with its peer(s) to implement this service (the peer interface) 54 Service and peer interfaces 55 Protocol Machinery Peer-to-peer is direct only at hardware level Most peer-to-peer communication is indirect each protocol communicates with its peer by passing messages to some lower-level protocol, which in turn delivers the message to its peer Protocol graph there are potentially multiple protocols at any given level, each providing a different communication service protocol graph represents the suite of protocols that make up a network system 56 Example of a protocol graph (nodes are the protocols, edges are “depends on” relations) Host 1 File application Digital library application Video application Host 2 File application Digital library application Video application 57 process-to-process channels RRP: Request Reply Protocol MSP: Message Stream Protocol host-to-host protocol (provides a host to host connectivity service) HHP: Host-to-Host Protocol 58 hardware level peers directly communicate with each other over a link the applications are said to employ the services of the protocol stack RRP/HHP or MSP/HHP 59 Encapsulation (header/body) Host Host Application Application program program Application Application program program Data Data RRP RRP RRP Data RRP HHP Data HHP HHP RRP Data High-level messages are encapsulated inside of low-level messages 60 Operation flow host1 application sends a message to its peer by passing the message to protocol RRP (uninterpreted) RRP communicates control info to its peer, instructing it how to handle the message when it is received attaches a “header” to the message 61 header a small data structure - from a few bytes to a few dozen bytes usually attached to the front of a message body (or payload) the rest of the message data application data is “encapsulated” in the new message created by protocol RRP 62 encapsulation high-level messages are encapsulated inside of lowlevel messages the process of encapsulation is repeated at each level of the protocol graph inspection & process nodes in the network (e.g., switches and routers) may inspect the HHP header at the front of the message 63 Multiplexing and Demultiplexing A fundamental idea of packet switching is to multiplex multiple flows of data over a single physical link The same idea applies up and down the protocol graph The header that RRP attaches to its messages contains an identifier that records the application to which the message belongs We call this identifier RRP’s demultiplexing key, or demux key 64 Source host at the source host, RRP includes the appropriate demux key in its header Destination host when the message is delivered to RRP on the destination host, it strips its header examines the demux key demultiplexes the message to the correct application 65 ISO Architecture ISO / OSI (International Standard Organization / Open Systems Interconnection) ISO the ISO, usually in conjunction with ITU (International Telecommunications Union), publishes a series of protocol specifications (X dot) based on the OSI architecture X dot series: X.25, X.400, X.500 66 OSI defines a partitioning of network functionality into seven layers not a protocol graph, but rather a reference model for a protocol graph 67 Description of OSI Layers 68 Layer 7: Application layer interfaces directly to and performs common application services for application processes issues requests to presentation layer 69 Layer 6: Presentation layer transforms data to provide a standard interface for the Application layer MIME encoding, data encryption and similar manipulation of the presentation are done at this layer to present data as a service or protocol that the developer sees fit MIME (Multipurpose Internet Mail Extensions,多用 途互聯網郵件擴展) 一個互聯網標準,它擴展了電子郵件標準,使其能支 源非ASCII字符、二進制格式附件等多種格式的郵件 消息 70 examples converts an EBCDIC-coded text file to an ASCII-coded file EBCDIC (Extended Binary Coded Decimal Interchange Code) a character encoding used to represent Unicode characters 為IBM於1963-1964年間推出的字元編碼表,根據早 期打孔機式的二進化十進數(BCD, Bindary Coded Decimal)排列而成 為IBM迷你級以上電腦的標準 71 serialize objects and other data structures into and out of XML serialization the process of saving an object onto a storage medium (such as a file, or a memory buffer) or to transmit it across a network connection link in binary form XML (eXtensible Markup Language) an extensible language that allows users to define their own tags 72 Layer 5: Session layer controls the dialogues / connections (sessions) between computers establishes, manages and terminates the connections between the local and remote application provides for either full-duplex or half-duplex operation establishes checkpoint, adjournment, termination, and restart procedures 73 Layer 4: Transport layer provides reliable data transfer services to the upper layers controls the reliability of a given link through flow control, segmentation/ desegmentation, and error control some protocols are state and connection oriented i.e. the transport layer can keep track of the segments and retransmit those that fail 74 the best known example: Transmission Control Protocol (TCP) the transport layer is the layer that converts messages into TCP segments or User Datagram Protocol (UDP), Stream Control Transmission Protocol (SCTP), etc. 75 Layer 3: Network layer provides the functional and procedural means of transferring variable length data sequences from a source to a destination via one or more networks while maintaining the quality of service requested by the Transport layer performs network routing functions, and might also perform fragmentation and reassembly, and report delivery errors 76 “routers” operate at this layer send data throughout the extended network and make the Internet possible there is a logical hierarchical addressing scheme the best known example: Internet Protocol (IP) 77 Layer 2: Data Link layer provides the functional and procedural means to transfer data between network entities and to detect and possibly correct errors that may occur in the Physical layer the best known example: Ethernet this layer manages the interaction of devices with a shared medium 78 other examples HDLC and ADCCP for point-to-point or packetswitched networks HDLC (High-Level Data Link Control) a bit-oriented synchronous data link layer protocol developed by ISO HDLC can be used for point to multipoint connections, but is now used almost exclusively to connect one device to another 79 ADCCP (Advanced Data Communication Control Procedures (or Protocol)) a bit-oriented data link layer protocol used to provide point-to-point and point-tomultipoint transmission of data frames that contain error control information 80 Aloha for local area networks Aloha a pioneering computer networking system developed at the University of Hawaii first deployed in 1970 one of the core concepts in the network is the basis for the widely used Ethernet the first version of the protocol was basic if you have data to send, send the data if the message collides with another transmission, try resending "later” 81 Slotted Aloha an improvement to the original Aloha protocol introduces discrete timeslots and increased the maximum throughput a station can send only at the beginning of a timeslot, and thus collisions are reduced 82 83 on IEEE 802 local area networks (LANs), and some non-IEEE 802 networks such as FDDI, this layer may be split into Media Access Control (MAC) layer and Logical Link Control (LLC) layer FDDI (Fiber Distributed Data Interface) provides a standard for data transmission in a LAN that can extend in range up to 200 kilometers (124 miles) 84 MAC a layer 2 sub-layer that provides addressing and channel access control mechanisms that makes it possible for several terminals or network nodes to communicate within a multipoint network, typically a LAN or MAN acts as an interface between the Logical Link Control (LLC) sub-layer and the network's physical layer 85 LLC a sub-layer primarily concerned with multiplexing protocols transmitted over the MAC layer (when transmitting) and demultiplexing them (when receiving) providing flow control and detection and retransmission of dropped packets, if requested the protocol used for LLC in IEEE 802 networks and in some non-IEEE 802 networks such as FDDI is specified by the IEEE 802.2 standard 86 arranges bits from the physical layer into logical chunks of data, known as frames “bridges” and “switches” operate at this layer connectivity is provided only among locally attached network nodes forming layer 2 domains for unicast or broadcast forwarding other protocols may be imposed on the data frames to create tunnels and logically separated layer 2 forwarding domain 87 Layer 1: Physical layer defines all the electrical and physical specifications for devices includes the layout of pins, voltages, and cable specifications 88 hubs, repeaters, network adapters and Host Bus Adapters (HBAs used in Storage Area Networks (SAN)) are physical-layer devices HBA connects a host system (the computer) to other network and storage devices SAN an architecture to attach remote computer storage devices (such as disk arrays, tape libraries and optical jukeboxes) to servers in such a way that, to the operating system, the devices appear as locally attached 89 major functions and services performed by the physical layer establishment and termination of a connection to a communications medium 90 switch hub, repeater, network adapter, HBA OSI Network Architecture 92 Operations physical layer handles the transmission of raw bits over a communications link data link layer collects a stream of bits into a larger aggregate called a frame network adaptors, along with device drivers running in the node’s OS, typically implement the data link level this means that, frames, not raw bits, are actually delivered to hosts 93 network layer handles routing among nodes within a packet-switched network at this layer, the unit of data exchanged among nodes is typically called a packet rather than a frame [note] the lower three layers are implemented on all network nodes, including switches within the network and hosts connected along the exterior of the network 94 transport layer implements a process-to-process channel the unit of data exchanged is commonly called a message rather than a packet or a frame the transport layer and higher layers typically run only on the end hosts and not on the intermediate switches or routers 95 session layer provides a name space that is used to tie together the potentially different transport streams that are part of a single application example it might manage an audio stream and a video stream that are being combined in a teleconferencing application 96 presentation layer concerned with the format of data exchanged between peers, for example, whether an integer is 16, 32, or 64 bits long whether the most significant byte is transmitted first or last how a video stream is formatted application layer protocols include things like the File Transfer Protocol (FTP), which defines a protocol by which file transfer applications can interoperate 97 Internet Architecture (TCP/IP Architecture) The Internet architecture evolved out of experiences with an earlier packet-switched network called the ARPANET Both Internet and ARPANET were funded by the Advanced Research Projects Agency (ARPA), one of the R&D funding agencies of the U.S. Department of Defense (DoD) Internet and ARPANET were around before the OSI architecture, and the experience gained from building them was a major influence on the OSI reference model 98 FTP HTTP NV TFTP UDP TCP IP Internet a four-layer model the lowest level NET1 NET2 ■■■ NETn a wide variety of network protocols: denoted NET1, NET2, and so on these protocols are implemented by a combination of hardware (e.g., a network adaptor) and software (e.g., network device driver) examples Ethernet or FDDI protocols 99 FTP HTTP NV TFTP UDP TCP IP the second layer NET 1 NET 2 ■■■ consists of a single protocol: Internet Protocol (IP) the protocol that supports the interconnection of multiple networking technologies into a single, logical internetwork the third layer contains two main protocols Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) TCP and UDP provide alternative logical channels to application programs 100 NET n TCP provides a reliable byte-stream channel UDP provides an unreliable datagram delivery channel (datagram may be thought of as a synonym for message) in the language of the Internet, TCP and UDP are sometimes called end-to-end protocols, although it is equally correct to refer to them as transport protocols FTP HTTP NV TFTP UDP TCP IP 101 NET1 NET 2 ■■■ NETn the top layer application protocols, such as FTP, TFTP (Trivial File Transport Protocol), Telnet (remote login), and SMTP (Simple Mail Transfer Protocol, or electronic mail), that enable the interoperation of popular applications FTP HTTP NV TFTP UDP TCP IP NET1 NET2 ■■■ NETn 102 the difference between an application layer protocol and an application all the available different World Wide Web browsers (Firefox, Safari, Internet Explorer, Lynx, etc) – application a similarly large number of different implementations of web servers – application we can use any one of these application programs to access a particular site on the Web is because they all conform to the same application layer protocol: HTTP (HyperText Transport Protocol) – application protocol confusingly, the same word sometimes applies to both an application and the application layer protocol that it uses (e g., FTP) 103 FTP HTTP NV TFTP UDP TCP IP NET 1 NET 2 ■■■ Internet protocol graph NET n Alternative view of Internet architecture 104 1.4 Implementing Network Software Application Programming Interface (Sockets) Protocol Implementation Issues 105 Application Programming Interface (Sockets) The place to start when implementing a network application is the interface exported by the network network Application Programming Interface (API) when we refer to the interface “exported by the network,” we are generally referring to the interface that the OS provides to its networking subsystem Socket interface originally provided by the Berkeley distribution of Unix now supported in virtually all popular operating systems 106 Protocol, API and implementation protocol provides a certain set of services API provides a syntax by which those services can be invoked in this particular OS implementation responsible for mapping the tangible set of operations and objects defined by the API onto the abstract set of services defined by the protocol 107 Socket the main abstraction of the socket interface the point where a local application process attaches to the network an interface between an application and the network an application creates the socket 108 Socket interface defines operations of creating a socket attaching a socket to the network sending/receiving messages through the socket closing the socket 109 Socket API (TCP) Create a socket int socket(int domain, int type, int protocol) domain specify the socket family that is going to be used examples PF_INET = Internet family PF_UNIX = UNIX pipe facility PF_PACKET = direct access to the network interface (i.e. bypass TCP/IP protocol stack) 110 type indicate the semantics of the communication examples SOCK_STREAM = a byte stream SOCK_DGRAM =a message-oriented service, e.g. UDP protocol identify the specific protocol that is going to be used example UNSPEC (Unspecified) 111 handle the return value from newly created socket an identifier by which we can refer to the socket in the future it is given as an argument to subsequent operations on this socket 112 Creating a Socket int sockfd = socket(address_family, type, protocol); The socket number returned is the socket descriptor for the newly created socket int sockfd = socket (PF_INET, SOCK_STREAM, 0); int sockfd = socket (PF_INET, SOCK_DGRAM, 0); The combination of PF_INET and SOCK_STREAM implies TCP Client-Serve Model with TCP Server passive open prepares to accept connection, does not actually establish a connection Server invokes int bind(int socket, struct sockaddr *addr, int addr_len) int listen(int socket, int backlog) int accept(int socket, struct sockaddr *addr, int addr_len) bind operation binds the newly created “socket” to the specified “address” (the server address) when used with Internet Protocols, “address” is a data structure that includes the IP address of the server a TCP port number used to indirectly identify a process usually some well-known number specific to the service being offered; e.g., web servers commonly accept connections on port 80 115 listen operation defines how many connections can be pending on the specified “socket” accept operation carries out the passive open it is a blocking operation that does not return until a remote participant has established a connection, when it does complete, it returns a new socket that corresponds to this new established connection 116 the “address” argument contains the remote participant’s address when accept returns, the original socket that was given as an argument still exists and still corresponds to the passive open; it is used in future invocations of accept 117 Client-Serve Model with TCP Client application performs active open it says who it wants to communicate with by invoking “connect” Client invokes int connect(int socket, struct sockaddr *addr, int addr_len) connect operation it does not return until TCP has successfully established a connection, at which time the application is free to begin sending data “address” contains the remote participant’s address 119 Client-Serve Model with TCP In practice the client usually specifies only remote participant’s address and let the system fill in the local information whereas a server usually listens for messages on a well-known port a client does not care which port it uses for itself, the OS simply selects an unused one Client-Serve Model with TCP Once a connection is established, the application process invokes the following two operations to send and receive data int send(int socket, char *msg, int mlen, int flags) int recv(int socket, char *buf, int blen, int flags) send operation it sends the given message over the specified socket receive operation it receives a message from the specified “socket” into the given “buffer” both “send” and “receive” take a set of “flags” that control certain details of the operation 122 Example Application: Client #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define SERVER_PORT 5432 #define MAX_LINE 256 int main(int argc, char * argv[]) { FILE *fp; struct hostent *hp; struct sockaddr_in sin; char *host; char buf[MAX_LINE]; int s; int len; if (argc==2) { host = argv[1]; } else { fprintf(stderr, "usage: simplex-talk host\n"); exit(1); } Example Application: Client /* translate host name into peer’s IP address */ hp = gethostbyname(host); if (!hp) { fprintf(stderr, "simplex-talk: unknown host: %s\n", host); exit(1); } /* build address data structure */ bzero((char *)&sin, sizeof(sin)); sin.sin_family = AF_INET; bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length); sin.sin_port = htons(SERVER_PORT); /* active open */ if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("simplex-talk: socket"); exit(1); } if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("simplex-talk: connect"); close(s); exit(1); } /* main loop: get and send lines of text */ while (fgets(buf, sizeof(buf), stdin)) { buf[MAX_LINE-1] = ’\0’; len = strlen(buf) + 1; send(s, buf, len, 0); } } Example Application: Server #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define SERVER_PORT 5432 #define MAX_PENDING 5 #define MAX_LINE 256 int main() { struct sockaddr_in sin; char buf[MAX_LINE]; int len; int s, new_s; /* build address data structure */ bzero((char *)&sin, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(SERVER_PORT); /* setup passive open */ if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("simplex-talk: socket"); exit(1); } Example Application: Server if ((bind(s, (struct sockaddr *)&sin, sizeof(sin))) < 0) { perror("simplex-talk: bind"); exit(1); } listen(s, MAX_PENDING); /* wait for connection, then receive and print text */ while(1) { if ((new_s = accept(s, (struct sockaddr *)&sin, &len)) < 0) { perror("simplex-talk: accept"); exit(1); } while (len = recv(new_s, buf, sizeof(buf), 0)) fputs(buf, stdout); close(new_s); } } 1.5 Performance Performance metrics Bandwidth versus latency Delay ╳ bandwidth product High-speed networks Application performance needs 127 Performance Metrics Network performance is measured in bandwidth (also called throughput) latency (also called delay) Bandwidth literally a measure of the width of a frequency band example a voice-grade telephone line supports a frequency band ranging from 300 to 3,300 Hz (Hz = the number of complete cycles per second) it is said to have a bandwidth of 3,300Hz - 300Hz = 3,000Hz 128 bandwidth the range of signals that can be accommodated measured in hertz bandwidth of a communication link the number of bits per second that can be transmitted over a link example the bandwidth of an Ethernet is 10 Mbps (10 million bits/second) 129 bandwidth is sometimes thought in terms of how long it takes to transmit each bit of data example on a 10-Mbps network, it takes 0.1 microsecond (μs) to transmit each bit 130 we can think of a second of time:a distance that we could measure bandwidth:how many bits fit in that distance each bit:a pulse of some width example each bit on a 1-Mbps link is 1 μs wide each bit on a 2-Mbps link is 0.5 μs wide 131 Bits transmitted at a particular bandwidth can be regarded as having some width: (a)bits transmitted at 1 Mbps (each bit 1 μs wide); (b)bits transmitted at 2 Mbps (each bit 0.5 μs wide) 132 Bandwidth requirements of an application the number of bits per second that it needs to transmit over the network to perform acceptably Throughput the measured performance of a system because of various inefficiencies of implementation, a pair of nodes connected by a link with a bandwidth of 10 Mbps might achieve a throughput of only 2Mbps 133 Latency (delay) corresponds to how long it takes a message to travel from one end of a network to the other (one-way) measured strictly in terms of time example a transcontinental network might have a latency of 24 milliseconds (ms) i.e., it takes a message 24 ms to travel from one end of North America to the other 134 Latency = Propagation delay + Transmit delay + Queuing delay Propagation delay = Distance / SpeedOfLight light travels across different mediums at different speeds, examples 3.0 × 108 m/s in a vacuum 2.3 × 108 m/s in a cable 2.0 × 108 m/s in a fiber Transmit delay = Packet size / Bandwidth Queuing delay = the time the packet switches takes to store packets for some time before forwarding them on an outbound link 135 Round-trip time (RTT) how long it takes to send a message from one end of a network to the other and back 136 Bandwidth versus Latency Relative importance (depends on applications) latency dominates bandwidth (latency bound) example: a client sends a 1-byte message to a server and receives a 1-byte message in return (latency bound) the application will perform much differently on a transcontinental channel with a 100-ms RTT than it will on an across-the-room channel with a 1-ms RTT whether the channel is 1 Mbps or 100 Mbps is relatively insignificant, however, since the former implies that the time to transmit a byte (Transmit) is 8 μs and the latter implies Transmit = 0.08 μs 137 bandwidth dominates latency (bandwidth bound) example: a digital library program that is being asked to fetch a 25MB image suppose that the channel has a bandwidth of 10 Mbps it will take 20 seconds to transmit the image, making it relatively unimportant if the image is on the other side of a 1-ms channel or a 100-ms channel the difference between a 20.001-second response time and a 20.1-second response time is negligible 138 Summary for large file transfer, bandwidth is critical for small messages (HTTP, NFS, etc.), latency is critical 139 The following graph shows how long it takes to move objects of various sizes (1 byte, 2KB, 1MB) across networks with RTTs ranging from 1 to 100 ms link speeds of either 1.5 or 10 Mbps 140 p. 48 of 5th ed. pp. 43-44 of 4th ed. 141 142 Delay ╳ Bandwidth Product Channel between a pair of processes as a hollow pipe Latency (delay) the length of the pipe Bandwidth the diameter of the pipe Delay × bandwidth the volume of the pipe i.e. the maximum number of bits that could be in transit through the pipe at any given instant 143 Example a transcontinental channel with a one-way latency of 50ms and a bandwidth of 45Mbps can hold 280KB (= 2.25 × 106 bits) of data 144 Sample Delay ╳ Bandwidth Products Link type Bandwidth (Typical) (Distance (Typical) Round-trip Delay Delay x BW Dial-up 56Kbps 10km 87μs 5bits Wireless LAN 54Mbps 50m 0.33μs 18bits Satellite 45Mbps 35,000 km 230ms 10MB Crosscountry fiber 10Gbps 4,000km 40ms 400MB 145 High-Speed Networks Example transmit a 1-MB file over a 1-Mbps network vs. over a 1-Gbps network, both of which have an RTT of 100 ms (“high speed” does not mean that latency improves at the same time as bandwidth) 1-Mbps network delay × bandwidth = 0.1Mb it takes 80 [= (1/0.1)*8] RTTs to transmit the file during each RTT, 1.25% of the file is sent 1-Gbps network delay × bandwidth = 12.5 [= 0.1 * (1000/8)] MB it takes < 1 [= (1/12.5)*8] RTT to transmit the file 146 Relationship between bandwidth and latency. A 1-MB file would fill the 1-Mbps link 80 times, but only fill the 1-Gbps link 1/12 of one time. *More data can be transmitted during each RTT on a high-speed network 147 Effective End-to-End Throughput Throughput = TransferSize / TransferTime TransferTime = RTT + (1/Bandwidth) x TransferSize TransferTime = one-way latency plus any additional time spent requesting or setting up the transfer RTT = a request message being sent across the network and the data being sent back in a high-speed network (infinite bandwidth), RTT dominates TransferTime 148 Example a user wants to fetch a 1-MB file across a 1-Gbps with a round-trip time of 100ms TransferTime = 100-ms (RTT) + transmit time for 1MB (1/1Gbps × 1MB = 8ms) = 108ms effective throughput = 1MB/108ms = 74.1Mbps (not 1Gbps) 149 Discussions transferring a larger amount of data will help improve the effective throughput where in the limit, an infinitely large transfer size will cause the effective throughput to approach the network bandwidth 150 Application Performance Needs Some applications are able to state an upper limit on how much bandwidth they need example suppose one wants to stream a video image; that is one-quarter the size of a standard TV image; i.e., it has a resolution of 352 by 240 pixels if each pixel is represented by 24 bits of information (24-bit color), then the size of each frame would be (352 × 240 × 24)/8 = 247.5 KB 151 if the application needs to support a frame rate of 30 frames per second, then it might request a throughput rate of 75 Mbps because the difference between any two adjacent frames in a video stream is often small, it is possible to compress the video by transmitting only the differences between adjacent frames 152 this compressed video does not flow at a constant rate, but varies with time according to factors such as the amount of action detail in the picture the compression algorithm it is possible to say what the average bandwidth requirement will be, but the instantaneous rate may be more or less 153 Jitter the variation in latency example the source sends a packet once every 33 ms, as would be the case for a video application transmitting frames 30 times a second if the packets arrive at the destination spaced out exactly 33 ms apart, then the delay experienced by each packet in the network was exactly the same 154 if the spacing between when packets arrive at the destination (interpacket gap) is variable, however, then the delay experienced by the sequence of packets must have also been variable, and the network is said to have introduced jitter into the packet stream such variation is generally not introduced in a single physical link, but it can happen when packets experience different queuing delays in a multihop packet-switched network 155 this queuing delay corresponds to the Queue component of latency, which varies with time Network-induced jitter 156 Relevance of jitter suppose that the packets being transmitted over the network contain video frames, and in order to display these frames on the screen the receiver needs to receive a new one every 33 ms if a frame arrives early, then it can simply be saved by the receiver until it is time to display it if a frame arrives late, then the receiver will not have the frame it needs in time to update the screen, and the video quality will suffer; it will not be smooth 157 if the receiver knows the upper and lower bounds on the latency that a packet can experience, it can delay the time at which it starts playing back the video (i.e., displays the first frame) long enough to ensure that in the future it will always have a frame to display when it needs it the receiver delays the frame, effectively smoothing out the jitter, by storing it in a buffer 158