Presentation is loading. Please wait.

Presentation is loading. Please wait.

Laboratório de Teleprocessamento e Redes1 Unix Network Programming Prof. Nelson Fonseca

Similar presentations

Presentation on theme: "Laboratório de Teleprocessamento e Redes1 Unix Network Programming Prof. Nelson Fonseca"— Presentation transcript:

1 Laboratório de Teleprocessamento e Redes1 Unix Network Programming Prof. Nelson Fonseca

2 Laboratório de Teleprocessamento e Redes2 Cleint-Server Client Server Application protocol

3 Laboratório de Teleprocessamento e Redes3 Client Server on different LANs connected through a WAN Applic. Client Host with TCP/IP LAN router LAN Applic. Server Host with TCP/IP WAN {

4 Laboratório de Teleprocessamento e Redes4 Overview of TCP/IP

5 Laboratório de Teleprocessamento e Redes5 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 An interface (“port”), local, created and owned by na application, controlled by the operating system, allows sending and receiving messages to a remote process socket

6 Laboratório de Teleprocessamento e Redes6 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 processo TCP com buffers, variáveis socket Created and owned by the application Controlled by the operating system processo TCP com buffers, variáveis socket Created and owned by the application Controlled by the Operating system internet

7 Laboratório de Teleprocessamento e Redes7 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 Laboratório de Teleprocessamento e Redes8 UDP  Used in real time applications  Loss tolerant  Delay sensitive Other protocols:  DNS  SNMP  Any functionality needs to be added at the application layer Source port 32 bits Application layer data UDP segment format length checksum Destination port

9 Laboratório de Teleprocessamento e Redes9 TCP RFCs: 793, 1122, 1323, 2018, 2581 transmissão full duplex:  MSS: Maximum segment size  Connection oriented:  Handshaking  Flow controlled 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

10 Laboratório de Teleprocessamento e Redes10 TCP segment Source port Destination port 32 bits payload Sequence number Acknowledgement number Receiver window Ptrurgent data checksum F SR PAU Leng header sem uso Options

11 Laboratório de Teleprocessamento e Redes11 TCP:sequence and ack number A B Seq=42, ACK=79, data = ‘C’ Seq=79, ACK=43, data = ‘C’ Seq=43, ACK=80 send ‘C’ time cenário simples de telnet

12 Laboratório de Teleprocessamento e Redes12 TCP: reliable data transfer wait for event wait for event event: data received from application above event: timer timeout for segment with seq # y event: ACK received, with ACK # y create, send segment retransmit segment ACK processing

13 Laboratório de Teleprocessamento e Redes13 TCP: retransmission scenarios Host A Seq=92, 8 bytes data ACK=100 perda Time out time Duplicated ACKs Host B X Seq=92, 8 bytes data ACK=100 Host A Seq=100, 20 bytes data ACK=100 Temp.p/ Seq=92 Early timeout Host B Seq=92, 8 bytes data ACK=120 Seq=92, 8 bytes data Timeout Seq=100 ACK=120 time

14 Laboratório de Teleprocessamento e Redes14 TCP options MSS – Maximum Segment Size Window scale option  Maximum window that can be advertized 65535 bytes  High speed connection ( > 45Mbits/s) and long propagation delays – sattelite (long fat pipe)- high bandwidth-delay product  Scale factor 0 to 14 bits  Maximum size: 65535 x 2 14 = 1GB  Timestamp

15 Laboratório de Teleprocessamento e Redes15 Packet exchange

16 Laboratório de Teleprocessamento e Redes16 TCP connection termination client FIN server ACK FIN close fechada Time Wait

17 Laboratório de Teleprocessamento e Redes17 TCP: connection management

18 Laboratório de Teleprocessamento e Redes18 TCP state transition diagram

19 Laboratório de Teleprocessamento e Redes19 TCP state transition diagram

20 Laboratório de Teleprocessamento e Redes20 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 Laboratório de Teleprocessamento e Redes21 Port numbers Well-knows ports (0 – 1023)  Accessible only by superusers in the UNIX system Well known ports IANA Registred IANA ports Dynamic or private IANA ports Portas Reservadas BSD BSD Ephemeral ports BSD servers (nonpriviled) rresvport Solaris Ephemeral ports 1 1023 1024 49151 49152 65535 1 1023 1024 3000 3001 65535 513-1023 32768 65535

22 Laboratório de Teleprocessamento e Redes22 Socket pair Client1 Client2 Server (child1) Server (child 2) {,} {,} {,} {,} {* : 21,* : *} connection listening socket Connected socket fork

23 Laboratório de Teleprocessamento e Redes23 Connection establishment

24 Laboratório de Teleprocessamento e Redes24 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 Laboratório de Teleprocessamento e Redes25 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 Laboratório de Teleprocessamento e Redes26 Steps and buffers limitations involved when application writes to a TCP socket Application TCP IP Output queue link Application Buffer) write Socket sender buffer ( SO_SNDBUF ) User process Kernel Segmentos TCP do tamanho do MSS MSS normally ≤ MTU – 40 (IPv4) ou MTU – 60 (IPv6) MTU-sized IPv4 or IPv6 packets

27 Laboratório de Teleprocessamento e Redes27 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 Laboratório de Teleprocessamento e Redes28 Steps and buffers limitations involved when application writes to a UDP socket Application UDP IP Output queue link Application buffer sendto Socket send buffer ( SO_SNDBUF ) User process Kernel UDP datagram MTU-sized IPv4 or IPv6 packets Sucessful write: datagram was placed at link output queue

29 Laboratório de Teleprocessamento e Redes29 Buffer sizes and limitations

Download ppt "Laboratório de Teleprocessamento e Redes1 Unix Network Programming Prof. Nelson Fonseca"

Similar presentations

Ads by Google