Recent Changes - Search:

Network Programming

This website demonstrates using wikis as teaching and learning tool.

The course instructor is happy to share the teaching materials here with those who find it readable.

Introduction to Networking

A Network Programming Lecture by Steven Choy

Lecture Overview: Networking Stacks and Layers - Internet Protocol - IP Addressing -- IP Addressing - for Private Networks - IP Subnets - TCP (Transmission Control Protocol) - UDP (User Datagram Protocol) - Domain Name System - Firewalls and Proxy Servers - Internet Protocol version 6 - Overview of basic concepts for network programming


Networking Stacks and Layers

  • Example: The Internet model of a network stack
  • User/Application - example: Firefox browser
  • Application layer - example: HTTP
  • Transport layer - example: TCP
  • Network layer - example: IP
  • Link layer - example: Ethernet driver
  • Hardware layer - example: Ethernet
  • OSI (Open Systems Interconnect) 7-layer model
    • Application (e.g. FTP, telnet, HTTP)
    • Presentation (e.g. XNS)
    • Session (e.g. RPC)
    • Transport (e.g. TCP, UDP)
    • Network (e.g. IP, AppleTalk)
    • Datalink (e.g. Ethernet frames)
    • Physical (e.g. voltages)
    • (I used this sentence to remember these seven layers: All People Seems To Need Data Processing.)
    • Reference: The OSI Model
  • IP (Internet Protocol) suites
    • Application (e.g. FTP, telnet, HTTP)
    • Transport (e.g. TCP, UDP)
    • Network (e.g. IP)
    • Datalink (e.g. Ethernet frames)
    • Physical (e.g. voltages)
  • Encapsulation - embed a layer's packets into packets of layers immediately below it (vs. Decapsulation)
  • Illustration: Encapsulation of data (Source: http://www.linux-tutorial.info/modules.php?name=MContent&pageid=142)
  • Illustration: The OSI Model

Internet Protocol

  • IP - host addressing scheme in network & packet routing scheme amongst hosts
  • Usually work with TCP (Transmission Control Protocol) or UDP (User Datagram Protocol)
  • IPv4: 32-bit Internet address a.b.c.d
    • From 00000000 00000000 00000000 00000000 to 11111111 11111111 11111111 11111111, how many IP addresses?
    • Specify the network id (netid) and the host id (hostid)
    • A network host uses the network ID and host ID to determine which packets it should receive or ignore and to determine the scope of its transmissions.
  • Looking at a packet traveling over the internet
Windows has a program that lets you trace a packet movement between routers. Type tracert <somehost> in the command prompt. Replace <somehost> with some hosts you want to test.
If you are using Windows, type ipconfig or ipconfig /all in the Command Prompt. It will then list the host name, IP address, subnet mask, gateway, and even the MAC address of your network card.
If you used a router/proxy, your IP address as seen by the server is different. Try the following websites.
Why?
Public versus private IP addresses: Besides the reserved IP addresses (0.0.0.0/8 and 127.0.0.0/8) mentioned above, there are other addresses not used on the public Internet. These private subnets consist of private IP addresses and are usually behind a firewall or router that performs NAT (network address translation). NAT is needed because private IP addresses are nonroutable on the public Internet, so they must be translated into public IP addresses before they touch the Internet. Private IPs are never routed because no one really owns them. And since anyone can use them, there's no right place to point a private IP address to on the public Internet. Private IP addresses are used in most LAN and WAN environments, unless you're lucky enough to own a Class A or at least a Class B block of addresses, in which case you might have enough IPs to assign internal and external IP addresses. (Extract from IP subnetting made easy)

IP addressing

  • IP "Classful" Addressing Overview and Address Classes
    • Class A: "0" + 7-bit netid + 24-bit hostid, 1-126, 16M
    • Class B: "10" + 14-bit netid + 16-bit hostid, 128-191, 65536
    • Class C: "110" + 21-bit netid + 8-bit hostid, 192-223, 256
    • Class D: "1110" + 28-bit multicast address, 224-239
    • Class E: "11110" + 27-bit reserved for future use, 240-255
IP Address Class Fraction of Total IP Address Space Number of Network ID Bits Number of Host ID Bits Intended Use
Class A 1/2 8 24 Unicast addressing for very large organizations with hundreds of thousands or million of hosts to connect to the Internet.
Class B 1/4 16 16 Unicast addressing for medium-to-large organizations with many hundreds to thousands of hosts to connect to the Internet.
Class C 1/8 24 8 Unicast addressing for smaller organizations with no more than about 250 hosts to connect to the Internet.
Class D 1/16 n/a n/a IP multicasting.
Class E 1/16 n/a n/a Reserved for “experimental use”.
  • 127.x.x.x is local loopback address (for testing)
  • Five classes of IP addresses

Classes

Range of first byte

Format

A

1-126

'0' + 7-bit network id + 24-bit host id

B

128-191

'10' + 14-bit network id + 16-bit host id

C

192-223

'110' + 21-bit network id + 8-bit host id

D

224-239

'1110' + 28-bit multicast address

E

240-255

'1111' + 28-bit address

Class Range within 1st octet Network ID Host ID Possible networks Possible hosts per network
A 1-126 a b.c.d 126 16,777,214
B 128-191 a.b c.d 16,384 65,534
C 192-223 a.b.c d 2,097,151 254
  • Class Exercises
1. What is the class of the network for each of the following IP addresses?
(a) 12.12.12.12
(b) 125.44.25.223
(c) 220.32.34.125
2. Why there is no network that owns an IP address such as 127.x.x.x?
3. What is the subnet mask for a non-subnetted class C network?
4. Can you send data to 234.5.6.7? If so, what will happen?

IP Addresses for Private Networks

In some cases, there is no need to have unique IP addresses, since the network will never be connected to the rest of the world. For example, in a factory where the machines communicate with each other via TCP/IP. There is no reason for these machines to be accessible from the Internet. Therefore, there is no need for them to have an official IP address.
You could just randomly assign IP addresses to these machines and hope that your router is configured correctly not to route the packets from these machines. One slip and you have the potential for not only messing up your own network, but someone else's as well.
The solution was provided in RFC-1918. Here, three sets of IP address were defined for use in "private" networks. These won't be routed and there is no need to coordinate their use with any of the registrations agencies. The IP addresses are:
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
As you can see that there is just a single class A address, but 16 class B and 255 class C networks. Therefore, no matter what size your network is, you can find a private network for your needs.

IP subnets

  • Class A address does not necessarily mean that there are 16 million hosts on a single network; they will then break it down further into smaller sub-nets.
  • Similarly, Class B address does not necessarily mean that there are 65,534 hosts on a single network.
  • Similarly, Class C address does not necessarily mean that there are 254 hosts on a single network.
  • Subnet logically divides a network into small networks
  • The benefits of subnetting
Using the subnet technique, network administrators can divide a network into multiple subnetworks and connect subnetworks with routers.
  • reduces network congestion by redirecting traffic and reducing broadcasts; it can significantly improve the performance of Ethernet network;
  • makes better use of the IP address; and
  • makes it easier to control the network segment by dividing hosts into different subnetworks.

IP Datagrams

  • IP datagram = header + PDU (protocol data unit)
  • Illustration: IP Header Diagram (1050x800 PNG)

TCP (Transmission Control Protocol)

  • TCP is a connection-oriented protocol: guarantees end-to-end delivery & sequencing
    • Use checksum, acknowledgement, & retransmission
    • Flow control, and slow start algorithm
    • Full-duplex transmission
  • Multiplexing based on port numbers
    • < 1024 for authorized services only (privileged)
    • <= 255 for system use only
  • Socket represents TCP connection between hosts
  • Illustration: TCP Header Diagram (1050x800 PNG)

UDP (User Datagram Protocol)

  • UDP is a connectionless protocol: no guarantee
  • Minimize overhead & transmit faster
  • Fragmentation: break a UDP datagram into small packets for transmission (easier to lose)
  • Example: NFS, DNS, SNMP
  • Class Discussion: When should we use UDP rather than TCP?
  • Illustration: UDP Header Diagram (1050x800 PNG)

IP family of services

  • Telnet - uses TCP port 23
Telnet is a service that allows users to open a remote terminal session to a specific machine. This allows Unix users, for example, to access their account from terminal servers, or desktop machines. Since Unix servers are intended to support multiple users, a telnet session is often used as only one person can access the machine from the local terminal (using a keyboard and monitor). Telnet allows many users to connect over the network, and to access their accounts as if they were doing so locally.
  • File Transfer Protocol (FTP) - uese TCP ports 20 and 21
The ability to transfer files is extremely important: even before the World Wide Web, people distributed images, documents, and software, using the File Transfer Protocol (FTP). FTP allows a user to login (using a special username and password), or to attempt an anonymous login (by using the username of anonymous). FTP servers will often grant different access permissions depending on the user. For example, an anonymous account might be unable to write a file to the server, but may be able to read all files. FTP uses two TCP ports for communication – port 21 is used to control sessions and port 20 is used for the actual transfer of file contents.
  • Post Office Protocol Version 3 (POP3) - uses TCP port 110
Email has become a vital part of most people’s lives. With the exception of web-based email, or specialized accounts, the majority of people access their email using the Post Office Protocol, which uses TCP port 110. Messages are stored on a server, retrieved by an email client, and then deleted from the server. This allows offline reading of mail, without being connected to the Internet.
  • Internet Message Access Protocol v4 (IMAP) - uses TCP port 143
While many browsers and email clients support only POP3, some also support the Internet Message Access Protocol (IMAP). This protocol is less popular, as it requires a continual connection to the mail server, and thus increases bandwidth consumption and disk usage since messages are not stored on the user’s system. IMAP allows users to create folders on the mail server, and also allows online searching of mail.
  • Simple Mail Transfer Protocol (SMTP) - uses TCP port 25
The Simple Mail Transfer Protocol allows messages to be delivered over the Internet. You might find the separation between retrieving mail, and sending mail, a little strange. However, it actually simplifies the process considerably, and allows different mail retrieval protocols to be used, or custom mail accounts.
  • Hyper-text Transfer Protocol (HTTP) - uses TCP port 80
HTTP is one of the most popular protocols in use on the Internet today, and made the world-wide-web possible. HTTP is an extremely important protocol, and Java includes good HTTP support.
  • WHOIS - uses TCP port 43
The WHOIS protocol allows users to look up information about a domain name. You can find some surprisingly useful information by doing this, such as the address of a company, who registered the domain name, and contact details for the registration.
(Extracted from Chapter One - Networking Theory, Java Network Programming & Distributed Computing, by David Reilly and Michael Reilly (ISBN: 0201710374))

Domain Name System

  • DNS: lookup services, or name resolution
    • Translate Internet domain name to IP address
    • E.g. www.ouhk.edu.hk to 202.40.220.3
  • Database maintenance for the mappings
  • Distributed, with a hierarchy of domain name servers
  • Authoritative name servers
  • Caching-only name servers

Firewalls and proxy servers

  • Firewall: examine all traffic to & from a private network for security
(Source: Java Network Programming & Distributed Computing, by David Reilly and Michael Reilly)
  • Proxy server:
    • A proxy server is a machine that acts as a proxy for application protocols.
    • Intercept requests from clients & reply by itself or forward to real servers
    • Improve access performance
    • Filter requests
    • Hide private network from outside world

Internet Protocol version 6

  • IPv6 = IPng (Internet Protocol Next Generation)
  • Evolutionary upgrade to IPv4
  • 128-bit addressing
  • For more information, go to http://www.ipv6.org
  • Limitations of IPv4
    • Insufficient addressing space
    • Limited QoS support (no bandwidth reservation)

Improvement by IPv6

  • Increase address size from 32 to 128 bits
  • Scope multicast addressing & routing
  • Have anycast addressing (for policy route selection)
  • Reduce extra header fields to improve performance
  • Enable packet labelling to traffic "flow"
  • Support source authentication, integrity and privacy checking
  • For probing further
IPv6 Information Page (www.ipv6.org) - http://www.ipv6.org/

Overview of basic concepts for network programming


Thanks for Reading

If you would rather like to have this lecture note in printed format, please click the print action link in the top right corner.

If you find any problem in this lecture note, please feel free to tell Steven via steven@findaway.hk.

Edit - History - Print - Recent Changes - Search
Page last modified on September 22, 2009, at 09:51 AM