Wyv9
?Dy ù?
C Network Application Development
1
Network Application Development
Autumn, 2005
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
2
Self-introduction
ù?
C :
?Associate Professor
?Office: Room 504 of New
Tech. Building
?Tel.:
?0451-86413750(O.)
?0451- 86922927 (H.)
?13351781125
?Email: liquanlong@hit.edu.cn
lql@public.hr.hl.cn
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
3
Reference
? Douglas E. Comer, David L. Stevens, Internetworking with TCP/IP
Vol. III Client-Server Programing and Application, Windows
Sockets Version(??? )b?vD?
2002M 1 5 F Y U # P P L
? Douglas E. Comer, David L. Stevens, Internetworking with TCP/IP
Vol.I, II (??? )b?vD?
2002M 1 b
? Behrouz A. Forouzan & Sophia Chung Fegan, TCP/IP Protocol Suite
??? , b?vD?
2004M 1 b
? James F. Kurose and Keith W. Ross,Computer Networking-A Top-
Down Approach Featuring the Internet (Third Edition)(???
,
Higher Education Press (China) & Pearson Education, 2001.
? William Stallings, Data & Computer Communications (Sixth Edition),
Higher Education Press (China) & Pearson Education, 2001.
? W. Richard Stevens, TCP/IP Illustrated Volume 1,2,3 (??? )
?y<?
2003M 2 b
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
4
Assessment
? Course work- 10%
? Lab- 20%
? Assignment (Mini Project)-20%
? Final examinition-50%
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
5
Course schedule
? Introduction
? Socket API
? Client software design
? Server software design
? Raw socket programming
? Web-based network application development
? RPC/Middleware application development
? P2P application development
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
6
Relationship with other Courses(1)
Physical
Data Link
Network
Transport
Session
Presentation
Application
Concepts&Theory
Typical Net&Protocols
App. Dev & Practice
Computer Networks
Net Planning
& Imp
Net App Dev
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
7
Relationship with other Courses(2)
Physical
Data Link
Network
Transport
Session
Presentation
Application
Computer Net
Net App Dev
Net Planning
&Implementation
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
8
Relationship with other Courses(2)
Concept&Theory
Typical Net&Prot
App Dev & Practice
Computer Net
Net App Dev
Net Planning
&Implementation
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
9
Chapter 1: Introduction
Chapter goal:
? Network basics
? TCP/IP protocols stack
review
? Client-server application
model and software design
? Concurrent processing in
client-server model
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
10
Chapter 1: Introduction
Chapter goal:
? Network basics
? TCP/IP protocols stack
review
? Client-server application
model and software design
? Concurrent processing in
client-server model
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
11
What’s the Internet: “nuts and
bolts” view
? millions of connected
computing devices: hosts,
end-systems
? pc’s workstations, servers
? PDA’s phones, toasters
running network apps
? communication links
? fiber, copper, radio,
satellite
? routers: forward packets
(chunks) of data thru
network
local ISP
company
network
regional ISP
router
workstation
server
mobile
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
12
What’s the Internet: “nuts and
bolts” view
? protocols: control sending,
receiving of msgs
? e.g., TCP, IP, HTTP, FTP,
PPP
? Internet: “network of
networks”
? loosely hierarchical
? Internet standards
? RFC: Request for comments
? IETF: Internet Engineering
Task Force
local ISP
company
network
regional ISP
router
workstation
server
mobile
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
13
What’s a protocol?
? Used for communications between entities
in a system
? Must speak the same language
? Entities
? User applications
? e-mail facilities
? terminals
? Systems
? Computer
? Terminal
? Remote sensor
protocols define format, order
of msgs sent and received
among network entities, and
actions taken on msg
transmission, receipt
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
14
Key Elements of a Protocol
? Syntax
? Data formats
? Signal levels
? Semantics
? Control information
? Error handling
? Timing
? Speed matching
? Sequencing
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
15
Protocol Functions
? Encapsulation
? Segmentation and reassembly
? Connection control
? Ordered delivery
? Flow control
? Error control
? Addressing
? Multiplexing
? Transmission services
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
16
The OSI Model
? The Open Systems Interconnection (OSI) model is defined by
International Standard Organization (ISO) in 1984.
? To open communication between different systems without
changing the underlying architecture (software and hardware).
? An international standard that referenced by most network
vendors for their products and services
? Best tools for teaching people about sending and receiving data
on a network.
? Consist of seven layers: Physical (layer 1), data link (layer 2),
Network (layer 3), Transport (layer 4), Session (layer 5),
Presentation (layer 6) and Application (layer 7). Each of the
layer illustrates a particular network function. This separation
of networking functions is called layering.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
17
7 layers of OSI model
Application
Presentation
Session
Transport
Network
Data link
Physical
Layer 7:
Layer 6:
Layer 5:
Layer 4:
Layer 3:
Layer 2:
Layer 1:
? Advantages of multi-layered
model
? Reduce complexity - simplified
teaching and learning
? Standardize interface
? Allow communication between
different network hardware
and software
? Prevent the change of one layer
from affecting the other layers
? Accelerate Evolution
Some Characteristics for the 7-layer model
? Peer-to-peer process - layer N of one computer (device) can
communicate with layer N on another computer (device) through
protocols of that layer.
? A layer provide service for the layer above it
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
18
Data flow and Peer communication in
OSI layers
Application
Presentation
Session
Transport
Network
Data link
Physical
7
6
5
4
3
2
1
Network
Data link Data link
Physical
Physical
Application
Presentation
Session
Transport
Network
Data link
Physical
7
6
5
4
3
2
1
PC 1 PC 2
Intermediate
node
link
link
For PC1 sends a message to PC2
Physical medium Physical medium
Transport-layer
protocol
Session-layer
protocol
Presentation-layer
protocol
Application-layer
protocol
Data flow Peer communication within layer
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
19
Data Encapsulation
Application
Presentation
Session
Transport
Network
Data link
Physical
7
6
5
4
3
2
1
PC 1
PC 2
User data
AH PH
SH
AH PH SH TH
NH
AH PH SH TH NH DHDT
10101010101011111110000000101010
A-PDU
S-PDU
P-PDU
T-PDU
N-PDU
Application
Presentation
Session
Transport
Network
Data link
Physical
7
6
5
4
3
2
1
User data
AH PH
SH
AH PH SH TH
AH PH SH TH NH
AH PH SH TH NH DHDT
10101010101011111110000000101010
A-PDU
S-PDU
P-PDU
T-PDU
N-PDU
Network
Wrapping of data with necessary protocol
information before network transit
(adding header or trailer or both)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
20
Why Data Encapsulation ?
?To add control information (in form of header or trailer or both)
to the data being encapsulated in order to ensure accurate and
secure communication. The data after encapsulated is called
protocol data unit (PDU)
The control information falls into the three categories:
? Address: The address of the sender and/or receiver may be
indicated.
? Error-detecting code: some sort of frame check sequence
? Protocol control: additional information is included to implement
the protocol functions such as: priority, quality of
service and security
?Note: Headers are added to the data at layers 6,5,4,3, and 2.
Trailers are usually added only at layer2.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
21
Functions of the Physical Layer
10101010111101
DL - PDU
From data link layer
Physical
layer
10101010111101
DL - PDU
To data link layer
Physical
layer
? Physical characteristics of interfaces and media - interface
between the devices and the transmission medium (e.g. network
card). It also defines the type of transmission medium (e.g. wire)
? Representation of bits - encoding the bit (0s and 1s ) into
electrical or optical signals. This layer also defines the type of
encoding (e.g. ASK or FSK)
? Data rate - the transmission rate in term of number of bit sent
each second (e.g. 56 Kb/s)
? Synchronization of bits - the sender and the receiver clocks
must be synchronized
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
22
Functions of the Physical Layer
? Line configuration - the connection of devices to the medium
(point-to-point or multipoint configuration)
? Physical topology - the configuration for the devices to be
connected to form a network (mesh topology, star topology, ring
topology or bus topology)
? Transmission mode - The physical layer also defines the
direction of transmission between two devices: Simplex, half-
duplex, or full-duplex
Example for the physical layer protocol:
? RS-232
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
23
Functions of the Data Link Layer
10101010111101
DHDT
N - PDU
Data
link
layer
Frame
To physical layer
From network layer
10101010111101
DHDT
N - PDU
Data
link
layer
Frame
From physical layer
To network layer
The data link layer is responsible for node-to-node delivery, it
makes the physical layer appear error free to the upper layer
(network layer). It also take care of the following functions:
? Framing - The data link layer divides the stream of bits received
from the network layer into manageable data units called frames
? Physical addressing - the data link layer adds a header to the
frame to define the physical address of the sender (source address)
and/or receiver (destination address) of the frame
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
24
Functions of the Data Link Layer
20
25 32
48
62
Data 20 62
DT
Trailer Source address
destination address
? Flow control - If the rate at which the data are absorbed by the
receiver is less than the rate produced in the sender, the data link
layer will impose a flow control mechanism to prevent overwhelming
the receiver
? Error control - mechanism that can detect and retransmit damaged
or lost frames and also prevent duplication of frames. Error control is
normally achieved by the trailer at the end of the frame
? Access control - When one or more devices are connected to the
same link, data link layer protocols are necessary to determine which
device has control over the link at any given time.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
25
Functions of the Network Layer
N-PDU
NH
T- PDU
Network
layer
packet
To data link layer
From transport layer
N-PDU
NH
T- PDU
Network
layer
packet
From data link layer
To transport layer
? Logical addressing - the network layer adds a header to the
incoming packet from the upper layer with a logical address of the
sender. If a packet passes the network boundary, this universal
(logical) address helps to distinguish whether the packet belong
to the source or destination systems
The network layer is responsible for the source-to-destination
delivery of a packet possibly across multiple networks, if two
systems are connected to the same link, no need for a network layer.
The functions of a network layer are:
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
26
Functions of the Network Layer
? Routing - Router (or gateways) connect independent networks
together, network layer routes the packet to their final destination
by router (gateway).
F
R
K
L
15
D
78
79
DT Data S D 02 46
DT Data S D 23 09
DT Data S D 29 79
The above figure shows the case for a computer "S" communicating with a
remote computer "D". S and D are the logical addresses of the source and
destination computers respectively, where 02 and 79 are the local physical
addresses of the source and destination computers respectively.
T
Ring
Router
Router
U
X
46
23
61
09
29
S A
02
37
C
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
27
Functions of the Transport Layer
T-PDU
S- PDU
Transport layer
To Network layer
From session layer
TH TH TH
T-PDU
T-PDU
T-PDU
S- PDU
Transport layer
From Network layer
To session layer
TH TH TH
T-PDU
T-PDU
segments
segments
? responsible for source-to-destination (end-to-end) delivery of the entire
message
? segmentation occurs and this layer also ensures the whole message arrives
intact and in order
? a logical path can be set up (fixed pathway) between the source and
destination for all packets in a message for additional security.
? This layer has more control over sequencing, flow and error detection and
correction
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
28
Functions of the Transport Layer
Data x y
Data-1 x y S D DHDT
Data-2 x y S D DHDT
Data-1 x y S D
Data-2 x y S D
Transport layer
Network
layer
Data link
layer
S
Data x y
Data-1 x y S D DHDT
Data-2 x y S D DHDT
Data-1 x y S D
Data-2 x y S D
Transport layer
Network
layer
Data link
layer
D
Internet
? Segmentation and re-assembly - A message is divided into
transmittable segments (can be handled by network layer) each
contains a sequence number (for correct re-assembling at the
destination).
? Service-point addressing - the transport layer is responsible for the
delivery of the entire message to the correct process on the computer
( that may be running several programs) by including a service-point
address (port address) in its header.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
29
Functions of the Transport Layer
? Connection control - The transport layer can be either connectionless
or connection-oriented. A connectionless transport layer deliver each
segments as an independent packet to the destination. A connection-
oriented transport layer firstly makes a connection with the transport
layer at the destination, then deliver the packets and after all data are
transferred without error, the connection is terminated.
? Flow control - Transport layer perform end to end flow control which
differs from the data link layer which is responsible for flow control in
single link.
? Error control - The transport layer performs end to end error control
which make sure the entire message arrives at the receiving transport
layer without error (damage, loss or duplication). Error correction is
done by re-transmission.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
30
Functions of the Session Layer
S-PDU
P- PDU
To transport layer
From Presentation layer
SH
Session
layer
syn syn syn
S-PDU
P- PDU
From transport layer
To Presentation layer
SH
Session
layer
syn syn syn
? Dialog control - The session layer allows two systems to enter into a
dialog. The communication between two processes can be controlled in
either half-duplex (one way at a time) or full-duplex (two ways at a time).
The session layer is the network dialog controlling. It establishes,
maintains, and synchronizes the interaction between communication
systems.
? Synchronization - The session layer allows a process to add
checkpoints (synchronization points) into a stream of data, when data
loss during transmission occurred, more efficient re-transmission can be
performed.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
31
Functions of the Presentation Layer
P-PDU
Encoded, encrypted,
and compressed data
PH
A- PDU
Presentation
layer
To session layer
From application layer
P-PDU
Decoded, decrypted,
and decompressed data
PH
A- PDU
Presentation
layer
From session layer
To application layer
The presentation layer is concerned with the syntax and semantics
of the information exchange between two systems.
? Translation - The presentation layer changes (encodes) the sender-
dependent format of the message into a common format that can be
readable by any receiving system
? Encryption - The presentation layer can transform the original
information into an encrypted form to assure privacy.
? Compression - Data compression can reduce the number of bits to be
transmitted, which is important for multimedia transmission.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
32
Functions of the Application Layer
This layers enable the user (human or software) to access the
network by user interfaces. Sometimes, No header or trailers are
added at this layer. Typical services provided by this layer are:
? Network virtual terminal - remote log-in other host in the internet
? File transfer, access, and management - store, retrieve or manage the
files from a remote computer. e.g. File Transfer Protocol (FTP)
? Mail services - e.g. Simple Mail Transfer Protocol (SMTP)
? Directory services - access for global information and services e.g.
Hyper Text Transfer Protocol (HTTP)
Application
layer
User A (U.S.)
HTTP
FTP SMTP
L7 data
Application
layer
User B (Africa)
HTTP
FTP SMTP
L7 data
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
33
Application
Presentation
Session
Transport
Network
Data link
Physical
Summary for the functions of
OSI-layers
allow access to
network
Translate, encrypt,
and compress data
Establish, manage,
and terminate session
Provide reliable end-to-
end message delivery and
error recovery
Move packets from
source to destination; to
provide internetworking
Organize bits into frames;
to provide node-to-node
deliveryTransmit bits over a
medium; to provide
mechanical and electrical
specification
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
34
Chapter 1: Introduction
Chapter goal:
? Network basics
? TCP/IP protocols stack
review
? Client-server application
model and software design
? Concurrent processing in
client-server model
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
35
TCP/IP Protocol Suite
? Dominant commercial protocol
architecture
? Specified and extensively used
before OSI
? Developed by research funded US
Department of Defense
? Used by the Internet
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
36
TCP/IP Protocol Architecture(1)
? Application Layer
? Communication between processes or
applications
? End to end or transport layer (TCP/UDP/…)
? End to end transfer of data
? May include reliability mechanism (TCP)
? Hides detail of underlying network
? Network Layer
? Routing of data
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
37
TCP/IP Protocol Architecture(2)
? Data link Layer
? data transfer between neighboring
network elements
? Physical Layer
? Transmission medium
? Signal rate and encoding
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
38
PDUs in TCP/IP
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
39
Some Protocols in TCP/IP Suite
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
40
IPX/SPX
? Developed by Xerox originally,be
applied in Novell Netware OS later
? Hosts that running Windows
NT/XP/2000/98/95 can connect to
Novell Netware by IPX/SPX
? IPX/SPX is called NWLlink in
Windows NT
? IPX/SPX can be routed like TCP/IP
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
41
IPX/SPX vs OSI
ApplicationNCP
SAP
RIP
Presentation
NetBios Session
SPX Transport
IPX Network
Data LinkMedia+Protocols
Such as Ethernet
Physical
IPX/SPX
OSI Model
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
IPX Protocols
? IPX — Inter-networks Packet eXchange like IP
? SPX — Serial Packet eXchange like TCP
? RIP—routing updates
? SAP—service advertisements
? NCP — NetWare Core Protocol
? NetBIOS emulation
? Design options
– Protocol filters
– Hierarchical design
– EIGRP and NLSP as routing protocols
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
Novell Servers Support Several Client
Stacks
NetBIOS
SPX
IPX
Open Data-Link Interface (ODI)
802.3 802.5 FDDI PPP
IPX IP DDP
NCP NFS AFP
SAA Gateway
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
44
AppleTalk
? Designed to connect Macintosh
computers originally
? Now can be integrated to NetWare
or Microsoft networks
? Be suitable to small net,not large
scale
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
45
AppleTalk vs OSI
Application
Presentation
Session
Transport
Network
Data Link
Physical
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
AppleTalk Protocols
? AppleShare —file sharing
? AFP —AppleTalk interFace Protocol
? ASP —AppleTalk Session protocol
? ATP —AppleTalk Transaction protocol
? RTMP—routing updates
? ZIP—zone information
? NBP—name-to-number translation
? DDP —Datagram Deliver Protocol
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
AppleTalk Protocol Suite
Physical and data link layers
MacTCP
supports
IP stack
AppleTalk network
applications
IP network
applications
AppleTalk higher
layers
RTMP
AARP
DDP
ATP ADSP NBP
ChooserRouting
ZIP
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
Windows Networking
? Based on NetBIOS
– Session-layer protocol
– Name Query—search for a server by name
? Transport protocols
– NetBEUI
– NWLink—NetBIOS over IPX
– NBT—NetBIOS over TCP/IP
? Design options
– Use NWLink or NBT
– Protocol filters
– Hierarchical designs
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
M.S Windows NetBIOS Protocol Stack
Application
Transport
Session
Network
Data Link
Physical
Presentation
Redirector
Server Message
Block (SMB)
NetBIOS
Network
interface card
1
7
6
2
3
4
5
OSI ReferenceNetBIOS
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
NetBIOS
7
? NetBIOS is a session—layer protocol used for
? File sharing
? Printer sharing
? Messaging
? Authentication
? Name resolution
Name Query - Broadcast
Where is File_Server?
Name Query - Broadcast
Where is Print_Server?
Print_
Server
File_
Server
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
Windows Network Transport Mechanisms
? NetBIOS can be transported by
? NetBEUI
? NetBIOS over IPX—NWLink
? NetBIOS over TCP/IP—NBT
NetBIOS
NetBEUI IPX TCP/IP
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
NetBEUI Protocol Stack
? Network-layer
addressing not
included
? Application
traffic must be
bridged
Application
Transport
Session
Network
Data Link
Physical
Presentation
Redirector
Server Message
Block (SMB)
NetBIOS
Network
interface card
1
7
6
2
3
4
5
OSI ReferenceNetBEUI
NetBEUI
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
NetBIOS over IPX—NWLink
? Technical requirements
? Recommended for small- to medium-size networks
? Needs IPX to be operational already
? Carried as IPX type-20 packets
Application
Data Link
NetBIOS
Physical
IPX
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
NetBIOS over TCP/IP—NBT
? Technical requirements
? Recommended for medium-size to large-scale networks
? Needed for networks that include a WAN link
? Depends on an IP address assignment policy
Application
Data Link
NetBIOS
Physical
TCP
IP
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
55
Internet Protocol (IP)
? Part of TCP/IP
? Used by the Internet
? Specifies interface with higher layer
? e.g. TCP
? Only protocol at Layer 3
? Fundamental in suite
? Defines
? Internet addressing
? Internet packet format
? Internet routing
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
56
IP Addressing: introduction
? IP address: 32-bit
identifier for host,
router interface
? interface: connection
between host, router
and physical link
? router’s typically have
multiple interfaces
? host may have multiple
interfaces
? IP addresses
associated with
interface, not host,
router
223.1.1.1
223.1.1.2
223.1.1.3
223.1.1.4 223.1.2.9
223.1.2.2
223.1.2.1
223.1.3.2
223.1.3.1
223.1.3.27
223.1.1.1 = 11011111 00000001 00000001 00000001
223 111
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
57
IP Addressing
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
58
IP Addressing
? IP address:
? network part (high order
bits)
? host part (low order bits)
? What’s a network ?
(from IP address
perspective)
? device interfaces with
same network part of IP
address
? can physically reach each
other without
intervening router
223.1.1.1
223.1.1.2
223.1.1.3
223.1.1.4 223.1.2.9
223.1.2.2
223.1.2.1
223.1.3.2
223.1.3.1
223.1.3.27
network consisting of 3 IP networks
(for IP addresses starting with 223,
first 24 bits are network address)
LAN
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
59
IP Addressing
How to find the
networks?
? Detach each
interface from
router, host
? create “islands
of isolated
networks
223.1.1.1
223.1.1.3
223.1.1.4
223.1.2.2223.1.2.1
223.1.2.6
223.1.3.2223.1.3.1
223.1.3.27
223.1.1.2
223.1.7.0
223.1.7.1
223.1.8.0223.1.8.1
223.1.9.1
223.1.9.2
Interconnected
system consisting
of six networks
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
60
IP Addresses
0
network
host
10
network
host
110 network host
1110
multicast address
A
B
C
D
class
1.0.0.0 to
127.255.255.255
128.0.0.0 to
191.255.255.255
192.0.0.0 to
223.255.255.255
224.0.0.0 to
239.255.255.255
32 bits
given notion of “network”, let’s re-examine IP
addresses:
“class-full” addressing:
E
1111
240.0.0.0 to
255.255.255.255
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
61
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
62
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
63
Special Addresses
Special Address NetID HostID Source or
Destination
Network Address Specific All 0s None
Direct broadcast Address Specific All 1s Destination
Limited broadcast Address All 1s All 1s Destination
This host on this network All 0s All 0s Source
Specific host on this
network
All 0s Specific Destination
Loopback address 127 Any Destination
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
64
Private Addresses
Class NetIDs Blocks
A 10.0.0 1
B 172.16 to 172.31 16
C 192.168.0 to
192.168.255
256
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
65
Subnets and Subnet Masks
? Allow arbitrary complexity of internetworked
LANs within organization
? Insulate overall internet from growth of
network numbers and routing complexity
? Site looks to rest of internet like single
network
? Each LAN assigned subnet number
? Host portion of address partitioned into
subnet number and host number
? Local routers route within subnetted network
? Subnet mask indicates which bits are subnet
number and which are host number
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
66
Subnets and Subnet Mask
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
67
Rules
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
68
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
69
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
70
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
71
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
72
First Subnetwork
000 00000 thru 11111 .0 thru .31
Second Subnetwork
001 00000 thru 11111 .32 thru .63
Third Subnetwork
010 00000 thru 11111 .64 thru .95
Fourth Subnetwork
011 00000 thru 11111 .96 thru .127
Fifth Subnetwork
100 00000 thru 11111 .128 thru .159
Sixth Subnetwork
101 00000 thru 11111 .160 thru .191
Seventh Subnetwork
110 00000 thru 11111 .192 thru .223
Eighth Subnetwork
111 00000 thru 11111 .224 thru .255
Fourth Octet of a Class "C" Network
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
73
First Subnetwork 000 00000 thru 11111 .0 thru .31
Second Subnetwork 001 00000 thru 11111 .32 thru .63
Third Subnetwork 010 00000 thru 11111 .64 thru .95
Fourth Subnetwork 011 00000 thru 11111 .96 thru .127
Fifth Subnetwork 100 00000 thru 11111 .128 thru .159
Sixth Subnetwork 101 00000 thru 11111 .160 thru .191
Seventh Subnetwork 110 00000 thru 11111 .192 thru .223
Eighth Subnetwork 111 00000 thru 11111 .224 thru .255
Which numbers in a subnetwork are
reserved for broadcasts/subnetwork ?
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
74
How does the router handle IP
addresses and subnet masks?
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
75
How does the router handle IP
addresses and subnet masks?
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
76
How does the router handle IP
addresses and subnet masks?
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
77
How does the router handle IP
addresses and subnet masks?
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
78
Supernetting
? Classes A and B are almost deleted
? Class C addresses are available
? One organazition can combine several class
C blocks
? But how?
? Randomly
? S set of rules
? Ramdomly assigning: increase the size of
the routing table
? So supernetting
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
79
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
? CIDR: Classless InterDomain Routing
? network portion of address of arbitrary length
? address format: a.b.c.d/x, where x is # bits in
network portion of address
11001000 00010111 00010000 00000000
network
part
host
part
200.23.16.0/23
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
80
Hierarchical addressing: route
aggregation
“Send me anything
with addresses
beginning
200.23.16.0/20”
200.23.16.0/23
200.23.18.0/23
200.23.30.0/23
Fly-By-Night-ISP
Organization 0
Organization 7
Internet
Organization 1
ISPs-R-Us
“Send me anything
with addresses
beginning
199.31.0.0/16”
200.23.20.0/23
Organization 2
.
.
.
.
.
.
Hierarchical addressing allows efficient advertisement
of routing information:
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
81
Hierarchical addressing: more
specific routes
ISPs-R-Us has a more specific route to Organization 1
“Send me anything
with addresses
beginning
200.23.16.0/20”
200.23.16.0/23
200.23.18.0/23
200.23.30.0/23
Fly-By-Night-ISP
Organization 0
Organization 7
Internet
Organization 1
ISPs-R-Us
“Send me anything
with addresses
beginning 199.31.0.0/16
or 200.23.18.0/23”
200.23.20.0/23
Organization 2
.
.
.
.
.
.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
82
IP datagram format
Ver/4
Length/16
32 bits
data
(variable length,
typically a TCP
or UDP segment)
16-bit identifier
Internet
checksum/16
time to
live/8
32 bit source IP address
IP protocol version
number
header length
(bytes)
max number
remaining hops
(decremented at
each router)
for
fragmentation/
reassembly
total datagram
length (bytes)
upper layer protocol
to deliver payload to
head.
len/4
type of
service/8
“type” of data
flgs/3
fragment
offset/13
upper
layer/8
32 bit destination IP address
Options (if any)
E.g. timestamp,
record route
taken, specify
list of routers
to visit.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
83
IP v6 - Version Number
? IP v 1-3 defined and replaced
? IP v4 - current version
? IP v5 - streams protocol
? IP v6 - replacement for IP v4
? During development it was called IPng
? Next Generation
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
84
Why IPv6?(Theoretical Reasons)
only compelling reason: more IP addresses!
? for billions of new users (Japan, China, India,…)
? for billions of new devices (mobile phones, cars,
appliances,…)
? for always-on access (cable, xDSL, ethernet-to-the-
home,…)
? for applications that are difficult, expensive, or
impossible to operate through NATs (IP telephony,
peer-to-peer gaming, home servers,…)
? to phase out NATs to improve the robustness,
security, performance, and manageability of the
Internet
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
85
Other Benefits of IPv6
? server-less plug-and-play possible
? end-to-end, IP-layer authentication & encryption
possible
? elimination of “triangle routing” for mobile IP
? other minor improvements
NON-benefits:
? quality of service (same QoS capabilities as IPv4)
? flow label field in IPv6 header may enable more efficient
flow classification by routers, but does not add any new
capability
? routing (same routing protocols as IPv4)
? except larger address allows more levels of hierarchy
? except customer multihoming is defeating hierarchy
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
86
IPv6
? Background
? Technology Overview
? Deployment Strategies
? Current Status
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
87
IPv6 Header compared to
IPv4 Header
Ver.
Time to
Live
Source Address
Total Length
Type of
Service
Hdr
Len
Identification
Fragment
Offset
Flg
Protocol
Header
Checksum
Destination Address
Options...
Ver.
Traffic
Class
Source Address
Payload Length
Next
Header
Hop
Limit
Destination Address
Identification
shaded fields have no equivalent in the
other version
IPv6 header is twice as long (40 bytes) as
IPv4 header without options (20 bytes)
Flow Label
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
88
Summary of Header Changes
? Revised
? Addresses increased 32 bits -> 128 bits
? Time to Live -> Hop Limit
? Protocol -> Next Header
? Type of Service -> Traffic Class
? Streamlined
? Fragmentation fields moved out of base header
? IP options moved out of base header
? Header Checksum eliminated
? Header Length field eliminated
? Length field excludes IPv6 header
? Alignment changed from 32 to 64 bits
? Extended
? Flow Label field added
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
89
Text Representation of
Addresses
“preferred” form:
1080:0:FF:0:8:800:200C:417A
compressed form: FF01:0:0:0:0:0:0:43
becomes FF01::43
IPv4-embedded:
0:0:0:0:0:FFFF:13.1.68.3
or ::FFFF:13.1.68.3
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
90
Text Representation of
Addresses (cont.)
address prefix: 2002:43c:476b::/48
(note: no masks in IPv6!)
zone qualifiers: FE80::800:200C:417A%3
in URLs:
http://[3FFE::1:800:200C:417A]:8000
(square-bracket convention also used
anywhere else there’s a conflict with address
syntax)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
91
Basic Address Types
unicast:
for one-to-one
communication
multicast:
for one-to-many
communication
anycast:
for one-to-nearest
communication
M
M
M
A
A
A
U
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
92
ICMP: Internet Control Message
Protocol
? used by hosts, routers,
gateways to communication
network-level information
? error reporting:
unreachable host,
network, port, protocol
? echo request/reply
(used by ping)
? network-layer “above” IP:
? ICMP msgs carried in IP
datagrams
? ICMP message: type, code
plus first 8 bytes of IP
datagram causing error
Type Code description
0 0 echo reply (ping)
3 0 dest. network unreachable
3 1 dest host unreachable
3 2 dest protocol unreachable
3 3 dest port unreachable
3 6 dest network unknown
3 7 dest host unknown
4 0 source quench (congestion
control - not used)
8 0 echo request (ping)
9 0 route advertisement
10 0 router discovery
11 0 TTL expired
12 0 bad IP header
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
93
ICMP Message Formats
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
94
ARP: Address Resolution Protocol
? Each IP node (Host,
Router) on LAN has
ARP module, table
? ARP Table: IP/MAC
address mappings for
some LAN nodes
< IP address; MAC address;
TTL>
< ………………………….. >
? TTL (Time To Live): time
after which address
mapping will be
forgotten (typically 20
min)
Question: how to determine
MAC address of B
given B’s IP address?
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
95
ARP Table
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
96
How do devices use ARP tables
to send data?(1)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
97
How do devices use ARP tables
to send data?(2)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
98
How do devices use ARP tables
to send data?(3)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
99
How do devices use ARP tables
to send data?(4)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
100
How do devices use ARP tables
to send data?(5)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
101
How do devices use ARP tables
to send data?(6)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
102
How do devices use ARP tables
to send data?(7)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
103
How do devices use ARP tables
to send data?(8)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
104
What happens if the device is unable to locate the
destination MAC address in its ARP table?
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
105
ARP message format (IP to Ethernet)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
106
ARP message format (IP to Ethernet)
‘1’-Ethernet
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
107
ARP message format (IP to Ethernet)
Upper layer protocol
address type, for IP,it’s
value is 0806H
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
108
ARP message format (IP to Ethernet)
Hardware Address Length
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
109
ARP message format (IP to Ethernet)
Protocol Address Length
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
110
ARP message format (IP to Ethernet)
‘1’-ARP request
‘2’-ARP response
‘3’-RARP request
‘4’-RARP response
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
111
ARP message format (IP to Ethernet)
Sender Hardware
Address
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
112
ARP message format (IP to Ethernet)
Sender IP Address
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
113
ARP message format (IP to Ethernet)
Target Hardware
Address
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
114
ARP message format (IP to Ethernet)
Target IP Address
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
115
ARP protocol
? A knows B's IP address, wants to learn
physical address of B
? A broadcasts ARP query pkt, containing B's
IP address
? all machines on LAN receive ARP query
? B receives ARP packet, replies to A with its
(B's) physical layer address
? A caches (saves) IP-to-physical address pairs
until information becomes old (times out)
? soft state: information that times out
(goes away) unless refreshed
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
116
Routing in the Internet
? The Global Internet consists of Autonomous
Systems (AS) interconnected with each other:
? Stub AS: small corporation
? Multihomed AS: large corporation (no transit)
? Transit AS: provider
? Two-level routing:
? Intra-AS: administrator is responsible for choice
? Inter-AS: unique standard
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
117
Internet AS Hierarchy
Inter-AS border (exterior gateway) routers
Intra-AS interior (gateway) routers
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
118
Intra-AS Routing
? Also known as Interior Gateway Protocols
(IGP)
? Most common IGPs:
? RIP: Routing Information Protocol
? OSPF: Open Shortest Path First
? IGRP: Interior Gateway Routing Protocol
(Cisco propr.)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
119
RIP ( Routing Information Protocol)
? Distance vector algorithm
? Included in BSD-UNIX Distribution in 1982
? Distance metric: # of hops (max = 15 hops)
? Can you guess why?
? Distance vectors: exchanged every 30 sec via
Response Message (also called advertisement)
? Each advertisement: route to up to 25
destination nets
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
120
RIP (Routing Information Protocol)
Destination Network Next Router Num. of hops to dest.
w A2
y B2
z B7
x -- 1
…. …. ....
w
xy
z
A
C
D
B
Routing table in D
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
121
RIP: Link Failure and Recovery
If no advertisement heard after 180 sec -->
neighbor/link declared dead
? routes via neighbor invalidated
? new advertisements sent to neighbors
? neighbors in turn send out new
advertisements (if tables changed)
? link failure info quickly propagates to
entire net
? poison reverse used to prevent ping-pong
loops (infinite distance = 16 hops)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
122
RIP Table processing
? RIP routing tables managed by application-
level process called route-d (daemon)
? advertisements sent in UDP packets,
periodically repeated
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
123
RIP Table example (continued)
Router: giroflee.eurocom.fr
? Three attached class C networks (LANs)
? Router only knows routes to attached LANs
? Default router used to “go up”
? Route multicast address: 224.0.0.0
? Loopback interface (for debugging)
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
127.0.0.1 127.0.0.1 UH 0 26492 lo0
192.168.2. 192.168.2.5 U 2 13 fa0
193.55.114. 193.55.114.6 U 3 58503 le0
192.168.3. 192.168.3.5 U 2 25 qaa0
224.0.0.0 193.55.114.6 U 3 0 le0
default 193.55.114.129 UG 0 143454
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
124
OSPF (Open Shortest Path First)
? “open”: publicly available
? Uses Link State algorithm
? LS packet dissemination
? Topology map at each node
? Route computation using Dijkstra’s algorithm
? OSPF advertisement carries one entry per
neighbor router
? Advertisements disseminated to entire AS
(via flooding)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
125
OSPF “advanced” features (not in RIP)
? Security: all OSPF messages authenticated
(to prevent malicious intrusion)
? Multiple same-cost paths allowed (only one
path in RIP)
? For each link, multiple cost metrics for
different TOS (eg, satellite link cost set
“low” for best effort; high for real time)
? Integrated uni- and multicast support:
? Multicast OSPF (MOSPF) uses same topology data
base as OSPF
? Hierarchical OSPF in large domains.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
126
Hierarchical OSPF
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
127
Hierarchical OSPF
? Two-level hierarchy: local area, backbone.
? Link-state advertisements only in area
? each nodes has detailed area topology; only
know direction (shortest path) to nets in
other areas.
? Area border routers: “summarize” distances
to nets in own area, advertise to other Area
Border routers.
? Backbone routers: run OSPF routing limited
to backbone.
? Boundary routers: connect to other ASs.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
128
IGRP (Interior Gateway Routing Protocol)
? CISCO proprietary; successor of RIP
(mid 80s)
? Distance Vector, like RIP
? several cost metrics (delay,
bandwidth, reliability, load etc)
? uses TCP to exchange routing updates
? Loop-free routing via Distributed
Updating Alg. (DUAL) based on
diffused computation
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
129
Inter-AS routing
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
130
Internet inter-AS routing: BGP
? BGP (Border Gateway Protocol): the de
facto standard
? Path Vector protocol:
? similar to Distance Vector protocol
? each Border Gateway broadcast to
neighbors (peers) entire path (I.e,
sequence of ASs) to destination
? E.g., Gateway X may send its path to dest.
Z:
Path (X,Z) = X,Y1,Y2,Y3,…,Z
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
131
Internet inter-AS routing: BGP
Suppose: gateway X send its path to peer
gateway W
? W may or may not select path offered by X
? cost, policy (don’t route via competitors
AS), loop prevention reasons.
? If W selects path advertised by X, then:
Path (W,Z) = w, Path (X,Z)
? Note: X can control incoming traffic by
controlling it route advertisements to peers:
? e.g., don’t want to route traffic to Z ->
don’t advertise any routes to Z
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
132
Internet inter-AS routing: BGP
? BGP messages exchanged using TCP.
? BGP messages:
? OPEN: opens TCP connection to peer and
authenticates sender
? UPDATE: advertises new path (or
withdraws old)
? KEEPALIVE keeps connection alive in
absence of UPDATES; also ACKs OPEN
request
? NOTIFICATION: reports errors in
previous msg; also used to close connection
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
133
IGMP
? Internet Group Management Protocol
? RFC 1112
? Host and router exchange of
multicast group info
? Use broadcast LAN to transfer info
among multiple hosts and routers
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
134
IGMP Format
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
135
IGMP Fields
? Version
? 1
? Type
? 1 - query sent by router
? O - report sent by host
? Checksum
? Group address
? Zero in request message
? Valid group address in report message
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
136
IGMP Operation
? To join a group, hosts sends report message
? Group address of group to join
? In IP datagram to same multicast destination
address
? All hosts in group receive message
? Routers listen to all multicast addresses to hear all
reports
? Routers periodically issue request message
? Sent to all-hosts multicast address
? Host that want to stay in groups must read all-
hosts messages and respond with report for each
group it is in
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
137
Group Membership in IPv6
? Function of IGMP included in ICMP v6
? New group membership termination
message to allow host to leave group
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
138
UDP: User Datagram Protocol [RFC 768]
? “no frills,” “bare bones”
Internet transport
protocol
? “best effort” service, UDP
segments may be:
? lost
? delivered out of order
to app
? connectionless:
? no handshaking between
UDP sender, receiver
? each UDP segment
handled independently
of others
Why is there a UDP?
? no connection
establishment (which
can add delay)
? simple: no connection
state at sender,
receiver
? small segment header
? no congestion control:
UDP can blast away as
fast as desired
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
139
UDP: more
? often used for
streaming multimedia
apps
? loss tolerant
? rate sensitive
? other UDP uses
(why?):
? DNS
? SNMP
? reliable transfer over
UDP: add reliability at
application layer
? application-specific
error recover!
source port # dest port #
32 bits
Application
data
(message)
UDP segment format
length checksum
Length, in
bytes of UDP
segment,
including
header
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
140
TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581
? full duplex data:
? bi-directional data flow
in same connection
? MSS: maximum segment
size
? connection-oriented:
? handshaking (exchange
of control msgs) init’s
sender, receiver state
before data exchange
? flow controlled:
? sender will not
overwhelm receiver
? Congestion controlled
? point-to-point:
? one sender, one receiver
? reliable, in-order byte
stream:
? no “message boundaries”
? pipelined:
? TCP congestion and flow
control set window size
? send & receive buffers
socket
door
TCP
send buffer
TCP
receive buffer
socket
door
segment
application
writes data
application
reads data
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
141
TCP segment structure
source port # dest port #
32 bits
application
data
(variable length)
sequence number
acknowledgement number
rcvr window size
ptr urgent data
checksum
FSRPAU
head
len
not
used
Options (variable length)
URG: urgent data
(generally not used)
ACK: ACK #
valid
PSH: push data now
(generally not used)
RST, SYN, FIN:
connection estab
(setup, teardown
commands)
# bytes
rcvr willing
to accept
counting
by bytes
of data
(not segments!)
Internet
checksum
(as in UDP)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
142
Application protocols
? http
? ftp
? tftp
? smtp
? pop
? Dns
? Telnet
? RTSP
? RTP
? RTCP
? RSVP
? ……
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
143
Chapter 1: Introduction
Chapter goal:
? Network basics
? TCP/IP protocols stack
review
? Client-server application
model and software design
? Concurrent processing in
client-server model
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
144
Why need new applications
? Well-known applications can not satisfy
specific requirement
? In fact, over 1/5 traffic is not well-known
applications
? New applications (application protocols) are
developed every day
? Emphasis shifts from building networks to
using them
? More programmers need to know the
functional principles and techniques used to
design and implement distributed/network
applications
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
145
Functionality
?Transport layer and layers below
?Basic communication
?Reliability
?Application layer
?Abstractions
? Files
? Services
? Databases
?Names
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
146
Dichotomy of Duties
? Network
? Transfers bits
? Operates at application’s request
? Applications determine
? What to send
? When to send
? Where to send
? Meaning of bits
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
147
How Two Application Programs
Make Contact-Rendezvous
? One application
? Begins execution first
? Waits passively at prearranged location
? Another application
? Begins execution later
? Actively contacts first program
? Called client-server interaction
? Why?
? TCP/IP does not provide any mechanisms that
automatically create running programs when a
message arrives
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
148
Client-Server Paradigm
? Used by almost all network applications
? Passive program called a server
? Active program called a client
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
149
Internet Communication
Almost all network applications use a
form of communication known as the
client-server paradigm. A server
application waits passively for
contact, while a client application
initiates communication actively.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
150
Characteristics of a Client
? Arbitrary application program
? Becomes client temporarily
? Can also perform other computations
? Invoked directly by user
? Runs locally on user’s computer
? Actively initiates contact with a
server
? Contacts one server at a time
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
151
Characteristics of a Server
? Special-purpose, privileged program
? Dedicated to providing one service
? Can handle multiple remote clients simultaneously
? Invoked automatically when system boots
? Executes forever
? Needs powerful computer and operating system
? Waits passively for client contact
? Accepts requests from arbitrary clients
? Servers can handle:
? Authentication
? Authorization
? Data security
? Privacy
? protection
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
152
Direction of Data Flow
?Data can flow
?From client to server only
?From server to client only
?In both directions
?Application protocol determines flow
?Typical scenario
?Client sends request(s)
?Sever sends response(s)
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
153
Key Idea
Although the client initiates contact,
information can flow in either or both
directions between a client and server.
Many services arrange for the client to
send one or more requests and the server
to return one response for each request.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
154
Clients, Servers, and Other
Protocols
? Clients and servers are application
programs
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
155
Identifying a Service
? Protocol port number used
? Each service given unique port number, P
? Server
?Informs OS it is using port P
?Waits for requests to arrive
? Client
?Forms request
?Send request to port P on server computer
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
156
The Point About Ports
Transport protocols assign each service a
unique port identifier. A server must
specify the identifier when it begins
execution. A client must specify the
identifier when it requests transport
protocol software to contact a server.
Protocol software on the server computer
uses the identifier to direct an incoming
request to the correct server.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
157
In Theory
? Port numbers are merely integers
? Any server could use any port number
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
158
In Practice
? Protocol port numbers used as service
identifiers
? Need uniform numbering
?To allow arbitrary client to contact server on
arbitrary machine
?To avoid inventing “directory assistance”
mechanism
? Port numbers
?Uniform throughout Internet
?Set by standards bodies
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
159
Stateless VS. Stateful Servers
? State information: Information that a server
maintains about the status of ongoing interactions
with clients.
? Stateless servers: Do not keep any state
information.
? Stateful servers: keep state information.
? Keeping a small information in a server can reduce
the size of messages that the client and server
exchange.
? Stateful design leads to complex application
protocols.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
160
Chapter 1: Introduction
Chapter goal:
? Network basics
? TCP/IP protocols stack
review
? Client-server application
model and software design
? Concurrent processing in
client-server model
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
161
Concurrency in networks
? Concurrency refers to real or apparent
simultaneous computing
? Among machines on a single network, many pairs of
applications can communicate concurrently
? Concurrency can also occur within a given
computer system
? The application programmer designs and
constructs each client program without regard to
concurrent execution
? Operating system allows users to execute client
programs concurrently
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
162
Concurrency in networks
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
163
Concurrency in servers
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
164
Terminology and concepts
? Process abstraction defines the fundamental unit
of computation.
? Some system use the terms of task or job instead
of process
? Instruction pointer: (the most essential information
associated with process) specifies the address at
which the process is executing.
? Other information associated with process
? Identity of the user that owns it
? The compiled program that it is executing
? The memory locations of process’ program text and data
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
165
Terminology and concepts
? A process is different from a program
? The process concept includes only the active
execution of a program, not the code
? After the code has been loaded into a computer,
the OS allows one or more processes to execute
it.
? Each process has a separate instruction pointer
that specifies which instruction it will execute
next and its own copy of variables.
? On a uniprocessor architecture, concurrent
execution means “apparently simultaneous
execution”.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
166
Important concept
? Application programmers build
programs for a concurrent environment
without knowing whether the
underlying hardware consists of a
uniprocessor or a multiprocessor.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
167
Terminology and concepts
? Threads
? Some OS, such as Win98/2000/XP,
provide a second form of concurrent
execution known as threads of execution.
? A thread has its own instruction pointer
and copy of local variables, and it
executes independently of other threads.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
168
Terminology and concepts
? A thread mechanism differs from a process
mechanism
? Each thread must be associated with a single process.
? Although each thread in process has its own copy of local
variables, all threads in a process share access to a single
copy of global variables.
? All threads in a process share resources that the OS
allocates to the process, including the descriptors used for
network communication.
? A concurrent program can be written either to
create separate processes or to create multiple
threads in a single process.
? One of the potential disadvantages of a
multithreaded design is interference.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
169
Terminology and concepts
? Programs vs. Threads
? A conventional application program is
merely a special case
? It consists of a piece of code that is executed
by exactly one thread at a time.
? When multiple threads execute a piece of
code concurrently
? Each thread has its own, independent copy of
the local variables associated with the code.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
170
Terminology and concepts
? Procedure calls
? If multiple threads execute code concurrently,
they can each be at a different point in the
sequence of procedure calls.
? The run-time system for procedure-oriented
programming languages uses a stack mechanism to
handle procedure calls.
? The run-time system pushes a procedure activation
record on the stack whenever it makes a procedure call.
? When multiple threads execute a piece of code
concurrently, each has its own run-time stack of
procedure activation records.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
171
An example of concurrent thread creation
? A sequential C example
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
int addem(int);
int main(int argc, char *argv[])
{ addem(5);
return 0;}
int addem(int count)
{inti, sum;
sum = 0;
for (i=0; i<=count; ++i) {
printf("The value of i is %d\n", i);
fflush(stdout);
sum += i;
}
printf("The sum is %d\n", sum);
fflush(stdout);
return 0;
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
172
An example of concurrent thread creation
? Output of sequential C example
The value of i is 0
The value of i is 1
The value of i is 3
The value of i is 4
The value of i is 5
The sum is 15
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
173
An example of concurrent thread creation
? A concurrent version
? In Windows, a new thread can be created by calling _beginthread
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
int addem(int);
int main(int argc, char *argv[])
{ _beginthread((void (*)(void *))addem, 0, (void *)5);
addem(5);
return 0;}
int addem(int count)
{ int i, sum;
sum = 0;
for (i=0; i<=count; ++i) {
printf("The value of i is %d\n", i);
fflush(stdout);
sum += i;}
printf("The sum is %d\n", sum);
fflush(stdout);
return 0;}
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
174
An example of concurrent thread creation
? Output of concurrent version
The value of i is 0
The value of i is 1
The value of i is 2
The value of i is 0
The value of i is 1
The value of i is 3
The value of i is 4
The value of i is 2
The value of i is 3
The value of i is 4
The value of i is 5
The sum is 15
The value of i is 5
The sum is 15
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
175
Timeslicing
? A timeslicing mechanism attempts to
allocate the available processing equally
among all available threads.
? Think about next example, and imagine
what kind of output it will create.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
176
Timeslicing
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
int addem(int);
int
main(int argc, char *argv[])
{ _beginthread((void (*)(void *))addem, 0, (void *)10000);
addem(10000);
return 0;}
int
addem(int count)
{inti, sum;
sum = 0;
for (i=0; i<=count; ++i) {
printf("The value of i is %d\n", i);
fflush(stdout);
sum += i;
}
printf("The sum is %d\n", sum);
fflush(stdout);
return 0;
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
177
Diverging threads
? In practice, multiple threads in a concurrent
program seldom execute a single procedure.
? Usually, each thread executes its own
procedure.
? How can thread diverge?
? The first argument to _beginthread specifies a
procedure for newly created thread to execute.
? The parent continues execution at the point
following the call to _beginthread.
? For example:
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
178
Diverging threads
_beginthread((void (*)(void *))addem, 0, (void *)5);
proc2( );
? The parent thread first calls _beginthread
and then calls proc2.
? The child thread begins executing addem
with an argument of 5.
? The child thread is created to call addem(5);
? If the call to addem returns, the thread
ceases execution.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
179
Context switching and protocol
software design
? When the OS temporarily stops executing
one thread and switches to another, a
context switch has occurred.
? Switching context requires use of CPU
? We view context switching as the overhead
needed to support concurrent processing.
? To avoid unnecessary overhead, protocol
software should be designed to minimize
context switching.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
180
Concurrency and asynchronous I/O
? In addition to providing support for
concurrent use of CPU, some OS allow a single
application program to initiate and control
concurrent input and output operations.
? In Windows, the select socket function
provides a fundamental operation that
programmers use to manage concurrent I/O.
? Select function allows a program to ask the
OS which source of I/O is ready for use.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
181
Concurrency under UNIX
? UNIX offers a process abstraction.
? To become concurrent, a UNIX application calls the
system function fork.
? fork does not take any arguments.
? fork create another process executing at exactly the
same location as the original.
? The value returned by the UNIX fork function
differs in the original and newly created processes.
? Concurrent programs use the difference to allow the
new process to execute different code than the
original process.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
182
Executing a separately compiled
program
? Both Windows and UNIX provide a mechanism that
allows any process to stop executing one application
and begin executing an independent program that has
been compiled separately and stored on disk.
? Using a family of OS functions named exec.
? Under UNIX, both fork and exec are used to create a
new process to run another program.
? Under windows, a single function, CreateProcess,
handles both tasks.
? Servers that handle many services can use exec to
simplify the server program.
Wyv9
?Dy ù?
C Network Application Development 1: Introduction
183
Summary
Learned:
? Network basics
? TCP/IP protocols review
? Client-server application model and
software design
? Concurrent processing in client-server
model