Download Network Programming with Sockets - CS 61 and more Summaries Network Technologies and TCP/IP in PDF only on Docsity!
Network Programming with
Sockets
CS61, Lecture 23
Prof. Stephen Chong
November 22, 2011
Stephen Chong, Harvard University
Announcements
• No class Thursday; Happy Thanksgiving
• Final Thursday Dec 1
• Practice exams posted on iSites
• Section next week will cover the 2010 practice exam
2
Stephen Chong, Harvard University
Clients and servers
Client
process
Server
process
- Client sends request
- Client 3. Server sends response handles response
- Server handles request
Resource
• Most network applications are 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
- Server and client communicate by some predefined protocol
- Server activated by request from client (vending machine analogy) 4
Stephen Chong, Harvard University
Clients and servers
Client
process
Server
process
- Client sends request
- Server handles request
- Client 3. Server sends response handles response
Resource
- E.g.,
- Web server
- Protocol used: HTTP
- Shared resource: Web pages, databases, Rick Astley video, etc.
- Email server
- Protocols used: SMTP, POP, IMAP
- Shared resource: Mailboxes
- Chat server
- Protocols used: AIM, MSN, Jabber
- Shared resource: Relay point for chat messages between clients 5
Stephen Chong, Harvard University How do a client and server communicate?
- If the client and server are on different machines, they communicate over a network
- A network is a hierarchical system of boxes and wires organized by geographical proximity - SAN (System Area Network) spans cluster or machine room - Switched Ethernet, Quadrics QSW, … - 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
- The Global IP Internet (uppercase “I”) is the most famous example of an internet (lowercase “i”) 7
network adapter
network
disk controller graphics adapter USB controller
mouse keyboard monitor
disk
I/O bus
Stephen Chong, Harvard University (^8)
Using the network
main
memory
North
bridge
bus interface
ALU
register file
CPU chip
system bus memory bus
South
bridge
Stephen Chong, Harvard University (^10)
Circuit Switching Networks
• There are two basic types of networks:
• Circuit switching :
- Network creates a dedicated circuit between two parties
- Like the old phone system.
Stephen Chong, Harvard University (^11)
Packet Switching Networks
• Packet switching :
- Each computer sends data in the form of (usually short) packets
- Packets are routed through the network to their destination.
- To send a long message, or a stream, use a bunch of packets
Stephen Chong, Harvard University (^13)
What does a packet look like?
• High level view:
• Header contains routing information (source,
destination, etc.)
• Payload contains application data
• Footer contains additional information
• e.g., CRC of the packet contents for error detection
Header Payload Footer
Stephen Chong, Harvard University (^14)
What does a packet look like?
• Protocol layering and encapsulation
- Multiple protocol layers may operate on a packet.
- Example: An HTTP request is carried inside a TCP packet, which is contained inside an IP packet, which is contained within an Ethernet packet.
- This is called packet encapsulation.
• Note that not all protocols use footers.
- TCP and IP don't use them.
- Shown in the figure just for illustration. Header PayloadPayload Footer Ethernet header Ethernet footer Payload
IP
header IP footer
HTTP
request
TCP
header TCP footer
Stephen Chong, Harvard University (^16)
What does a packet look like?
Header PayloadPayload Footer Ethernet header Ethernet footer Payload
IP
header IP footer
HTTP
request
TCP
header TCP footer Version Header len Type of service
Total length
Flags Frag offset
TTL Protocol
ID
Header checksum
Source IP address Destination IP address Options
Stephen Chong, Harvard University (^17)
Looking at packets
• Several tools allow
you to inspect the
contents of network
packets.
• Two most popular
are tcpdump
and Wireshark.
Stephen Chong, Harvard University (^19)
CSMA/CD
- CSMA/CD: Carrier sense multiple access with collision detection
- Carrier sense : One node can “listen” to see if another node is speaking
- Collision detection : Hardware can tell if two nodes stomp on each other
- What does a node do to transmit a message?
- First, listen for another transmission
- If channel is clear, go ahead and transmit
- Transmitter can tell whether its message collided with another
- In the event of a collision:
- On the first collision, wait for 0 or 1 “time slots” before retransmitting
- Time slot is twice the maximum round-trip message delay (51.2 μsec on 10Mbps)
- If there is another collision, wait for 0, 1, 2, or 3 time slots before retransmitting
- After N collisions, wait for between 0 ... 2 N - 1 time slots
- This is called^ exponential backoff
- Eventually give up and report error back to the network card driver!
- These days, Ethernet cables are not shared across multiple machines
- Collisions are a serious problem at high data rates
- If shared Ethernet cable is broken or gets too long, serious problems arise
- Rather, each cable runs to an Ethernet hub or **switch
- Ethernet hub:**
- Acts as a “virtual shared cable”
- Multiple end hosts connect to the hub
- Each message received by hub retransmitted to all hosts
- Inexpensive simple circuitry, but collisions still a problem
- Ethernet switch:
- Only sends messages to the particular port that they are destined for
- Needs to know which MAC (Media Access Control) address(es) are connected to each port (can be configured or learned) Stephen Chong, Harvard University (^20)
Switched Ethernet