BHAVANI 2
BHAVANI 2
INTRODUCTION
1
2.SYSTEM CONFIGURATION
2.1HARDWARE CONFIGURATION
Hard disk : 40 GB
RAM : 512 MB
2.2SOFTWARE SPECIFICATION
User Interface
* Swing - Swing is a set of classes that provides more powerful and flexible components
that are possible with AWT. In addition to the familiar components, such as button
checkboxes and labels, swing supplies several exciting additions, including tabbed panes,
scroll panes, trees and tables.
* Applet - Applet is a dynamic and interactive program that can run inside a web page
displayed by a java capable browser such as hot java or Netscape.
2
Software Interface
JDK 1.5
2.3SOFTWARE DESCRIPTION
Java:
Java was conceived by James Gosling, Patrick Naughton, Chris Wrath, Ed Frank, and
language that extends it’s features wide over the network.Java2 version introduces an
new component called “Swing” – is a set of classes that provides more power
- It’s a light weight package, as they are not implemented by platform-specific code.
-Related classes are contained in javax.swing and its sub packages, such as
javax.swing.tree.
-Components explained in the Swing have more capabilities than those of AWT
What Is Java?
3
Java is a high-level programming language that is all of the following:
Simple
Object-oriented
Distributed
Interpreted
Robust
Secure
Architecture-neutral
Portable
High-performance
Multithreaded
Dynamic
Java is also unusual in that each Java program is both compiled and interpreted.
With a compiler, you translate a Java program into an intermediate language called Java
byte codes--the platform-independent codes interpreted by the Java interpreter. With an
interpreter, each Java byte code instruction is parsed and run on the computer.
Compilation happens just once; interpretation occurs each time the program is executed.
This figure illustrates how this works.
4
Java byte codes can be considered as the machine code instructions for the Java
Virtual Machine (Java VM). Every Java interpreter, whether it's a Java development tool
or a Web browser that can run Java applets, is an implementation of the Java VM. The
Java VM can also be implemented in hardware.
Java byte codes help make "write once, run anywhere" possible. The Java program
can be compiled into byte codes on any platform that has a Java compiler. The byte codes
can then be run on any implementation of the Java VM. For example, the same Java
program can run on Windows NT, Solaris, and Macintosh.
The following figure depicts a Java program, such as an application or applet, that's
running on the Java platform. As the figure shows, the Java API and Virtual Machine
insulates the Java program from hardware dependencies.
Probably the most well-known Java programs are Java applets. An applet is a Java
program that adheres to certain conventions that allow it to run within a Java-enabled
browser.
However, Java is not just for writing cute, entertaining applets for the World Wide
Web ("Web"). Java is a general-purpose, high-level programming language and a
powerful software platform. Using the generous Java API, we can write many types of
programs.
The most common types of programs are probably applets and applications, where
a Java application is a standalone program that runs directly on the Java platform.
6
How does the Java API support all of these kinds of programs?
The Essentials: Objects, strings, threads, numbers, input and output, data structures,
system properties, date and time, and so on.
Internationalization: Help for writing programs that can be localized for users
worldwide. Programs can automatically adapt to specific locales and be displayed in the
appropriate language.
Java not only has a core API, but also standard extensions. The standard extensions
define APIs for 3D, servers, collaboration, telephony, speech, animation, and more.
7
How Will Java Change My Life?
Java is likely to make your programs better and requires less effort than other
languages. We believe that Java will help you do the following:
Get started quickly: Although Java is a powerful object-oriented language, it's easy to
learn, especially for programmers already familiar with C or C++.
Write less code: Comparisons of program metrics (class counts, method counts, and so
on) suggest that a program written in Java can be four times smaller than the same
program in C++.
Write better code: The Java language encourages good coding practices, and its garbage
collection helps you avoid memory leaks. Java's object orientation, its JavaBeans
component architecture, and its wide-ranging, easily extendible API let you reuse other
people's tested code and introduce fewer bugs.
Develop programs faster: Your development time may be as much as twice as fast
versus writing the same program in C++. Why? You write fewer lines of code with Java
and Java is a simpler programming language than C++.
Avoid platform dependencies with 100% Pure Java: You can keep your program
portable by following the purity tips mentioned throughout this book and avoiding the
use of libraries written in other languages.
Write once, run anywhere: Because 100% Pure Java programs are compiled into
machine-independent byte codes, they run consistently on any Java platform.
Distribute software more easily: You can upgrade applets easily from a central server.
Applets take advantage of the Java feature of allowing new classes to be loaded "on the
fly," without recompiling the entire program.
8
Networking Basics
Ken Thompson and Dennis Ritchie developed UNIX in concert with the C
language at Bell Telephone Laboratories, Murray Hill, New Jersey, in 1969. In 1978, Bill
Joy was leading a project at Cal Berkeley to add many new features to UNIX, such as
virtual memory and full-screen display capabilities. By early 1984, just as Bill was
leaving to found Sun Microsystems, he shipped 4.2BSD, commonly known as Berkeley
UNIX.4.2BSD came with a fast file system, reliable signals, interprocess communication,
and, most important, networking. The networking support first found in 4.2 eventually
became the de facto standard for the Internet. Berkeley’s implementation of TCP/IP
remains the primary standard for communications with the Internet. The socket paradigm
for inter process and network communication has also been widely adopted outside of
Berkeley.
Socket Overview
A network socket is a lot like an electrical socket. Various plugs around the
network have a standard way of delivering their payload. Anything that understands the
standard protocol can “plug in” to the socket and communicate.
Internet protocol (IP) is a low-level routing protocol that breaks data into
small packets and sends them to an address across a network, which does not guarantee to
deliver said packets to the destination.
9
Client/Server
A server is anything that has some resource that can be shared. There are compute
servers, which provide computing power; print servers, which manage a collection of
printers; disk servers, which provide networked disk space; and web servers, which store
web pages. A client is simply any other entity that wants to gain access to a particular
server.
Reserved Sockets
Java supports TCP/IP both by extending the already established stream I/O
interface. Java supports both the TCP and UDP protocol families. TCP is used for reliable
stream-based I/O across the network. UDP supports a simpler, hence faster, point-to-
point datagram-oriented model.
10
InetAddress
Factory Methods
throws UnknownHostException
11
On the internet, it is common for a single name to be used to represent several
machines. In the world of web servers, this is one way to provide some degree of scaling.
The getAllByName ( ) factory method returns an array of InetAddresses that represent all
of the addresses that a particular name resolves to. It will also throw an
UnknownHostException if it can’t resolve the name to at least one address. Java 2,
version 1.4 also includes the factory method getByAddress( ), which takes an IP address
and returns an InetAddress object. Either an IPv4 or an IPv6 address can be used.
Instance Methods
The InetAddress class also has several other methods, which can be used on
the objects returned by the methods just discussed. Here are some of the most commonly
used.
Boolean equals (Object other)- Returns true if this object has the same
Internet address as other.
String get HostName( )- Returns a string that represents the host name
associated with the InetAddress object.
, it returns false.
String to String( )- Returns a string that lists the host name and the IP
address for conveneince. boolean isMulticastAddress( )- Returns true if this Internet
address is a multicast address. Otherwise
12
autocratically, such as for itself and nearby servers. For other names, it may ask a local
DNS server for IP address information. If that server doesn’t have a particular address, it
can go to a remote site and ask for it. This can continue all the way up to the root server,
called Inter NIC (internic.net).
There are two kinds of TCP sockets in Java. One is for servers, and the other is for
clients. The Server Socket class is designed to be a “listener,” which waits for clients to
connect before doing anything. The Socket class is designed to connect to server sockets
and initiate protocol exchanges.
A socket can be examined at any time for the address and port information
associated with it, by use of the following methods:
13
InetAddress getInetAddress( )- Returns the InetAddress associated with the
Socket object.
int getPort( ) Returns the remote port to which this Socket object is connected.
int getLocalPort( ) Returns the local port to which this Socket object is
connected.
Once the Socket object has been created, it can also be examined to gain
access to the input and output streams associated with it. Each of these methods can
throw an IOException if the sockets have been invalidated by a loss of connection on the
Net.
Java has a different socket class that must be used for creating server
applications. The ServerSocket class is used to create servers that listen for either local or
remote client programs to connect to them on published ports. ServerSockets are quite
different form normal Sockets.
14
ServerSocket(int port) Creates server socket on the specified port with a queue
length of 50.
ServerSocket has a method called accept( ), which is a blocking call that will wait
for a client to initiate communications, and then return with a normal Socket that is then
used for communication with the client.
URL
The Web is a loose collection of higher-level protocols and file formats, all
unified in a web browser. One of the most important aspects of the Web is that Tim
Berners-Lee devised a scaleable way to locate all of the resources of the Net. The
Uniform Resource Locator (URL) is used to name anything and everything reliably.
Format
15
second component is the host name or IP address of the host to use; this is delimited on
the left by double slashes (/ /) and on the right by a slash (/) or optionally a colon (:) and
on the right by a slash (/). The fourth part is the actual file path. Most HTTP servers will
append a file named index.html or index.htm to URLs that refer directly to a directory
resource.
Java’s URL class has several constructors, and each can throw a Malformed
URL Exception. One commonly used form specifies the URL with a string that is
identical to what is displayed in a browser:
URL(String urlSpecifier)
The next two forms of the constructor breaks up the URL into its component parts:
JDBC
In an effort to set an independent database standard API for Java, Sun Microsystems
developed Java Database Connectivity, or JDBC. JDBC offers a generic SQL database
access mechanism that provides a consistent interface to a variety of RDBMS. This
consistent interface is achieved through the use of “plug-in” database connectivity
16
modules, or drivers. If a database vendor wishes to have JDBC support, he or she must
provide the driver for each platform that the database and Java run on.
To gain a wider acceptance of JDBC, Sun based JDBC’s framework on ODBC. As you
discovered earlier in this chapter, ODBC has widespread support on a variety of
platforms. Basing JDBC on ODBC will allow vendors to bring JDBC drivers to market
much faster than developing a completely new connectivity solution.
JDBC Goals
Few software packages are designed without goals in mind. JDBC is one that, because of
its many goals, drove the development of the API. These goals, in conjunction with early
reviewer feedback, have finalized the JDBC class library into a solid framework for
building database applications in Java.
The goals that were set for JDBC are important. They will give you some insight as to
why certain classes and functionalities behave the way they do. The eight design goals
for JDBC are as follows:
SQLevelAPI
The designers felt that their main goal was to define a SQL interface for Java. Although
not the lowest database interface level possible, it is at a low enough level for higher-
level tools and APIs to be created. Conversely, it is at a high enough level for application
programmers to use it confidently. Attaining this goal allows for future tool vendors to
“generate” JDBC code and to hide many of JDBC’s complexities from the end user.
SQLConformance
SQL syntax varies as you move from database vendor to database vendor. In an effort to
support a wide variety of vendors, JDBC will allow any query statement to be passed
through it to the underlying database driver. This allows the connectivity module to
handle non-standard functionality in a manner that is suitable for its users.
17
JDBC must be implemental on top of common database interfaces
The JDBC SQL API must “sit” on top of other common SQL level APIs. This goal
allows JDBC to use existing ODBC level drivers by the use of a software interface. This
interface would translate JDBC calls to ODBC and vice versa.
Provide a Java interface that is consistent with the rest of the Java system
Because of Java’s acceptance in the user community thus far, the designers feel that they
should not stray from the current design of the core Java system. Keep it simple
This goal probably appears in all software design goal listings. JDBC is no exception.
Sun felt that the design of JDBC should be very simple, allowing for only one method of
completing a task per mechanism. Allowing duplicate functionality only serves to
confuse the users of the API.
18
3.SYSTEM ANALYSIS
Time consumed to send the data is increased due to resending of lost data.
DISADVATAGES:
19
Recovery in all single failure scenarios without knowing root cause of the
failure.
Each and Every Node having Preconfigured Backup Path. That Backup
path maintains the routing table.
ADVANTAGES:
During message transfer the load is distributed which increases the speed of
transmission.
Modules
20
Module 1: Topology Construction
21
Module 3:Routing Table (Backup Path)
In the Data Transmission module, the Message transfer relates with that the
sender node wants to send a message to the destination node
Sender node first selects the Destination node.
Sender types the data or browses the .txt file and uploads the url from the textbox.
Checks the corresponding node and corresponding path is available .
After the path is selected also find out that node or link is failure and status of the
destination node through is true.
If anyone of the node or link is failed means sender use the preconfigured backup
path.
22
4.SYSTEM DESIGN
Source
Check
failure Node or
means Link
failure
Routing Table
No Failure
maintain the
back up path
23
4.2 System Architecture
USER
SQL
24
CLASS DIAGRAM:
pathcon NODEC
addcombo() bckuppath()
server getrelatednode()
startserver() sendpackets()
adddata()
25
USECASE DIAGRAM:
Topology Creation
26
4.3 DATABASE NAME: MRC
nodename nvarchar
ipaddress nvarchar
portno nvarchar
sourcenode nvarchar
destinationnode nvarchar
weights nvarchar
Destination nvarchar
path nvarchar
weights nvarchar
27
5.SYSTEM TESTING
The purpose of testing is to discover errors. Testing is the process of trying to discover
every conceivable fault or weakness in a work product. It provides a way to check the
functionality of components, sub assemblies, assemblies and/or a finished product It is
the process of exercising software with the intent of ensuring that the Software system
meets its requirements and user expectations and does not fail in an unacceptable manner.
There are various types of test. Each test type addresses a specific testing requirement.
Types of Tests
Unit testing involves the design of test cases that validate that the internal program
logic is functioning properly, and that program input produce valid outputs. All decision
branches and internal code flow should be validated. It is the testing of individual
software units of the application .it is done after the completion of an individual unit
before integration. This is a structural testing, that relies on knowledge of its construction
and is invasive. Unit tests perform basic tests at component level and test a specific
business process, application, and/or system configuration. Unit tests ensure that each
unique path of a business process performs accurately to the documented specifications
and contains clearly defined inputs and expected results.
28
Functional test
System Test
System testing ensures that the entire integrated software system meets
requirements. It tests a configuration to ensure known and predictable results. An
example of system testing is the configuration oriented system integration test. System
testing is based on process descriptions and flows, emphasizing pre-driven process links
and integration points.
Performance Test
The Performance test ensures that the output be produced within the time limits,
and the time taken by the system for compiling, giving response to the users and request
being send to the system for to retrieve the results.
29
5.2 Integration Testing
Check the Route status in the Cache Table after the status information is received by the
Node
Acceptance Testing
User Acceptance Testing is a critical phase of any project and requires significant
participation by the end user. It also ensures that the system meets the functional
requirements.
The Acknowledgements will be received by the Sender Node after the Packets are
received by the Destination Node
The Route add operation is done only when there is a Route request in need
The Status of Nodes information is done automatically in the Cache Updation process
30
6.SYSTEM IMPLEMENTATION
Implementation is the stage in the project where the theoretical design is turned
into a working system and is giving confidence on the new system for the users, which it
will work efficiently and effectively. It involves careful planning, investigation of the
current System and its constraints on implementation, design of methods to achieve the
change over, an evaluation, of change over methods. Apart from planning major task of
preparing the implementation are education and training of users. The more complex
system being implemented, the more involved will be the system analysis and the design
effort required just for implementation.
Implementation is the final and important phase, the most critical stage in
achieving a successful new system and in giving the users confidence. That the new
system will work is effective .The system can be implemented only after through testing
is done and if it found to working according to the specification. This method also offers
the greatest security since the old system can take over if the errors are found or inability
to handle certain type of transactions while using the new system.
User Training
After the system is implemented successfully, training of the user is one of the most
important subtasks of the developer. For this purpose user manuals are prepared and
handled over to the user to operate the developed system. Thus the users are trained to
operate the developed systems successfully in future .In order to put new application
system into use, the following activities were taken care of:
31
Preparation of user and system documentation
Test run for some period to ensure smooth switching over the system.
The users are trained to use the newly developed functions. User manuals describing the
procedures for using the functions listed on menu and circulated to all the users .it is
confirmed that the system is implemented up to user need and expectations.
Security
The Administrator checks the path information and status information before the data
transfer
Messages that are sent will receive the acknowledgements automatically if there is no
link failure after the message received by the Receiver Node
Failure of link’s will automatically make updation in the Cache table to other nodes in
the Network
By adding the nodes in its notification list. The graph will be close to a tree.
Second, we piggyback a notification on the data packet that encounters a broken link if
that packet can be salvaged. When using the algorithm, we also use a small list of broken
links, which is similar to the negative cache proposed in prior work, to prevent a node
from being re-polluted by in-flight stale routes.
32
6.1Source Code
AddNode.java:
/****************************************************************/
/* AddNode */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
/**
* Summary description for AddNode
*
*/
public class AddNode extends JFrame
{
// Variables declaration
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JTextField jTextField1;
private JTextField jTextField2;
private JTextField jTextField3;
private JButton ADD;
private JButton FINISH;
private JPanel contentPane;
// End of variables declaration
Statement st;
Connection con;
public AddNode()
{
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
33
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:MRC","sa","");
st=con.createStatement();
st.executeUpdate("delete from newnodedetails");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel5 = new JLabel();
jLabel6 = new JLabel();
jTextField1 = new JTextField();
jTextField2 = new JTextField();
jTextField3 = new JTextField();
ADD = new JButton();
FINISH = new JButton();
contentPane = (JPanel)this.getContentPane();
//
// jLabel2
//
jLabel2.setText("Node Name");
//
// jLabel3
//
jLabel3.setText("TOPOLOGY CONSTRUCTION");
//
// jLabel4
//
jLabel4.setText("IP Address");
//
// jLabel5
//
jLabel5.setText("Port No");
34
jLabel6.setIcon(new ImageIcon("C:\\Documents and
Settings\\shi\\Desktop\\MRC\\images\\images.jpg"));
jLabel6.setText("jLabel6");
//
// jTextField1
//
jTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField1_actionPerformed(e);
}
});
//
// jTextField2
//
jTextField2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField2_actionPerformed(e);
}
});
//
// jTextField3
//
jTextField3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField3_actionPerformed(e);
}
});
//
// ADD
//
ADD.setText("ADD");
ADD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
ADD_actionPerformed(e);
}
});
FINISH.setText("FINISH");
FINISH.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
FINISH_actionPerformed(e);
}
});
35
//
// contentPane
//
contentPane.setLayout(null);
contentPane.setBackground(new Color(204, 204, 0));
addComponent(contentPane, jLabel2, 72,70,60,32);
addComponent(contentPane, jLabel3, 113,11,150,30);
addComponent(contentPane, jLabel4, 72,120,60,18);
addComponent(contentPane, jLabel5, 71,162,60,18);
addComponent(contentPane, jLabel6, -314,1,701,275);
addComponent(contentPane, jTextField1, 167,73,100,22);
addComponent(contentPane, jTextField2, 166,117,100,22);
addComponent(contentPane, jTextField3, 167,157,100,22);
addComponent(contentPane, ADD, 77,214,83,28);
addComponent(contentPane, FINISH, 177,214,83,28);
//
// AddNode
//
this.setTitle("AddNode - extends JFrame");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(390, 300));
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jTextField1_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
36
System.out.println("\njTextField3_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
}
catch(Exception e1)
{
e1.printStackTrace ();
}
//
// TODO: Add any method code to meet your needs in the following area
//
37
NODEA.java
/****************************************************************/
/* NODEA */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import javax.swing.table.*;
/**
* Summary description for NODEA
*
*/
public class NODEA extends JFrame
{
// Variables declaration
private JTabbedPane jTabbedPane1;
private JPanel contentPane;
//-----
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel lab_list;
private JLabel lab1_list;
private JLabel messge_label;
private JLabel receive_label;
private JTextField jTextField1;
private JComboBox combo;//DESTINATION ADDRESS
private JTextField txt_path;//BROWSE FILE PATH
private JList jList1;
private JScrollPane jScrollPane1;
private JButton jButton1;// SEND BUTTON
private JButton jButton2;// BROWSE BUTTON
private JPanel NODE;
private JTextArea jTextArea2; //SENDING MESSAGE
private JScrollPane jScrollPane2;
private JTextArea jTextArea3; //RECEVING MESSAGE
private JScrollPane jScrollPane3;
private JButton jButton3;//CLEAR BUTTON
38
private JButton jButton4;// RESTRICT BUTTON
private JButton LINKFAILURE;// LINK FAILURE BUTTON
//-----
private JPanel ROUTER;
String findedpath1="";
String str="";
String nodename="A";
int portt;
String ipaddress="";
String fname="";
String sender="";
String nexthost="";
//-----
// End of variables declaration
public NODEA()
{
super();
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
start();
getrelatednodes();
bckuppath();
try
{
Socket s=new Socket("localhost",5690);
out.writeUTF("getnodeport");
39
out.writeUTF(nodename);
//out.writeUTF(ipaddress);
String receive=in.readUTF();
String receive2=in.readUTF();
start();
portt=Integer.parseInt(receive);
serverlisten();
}
catch (Exception ex)
{
System.out.println("jwgd:"+ex);
ex.printStackTrace();
}
try
{
outt.writeUTF("getaallnodes");
outt.writeUTF("");
System.out.println("gfghdfjkhsdfjk");
40
DataInputStream inn=new DataInputStream(sd.getInputStream());
String ar=inn.readUTF();
System.out.println("is1 :"+ar);
String ar1=inn.readUTF();
System.out.println("2nd:"+ar1);
String[] arr=ar.split("@");
}
catch (Exception ex)
{
System.out.println(ex);
ex.printStackTrace();
}
Socket s=node.accept();
if(p1.equals("message"))
{
String[] ss=p.split("&");
int lent=ss[1].length();
if (lent == 1)
{
41
jTextArea3.setText(ss[0]);
}
else
{
findedpath1=ss[1];
str=ss[0];
sendPackets();
}
}
catch (Exception ex)
{
System.out.println(ex);
ex.printStackTrace();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
jTabbedPane1 = new JTabbedPane();
contentPane = (JPanel)this.getContentPane();
//-----
jLabel2 = new JLabel();
jLabel3 = new JLabel();
messge_label = new JLabel("SEND MSG");
receive_label = new JLabel("RECEIVED MSG");
lab_list= new JLabel("LINK DETAILS");
lab1_list= new JLabel("RESTRICT");
42
jTextField1 = new JTextField();
//jTextField2 = new JTextField();
txt_path=new JTextField();
jList1 = new JList();
combo = new JComboBox();
jScrollPane1 = new JScrollPane();
jButton1 = new JButton();
jButton2 = new JButton();
jButton3 = new JButton("CLEAR");
jButton4 = new JButton("RESTRICT");
LINKFAILURE=new JButton("ISOLATE");
NODE = new JPanel();
jTextArea2 = new JTextArea();
jScrollPane2 = new JScrollPane();
jTextArea3 = new JTextArea();
jScrollPane3 = new JScrollPane();
//-----
ROUTER = new JPanel();
//-----
//
// jTabbedPane1
//
jTabbedPane1.addTab("NODE", NODE);
jTabbedPane1.addTab("ROUTER", ROUTER);
jTabbedPane1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e)
{
jTabbedPane1_stateChanged(e);
}
});
//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jTabbedPane1, 5,12,458,452);
//
// jLabel2
//
jLabel2.setText("DESTINATION NODE");
//
// jLabel3
//
jLabel3.setText("SELECT FILE");
//
// jTextField1
//
jScrollPane2.setViewportView(jTextArea2);
jTextField1.addActionListener(new ActionListener() {
43
public void actionPerformed(ActionEvent e)
{
jTextField1_actionPerformed(e);
}
});
//
// jTextField2
//
//
// jList1
//
jList1.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e)
{
jList1_valueChanged(e);
}
});
//
// jScrollPane1
//
jScrollPane1.setViewportView(jList1);
jScrollPane3.setViewportView(jTextArea3);
//
// jButton1
//
jButton1.setText("SEND");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
//
// jButton2
//
jButton2.setText("BROWSE");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton2_actionPerformed(e);
}
});
//
// jButton3
//
44
//jButton3.setText("");
jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton3_actionPerformed(e);
}
});
//
// jButton4
//
// jButton4.setText();
jButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton4_actionPerformed(e);
}
});
LINKFAILURE.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
LINKFAILURE_actionPerformed(e);
}
});
//
// NODE
//
NODE.setLayout(null);
addComponent(NODE,jLabel2, 10,30,130,25);
addComponent(NODE,combo, 160,30,90,25);
addComponent(NODE,jLabel3, 10,80,100,25);
45
addComponent(NODE,txt_path, 90,80,160,25);
addComponent(NODE,lab1_list,359,20,80,20);
addComponent(NODE,lab_list,355,40,80,25);
addComponent(NODE,jScrollPane1,350,65,90,80);
addComponent(NODE,jButton4,350,165,90,25);
addComponent(NODE,LINKFAILURE,350,190,90,25);
addComponent(NODE,jButton2,255,80,80,25);
addComponent(NODE,messge_label, 20,130,100,25);
addComponent(NODE,jScrollPane2, 20,160,110,95);
addComponent(NODE,jButton1, 20,270,100,25);
addComponent(NODE,receive_label, 140,130,100,25);
addComponent(NODE,jScrollPane3, 140,160,110,95);
addComponent(NODE,jButton3, 140,270,100,25);
addComponent(ROUTER,jsp, 10,30,130,25);
//ROUTER.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
//
// NODEA
//
this.setTitle("NODEA - extends JFrame");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(550,452));
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jTabbedPane1_stateChanged(ChangeEvent e)
{
System.out.println("\njTabbedPane1_stateChanged(ChangeEvent e) called.");
// TODO: Add any handling code here
46
private void jList1_valueChanged(ListSelectionEvent e)
{
System.out.println("\njList1_valueChanged(ListSelectionEvent e) called.");
if(!e.getValueIsAdjusting())
{
Object o = jList1.getSelectedValue();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
// TODO: Add any handling code here for the particular object being selected
}
}
String dest=(String)combo.getSelectedItem();
str=jTextArea2.getText();
System.out.println("Dest"+dest);
try
{
Socket ss=new Socket("localhost",5690);//1680
DataOutputStream dos=new DataOutputStream(ss.getOutputStream());
47
Socket bp=new Socket("localhost",5690);//1680
DataOutputStream bp1=new DataOutputStream(bp.getOutputStream());
//DataInputStream bp2=new DataInputStream(bp.getInputStream());
bp1.writeUTF("getbackuppath");
bp1.writeUTF(nodename);
System.out.println("backup path");
DataInputStream op=new DataInputStream(bp.getInputStream());
validpath1=op.readUTF();
for(int i=0;i<validpath.size();i++)
{
String data=String.valueOf(validpath.elementAt(i));
int intlen=data.length();
String strDes=data.substring(intlen-1,intlen);
Vbck.addElement(nodename);
Vbck.addElement(strDes);
Vbck.addElement(data);
//bp1.writeUTF("getbackuppath");
//bp1.writeUTF(nodename);
//System.out.println("backup path");
DataInputStream opdest=new DataInputStream(bp.getInputStream());
48
DESTvalidpath1=opdest.readUTF();
int intlen=data.length();
String strDes=data.substring(intlen-1,intlen);
Vbck.addElement(strDes);
Vbck.addElement(nodename);
Vbck.addElement(data);
//valid.add(validpath);
// System.out.println("back"+validpath);
//
// Iterator e2=validpath.iterator();
//
// String strValues="",strBPath="";
//
// while (e2.hasNext())
// {
// strValues+=e2.next().toString()+"&";
// }
// System.out.println("Records "+strValues);
//
// String [] bckpath=strValues.split("&");
// for(int i=0;i<bckpath.length;i++)
49
// {
// strBPath=bckpath[i];
//
// }
}
catch (Exception x)
{
x.printStackTrace();
}
}
dal.writeUTF("getalllinks");
dal.writeUTF(nodename);
String allpaths=di.readUTF();
//allpaths=jList1.setText();
//list_view.setListData(vector_list);
//jList1.setListData(allpaths);
System.out.println("helllllllllllllloooooooo:"+allpaths);
String[] arr_ap=allpaths.split("&");
Vector inn=in(arr_ap[0]);
Vector outt=out(arr_ap[1]);
50
Enumeration e1=inn.elements();
while (e1.hasMoreElements())
{
vv.addElement(e1.nextElement());
}
Enumeration e2=outt.elements();
while (e2.hasMoreElements())
{
vv.addElement(e2.nextElement());
}
//jList1.setListData(inn);
jList1.setListData(vv);
}
catch (Exception ex)
{
System.out.println(" exsception in getrelatednodes Method:"+ex);
ex.printStackTrace();
}
}
51
{
try
{
System.out.println("----fpppp----------------:"+findedpath1);
String[] pathh=findedpath1.split(">");
System.out.println("pathh value one is:"+pathh[0]);
System.out.println("pathh value two is:"+pathh[1]);
System.out.println("hghghj;;;;;;;;;:");
int portno=Integer.parseInt(diis.readUTF());
ipaddress=diis.readUTF();
int len=findedpath1.length();
findedpath1=findedpath1.substring(2,len);
Socket sss=new Socket(ipaddress,portno);
DataOutputStream dout=new DataOutputStream(sss.getOutputStream());
dout.writeUTF("message");
dout.writeUTF(str+"&"+findedpath1);
// String ack1=diis.readUTF();
// System.out.println("this is ack"+ack1);
}
catch (Exception ex)
{
System.out.println(" exsception in sendPacket Method:"+ex);
ex.printStackTrace();
}
System.out.println("\nBROWSE_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
File file;
JFileChooser fc=new JFileChooser(".");
int val=fc.showOpenDialog(this);
52
try
{
if(val==JFileChooser.APPROVE_OPTION)
{
file=fc.getSelectedFile();
String path=file.getAbsolutePath();
System.out.println(path);
FileInputStream fis=new FileInputStream(file);
byte[] by1=new byte[fis.available()];
fis.read(by1);
String st1=new String(by1);
jTextArea2.setText(st1);
txt_path.setText(path);
//jTextArea1.setText(path);
}
}
catch (Exception ex)
{
ex.printStackTrace();
jTextArea3.setText("");
try
{
String listval="";
System.out.println("\njButton2_actionPerformed(ActionEvent e) called.");
Socket s1s=new Socket("localhost",5690);//1680
DataOutputStream dos1=new DataOutputStream(s1s.getOutputStream());
String p_name= jList1.getSelectedValue().toString();
//Object [ ] selected=jList1.getSelectedValues();
System.out.println("This is jList1:"+p_name);
dos1.writeUTF("restrictlink");
dos1.writeUTF(p_name);//lhost
System.out.println("RESTRICT LINK WEIGHT:");
53
DataInputStream diis=new DataInputStream(s1s.getInputStream());
String dmsg1=diis.readUTF();
System.out.println("dialog message is:"+dmsg1);
JOptionPane.showMessageDialog(this,dmsg1);
}
catch (Exception ex)
{
ex.printStackTrace();
}
dos1.writeUTF("LinkFailure");
dos1.writeUTF(lf_name);//lhost
DataInputStream diis=new DataInputStream(lf.getInputStream());
String dmsg=diis.readUTF();
System.out.println("dialog message is:"+dmsg);
JOptionPane.showMessageDialog(this,dmsg);
Object o=jList1.getSelectedValue();
//int index=Integer.parseInt(lf_name);
//System.out.println("Index value ::"+index);
//jList1.remove(index);
//jList1.clearSelection();
}
catch (Exception lf1)
{
lf1.printStackTrace();
54
}
pathtab.addRow(vbpath);
}
}
}
//
// TODO: Add any method code to meet your needs in the following area
//
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
ex.printStackTrace();
55
}
new NODEA();
}
//= End of Testing =
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new AddNode();
}
//= End of Testing =
HOME.java
/****************************************************************/
/* hOME */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Summary description for hOME
*
*/
56
public class Home extends JFrame
{
// Variables declaration
private JLabel jLabel1;
private JButton jButton1;
private JPanel contentPane;
// End of variables declaration
public Home()
{
super();
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
jLabel1 = new JLabel();
jButton1 = new JButton();
contentPane = (JPanel)this.getContentPane();
//
// jLabel1
//
jLabel1.setIcon(new ImageIcon("images\\networking2.jpg"));
jLabel1.setText("jLabel1");
//
// jButton1
//
jButton1.setIcon(new ImageIcon("images\\s3.jpg"));
jButton1.setText("jButton1");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
//
57
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jLabel1, -9,2,445,318);
addComponent(contentPane, jButton1, 161,324,114,53);
//
// hOME
//
this.setTitle("hOME - extends JFrame");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(444, 406));
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jButton1_actionPerformed(ActionEvent e)
{
System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
this.setVisible(false);
AddNode a = new AddNode();
//
// TODO: Add any method code to meet your needs in the following area
//
58
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new Home();
}
//= End of Testing =
path.java
import java.sql.*;
import java.util.*;
59
// DB= new sql();
// st=DB.connect();
//System.out.println(start);
//System.out.println(strDst);
//st.execute("delete possibledelay");
strDest = strDst;
strStart = start;
flip = true;
flip1 = true;
flip2 = false;
index = -1;
weight = 0;
getPath( start );
}
catch( Exception e )
{
e.printStackTrace( );
}
}
while( rs.next( ) )
{
flip2 = true;
if( flip == false )
{
for( int i=0;i < index;i++ )
{
stack[i] = stack[i+1];
}
index--;
flip = true;
}
60
String strarray[ ] = strStart.split( ">" );
flip1 = true;
} // end of while loop
if(nodePath.substring(end + 1).equals(strDest))
61
{
findWeight( nodePath );
if( index != 0 )
{
for( int i = 0; i <= index; i++ )
{
stack[i] = stack[i+1];
}
index--;
flip = true;
strStart = stack[0];
findNode( stack[0] );
}
}
else
{
flip = false;
getPath( nodePath.substring(end + 1) );
// getPath( nodePath.substring( nodePath.length( )-1) , nodePath.substring( nodePath.length( )-
3,(nodePath.length( )-3) + 1 ) );
}
}
try
{
for( int i = 0;i < strArray.length-1;i++ )
{
if( rs.next())
{
weight += rs.getInt(3);
}
}
System.out.println("Path-->"+nodePath);
System.out.println("Weight-->"+weight);
String pathweight =nodePath+"#"+weight;
System.out.println("Find path"+pathweight);
if(rs.next())
{
System.out.println( "Already Exist" );
}
62
else
{
st.executeUpdate("insert into findedpath values(
'"+strDest+"','"+nodePath+"',"+weight+" )" );
System.out.println( "weight"+weight );
//cost = 0;
weight = 0;
}
System.out.println("Find path");
vPathWeigth.add(pathweight);
catch( Exception e )
{
e.printStackTrace( );
}
}
}
pathcon.java
/****************************************************************/
/* pathcon */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
/**
* Summary description for pathcon
*
*/
public class pathcon extends JFrame
{
// Variables declaration
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel6;
private JTextField jTextField3;
private JComboBox jComboBox1;
63
private JComboBox jComboBox2;
Connection con;
Statement st;
public pathcon()
{
super();
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:MRC","sa","");
st=con.createStatement();
st.executeUpdate("delete from edgedetails");
}
catch (Exception e1)
{
System.out.println(e1);
e1.printStackTrace();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
jLabel2 = new JLabel();
64
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel6 = new JLabel();
jTextField3 = new JTextField();
jComboBox1 = new JComboBox();
jComboBox2 = new JComboBox();
CREATE = new JButton();
FINISH = new JButton();
contentPane = (JPanel)this.getContentPane();
//
// jLabel2
//
jLabel2.setForeground(new Color(255, 153, 255));
jLabel2.setText("SOURCE NODE NAME");
//
// jLabel3
//
jLabel3.setForeground(new Color(255, 51, 255));
jLabel3.setText(" DESTINATION NODE NAME");
//
// jLabel4
//
jLabel4.setForeground(new Color(255, 51, 255));
jLabel4.setText(" WEIGHTS");
//
// jLabel6
//
jLabel6.setIcon(new ImageIcon("C:\\Documents and
Settings\\shi\\Desktop\\MRC\\images\\networking iStock_000005664283Small.jpg"));
jLabel6.setText("jLabel6");
//
// jTextField1
//
//jTextField1.addActionListener(new ActionListener() {
//public void actionPerformed(ActionEvent e)
//{
// jTextField1_actionPerformed(e);
//}
//});
//
// jTextField2
//
//jTextField2.addActionListener(new ActionListener() {
//public void actionPerformed(ActionEvent e)
//{
// jTextField2_actionPerformed(e);
//}
//});
65
//
// jTextField3
//
jTextField3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jTextField3_actionPerformed(e);
}
});
jComboBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox1_actionPerformed(e);
}
});
jComboBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox2_actionPerformed(e);
}
});
//
// CREATE
//
CREATE.setForeground(new Color(255, 51, 255));
CREATE.setText("CREATE");
CREATE.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
CREATE_actionPerformed(e);
}
});
FINISH.setText("FINISH");
FINISH.addActionListener(new ActionListener() {
66
public void actionPerformed(ActionEvent e)
{
FINISH_actionPerformed(e);
}
});
//
// contentPane
//
contentPane.setLayout(null);
contentPane.setBackground(new Color(217, 206, 147));
//
// pathcon
//
this.setTitle("pathcon - extends JFrame");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(390, 300));
addcombo();
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jTextField3_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField3_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
67
}
Object o = jComboBox1.getSelectedItem();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
// TODO: Add any handling code here for the particular object being selected
Object o = jComboBox2.getSelectedItem();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
// TODO: Add any handling code here for the particular object being selected
68
{
System.out.println("\nADD_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
String s11=(String)jComboBox1.getSelectedItem();
String s22=(String)jComboBox2.getSelectedItem();
String s33=jTextField3.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:MRC","sa","");
Statement st=con.createStatement();
//jComboBox1.setText("");
//jComboBox2.setText("");
jTextField3.setText("");
}
catch(Exception e1)
{
e1.printStackTrace();
}
//
// TODO: Add any method code to meet your needs in the following area
//
69
//= The following main method is just for testing this class you built.=//
//= After testing,you may simply delete it. =//
//======================================================================//
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new pathcon();
}
//= End of Testing =
70
71
72
73
74
75
76