CS360 Special Topics: Computer Networking

33
CS 360 – Spring 2007 Pacific University CS360 Special Topics: Computer Networking Chadd Williams Office Hours: [email protected] Mon 11:00 - Noon 202 Strain Tues 3:00 – 4:00 PM Fri 10:00 – Noon and by appointment http://zeus.cs.pacificu.edu/chadd/cs360s07/

description

CS360 Special Topics: Computer Networking. Chadd Williams Office Hours:[email protected] Mon 11:00 - Noon 202 Strain Tues  3:00 – 4:00 PM Fri  10:00 – Noon and by appointment http://zeus.cs.pacificu.edu/chadd/cs360s07/. - PowerPoint PPT Presentation

Transcript of CS360 Special Topics: Computer Networking

Page 1: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

CS360 Special Topics:Computer Networking

Chadd Williams

Office Hours: [email protected] 11:00 - Noon 202 StrainTues  3:00 – 4:00 PM Fri  10:00 – Noon and by appointment

http://zeus.cs.pacificu.edu/chadd/cs360s07/

Page 2: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

Syllabushttp://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!

Page 3: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 4: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 5: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 6: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 7: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

It’s a joke, laugh.• Will I learn to set up my wireless router in my house?

• Will I learn how my wireless router assigns my laptop an IP address?

But, it’s funny because it’s true.

NO

YES

I don’t know, read the owner’s manual

this is a well defined standard that all routers use

Page 8: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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?

Page 9: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 10: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

Network Models (quick preview)

Computer Networks, 4th edition, Tanenbaum, page 43.

Page 11: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

Applications and Protocols• Network Applications (protocol)

• 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)

High levelprotocols

Page 12: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 13: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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?

Page 14: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

Example HTTP• The client (web browser) can send a set of predefined,

specifically formatted requests to the server (web server)

• The server (web server) responds with a status code and possibly some data

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

404 Not Found The data was not found

500 Server Error Web server error

200 OK Success! Data to follow

Page 15: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

• server (web server)

GET /index.html HTTP/1.1Host: zeus.cs.pacificu.edu

HTTP/1.1 200 OKDate: Tue, 16 Jan 2007 19:58:22 GMTServer: Apache-AdvancedExtranetServer/2.0.53 (Mandriva·Linux/PREFLast-Modified: Mon, 05 Sep 2005 23:13:58 GMTETag: "4f8-9a2-4000e774e3980"Accept-Ranges: bytesContent-Length: 2466Connection: closeContent-Type: text/html <html> ….

Website that allows you to view the HTTP traffic for your request: http://web-sniffer.net/

Page 16: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

Network Models (1.4)

Computer Networks, 4th edition, Tanenbaum, page 43.

Page 17: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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)

Page 18: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 19: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 20: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 21: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 22: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 23: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 24: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 25: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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!

Page 26: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

Internet Addresses• IPv4 addresses: 64.59.233.197

– each number is 0-255 (why?)– more specific left to right

• Connection between machines– IP address and socket number– 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

– 127.0.0.1 is always the localhost

64.59.233.197:80

64.59.233.200:2030

64.59.233.197:8012

Page 27: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 28: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

API Usage: Call Sequences• UDP over IP (connectionless):

• TCP over IP (connection-based):

socket()bind()recvfrom()close()

server

socket()sendto()close()

client

socket()bind()listen()accept()recv()/send()close()

server

socket()connect()send()/recv()close()

client

Page 29: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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

Page 30: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific University

Socket library functionsssize_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

Page 31: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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 fieldsint version:4;int priority:8;

Page 32: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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)

Page 33: CS360 Special Topics: Computer Networking

CS 360 – Spring 2007Pacific 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!