10. udp/tcp

8
10. UDP/TCP WWW page: http:/www.dcs.napier.ac.uk/~bill/cnds/index.html Text book: Mastering Networks (Chapter 10) Network IP protocol is routes the data packet through the network Application 1 Application 2 Application 3 Application 1 Application 2 Application 3 Socket IP TCP Higher-level protocol

Upload: shandi

Post on 04-Jan-2016

44 views

Category:

Documents


0 download

DESCRIPTION

IP. TCP. Higher-level protocol. Socket. Application 1. Application 1. Network. Application 2. Application 2. Application 3. IP protocol is routes the data packet through the network. Application 3. 10. UDP/TCP. WWW page: http:/www.dcs.napier.ac.uk/~bill/cnds/index.html - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 10. UDP/TCP

10. UDP/TCP

WWW page: http:/www.dcs.napier.ac.uk/~bill/cnds/index.htmlText book: Mastering Networks (Chapter 10)

Network

IP protocol isroutes the datapacket through thenetwork

Application1

Application1

Application2

Application2

Application3

Application3

Application1

Application1

Application2

Application2

Application3

Application3

Socket

IPIP TCPTCP Higher-level protocolHigher-level protocol

Page 2: 10. UDP/TCP

10.1 TCP (Transmission Control Protocol)Data Transfer. Data is transmitted between two applications by packaging the data within TCP packets. This data is buffered and forwarded whenever necessary. A push function can be used when the data is required to be sent immediately. Reliability. TCP uses sequence numbers and positive acknowledgements (ACK) to keep track of transmitted packets. Thus, it can recover from data that is damaged, lost, duplicated, or delivered out of order, such as:

Time-outs. The transmitter waits for a given time (the timeout interval), and if it does not receive an ACK, the data is retransmitted. Sequence numbers. The sequence numbers are used at the receiver to correctly order the packets and to delete duplicates. Error detection and recovery. Each packet has a checksum, which is checked by the receiver. If it is incorrect the receiver discards it, and can use the acknowledgements to indicate the retransmission of the packets.

Data Transfer. Data is transmitted between two applications by packaging the data within TCP packets. This data is buffered and forwarded whenever necessary. A push function can be used when the data is required to be sent immediately. Reliability. TCP uses sequence numbers and positive acknowledgements (ACK) to keep track of transmitted packets. Thus, it can recover from data that is damaged, lost, duplicated, or delivered out of order, such as:

Time-outs. The transmitter waits for a given time (the timeout interval), and if it does not receive an ACK, the data is retransmitted. Sequence numbers. The sequence numbers are used at the receiver to correctly order the packets and to delete duplicates. Error detection and recovery. Each packet has a checksum, which is checked by the receiver. If it is incorrect the receiver discards it, and can use the acknowledgements to indicate the retransmission of the packets.

Flow Control. TCP returns a window with every ACK. This window indicates a range of acceptable sequence numbers beyond the last segment successfully received. This window also indicates the number of bytes that the sender can transmit before receiving further acknowledgements.Multiplexing. To support multiple connections to a single host, TCP provides a set of ports within each host. This, along with the IP addresses of the source and destination, makes a socket. Each connection is uniquely identified by a pair of sockets. Ports are normally associated with various services and allow service programs to listen for defined port numbers. Connections. A connection is defined by the sockets, sequence numbers and window sizes. Each host must maintain this information for the length of the connection. When the connection is closed, all associated resources are freed. As TCP connections can be made with unreliable hosts and over unreliable communication channels, TCP uses a handshake mechanism with clock-based sequence numbers to avoid inaccurate connection initialisation.Precedence and Security. TCP allows for

different security and precedence levels.

Flow Control. TCP returns a window with every ACK. This window indicates a range of acceptable sequence numbers beyond the last segment successfully received. This window also indicates the number of bytes that the sender can transmit before receiving further acknowledgements.Multiplexing. To support multiple connections to a single host, TCP provides a set of ports within each host. This, along with the IP addresses of the source and destination, makes a socket. Each connection is uniquely identified by a pair of sockets. Ports are normally associated with various services and allow service programs to listen for defined port numbers. Connections. A connection is defined by the sockets, sequence numbers and window sizes. Each host must maintain this information for the length of the connection. When the connection is closed, all associated resources are freed. As TCP connections can be made with unreliable hosts and over unreliable communication channels, TCP uses a handshake mechanism with clock-based sequence numbers to avoid inaccurate connection initialisation.Precedence and Security. TCP allows for

different security and precedence levels. Transport

Network

TCP

IPIPIP TCPTCP Higher-level protocolHigher-level protocol

Page 3: 10. UDP/TCP

10.2 TCP operation

OperationWhen a host wishes to make a connection, TCP sends out a request message to the destination machine that contains unique numbers called a socket number, and a port number. The port number has a value which is associated with the application (for example a TELNET connection has the port number 23 and an FTP connection has the port number 21). The message is then passed to the IP layer, which assembles a datagram for transmission to the destination.When the destination host receives the connection request, it returns a message containing its own unique socket number and a port number. The socket number and port number thus identify the virtual connection between the two hosts.After the connection has been made the data can flow between the two hosts (called a data stream).

OperationWhen a host wishes to make a connection, TCP sends out a request message to the destination machine that contains unique numbers called a socket number, and a port number. The port number has a value which is associated with the application (for example a TELNET connection has the port number 23 and an FTP connection has the port number 21). The message is then passed to the IP layer, which assembles a datagram for transmission to the destination.When the destination host receives the connection request, it returns a message containing its own unique socket number and a port number. The socket number and port number thus identify the virtual connection between the two hosts.After the connection has been made the data can flow between the two hosts (called a data stream).

Sending Port Number (such as 21 for FTP)

Unique SendingSocket Number

Unique ReceivingSocket Number

Receiving Port Number (typically the same as sender’s)

Data transfer usingports and sockets(data stream)

Page 4: 10. UDP/TCP

10.3 TCP and IP

Network

IP protocolroutes the datapackets through thenetwork

Application1

Application1

Application2

Application2

Application3

Application3

Application1

Application1

Application2

Application2

Application3

Application3 TCP protocol

is responsible fora data stream betweenapplication programs

Socket

IPIP TCPTCP Higher-level protocolHigher-level protocol

Page 5: 10. UDP/TCP

10.4 TCP header contents1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Source port

Destination port

Sequence number

Acknowledgment number

Checksum

ReservedData offset Flags

UrgPtr

DATA

Window

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Source port

Destination port

Sequence number

Acknowledgment number

Checksum

ReservedData offset Flags

UrgPtr

DATA

Window

Main fieldsSource and destination port number – which are 16-bit values that identify the local port number (source number and destination port number or destination port).Sequence number – which identifies the current sequence number of the data segment. This allows the receiver to keep track of the data segments received. Any segments that are missing can be easily identified. The sequence number of the first data byte in this segment (except when SYN is present). If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1.Acknowledgement number – when the ACK bit is set, it contains the value of the next sequence number the sender of the packet is expecting to receive. This is always set after the connection is made. Data offset – which is a 32-bit value that identifies the start of the data. It is defined as the number of 32-bit words in the header (as the TCP header always has a multiple number of 32-bit words).Flags – the flag field is defined as UAPRSF, where U is the urgent flag (URG), A the acknowledgement flag (ACK), P the push function (PSH), R the reset flag (RST), S the sequence synchronise flag (SYN) and F the end-of-transmission flag (FIN).

Main fieldsSource and destination port number – which are 16-bit values that identify the local port number (source number and destination port number or destination port).Sequence number – which identifies the current sequence number of the data segment. This allows the receiver to keep track of the data segments received. Any segments that are missing can be easily identified. The sequence number of the first data byte in this segment (except when SYN is present). If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1.Acknowledgement number – when the ACK bit is set, it contains the value of the next sequence number the sender of the packet is expecting to receive. This is always set after the connection is made. Data offset – which is a 32-bit value that identifies the start of the data. It is defined as the number of 32-bit words in the header (as the TCP header always has a multiple number of 32-bit words).Flags – the flag field is defined as UAPRSF, where U is the urgent flag (URG), A the acknowledgement flag (ACK), P the push function (PSH), R the reset flag (RST), S the sequence synchronise flag (SYN) and F the end-of-transmission flag (FIN).

Window – which is a 16-bit value and gives the number of data bytes that the receiving host can accept at a time, beginning with the one indicated in the acknowledgement field of this segment.Checksum – which is a 16-bit checksum for the data and header. It is the 1’s complement of the 1’s complement sum of all the 16-bit words in the TCP header and text. The checksum is assumed to be a zero when calculating the checksum.

Window – which is a 16-bit value and gives the number of data bytes that the receiving host can accept at a time, beginning with the one indicated in the acknowledgement field of this segment.Checksum – which is a 16-bit checksum for the data and header. It is the 1’s complement of the 1’s complement sum of all the 16-bit words in the TCP header and text. The checksum is assumed to be a zero when calculating the checksum.

IPIP TCPTCP Higher-level protocolHigher-level protocol

Page 6: 10. UDP/TCP

10.5 UDP

Length

Source port

Destination port

Checksum

DATA

32 bits

Source IP address

Destination IP address

Zero Protocol=17 UDP length

IPheader

UDPheader

Source port. This is an optional field and is set to a zero if not used. It identifies the local port number which should be used when the destination host requires to contact the originator.Destination. Port to connect to on the destination. Length. Number of bytes in the datagram, including the UDP header and the data.Checksum. The 16-bit 1’s complement of the 1’s complement sum of the IP header, the UDP header, the data (which, if necessary, is padded with zero bytes at the end, to make an even number of bytes).

Source port. This is an optional field and is set to a zero if not used. It identifies the local port number which should be used when the destination host requires to contact the originator.Destination. Port to connect to on the destination. Length. Number of bytes in the datagram, including the UDP header and the data.Checksum. The 16-bit 1’s complement of the 1’s complement sum of the IP header, the UDP header, the data (which, if necessary, is padded with zero bytes at the end, to make an even number of bytes).

UDP sends data packets that are not acknowledged. It is thus unreliable, as the sender cannot tell if the data has been received and the receiver does not knowif there has been a loss of packets. There is also no connection, so the sender does even know if the receive is even receiving data

TCP sends back acknowledgements to accept data that has been sent. The receiver can also tell if there are any lost packets, or if theremote computer has crashed, and has been restarted.

Connection and ACK’s

Data stream

IPIP UDPUDP Higher-level protocolHigher-level protocol

Page 7: 10. UDP/TCP

10.6 Server applications listening for TCP ports

Input TCP packetswith port number

TELNET serverlistens for port 23

FTP serverlistens for port 21

HTTP serverlistens for port 80

SMTP serverlistens for port 161

Server

Page 8: 10. UDP/TCP

Port Service Comment Port Service Comment1 TCPmux 7 echo9 discard Null 11 systat Users13 daytime 15 netstat17 qotd Quote 18 msp Message send protocol19 chargen ttytst source 21 ftp23 telnet 25 smtp Mail37 time Timserver 39 rlp Resource location42 nameserver IEN 116 43 whois Nicname53 domain DNS 57 mtp Deprecated67 bootps BOOTP server 67 bootps68 bootpc BOOTP client 69 tftp70 gopher Internet Gopher 77 rje Netrjs79 finger 80 www WWW HTTP87 link Ttylink 88 kerberos Kerberos v595 supdup 101 hostnames102 iso-tsap ISODE 105 csnet-ns CSO name server107 rtelnet Remote Telnet 109 pop2 POP version 2110 pop3 POP version 3 111 sunrpc113 auth Rap ID 115 sftp117 uucp-path 119 nntp USENET 123 ntp Network Timel 137 netbios-ns NETBIOS Name Service138 netbios-dgm NETBIOS 139 netbios-ssn NETBIOS session 143 imap2 161 snmp SNMP162 snmp-trap SNMP trap 163 cmip-man ISO management over IP 164 cmip-agent 177 xdmcp X Display Manager178 nextstep NeXTStep 179 bgp BGP191 prospero 194 irc Internet Relay Chat199 smux SNMP Multiplexer 201 at-rtmp AppleTalk routing

Port Service Comment Port Service Comment1 TCPmux 7 echo9 discard Null 11 systat Users13 daytime 15 netstat17 qotd Quote 18 msp Message send protocol19 chargen ttytst source 21 ftp23 telnet 25 smtp Mail37 time Timserver 39 rlp Resource location42 nameserver IEN 116 43 whois Nicname53 domain DNS 57 mtp Deprecated67 bootps BOOTP server 67 bootps68 bootpc BOOTP client 69 tftp70 gopher Internet Gopher 77 rje Netrjs79 finger 80 www WWW HTTP87 link Ttylink 88 kerberos Kerberos v595 supdup 101 hostnames102 iso-tsap ISODE 105 csnet-ns CSO name server107 rtelnet Remote Telnet 109 pop2 POP version 2110 pop3 POP version 3 111 sunrpc113 auth Rap ID 115 sftp117 uucp-path 119 nntp USENET 123 ntp Network Timel 137 netbios-ns NETBIOS Name Service138 netbios-dgm NETBIOS 139 netbios-ssn NETBIOS session 143 imap2 161 snmp SNMP162 snmp-trap SNMP trap 163 cmip-man ISO management over IP 164 cmip-agent 177 xdmcp X Display Manager178 nextstep NeXTStep 179 bgp BGP191 prospero 194 irc Internet Relay Chat199 smux SNMP Multiplexer 201 at-rtmp AppleTalk routing

10.7 Standard TCP ports