cnt5505 data/comuter communications spring 2012

50
Computer Science, FSU 1 CNT5505 DATA/COMUTER COMMUNICATIONS Spring 2012

Upload: zulema

Post on 22-Jan-2016

17 views

Category:

Documents


0 download

DESCRIPTION

CNT5505 DATA/COMUTER COMMUNICATIONS Spring 2012. About myself. Zhenghao Zhang Office: Love 164; Phone: 644-1685 Email: [email protected] URL: http://www.cs.fsu.edu/~zzhang Research area: Wireless networks Network security Peer to peer networks Optical networks. Office Hours. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 1

CNT5505DATA/COMUTER COMMUNICATIONS

Spring 2012

Page 2: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 2

About myselfZhenghao ZhangOffice: Love 164; Phone: 644-1685Email: [email protected]: http://www.cs.fsu.edu/~zzhang

Research area: • Wireless networks • Network security• Peer to peer networks• Optical networks

Page 3: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 3

Office Hours

• Love 164

• 3:30pM – 5:30PM, Thursday, or by appointments through email

Page 4: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 4

What is CNT5505 about?• General purpose computer networks

– Not specialized networks (e.g., telephone or cable)

• Fundamental principles– Not survey of existing protocol standards

• Focus on network software architecture– Only discuss some relevant network

hardware

• Designing and building network systems

Page 5: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 5

Course Prerequisites• A rudimentary understanding of computer

architecture, and operating systems would be helpful

• Basic understanding of algorithm analysis• C/C++ or Java programming is required

– Socket programming– Unix programming

• Event multiplexing, timer• Provided executable code and template of project in C/C++

– You can develop the project in Java• Basic probability theory may be needed to

understand some performance analysis

Page 6: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 6

Course Materials• Required textbook

– “Computer Networks,'' by Andrew S. Tanenbaum, Prentice Hall, 5th edition

• Class notes, other assigned readings • Materials on the Internet

Page 7: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 7

Class Information

• Class website– http://www.cs.fsu.edu/~zzhang/CNT5505_Spring_2012.htm

– Go to my website and click teaching

• Check the Announcements and your email account regularly

Page 8: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 8

Course Requirements

• Do assigned readings– Be prepared; read textbook/lectures before class

• Attend and participate in class activities– Please ask and answer questions in (and out of) class– Attendance will be considered in the final letter grade

• Workload– Homework assignments.– Projects.– One midterm– One final

Page 9: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 9

Policies and Guidelines• Homework and Assignments usually have two due times.

– Please work early and make the first due time.– 10% penalty for submission by the second due time.– Zero if later than the second due time.

• No make-up exam, no incomplete– unless proof of emergency

• Scholastic behaviors– Follow the Academic Honor Code.– Acknowledge reference/credits if receive help.– You may end up “F” for dishonesty. It is not worth it.

Page 10: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 10

Important dates

• Check the course website• For homework assignments

– Hand in hard-copy in class on due dates– Preferably typed instead of handwritten

• For course project– Submit by email– Midnight on the due dates– Demo time will be announced later

Page 11: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Course Project

• There will be several projects.• Not coding intensive

Computer Science, FSU 11

Page 12: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 12

Questions and Concerns?

Page 13: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 13

Computer Communication: A motivation example

• What happens behind the scene when I type http://www.google.com in the address bar of my iPhone?

Page 14: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 14

Step 1: on local host

• Browser figures out what to do with the URL: http://www.google.com/– Three components in URL

• Where: www.google.com• What: (retrieving file index.html)• How: through HTTP protocol

– Talk to http daemon on www.google.com to get file index.html through HTTP protocol

Page 15: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 15

Step 2: translating domain name to IP address

• Each machine on the Internet identified by one or more IP address

• Browser translating domain name (www.google.com) to corresponding IP address using domain name service (DNS)

Page 16: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 16

Step 2: Getting IP address (Cont’d)

• Browser calls UDP protocol entity to send a message to 128.186.120.179/53 (assuming that is our DNS server)

• The UDP message to the DNS server is “What is the IP address of www.google.com?”

• The DNS server sends a message back: 64.233.161.99– Actually situation is complicated than this– www.google.com is associated with

multiple IP addresses

Page 17: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Step 2: Getting IP address (Cont’d)

• How can my iPhone talk to the DNS server?

• It will have to first talk to the Access Point (AP) by sending frames.

• What is a frame?

Computer Science, FSU 17

Page 18: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Step 2: Getting IP address (Cont’d)

• The frame is the wireless signal sent by the Wi-Fi interface of my iPhone that carries bits.

• The wireless signal is the oscillating wave.

• The frame encapsulates the IP packet.

Computer Science, FSU 18

Page 19: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Step 2: Getting IP address (Cont’d)

• What if another iPhone also wants to talk to the same AP?

• What if someone just walks by and blocks my line-of-sight path to the AP?

Computer Science, FSU 19

Page 20: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Step 2: Getting IP address (Cont’d)

• The AP relays the IP packet from my iPhone to the DNS server, assuming they are in the same Ethernet LAN.

• Note that the AP is not relaying the Wi-Fi frame.

• The AP may have to use the ARP protocol to find the Ethernet address of the DNS server, then encapsulates the IP packet in an Ethernet frame.

Computer Science, FSU 20

Page 21: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 21

Step 3: establishing HTTP connection

• Calls TCP entity to set up a connection to 64.233.161.99 /80

• TCP protocol calls IP to send a datagram to 64.233.161.99

Page 22: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Step 3: establishing HTTP connection (Cont’d)

• Turns out that www.google.com is far away.

• Need to forward to the first-hop router (128.186.120.1)find the Ethernet address of first-hop

router using arpforward packet to first-hop router

• (second router, third router) …... • www.google.com receives a packet.

Computer Science, FSU 22

Page 23: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Step 3: establishing HTTP connection (Cont’d)

• There are many options (paths) to reach the destination.

• How to choose the best path?• How to maintain the path

information?

Computer Science, FSU 23

Page 24: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 24

Step 4: Web page request and retrieval

• Use TCP to send requests– TCP entity calls IP to send a datagram– …..– www.google.com responses with the

content of index.html

Page 25: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Step 4: Web page request and retrieval (Cont’d)

• The webpage may contain lots of data (images, videos).

• We will receive a bunch of IP packets.• What if some of the IP packets are

dropped by the routers? – We will be missing some parts in a picture

• How can the google server figure out how fast to send the data?

Computer Science, FSU 25

Page 26: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 26

Step 5: web page rendering

• Browser displays the content of the web page

Page 27: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Socket Programming

Page 28: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 28

Interprocess Communication

• Within a single system– Pipes, FIFOs– Message Queues– Semaphores, Shared Memory

• Across different systems– BSD Sockets– Transport Layer Interface (TLI)

• Reference– Unix Network Programming by Richard

Stevens

Page 29: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 29

BSD Socket API

• Introduced in 1981 BSD 4.1 UNIX• Sockets is just a convenient interface

for the processes on different hosts to communicate.

• Just like if you want to write to the hard disk, you can operate the hard disk directly, but it is much more convenient to open a file and write to the file using the interface provided by the system.

Page 30: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Socket

• A 5-tuple associated with a socket– {protocol, local IP address, local port,

remote IP address, remote port}

• Complete socket is like a file descriptor– Both send() and recv() through same socket

Page 31: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 31

Sockets: Conceptual View

Page 32: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 32

Connection-Oriented Application

1. Server gets ready to service clients– Creates a socket– Binds an address (IP interface, port number)

to the socket• Server’s address should be made known to clients

2. Client contacts the server– Creates a socket– Connects to the server

• Client has to supply the address of the server when using connect()

3. Accepts connection requests from clients4. Further communication is specific to

application

Page 33: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 33

Creating a socket

int socket(int family, int service, int protocol)• family: symbolic name for protocol family

– AF_INET, AF_UNIX

• type: symbolic name for type of service– SOCK_STREAM, SOCK_DGRAM, SOCK_RAW

• protocol: further info in case of raw sockets– typically set to 0

Returns socket descriptor

Page 34: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 34

Binding Socket with an Address

int bind(int sd, struct sockaddr *addr, int len)• sd: socket descriptor returned by socket()• addr: pointer to sockaddr structure

containing address to be bound to socket• len: length of address structure

Returns 0 if success, -1 otherwise

Page 35: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 35

Specifying Socket Address

struct sockaddr_in {short sin_family; /* set to AF_INET */u_short sin_port; /* 16 bit port number */struct in_addr sin_addr; /* 32 bit host address */char sin_zero[8]; /* not used */

};

struct in_addr {u_long s_addr; /* 32 bit host address */

};

Page 36: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 36

Bind Example

int sd;struct sockaddr_in ma;sd = socket(AF_INET, SOCK_STREAM, 0);

ma.sin_family = AF_INET;ma.sin_port = htons(5100);ma.sin_addr.s_addr = htonl(INADDR_ANY);if (bind(sd, (struct sockaddr *) &ma, sizeof(ma)) != -1)

Page 37: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 37

Connecting to Server

int connect(int sd, struct sockaddr *addr, int len)

• sd: socket descriptor returned by socket()• addr: pointer to sockaddr structure

containing server’s address (IP address and port)

• len: length of address structure

Returns 0 if success, -1 otherwise

Page 38: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 38

Connect Example

int sd;struct sockaddr_in sa;sd = socket(AF_INET, SOCK_STREAM, 0);

sa.sin_family = AF_INET;sa.sin_port = htons(5100);sa.sin_addr.s_addr = inet_addr(“128.101.34.78”);if (connect(sd, (struct sockaddr *) &sa, sizeof(sa)) != -1)

Page 39: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 39

Connection Acceptance by Server

int accept(int sd, struct sockaddr *from, int *len)

• sd: socket descriptor returned by socket()• from: pointer to sockaddr structure which

gets filled with client’s address• len: length of address structure

Blocks until connection requested or error• returns a new socket descriptor on success

Page 40: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 40

Connection-oriented Serverint sd, cd, calen;struct sockaddr_in ma, ca;

sd = socket(AF_INET, SOCK_STREAM, 0);ma.sin_family = AF_INET;ma.sin_port = htons(5100);ma.sin_addr.s_addr = htonl(INADDR_ANY);bind(sd, (struct sockaddr *) &ma, sizeof(ma));

listen(sd, 5);calen = sizeof(ca);cd = accept(sd, (struct sockaddr *) &ca, &calen);…read and write to client treating cd as file descriptor…

Page 41: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 41

More on Socket Descriptor• socket() fills the protocol component• local IP address/port can be filled by

bind()• remote IP address/port by accept()

in case of server• in case of client both local and

remote by connect()• accept() returns a new complete socket

– Original one can be used to accept more connections

Page 42: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 42

Streams and Datagrams

• Connection-oriented reliable byte stream– SOCK_STREAM based on TCP– No message boundaries– Multiple write() may be consumed by one

read()

• Connectionless unreliable datagram– SOCK_DGRAM based on UDP– Message boundaries are preserved– Each sendto() corresponds to one recvfrom()

Page 43: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 43

Input/Output Multiplexing

• Polling– Nonblocking option using fcntl()/ioctl()– Waste of computer resources

• Asynchronous I/O– Generates a signal on an input/output event– Expensive to catch signals

• Wait for multiple events simultaneously– Using select() system call– Process sleeps till an event happens

Page 44: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 44

Select System Call

int select(int maxfdp1, fd_set *readfds,fd_set *writefds, fd_set *exceptfds,struct timeval *timeout)

• maxfdp1: largest numbered file descriptor + 1

• readfds: check if ready for reading• writefds: check if ready for writing• exceptfds: check for exceptional conditions• timeout: specifies how long to wait for events

Page 45: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 45

Timeout in Select

• Wait indefinitely till there is an event– Pass NULL to the timeout argument

• Don’t wait beyond a fixed amount of time– Pass pointer to a timeval structure specifying

the number of seconds and microseconds.

• Just poll without blocking– Pass pointer to a timeval structure specifying

the number of seconds and microseconds as 0

Page 46: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 46

Working with File Descriptor Set

• Set is represented by a bit mask– Keep a descriptor in/out the set, turn on/off

corresponding bit• Using FD_ZERO, FD_SET and FD_CLR• Use FD_ISSET to check for membership

• Example:– Make descriptors 1 and 4 members of the readset

fd_set readset;FD_ZERO(&readset);FD_SET(1, &readset);FD_SET(4, &readset);

– Check if 4 is a member of readset• FD_ISSET(4, &readset);

Page 47: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 47

Return Values from Select

• Arguments readfds etc are value-result• Pass set of descriptors you are interested

in• Select modifies the descriptor set

– Keeps the bit on if an event on the descriptor– Turns the bit off if no event on the descriptor

• On return, test the descriptor set– Using FD_ISSET

Page 48: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 48

Select Examplefd_set readset;FD_ZERO(&readset);FD_SET(0, &readset);FD_SET(4, &readset);select(5, &readset, NULL, NULL, NULL);if (FD_ISSET(0, &readset) {

/* something to be read from 0 */}if (FD_ISSET(4, &readset) {

/* something to be read from 4 */}

Page 49: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

Computer Science, FSU 49

Servers and Services

• Mapping between names and addresses (DNS)– Host name to address: gethostbyname()– Host address to name: gethostbyaddr()

Page 50: CNT5505 DATA/COMUTER COMMUNICATIONS  Spring 2012

send() and recv()

• Once the sockets have been set up, the bytes can be sent and receive using send() and recv().– send():

• ssize_t send(int socket, const void *buffer, size_t length, int flags);

• Returns the number of bytes sent. -1 if error.• To send, fill the buffer to length, and call send().

– recv(): • ssize_t recv(int socket, void *buffer, size_t length, int flags);• Returns the number of bytes received. If returns 0, means

the connection is down. -1 if error.• When the socket fd is set, call recv(), and check the return

value and buffer.