operating systems - networks
DESCRIPTION
From the Operating Systems course (CMPSCI 377) at UMass Amherst, Fall 2007.TRANSCRIPT
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Operating SystemsCMPSCI 377NetworksEmery Berger
University of Massachusetts Amherst
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 2
Networks
Goal: Efficient, correct, robust message passing between two separate nodes
Local area network (LAN) – nodes in single building, fast & reliable (Ethernet) Media: twisted-pair, coax, fiber Bandwidth: 10-1,000MB/s
Wide area network (WAN) – nodes across large geographic area (Internet) Media: fiber, microwave links, satellite channels Bandwidth: 1.544MB/s (T1), 45 MB/s (T3)
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 3
Principles of Net Communication
Data broken into packets (~ 1Kb) Basic unit of transfer
Computers & routers control packet flow
Road analogy: Packets = cars Network = roads Computer = traffic lights (intersection) Too many packets on shared link/node =
traffic jam
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 4
Communication Protocols
Protocol: agreed-upon rules for communication
Protocol stack: layers that comprise networking software
Each layer N provides service to layer N+1
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 5
Traditional Layers
Application layer – applications that use the net
Presentation layer – data format conversion(big/little endian)
Session layer – implements communication strategy(e.g., RPC)
Transport layer – reliable end-to-end communication
Network layer – routing & congestion control
Data link control layer – reliable point-to-point communication over unreliable channel
Physical layer – electrical/optical signaling across “wire”
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 6
TCP/IP Protocol Stack
Internet standard protocol stack TCP: reliable protocol – packets received in order
UDP (user datagram protocol) – unreliable
No guarantee of delivery
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 7
Packet Format
All info needed to recreate original message
Packets may arrive out of order need sequence
number
Data segment contains headersfor higher protocol layers & application data
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Sockets
Standard API for network programming
Duplex communication (2-way)
Can configure sockets to use UDP or TCP
UDP – best for lossy communication
Pings, video, audio, other multimedia
Sends datagrams (packets)
TCP – most stuff
Sends reliable stream of bytes
8
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Socket communication
Sockets (in TCP) send stream of bytes
Multiple sends may be combinedinto one received message
To send multiple application-level messages, must have application level protocol
E.g., 4-bytes = message type, 4-bytes = message length, plus message
9
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Client-side: using sockets
Creates socket
int fd = socket (AF_INET, SOCK_STREAM, 0)
Converts hostname to IP address with getaddrinfo
getaddrinfo (name, portStr, NULL, portNum)
Connects to host
connect (fd, addr, len); // from getaddrinfo
Once connected, can send or recv
send (fd, data, amount, 0);
recv (fd, buf, len, 0);
10
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Server-side: using sockets
As before:
Create socket as before
Convert hostname to IP address with getaddrinfobut in passive mode hint.ai_flags = AI_PASSIVE
getaddrinfo (name, portStr, &hint, &addrinfo)
Binds socket to address: bind (fd, addr, len); // from getaddrinfo
Listens for connection: listen (fd, 1); // number of waiting msgs
Accepts connection ) new socket
int newfd = accept (fd, addr, len);
11
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Exercise
Lamest web server ever
Wait for connections on localhost port 80
Read message until first newline (‘\n’)
Send <html><body>Hello world</body></html>
Use:
int fd = socket (AF_INET, SOCK_STREAM, 0)
getaddrinfo (name, portStr, &hint, &addrinfo)
bind (fd, addr, addrlen)
int v = listen (fd, 1)
int newfd = accept (fd, addr, len)12
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 13
Network Topologies
Connection of nodes impacts:
Maximum & average communication time
Fault tolerance
Expense
Two basic topologies:
Bus (for LANs)
Point-to-point
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 14
Bus Network Topologies
Bus nodes connect to common network
Linear bus – single shared link Nodes connect directly to each other via bus
Inexpensive (linear in # of nodes)
Tolerant of node failures
Ethernet LAN
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 15
Bus Network Topologies
Ring bus – single shared circular link
Same technology & tradeoffs as linear bus
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 16
Point-to-Point Network Topologies
Fully-connected
Each message takes one “hop”
Node failure – no effect on communication with others
Expensive – impractical for WANs
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 17
Point-to-Point Network Topologies
Fully-connected
Each message takes one “hop”
Node failure – no effect on communication with others
Expensive – impractical for WANs
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 18
Point-to-Point Network Topologies
Fully-connected
Each message takes one “hop”
Node failure – no effect on communication with others
Expensive – impractical for WANs
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 19
Point-to-Point Network Topologies
Fully-connected
Each message takes one “hop”
Node failure – no effect on communication with others
Expensive – impractical for WANs
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 20
Point-to-Point Network Topologies
Partially connected Links between some, but not all nodes Less expensive, less tolerant to failures
Single node failure can partition network
Several hops – requires routing
2
3
4
1
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 21
Point-to-Point Network Topologies
Partially connected Links between some, but not all nodes Less expensive, less tolerant to failures
Single node failure can partition network
Several hops – requires routing
2
3
4
1
I want to goto Node 4!
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 22
Point-to-Point Network Topologies
Partially connected Links between some, but not all nodes Less expensive, less tolerant to failures
Single node failure can partition network
Several hops – requires routing
2
3
4
1
I want to goto Node 4!
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 23
Point-to-Point Network Topologies
Tree structure: network hierarchy Messages fast between direct descendants
Max message cost?
Not failure tolerant Any interior node fails – network partitioned
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 24
Point-to-Point Network Topologies
Star network: all nodes connect to central node
Each message takes how many hops?
Not failure tolerant
Inexpensive – sometimes used for LANs
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 25
Point-to-Point Network Topologies
One-directional ring Given n nodes, max hops?
Inexpensive
Fault-tolerant?
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 26
Point-to-Point Network Topologies
Bi-directional ring Given n nodes, max hops?
Inexpensive
Fault-tolerant? One node? Two?
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 27
Point-to-Point Network Topologies
Doubly-connected ring: nodes connected to neighbors & one more distant Given n nodes, max hops?
Fault-tolerant?
More expensive
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 28
The End
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 29
Distributed Systems
Distributed system: physically separate processors connected by one or more communication links no shared clock or memory
Most systems today distributed in some way e-mail, file servers, network printers, remote
backup, web...
P2P1
P3P4
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 30
Parallel vs. Distributed Systems
Tightly coupled systems: “parallel processing”
Processors share clock, memory, run one OS
Frequent communication
Loosely coupled systems: “distributed computing”
Each processor has own memory, runs independent OS
Infrequent communication
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 31
Advantages of Distributed Systems
Resource sharing
Computational speedup
Reliability
Communication
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 32
Advantages of Distributed Systems
Resource sharing
Resources need not be replicated
Shared files
Expensive (scarce) resources can be shared
Poster-size color laser printers
Processors present same environment to user
Keeping files on file server
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 33
Advantages, continued
Computational speedup n processors = n times computational power
SETI@home
Problems must be decomposable into subproblems Trivial = embarrassingly parallel
Coordination & communication required between cooperating processes Synchronization
Exchange of results
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 34
Advantages, continued
Reliability
Replication of resources provides fault tolerance
One node crashes, user works on another one
Performance degradation but system available
Must avoid single point of failure
Single, centralized component of system
Example: central file servers
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 35
Advantages, continued
Communication
Users/processes on different systems can communicate
Mail, transaction processing systems like airlines & banks, www