advanced unix programming fall 2002, lecture 16 instructor: ashok srinivasan acknowledgements: the...

14
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan

Upload: charles-tyler

Post on 21-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

Advanced UNIX programming

Fall 2002, lecture 16

Instructor: Ashok Srinivasan

Acknowledgements: The syllabus and power point presentations are modified versions of those by T. Baker and X. Yuan

Page 2: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

Announcements

• Reading assignment– Chapters 1 and 2 of Unix Network

programming– Chapters 3 and 4

• No quiz Oct 7

Page 3: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

Week 6 Topics

• Introduction to UNIX network programming– Introduction– Overview of TCP/IP

Page 4: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• Application layer (telnet, ssh, http, ftp, etc)– Things that we use daily

• Transport layer (TCP, UDP)– Allows processes (on different machines) to

communicate (reliably or unreliably) with each other

• Network layer (IPv4, IPv6)– Handles routing, fragmentation, and internetworking

• Host to Network layer (Ethernet)– Communication between two machines that are

directly connected

Introduction

Page 5: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• The entities that implement each layer can be processes, system calls, hardware, etc

• Protocol– Rules that govern how peer entities in the same

layer (on different machines) communicate

• Each layer provides services to the upper layer defined by the service interface– Example: TCP service interface is defined by a set

of system calls• socket, bind, listen, accept, connect, read and write

Introduction ... continued

Page 6: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• Some TCP/IP protocols:– TCP: transmission control protocol

• Connection-oriented, reliable, full duplex, byte stream service

– UDP: User datagram protocol• Connectionless, unreliable

– IPv4: Internet Protocol, version 4. • The protocol that glues the Internet together.• Provides (unreliable) packet delivery service for TCP,

UDP, ICMP, IGMP

– IPv6: Internet Protocol, version 6.• 128 bits address, newer version of Internet Protocol

Overview of TCP/IP

Page 7: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• Some TCP/IP protocols ... continued– ICMP: Internet Control Message Protocol

• Handles errors and control information for IP (ping, traceroute)

– IGMP: Internet Group Management Protocol

• Used in IP multicast

• Socket Programming– The use of TCP and UDP

• Can also access the lower layers directly (raw socket)

Overview of TCP/IP ... continued

Page 8: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• Interface• socket, bind, sendto, recvfrom• Can also use the TCP interface (connect, read,

write)

• Unreliable, connectionless service– Data may be lost, duplicated, or reordered– Client and server do not have any long

term relation

• Can perform (unreliable) multicast

UDP: User Datagram Protocol

Page 9: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• Interface– socket, bind, listen, accept, connect, read, write,

close

• An analogySocket: telephoneBind: assign telephone number to a telephoneListen: turn on the ringer so that you can hear the

phone callConnect: dial a phone numberAccept: answer the phoneRead and write: listening and talkingClose:

TCP: Transmission control protocol

Page 10: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• Implementing reliable communication may require– Sequence number, acknowledgement,

retransmission, timeout (RTT)– Sliding window protocol for efficiency– Flow control– Connection establishment and release

Reliable communication

Page 11: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• TCP connection establishment– Three way handshake– Figure 2.2

• TCP connection termination– Four way handshake

• Can release the connection reliably• Practical solution: make the client wait for a

while

– Figure 2.3

TCP connection establishment and termination

Page 12: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

(Figure 2.4 from text)

TCP state transition Diagram

Page 13: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• See Figure 2.5 from text

Packet exchange for TCP connection

Page 14: Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified

• Need both– Source IP address and port– Destination IP address and port

Identifying a TCP connection