Professional Documents
Culture Documents
1.2 Cc giao thc v dch v trn Internet. 1.3 Gii thiu mt s ng dng mng
Mt s c tnh :
- c lp v hnh thi ca mng. - c lp v phn cng ca mng. - Cc chun giao thc m. - M hnh a ch ton cu. - Nn tng client/server mnh m. - Cc chun v giao thc ng dng mnh m.
Gii thiu
OSI TCP/IP
Application Presentation Session Applications layer Telnet FTP SMTP DNS SNMP
TCP
UDP
ICMP
Network Internet layer (gateway level) ARP IP
Ethernet
Token Ring
FDDI
WANs
TCP/IP
TCP/IP l mt tp ca cc protocols (mt b giao thc) nh ngha cch thc truyn d liu qua mi trng Internet TCP/IP l tn ca m hnh mng c ghp gia hai giao thc chnh trong mng l TCP (Transmission Control Protocol) v IP (Internet Protocol)
McGraw-Hill
TCP/IP v OSI
TCP/IP c xy dng trc m hnh OSI nn cc lp trong b giao thc TCP/IP khng hon ton ging vi b giao thc trong m hnh OSI. C 4 lp trong m hnh TCP/IP lp transport, TCP/IP nh ngha hai protocol l TCP v UDP. lp network, protocol chnh l IP v c cc protocol khc h tr vic truyn d liu lp physical & data link, TCP/IP khng nh ngha protocol no, khng ph thuc vo phn cng bn di Mt mng trong mt lin mng TCP/IP c th l mng LAN, MAN hoc WAN.
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
11
Lp Network
Ni dung:
- Lp Internet - a ch IP - Cc nh a ch, phn mng con - Cc giao thc ph trong lp Network
Lp Internet
M hnh TCP/IP cung cp giao thc lin mng (internetwork protocol -IP), l mt c ch truyn d liu khng tin cy v khng kt ni (connectionless) Cc giao thc h tr cho vic truyn d liu bao gm: ARP, RARP, ICMP v IGMP.
IP (tt)
IP ct d liu ra thnh cc gi. cc gi gi l datagrams, v mi gi c truyn c lp
Datagram c th i theo cc ng khc nhau v c th n khng ng th t hoc trng nhau. IP khng gi thng tin ng i cng nh khng sp xp li cc gi li khi chng n IP l mt dch v connectionless, n khng khi to Virtual Circuits v khng c s thng bo n phn t nhn
Datagram
IP Datagram
Version. Version number of IP current version is 4 (0100 in binary). HLEN. Header length. The HLEN field defines the length of the header in multiple of 4 bytes ( 0 - 15 # maximum 60 bytes) Service type. The service type field defines how the datagram should be handled. It includes bits that define the priority of the datagram. Total length. The total length field defines the total length of the IP datagram. It is a two-byte field (16 bits) and can define up to 65,535 bytes Identification. The identification field is used in fragmentation. A datagram, when passing through different networks, may be divided fragments to match the network frame size. When this happens, each fragment is identified with a sequence number in this field.
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
19
IP Datagram (cont.)
Flags. The bits in this field deal with fragmentation Fragmentation offset. A pointer that shows the offset of the data in original datagram Time to live. The time to live field defines the number of hops a datagram can travel before it is discarded. Protocol. Defined which upper-layer protocol (TCP, UDP, ICMP) Header checksum. Check the integrity of the header Option. Give more functionality to the IP datagram, can control routing, timing, management and alignment
a ch IP
L a ch lun l trong mng xc nh a ch ca cc my trong mng (ngoi a ch vt l) cho vic truyn nhn d liu a ch IP c 32 bit nh phn chia ba phn: class type, netid, hostid
Phn lp a ch
Addressing-Dotted-decimal notation
biu din dng ngn hn v d c, a ch IP c chia thnh dng 4 phn x 8 bit, cch nhau bng du chm, mt phn c biu din theo gi tr thp phn
Examples
What is the class of each of the following addresses?
A. 10011101 10001111 11111110 11001111 B. 01111011 11110000 10101010 11110000 C. 11110101 10001111 11111110 11001111
Solutions
Classes identify
A. Class B B. Class A C. Class E
Dotted-decimal notation
A. 157.143.252.207 B. 221.143.253.15
Mt s a ch IP c bit
Mt my vi nhiu a ch
a ch IP nh ngha cho mi kt ni n mt mng Mt phn t mng c nhiu kt ni n cc mng khc nhau ( v d nh router) phi c cc a ch IP tng ng vi mng Mt my c mt giao tip mng cng c th nh ngha nhiu a ch IP, tu theo nhu cu
A Sample Internetnetwork
Subneting
Hnh minh ho mt mng c hai lp phn cp
Subneting
Khng c subnetting, a ch c 2 lp (bao gm netid v hostid) khng hiu qu, khng th c nhiu mng vt l Vi m hnh ny, cc my khng th t chc thnh cc nhm v cng mt mc. iu ny rt kh cho vic qun l i vi cc mng c nhiu my Phn mng con (subnetting) l gii php cho vn ny, l s chia mt mng ln thnh cc mng nh hn gi l mng con (subnetworks)
Subneting
Hnh v minh ha mng c chia thnh 3 cp
Masking
Masking l cch tnh a ch vt l ca mng t a ch IP, c th tnh k c mng c phn mng con hoc khng Nu c phn mng con, masking s ly c a ch mng t a ch IP Nu mng c chia mng con th masking s ly c thng tin a ch ca mng con (subnetwork address) t a ch IP
Masking example
class A B C D E
Address (e.g.)
15.32.56.7 135.67.13.9
class A B C
Address (e.g.)
15.32.56.7 135.67.13.9
255.255.255.192 201.34.12.72
D
E
N/A
N/A
N/A
N/A
N/A
N/A
- If the masking is at the boundary level (the mask numbers are either 255 or 0), finding the subnetwork address is very easy. Follow these two rules:
1.The bytes in the IP address that correspond to 255 in the mask will be repeated in the subnetwork address 2.The bytes in the IP address that correspond to 0 in the mask will change to 0 in the subnetwork address.
Nonboundary-level Masking
- If the masking is not at the boundary level (the mask numbers are not just 255 or 0), finding the subnetwork address involves using the bit-wise operator. Follow these three rules:
1. The bytes in the IP address that correspond to 255 in the mask will be repeated in the subnetwork address 2. The bytes in the IP address that correspond to 0 in the mask will change to 0 in the subnetwork address. 3. For other bytes, use the bit-wise AND operator.
IP address 45 . 123 . 21 . 8 Mask 255 . 192 . 0 . 0 -------------------------------------------------------Subnetwork 45 . ? . 0 . 0 Address ? use bit-wise AND operator 123 01111011 192 11000000 ----------------------------------0 1 0 0 0 0 0 0 = 64
IP address 213 . 23 . 47 . 37 Mask 255 . 255 . 255 . 240 -------------------------------------------------------Subnetwork 213 . 23 . 47 . ? Address ? use bit-wise AND operator 37 00100101 240 11110000 ----------------------------------0 0 1 0 0 0 0 0 = 32
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
43
IP addressing: CIDR
Classful addressing:
- inefficient use of address space, address space exhaustion - e.g., class B net allocated enough addresses for 65K hosts, even if only 2K hosts in that network
Organization 1
Organization 2
200.23.18.0/23
200.23.20.0/23 . 200.23.30.0/23
Organization 7
ARP v RARP
Vn phn gii a ch
Hai giao thc dng phn gii a ch l ARP (Address Resolution Protocol) v RARP (Reverse ARP)
- ARP dng phn gii a ch IP 32 bits sang a ch Ethernet 48 bits - RARP dng phn gii a ch Ethernet 48 bits sang a ch IP 32 bits
ARP v RARP
a ch mng (lp Internet) v a ch MAC (lp Network Interface) cn c s chuyn i qua li:
- Lp Internet gi d liu cho lp Network Interface, ch cung cp a ch IP ca my nhn - Lp Network Interface cn a ch MAC ca my nhn truyn thng tin
ARP v RARP
ARP
ARP
L giao thc c dng hi a ch vt l mt my khi bit a ch IP Cn cho lp Network Interface ng gi mt Ethernet Frame Khi cn a ch vt l, my s broadcast trn mng hi a ch vt l tng ng vi a ch IP, my c a ch IP tng ng s reply thng tin
RARP operation
RARP packet
Lp transport
network data link physical application transport network data link physical
Lp transport
Cung cp s truyn nhn lun l gia cc process ng dng gia cc my trong mng Cc giao thc lp transport hot ng cc h thng u cui. Lp transport so vi lp network:
- network layer: d liu truyn nhn gia cc h thng - transport layer: d liu c truyn nhn gia cc processes, da trn cc dch v ca lp network v m rng mt s chc nng
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
58
Lp Transport
Lp TCP/IP transport cung cp c ch cho source process gi d liu destination process qua mng nh ngha mt tp cc kt ni mc khi nim cho cc processes gi l protocol ports. Mt protocol port l mt im ch (buffer) dng lu d liu cho mt process c th
Transport layer
Vic qun l giao tip gia cc processes v cc ports tng ng c h iu hnh cung cp Cc protocol lp transport l port-to-port protocols, truyn d liu gia process gi n process nhn Mi port c xc nh bng mt s nguyn dng 16 bits nh phn
Lp Transport
Port Addresses
Transport-layer protocols
Internet transport services: reliable, in-order unicast delivery (TCP)
- congestion - flow control - connection setup
unreliable (best-effort), unordered unicast or multicast delivery: UDP services not available:
Ch thm thng tin v cc a ch port, iu khin li checksum v di thng tin length information
UDP ch cung cp cc chc nng c bn cho c ch truyn end-to-end, khng cung cp cc chc nng x l li v truyn li d liu b hng hoc mt.
TCP
IP v UDP xem cc datagrams trong mt single transmission l cc n v hon ton c lp, khng lin quan vi nhau. Mi datagram n phn t nhn cng l cc n v phn bit, v khng c s thng bo cho phn t nhn Khc vi IP v UDP, TCP l dch v connectionoriented, cung cp c ch truyn tin cy cho ton b stream cha trong message m ng dng gi i C ch truyn tin cy m bo bng vic cung cp vic pht hin li v truyn li nhng d liu hng
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
67
TCP
Khi truyn d liu, TCP chia d liu thnh cc n v nh hn gi l segment. Tt cc cc segment phi c nhn v phn hi (acknowledge) trc khi s truyn nhn hon thnh v mch o c hy Mi segment c mt s tun t (sequencing number) sp xp li sau khi nhn kt hp vi ACK ID number v field window-size cho ca s dch (sliding window) Cc segments TCP truyn trn mng c cha trong cc IP datagrams. phn t nhn, TCP nhn mi datagram theo th t n v da vo s tun t sp xp li
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
68
Control (cont.)
- RST: reset, - SYN: used for sequence number synchronization (connection request, connection confirmation-with ACK set, confirmation acknowledgement-with ACK set) - FIN: used in termination confirmation
Window size. Defines the sliding window Checksum. Used for error detection Urgent Pointer. Valid if URG is set. Define the end of urgent data and the start of normal data
Lp ng dng
Lp ng dng
nh ngha cc giao thc cho cc ng dng mng Nhn gc h iu hnh, ng dng c hiu nh l cc processes. Cc giao thc lp ng dng phi nh ngha cch thc giao tip gia cc processes qua cc vn :
- nh dng ca message - Th t ca cc message trao i - Cc cng vic phi thc thi khi mt process nhn hay truyn d liu
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
73
Lp ng dng
Cc ng dng mng hot ng theo m hnh client/server
- Server : l phn t th ng
- Client : l phn t ch ng
Kt ni n server gi yu cu. Ch nhn kt qu tr v v x l kt qu.
Vn quan trng khi lp trnh cc ng dng mng l nh ngha giao thc gia client v server
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
74
Lp ng dng
User agent l giao tip gia ngi s dng v ng dng mng.Mi ng dng mng client phi c hin thc vic giao tip gia user v chng trnh mng:
M hnh client-server
Cc loi server
Concurrent: x l ng thi, c ch x l nhiu processes trn mt h thng ch c mt CPU
Parallel
Programs v Processes
Server vi c ch multi-process
process
internet
host or server
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
host or server
83
Socket :
- L mi trng cc process ng dng giao tip vi nhau, process ng dng c th chy trn cng mt my hoc trn hai my khc nhau. - c ng dng to ra v s dng tuy nhin c h thng (h iu hnh) kim sot.
Socket API
- c gii thiu BSD4.1 UNIX, 1981 - c ng dng khi to, s dng hay hy b - Dng c ch client/server - Cung cp hai dch v chuyn d liu thng qua socket API:
unreliable datagram reliable, byte stream-oriented
Cc loi socket
Client
create socket, port=x, for incoming request: welcomeSocket = ServerSocket() wait for incoming connection request connection connectionSocket = welcomeSocket.accept()
TCP
setup
create socket, connect to hostid, port=x clientSocket = Socket() send request using clientSocket
class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(6789);
Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket
while(true) {
Socket connectionSocket = welcomeSocket.accept();
} End of while loop, loop back and wait for another client connection
Client
create socket, clientSocket = DatagramSocket()
read request from serverSocket write reply to serverSocket specifying client host address, port number
Create input stream Create client socket Translate hostname to IP address using DNS
InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine(); sendData = sentence.getBytes();
{ 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);
serverSocket.send(sendPacket);
}
End of while loop, loop back and wait for another datagram
H thng e-mail
- giao thc SMTP - giao thc POP3
Zone v domain
nh x a ch trong DNS
Network ch hiu a ch IP (binary) => nh x gia a ch IP v tn. Mi ng dng mng phi chuyn a ch t dng tn sang a ch IP H thng tn min c hin thc theo distributed database, qun l theo dng phn cp vi nhiu name servers
- Kt ni n name server tng ng vi tng domain (trong trng hp root name khng bit thng tin) - Ly thng tin nh x a ch - tr thng tin v cho local name server
C rt nhiu root name server trong mng Internet trn ton th gii
Inverse domain
nh x a ch trong DNS
ng dng giao tip vi local name 2 3 server hi a ch nh x. Local name server local name server dns.eurecom.fr s tr li hoc 1 8 request tip
surf.eurecom.fr
iterated query
4 7
intermediate name server dns.umass.edu
requesting host
gaia.cs.umass.edu
V d
- User nh a ch URL sau ln browser
http://www.dit.hcmut.edu.vn/~phu/courses/net-programming/index.html 1a. http client to TCP connection (to socket) n http server www.dit.hcmut.edu.vn Port 80
time
2. http client gi http request message (cha ng dn) thng qua TCP connection socket
1b. http server a ch www.dit.hcmut.edu.vn ang ch i kt ni port 80, chp nhn kt ni v notifying n client
V d (tt)
3. http server nhn yu cu, to response message (/~phu/courses/netprogramming/index.html) tr kt qu, gi message qua socket
5. http client nhn response time message cha file html v hin th. Phn tch file html tm cc lin kt
W W W (tt)
- C hai dng message trong http : request, response - http request message:
ASCII
(human-readable format)
Browser caches name & password so usual http response msg that user does not have to repeatedly enter it.
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
time
120
client
usual http request msg
server
Set-cookie: #
usual http request msg
cookie: #
cookie: #
client Goal: dont send object if http request msg client has up-to-date If-modified-since: stored (cached) version <date> client: specify date of http response HTTP/1.0 cached copy in http 304 Not Modified request
If-modified-since: <date>
server
object not modified
If-modified-since: <date>
HTTP/1.1 200 OK
object modified
<data>
H thng FTP
user at host
- Chuyn file t local n server hoc ly file t server v local. - Hot ng theo c ch client/server - FTP server chy port 21. - Tham kho : RFC 959
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
123
H thng FTP
ftp client giao tip n ftp server qua TCP port 21 Hai cu ni TCP c thit lp: - control: exchange commands, responses between client, server. out of band control - data: file data to/from server ftp server hin thc c ch state: current directory, earlier authentication
Control connection
Data connection
H thng FTP
Mt s nh dng mesage trong giao thc FTP: D liu c gi qua control channel theo dng m ASCII
- USER username - PASS password - LIST tr v list cc file v th mc trong th mc hin hnh - RETR filename retrieves (gets) file - STOR filename stores (puts) file onto remote host
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
127
H thng FTP
Sample return codes
status code and phrase (as in http) 331 Username OK, password required 125 data connection already open; transfer starting 425 Cant open data connection 452 Error writing file
Mt s lnh ftp c bn
#ftp [host] #open host #close #help #reset #ls #pwd #cd #lcd #mkdir, rmdir #get, mget #put, mput #delete, mdelete #bye
H thng E-mail
H thng E-mail
- RFC 821, 822 - SMTP: port 25 - POP3: port 110 - IMAP: port 143 - MTA: Mail Transfer Agent - UA: User Agent
mail server
SMTP SMTP
mail server
SMTP
user agent
user agent
user agent
MIME header
Base64 Encoding
Quoted-printable encoding
IMAP
- Internet Mail Access Protocol - RFC 1730 - Cc lnh phc tp, cho php c ch lu tr v qun l e-mail trn mail server
POP3
- Post Office Protocol, version 3 - RFC 1939 - ng nhp n mail server v download email c trong mail box ca user v my client
HTTP
- Web-based mail client program - Dng ng dng web hin thc giao thc IMAP hoc POP3
Nguyn Duy Hiu B mn: KTMT & Mng - TBU
141
V d v POP3
authorization phase
client commands:
- user: declare username - pass: password
S: C: S: C: S: C: S: S: S: C: S: S: C: C: S: S: C: C: S:
+OK POP3 server ready user alice +OK pass hungry +OK user successfully logged list 1 498 2 912 . retr 1 <message 1 . dele 1 retr 2 <message 1 . dele 2 quit +OK POP3 server
on
server responses
- +OK - -ERR
contents>
contents>
signing off