TCPIP Basics Protocol Suite TCP Transmission Control Protocol
TCP/IP Basics — Protocol Suite — TCP (Transmission Control Protocol); IP (Internet Protocol)
Multi-layer Communication (1/2) 2
Multi-layer Communication (2/2) } A series of layers, each built upon the one below it } Each layer offers certain services to higher layers, hiding the detailed implementation of these services from higher layers } Each layer is completely independent of others as long as the interfaces are not changed } Secretaries can switch from fax to email, without disturbing other layers } Modularization } Well-defined interface makes easy collaboration } 模組化分 ,模組抽換容易 3
Protocol (協定) } Protocol is an agreement between two communication parties on how communication is to proceed } Two communication parties communicate by means of formatted blocks of data that obey the rules and conventions known as a protocol } Protocol is like a language that people speak. Two persons speaking the same language can understand each other } 協定規範交談的邏輯,實作於軟體模組;參與訊息傳遞的網 路節點均會運行這一類的軟體,有足夠的智能處理訊息傳遞 } Key features of a protocol } Syntax: Concerns the format of the data blocks } Semantics: Includes control information for coordination and error handling } Timing: Includes speed matching and sequencing 4
TCP/IP Protocol Suite } TCP/IP protocol stack: A set of standard protocols used for Today’s Internet communication
TCP/IP Protocol Suite Is Like Corporate Hierarchy } Each module is dedicated to certain jobs and is designed to work jointly with others } Higher layers invoke lower levels for certain tasks/services } Lower levels implement actions to realize services } 各司其職,分 合作,隸屬不同部 門的人力有特定的任務 } IP為所有上層協定均會使用到的機 制,把來自於上層的訊息統一打包 處理成既定的格式再傳送
TCP/IP Layers } Client-server model: the user who initiates/requests communication is a client } Implemented by 5 layers } } } Application layer Host-to-host (end-to-end) or transport layer Internet layer … Layer 3 Network access layer … Layer 2 Physical layer … Layer 1
Layered Concepts 9
Service Primitives (服務指令) and Parameters } Define services between adjacent layers using: } Primitives to specify function performed } Parameters to pass data and control information
Common Service Primitives REQUEST A primitive issued by a service user to invoke some service and to pass the parameters needed to specify fully the requested service INDICATION A primitive issued by a service provider either to: indicate that a procedure has been invoked by the peer service user on the connection and to provide the associated parameters, or notify the service user of a provider-initiated action RESPONSE A primitive issued by a service user to acknowledge or complete some procedure previously invoked by an indication to that user CONFIRM A primitive issued by a service provider to acknowledge or complete some procedure previously invoked by a request by the service user
Client-Server Interaction Model 6 service primitives provide a simple connection-oriented service
Application Layer } Software that services and interacts with users } E. g. e-mail, FTP, WWW, any APP that you can use manipulate directly } Contains the logic needed to support various user applications } Uses separate modules that are peculiar to each different type of application } 各式各樣使用者可直接啟動或取用的應用程式(APP) 13
Host-to-Host or Transport Layer } Provides reliability during data exchanges } } Completeness (沒有漏失) In-order delivery (循序傳遞) Transmission Control Protocol (TCP) is mostly used Another is UDP (User Datagram Protocol) } TCP = connection-oriented protocol provides a reliable unicast end-to-end byte stream over an unreliable internetwork ← TCP segment 14
Transport Layer — Connection-Oriented } Before data transfer, TCP establishes a connection (3 -way handshake)(三向交握) } Each connection is full duplex ACK (acknowledgmen t) 也有可能由server主導發出斷線訊息
Use Wireshark to Observe Message Flow 16
Transport Layer — TCP Connection } Each host must have a global Internet address (e. g. , 140. 125. 21. 42) } Each process with a host must have an address that is unique within the host — port (埠) • A port number identifies the endpoint of a connection } Pairs <client IP address, client port#> and <server IP address, server port#> identify a connection 17
A Port Number Corresponds to A Certain Service (Network Application) That Handles Messages. What Are Well-Known Port Numbers? 埠號對應特定的網路應用程式,有哪些埠 號是經常被用到或保留作特定用途的? 自行開發的網路程式應避 開這些埠號,以免衝突
Transport Layer — Reliable Transfer } Byte stream is broken up into chunks, i. e. , segments } Receiver sends acknowledgements (ACKs) for segments } TCP maintains a timer. If an ACK is not received in time, the segment is retransmitted } Detecting errors } TCP has checksums for header and data } Segments with invalid checksums are discarded } Each byte that is transmitted has a sequence number 19
Internet Layer } Network access layer is concerned with access and routing data across a network for two end systems attached the same network } Uses the Internet protocol (IP) when devices are attached to different networks } Provides routing functions to allow data to traverse multiple interconnected networks } Implemented in end systems and routers } A router is a processor or host that connects two networks } To relay data from one network to the other on its route from the source to the destination end systems 20
Network Access Layer } Concerned with the exchange of data between an end system (server, workstation) and the network to which it is attached } MAC-level (網卡) addressing, 例 00: 0 a: 95: 9 d: 68: 16 (48 bits) } 區域網路內的多重存取技術 (下一單元討論) } Ethernet, Bluetooth, Wi. Fi, and Lo. Ra belong to the networkaccess layer } Software used depends on type of network } } Circuit switching Packet switching (e. g. , X. 25) LANs (e. g. , Ethernet) Others 21
Physical (PHY) Layer } Covers the physical interface between a transmission device (e. g. , workstation) and a transmission medium or network } The sending computer must provide the network of the address of the destination computer } The sending computer may wish to invoke certain services provided by the network } Different standards have been developed } Physical layer specifies: } } Characteristics of the transmission medium The nature of signals Data rate Other related matters } Upper layers above network access do not need to consider the specifics of the network to be used 22
運作範例 (1/2) 140. 125. 20. 43 TCP: Transmission Control Protocol IP: Internet Protocol NAP: Network Access Protocol 168. 95. 1. 168 23
Protocol Encapsulation ü When data moves from upper to lower layer, each layer includes a bundle of relevant information called "header" along with the actual data ü This packing of data at each layer is called data encapsulation } A block of information exchanged at any protocol level is referred to as protocol data units (PDUs) } Header + Data (payload) + Trailer Destination Port Sequence number Checksum Destination IP Address Source IP address Dest. Network Address Priority info 25
Protocol Encapsulation ü 每一層把資料傳給下層之前,於資料區塊的 前端附加標頭(header)的控制資訊,標頭記 錄該資料塊相對於該層的特性及處理指引 ü 每一層把上層傳來的資料連同新加的標頭再 送至下一層作處理,這個過程稱為資料封裝 } A block of information exchanged at any protocol level is referred to as protocol data units (PDUs) } Header + Data (payload) + Trailer Destination Port Sequence number Checksum Destination IP Address Source IP address Dest. Network Address Priority info 26
Protocol Encapsulation, Decapsulation (解封裝) 27
Transport Layer } TCP and UDP are two different protocols that handle data communications between hosts over an IP network (the Internet) } TCP vs. UDP } TCP is connection-oriented and reliable; UDP is connectionless } Speed for TCP is slower; UDP is faster } TCP uses handshake like SYN, SYN-ACK, ACK; UDP uses no handshakes } TCP does error checking and makes error recovery; UDP performs error checking but discards erroneous packets } TCP has acknowledgment segments, but UDP does not } TCP is heavy-weight; UDP is lightweight 28
Knowing distinctions between TCP and UDP, does that really matter to network engineers like you? It will affect how you think about network programing and what kind of services or quality you will have 29
Recall Experiments on Raspberry Pi http: //140. 125. 21. 43/src/ } Client-server interactions are based on the same UDP or TCP mechanisms (must be paired) } Communication cannot achieve if one side uses a UDP socket while the other uses a TCP socket } On the PC side } client. py (UDP), TCPclient. py } In client. py, comment lines 39— 41; the program still runs if echo. Server. py has not been activated beforehand } On Raspberry Pi } echo. Server. py (UDP), IOTserver. py (UDP), TCPserver. py } Differences } When using UDP, the client program can run fine although the server has not yet started a priori 30
Where Differentiates between UDP- and TCPbased Programs?
Internet Layer (IP): Direct Routing vs. Indirect Routing } Consult the routing table to determine how to route an IP packet } Direct routing (直接繞送) } Destination are attached to the same physical network } Find the physical address of the destination host (ARP) } Encapsulate the packet in a physical frame and send the frame directly to the physical address } Indirect routing (間接繞送) } Destination is not on a directly attached network } Encapsulate the packet and send it to the next-hop router } An IP packet is routed hop-by-hop until the packet can be delivered directly https: //goo. gl/9 F 9 n. AE
ARP, Proxy ARP (1/2) } Two machines on a physical network communicate using the physical address } Address Resolution Protocol (ARP): mapping Internet addresses to physical addresses } Example } When a user types “ftp hostname” 33
ARP, Proxy ARP (2/2) } Address Resolution Protocol } Determine physical addresses when sending a packet } Answer physical address requests from other machines } Address Resolution Cache: recently acquired IP-tophysical address bindings can be cached } ARP refinement (avoid request from an anticipated source) } Sender includes its IP-to-physical address binding in the ARP request } Receivers update the cached IP-to-physical bindings } ARP encapsulation } On an Ethernet, frame type is 080616 for ARP messages 34
Fake IP Address? How to Tell? } IP address identifies where to reach a host on the Internet } Mostly unique but may be shared by multiple hosts through NAT (network address translation) • NAT is often implemented inside the network router } Associated with geolocation • E. g. 140. 125. 21. 43, 163. 28. 5. 27, 134. 60. 1. 22 } Common private IP addresses } 10. 0. 0. x, 172. 16. 0. x, 192. 168. x. x } How to identify your own IP address? } ipconfig (Windows), ifconfig (linux) } netstat -ano 35
Five Classes of IPv 4 Addresses } A, B, C, D, and E five classes } Router interprets the network and host fields by examining the first few bits of the IP address Class A 01234 0 netid 8 16 24 Class B 10 Class C 110 Class D 1110 multicast address Class E 1111 reserved for future use 31 hostid netid hostid Q: Yun. Tech IP addresses belong to which class? 37
We Are Always Under Cyber Attacks 38
Tools To Trace Whereabouts of IP Addresses } Example: tracert www. youtube. com } Free visualization tool: Open Visual Traceroute
Common Protocol Header 常見的協定標頭欄位
TCP Header (1/2) } } Destination port Sequence number Checksum Code bits } } } FIN: 結束連線 SYN: 建立連線 RST: 重置連線 PSH: 封包立即傳送 ACK: 回應上一次收到的封包 URG: 請接收端立即處理Urgent pointer所指位址(offset from the current sequence number)之緊要資料,類“interrupt”用途 } ECE: Explicit Congestion Notification Echo → TCP sender } CWR: Congestion Window Reduced, TCP sender → receiver 42
TCP Header (2/2) } Each sequence number identifies a byte in the byte stream } Acknowledgement Number (Ack. No) } Acknowledgements are piggybacked • A segment from A→B can contain an acknowledgement for a data sent in the B→A direction } A host uses Ack. No to send acknowledgements. (If a host sends an Ack. No in a segment it sets the “ACK flag”) } Ack. No contains the next Seq. No that a host wants to receive • 例: The acknowledgement for a segment with sequence numbers 0 -1500 is Ack. No=1501 • 例: Sender sends two segments with “ 1. . 1500” and “ 1501. . 3000”, but receiver only gets the second segment. In this case, the receiver cannot acknowledge the second packet. It can only send Ack. No=1 43
TCP Connection Establishment } TCP uses a three-way handshake to open a connection: (1) Client sends a segment with • SYN bit set • port number of client • initial sequence number (ISN) of client (2) Server responds with a segment with • SYN bit set • initial sequence number of server • ACK for ISN of client (3) Client acknowledges by sending a segment with • ACK ISN of server 44
User Datagram Protocol (UDP) } } } An alternative to TCP No guaranteed delivery No preservation of sequence No protection against duplication Minimum overhead Just adds port addressing to IP UDP header
IP Datagram Format 46
IP Datagram Format: Fields (1/4) } Version (4 bits): current version is 4, next version 6 } Header length (4 bits): length of IP header, in multiples of 4 bytes } DS/ECN field (1 byte) } This field was previously called as Type-of-Service (TOS) field. The role of this field has been re-defined, but is “backwards compatible” to TOS interpretation } Differentiated Service (DS) (6 bits): • Used to specify service level (currently not supported in the Internet) } Explicit Congestion Notification (ECN) (2 bits): • New feedback mechanism used by TCP 47
IP Datagram Format: Fields (2/4) } Identification (16 bits) } Unique identification of a datagram from a host } Incremented whenever a datagram is transmitted } Flags (3 bits) } First bit always set to 0 } DF bit (Do not fragment) } MF bit (More fragments) } Time To Live (TTL) (1 byte) } Specifies longest paths before datagram is dropped } Role of TTL field: Ensure that packet is eventually dropped when a routing loop occurs } Used as follows: • Sender sets the value (e. g. , 64) • Each router decrements the value by 1 • When the value reaches 0, the datagram is dropped 48
IP Datagram Format: Fields (3/4) } Protocol (1 byte) } Specifies the higher-layer protocol } Used for demultiplexing to higher layers } Header checksum (2 bytes) } A simple 16 -bit long checksum which is computed for the header of the datagram 49
IP Datagram Format: Fields (4/4) } Options } Security restrictions } Record Route: each router that processes the packet adds its IP address to the header } Timestamp: each router that processes the packet adds its IP address and time to the header } (loose) Source Routing: specifies a list of routers that must be traversed } (strict) Source Routing: specifies a list of the only routers that can be traversed } Padding bytes are added to ensure that header ends on a 4 -byte boundary 50
Some Protocols in TCP/IP Suite 51
另一常見的協定分層架構 OSI (Open Systems Interconnection) Reference Model
Layers of the OSI Model (1/5) } The OSI (Open Systems Interconnection) reference model was developed by the International Organization for Standardization (ISO) } } } } Application Presentation Session Transport Network Data link Physical 53
Layers of the OSI Model (2/5) } Application layer } Provides access to the OSI environment for users } Provides distributed information services } Presentation layer } Provides independence to the application processes from differences in data representation (syntax) } Concerned with the syntax and semantics of the information transmitted, e. g. ACSII code, Unicode incompatible } Data compression } Encryption 54
Layers of the OSI Model (3/5) } Session layer } Provides the control structure for communication between applications • Whose turn to talk? } Establishes, manages, and terminates connections between cooperating applications } Token management: dialogue discipline (full-duplex, halfduplex) • For some protocols, it is essential that both sides do not attempt the same operation at the same time. Only the side holding the token may perform the critical operation } Synchronization • Insert checkpoints into the data stream, so that after a crash, only the data transferred after the last checkpoint need to be repeated 55
Layers of the OSI Model (4/5) } Transport layer } Provides reliable, transparent transfer of data between end points } Provides end-to-end error recovery and flow control } Network layer } Provides upper layers with independence from the data transmission and switching technologies used to connect systems } Responsible for establishing, maintaining, and terminating connections } A key design issue is determining how packets are routed from source to destination. Static table? Dynamic table is determined anew for each packet, to reflect the current network load 56
Layers of the OSI Model (5/5) } Data-link layer } Provides the reliable transfer of information across the physical link } Sends blocks (frames) with the necessary synchronization, error control (error detection/correction), and flow control } Physical layer } Transmission of unstructured bit stream over physical medium } Deals with accessing the physical medium • Mechanical characteristics • Electrical characteristics • Functional characteristics • Procedural characteristics 57
TCP/IP Architectural Dominance (支配地位) } TCP/IP protocols matured quicker than similar OSI protocols } When the need for interoperability across networks was recognized, only TCP/IP was available and ready to go } OSI model is unnecessarily complex } Accomplishes in seven layers what TCP/IP does with fewer layers 58
- Slides: 58