Top Banner
CSTP FS01 CS423 (cotter) 1 Protocols 2 References: RFC’s 791, 793, 768, 826
28

CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

Dec 31, 2015

Download

Documents

Cordelia King
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 1

Protocols 2

References:

RFC’s 791, 793, 768, 826

Page 2: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 2

Lecture Outline

• TCP Header • TCP Functions

• Introduction to Sockets

Page 3: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 3

TCP Protocol Functions

• Connection Oriented• Sequence Numbers• Flow Control• Reliable Data Transfer• Congestion Control

Page 4: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 4

TCP Header

0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgment Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | data | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Page 5: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 5

TCP - Connection control

2-way Handshake 3-way Handshake

System A System B System A System B

syn

syn

syn i

syn jack i+1

data i+1ack j+1

data

Page 6: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 6

Segment Sequence Numbers

• 32 bit field (2^32 numbers)• suggest timer based initialization (4 microsec.)• wrap-around at 4.55 hrs.

Page 7: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 7

TCP Window

• Identify how much data a receiving site can hold (buffer size) in bytes.

• Example:– Window size is 4096 bytes

– Assume packet size is 512 bytes (with 40 additional bytes for TCP and IP headers).

– Initial sequence number is 123000

Page 8: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 8

TCP Window

System A System B

seq 123000

ack 124536credit 4096

ack 126584credit 4096

seq 123512

seq 126072

seq 124536seq 125048

seq 125560

seq 124024

Page 9: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 9

TCP Window (recv failure)

System A System B

seq 123000

ack 124536credit 4096

ack 125048credit 4096

seq 123512

seq 126072

seq 124536seq 125048

seq 125560

seq 124024

Page 10: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 10

TCP-Reliable Data Transfer

• Lost Packet Retransmission – Go-Back-N

– Selective Repeat

• Round Trip Time Calculation– time from send to ack

– RTT = X * old_RTT + (1 - X)*new_RTT

– Karn’s Algorithm (don’t time retransmissions)

Page 11: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 11

TCP - Flow Control

0 1 2 3 4 5 6 7

Packets

sent

ack.

window (8)

Page 12: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 12

TCP - Congestion Control

• Window-size backoff– multiplicative decrease

– additive increase

Page 13: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 13

Sockets IntroductionIP Addresses

134.193.2.254 134.193.2.250

Page 14: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 14

Sockets IntroductionPorts

134.193.2.254 134.193.2.250

1 2 3 7 8 9

Page 15: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 15

Sockets IntroductionSocket

App 1 App 2 App 3

1 2 3

134.193.2.254

Page 16: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 16

Internet Ports

• 16 bit fields (64k ports possible)• Duplicate sets for TCP and UDP• Well-known Ports ( 1-255 reserved)

– ftp: 21 telnet: 23 finger: 79

– time: 37 echo: 7 SNMP: 161

• BSD usage conventions– 1 - 1024 Privileged Ports

– 1025 - 5000 General Applications (arbitrary ports)

– 5000 + Site Specific services

Page 17: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 17

Basic Socket FunctionsServer

• Socket ( )– Create a socket of a particular type

• Bind ( )– Bind that socket to a specific port

• Listen ( )– Wait for an incoming message

• Accept ( )– Create a new socket and return new socket ID to server

Page 18: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 18

Basic Socket FunctionsServer

• Read ( )– Read an incoming message

• Write ( )– Send a message to client

• Close ( )– Close the socket

Page 19: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 19

Basic Socket FunctionsClient

• Socket ( )– Create a socket of a particular type

• Connect ( )– Establish a connection to a remote Port/Socket

• Read ( ) / Write ( )– Send and receive messages to/from remote socket

• Close ( )– Close the socket

Page 20: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 20

Socket Interaction

Client Server

Wait for connection requestsand accept when one arives

accept ( )

Create a Socketsocket ( )

Bind address to socketbind ( )

Put socket in listen statelisten ( )

Create a Socketsocket ( )

Bind address to socketbind ( )

Make a connection requestconnect ( )

Page 21: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 21

Additional Socket Functions

• Byte ordering functions– DEC / Intel vs Internet / 68000

• Name resolution functions– host / protocol / service

– by name / address / port

• Other Stuff

Page 22: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 22

Information Byte Ordering

• Convert from host to network orderhtons ( ) /* used to convert a short integer */

htonl ( ) /* used to convert a long integer */

• Convert from network to host orderntohs ( )

ntohl ( )

Page 23: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 23

Host Name Lookup

• Convert Domain name to IP address• hostent *hptr gethostbyname (char *newname)

struct hostent {

char *h_name; /* official host name */

char **h_aliases; /* other aliases */

int h_addrtype; /* address type */

int h_length; /* address length */

char **h_addr_list; /* list of addresses*/

};

#define h_addr h_addr_list[0]

Page 24: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 24

Port Number Lookup

• Used for well-known services• servent *sptr getservbyname(char *service)• struct servent {

char *s_name; /* official service name */

char **s_aliases; /* other aliases */

int s_port; /* port for this service */

char *s_proto; /* protocol to use */

};

Page 25: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 25

Protocol Number Lookup

• Used to convert protocol name to official number• protoent *pptr getprotobyname ( char *protocol)

struct protoent {

char *p_name; /* official protocol name */

char **p_aliases; /* list of aliases allowed */

short p_proto; /* official protocol number */

};

Page 26: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 26

Socket Address Structure

• connect (sd, (struct sockaddr far *) &addr_Loc, sizeof(addr_Loc));

struct sockaddr_in {

u_short sin_family; /* address family */

u_short sin_port; /* address port */

struct in_addr sin_addr; /* IP address (union) */

char sin_zero[8]; /* filler */

};

Page 27: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 27

Course Review:

• Evolution of C / S Architecture– how did we get to Client Server?

• Objectives of C/S Architecture– What problem is C/S trying to solve?

• C / S transport (specifically Internet model)– How do the lower protocol layers work?

• Socket Concepts– How do sockets (in general) work?

Page 28: CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.

CSTP FS01 CS423 (cotter) 28

Next Step:Client/Server in Windows

• CSTP Windows Support Environment• Windows Operating Environment• Windows Programming Environment• Sockets