ieg 3310 b chapter #2 - internet and tcp page 1. page 2 outline tcp/ip architecture access network...
TRANSCRIPT
IEG 3310 B
Chapter #2 - Internet and TCP
Page 1
Page 2
Outline TCP/IP Architecture Access Network IP, TCP and UDP Socket API
Page 3
TCP/IP architecture OSI TCP/IP
Application
Presentation
Session
Transport
Network
Data Link
Physical
Application
Transport
Internet
Network Interface(Ethernet, ADSL, ATM, etc.)
Page 4
Telnet &
RloginSNMPPing FTP SMTP
Trace-route
DNS TFTPBOOTP
& DHCP
TCP UDP
IPICMP IGMP
Data Link
ARP RARP
Physical Media
TCP/IP protocol graph
UserDatagramprotocol
Transmission ControlProcedure
Page 5
Outline TCP/IP Architecture Access Network IP, TCP and UDP Socket API
Page 6
Network Cabling Cable – allows you to connect devices Connector – standard interface
for making connections.Note: We need different cables & connectors
for different links.
Page 7
Repeater and Hub
1. Repeater
2. Hub – multiple port repeater
<100m<100m
Signal regenerationSignal regeneration
<100m<100m<100m<100m
<100m<100m<100m<100m
The signal is regenerated on all segments
uplinkuplink
Page 8
Switches and Hub
Number of ports: 8/16/24/…
Nature: Hub or Switch (access/core)
Speed: 10/100/1Gbps
Interfaces: Fiber/Copper
Backplane bus: stackability
Uplink: connecting to core switch
Management: SNMP and web
Others:
redundant supply
control console
…
Page 9
Using a Hub or Switch
Straight Through Cable
Computer Hub
1 Tx+ 1 Rx+
2 Tx- 2 Rx-
3 Rx+ 3 Tx+
6 Rx- 6 Tx-
Other lines: unused.
Page 10
Direct ConnectionWe need a cross over cable – one side uses
568A and the other side uses 568B.
WOGBN – Write: Orange Green, bluish brown
Page 11
How to wire many computers?
Structured Cabling and Patch Panels
Page 12
Ethernet Transmissions• The address of a node as defined by its LAN.
• The address in included in an Ethernet frame of data.
•Ethernet uses a six-byte physical address which is imprinted on the network interface card (NIC)
Page 13
Ethernet FramesData is divided into frames. 64-1518 bytes Src address: 6 bytes Dst address: 6 bytes
Page 14
LAN addressingEvery Ethernet node has a built-in, unique MAC
(medium access control) address. It represents the address of the node on a shared Ethernet network.
Finding your MAC address: winipcfg or ipconfig /all
Page 15
Outline TCP/IP Architecture Access Network IP, TCP and UDP Socket API
Page 16
IP Addressing
The Internet (IP) addressing. Each address is represented by4 bytes, denoting(1) Network address(2) Host address
11001010 00101101 10110111 00000001
202.45.183.1
Network-ID Host-ID
Host address=0 the network, host address=1s broadcast.
Page 17
IP Addresses
1 1 1 1 Reserved for future use0
1 1 1 0 Multicast address
1 1 0 netid hostid
1 0 netid hostid
0 netid hostid
Class
A
B
C
D
E
24 bits (16777214)7 bits
14 bits 16 bits (65534)
21 bits 8 bits (254)
CUHK : 137.189.X.X (dotted decimal notation) -> a Class B network
1st Octet netid hostidA 1 - 126 p q.r.sB 128 - 192 p.q r.sC 192 - 223 p.q.r s
Page 18
Internet Domains
IGS1.IE.CUHK.HK
adnetpc0
137.189.96.37
137.152.96.253
137.152.96.254
137.154.96.250
137.148.96.252
AGS.PWH.HK
IGS2.STH.HK137.150.96.252
137.189.96.131
T-1
137.189.96.252
137.154.96.251
137.148.96.47
137.150.96.48
magnet2.pwh.hk
magnet3.sth.hk
adnet1
Page 19
IP Packet Format
PADDING
SOURCE IP ADDRESS
DESTINATION IP ADDRESS
IP OPTIONS (IF ANY)
FRAGMENT OFFSET
TOTAL LENGTH
IDENTIFICATION
0 8 16 31
HLENVERS SERVICE TYPE
FLAGS
HEADER CHECKSUMPROTOCOLTIME TO LIVE
DATA
...
PacketHeader
PacketData
Page 20
How are IP packets routed?
magnet2.pwh.hk
IGS1.IE.CUHK.HK
137.152.96.253
137.152.96.254
137.154.96.250
137.148.96.252
AGS.PWH.HK
IGS2.STH.HK137.150.96.252
137.189.97.37
T-1
137.189.96.252
137.154.96.251
137.148.96.47
137.150.96.48
magnet3.sth.hk
adnetpc0
(1)
(2)
(3)
(4)
IP addresswith net_id routing137.152.0.0 directly137.154.0.0 directly137.148.0.0 directly137.150.0.0 137.154.96.250137.189.0.0 137.152.96.254
Routing table for AGS.PWH.HK
Page 21
IP Routing AlgorithmRoute_IP_Datagram(datagram, routing_table)
Extract destination address, I-d, from datagramCompute IP address of destination network, I-n
If I-n matches any directly connected network addresssend datagram to destination over that network;
else if I-d appears as a host-specific routeroute datagram as specified in the list;
else if I-n appears in routing tableroute datagram as specified in the table;
else if a default route has been specifiedroute datagram to the default gateway;
else declare a routing error;
IP net_id routing137.152.0.0 directly137.154.0.0 directly137.148.0.0 directly137.150.0.0 137.154.96.250137.189.0.0 137.152.96.254
IP net_id routing137.152.0.0 directly137.154.0.0 directly137.148.0.0 directly137.150.0.0 137.154.96.250137.189.0.0 137.152.96.254
Page 22
TCP and UDP
End-to-End Transport Protocola. Connectionless packet delivery service (UDP)b. Reliable Stream Transport service (TCP)
It featuresa. Network technology independenceb. Universal interconnectionc. End-to-end acknowledgmentsd. Application protocol standards
Its major applicationsa. e-mail (SMTP)b. file transfer (FTP)c. remote login (TELNET)d. web (HTTP)
physicalnetwork
router orgateway
Page 23
Relationship of layers and addresses in TCP/IP
Page 24
End-to-end TransportApplication
Transport
Internet
Interface
Internet
Interface
Physicalnetwork 1
Physicalnetwork 1
Application
Transport
Internet
Interface
Gateway G
frame
packet
datagram or transport segment
Frame Data AreaFrame Header
Packet Header Packet Data Area
Header
Kernal
User
H/W
Page 25
Internet Connection via TCP
Page 26
TCP Segment Format
. . .
DATA
DESTINATION PORTSOURCE PORT
0 16 31
OPTIONS (IF ANY)
Segments for connection management, data transfer, andreception acknowledgements.
SEQUENCE NUMBER
ACKNOWLEDGEMENT NUMBER
WINDOWHLEN RESVD CODE BITS
4 10
PADDING
URGENT POINTERCHECKUM
24
Page 27
UDP CHECKSUM
. . .
DATA
UDP MESSAGE LENGTH
UDP DESTINATION PORTUDP SOURCE PORT
UDP Datagram Format 0 16 31
UDP Message length in bytes (Minimum: 8)UDP Checksum is optional (16-bit 1-complement of 1-complement sum)
To be transferred independently by IP packets.
Page 28
How can a server serves multiple clients?
binding: 23-204
1048
TELNET client
23
TELNET Server
7 21
magnet1137.189.96.31
iestp10137.189.96.210
204
TELNET Client
9 208
TCP assigns some well-known ports for communications- server port defines the application.- client port defines the client.
Solution: Connection is identified by a pair of end-points
E.g., (137.189.96.31, 23) and (137.189.96,210, 204)
Page 29
TCP Port numbers
Decimal Keyword Description015791113202123253742537980103104113117119139
--TCPMUXRJEECHODISCARDUSERSDAYTIMEFTP-DATAFTPTELNETSMTPTIMENAMESERVERDOMAINFINGERHTTPX400X400SNDAUTHUUCP-PATHNNTPNETBIOS-SSN
ReservedTCP multiplexerRemote job entryEchoDiscardActive usersDaytimeFile transfer protocol-dataFile transfer protocolTerminal connectionSimple mail transfer protocolTimeHost name serverDomain name serverFingerWeb serverX.400 Mail ServiceX.400 Mail SendingAuthentication ServiceUUCP Path ServiceUSENET news transfer protocolNETBIOS session service
Page 30
UDP Port numbers
Decimal Keyword Description
079111315171937424353676869111123161162513514
--ECHODISCARDUSERSDAYTIME--QUOTECHARGENTIMENAMESERVERNICNAMEDOMAINBOOTPSBOOTPCTFTPSUNRPCNTP--------
ReservedEchoDiscardActive UsersDaytimeWho is up or NETSTATQuote of the DayCharacter GeneratorTimeHost Name ServerWho isDomain Name ServerBootstrap Protocol ServerBootstrap Protocol ClientTrivial File TransferSun Microsystems RPCNetwork Time ProtocolSNMP net monitorSNMP trapsUnix rwho daemonSystem log
Page 31
FTP: File Transfer Protocol
userinterface
user protocol
interpreter
user data transfer
function
serverprotocol
interpreter
serverdata transfer
functionfile systemfile system
user at aterminal
ServerClient
controlconnection
dataconnection
21
20
Commands 3 or 4 bytes NVT ASCII w/wo arguments
Replies 3-digit numbers, optional messages ASCII
Page 32
FTP commands (NVT ASCII)
ABOR
LIST filelist
PASS password
PORT n1,n2,n3,...,n6
QUIT
RETR filename
STOR filename
SYST
TYPE type
USER username
abort previous FTP command and any data transfer
list files or directory
password on server
client IP address (n1..n4) and port (n5x256+n6)
logoff from server
retrieve (get) a file
store (put) a file
server returns system type
specify file type:A (for ascii) I (for image)
username on server
Name Meaning
Page 33
FTP commands and replies
/data/staff/pcwong> ftp -d magnet1Connected to magnet1.220 magnet1 FTP server (SunOS 4.1) ready.Name (magnet1:pcwong): pcwong---> USER pcwong331 Password required for pcwong.Password:---> PASS rachel41230 User pcwong logged in.ftp> dir cantoni.1---> PORT 137,189,96,21,11,33200 PORT command successful.---> LIST cantoni.1150 ASCII data connection for /bin/ls (137.189.96.21,2849) (0 bytes).-rw-r--r-- 1 pcwong staff 1953 Nov 10 18:16 cantoni.1226 ASCII Transfer complete. �remote: cantoni.165 bytes received in 0.11 seconds (0.56 Kbytes/s)ftp> get cantoni.1---> PORT 137,189,96,21,11,34200 PORT command successful.---> RETR cantoni.1150 ASCII data connection for cantoni.1 (137.189.96.21,2850) (1953 bytes).226 ASCII Transfer complete.local: cantoni.1 remote: cantoni.12009 bytes received in 0.051 seconds (39 Kbytes/s)
Page 34
User clicks on http://www.singtao.com/ Ethereal network analyzer captures all frames observed
by its Ethernet NIC Sequence of frames and contents of frame can be
examined in detail down to individual bytes
How do the layers work together?
Internet
Page 35
Top Pane shows
frame/packet sequence
Middle Pane shows
encapsulation for a given frame
Bottom Pane shows hex & text
Page 36
TCP Segment
GET HTTP Request
Page 37
Outline TCP/IP Architecture IP TCP and UDP Socket API
Page 38
Socket API API (Application Programming Interface)
Provides a standard set of functions that can be called by applications
Berkeley UNIX Sockets API Abstraction for applications to send & receive data Applications create sockets that “plug into” network Applications write/read to/from sockets Implemented in the kernel Facilitates development of network applications Hides details of underlying protocols & mechanisms
Also in Windows, Linux, and other OS’s
Page 39
Communications through Socket Interface
Client Server
descriptor
port number
descriptor
port number
• Application references a socket through a descriptor• Socket bound to a port number
Application 1
Socket
Socket interface
User
Kernel
Application 2
User
Kernel
Underlying communication
protocols
Underlying communication
protocols
Communications network
Socket
Socket interface
Page 40
Socket Streams - mode of serviceConnection-oriented First, setup connection
between two peer application processes
Then, reliable bidirectional in-sequence transfer of byte stream (boundaries not preserved in transfer)
Multiple write/read between peer processes
Finally, connection release Uses TCP
Connectionless Immediate transfer of one
block of information (boundaries preserved)
No setup overhead & delay
Destination address with each block
Send/receive to/from multiple peer processes
Best-effort service only Possible out-of-order Possible loss
Uses UDP
Page 41
Client & Server Differences Server
Specifies well-known port # when creating socket May have multiple IP addresses (net interfaces) Waits passively for client requests
Client Assigned ephemeral port # Initiates communications with server Needs to know server’s IP address & port #
DNS for URL & server well-known port # Server learns client’s address & port #
Page 42
socket()
bind()
listen()
read()
close()
socket()
connect()
read()
write()
close()
blocks until server receivesa connect request from client
data
data
Server
Clientaccept()
write()
connect negotiation
Figure 2.17
Connection Stream
Page 43
Java TCP Server import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSente
nce = "Welcome "+ clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); } } }
Page 44
import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; String hostName= “localhost"; // or the server hostname BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket(hostName, 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); } }
Java TCP Client
Page 45
socket()
bind()
sendto()
close()
socket()
bind()
recvfrom()
sendto()
close()
blocks until serverreceives data from client data
data
Server
Client
recvfrom()
Figure 2.18
Datagram Stream
Page 46
import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } } }
Java UDP Server
Page 47
import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName(localhost"); byte[] sendData = new byte[512]; byte[] receiveData = new byte[512]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); System.out.println("Length " + receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } }
Java UDP Client
Thank You