laboratório de teleprocessamento e redes1 unix network programming prof. nelson fonseca...

Download Laboratório de Teleprocessamento e Redes1 Unix Network Programming Prof. Nelson Fonseca nfonseca@ic.unicamp.br nfonseca

If you can't read please download the document

Upload: alayna-liggett

Post on 14-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

  • Slide 1

Laboratrio de Teleprocessamento e Redes1 Unix Network Programming Prof. Nelson Fonseca [email protected] http://www.ic.unicamp.br/~nfonseca Slide 2 Laboratrio de Teleprocessamento e Redes2 Cleint-Server Client Server Application protocol Slide 3 Laboratrio 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 { Slide 4 Laboratrio de Teleprocessamento e Redes4 Overview of TCP/IP Slide 5 Laboratrio 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 servio 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 Slide 6 Laboratrio de Teleprocessamento e Redes6 TCP sockets Socket: a port used for the communication between two remote processes (UDP ou TCP) Servio TCP: reliable data transfer, a pipe between the two remote processes processo TCP com buffers, variveis socket Created and owned by the application Controlled by the operating system processo TCP com buffers, variveis socket Created and owned by the application Controlled by the Operating system internet Slide 7 Laboratrio 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 Slide 8 Laboratrio 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 Slide 9 Laboratrio de Teleprocessamento e Redes9 TCP RFCs: 793, 1122, 1323, 2018, 2581 transmisso 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 Slide 10 Laboratrio 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 Slide 11 Laboratrio 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 cenrio simples de telnet Slide 12 Laboratrio 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 Slide 13 Laboratrio 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 Slide 14 Laboratrio 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 Slide 15 Laboratrio de Teleprocessamento e Redes15 Packet exchange Slide 16 Laboratrio de Teleprocessamento e Redes16 TCP connection termination client FIN server ACK FIN close fechada Time Wait Slide 17 Laboratrio de Teleprocessamento e Redes17 TCP: connection management Slide 18 Laboratrio de Teleprocessamento e Redes18 TCP state transition diagram Slide 19 Laboratrio de Teleprocessamento e Redes19 TCP state transition diagram Slide 20 Laboratrio 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 Slide 21 Laboratrio 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 Slide 22 Laboratrio de Teleprocessamento e Redes22 Socket pair Client1 Client2 Server (child1) Server (child 2) 206.168.112.219 12.106.32.254 192.168.42.1 {206.168.112.219:1500, 12.106.32.254:21} {206.168.112.219:1501, 12.106.32.254:21} {12.106.32.254:21, 206.168.112.219:1501} {12.106.32.254:21, 206.168.112.219:1500} {* : 21,* : *} connection listening socket Connected socket fork