Post on 07-Apr-2018
transcript
1
MESH BASED MULTICAST ROUTING PROTOCOL FOR MANET:
A Link Based Approach
BY
HRUSHIKESH APTE,
ASHWIN B. RAJ,
JOSHUA P. MORAN
TERM PROJECT
Submitted in partial fulfillment of the course Computer Networks at
Santa Clara University
Santa Clara, California
2
Preface
This work was motivated by a desire for reliability and efficiency of mobile ad-hoc wireless
networks (MANETs). Increasingly, MANETs are becoming more commonplace in our lives, so they
deserve our attention.
Acknowledgments
This project has helped us learn a lot of about MANETs. We would like to thank Prof. Wang for
helping us come up with and implement the idea for multicast routing in ad-hoc MANET networks.
3
Table of Contents
Abstract......................................................................................................................................................4
Introduction................................................................................................................................................5
Theoretical basis and literature review.......................................................................................................5
Hypothesis..................................................................................................................................................5
Methodology..............................................................................................................................................5
Implementation..........................................................................................................................................6
Data analysis and discussion....................................................................................................................33
Conclusions and recommendations..........................................................................................................33
Bibliography.............................................................................................................................................34
Appendices........................................................
4
Abstract
With the increase in mobile devices, the demand for high performance wireless mobile ad-hoc
networks (MANETs) is growing. Multicast routing is used to support those services. Many problems
arise from node mobility that decrease reliability of the network. Solutions have previously been
proposed to the problems that arise in these networks, with varying reliability, overhead, and speed. In
this project, we propose and simulate a link-based approach for a mesh based multicast routing protocol
for MANETs with the goal of maximizing reliability with only minimal delay and overhead. The
simulation demonstrates the reliability of the approach we propose.
5
Introduction
A mobile ad-hoc network (MANET) is an infrastructureless, self-configuring network of mobile
devices. In MANETs, nodes are free to come and go, so the network needs to be very adaptable. They
are commonly used by mobile devices, especially cell phones, for various applications. Since the
demand for such services are high and increasing, the more important it becomes to implement high
quality protocols for MANETs.
Theoretical bases and literature review
MANETs are commonly supported by multicast routing protocols, which are network layer
protocols in which a message is initiated by one user but may be received by multiple users. Almost
every existing protocol for MANETs are either tree or mesh based. The tree-based protocols establish a
single path between any two nodes in the multicast group. The tree needs to be reconfigured when
node mobility causes link failure. When there are many sources, one either looses path optimality by
maintaining a shared tree, or suffer increased storage and control overhead by maintaining multiple
trees.
Many aspects of MANETs are covered in the literature from scalability (Gui and Mohapastra,
2004), security (Hu, Perrig, & Johnson, 2002), energy efficiency (Olagbegi and Meghanathan, 2010),
and network performance (Broch, Maltz, Johnson, Hu, & Jetcheva, 1998). Of these many problems, in
this project, we are primarily concerned with maximizing reliability while maintaining high speed.
Approaches similar to ours using forward error correction techniques have recently been presented to
address these issues. Such approaches have been proven to be reliable with a high delivery ratio (Chen,
Dow, Lin, Hwang, 2008).
Our solution seeks to improve the overall performance of similar algorithms by implementing a
stable mesh-based multicast routing scheme that utilizes stable forwarding nodes to provide a better
packet delivery ratio, control overhead, and packet delay.
Hypothesis
Our hypothesis is that our mesh-based multicast routing protocol, which uses a stable link-based
approach, can be implemented to ensure a high packet delivery ratio, low overhead, and low packet
delay.
6
Activity Diagram
Client sends message
Processing client request
Find out available paths and
choose shortest one
Path found
Send to receiver
Yes
No
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
7
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
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.
Integration testing
Integration tests are designed to test integrated software components to determine if they
actually run as one program. Testing is event driven and is more concerned with the basic outcome of
screens or fields. Integration tests demonstrate that although the components were individually
satisfaction, as shown by successfully unit testing, the combination of components is correct and
consistent. Integration testing is specifically aimed at exposing the problems that arise from the
combination of components.
Functional test
Functional tests provide a systematic demonstrations that functions tested are available as
specified by the business and technical requirements, system documentation , and user manuals.
Functional testing is centered on the following items:
Valid Input : identified classes of valid input must be accepted.
Invalid Input : identified classes of invalid input must be rejected.
Functions : identified functions must be exercised.
Output : identified classes of application outputs must be exercised.
Systems/Procedures : interfacing systems or procedures must be invoked.
Organization and preparation of functional tests is focused on requirements, key functions, or
special test cases. In addition, systematic coverage pertaining to identify
Business process flows; data fields, predefined processes, and successive processes must be considered
for testing. Before functional testing is complete, additional tests are identified and the effective value
of current tests is determined.
System Test
8
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.
White Box Testing
White Box Testing is a testing in which in which the software tester has knowledge of the inner
workings, structure and language of the software, or at least its purpose. It is purpose. It is used to test
areas that cannot be reached from a black box level .
Black Box Testing
Black Box Testing is testing the software without any knowledge of the inner workings, structure
or language of the module being tested . Black box tests, as most other kinds of tests, must be written
from a definitive source document, such as specification or requirements document, such as
specification or requirements document. It is a testing in which the software under test is treated, as a
black box .you cannot “see” into it. The test provides inputs and responds to outputs without
considering how the software works.
Methodology
Our program is a Java program that runs on Eclipse. It shows a simulation of the algorithm in
practice.
General algorithm:
The algorithm uses a tree management algorithm of hop-by-hop (HBH) transport which uses
three control messages to construct a shortest path tree. The receivers then periodically send messages
to the source. The receivers periodically receive messages that are multicast from the source.
Intermediate nodes may produce messages that refine the tree. When a source node needs to send data
to receiver nodes, a multicast mesh is created with stable links.
A mesh is created among members of the group by a mesh creation technique which uses a
control packet to identify group members in a in an expanded ring search. Each mesh created consists
of a logical core node, which maintains the tree and the tree members. A user multicast tree is then
created from the mesh so that the group members are nodes. The tree is then maintained by
periodically sending a message to group members. A core migration technique may be implemented to
maintain efficiency.
When a receiver joins the group, the group constructs a distribution tree using control messages.
Whenever a node identifies a link failure, a route error (RE) is produced with a route error flag,
and the node then sends the packet to either the receiver or source.
To test against hypothesis, we observe the behavior of the nodes when simulated using our Java
program to determine whether their performance meets the goal.
9
Implementation
The code of the program is as follows:
package networks;
import java.awt.*;
import java.applet.*; import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
@SuppressWarnings({ "serial", "unused" })
public class Terminal extends Applet implements ActionListener
{
String msg; Button but1;
Button but2;
Font f=new Font("TimesNewRoman",Font.BOLD, 40);
Font f1=new Font("TimesNewRoman",Font.BOLD, 10);
Font f2=new Font("TimesNewRoman",Font.BOLD, 20);
public static Socket cs[]=new Socket[5];
public static ServerSocket ss; public static PrintWriter pw;
public static String mobile[]=new String[5];
String tree="";
public void init()
{
setBackground(new Color(80,80,200));
setSize(1000,1000); setLayout(null);
repaint();
but1=new Button(" Start Listen ");
but1.setBounds(450,100,150,50);
add(but1); but1.addActionListener(this);
but2=new Button(" Draw Path "); but2.setBounds(600,100,150,50);
but2.setVisible(false); add(but2);
but2.addActionListener(this);
}
public void paint(Graphics g)
{
if(mobile[0].equals("yes"))
{ g.setFont(f1);
g.drawString("C (SENDER)",520,230);
g.fillOval(500,250,40,40); }
if(mobile[1].equals("yes")) {
g.setFont(f1);
10
g.drawString("C1",410,330);
g.fillOval(420,330,40,40);
}
if(mobile[2].equals("yes"))
{ g.setFont(f1);
g.drawString("C2",450,420);
g.fillOval(450,420,40,40); g.setFont(f2);
if(!mobile[3].equals("yes") && mobile[1].equals("yes"))
{ g.drawString("Generating Route",400,520);
new delay();
new delay(); new delay();
new delay();
new delay(); g.drawString("AlterNate Path: c-->c1-->c2-->c4",400,560);
}
if(!mobile[3].equals("yes") && !mobile[1].equals("yes"))
{
g.drawString("Generating Route",400,520);
new delay();
new delay(); new delay();
new delay();
new delay(); g.drawString("Sender cannot communicate with reciever",400,560);
} }
if(mobile[4].equals("yes")) {
g.setFont(f1);
g.drawString("C4 (RECIEVER)",550,420);
g.fillOval(540,420,40,40);
but2.setVisible(true);
}
if(mobile[3].equals("yes"))
{ g.setFont(f1);
g.drawString("C3",580,330);
g.fillOval(570,330,40,40); g.setFont(f2);
g.drawString("Generating Route",400,540);
new delay(); new delay();
new delay(); new delay();
new delay();
g.drawString("Shortest Path : c-->c3-->c4",400,580); }
if(tree.equals("yes")) {
if(mobile[1].equals("yes")) {
g.drawLine(520,250,460,330);
new delay(); g.drawLine(460,330,480,420);
new delay();
g.drawLine(480,420,550,420); }
11
if(mobile[3].equals("yes"))
{
g.drawLine(520,250,580,330);
new delay();
g.drawLine(580,330,550,420);
}
}
String mss1=" Multicast Routing in MANET"; setForeground(Color.white);
g.setFont(f);
g.drawString(mss1,20,40);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==but1)
{
try
{ ss=new ServerSocket(4545);
System.out.println("Terminal is listening.....");
int i=0; while(i<5)
{
new Connect(ss,i); i++;
}
System.out.println("Clients are connected...."); }
catch(Exception er)
{ System.out.println("error at :"+er);
}
}
if(e.getSource()==but2)
{ tree="yes";
repaint();
} }
public Terminal() {
try
{ int i=0;
while(i<5) {
mobile[i]="No";
i++; }
}
catch(Exception ee) {
System.out.println("error in:"+ee);
} }
public Terminal(String me){} }
class delay extends Thread {
delay()
12
{
try
{
Thread.sleep(500);
}
catch(Exception ee){} }
}
class Connect
{
@SuppressWarnings("unused") private ServerSocket ss;
@SuppressWarnings("unused")
private int i; Terminal m1=new Terminal("initial");
Connect(ServerSocket ss,int i) {
try
{
this.ss=ss;
this.i=i;
Socket soc=ss.accept(); Terminal.mobile[i]="yes";
Terminal.cs[i]=soc;
if(i==1 || i==3)
{
new GetMessage(soc,i).start(); }
m1.repaint();
} catch(Exception ex)
{
System.out.println("Error in formingStream:"+ex); }
}
}
class GetMessage extends Thread
{ @SuppressWarnings("unused")
private Socket soc;
private BufferedReader in; private int i;
Terminal m1=new Terminal("initial");
GetMessage(Socket soc,int i)
{
try {
this.soc=soc; this.i=i;
in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
} catch(Exception ex)
{
System.out.println("Error in formingStream:"+ex); }
}
public void run()
{
while(true) {
try
{ String message=in.readLine();
if(message.equals("yes"))
13
Terminal.mobile[i]="yes";
else
Terminal.mobile[i]="no";
}
catch(Exception re){}
} }
}
package networks;
import java.awt.*;
@SuppressWarnings("serial") public class ShortPath extends java.applet.Applet {
GraphCanvas graphcanvas = new GraphCanvas(this);
Options1 options1 = new Options1(this); Options2 options2 = new Options2(this);
Documentation documentation = new Documentation();
public void init() {
setLayout(new BorderLayout());
add("North",options1); add("Center", graphcanvas);
add("South", options2);
}
public void lock() {
graphcanvas.lock(); options1.lock();
}
public void unlock(){
graphcanvas.unlock();
options1.unlock(); }
}
@SuppressWarnings("serial")
class Options1 extends Panel {// set of options at the right of the screen
Button b2 = new Button("Run"); Button b3 = new Button("Step");
Button b4 = new Button("Reset");
ShortPath parent; boolean Locked=false;
Options1(ShortPath myparent) { parent = myparent;
setLayout(new GridLayout(1, 3));
add(b2); add(b3);
add(b4); }
public boolean action(Event evt, Object arg) {
if (evt.target instanceof Button){
if (((String)arg).equals("Step")) { if (!Locked){
b3.setLabel("Next Step");
parent.graphcanvas.stepalg(); }
}
if (((String)arg).equals("Next Step")) parent.graphcanvas.nextstep();
if (((String)arg).equals("Reset")){ parent.graphcanvas.reset();
b3.setLabel("Step");
14
}
if (((String)arg).equals("Refresh")){
parent.graphcanvas.clear();
b3.setLabel("Step");
}
if (((String)arg).equals("Run")){
if (!Locked) parent.graphcanvas.runalg();
}
} return true;
}
public void lock(){
Locked=true;
}
public void unlock(){
Locked=false;
b3.setLabel("Step");
}
}
@SuppressWarnings("serial")
class Options2 extends Panel {// set of options at the bottom of the screen Button b11 = new Button("Tree 1");
Button b12 = new Button("Tree 2");
Button b13 = new Button("Tree 3"); Button b14 = new Button("Tree 4");
Button b15 = new Button("Tree 5");
ShortPath parent; Options2(ShortPath myparent) {
parent = myparent;
setLayout(new GridLayout(1, 5)); add(b11);
add(b12);
add(b13);
add(b14);
add(b15);
}
public boolean action(Event evt, Object arg) {
if (evt.target instanceof Button){
if (((String)arg).equals("Tree 1")){
parent.graphcanvas.clear(); parent.options1.b3.setLabel("Step");
if (!parent.options1.Locked) parent.graphcanvas.showexample1();
}
if (((String)arg).equals("Tree 2")){
parent.graphcanvas.clear(); parent.options1.b3.setLabel("Step");
if (!parent.options1.Locked)
parent.graphcanvas.showexample2();
}
if (((String)arg).equals("Tree 3")){
parent.graphcanvas.clear();
parent.options1.b3.setLabel("Step"); if (!parent.options1.Locked)
parent.graphcanvas.showexample3();
}
if (((String)arg).equals("Tree 4")){
15
parent.graphcanvas.clear();
parent.options1.b3.setLabel("Step");
if (!parent.options1.Locked)
parent.graphcanvas.showexample4();
}
if (((String)arg).equals("Tree 5")){
parent.graphcanvas.clear();
parent.options1.b3.setLabel("Step"); if (!parent.options1.Locked)
parent.graphcanvas.showexample5();
} }
return true;
} }
@SuppressWarnings("serial") class Documentation extends Panel{
// Documentation on top of the screen
DocOptions docopt = new DocOptions(this);
DocText doctext = new DocText();
Documentation() {}
}
@SuppressWarnings("serial")
class DocOptions extends Panel{ Choice doc = new Choice();
Documentation parent;
DocOptions(Documentation myparent){} public boolean action(Event evt, Object arg){
return true;
} }
@SuppressWarnings("serial") class DocText extends TextArea {
public void showline(String str){
}
}
@SuppressWarnings("serial") class GraphCanvas extends Canvas implements Runnable {// drawing area for the graph
final int MAXNODES = 20;
final int MAX = MAXNODES+1; final int NODESIZE = 26;
final int NODERADIX = 13;
final int DIJKSTRA = 1; // basic graph information
Point node[] = new Point[MAX];
// node int weight[][] = new int[MAX][MAX]; // weight of arrow
int myWeight[][] = new int[MAX][MAX]; // weight of arrow Point arrow[][] = new Point[MAX][MAX]; // current position of arrowhead
Point startp[][] = new Point[MAX][MAX]; // start and
Point endp[][] = new Point[MAX][MAX]; // endpoint of arrow float dir_x[][] = new float[MAX][MAX]; // direction of arrow
float dir_y[][] = new float[MAX][MAX]; // direction of arrow
// graph information while running algorithm boolean algedge[][] = new boolean[MAX][MAX];
int dist[] = new int[MAX];
int finaldist[] = new int[MAX]; Color colornode[] = new Color[MAX];
Color BKCOLOR=new Color(132,0,0);
Color STCOLOR=new Color(54,73,61); boolean changed[] = new boolean[MAX]; // indicates distance change during algorithm
int numchanged =0;
int neighbours=0; int step=0;
// information used by the algorithm to find the next
16
// node with minimum distance
int mindist, minnode, minstart, minend;
int numnodes=0; // number of nodes
int emptyspots=0; // empty spots in array node[] (due to node deletion)
int startgraph=0; // start of graph
int hitnode; // mouse clicked on or close to this node int node1, node2; // numbers of nodes involved in current action
Point thispoint=new Point(0,0); // current mouseposition
Point oldpoint=new Point(0, 0); // previous position of node being moved // current action boolean newarrow = false;
boolean movearrow = false;
boolean movestart = false; boolean deletenode = false;
boolean movenode = false;
boolean performalg = false; boolean clicked = false; // fonts
Font roman= new Font("TimesRoman", Font.BOLD, 12);
Font helvetica= new Font("Helvetica", Font.BOLD, 15); FontMetrics fmetrics = getFontMetrics(roman);
int h = (int)fmetrics.getHeight()/3;
// for double buffering
private Image offScreenImage;
private Graphics offScreenGraphics;
private Dimension offScreenSize; // for run option Thread algrthm;
// current algorithm, (in case more algorithms are added)
int algorithm; // algorithm information to be displayed in documetation panel String showstring = new String("");
boolean stepthrough=false; // locking the screen while running the algorithm
boolean Locked = false; ShortPath parent;
GraphCanvas(ShortPath myparent) { parent = myparent;
init();
algorithm=DIJKSTRA; setBackground(BKCOLOR);
}
public void lock(){ // lock screen while running an algorithm
Locked=true;
}
public void unlock(){
Locked=false; }
@SuppressWarnings("deprecation") public void start(){
if (algrthm != null)
algrthm.resume(); }
public void init(){
for (int i=0;i<MAXNODES;i++) {
colornode[i]=Color.gray; for (int j=0; j<MAXNODES;j++)
algedge[i][j]=false;
}
colornode[startgraph]=Color.red;
performalg = false; }
@SuppressWarnings("deprecation") public void clear(){ // removes graph from screen
startgraph=0;
numnodes=0; emptyspots=0;
init();
17
for(int i=0; i<MAXNODES; i++){
node[i]=new Point(0, 0);
finaldist[i]=-1;
for (int j=0; j<MAXNODES;j++){
weight[i][j]=0;
myWeight[i][j]=-1; }
}
if (algrthm != null) algrthm.stop();
parent.unlock();
repaint(); }
@SuppressWarnings("deprecation") public void reset() { // resets a graph after running an algorithm
init();
if (algrthm != null) algrthm.stop();
parent.unlock();
repaint();
}
public void runalg() { // gives an animation of the algorithm parent.lock();
initalg();
performalg = true; algrthm = new Thread(this);
algrthm.start();
}
public void stepalg(){ // lets you step through the algorithm
parent.lock(); initalg();
performalg = true;
nextstep(); }
public void initalg() {
init();
for(int i=0; i<MAXNODES; i++) {
dist[i]=-1; finaldist[i]=-1;
for (int j=0; j<MAXNODES;j++)
algedge[i][j]=false; }
dist[startgraph]=0; finaldist[startgraph]=0;
step=0; }
public void nextstep() { // calculates a step in the algorithm (finds a shortest // path to a next node).
finaldist[minend]=mindist; algedge[minstart][minend]=true;
colornode[minend]=Color.black; // build more information to display on documentation panel
step++; repaint();
}
@SuppressWarnings("deprecation")
public void stop(){
if (algrthm != null) algrthm.suspend();
}
@SuppressWarnings("static-access")
public void run(){
for(int i=0; i<(numnodes-emptyspots); i++){ nextstep();
try {
18
algrthm.sleep(2000);
}
catch (InterruptedException e){
e.printStackTrace();
}
} algrthm = null;
}
@SuppressWarnings("deprecation")
public void showexample3(){ // draws a graph on the screen
int w, h; clear();
init();
numnodes=5; emptyspots=0;
for(int i=0; i<MAXNODES; i++){
node[i]=new Point(0, 0); for (int j=0; j<MAXNODES;j++)
weight[i][j]=0;
}
w=this.size().width/12;
h=this.size().height/12; node[0]=new Point(6*w, h);
node[1]=new Point(10*w, h);
node[2]=new Point(2*w, 5*h); node[3]=new Point(6*w, 10*h);
node[4]=new Point(10*w, 10*h);
weight[0][1]=1; weight[0][2]=7;
weight[2][3]=1;
weight[1][4]=2; weight[3][0]=8;
weight[3][4]=2;
for (int i=0;i<numnodes;i++)
for (int j=0;j<numnodes;j++)
if (weight[i][j]>0)
arrowupdate(i, j, weight[i][j]);
repaint();
}
@SuppressWarnings("deprecation") public void showexample4(){ // draws a graph on the screen
int w, h;
clear(); init();
numnodes=8;
emptyspots=0; for(int i=0; i<MAXNODES; i++){
node[i]=new Point(0, 0); for (int j=0; j<MAXNODES;j++)
weight[i][j]=0;
}
w=this.size().width/14;
h=this.size().height/16; node[6]=new Point(4*w, 4*h);
node[1]=new Point(8*w, 4*h);
node[5]=new Point(2*w, 8*h); node[3]=new Point(6*w, 8*h);
node[4]=new Point(2*w, 15*h);
node[2]=new Point(6*w, 15*h); node[0]=new Point(10*w, 15*h);
node[7]=new Point(6*w,2*h);
weight[0][1]=1; weight[1][0]=1;
weight[0][2]=4; weight[2][0]=4;
19
weight[1][2]=2; weight[2][1]=2;
weight[1][3]=9; weight[3][1]=9;
weight[3][6]=1; weight[6][3]=1;
weight[1][6]=4; weight[6][1]=4;
weight[2][3]=1; weight[3][2]=1;
weight[2][4]=3; weight[4][2]=3; weight[4][3]=1; weight[3][4]=1;
weight[4][5]=1; weight[5][4]=1;
weight[5][3]=3; weight[3][5]=3; weight[5][6]=6; weight[6][5]=6;
weight[1][7]=2; weight[7][1]=2;
weight[7][6]=14;weight[6][7]=14;
for (int i=0;i<numnodes;i++)
for (int j=0;j<numnodes;j++) if (weight[i][j]>0)
arrowupdate(i, j, weight[i][j]);
repaint(); }
@SuppressWarnings("deprecation")
public void showexample5(){ // draws a graph on the screen
int w, h;
clear(); init();
numnodes=12;
emptyspots=0; for(int i=0; i<MAXNODES; i++){
node[i]=new Point(0, 0);
for (int j=0; j<MAXNODES;j++) weight[i][j]=0;
}
w=this.size().width/8; h=this.size().height/8;
node[0]=new Point(w, h);
node[1]=new Point(3*w, h); node[2]=new Point(5*w, h);
node[3]=new Point(w, 4*h);
node[4]=new Point(3*w, 4*h);
node[5]=new Point(5*w, 4*h);
node[6]=new Point(w, 7*h);
node[7]=new Point(3*w, 7*h); node[8]=new Point(5*w, 7*h);
node[9]=new Point(7*w, 4*h);
node[10]=new Point(7*w,h); node[11]=new Point(7*w,7*h);
weight[0][1]=4; weight[0][3]=1;
weight[1][0]=74;
weight[1][2]=2; weight[1][4]=12;
weight[2][5]=74; weight[2][1]=12;
weight[2][9]=12;
weight[3][4]=32; weight[3][6]=22;
weight[4][3]=66;
weight[4][5]=76; weight[4][7]=33;
weight[5][8]=11;
weight[5][9]=21; weight[6][7]=10;
weight[6][3]=12;
weight[7][6]=2; weight[7][8]=72;
weight[8][5]=31;
weight[8][9]=7; weight[8][7]=18;
weight[9][5]=8;
20
weight[10][2]=10;
weight[10][9]=15;
weight[10][5]=12;
weight[5][11]= 30;
weight[11][8]=45;
weight[11][9]=25; for (int i=0;i<numnodes;i++)
for (int j=0;j<numnodes;j++)
if (weight[i][j]>0) arrowupdate(i, j, weight[i][j]);
repaint();
}
@SuppressWarnings("deprecation") public void showexample1(){ // draws a graph on the screen
int w, h;
clear(); init();
numnodes=3;
emptyspots=0;
for(int i=0; i<MAXNODES; i++){
node[i]=new Point(0, 0);
for (int j=0; j<MAXNODES;j++) weight[i][j]=0;
}
w=this.size().width/5;
h=this.size().height/5;
node[0]=new Point(2*w, h); node[1]=new Point(w, 3*h);
node[2]=new Point(4*w, 4*h);
weight[0][1]=15; weight[1][0]=15;
weight[0][2]=70;
weight[2][0]=20; weight[2][1]=12;
weight[1][2]=12;
for (int i=0;i<numnodes;i++)
for (int j=0;j<numnodes;j++)
if (weight[i][j]>0) arrowupdate(i, j, weight[i][j]);
repaint();
}
@SuppressWarnings("deprecation")
public void showexample2(){ // draws a graph on the screen int w, h;
clear();
init(); numnodes=4;
emptyspots=0; for(int i=0; i<MAXNODES; i++){
node[i]=new Point(0, 0);
for (int j=0; j<MAXNODES;j++) weight[i][j]=0;
}
w=this.size().width/8;
h=this.size().height/8;
node[0]=new Point(4*w, h); node[1]=new Point(w, 6*h);
node[2]=new Point(6*w, 6*h);
node[3]=new Point(4*w, 4*h); weight[0][1]=1;
weight[1][0]=1;
weight[0][2]=7; weight[2][0]=7;
weight[3][2]=2;
21
weight[2][3]=2;
weight[3][1]=8;
weight[1][3]=8;
weight[0][3]=2;
weight[3][0]=2;
weight[2][1]=20; weight[1][2]=20;
for (int i=0;i<numnodes;i++)
for (int j=0;j<numnodes;j++) if (weight[i][j]>0)
arrowupdate(i, j, weight[i][j]);
repaint(); }
public boolean mouseDown(Event evt, int x, int y) {
if (!Locked){
clicked = true; // Change Start node
if (nodehit(x, y, NODESIZE)) {
node1 = hitnode;
if (startgraph==node1) {
movestart=true;
thispoint = new Point(x,y); colornode[startgraph]=Color.gray;
}
} }
else
repaint(); return true;
}
public boolean mouseDrag(Event evt, int x, int y) {
if ( (!Locked) && clicked ) {
if (movenode) { // move node and adjust arrows coming into/outof the node node[node1]=new Point(x, y);
for (int i=0;i<numnodes;i++) {
if (weight[i][node1]>0) {
arrowupdate(i, node1, weight[i][node1]);
}
if (weight[node1][i]>0) { arrowupdate(node1, i, weight[node1][i]);
}
} repaint();
}
else if (movestart || newarrow) { thispoint = new Point(x, y);
repaint();
} }
return true; }
@SuppressWarnings("deprecation") public boolean mouseUp(Event evt, int x, int y) {
if ( (!Locked) && clicked ) {
if (movenode) { // move the node if the new position is not to close to // another node or outside of the panel
node[node1]=new Point(0, 0);
if ( nodehit(x, y, 50) || (x<0) || (x>this.size().width) || (y<0) || (y>this.size().height) ) { node[node1]=oldpoint;
}
else node[node1]=new Point(x, y);
for (int i=0;i<numnodes;i++) {
if (weight[i][node1]>0) arrowupdate(i, node1, weight[i][node1]);
if (weight[node1][i]>0)
22
arrowupdate(node1, i, weight[node1][i]);
}
movenode=false;
}
else if (deletenode) {
nodedelete();
deletenode=false; }
else if (newarrow) { newarrow = false;
if (nodehit(x, y, NODESIZE)) {
node2=hitnode; if (node1!=node2) {
arrowupdate(node1, node2, 50);
if (weight[node2][node1]>0) { arrowupdate(node2, node1, weight[node2][node1]);
}
}
}
}
else if (movearrow) { movearrow = false;
}
else if (movestart) {
if (nodehit(x, y, NODESIZE))
startgraph=hitnode; colornode[startgraph]=Color.red;
movestart=false;
} repaint();
}
return true; }
public boolean nodehit(int x, int y, int dist) {
// checks if you hit a node with your mouseclick
for (int i=0; i<numnodes; i++)
if ( (x-node[i].x)*(x-node[i].x) + (y-node[i].y)*(y-node[i].y) < dist*dist ) { hitnode = i;
return true;
} return false;
}
public boolean arrowhit(int x, int y, int dist) {
// checks if you hit an arrow with your mouseclick
for (int i=0; i<numnodes; i++) for (int j=0; j<numnodes; j++) {
if ( ( weight[i][j]>0 ) && (Math.pow(x-arrow[i][j].x, 2) + Math.pow(y-arrow[i][j].y, 2) < Math.pow(dist, 2) ) ) {
node1 = i;
node2 = j; return true;
}
} return false;
}
public void nodedelete() {
// delete a node and the arrows coming into/outof the node
node[node1]=new Point(-100, -100); for (int j=0;j<numnodes;j++) {
weight[node1][j]=0;
weight[j][node1]=0; }
23
emptyspots++;
}
public void arrowupdate(int p1, int p2, int w) {
// make a new arrow from node p1 to p2 with weight w, or change
// the weight of the existing arrow to w, calculate the resulting // position of the arrowhead
int dx, dy;
float l; weight[p1][p2]=w; // direction line between p1 and p2
dx = node[p2].x-node[p1].x;
dy = node[p2].y-node[p1].y; // distance between p1 and p2 l = (float)( Math.sqrt((float)(dx*dx + dy*dy)));
dir_x[p1][p2]=dx/l;
dir_y[p1][p2]=dy/l; // calculate the start and endpoints of the arrow,
// adjust startpoints if there also is an arrow from p2 to p1
if (weight[p2][p1]>0){ startp[p1][p2] = new Point((int)(node[p1].x-5*dir_y[p1][p2]),(int)(node[p1].y+5*dir_x[p1][p2]));
endp[p1][p2] = new Point((int)(node[p2].x-5*dir_y[p1][p2]),(int)(node[p2].y+5*dir_x[p1][p2]));
}
else{
startp[p1][p2] = new Point(node[p1].x, node[p1].y);
endp[p1][p2] = new Point(node[p2].x, node[p2].y); }
// range for arrowhead is not all the way to the start/endpoints
int diff_x = (int)(Math.abs(20*dir_x[p1][p2])); int diff_y = (int)(Math.abs(20*dir_y[p1][p2]));
// calculate new x-position arrowhead
if (startp[p1][p2].x>endp[p1][p2].x) { arrow[p1][p2] = new Point(endp[p1][p2].x + diff_x + (Math.abs(endp[p1][p2].x-startp[p1][p2].x) - 2*diff_x )*(100-
w)/100 , 0);
} else{
arrow[p1][p2] = new Point(startp[p1][p2].x + diff_x + (Math.abs(endp[p1][p2].x-startp[p1][p2].x) - 2*diff_x )*w/100, 0);
} // calculate new y-position arrowhead if (startp[p1][p2].y>endp[p1][p2].y) {
arrow[p1][p2].y=endp[p1][p2].y + diff_y + (Math.abs(endp[p1][p2].y-startp[p1][p2].y) - 2*diff_y )*(100-w)/100;
}
else{
arrow[p1][p2].y=startp[p1][p2].y + diff_y + (Math.abs(endp[p1][p2].y-startp[p1][p2].y) - 2*diff_y )*w/100;
} }
public String intToString(int i){ char c=(char)((int)'a'+i);
return ""+c;
}
@SuppressWarnings("deprecation")
public final synchronized void update(Graphics g) { // prepare new image offscreen Dimension d=size();
if ((offScreenImage == null) || (d.width != offScreenSize.width) || (d.height != offScreenSize.height)) { offScreenImage = createImage(d.width, d.height);
offScreenSize = d;
offScreenGraphics = offScreenImage.getGraphics(); }
offScreenGraphics.setColor(BKCOLOR);
offScreenGraphics.fillRect(0, 0, d.width, d.height); paint(offScreenGraphics);
g.drawImage(offScreenImage, 0, 0, null);
}
public void drawarrow(Graphics g, int i, int j) {// draw arrow between node i and node j
int x1, x2, x3, y1, y2, y3; // calculate arrowhead x1= (int)(arrow[i][j].x - 3*dir_x[i][j] + 6*dir_y[i][j]);
x2= (int)(arrow[i][j].x - 3*dir_x[i][j] - 6*dir_y[i][j]);
x3= (int)(arrow[i][j].x + 6*dir_x[i][j]); y1= (int)(arrow[i][j].y - 3*dir_y[i][j] - 6*dir_x[i][j]);
y2= (int)(arrow[i][j].y - 3*dir_y[i][j] + 6*dir_x[i][j]);
24
y3= (int)(arrow[i][j].y + 6*dir_y[i][j]);
int arrowhead_x[] = { x1, x2, x3, x1 };
int arrowhead_y[] = { y1, y2, y3, y1 };
// if edge already chosen by algorithm change color
if (algedge[i][j]){
g.setColor(Color.green); myWeight[i][j]=weight[i][j];
}
// draw arrow g.drawLine(startp[i][j].x, startp[i][j].y, endp[i][j].x, endp[i][j].y);
g.fillPolygon(arrowhead_x, arrowhead_y, 4);
// write weight of arrow at an appropriate position int dx = (int)(Math.abs(7*dir_y[i][j]));
int dy = (int)(Math.abs(7*dir_x[i][j]));
String str = new String("" + weight[i][j]); g.setColor(Color.white);
if ((startp[i][j].x>endp[i][j].x) && (startp[i][j].y>=endp[i][j].y))
g.drawString( str, arrow[i][j].x + dx, arrow[i][j].y - dy); if ((startp[i][j].x>=endp[i][j].x) && (startp[i][j].y<endp[i][j].y))
g.drawString( str, arrow[i][j].x - fmetrics.stringWidth(str) - dx , arrow[i][j].y - dy);
if ((startp[i][j].x<endp[i][j].x) && (startp[i][j].y<=endp[i][j].y))
g.drawString( str, arrow[i][j].x - fmetrics.stringWidth(str) , arrow[i][j].y + fmetrics.getHeight());
if ((startp[i][j].x<=endp[i][j].x) && (startp[i][j].y>endp[i][j].y))
g.drawString( str, arrow[i][j].x + dx, arrow[i][j].y + fmetrics.getHeight() ); }
public void detailsDijkstra(Graphics g, int i, int j) { // check arrow between node i and node j is amongst the arrows to
// choose from during this step of the algorithm
// check if node j has the next minimal distance to the startnode if ((finaldist[i]!=-1) && (finaldist[j]==-1)){
g.setColor(Color.cyan);
if ((dist[j]==-1) || (dist[j]>=(dist[i]+weight[i][j]))){ if ( (dist[i]+weight[i][j])<dist[j] ) {
changed[j]=true;
numchanged++; }
dist[j] = dist[i]+weight[i][j];
colornode[j]=Color.cyan;
if ( (mindist==0) || (dist[j]<mindist) ) {
mindist=dist[j];
g.drawString(" ",200,200); g.drawString(""+dist[j],200,200);
minstart=i;
minend=j; }
}
} else
g.setColor(Color.gray);
}
public void endstepDijkstra(Graphics g) { // displays current and final distances of nodes, sets the final distance // for the node that had minimal distance in this step // explains
algorithm on documentation panel
for (int i=0; i<numnodes; i++) if ( (node[i].x>0) && (dist[i]!=-1) ){
String str = new String(""+dist[i]);
g.drawString(str, node[i].x - (int)fmetrics.stringWidth(str)/2 -1,node[i].y + h); // string to distance to nodes on the documentation panel
if (finaldist[i]==-1)
{ neighbours++;
if (neighbours!=1)
showstring = showstring + ", "; showstring = showstring + intToString(i) +"=" + dist[i];
}
} showstring = showstring + ". ";
if ( (step>1) && (numchanged>0) ) {
25
if (numchanged>1)
showstring = showstring + "Notice that the distances to ";
else
showstring = showstring + "Notice that the distance to ";
for (int i=0; i<numnodes; i++)
if ( changed[i] ) showstring = showstring + intToString(i) +", ";
if (numchanged>1)
showstring = showstring + "have changed!\n"; else
showstring = showstring + "has changed!\n";
} else
showstring = showstring + " ";
if (neighbours>1) { // if there where more canditates explain why this node is taken showstring = showstring + "Node " + intToString(minend) + " has the minimum distance.\n";
//check if there are other paths to minend.
int newpaths=0; for (int i=0; i<numnodes; i++)
if ( (node[i].x>0) && (weight[i][minend]>0) && ( finaldist[i] == -1 ) )
newpaths++;
if (newpaths>0)
showstring = showstring + "Any other path to " + intToString(minend) + " visits another red node, and will be longer than
" + mindist + ".\n"; else
showstring = showstring + "There are no other arrows coming in to "+ intToString(minend) + ".\n";
} else {
boolean morenodes=false;
for (int i=0; i<numnodes; i++) if ( ( node[i].x>0 ) && ( finaldist[i] == -1 ) && ( weight[i][minend]>0 ) )
morenodes=true;
boolean bridge=false; for (int i=0; i<numnodes; i++)
if ( ( node[i].x>0 ) && ( finaldist[i] == -1 ) && ( weight[minend][i]>0 ) )
bridge=true; if ( morenodes && bridge )
showstring = showstring + "Since this node forms a 'bridge' to "+ "the remaining nodes,\nall other paths to this
node will be longer.\n";
else
if ( morenodes && (!bridge) )
showstring = showstring + "Remaining gray nodes are not reachable.\n"; else
showstring = showstring + "There are no other arrows coming in to "+ intToString(minend) + ".\n";
} showstring = showstring + "Node " + intToString(minend) + " will be colored green to indicate " + mindist + " is the
length of the shortest path to " + intToString(minend) +".";
}
public void detailsalg(Graphics g, int i, int j) {// more algorithms can be added later
if (algorithm==DIJKSTRA) detailsDijkstra(g, i, j);
} @SuppressWarnings({ "deprecation", "unused" })
public void endstepalg(Graphics g){ // more algorithms can be added later
if (algorithm==DIJKSTRA) endstepDijkstra(g);
if ( ( performalg ) && (mindist==0) ){
if (algrthm != null) algrthm.stop();
int nreachable = 0;
for (int i=0; i<numnodes; i++) if (finaldist[i] > 0)
nreachable++;
} }
@SuppressWarnings("deprecation") public void paint(Graphics g){
mindist=0; minnode=MAXNODES;
26
minstart=MAXNODES; minend=MAXNODES;
for(int i=0; i<MAXNODES; i++)
changed[i]=false;
numchanged=0;
neighbours=0;
g.setFont(roman); g.setColor(Color.white);
if (step==1)
showstring="Algorithm running: red arrows point to nodes reachable from " + " the startnode.\nThe distance to: "; else showstring="Step " + step + ": Red arrows point to nodes reachable from " + "nodes that already have a final distance." + "\nThe distance to: ";
// draw a new arrow upto current mouse position
if (newarrow) g.drawLine(node[node1].x, node[node1].y, thispoint.x, thispoint.y);
// draw all arrows
for (int i=0; i<numnodes; i++) for (int j=0; j<numnodes; j++)
if (weight [i][j]>0) {
// if algorithm is running then perform next step for this arrow if (performalg)
detailsalg(g, i, j);
drawarrow(g, i, j);
}
// if arrowhead has been dragged to 0, draw it anyway, so the user // will have the option to make it positive again
if (movearrow && weight[node1][node2]==0) { drawarrow(g, node1, node2);
g.drawLine(startp[node1][node2].x, startp[node1][node2].y,endp[node1][node2].x, endp[node1][node2].y);
} // draw the nodes
for (int i=0; i<numnodes; i++)
if (node[i].x>0){ g.setColor(colornode[i]);
g.fillOval(node[i].x-NODERADIX, node[i].y-NODERADIX, NODESIZE, NODESIZE);
} // reflect the startnode being moved g.setColor(Color.red);
if (movestart)
g.fillOval(thispoint.x-NODERADIX, thispoint.y-NODERADIX,NODESIZE, NODESIZE); g.setColor(Color.white); // finish this step of the algorithm
if (performalg) endstepalg(g); // draw black circles around nodes, write their names to the screen
g.setFont(helvetica);
for (int i=0; i<numnodes; i++)
if (node[i].x>0) {
g.setColor(Color.white); g.drawOval(node[i].x-NODERADIX, node[i].y-NODERADIX,NODESIZE, NODESIZE);
g.setColor(Color.red);
g.drawString(intToString(i), node[i].x-14, node[i].y-14); }
if(Locked){
char startChar='a'; g.setColor(Color.white);
for(int i=0;i<numnodes;i++){ g.drawString(""+((char) ('a'+i)),10,20+30*i);
if(finaldist[i]==-1){ g.drawString("-",60,20+30*i);
}
else{ g.drawString(""+ finaldist[i],60,20+30*i);
if(finaldist[i]==0){
startChar=(char) ('a'+i); }
}
}
int k=0,ypos;
String[] path=new String[100]; int[] pathWeight=new int[100];
for(int i=0;i<numnodes;i++){ for(int j=0;j<numnodes;j++){
if(myWeight[i][j]!=-1){
27
path[k]=""+((char) ('a'+i))+((char) ('a'+j));
pathWeight[k]=myWeight[i][j];
k++;
}
} }
for(int l=0;l<k-1;l++){ for(int m=1;m<k;m++){
if(path[l].charAt(path[l].length()-1)==path[m].charAt(0)){//can be joined
path[k]=path[l]+"-"+path[m]; pathWeight[k]=pathWeight[l]+pathWeight[m];
k++;
} }
}
//startChar='f';
ypos=20;
for(int kk=0;kk<k;kk++){
if(path[kk].charAt(0)==startChar){
boolean duplicate=false;
for(int n=0;n<kk;n++){ if(path[kk].equals(path[n])){
duplicate=true;
} }
if(!duplicate){
g.drawString(" ",size().width-200,ypos); g.drawString(path[kk],size().width-200,ypos);
g.drawString(""+pathWeight[kk],size().width-20,ypos);
ypos+=20; }
}
} if(startChar=='f' && numnodes==8){
g.drawString(" ",size().width-200,ypos);
g.drawString("fb-bg",size().width-200,ypos);
g.drawString("3",size().width-20,ypos);
}
} }
}
package networks;
public class Send {
}
package networks;
public class Receive {
}
package networks;
import java.io.*; import java.net.*;
import java.util.*;
class client{
public static Socket ms,soc; public static ServerSocket ss,ss2;
public static Socket cs[]=new Socket[2];
public static String mobile[]=new String[2];
public static boolean flag[]={true,true};
28
@SuppressWarnings("rawtypes")
public static Hashtable has;
public static SendReceive sendrec;
public static Connect0 con;
int length=0;
int size=0; byte message[];
Random r;
public client() throws IOException{
try {
connect();
}catch(Exception e) {System.out.println("Exception in client:"+e);}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void connect() {
has = new Hashtable();
try {
ms=new Socket(InetAddress.getLocalHost(),4545); System.out.println("Client IS CONNECTED TO Terminal:");
ss=new ServerSocket(4000);
System.out.println("client is listening....."); int i=0;
while(i<2){
cs[i]=ss.accept(); mobile[i]="yes";
con = new Connect0(i);
con.start(); i++;
}
ss2=new ServerSocket(3535);
//soc=ss2.accept();
int j=1;
while(true){
/////////////// soc=ss2.accept();
System.out.println("Connected with Sender");
has.put("Sender"+j,soc); sendrec = new SendReceive(has,j);
sendrec.start();
j++;
////////////
} }catch(Exception er){System.out.println("error at :"+er);}
}
public static void main(String ar[])throws IOException{
new client();
}
class SendReceive extends Thread {
@SuppressWarnings("rawtypes") Hashtable has;
int i;
SendReceive(@SuppressWarnings("rawtypes") Hashtable has, int i) {
this.has = has; this.i = i;
29
}
public void run() {
sendMessage();
}
public void sendMessage(){
PrintWriter out;
DataInputStream in;
r = new Random();
try{
in=new DataInputStream(((Socket)has.get("Sender"+i)).getInputStream()); @SuppressWarnings("deprecation")
String mess=in.readLine();
for(int i=1;i>-1;i--){
if(mobile[i].equals("yes")){
if(flag[i]){
out=new PrintWriter(cs[i].getOutputStream(),true); out.println(mess);
System.out.println("Message Recieved :"+mess);
break;
}
} }
if(!flag[0] && !flag[1]){
System.out.println("Both the nearer mobiles are out of Range !!!"); }
}catch(Exception er){System.out.println("Exception in connetion with Mobile:"+er);}
} }
}
class Connect0 extends Thread {
private BufferedReader in; private int i;
Connect0(int i){
try{
this.i=i;
}catch(Exception ex){System.out.println("Error in formingStream:"+ex);}
}
public void run(){
try{
while(true){ in = new BufferedReader(new InputStreamReader(client.cs[i].getInputStream()));
if(in.readLine().equalsIgnoreCase("yes")){
client.mobile[i]="yes"; client.flag[i]=true;
} else{
client.mobile[i]="No";
client.flag[i]=false; }
}
}catch(Exception er){System.out.println("Exception in connection with clients:"+er);} }
}
30
package networks;
import java.io.*;
import java.net.*;
import java.lang.*;
@SuppressWarnings("unused")
class client1{
public static ServerSocket ss; public static Socket cs[]=new Socket[3];
public static Socket soc;
public static void main(String ar[]){
try{ cs[0]=new Socket(InetAddress.getLocalHost(),4545);
System.out.println("Client1 IS CONNECTED TO Terminal:");
cs[1]=new Socket(InetAddress.getLocalHost(),4000); System.out.println("client1 is connected to client.\n");
ss=new ServerSocket(4001);
cs[2]=ss.accept();
new SendSignal1().start(); new ByPass1().start();
}catch(Exception er) {System.out.println("error at :"+er);} }
}
class SendSignal1 extends Thread {
private BufferedReader in;
private PrintWriter out;
SendSignal1(){}
public void run(){
try{
while(true) {
System.out.println("Type in/out for mobile to be within range or out of range");
in=new BufferedReader(new InputStreamReader(System.in));
String mess=in.readLine(); if(mess.equalsIgnoreCase("in"))
mess="yes";
else mess="no";
for(int i=0;i<3;i++) {
out=new PrintWriter(client1.cs[i].getOutputStream(),true);
out.println(mess);
}
}
} catch(Exception er){}
} }
class ByPass1 extends Thread {
private BufferedReader in;
private PrintWriter out; Send send;
Receive receive;
ByPass1(){}
public void run(){
try { while(true){
in=new BufferedReader(new InputStreamReader(client1.cs[1].getInputStream()));
31
String mess=in.readLine();
out=new PrintWriter(client1.cs[2].getOutputStream(),true);
out.println(mess);
System.out.println("Message Recieved :"+mess);
} } catch(Exception e1){}
}
}
package networks;
import java.io.*; import java.net.*;
import java.lang.*;
@SuppressWarnings("unused")
class client2
{ public static ServerSocket ss;
public static Socket cs[]=new Socket[3];
public static Socket soc;
public static boolean flag=true;
Send send;
Receive receive;
public static void main(String ar[])
{ try
{
cs[0]=new Socket(InetAddress.getLocalHost(),4545); System.out.println("Client2 IS CONNECTED TO Terminal:");
cs[1]=new Socket(InetAddress.getLocalHost(),4001);
System.out.println("client2 is connected to client1.");
ss=new ServerSocket(4002);
cs[2]=ss.accept();
new ByPass2();
}
catch(Exception er)
{
System.out.println("error at :"+er); }
}
}
class ByPass2
{ private BufferedReader in;
private PrintWriter out;
Send send; Receive receive;
ByPass2()
{
try {
while(true)
{ in=new BufferedReader(new InputStreamReader(client2.cs[1].getInputStream()));
String mess=in.readLine();
if(mess.equalsIgnoreCase("yes"))
client2.flag=true; else if(mess.equalsIgnoreCase("no"))
client2.flag=false;
else {
out=new PrintWriter(client2.cs[2].getOutputStream(),true);
32
out.println(mess);
System.out.println("Message Recieved is:"+mess);
}
}
} catch(Exception e1){}
}
}
package networks;
import java.io.*; import java.net.*;
import java.lang.*;
@SuppressWarnings("unused")
class client3
{
public static ServerSocket ss;
public static Socket cs[]=new Socket[3];
public static Socket soc;
public static boolean flag=true;
public static void main(String ar[])
{
try {
cs[0]=new Socket(InetAddress.getLocalHost(),4545);
System.out.println("Client3 IS CONNECTED TO Terminal:"); cs[1]=new Socket(InetAddress.getLocalHost(),4000);
System.out.println("client3 is connected to client.\n");
ss=new ServerSocket(4003);
cs[2]=ss.accept();
new SendSignal3().start();
new ByPass3();
}
catch(Exception er)
{
System.out.println("error at :"+er); }
}
}
class SendSignal3 extends Thread
{ private BufferedReader in;
private PrintWriter out;
SendSignal3(){}
public void run()
{
try {
while(true)
{ System.out.println("Type in/out for mobile to be within range or out of range");
in=new BufferedReader(new InputStreamReader(System.in));
String mess=in.readLine(); if(mess.equalsIgnoreCase("in"))
{
mess="yes"; client3.flag=true;
}
else {
mess="no";
33
client3.flag=false;
}
for(int i=0;i<3;i++)
{
out=new PrintWriter(client3.cs[i].getOutputStream(),true); out.println(mess);
} }
}
catch(Exception er){} }
}
class ByPass3
{
private BufferedReader in; private PrintWriter out;
Send send;
Receive receive;
ByPass3()
{ try
{
while(true) {
if(client3.flag)
{ in=new BufferedReader(new InputStreamReader(client3.cs[1].getInputStream()));
String mess=in.readLine(); out=new PrintWriter(client3.cs[2].getOutputStream(),true);
out.println(mess);
System.out.println("Message Recieved is:"+mess); }
}
}
catch(Exception e1){}
}
}
package networks; import java.io.*;
import java.net.*;
class client4
{
public static Socket cs[]=new Socket[3]; public static Socket soc,in1;
public static boolean flag=true;
public static void main(String ar[])
{ try
{
cs[0]=new Socket(InetAddress.getLocalHost(),4545); System.out.println("Client4 IS CONNECTED TO Terminal:");
cs[1]=new Socket(InetAddress.getLocalHost(),4002);
System.out.println("client4 is connected to client2."); cs[2]=new Socket(InetAddress.getLocalHost(),4003);
System.out.println("client4 is connected to client3.\n");
@SuppressWarnings("resource")
ServerSocket s=new ServerSocket(4500);
in1=s.accept();
new GetSignal4().start();
34
new ByPass4().start();
}
catch(Exception er)
{
System.out.println("error at :"+er);
} }
}
class GetSignal4 extends Thread
{
private BufferedReader in; @SuppressWarnings("unused")
private PrintWriter out;
int i; PrintWriter outss;
GetSignal4(){}
public void run()
{
try
{
outss= new PrintWriter(client4.in1.getOutputStream(),true);
while(true)
{
in = new BufferedReader(new InputStreamReader(client4.cs[2].getInputStream())); String mess=in.readLine();
if(mess.equalsIgnoreCase("yes")) client4.flag=true;
else if(mess.equalsIgnoreCase("no"))
client4.flag=false;
else
{ System.out.println("Message Recieved is:"+mess);
outss.println(mess);
}
}
}
catch(Exception er){} }
}
class ByPass4 extends Thread
{
private BufferedReader in; @SuppressWarnings("unused")
private PrintWriter out;
PrintWriter outss; int i;
ByPass4(){}
public void run() {
try
{ outss= new PrintWriter(client4.in1.getOutputStream(),true);
while(true)
{ in=new BufferedReader(new InputStreamReader(client4.cs[1].getInputStream()));
String mess=in.readLine(); System.out.println("Message Recieved is:"+mess);
outss.println(mess);
}
}
35
catch(Exception e1){}
}
}
Data analysis and discussion
Output generation
Output analysis
Compare output against hypothesis
Abnormal case explanation (most important task)
Statistic regression
Discussion
The program outputs a simulation of the algorithm via a GUI. The results of the simulation
show that the nodes in the algorithm reliably maintain the mesh. The source node is able to maintain a
shortest path tree to other members. Most importantly, it shows that the nodes handle link failure
effectively.
Conclusions and recommendations
Our program demonstrates the reliability and speed of the stable mesh-based multicast routing
scheme for MANETs (LSMRM). This reliability is because the use of stable forwarding nodes assures
high quality of links and performs well with regard to packet deliver ratio, control overhead, and packet
delay. This increased reliability is invaluable for group-oriented services, such as cell phone apps and
inter-vehicular communication.
Improvements that we recommend modifying this algorithm for are scalability, flexibility, and
customization services.
36
Bibliography
Broch, J., Maltz, D. A., Johnson, D. B., Hu, Y., & Jetcheva, J. (1998). A Performance Comparison of
Multi-Hop Wireless Ad-Hoc Network Routing Protocols.
Chen, S., Dow, C., Lin, P., Hwang, S. (2008). An Efficient Multicast Protocol in Mobile Ad-hoc
Networks Using Forward Error Correction Techniques.
Gui, C., Chao & Mohapastra, P., (2004). Scalable Multicasting in Mobile Ad Hoc Networks.
Hu, Y., Perrig, A., & Johnson, D. (2005). Ariadne: A Secure On-Demand Protocol for Ad Hoc
Networks.
Olagbegi, B. S. & Meghanathan, N. (2010). A Review of the Energy Efficient and Secure Multicast
Routing for Mobile Ad Hoc Networks. International Journal on Applications of Graph Theory
in Wireless Ad Hoc Networks and Sensor Networks, 2, 1-15.
Sheng-Chang Chen et al. (2008) An Efficient Multicast Protocol in Mobile Ad-hoc Networks Using
Forward Error Correction Techniques, (paper presented at the 5th ACM symposium on
performance evaluation of wireless ad hoc, sensor, and ubiquitous networks, Vancouver,
Canada, October 27-31, 2008)
Appendices
Program flowchart
Program source code with documentation
Input/output listing
Other related material