Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

28
Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse
  • date post

    15-Jan-2016
  • Category

    Documents

  • view

    216
  • download

    0

Transcript of Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Page 1: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Computer Science 686

SPECIAL TOPIC: Programming Gigabit Ethernet

Spring 2008Professor Allan Cruse

Page 2: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Some important prerequisites

• You are a computer science grad student

• You are acquainted with x86 architecture

• You can execute Linux/UNIX commands

• You know how to use a text-editing tool

• You can write programs in the C language

• You can print out a program’s source-file

Page 3: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Instructor Contact Information

• Office: Harney Science Center – 212

• Hours: Mon-Wed-Fri 1:30pm-2:20pm

Tues-Thurs 6:15pm-7:15pm

• Phone: (415) 422-6562

• Email: [email protected]

• Webpage: http://cs.usfca.edu/~cruse/

Page 4: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

The class website

• URL: http://cs.usfca.edu/~cruse/cs686/– General description of the course– Links to some useful online resources– Lecture-slides and demo-programs– System software for use with this course– Class announcements (e.g., exam dates)– A link to our CS686 discussion-list– Our schedule of textbook readings

Page 5: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Recommended texts

Mark Norris,Gigabit Ethernet Technology and Applications

Artech House (2002), ISBN 1-580-53504-4

Corbet, Rubini, and Kroah-Hartman,Linux Device Drivers (3rd Ed),

O’Reilly (2005), ISBN 0-596-00590-3

Page 6: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Course’s continuing theme is…

“Using the computer to study the computer”

Page 7: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Normal C/C++ programming

applicationWe would write most of this source-code “app.cpp”

but we would call some library-functions e.g., open(), read(), write(), malloc(), …

then our code would get ‘linked’ with standard runtime libraries written usually by other programmers and ‘shared’ among many applications

(So this is an example of “code reuse”)

standard“runtime”libraries

call

ret

Page 8: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Normal C/C++ programming

application

standard“runtime”libraries

call

ret

user space kernel space

Operating Systemkernel

syscall

sysret

Many standard library functions perform services that require executing privileged instructions (which only the kernel can do)

Page 9: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Linux Kernel Modules

application

standard“runtime”libraries

call

ret

user space kernel space

Operating Systemkernel

syscall

sysret

module

Linux allows us to write our own installable kernel modulesand add them to a running system

callret

Page 10: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Requirements/Benefits

• An LKM has to be written using “C” -- but can include “inline” assembly language

• An LKM runs in kernel-space – so it can do anything that the CPU supports

• Therefore, an LKM can –– directly control any peripheral devices– modify the kernel’s scheduling algorithms– examine the kernel’s hidden data-structures

Page 11: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Network Interface Controllers

• One of the most interesting peripherals in every modern PC is its Network Interface Controller (NIC), allowing communication among computers (and other equipment)

Page 12: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Thanks, Intel!☻

• Intel Corporation has kindly posted details online for programming its family of gigabit Ethernet controllers – our course’s focus

Page 13: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Thanks, Linus! ☻

• Linus Torvalds initiated the collaboration among programmers that has resulted in our free “open source” operating system

• The Linux OS continues to evolve – new version is posted almost every week, at:

http://www.kernel.org

• For example, late last August we started our semester with version 2.6.22.1 – then, by mid-December version 2.6.22.15 had been released

Page 14: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Thanks, Richard! ☻

• Richard Stallman (who spoke at USF last semester) established the Free Software Foundation, which produces the systems software (e.g., editors, compilers, linkers, libraries, debuggers) that will allow us to write Linux application-programs – and Loadable Kernel Modules – that explore the capabilities of Intel’s 82573L NIC

• Website: http://www.fsf.org

Page 15: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Thanks, Alex! ☻

• Alex Fedosov (USF ’01) is SysAdmin for our department’s ‘anchor’ server-cluster

• We can connect to those servers from our classroom’s workstations or the CS Labs

• They have Intel’s gigabit Ethernet NICs

• Alex has connected them via a switched hub, thereby creating a private Local Area Network for doing course-experiments

Page 16: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Thanks, Alfred! ☻

• Alfred Chuang (USF, ’82) is a founder of BEA Systems, Inc. (located in San Jose)

• As a computer science undergraduate at USF, he was inspired by his teacher and Faculty Advisor, Dr. Michael D. Kudlick

• To express his gratitude in a way that would benefit future USF students, Alfred made the generous gift of this classroom

Page 17: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Course acknowledgements

Paul Otellini Linus Torvalds Richard Stallman Alex Fedosov Alfred Chuang

Intel NICdocuments

Linuxoperating system

GNU software tools

‘anchor’ clusterservers

Interactive learningclassroom

This ‘special topics’ course would not be possible without these contributions

Page 18: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Why use a private LAN?

• For our class exercises and experiments we’ll be able to use the CS department’s ‘anchor’ cluster (which currently consists of 8 server stations, but soon will be 16)

• These stations have Intel’s 82573L NIC and they all connect to a ‘switched hub’

• We can control the network-traffic volume and not worry about causing others trouble

Page 19: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Our ‘anchor’ servers

anchor00

D-Link Gigabit Switched Hub

anchor01

anchor02

anchor03

anchor07

anchor06

anchor05

anchor04

computer science department’s student network (138.202.171.0)

Page 20: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Demo program: ‘netsniff.cpp’

• This privileged application can monitor a Linux station’s network-traffic, showing all the data-packets that are being processed by between the station’s network interface

• We can demonstrate this tool on stations in our classroom or on the ‘anchor’ cluster

• It will give you a chance to see how those ‘anchor’ machines can be accessed

Page 21: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Berkeley ‘sockets’ API

• The BSD sockets application programming interface provides a standardized library of functions for writing network programs in C

• These functions make it straightforward to create programs following a ‘client/server’ programming paradigm

‘server’program

‘client’program

request

reply

Page 22: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Simple ‘echo’ server

• A former USF grad student presented a very simple example in his M.S. Thesis, based on the User Datagram Protocol

• We’ve adapted his UNIX code for Linux:– ‘udpserver.cpp’– ‘udpclient.cpp’

• We can run this demo in our classroom, but it’s also instructive to run it on ‘anchor’

Page 23: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

A few socket-API functions

// create a new socket (i.e., an endpoint for network communication)int socket( int domain, int type, int protocol );

// bind an ‘address’ to a socketint bind( int sockfd, struct sockaddr *addr, socklen_t alen );

// receive a datagram from a client-processint recvfrom( int sock, char *buf, int len, int flags,

struct sockaddr *from, socklen_t *fromlen );

// transmit a datagram to another processint sendto( int sock, const char *msg, size_t msglen, int flags,

struct sockaddr *to, socklen_t tolen );

Page 24: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Our course’s context

• This course is NOT about writing network application programs – but instead about programming ethernet interface hardware

• Nevertheless, we believe it is helpful for understanding why we consider various system programming issues if we know what uses will be made by application-programs of our hardware’s capabilities

Page 25: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

For some exercises…

• We will need to use a few standard UNIX tools for performing our experiments:– The ‘ping’ command is useful for testing if a

pair of network-stations can communicate– The ‘ifconfig’ program will allow us to assign

an internet-address to a specific interface, so that standard network programs can be used

– The ‘sudo’ command will allow classmembers to execute certain ‘privileged’ system tools

Page 26: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Classroom’s stations

# Kudlick classroom hosts138.202.171.61 hrn23501.usfca.edu hrn23501138.202.171.62 hrn23502.usfca.edu hrn23502 … 138.202.171.90 hrn23530.usfca.edu hrn23530

# Fifth-Floor CS-Lab hosts138.202.171.21 hrn53501.usfca.edu hrn53501 …138.202.171.32 hrn53512.usfca,edu hrn53512

# ‘anchor’ server-cluster hosts138.202.171.200 anchor00.usfca.edu anchor00 …138.202.171.207 anchor07.usfca.edu anchor07

Page 27: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

Kudlick Classroom

08 09 10 15 16 17 18 19 20 28 29 30

04 05 06 07 11 12 13 14 24 25 26 27

01 02 03 21 22 23

lectern

Page 28: Computer Science 686 SPECIAL TOPIC: Programming Gigabit Ethernet Spring 2008 Professor Allan Cruse.

In-class exercises

• Use ‘ping’ to check that you can reach at least three other stations:– Another station in our Kudlick classroom– One of the stations in the 5th-Floor CS Lab– One of the stations on our ‘anchor’ cluster

• Try using our ‘netsniff.cpp’ application to capture some network-packets (by using I/O-redirection): $ netsniff > netsniff.out