Sunteți pe pagina 1din 33

10/15/2010

Network programming:
Chap 1: Introduction to networking
Dr. Mohamad Chaitou LIU

Course contents

Basic Concepts, Protocols and Terminology (1 week)


Client/server scheme, TCP connection, UDP connectionless, Port, Socket

Manipulating Internet Addresses (1 week)


DNS System, Local/Remote IP Finder Application

TCP/UDP Sockets (3 weeks)


Echo, Ping, Simplex Chat, Port Scanner, IP Scanner

Network Programming with GUIs (2.5 weeks)


Chat through GUI, Browsing Web Pages

Multithreading (1.5 weeks)


Chat with Multiple Clients, Full Duplex Chat
Mohamad Chaitou
2

10/15/2010

Course contents
File Handling, Serialisation (2 weeks)
File transfer

Remote Method Invocation (2 weeks)


Banking Application

Projects Demos (1 week)

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

Network definition and advantages


Definition:
A network is a set of nodes interconnected together via physical links in order to exchange information and share resources. These nodes can be a computer, a phone, or other network equipment such as a router or firewall.

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

Classification by size: PAN, LAN, MAN, WAN


1m: connection between a (mouse, keyboard, printer, etc.) and a computer) 10m/1km: building, campus, etc: Use of Ethernet LAN or Wireless LAN 10km: city, town Use of simple architecture (ring): xDSL Fiber To The Home >100km: Internet (network interconnexion), Planet: Fiber optic, satellite

WAN
PAN

LAN
Local area networks

MAN
Metropolitan area networks

Wide area network

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

Public switched telephony network (PSTN)


Used for voice transmission:
Data can be transmitted by using a numeric to analog modem (56kbit/s) Data and voice cannot be transmitted simultaneously

Resources are reserved for a call:


64 Kbit/s per channel Multiplexing is performed by the telephony switches

Mohamad Chaitou

10

10/15/2010

Computer network
A set of computer connected between them by the same technology

Many computer network can be connected between them:


This is the example of the internet

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

IEEE(Institute of Electrical and Electronics Engineers Institute Engineers):


IEEE has started the standardization of local networks in 1979. This process consists of applying the principles of layers 1 and 2 of the OSI model on the varieties of LAN and MAN networks This working group has taken the name of IEEE 802.X in 1980

Mohamad Chaitou

13

OSI model (1)


Open System Interconnexion:
based on a principle stated by Julius Caesar 'divide and rule description of networks as a set of layers superimposed on each other:
their number, their name, their function varies depending on the network the goal of each layer is to provide services to higher layers:

the latter do not know the implementation of these services

The study of the network is reduced to that of its parts, the whole becomes easier to manipulate

Mohamad Chaitou

14

10/15/2010

OSI model (2)


7 functional layers divided into 2 groups:
lower layers:
transport functions information transfer between terminals via a telecommunication network layers 1-4

upper layers:
application management applications taken over by the terminal layers 5-7

Mohamad Chaitou

15

OSI model (3)


Layer 1 - Physical: transmission of bits on physical support. Also, it determines the voltage of each bit level, length of bits, modulation, etc. Layer 2 - Link: transfer of information in the form of frames, detection and correction of errors. Layer 3 - Network: establishment and release of communications, routing through the network: Internet protocol (IP) Layer 4 - Transport: transports information reliably from one end of the connection to the other end, connection procedure: TCP or UDP Layer 5 - Session: organization of the exchange and structure of dialogue between applications (example: negociate if half-duplex or full duplex) Layer 6 - Presentation: syntax for the exchange of information (alphabet, presentation graphics, etc..). Representing data independently from used platforms or OS. The security mechanism to access information Layer 7 - Application: contains the mechanism that can be activated for different services (applications). The user accesses OSI by this service. The applications are not parts of this layer: HTTP, FTP, SMTP, etc.
Mohamad Chaitou
16

10/15/2010

OSI Model (4)


Sender Application 7 6 5 4 3 2 1 Presentation Session Transport Network Link Physical Physical transmission support
Data path APDU PPDU SPDU TPDU Packet Frame Bit

Receiver Application 7 Presentation Session Transport Network Link Physical 6 5 4 3 2 1

Mohamad Chaitou

17

OSI model (5)


Sender Application Presentation Session Transport Network Link Physical
P L L R R R T T T T S S S S S P P P P P P A A A A A A A DATA DATA DATA DATA DATA DATA DATA DATA

Receiver Application Presentation Session Transport Network Link Physical

Physical transmission support


Mohamad Chaitou
18

10/15/2010

OSI model (6)


Sender Application Presentation Session Transport Network Link Physical
P L L R R R T T T T S S S S S P P P P P P A A A A A A A Data Data Data Data Data Data Data Data

Receiver Application Presentation Session Transport Network Link Physical

Physical transmission support

Mohamad Chaitou

19

OSI Model (7)


Sender
Application Presentation Session Transport Network Link Physical Network Link Physical Network Link Physical

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

OSI Model (8)


There are three key concepts for the OSI model:
SAP (SERVICE ACCESS POINT):
identifies the interfaces between adjacent layers in the equipment. The interface between Layer 1 (Physical) and layer 2 is named PH-SAP, between layer 2 and 3 is DL-SAP, between layer 3 and 4 N-SAP, etc.

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)

1980: TCP / IP implemented on the DARPA network


this is the beginning of the Internet!

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

The IP datagram: demultiplexing by using the protocol field of the header


ICMP TCP UDP

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

Padding field (variable size)


Complete the Options field so that the length of the header is a multiple of 32 bits

Note: size of the IP header 20 bytes

Mohamad Chaitou

30

15

10/15/2010

ICMP
Internet Control Message Protocol (RFC 792)
Protocol of 'management' of the network
error reporting mechanisms

Implemented on all IP devices


ICMP is contained in the IP datagram Protocol field = 1

Sent by the destination device or an intermediate router:


if there is a problem with the IP datagram to notify the transmitter to change its behavior

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)

It must be unique (@ public)


Software configurable associated with each network interface

Mohamad Chaitou

33

IP addresses and DNS


Normally, human beings will use domain names in preference to IP addresses, but they can just as well use the corresponding IP addresses (if they know what they are!). The Domain Name System provides a mapping between IP addresses and domain names and is held in a distributed database. The IP address system and the DNS are governed by ICANN (the Internet Corporation for Assigned Names and Numbers), which is a non-profitmaking organisation. When a URL is submitted to a browser, the DNS automatically converts the domain name part into its numeric IP equivalent.

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

10101010 170 1 to 126 128 to 191 192 to 223

. . . . .

01010101 85

host
0 to 255 0 to 255

. . . . .

00110011 51

host host
0 to 255

. . . . .

11001100 204

host host host


35

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

CIDR: Classless Routing InterDomain


address format: @ IP / x, where x is the number of bits in the network address (the rest designating the host part) ex: Class B: 130.190.0.0
default mask: 255.255.0.0 -> 130.190.0.0/16 255.255.255.0 mask if dividing into 256 subnets of class C -> 130.190.0.0/24
37

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

2 046 possible host


Mohamad Chaitou
38

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

@ network: 170.85.48.0 @ host(51-48 = 3) : host(510.0.3.204

The transport layer


Two protocols are used for communication between applications:
UDP: User Datagram Protocol
Connectionless the sending machine sends data without notifying the receiving machine, and the receiving machine receives the data without sending a receipt to the sending machine

TCP: Transmission Control Protocol


Connection-oriented the receiving machine sends acknowledgments during the communication and the sending machine guarantees the validity of the data it sends

Mohamad Chaitou

40

20

10/15/2010

The transport layer


Need for identifying an application:
the identification is made by a port number
abstract value used only by the transport protocol to designate an application

Combination (IP address - port number):


necessary to identify the processes on a machine : it is called "demon
ex: 130.190.5.1 - port 23 is the telnet demon on the station 130.190.5.1

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

The transport layer


Pre-defined Ports (RFC 1060 "Assigned Numbers") for standard services:
port 21 port 25 port 53 -> FTP -> SMTP -> DNS (Domain Name Server) port 23 -> Telnet port 69 -> TFTP port 80 -> HTTP

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)

It is an unreliable transport protocol:


used by NFS (Network File System) used for broadcasting:
TFTP (Trivial File Transfer Protocol) NTP (Network Time Protocol) more generally: when the multicast is required

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

Ports and sockets


A port is a logical connection to a computer (as opposed to a physical connection) and is identified by a number in the range 165535. This number has no correspondence with the number of physical connections to the computer, of which there may be only one Addresses would be all you needed if each computer did no more than one thing at a time. However, modern computers do many different things at once. Email needs to be separated from FTP requests, which need to be separated from web traffic. This is accomplished through ports. In most applications, of course, there are likely to be multiple clients wanting the same service at the same time. A common example of this requirement is that of multiple browsers (quite possibly thousands of them) wanting Web pages from the same server. The server, of course, needs some way of distinguishing between clients and keeping their dialogues separate from each other. This is achieved via the use of sockets.
Mohamad Chaitou

48

24

10/15/2010

Ports and sockets


When a client wishes to make connection to a server, it will create a socket at its end of the communication link. Upon receiving the client's initial request (on a particular port number), the server will create a new socket at its end that will be dedicated to communication with that particular client. Just as one hardware link to a server may be associated with many ports, so too may one port be associated with many sockets

Mohamad Chaitou

49

Ports and sockets

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

Segments are exchanged to:


open connections transfer data manage flow control: sends "ACK inform the window size close connections
Mohamad Chaitou
51

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

transmission window accordingly modified

Flow control is essential to the Internet


heterogeneous Internet systems
TCP solves the problem with the "Sliding Window

Machines of the Internet are of different capacities:


TCP solves the problem by the algorithm of "Slow Start segment loss interpreted as a sign of congestion transmission window is reduced sharply
57

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

Window Urgent Pointer

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

S-ar putea să vă placă și