Unix Network Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Unix Network Programming

Description:

Title: Slide 1 Author: Renato Tadao Suda Last modified by: nfonseca Created Date: 8/31/2004 7:39:07 PM Document presentation format: Apresenta o na tela – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 30
Provided by: RenatoTa
Category:

less

Transcript and Presenter's Notes

Title: Unix Network Programming


1
Unix Network Programming
  • Prof. Nelson Fonseca
  • nfonseca_at_ic.unicamp.br
  • http//www.ic.unicamp.br/nfonseca

2
Cleint-Server
Application protocol
Client
Server
3
Client Server on different LANs connected through
a WAN
Applic. Client
Applic. Server
Host with TCP/IP
Host with TCP/IP

LAN
LAN
router
router
WAN
router
router
router
router
4
Overview of TCP/IP
5
Programming with sockets
  • API Sockets
  • First in BSD4.1 UNIX,1981
  • Explicitly created and terminated by the
    applications
  • client/server
  • dois tipos de serviço de transporte via API
    Sockets
  • Datagram, non-reliable delivery
  • Byte flow, reliable delivery

6
TCP sockets
  • Socket a port used for the communication
    between two remote processes (UDP ou TCP)
  • Serviço TCP reliable data transfer, a pipe
    between the two remote processes

Created and owned by the application
Created and owned by the application
Controlled by the Operating system
Controlled by the operating system
internet
7
UDP User Datagram Protocol RFC 768
  • no luxuary
  • Best effort service,
  • UDP segments can be
  • lost
  • Delivered out of order
  • no connection
  • There is no connection setup
  • Each message is proccessed individually
  • Why use UDP?
  • No connection setup overhead
  • stateless
  • Small header
  • No congestion control
  • No flow control

8
UDP
  • Used in real time applications
  • Loss tolerant
  • Delay sensitive
  • Other protocols
  • DNS
  • SNMP
  • Any functionality needs to be added at the
    application layer

32 bits
Source port
Destination port
checksum
length
Application layer data
UDP segment format
9
TCP RFCs 793, 1122, 1323, 2018, 2581
  • Point to point
  • One sender, one receive
  • Ordered flow of bytes, reliable delivery
  • Non-structured messages
  • pipelined
  • Transmission window controlled by flow control
    and by congestion control
  • Buffers at the sendder and at the receiver
  • transmissão full duplex
  • MSS Maximum segment size
  • Connection oriented
  • Handshaking
  • Flow controlled

10
TCP segment
11
TCPsequence and ack number
B
A
send C
Seq42, ACK79, data C
Seq79, ACK43, data C
Seq43, ACK80
cenário simples de telnet
12
TCP reliable data transfer
event data received from application above
create, send segment
wait for event
event timer timeout for segment with seq y
wait for event
retransmit segment
event ACK received, with ACK y
ACK processing
13
TCP retransmission scenarios
Host A
Host B
Host A
Host B
Seq92, 8 bytes data
Seq92, 8 bytes data
Seq100, 20 bytes data
ACK100
Temp.p/ Seq92
Time out
X
ACK100
ACK120
Timeout Seq100
perda
Seq92, 8 bytes data
Seq92, 8 bytes data
ACK120
ACK100
Early timeout
Duplicated ACKs
14
TCP options
  • MSS Maximum Segment Size
  • Window scale option
  • Maximum window that can be advertized 65535 bytes
  • High speed connection ( gt 45Mbits/s) and long
    propagation delays sattelite (long fat pipe)-
    high bandwidth-delay product
  • Scale factor 0 to 14 bits
  • Maximum size 65535 x 214 1GB
  • Timestamp

15
Packet exchange
16
TCP connection termination
client
server
close
FIN
ACK
close
FIN
ACK
TimeWait
fechada
17
TCP connection management
18
TCP state transition diagram
19
TCP state transition diagram
20
TIME_WAIT state
  • Twice the Maximum Segment Lifetime (2 MSL)
  • Recommended MSL 2 minutes
  • IP packet maximum 255 hops (8 bits TTL)
  • TTL avoids routing loop
  • Time-wait allow
  • Reliable connection termination
  • Expiration of late dupliacates

21
Port numbers
  • Well-knows ports (0 1023)
  • Accessible only by superusers in the UNIX system

Dynamic or private IANA ports
Well known ports IANA
Registred IANA ports
1 1023 1024

49151 49152 65535
Portas Reservadas BSD
BSD Ephemeral ports
BSD servers (nonpriviled)
1 1023 1024 3000
3001
65535
rresvport
Solaris Ephemeral ports
513-1023
32768
65535
22
Socket pair
  • ltlocal IP address, local TCP port, remote IP
    address, remote TCP portgt

12.106.32.254 192.168.42.1
206.168.112.219
Client1
Server
connection
206.168.112.2191500, 12.106.32.25421
21,
listening socket
Server (child1)
fork
Client2
12.106.32.25421, 206.168.112.2191500
Connected socket
connection
206.168.112.2191501, 12.106.32.25421
Server (child 2)
12.106.32.25421, 206.168.112.2191501
Connected socket
23
Connection establishment
24
Buffer sizes and limitations
  • Maximum size of IPv4 datagram 65535 bytes
    including the header
  • Maximum size of IPv6 datagram 65575 bytes
    including the header
  • IPv6 option Jumbo Payload 32 bits, MTU must
    support

25
Buffer sizes and limitations
  • Minimum MTU
  • IPv4 68 bytes IPv6 576 bytes
  • Path MTU minimum MTU in a path
  • Path MTU discovery
  • Minimum reassembly buffer size (minimum datagram
    size)
  • IPv4 576 bytes, IPv6 1500 bytes

26
Steps and buffers limitations involved when
application writes to a TCP socket
Application
Application Buffer)
write
User process
Kernel
TCP
Socket sender buffer (SO_SNDBUF)
Segmentos TCP do tamanho do MSS
MSS normally MTU 40 (IPv4) ou MTU 60 (IPv6)
IP
MTU-sized IPv4 or IPv6 packets
Output queue
link
27
Buffer sizes and limitations
  • Kernel copies data from application buffer to
    socket buffer
  • If no space is available, process is blocked
    until the transfer of last byte
  • A suuccessful write does not mean remote process
    received the data

28
Steps and buffers limitations involved when
application writes to a UDP socket
Application
Application buffer
sendto
User process
Kernel
UDP
Socket send buffer (SO_SNDBUF)
UDP datagram
IP
MTU-sized IPv4 or IPv6 packets
Output queue
link
  • Sucessful write datagram was placed at link
    output queue

29
Buffer sizes and limitations
Write a Comment
User Comments (0)
About PowerShow.com