Documente Academic
Documente Profesional
Documente Cultură
Network programming:
Chap 1: Introduction to networking
Dr. Mohamad Chaitou LIU
Course contents
10/15/2010
Course contents
File Handling, Serialisation (2 weeks)
File transfer
Mohamad Chaitou
Assessment
Assignments & Participations: Weekly assignments due every Wednesday at the beginning of class time. (10 percent) Tests & Final Examination: Each test takes place according to the following table:
Test Number Assg & Part MID I Project Final Exam* December 1st, 2010 JAN 14th, 2011 TBA 3 hours 90 minutes Date Duration Weight 10% 25% 25% 40%
Mohamad Chaitou
10/15/2010
Advantages:
Resource sharing, e.g. Printers, memory space (file server), processor (Application server or distributed application). Data exchange and communication: Networks provide new ways of communication and of data exchange, for example, teleconference, email servicesetc.
Mohamad Chaitou
Network classification
By size:
PAN, LAN, MAN, WAN
By topology:
Mesh, bus, ring, star,etc.
By performance:
Bandwidth and delay By the type of terminals:
Telephony network Computer network Home network
Mohamad Chaitou
6
10/15/2010
WAN
PAN
LAN
Local area networks
MAN
Metropolitan area networks
1m
Mohamad Chaitou
10 m
100 m
1 Km
10 Km
100 Km
7
By topology
Mesh:
Full:
each node is connected to all other nodes Rarely used because it need n(n-1)/2 cables!
Partial mesh:
Each node is connected to a few number of nodes Use of routing/switching protocols to go from node to node
BUS or Ring:
Each node is connected to a shared bus or ring Used in Ethernet LAN
Star:
All nodes are connected to a central node
8
Mohamad Chaitou
10/15/2010
By performance
Mohamad Chaitou
Mohamad Chaitou
10
10/15/2010
Computer network
A set of computer connected between them by the same technology
Mohamad Chaitou
11
Wireless networks
Multiple technologies:
GSM, 3G, 3G+, 4G Wireless LAN (standard IEEE 802.11): up to 54 Mbit/s for several meters
Example: WIFI, ADHOC, BLUETOOTH
Mohamad Chaitou
12
10/15/2010
Standarization
IETF (Internet Engineering Task Force):
Regroups: constructors, network operators and researchers from all the world It aims to produce standards called RFC (Request For Comments) for protocols covered by the technology TCP/IP. It aims also to ensure a long-term development of the Internet
Mohamad Chaitou
13
The study of the network is reduced to that of its parts, the whole becomes easier to manipulate
Mohamad Chaitou
14
10/15/2010
upper layers:
application management applications taken over by the terminal layers 5-7
Mohamad Chaitou
15
10/15/2010
Mohamad Chaitou
17
10/15/2010
Mohamad Chaitou
19
Receiver
Application Presentation Session Transport Network Link Physical
Sender
Application Presentation Session Transport Network Link Physical Link Physical
Router
Receiver
Application Presentation Session Transport Network Link Physical Link Physical
Switch
Mohamad Chaitou
20
10
10/15/2010
Primitives:
constitute the basis of dialogue between the adjacent layers in the equipment. There are 4 types: request, indication, response and confirmation. They are used by the layer n requesting a service from layer n-1 and offering the service to layer n +1.
Protocols
rules defining the dialogue between the layers of the same level for two terminals in communication. The precise specification of protocols implies that there is a detailed division of functions between the terminals.
Mohamad Chaitou
21
Introduction to Internet
A little history on the Internet:
Research from the DARPA
Defense Advanced Research Projects Agency ARPANET network
first network packet (beginning 1970) point to point links (terrestrial, radio, satellite)
DARPA will require that all machines of ARPANET have to use TCP / IP TCP / IP is then integrated into the UNIX world
Entering into the academic world
Mohamad Chaitou
22
11
10/15/2010
Introduction to Internet
What is the Internet?
virtual network constructed by interconnecting physical networks through gateways: Routers need for a universal communication service
TCP / IP allows the use of applications without knowing the technology and architecture of the Internet
Network 1
network 2
Network 3 3
Mohamad Chaitou
23
Introduction to Internet
Users view of the Internet
Internet
Mohamad Chaitou
24
12
10/15/2010
Introduction to Internet
Reality of the Internet
Mohamad Chaitou
25
The IP layer
IP: Internet Protocol (RFC 791) comparable to the layer 3 of OSI model (Network) IP is operating over everything
it is the convergence protocol It works on all existing level 2 protocols:
Ethernet (RFC 894) Token-Ring (RFC 1469) Serial connexion: SLIP (RFC 1055), PPP (RFC 1353), X25 (RFC 877), FR (RFC 1294) FDDI (RFC 1188) ATM (RFC 1483, RFC 1577, LANE)
Mohamad Chaitou
26
13
10/15/2010
The IP layer
The TCP/IP model and the OSI model
Mohamad Chaitou
27
The IP datagram
The format of the IP datagram
Minimum 20 bytes
IP header 1 16 17
Type-ofType-of-service Flags Protocol Source address Destination address Options (+ padding)
Data 8 9 19 20
Total length Fragement Offset Header checksum
4 5
Version IHL
32
Identification Time-toTime-to-live
Data (variable)
Mohamad Chaitou
28
14
10/15/2010
IP Module
Datagram arrival
Mohamad Chaitou
29
The IP datagram
Source @ field (32 bits): @ IP of the transmitter Destination @ field (32 bits): @ IP of the destination These are the addresses of the end machines and not those of intermediate equipments! Options field (variable size): Allows extensions
option code (1 byte) + length of option (1 byte) + data associated
Mohamad Chaitou
30
15
10/15/2010
ICMP
Internet Control Message Protocol (RFC 792)
Protocol of 'management' of the network
error reporting mechanisms
Mohamad Chaitou
31
ICMP
Using ICMP: PING (Packet INternet Groper)
To verify IP connectivity equipment with other network equipment By default: sending 4 queries and waiting for 4 answers Example:
Mohamad Chaitou
32
16
10/15/2010
IP addressing, DNS
The IP addresses:
consists of 4 bytes (32 bits) notation "dotted decimal" : X.X.X.X with 0 <= X <= 255 Example: 130.190.57.12 2 distinct parts:
network address: network ID assigned by an authority, identifies the network machine address: host ID assigned by the administrator, identifies the machine (host)
Mohamad Chaitou
33
Mohamad Chaitou
34
17
10/15/2010
IP addressing
32 bits
Network id
8 bits 8 bits 8 bits
Host id
8 bits
Binary notation Decimal notation Classe A 16 777 214 machines Classe B 65 534 machines Classe C 254 machines
Mohamad Chaitou
. . . . .
01010101 85
host
0 to 255 0 to 255
. . . . .
00110011 51
host host
0 to 255
. . . . .
11001100 204
35
TNA - 28/08/02
IP addressing
The concept of sub-networks (subnetting)
pure classes -> limited flexibility, waste places Cutting the network into smaller entities:
decided by the network administrator
@initial network id @initial host id
@ network
@ subnet
@ @ htehost
@final host id
@final net id
This division may be unknown to the outside All network devices must use the notion of sub-networks (PC, routers, printers, ...) Interconnection of subnets by routers
Mohamad Chaitou
36
18
10/15/2010
IP addressing
The division is made possible by using a subnet mask :
same notation as the IP address (32 bits): X.X.X.X X values: 0, 128, 192, 224, 240, 248, 252, 255 bit 1 -> designate the network portion bit 0 -> means the party host
Mohamad Chaitou
IP addressing
Subnetting IP Address (1st method) IP: 170.85.51.204 Subnet Mask: 255.255.248.0 or / 21
170 85 51 204
10101010
255
11111111
170
10101010
0
00000000
. . . .
01010101
255
11111111
85
01010101
0
00000000
. . . .
00110011
248
11111 000
48
00110 000
3
00000 011
. . . .
11001100
0
@ IP Mask
00000000
0
00000000
204
@ network @ host
11001100
19
10/15/2010
IP addressing
Subnetting (2nd method): complement to 255 IP address: 170.85.51.204 Subnet Mask: 255.255.248.0 or / 21 what is the @ Network and the @ of the host?
(255 - 248) + 1 = 8 (the value used for sub-network partitioning) subnet 1 : 170.85.0.x to 170.85.7.x subnet 2 : 170.85.8.x to 170.85.15.x subnet 3 : 170.85.16.x to 170.85.23.x subnet 4 : 170.85.24.x to170.85.31.x subnet 5 : 170.85.32.x to 170.85.39.x subnet 6 : 170.85.40.x to 170.85.47.x subnet 7 : 170.85.48.x to 170.85.55.x etc until 170.85.255.x
Mohamad Chaitou
39
Mohamad Chaitou
40
20
10/15/2010
The combination of two (IP address - port number) completely defines a TCP or UDP flow:
ex: 130.190.5.1 - 23 and 147.171.150.2 1094
User 147.171.150.2 took a telnet in 130.190.5.1
Mohamad Chaitou
41
Ports are coded on 16 bits: 65536 possibilities Ports 0-1023: Well Known Ports
assigned by the IANA: only to be used by system processes or programs executed by privileged users
ports 1024-49151: registered ports (Registered) Ports 49152 to 65535: dynamic or private ports All equipment TCP / IP must respect this allocation
Mohamad Chaitou
42
21
10/15/2010
UDP
User Datagram Protocol
connectionless service, no warranty, using IP to transport messages between machines UDP segment is contained in an IP datagram
8 octets
IP header
UDP header
IP data
Data
1
Source Port Length
16 17
Destination Port Checksum
32
Mohamad Chaitou
43
UDP
Compared to IP, UDP adds information indicating the service used:
snmp
ntp
tftp
Port 161
Port 123
Port 69
UDP multiplexing
Datagram UDP
IP layer
44
Mohamad Chaitou
22
10/15/2010
UDP
UDP does not:
connected mode packet retransmission if errors or losses sequencing of packets Flow Control -> very easy to saturate a LAN or router! (Streaming audio / video)
Mohamad Chaitou
45
TCP protocol
Transmission Control Protocol The TCP / IP is enabled on all network devices with IP (routers, workstations, ...) The aim is to transport data:
end to end between applications connected mode: establishement/closure of sessions without error: control and retransmission if necessary Lossless: "dial" and retransmission ordered: sequencing of packets Acknowledgment system flow control: emission window Full Duplex..
Mohamad Chaitou
46
23
10/15/2010
TCP/IP architecture
Mohamad Chaitou
47
48
24
10/15/2010
Mohamad Chaitou
49
Mohamad Chaitou
50
25
10/15/2010
TCP
TCP treats the data from the upper layers as a sequence of bytes It Cuts this sequence of bytes in TCP segments
maximum size: 64 Kbytes size depends on the media in face of the sending station
TCP
Connected mode: mechanism "Send and Wait
It transmits a packet, then waits for acknowledgment before sending the following one:
Sender Transmit packet 1 Receive packet 1 Transmit ACK 1 Receive ACK 1 Transmit Packet 2 Receive Packet 2 TransmitACK 2 Receive ACK 2 network receiver
Mohamad Chaitou
52
26
10/15/2010
TCP
If there is no acknowledgment (ACK) at the expiration of the timer, it retransmits the packet and then waits again, etc. This technique uses very little network
The network is only used when transmitting
eg transmission time tt =, tp = propagation time , efficiency = tt / (tt + 2 x tp) = 1 / (1 + 2 x tp / tt) if the network size increases (ie tp increases), efficiency decreases!
Introduction of the window of anticipation (or transmission window) to maximize the effeciency of TCP exchanges
Mohamad Chaitou
53
TCP
Mechanism of the "sliding window
Initial window Packets
1 2 3 4 5 6 7 8
The transmitter may send 3 packets before receiving an acknowledgment The ack of a packet arrives, the window slides:
Sliding Packets
1 2 3 4 5 6 7 8
The performance depends on the size of the window and the speed at which the network accepts packets
Mohamad Chaitou
54
27
10/15/2010
TCP
If the window is large enough, there is no blockage
Sender network destination
tt Transmission window
tp
tt tt
end rx segment 1 -> tx ACK 1 end rx segment 2 -> tx ACK 2 end rx segment 3 -> tx ACK 3 end rx segment 4 -> tx ACK 4 end rx segment 5 -> tx ACK 5
Important : no blocking because ACK 1 received before the end of the transmission window
Mohamad Chaitou
55
TCP
If he window size is too small, then there is blocking:
Sender tt Transmission window tt tt end rx segment 1 -> tx ACK 1 end rx segment 2 -> tx ACK 2 tt Transmission window tt tt end rx segment 4 -> tx ACK 4 End rx segment 5 -> tx ACK 5 end rx segment 6 -> tx ACK 6 end rx segment 3 -> tx ACK 3 Network Receiver
tp
Blocking zone
Blocking zone
Mohamad Chaitou
56
28
10/15/2010
TCP
Flow Control:
the recipient plays with the space available in its buffers to reduce (or increase) the transmission window:
WINDOW field in the TCP frame number of bytes that the receiver can process
Mohamad Chaitou
TCP
A TCP segment is contained in an IP datagram
protocol field of IP datagram = 6
min 20 bytes
IP Header 1 4 5
TCP header
IP data
Data 32
Destination Port
10 1112 13 14 15 16 17 1314
Source Port Sequence Number Acknowledgment Number
Data Offset
Reserved Checksum
U R G
A C K
P S H
P S T
S Y N
F I N
Options (+ padding)
Data (variable)
Mohamad Chaitou
58
29
10/15/2010
Firewalls
The most basic firewall is a packet filter that inspects each packet coming into or out of a network and uses a set of rules to determine whether that traffic is allowed. Filtering is usually based on network addresses and ports. For example, all traffic coming from the Class C network 193.28.25 may be rejected because you had bad experiences with hackers from that net in the past. Outgoing Telnet connections may be allowed, but incoming Telnet connections may not be. Incoming connections on port 80 (Web) may be allowed but only to the corporate web server. The exact configuration of a firewallwhich packets of data are and are not allowed to pass throughdepends on the security needs of an individual site.
Mohamad Chaitou
59
Firewalls
Mohamad Chaitou
60
30
10/15/2010
Proxy servers
A machine that is prevented from connecting to the external network by a firewall would make a request for a web page from the local proxy server instead of requesting the web page directly from the remote web server. The proxy server would then request the page from the web server and forward the response to the original requester. While firewalls generally operate at the level of the transport or internet layer, proxy servers operate at the application layer. A proxy server has detailed understanding of some application level protocols, like HTTP and FTP. Packets that pass through the proxy server can be examined to ensure that they contain data appropriate for their type. For instance, FTP packets that seem to contain Telnet data can be rejected.
Mohamad Chaitou
61
Proxy servers
Proxy servers can also be used to implement local caching. When a file is requested from a web server, the proxy server will first check to see whether the file is in its cache. If the file is in the cache, then the proxy will serve the file from the cache rather than from the Internet. If the file is not in the cache, then the proxy server will retrieve the file, forward it to the requester, and store it in the cache for the next time it is requested.
Mohamad Chaitou
62
31
10/15/2010
Client/Server model
A client/server application typically stores large quantities of data on an expensive, high-powered server, while most of the program logic and the user interface is handled by client software running on relatively cheap personal computers.
Mohamad Chaitou
63
Client/server model
Some servers process and analyze the data before sending the results to the client. Such servers are often referred to as "application servers" to distinguish them from the more common file servers and database servers. A file or database server will retrieve information and send it to a client, but it won't process that information. Web servers such as Apache respond to requests from web clients such as Netscape. An older service that fits the client/server model is FTP. Java is a powerful environment in which to write GUI programs that access many different kinds of servers Java makes it easy to write clients of all sorts, but it really shines when you start writing servers.
Mohamad Chaitou
64
32
10/15/2010
Client/server model
Not all applications fit easily into a client/server model. For instance, in networked games it seems likely that both players will send data back and forth roughly equally (at least in a fair game). These sorts of connections are called "peer-to-peer". The telephone system is the classic example of a peer-to-peer network. Java does not have explicit peer-to-peer communication in its networking API. However, applications can easily implement peerto-peer communications in several ways, most commonly by acting as both a server and a client. Alternatively, the peers can communicate with each other through an intermediate server program that forwards data from one peer to the other peers.
Mohamad Chaitou
65
33