ppt - Pacific University

Download Report

Transcript ppt - Pacific University

CS360 Special Topics:
Computer Networking
Chadd Williams
Office Hours:
Mon 11:00 - Noon
Tues 3:00 – 4:00 PM
Fri
10:00 – Noon
and by appointment
[email protected]
202 Strain
http://zeus.cs.pacificu.edu/chadd/cs360s07/
CS 360 – Spring 2007
Pacific University
Syllabus
http://zeus.cs.pacificu.edu/chadd/cs360s07/syllabus.html
• Computer Networks, Andrew S. Tanenbaum (4th edition)
– I may assign problems out of this book
– I will expect you to read the book
Grades:
• Homework/Quizzes: 10%
• 2 Midterms: 20% each
• 1 Final 20% (Comprehensive)
• Programming Projects 30%
Dates:
• Midterm 1, Tues Mar 8
• Midterm 2, Tues Apr 17
• Final, Mon May 14 (3:00 – 5:30 PM)
Policies:
• Assignments are due at the beginning of class. Late assignments will not be
accepted.
• The cheating policy is defined in the Catalog but read the syllabus!
• Silence all electronic devices
• Class starts promptly at 1pm!
CS 360 – Spring 2007
Pacific University
Programming Projects
• 30% of the final grade
• Fairly intense programming problems
– Network programming is always
tricky – things happen
asynchronously!
– Start the day the project is assigned
Project 1
20 pts
Project 2
15 pts
Project 3
20 pts
Project 4
25 pts
Project 5
20 pts
Total
100 pts
• You’ll be using lots of new libraries and tools
– I’ll expect you to look at the man pages to learn the
details of the socket library
– Projects (through Project 4) build on code written for
earlier projects
• Project 5: Routing project with donated CISCO hardware!
• All assignments are individual projects
CS 360 – Spring 2007
Pacific University
Programming Projects
• You must program on Linux
– I will not accept Visual Studio projects
• Eclipse
– Integrated Development Environment
• 3.2.1
• subclient plugin
• CDT plugin
– may use gcc from the command line
• Subversion
– source code control
– you are required to use this
• Machines to use
–
–
–
–
–
zeus: Linux: Intel ♦
ada: Linux: Intel
lab machines: Linux: Intel
circe: OpenBSD: SPARC ♦
g3ubuntu: Linux: PowerPC
CS 360 – Spring 2007
Pacific University
Coding on Linux/Unix
• Wednesday, 8 – 10 pm in Strain 222
– Linux programming basics with Doug and Chadd
– if you cannot make this, let me know ASAP
– one class later in the semester will be cancelled
• submit script
– allows you to submit your project electronically
• I still need a hardcopy!
– You can do this exactly once for each assignment!
– must be run from zeus
zeus$ ~chadd/submit cs360s07 filename.tar.gz
CS 360 – Spring 2007
Pacific University
Overview
• How do we send data from here to there on the Internet?
– we will talk about non-Internet networks (Bluetooth)
• Internetworking
– implement the protocol
– join the network
• Computer Networks are complex things
–
–
–
–
–
we will use a model of the network to guide us through
Open Systems Interconnection Basic Reference Model
TCP/IP reference model
breaks down the functionality of the network into layers
from Mozilla Firefox to radio waves in the air
• How to write networking code
– network socket libraries
CS 360 – Spring 2007
Pacific University
It’s a joke, laugh.
• Will I learn to set up my wireless router in my house?
NO
I don’t know, read the owner’s manual
• Will I learn how my wireless router assigns my laptop an
IP address?
YES
this is a well defined standard that all routers use
But, it’s funny because it’s true.
CS 360 – Spring 2007
Pacific University
Terms
• Read Chapter 1 (1.1 – 1.5)
– 1.4 is especially important
– describes models of the network
– 1.6 is interesting and we may return to it later
• Network Application: a piece of software that interacts
with the network
• Network Protocol: “an agreement between the
communicating parties on how communication is to
proceed” – Tanenbaum, pg 27
– very strict, to the bit, description of how to do things
Hello?
CS 360 – Spring 2007
Pacific University
Terms
• Protocol Stack: all the protocols an application
uses, in order of abstraction
– ~1 per layer of the model
• Packet: (small) chunk of data sent across the
network
CS 360 – Spring 2007
Pacific University
Network Models (quick preview)
Computer Networks, 4th edition, Tanenbaum, page 43.
CS 360 – Spring 2007
Pacific University
Applications and Protocols
• Network Applications (protocol)
–
High level
protocols
• Lower level protocols:
– IEEE 802.11[a|b|g] is a wireless networking standard
• differences in letters are speed and security
• what does a 1 and 0 look like?
– TCP (Reliable transport)
– IP (Internet protocol)
– Bluetooth (wireless keyboard/mice)
CS 360 – Spring 2007
Pacific University
Protocols
• Open/standardized protocols allow anyone to
write code that uses the protocol
– all web- servers/browsers understand HTTP
– anyone can write a web browser!
– two independently developed network applications
can communicate
• Protocols specify a by the bit communication
scheme
– packet layout
– error checking
CS 360 – Spring 2007
Pacific University
Proprietary protocols
• Proprietary protocols are not released to the
public
– OSCAR (AOL IM) is not actually an open protocol
– however it has been reverse engineered
• therefore, other chat clients can implement it
– AOL used to change the protocol very often to frustrate the efforts
of those trying to build an AIM chat client
– Microsoft never fully disclosed the protocol for MSN Messenger
– Why would a company do this?
CS 360 – Spring 2007
Pacific University
Example HTTP
• The client (web browser) can send a set of predefined,
specifically formatted requests to the server (web server)
GET
Requests a piece of data (html file, jpeg) be
sent to the client
HEAD
Same as above, but the file is not transferred,
just the header information
POST
Send data to the server, as in a web form
• The server (web server) responds with a status code and
possibly some data
404 Not Found
The data was not found
500 Server Error Web server error
200 OK
Success! Data to follow
CS 360 – Spring 2007
Pacific University
Example: HTTP
• The HTTP protocol defines a way to request data across
the network
• client (web browser) http://zeus.cs.pacificu.edu/index.html
GET /index.html HTTP/1.1
Host: zeus.cs.pacificu.edu
• server (web server)
HTTP/1.1 200 OK
Date: Tue, 16 Jan 2007 19:58:22 GMT
Server: Apache-AdvancedExtranetServer/2.0.53 (Mandriva·Linux/PREF
Last-Modified: Mon, 05 Sep 2005 23:13:58 GMT
ETag: "4f8-9a2-4000e774e3980"
Accept-Ranges: bytes
Content-Length: 2466
Connection: close
Content-Type: text/html
<html> ….
Website that allows you to view the HTTP traffic for your request: http://web-sniffer.net/
CS 360 – Spring 2007
Pacific University
Network Models (1.4)
Computer Networks, 4th edition, Tanenbaum, page 43.
CS 360 – Spring 2007
Pacific University
Why layers?
• Each layer performs a different function
– called service primitives
– upper layers rely on the lower layers working
• Layering allows information hiding
– remember this from OO programming?
– upper layers don’t care how the lower layers operate
• Lower layers can change and the upper layers
won’t notice (waves hands quickly)
– wired Ethernet, 802.11 wireless, carrier pigeon (RFC
1149)
CS 360 – Spring 2007
Pacific University
Application
• User level code
• Standardize data exchanges
• High level protocols
– HTTP
– FTP
– DHCP
• Where the actual real, end-user important data gets
transferred
– everything else is really just supporting code
CS 360 – Spring 2007
Pacific University
Presentation
• Syntax and semantics of data
• Translate data representations between machines
– big or little endian
– which character encoding?
– which image encoding?
• Often not used (not in the TCP/IP model)
– this is usually left to the Application level
CS 360 – Spring 2007
Pacific University
Session
• Share/combine data from two independent connections
between machines
• Dialog control
– whose turn is it to transmit
• Token management
– who has the mutex?
• Synchronization
– check point long transmissions so the can restart
• Often not used (not in the TCP/IP model)
• Canonical example: Multimedia
– make sure the audio and video streams match up
CS 360 – Spring 2007
Pacific University
Transport
• Key interface: where the application accesses the net
– end to end principle: put all the smarts above the network layer
• Transmission Control Protocol (the TCP in TCP/IP)
– reliable transport
• track acknowledgement of data and retransmit as necessary
– breaks data into packets
• reassemble packets at destination in order
– flow control: don’t swamp the receiver
– connection based
• User Datagram Protocol (UDP)
– unreliable, connectionless
– fire and forget: maybe it gets there, maybe not
CS 360 – Spring 2007
Pacific University
Network
• Routing data around the network
– congestion control
– allow heterogeneous networks to interact (internetworking)
• negotiate packet size
• negotiate addressing
– Internet Protocol (the IP in TCP/IP)
• uses packets, stateless/connectionless (dumb), unreliable
– best effort delivery
– though the IP header is error free
• Internet layer in the TCP/IP reference model
• QoS: area of recent research!
– delay/transit time/jitter
– Other examples: IPX, ICMP
CS 360 – Spring 2007
Pacific University
Data link
• Take data from physical layer and pass it up to the
network layer
– uses data frames
• chunks of data of a 100-1000s of bytes
– may provide reliable service
• acknowledge data frames and request retransmissions of missing
data frames
– provides some error checking
• don’t pass data up that is full of static from the line
– Flow control (rate control)
• prevent the sender from overwhelming the receiver
• how big is your buffer?
– Regulate access to a shared medium (not always necessary)
• Ethernet is one shared bus (or tube!)
• collisions cause each sender to back off exponentially
• medium access control sub-layer
CS 360 – Spring 2007
Pacific University
Physical
• Transmitting raw bits over the wire
–
–
–
–
–
real computer engineering stuff
mechanical, electrical and timing issues
what does the wire look like?
how many strands of copper?
how many volts at how long for a 1? 0?
• We will not deal too much with this layer
CS 360 – Spring 2007
Pacific University
Circuit vs Packet switched
• What’s a packet?
– a chunk of data sent across the network
• Circuit switched
– like the (old) telephone network
– build, and maintain, a complete circuit to transmit data on
– dedicate resources throughout the network to a connection
• “All lines are busy, please call again later”
– easy to guarantee QoS
• Packet switched
–
–
–
–
each packet is routed independently from end to end
no overhead
no wasted resources
hard to guarantee QoS
• one packet may run into a bottle neck
– Canonical example: Snail mail!
CS 360 – Spring 2007
Pacific University
Internet Addresses
• IPv4 addresses: 64.59.233.197
– each number is 0-255 (why?)
– more specific left to right
64.59.233.197:8012
• Connection between machines
– IP address and socket number
64.59.233.197:80
– socket: numbered interfaces to a single machine
• allows a machine to be connected to multiple machines
– 0 – 65535 (why?)
– 0 - 1023 are reserved for well known services
– Servers listen on a specific port then create a new socket to
continue communication
• 80: webserver
• 25: smtp
• 22: ssh
64.59.233.200:2030
– 127.0.0.1 is always the localhost
CS 360 – Spring 2007
Pacific University
Socket Libraries (Unix/Linux)
#include <sys/types.h> // data types
#include <sys/socket.h> // socket interface
#include <netinet/in.h> // Internet interface
• The socket is the common Unix interface to the network
– a socket represents an end point for network communication
– Berkeley Software Distribution socket API
• 4.2 BSD Unix
• most OSes now provide a BSD socket interface for networking
– Microsoft Windows almost provides it
• defacto standard
– a socket is represented by an int
CS 360 – Spring 2007
Pacific University
API Usage: Call Sequences
• UDP over IP (connectionless):
socket()
bind()
recvfrom()
close()
socket()
sendto()
close()
server
client
• TCP over IP (connection-based):
socket()
bind()
listen()
accept()
recv()/send()
close()
socket()
connect()
send()/recv()
close()
server
client
CS 360 – Spring 2007
Pacific University
Socket library functions
• UDP over IP
– domain (protocol family): PF_INET
– type: SOCK_DGRAM
– protocol: 0 (IP)
• see /etc/protocols for a list
– address family: AF_INET
int socket(int domain, int type, int protocol)
int bind(int sockfd, const struct sockaddr *my_addr,
socklen_t addrlen)
– actually use struct sockaddr_in for IP networking
CS 360 – Spring 2007
Pacific University
Socket library functions
ssize_t recvfrom(int sockfd, void *buf, size_t len,
int flags, struct sockaddr *from, socklen_t
*fromlen)
– again, use struct sockaddr_in for IP connections
• this struct is filled with address information specifying the source of the data
• this can be used to send a message back to the source.
– flags tells the function how to behave
• OR together zero or more options:
• MSG_WAITALL – wait until the full request is satisfied
• MSG_PEEK – retrieve data but don’t remove it from the receive queue
– subsequent calls to recvfrom return the same data
sendto() is the complement of recvfrom
– man sendto
close(int sockfd)
– just like closing a file
CS 360 – Spring 2007
Pacific University
Network Byte Order
• Intel machines use little-endian encoding
– 32-bit int: 0x01000000 is what?
• PowerPCs (Macs), SPARC (Sun), use big-endian
encoding
– 32-bit int: 0x00000001 is what?
• On the network, everything is transferred as big-endian
– says the protocol
• API to help us:
– htonl – transform 32 bits from host- to network- byte order
• on Intel this goes from little to big endian
• on SPARC this has no effect
– htons
– ntohl/ntohs – transform 16 bits
• Bit fields
int version:4;
int priority:8;
CS 360 – Spring 2007
Pacific University
Programming Assignment
• DUE Feb 13, 2007, 1 pm
– electronic copy
• submit script
– paper copy
• use the color printer for source code only
• UDP over IP
– client and server
– calculation server: perform simple math tasks
• The packet format is specified
– size of data is specified in bits
– this size may be different than the native data type
• Test on big- and little-endian machines
– I have a reference implementation server running on
• 64.59.233.204:9999 (circe.cs.pacificu.edu, big endian)
• 64.59.233.197:9999 (zeus.cs.pacificu.edu, little endian)
CS 360 – Spring 2007
Pacific University
Programming Assignment
• Server:
./server 9891
• Client
./client 127.0.0.1 9891 a 4 5
Result: 9
• Extra Credit
– accept either a DNS name or IP address at the command line
– ./client zeus.cs.pacificu.edu 9891 a 4 5
– hint: man inet_addr
• Be prepared to demo your code in class!
CS 360 – Spring 2007
Pacific University