LIU – Chapter 1

 

Basics in three areas

Some of the notations and concepts from these areas will be employed from time to time in the presentations for this course:

nSoftware engineering

nOperating systems

nNetworks.

 

 

Software Engineering Basics

Procedural versus Object-oriented Programming

In building network applications, there are two main classes of programming languages: procedural language and object-oriented language

nProcedural languages, with the C language being the primary example, use procedures (functions) to break down the complexity of the tasks that an application entails.   

nObject-oriented languages, exemplified by Java, use objects to encapsulate the details.  Each object simulates an object in real life, carrying state data as well as behaviors.  State data are represented as instance data.  Behaviors are represented as methods.

 

UML Class Diagram Notations

 

NOTE: The shape, the style of the line (dashed or solid), the direction of the arrow, and the shape of the arrowheads (pointed, hollow, or solid) are significant.

 

 

 

The Architecture of Distributed Applications

 

Operating Systems Basics

nA process consists of an executing program, its current values, state information, and the resources used by the operating system to manage its execution.

nA program is an artifact constructed by a software developer; a process is a dynamic entity which exists only when a program is run.

 

Process State Transition Diagram

 

 

Java processes

nThere are three types of Java program: applications, applets, and servlets, all are written as a class.

nA Java application program has a main method, and is run as an independent(standalone) process.

nAn applet does not have a main method, and is run using a browser or the appletviewer.

nA servlet does not have a main method, and is run in the context of a web server.

nA Java program is compiled into bytecode, a universal object code.  When run, the bytecode is interpreted by the Java Virtual Machine (JVM).

 

Three Types of Java programs

nApplications

           

a program whose byte code can be run on any system which has a Java Virtual Machine.  An application may be standalone (monolithic) or distributed (if it interacts with another process).

nApplets

           

A program whose byte code is downloaded from a remote machine and is run in the browser’s Java Virtual Machine. 

nServlets

           

A program whose byte code resides on a remote machine and is run at the request of an HTTP client (a browser).

 

Three Types of Java programs

 

 

A sample Java application

 

/*******************************************************

 *  A sample of a simple Java application.

 *   M. Liu               1/8/02

 ******************************************************/

import java.io.*;

class MyProgram{

  

   public static void main(String[ ] args)

      throws IOException{

      BufferedReader keyboard = new

         BufferedReader(new InputStreamReader(System.in));

      String theName;

      System.out.println("What is your name?");

      theName = keyboard.readLine( );

      System.out.print("Hello " + theName );

      System.out.println(" - welcome to CSC369.\n");

   } // end main

} //end class

 

 

 

A Sample Java Applet

 

/***************************************************

 *  A sample of a simple applet.

 *   M. Liu               1/8/02

 ***************************************************/

import java.applet.Applet;

import java.awt.*;

public class MyApplet extends Applet{

   public void paint(Graphics g){

      setBackground(Color.blue);

      Font Claude = new Font("Arial", Font.BOLD, 40);

      g.setFont(Claude);                                       

      g.setColor(Color.yellow);

      g.drawString("Hello World!", 100, 100);

   } // end paint

} //end class

<!-- A web page which, when browsed, will run >

<!-- the MyApplet applet>

<!-- M. Liu 1/8/02>

 

<title>SampleApplet</title>

<hr>

 

<applet code="MyApplet.class" width=500 height=500>

</applet>

 

<hr>

<a href="Hello.java">The source.</a> 

 

 

A Sample Java Servlet

/*******************************************************

 *  A sample of a simple Java servlet.

 *   M. Liu               1/8/02

 ******************************************************/

import java.io.*;

import java.text.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class MyServlet extends HttpServlet {

   public void doGet (HttpServletRequest request,

                      HttpServletResponse response)  

      throws ServletException, IOException {

      PrintWriter out;

      String title = "MyServlet Output";

      // set content type and other response header

      //   fields first

      response.setContentType("text/html");

      // then write the data of the response

      out = response.getWriter();

      out.println("<HTML><HEAD><TITLE>");

      out.println(title);

      out.println("</TITLE></HEAD><BODY>");

      out.println("<H1>" + title +   "</H1>");

      out.println("<P>Hello World!");

      out.println("</BODY></HTML>");

      out.close();

   } //end doGet

} //end class

 

 

Concurrent Processing

On modern day operating systems, multiple processes appear to be executing concurrently on a machine by timesharing resources.

 

 

Concurrent processing within a process

It is often useful for a process to have parallel threads of execution, each of which timeshare the system resources in much the same way as concurrent processes.

 

Java threads

nThe Java Virtual Machine allows an application to have multiple threads of execution running concurrently.

nJava provides a Thread class:

     public class Thread

     extends Object

     implements Runnable

n When a Java Virtual Machine starts up, there is usually a single thread (which typically calls the method named main of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs:

nThe exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.

nAll threads have ter,omated, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.

 

 

Two ways to create a new thread of execution

nUsing a subclass of the Thread class

nUsing a class that implements the Runnable interface

 

Create a class that is a subclass of the Thread class

Declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started:

 

 

Create a class that is a subclass of the Thread class

/******************************************************

 *   A program which makes use of the SomeThread class.

 *   M. Liu       1/8/02

 *****************************************************/

 

// import SomeThread;

public class RunThreads

{

   public static void main (String[] args)

   {

     SomeThread p1 = new SomeThread(1);

     p1.start();

 

     SomeThread p2 = new SomeThread(2);

     p2.start();

 

     SomeThread p3 = new SomeThread(3);

     p3.start();

   }

}// end class RunThreads

/**************************************************

 *   A class which extends the Java Thread class.

 *   M. Liu       1/8/02

 *************************************************/

class SomeThread extends Thread {

   int myID;

   SomeThread(int id) {

      this.myID = id;

   }

 

   public void run() {

      int i;

      for (i = 1; i < 11; i++)

         System.out.println ("Thread"+myID + ": " + i);

   }

} //end class SomeThread

 

Java Threads-2

The other way to create a thread is to declare a class that implements the Runnable interface. That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started.

 

 

Create a class that implements the Runnable interface

 

public class RunThreads2

{

   public static void main (String[] args)

   {

     Thread p1 = new Thread(new SomeThread2(1));

     p1.start();

 

     Thread p2 = new Thread(new SomeThread2(2));

     p2.start();

 

     Thread p3 = new Thread(new SomeThread2(3));

     p3.start();

   }

} //end class RunThreads2

 

class SomeThread2 implements Runnable {

   int myID;

 

   SomeThread2(int id) {

      this.myID = id;

   }

 

   public void run() {

      int i;

      for (i = 1; i < 11; i++)

        System.out.println ("Thread"+myID + ": " + i);

   }

} //end class SomeThread2

 

Program samples

nRunThreads.java

nSomeThread.java

nRunThreads2.java

nSomeThread2.java

 

 

Thread-safe Programming

nWhen two threads independently access and update the same data object, such as a counter, as part of their code, the updating needs to be synchronized. (See next slide.)

nBecause the threads are executed concurrently, it is possible for one of the updates to be overwritten by the other due to the sequencing of  the two sets of machine instructions executed in behalf of the two threads. 

nTo protect against the possibility, a synchronized method can be used to provide mutual exclusion.

 

Race Condition

 

Synchronized method in a thread

class SomeThread3 implements Runnable {

   static int count=0;

   SomeThread3() {

      super();

   }

 

   public void run() {

      update();

   }

   static public synchronized void update( ){

      int myCount = count;

      int second = (int)(Math.random( ) * 500);

      try {

        Thread.sleep(second);

      }

      catch (InterruptedException e) {

      }

      myCount++;

      count = myCount;

      System.out.println("count="+count+

        "; thread count=" + Thread.activeCount( ));

   }

} //end class SomeThread3

 

Network Basics

Network standards and protocols

nOn public networks such as the Internet, it is necessary for a common set of rules to be specified for the exchange of data.

nSuch rules, called protocols, specify such matters as the formatting and semantics of data, flow control, error correction.

nSoftware can share data over the network using network software which supports a common set of protocols.

 

Protocols

§In the context of communications, a protocol is a set of rules that must be observed by the participants.

§In communications involving computers, protocols must be formally defined and precisely implemented.   For each protocol, there must be rules that specify the followings:

§How is the data exchanged encoded? 

§How are events (sending , receiving) synchronized  so that the participants can send and receive in a coordinated order?

§The specification of a protocol does not dictate how the rules are to be implemented.

 

The network architecture

nNetwork hardware transfers electronic signals,which represent a bit stream, between two devices.

nModern day network applications require an application programming interface (API) which masks the underlying complexities of data transmission.

nA layered network architecture allows the functionalities needed to mask the complexities to be provided incrementally, layer by layer.

nActual implementation of the functionalities may not be clearly divided by layer.

 

The OSI seven-layer network architecture

 

Network Architecture

The division of the layers is conceptual: the implementation of the functionalities need not be clearly divided as such in the hardware and software that implements the architecture. 

         

The conceptual division serves at least two useful purposes :

1.Systematic specification of protocols

           

it allows protocols to be specified systematically

2.         Conceptual Data Flow: it allows programs to be written in terms of logical data flow.

 

The TCP/IP Protocol Suite

nThe Transmission Control Protocol/Internet Protocol suite is a set of network protocols which supports a four-layer network architecture.

nIt is currently the protocol suite employed on the Internet.

 

 

 

The TCP/IP Protocol Suite -2

nThe Internet layer implements the Internet Protocol, which provides the functionalities for allowing data to be transmitted between any two hosts on the Internet.

nThe Transport layer delivers the transmitted data to a specific process running on an Internet host.

nThe Application layer supports the programming interface used for building a program.

 

Network Resources

nNetwork resources are resources available to the participants of a distributed computing community. 

nNetwork resources include hardware such as computers and equipment, and software such as processes, email mailboxes, files, web documents. 

nAn important class of network resources is network services such as the World Wide Web and file transfer (FTP), which are provided by specific processes running on computers.

 

Identification of Network Resources

One of the key challenges in distributed computing is the unique identification of resources available on the network, such as e-mail mailboxes, and web documents.

nAddressing an Internet Host

nAddressing a process running on a host

nEmail Addresses

nAddressing web contents: URL

 

Addressing an Internet Host

The Internet Topology

 

The Internet Topology

nThe internet consists of an hierarchy of networks, interconnected via a network backbone.

nEach network has a unique network address.

nComputers, or hosts, are connected to a network.  Each host has a unique ID within its network.

nEach process running on a host is associated with zero or more ports.  A port is a logical entity for data transmission.

 

The Internet addressing scheme

nIn IP version 4, each address is 32 bit long.

nThe address space accommodates 232 (4.3 billion) addresses in total.

nAddresses are divided into 5 classes (A through E)

 

 

The Internet addressing scheme - 2

 

Example:

           

Suppose the dotted-decimal notation for a particular Internet address is129.65.24.50.   The 32-bit binary expansion of the notation is as follows:

Since the leading bit sequence is 10, the address is a Class B address.  Within the class, the network portion is identified by the remaining bits in the first two bytes, that is, 00000101000001, and the host portion is the values in the last two bytes, or 0001100000110010.  For convenience, the binary prefix for class identification is often included as part of the network portion of the address, so that we would say that this particular address is at network 129.65 and then at host address 24.50 on that network.

 

Another example:

Given the address 224.0.0.1, one can expand it as follows:

 

 

The binary prefix of 1110 signifies that this is class D, or multicast, address.   Data packets sent to this address should therefore be delivered to the multicast group 0000000000000000000000000001. 

 

The Internet Address Scheme - 3

nFor human readability, Internet addresses are written in a dotted decimal notation:

         nnn.nnn.nnn.nnn, where each nnn group is a decimal value in the range of 0 through 255

# Internet host table (found in /etc/hosts file)

127.0.0.1          localhost

129.65.242.5    falcon.csc.calpoly.edu  falcon  loghost

129.65.241.9    falcon-srv.csc.calpoly.edu      falcon-srv

129.65.242.4    hornet.csc.calpoly.edu  hornet

129.65.241.8    hornet-srv.csc.calpoly.edu      hornet-srv

129.65.54.9     onion.csc.calpoly.edu   onion

129.65.241.3    hercules.csc.calpoly.edu        hercules

 

IP version 6 Addressing Scheme

nEach address is 128-bit long.

nThere are three types of addresses:

nUnicast: An identifier for a single interface.

nAnycast: An identifier for a set of interfaces (typically belonging to different nodes).

nMulticast: An identifier for a set of interfaces (typically belonging to different nodes). A packet sent to a multicast address is delivered to all interfaces identified by that address.

nSee Request for Comments: 2373 http://www.faqs.org/rfcs/ (link is in book’s reference)

 

The Domain Name System (DNS)

For user friendliness, each Internet address is mapped to a symbolic name, using the DNS, in the format of:

     <computer-name>.<subdomain hierarchy>.<organization>.<sector name>{.<country code>}

        e.g.,  www.csc.calpoly.edu.us

 

 

 

The Domain Name System

For network applications, a domain name must be mapped to its corresponding Internet address.

. Processes known as  domain name system servers provide the mapping service, based on a distributed database of the mapping scheme.

. The mapping service is offered by thousands of DNS servers on the Internet, each responsible for a portion of the name space, called a zone. The servers that have access to the DNS information (zone file) for a zone is said to have authority for that zone.

 

Top-level Domain Names

n.com: For commercial entities, which anyone, anywhere in the world, can register.

n.net : Originally designated for organizations directly involved in Internet operations. It is increasingly being used by businesses when the desired name under "com" is already registered by another organization. Today anyone can register a name in the Net domain.

n.org: For miscellaneous organizations, including non-profits.

n.edu: For four-year accredited institutions of higher learning.

n.gov: For US Federal Government entities

n.mil: For US military

nCountry Codes :For individual countries based on the International Standards Organization. For example, ca for Canada, and jp for Japan.

 

Domain Name Hierarchy

 

Name lookup and resolution

nIf a domain name is used to address a host, its corresponding IP address must be obtained for the lower-layer network software.

nThe mapping, or name resolution, must be maintained in some  registry.

nFor runtime name resolution, a network service is needed; a protocol must be defined for the naming scheme and for the service.  Example: The DNS service supports the DNS; the Java RMI registry supports RMI object lookup; JNDI is a network service lookup protocol.

 

Addressing a process running on a host

Logical Ports

 

Well Known Ports

nEach Internet host has 216 (65,535) logical ports.  Each port is identified by a number between 1 and 65535, and can be allocated to a particular process.

nPort numbers beween 1 and 1023 are reserved for processes which provide well-known services such as finger, FTP, HTTP, and email.

 

Well-known ports

 

Choosing a port to run your program

nFor our programming exercises: when a port is needed, choose a random number above the well known ports: 1,024- 65,535.

nIf you are providing a network service for the community, then arrange to have a port assigned to and reserved for your service.

 

Addressing a Web Document

The Uniform Resource Identifier (URI)

nResources to be shared on a network need to be uniquely identifiable.

nOn the Internet, a URI is a character string which allows a resource to be located.

nThere are two types of URIs:

nURL (Uniform Resource Locator) points to a specific resource at a specific location

nURN (Uniform Resource Name) points to a specific resource at a nonspecific location.

 

URL

A URL has the format of:

 protocol://host address[:port]/directory path/file name#section

 

nThe path in a URL is relative to the document root of the server.  On the CSL systems, a user’s document root is ~/www.

nA URL may appear in a document  in a relative form:

         < a href=“another.html”>

    and the actual URL referred to will be another.html preceded by the protocol, hostname, directory path of the document .