CS 336/621 Computer Networks and Network Programming
-
Upload
bruno-bishop -
Category
Documents
-
view
35 -
download
1
description
Transcript of CS 336/621 Computer Networks and Network Programming
![Page 1: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/1.jpg)
CS 336/621Computer Networks and
Network Programming
Spring 2009
Professor Allan B. Cruse
University of San Francisco
![Page 2: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/2.jpg)
Course synopsis
• Combines a survey of network principles with hands-on exercises and experiments
• Utilizes our classroom and CS laboratory networking hardware infrastructures
• Employs C/C++ programming language and the standard ‘sockets’ API libraries
![Page 3: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/3.jpg)
Course prerequisites
• Open to USF Computer Science students
• Upper-division or graduate-level standing
• Familiarity with Linux (or UNIX) systems
• Programming experience: C/C++/Python
• Prior coursework: CS 110/112 and CS 245 (or the equivalent preparation elsewhere)
![Page 4: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/4.jpg)
methodology
• Lectures
• Readings
• Discussions
• Demonstrations
• Exercises
• Projects
• Quizzes
![Page 5: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/5.jpg)
Course website
• You will find current course-information at this website:
<http://cs.usfca.edu/~cruse/cs336>
• Reading-assignments, exam-dates, class announcements, course-related software, links to other resources and to the ‘signup’ page for our class’s online discussion-list
![Page 6: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/6.jpg)
Textbook
• James F. Kurose and Keith W. Ross • Computer Networking: A Top-Down Approach • 4th Edition• Pearson/Addison-Wesley (2008)
This up-to-date textbook is very widely used in networking courses at colleges and universities in the United States and elsewhere.Lots of material – maybe too much for one semester – the authors recommend we cover at least the first five chapters in sequence, then maybe one of the concluding chapters if time allows for that.
![Page 7: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/7.jpg)
Reference Model
link layer
network layer
transport layer
application layer
The textbook authors have utilized the standard reference model for network-software’s layered architecture as a principle which guides their “Top-Down Approach” to organizing the Chapters
Chapter 2
Chapter 3
Chapter 4
Chapter 5
introduction Chapter 1
![Page 8: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/8.jpg)
Network hardware elements
• NIC (Network Interface Controller)• Cable (e.g., coaxial, fiber optic, twisted pair)• Repeater (boosts signal-strength on long cables)• Hub (promiscuously connects nearby NICs)• Switch (selectively connects nearby NICs)• Bridge (connects multiple network segments)• Router (intelligently forwards network packets)
![Page 9: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/9.jpg)
Network Interface Card (NIC)
![Page 10: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/10.jpg)
Before the internet there was…… sneaker-net!
host
host
Users often would transfer their data from one computer to another by simply copying it onto a floppy diskette, and then carrying that diskette over to their other computer – located, hopefully, not too far away (e.g., just down the hall)
![Page 11: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/11.jpg)
‘crossover’ cable
host
host
An improvement over the ‘sneaker net’ approach to data sharing between two host computers that are a short distance apart is to utilize a special direct cable connection – inexpensive to purchase, easy to connect if NICs are installed, less physical effort is required, no floppy disks are needed, and no risk of any unwanted ‘virus’ software infecting the host machines
NIC
NIC
cable
![Page 12: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/12.jpg)
A ‘Point-to-Point’ connection
host host
repeater
Over a long-distance cable-connection the electrical signals can degrade, but ‘repeaters’ can be inserted to receive and amplify a weakened signal before sending it along (i.e., “repeating it”) to the next connection-point
![Page 13: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/13.jpg)
‘Local’ networks
host
host
host
hosthost
‘ring’ topology
host
host
host
host
HUB
‘star’ topology
Why do you think the star-topology is more widely deployed nowadays?
![Page 14: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/14.jpg)
‘Hub’ versus ‘Switch’
host host host host host host host host
Why are ‘switches’ preferred over ‘hubs’ nowadays?
![Page 15: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/15.jpg)
The ‘Bridge’ device
host
hosthost
switch
host
hosthost
switch
bridge
![Page 16: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/16.jpg)
The ‘Router’ device
host
hosthost
switch
host
hosthost
switch
host
hosthost
switch
router
![Page 17: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/17.jpg)
Network software elements
operating system kernel
networkapplication
program
functionlibrary
NIC
device driver
‘socket’data-structure
User-space Kernel-space
File and I/Osubsystems
(‘protocol stack’)
cable
![Page 18: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/18.jpg)
Demo: iplookup.py
• This application reports the IP- address for a particular network host (if it’s known)
• For example:$ python iplookup.py stargate
The IP-address for ‘stargate’ is 138.202.171.14
$ python iplookup.py pyramid
The IP-address for ‘pyramid’ is 138.202.171.19
$ python iplookup.py neptune
The IP-address for ‘neptune’ is unknown
![Page 19: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/19.jpg)
Source-code (in Python)
#!/usr/bin/python
import systry:
hostname = sys.argv[1]except:
hostname = “localhost”
import sockettry:
hostip = socket.gethostbyname( hostname )except:
hostip = “unknown”
print “The IP-address for \’” + hostname + “\’ is “ + hostip
![Page 20: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/20.jpg)
Demo: getquote.py
• This internet application reports the latest price for a share of Intel Corporation stock
• For example:$ python getquote.py
Intel Stock: $13.53 at “12:05pm” on “1/26/2009”
![Page 21: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/21.jpg)
Internet programming
import socket
try:host = “download.finance.yahoo.com”port = 80sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )sock.settimeout( 2 )sock.connect( ( host, port) )sock.send( “GET /d/quotes.csv?s=INTC&f=sl1d1t1c1ohgv&e=.csv \r\n” )sock.send( “\r\n” );response_string, server = sock.recvfrom( 4096 )quote = str.split( response_string, ‘,’ )
except socket.error, msg:print “An error occurred:”, msg
else:printprint “Intel Stock: “, ‘$’+quote[1], “at”, quote[3], “on”, quote[2]print
![Page 22: CS 336/621 Computer Networks and Network Programming](https://reader036.fdocuments.us/reader036/viewer/2022062321/56812b20550346895d8f1e16/html5/thumbnails/22.jpg)
In-class exercise #1
• Can you modify the ‘getquote.py’ program so that it will report the latest stock-price for some other famous technology firms?– Microsoft Corporation– Red Hat Corporation– Oracle Corporation– Siemens Corporation– Sony Corporation