N342 Networking Basics

Modified

Internet - The Internet consists of a set of protocols (rules) for communication between computers. The software implementation of these protocols have been divided into layers, with each layer isolating a specific function required for network operation. The three layers of interest are:

  1. network (IP) which allows message routing over the Internet
  2. transport (TCP) for reliable end-to-end communications
  3. application (HTTP) defining communication between a client and server.

Protocol Hierarchies

The figure at right illustrates a typical, five layer network. Virtual communication occurs between common layers on the hosts, the common layers are peers. From the perspective of each peer, all communication is with the peer on the other host. In fact, the real communication occurs between layers on a single host. The only direct communication can occur at the lowest or physical layer (e.g. over the wire).

In the figure below, protocols virtually communicate horizontally through the real vertical communication layers. A Web client implements the protocol to communicate with a Web server, however the real communication must pass from the client down through interfaces to the underlying layers, across a physical connection that actually carries the bits, then up through the layer interface to the Web server protocol implementation.

A more detailed illustration of the vertical communication is below. As a message at Layer 5 is sent from a host, it moves down the layers. Each layer communicates virtually horizontally with its peer by adding information to the message received from the higher layer, this information is usually termed a header or trailer. For example, the information added by the sending host at layer 3 is used at layer 3 on the receiving host, the headers and trailers implement the virtual communication. On reaching the destination host, the message moves from lower to higher layers. Each peer layer examines and removes the header (or trailer) before passing the message to the next higher layer.

Network layer - concerned with delivering packets from source to destination, often through many intermediate routers, called Internet Message Processor on the Internet.

  1. Connectionless - Internet view.
  2. Connection-oriented - Phone company view.

Internet Network Layer

  1. IP Protocol

  1. IP Addresses - 32 bit in form of Network | Host

  1. Subnet - Appear as one network to outside but consists of multiple networks inside.
  2. Internet Control Protocols - IP used for data transfer
  3. Interior Gateway Routing Protocols: OSPF (Open Shortest Path First) - Used within an organization where all routers run same routing algorithm
  4. Exterior Gateway Routing Protocol: BGP (Border Gateway Protocol) - Used to connect organization networks running own version of an interior gateway routing protocol, must deal with politics. May not allow certain transit traffic, etc.
  5. Mobile IP - When IP's move to different network but keep same IP
    1. Mobile IP
      1. When host arrives in new area listens for advertizement of services from foreign routing agents or broadcasts its arrival and waits for foreign agent response.
      2. Registers with foreign routing agent giving IP home routing agent address. Foreign agent contacts home routing agent.
    2. Foreign routing agent - Sends in-care-of address to home routing agent. Receives packets for mobile IP from home routing agent, forwards to mobile IP.
    3. Home routing agent - Routes packets for IP to a willing foreign routing agent where mobile IP has moved, packet essentially tunneled through Internet (an IP packet inside an IP packet) from home router to foreign routing agent.

  1. CIDR IPv4 - Classless InterDomain Routing - Delaying the IP network explosion problem
  2. IPv6


Transport layer - Provides end-to-end data transport for user. depends upon services of network layer. Required because network layer is not generally reliable and often controlled by someone other than network user. The TPDU (Transport Protocol Data Unit) discussed in the text corresponds to the TCP (Transmission Control Protocol) header and data load. The TPDU is contained within a network packet which is itself contained within a data link frame as illustrated below for Ethernet, IP, and TCP protocols:

Berkley Sockets - A standard set of transport primitives used in Berkley UNIX for TCP and widely ported to other systems, including Windows, though they made significant improvements such as changing some function name spellings.
 

Echo Server and Client using Berkley Socket Primitives
// Server

#include <winsock2.h> 

void main(void)
{
  char               buffer[128]; 
  int                retval, sinlen; 
  struct sockaddr_in sin; 
  SOCKET             s, h; 

  sin.sin_family = AF_INET; 
  sin.sin_addr.s_addr = INADDR_ANY;
  sin.sin_port = htons(888);   // Port 888
                  // SOCK_STREAM is TCP
  s = socket(AF_INET, SOCK_STREAM,0);
                  // Bind socket to local port
  bind(s,(struct sockaddr*)&sin,sizeof(sin));
                  // Listen for 1 connection
  listen(s,1);
  sinlen = sizeof(sin);      
                  // Block for connection
  h=accept(s,(struct sockaddr*)&sin,&sinlen );
        
                  // Block for receive
  recv(h,buffer,sizeof(buffer),0); 
                  // Echo what is received
  send(h,buffer,strlen(buffer),0);
 
  closesocket(h);
}

// Client

#include <winsock2.h> 
#include <iostream.h>
void main(int argc, char* argv[])
{
  char               buffer[128]= "Hello"; 
  int                retval; 
  unsigned int       addr=0; 
  struct sockaddr_in sin; 
  struct hostent     *host; 
  SOCKET             s; 
                    // Assume valid DNS given
  host = gethostbyname(argv[1]);

  memcpy(&(sin.sin_addr),
         host->h_addr,host->h_length); 
  sin.sin_family = host->h_addrtype; 
  sin.sin_port = htons(888);
                    // Create socket
  s = socket(AF_INET, SOCK_STREAM,0);
                    // Block for server
  connect(s,
          (struct sockaddr*)&sin,sizeof(sin));
                    // Send                  
  send(s,buffer,strlen(buffer)+1,0);
                    // Block for Receive 
  recv(s,buffer,sizeof(buffer),0);
                    // Print what is received
  cout << "Received " << buffer << "\n"; 
        
  closesocket(s);
}

The Internet Transport Protocols (TCP and UDP)

TCP - Designed to provide reliable end-to-end service over unreliable network layer. Runs on hosts communicating via segments. IP runs on routers and hosts communicating via packets. TCP connection is full-duplex, point-to-point (only two ends), appearing as a byte stream just like reading a file (no message boundaries though a carriage return can be data).

HTTP

The HTTP protocol defines how a client and server communicate. In its most basic form, the client sends a request for a file to the server, the server sends the file contents back the client. In the following diagram, the client requests the file Hello.htm in the rwisman directory from the www.ius.edu server. The server responds by sending a header of information back to the client, the header of Content-type: text/html tells the client browser what type of file its returning. There are many other possibilities such as Content-type: image/gif etc. Note that HTML is not part of the HTTP protocol but one of the content types used by the browser. The HTML sent to and displayed by the browser is <H1>Hello World</H1> which is rendered by the browser as: Hello World

Further Information - The text Computer Networks by Andrew S. Tanenbaum, Prentice-Hall provides an in depth examination of networking in general. The serious student would enjoy examination of the original HTTP specification: http://www.ics.uci.edu/pub/ietf/http/rfc1945.html