grey hole document

94
1 CHAPTER 1 INTRODUCTION 1.1 OBJECTIVE Mobile Ad-hoc Network is used most commonly all around the world, because it has the ability to communicate each other without any fixed network. It has the tendency to take decisions on its own that is autonomous state. MANET is generally known for infrastructure less. The bridges in the network are generally known as a base station. A unified security solution is very much needed for networks to protect both route and data forwarding operations in the network layer. Security is an essential requirement in MANET. Without any proper security solution, the malicious node in the network will act as a normal node which causes eaves dropping and selective forwarding attack generally known as gray hole attack. In this paper we surveyed about the different types of attacks occurred in the network layer in MANET. Gray Hole attack is one of the attacks in network layer which comes under security active attacks in MANET.

Upload: ragavendran-anbalagan

Post on 22-Oct-2015

24 views

Category:

Documents


1 download

DESCRIPTION

My analysis and remedy over the attack

TRANSCRIPT

Page 1: Grey Hole Document

1

CHAPTER 1

INTRODUCTION

1.1 OBJECTIVE

Mobile Ad-hoc Network is used most commonly all around the world,

because it has the ability to communicate each other without any fixed

network. It has the tendency to take decisions on its own that is autonomous

state. MANET is generally known for infrastructure less. The bridges in the

network are generally known as a base station. A unified security solution is

very much needed for networks to protect both route and data forwarding

operations in the network layer. Security is an essential requirement in

MANET. Without any proper security solution, the malicious node in the

network will act as a normal node which causes eaves dropping and

selective forwarding attack generally known as gray hole attack. In this

paper we surveyed about the different types of attacks occurred in the

network layer in MANET. Gray Hole attack is one of the attacks in network

layer which comes under security active attacks in MANET.

Page 2: Grey Hole Document

2

1.2 LITERATURE SURVEY

Wireless mesh networks are emerging as a popular choice for

Internet service providers to provision broadband wireless access in the

future. The WMNs are expected to incorporate the attributes of self-

organization, self-healing, and self-configuration for high reliability and

scalability. In spite of the multiple aspects of advantages, the WMNs lack

security guarantees due to its open medium, distributed architecture, and

dynamic topology. The WMN is a multi-hop network, which relies on mesh

routers to forward the packets to the destination. It is clear that successful

collaboration among routers is the foundation for a strong and reliable

network. Cryptography solutions can be used to protect the mesh routers

from most of the routing protocol attacks—selective forwarding, black hole,

sinkhole, and wormhole attacks. Nevertheless, if the routers are

compromised, the attacker will gain access to the public/private keys of the

compromised routers and then break through the cryptographic system.

Therefore, to achieve complete security in a network, it is preferred to use

cryptographic solutions as a first line of defense and non-cryptographic

solutions as a second line of defense.

We investigate a special case of denial of service attack, known

as selective forwarding attack or gray hole attack. With such an attack, the

misbehaving router accepts the packet for transmission but refuses to

forward certain packets by simply dropping them. To launch a selective

forwarding attack, an attacker may compromise or hijack the mesh router

that belongs to the network, known as internal attacks; or attack the network

from outside, known as external attacks.

Page 3: Grey Hole Document

3

Fig 1.2.1 Average detection rate of GHA with respect to simulation time.

To prevent external attacks, routers may employ an

authentication mechanism, e.g., TESLA, to avoid the attacks from

unauthorized routers. However, internal attacks may pose severe threats and

are difficult to defend by cryptographic measures alone. We thus focus on a

non-cryptographic approach to counteract the dropping misbehavior

launched by internal attackers.

PARAMETERS VALUES

Simulation Ns

Nodes 60

Simulation time(s) 500

Warm up period(s) 50

Normal channel loss rate 10%

Channel error nodes (random) 30%

Source nodes 2

Table 1.2.1 Parameters and values during GHA

Page 4: Grey Hole Document

4

A survey on wireless mesh networks

Wireless mesh networks have emerged as a key technology for

next-generation wireless networking. Because of their advantages over other

wireless networks, WMNs are undergoing rapid progress and inspiring

numerous applications. However, many technical issues still exist in this

field. In order to provide a better understanding of the research challenges of

WMNs, this article presents a detailed investigation of current state-of-the-

art protocols and algorithms for WMNs. Open research issues in all protocol

layers are also discussed, with an objective to spark new research interests in

this field.

Fig 1.2.2 Packet delivery ratio with no channel loss

In order to provide a better understanding of the research

challenges of WMNs, this article presents a detailed investigation of current

state-of-the-art protocols and algorithms for WMNs. Open research issues in

all protocol layers are also discussed, with an objective to spark new

research interests in this field.

Page 5: Grey Hole Document

5

PARAMETERS VALUES

Simulation Ns

Nodes 60

Simulation time(s) 500

Warm up period(s) 50

Channel error nodes (random) 30%

Attacker nodes (random) 30%

Source nodes 2

Table 1.2.2 Parameters and values during no channel loss

Mitigating routing misbehavior in mobile ad hoc networks

This paper describes two techniques that improve throughput in

an ad hoc network in the presence of nodes that agree to forward packets but

fail to do so. To mitigate this problem, we propose categorizing nodes based

upon their dynamically measured behavior. We use a watchdog that

identifies misbehaving nodes and a path rater that helps routing protocols

avoid these nodes.

Through simulation we evaluate watchdog and path rater using

packet throughput, percentage of overhead (routing) transmissions, and the

accuracy of misbehaving node detection. To achieve complete security in a

network, it is preferred to use cryptographic solutions as a first line of

defense and non-cryptographic solutions as a second line of defense.

Page 6: Grey Hole Document

6

Fig 1.2.3 Packet delivery ratio with channel loss

PARAMETERS VALUES

Simulation Ns

Nodes 60

Simulation time(s) 500

Warm up period(s) 50

Attacker nodes (random) 30%

Source nodes 2

Table 1.2.3 Parameters and values during channel loss

When used together in a network with moderate mobility, the two

techniques increase throughput by 17% in the presence of 40% misbehaving

nodes, while increasing the percentage of overhead transmissions from the

standard routing protocol's 9% to 17%. During extreme mobility, watchdog

and path rater can increase network throughput by 27%, while increasing the

overhead transmissions from the standard routing protocol's 12% to 24%.

Page 7: Grey Hole Document

7

Secure routing in wireless sensor networks: attacks and

countermeasures

We consider routing security in wireless sensor networks. Many

sensor network routing protocols have been proposed, but none of them have

been designed with security as a goal. We propose security goals for routing

in sensor networks, show how attacks against ad-hoc and peer-to-peer

networks can be adapted into powerful attacks against sensor networks,

introduce two classes of novel attacks against sensor networks sinkholes and

HELLO floods, and analyze the security of the entire major sensor network

routing protocols. We describe crippling attacks against all of them and

suggest countermeasures and design considerations. This is the first such

analysis of secure routing in sensor networks.

Page 8: Grey Hole Document

8

CHAPTER 2

SYSTEM ANALYSIS

2.1 EXISTING SYSTEM

The Existing system addresses the Gray hole Attack detection

by using CAD algorithm. The CAD identify the gray hole attackers by

filtering the normal channel losses and is based on two procedures such as

Channel estimation and traffic monitoring. Even during the normal losses,

CAD can effectively detect the attackers thereby increases the packet

delivery ratio of the network.

2.1.1 DRAWBACKS OF EXISTING SYSTEM

The existing system has following disadvantages,

Current CAD simulation works only when the system is

Collision free and also free from jamming attacks

During noisy channel or when the noise is introduced by

the attackers into the channel, it affects the sensing

process which in turn leads to inaccurate threshold.

Current CAD has not addressed the scenario when

multiple malicious nodes act in Collision.

Page 9: Grey Hole Document

9

2.2 PROPOSED SYSTEM

The proposed system addresses the challenges of CAD

algorithm to detect Gray Hole Attack when multiple malicious nodes act in

collision. This is done by extending the CAD to address the challenges. The

ultimate goal for MANET is to provide security solutions. To provide a

solution for security reason there are some of the mechanism which is used

to prevent, detect and respond. They are mainly Availability,

Confidentiality, Integrity and Authentication.

2.3 FEASIBILITY STUDY

The feasibility study deals with all the analysis that takes up in

developing the project. Each structure has to be thought of in the developing

of the project, as it has to serve the end user in a user-friendly manner. One

must know the type of information to be gathered and the system analysis

consist of collecting, Organizing and evaluating facts about a system and its

environment.

The main objective of the system analysis is to study the

existing operation and to learn and accomplish the processing activities. The

land management and tree cultivation process and applying them through

web application need to be analyzed well. The details are processed through

coding themselves. It will be controlled by the programs alone.

Economic Feasibility

Operational Feasibility

Technical Feasibility

Page 10: Grey Hole Document

10

2.3.1 ECONOMIC FEASIBILITY

The organization has to buy a personal computer with a

keyboard and a mouse, this is a direct cost. There are many direct benefits of

covering the manual system to computerized system. The user can be given

responses on asking questions, justification of any capital outlay is that it

will reduce expenditure or improve the quality of service or goods, which in

turn may be expected to provide the increased profits.

2.3.2 OPERATIONAL FEASIBILITY

The Proposed system accessing process to solves problems

what occurred in existing system. The current day-to-day operations of the

organization can be fit into this system. Mainly operational feasibility should

include on analysis of how the proposed system will affects the

organizational structures and procedures.

2.3.3 TECHNICAL FEASIBILITY

The cost and benefit analysis may be concluded that

computerized system is favorable in today’s fast moving world. The

assessment of technical feasibility must be based on an outline design of the

system requirements in terms of input, output, files, programs and

procedure. The project aims to manage land providers and tree planters and

their transaction process using web site. The current system aims to

overcome the problems of the existing system. The current system is to

reduce the technical skill requirements so that more number of users can

access the application.

Page 11: Grey Hole Document

11

CHAPTER 3

SYSTEM SPECIFICATION

3.1 HARDWARE REQUIREMENTS

Processor : Intel(R) Core(TM) i5-2430M

RAM : 4GB

Monitor : 17” Color

Hard disk : 500 GB

Keyboard : Standard PS/2 Keyboard

Mouse : Synaptics PS/2 Port TouchPad

3.2 SOFTWARE REQUIREMENTS

Coding Language : JAVA

Operating System : Windows 7

SDK : JDK 1.5.0 and higher

Page 12: Grey Hole Document

12

CHAPTER 4

SOFTWARE DESCRIPTION

4.1 FRONT END

INTRODUCTION

Java technology is both a programming language and a

platform. The Java programming language is a high-level language that can

be characterized by all of the following buzzwords:

Simple

Architecture neutral

Object oriented

Portable

Distributed

High performance

Interpreted

Multithreaded

Robust

Dynamic

Secure

With most programming languages, you either compile or

interpret a program so that you can run it on your computer. The Java

programming language is unusual in that a program is both compiled and

interpreted. With the compiler, first you translate a program into an

intermediate language called Java byte codes —the platform-independent

codes interpreted by the interpreter on the Java platform.

Page 13: Grey Hole Document

13

The interpreter parses and runs each Java byte code instruction

on the computer. Compilation happens just once; interpretation occurs each

time the program is executed. The following figure illustrates how this

works.

THE JAVA PLATFORM

A platform is the hardware or software environment in which a

program runs. We’ve already mentioned some of the most popular platforms

like Windows 2000, Linux, Solaris, and Mac OS. Most platforms can be

described as a combination of the operating system and hardware. The Java

platform differs from most other platforms in that it’s a software-only

platform that runs on top of other hardware-based platforms. The Java

platform has two components:

The Java Virtual Machine

The Java Application Programming Interface

Java VM is the base for the Java platform and is ported onto

various hardware based platforms. The Java API is a large collection of

ready-made software components that provide many useful capabilities, such

as graphical user interface widgets. The Java API is grouped into libraries of

related classes and interfaces; these libraries are known as packages.

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 RDBMSs. This consistent interface is

Page 14: Grey Hole Document

14

achieved through the use of “plug-in” database connectivity 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.

FEATURES OF JAVA

OBJECT ORIENTED

In java everything is an Object. Java can be easily extended

since it is based on the Object model.

PLATFORM INDEPENDENT

Unlike many other programming languages including C and

C++ when Java is compiled, it is not compiled into platform specific

machine, rather into platform independent byte code. This byte code is

distributed over the web and interpreted by virtual Machine on whichever

platform it is being run.

SIMPLE

Java is designed to be easy to learn. If you understand the basic

concept of OOP java would be easy to master.

Page 15: Grey Hole Document

15

SECURE

With Java's secure feature it enables to develop virus-free,

tamper-free systems. Authentication techniques are based on public-key

encryption.

ARCHITECTURAL- NEUTRAL

Java compiler generates an architecture-neutral object file

format which makes the compiled code to be executable on many

processors, with the presence Java runtime system.

PORTABLE

Being architectural neutral and having no implementation

dependent aspects of the specification makes Java portable. Compiler and

Java is written in ANSI C with a clean portability boundary which is a

POSIX subset.

ROBUST

Java makes an effort to eliminate error prone situations by

emphasizing mainly on compile time error checking and runtime checking.

MULTI-THREADED

With Java's multi-threaded feature it is possible to write

programs that can do many tasks simultaneously. This design feature allows

developers to construct smoothly running interactive applications.

Page 16: Grey Hole Document

16

INTERPRETED

Java byte code is translated on the fly to native machine

instructions and is not stored anywhere. The development process is more

rapid and analytical since the linking is an incremental and light weight

process.

DYNAMIC

Java is considered to be more dynamic than C or C++ since it is

designed to adapt to an evolving environment. Java programs can carry

extensive amount of run-time information that can be used to verify and

resolve accesses to objects on run-time.

Page 17: Grey Hole Document

17

CHAPTER 5

PROJECT DESCRIPTION

5.1 PROBLEM DEFINITION

Gray hole is a node that can switch from behaving correctly to

behaving like a black hole that is it is actually an attacker and it will act as a

normal node. So we can’t identify easily the attacker since it behaves as a

normal node. Every node maintains a routing table that stores the next hop

node information which is a route packet to destination node .If a source

node is in need to route a packet to the destination node it uses a specific

route and it will be checked in the routing table whether it is available or not.

If a node initiates a route discovery process by broadcasting Route Request

message to its neighbor, by receiving the route request message the

intermediate nodes will update their routing tables for reverse route to the

source. A route reply message is sent back to the source node when the

RREQ query reaches either to the destination node or to any other node

which has a current route to destination.

5.2 OVERVIEW OF THE PROJECT

A variation of black hole attack is the gray hole attack, in which

the nodes will drop the packets selectively. Selective forward attack is of

two types they are

Dropping all UDP packets while forwarding TCP packets.

Dropping 50% of the packets or dropping them with a

probabilistic distribution.

Page 18: Grey Hole Document

18

These are the attacks that seek to disrupt the network without

being detected by the security measures. The gray hole attack has two

phases:

Phase 1

A malicious node exploits the AODV protocol to advertise

itself as having a valid route to destination node, with the intention of

interrupting packets of spurious route.

Phase 2

In this phase, the nodes has been dropped the interrupted

packets with a certain probability and the detection of gray hole attack is a

difficult process. Normally in the gray hole attacks the attacker behaves

maliciously for the time until the packets are dropped and then switch to

their normal behavior. Both normal node and attacker are same. Due to this

behavior it is very hard to find out in the network to figure out such kind of

attack. The other name for Gray hole attack is node misbehaving attack.

To develop a channel aware detection algorithm that can

effectively identify the selective forwarding attackers by filtering out the

normal channel losses. The CAD approach is based on two procedures,

Channel estimation

Traffic monitoring

Channel estimation

Channel estimation is to estimate the normal loss rate due to

bad channel quality or medium access collision. The channel estimation

Page 19: Grey Hole Document

19

procedure at each node correspondingly sets an upstream detection threshold

and downstream detection threshold. Each node judges the behavior of its

neighbors by comparing the upstream/downstream observations against the

detection thresholds to identify the misbehaving nodes. In particular, the

thresholds will be dynamically adjusted with the normal loss rates to

maintain the detection accuracy when network status changes.

Fig 5.2.1 CAD approach

Traffic monitoring

Traffic monitoring is to monitor the actual loss rate; if the

monitored loss rate at certain hops exceeds the estimated loss rate, those

nodes involved will be identified as attackers. Specifically, the traffic

monitoring procedure at each intermediary node1 along a path monitors the

behaviors of both its upstream and downstream neighbors, termed as

upstream monitoring and downstream monitoring, respectively.

Page 20: Grey Hole Document

20

5.3 PROBLEM FORMULATION

The channel estimation is integrated with traffic monitoring to

achieve channel-aware detection of gray hole attack, which can effectively

identifies selective forwarding misbehavior hidden in the normal loss events

due to bad channel quality or medium access collisions.

In CAD, upstream and downstream traffic monitoring is

combined to achieve a versatile detection method. We carry out analytical

studies of the false alarm and missed detection probabilities for the CAD

scheme. Based on the analytical model, the optimal upstream/ downstream

detection thresholds can be computed to minimize the summation of false

alarm and missed detection probabilities. The thresholds are dynamically

adjusted with the channel status to maintain the efficiency of CAD under

varying network conditions.

Page 21: Grey Hole Document

21

5.4 MODULE DESCRIPTION

5.4.1 MODULES

1. Selecting the Source

In this module node has been inserted in to the screen and the

route for the nodes has been shown. Then the source of the data has been

set and the destination of the data to be sent has been set. Path from

source and the destination has been shown in order to send the data from

source to destination. The data from source to destination has been sent

through the path that has been shown.

2. Data Transfer

The main feature of this module is to transfer data from source to

the destination. The source and destination has been set and the data has

been sent from the source through the existing path to the destination.

The data has been sent through the network that is formed between the

source and the destination. The data is spliced in to packets and it has

been sent from the source to the destination.

3. Gray Hole attack

The main feature of this module is to find the gray hole attack

during the transfer of data between two nodes. When the data is sent from

one node to another node there may exist an attacker, by this module the

attacker can be detected. During the data transfer between the nodes there

may exist an attacker, they can found by applying the CAD algorithm to

the received data result. The exact attacker (i.e.) the exact node who is

attacked the data can be detected in this module.

Page 22: Grey Hole Document

22

5.5 SYSTEM FLOW DIAGRAM

Fig 5.5.1 System flow diagram

Page 23: Grey Hole Document

23

5.6 INPUT DESIGN

Input design is the process of converting user-originated inputs

to a computer understandable format. Input design is one of the most

expensive phases of the operation of computerized system and is often the

major problem of a system. A large number of problems with a system can

usually be tracked backs to fault input design and method. Every moment of

input design should be analyzed and designed with utmost care.

The design of the input should be made the input as the over to

the numerous networks in the reliable area that should be passed as the

installation in the remote network. It has the following constraints in the

input database.

All the files from the disk should be acquired by data.

It is suitable to more available data clearance and made available.

The menu of design should be understandable and it is in the right

format.

The system takes input from the users, processes it and

produces an output. Input design is link that ties the information system into

the world of its users. The system should be user-friendly to gain appropriate

information to the user. The project gives the low time consumption to make

the sensitive application made simple. When applying the project it provides

the low man-power attrition with the reasonable output.

The amount of fund that the company can spend into the

research and development of the system is limited. The expenditures must be

justified. Thus the developed system as well within the budget and this was

Page 24: Grey Hole Document

24

achieved because most of the technologies used are freely available. Only

the customized products had to be purchased.

In this system mainly used to protect the system and files giving

file path input option. Mail sending utility input as sends the Email to

recipient with attachment. System analysis decide the following input design

details like, what data to input, what medium to use, how the data should be

arranged or coded, data items and transactions needing validations to detect

errors and at last the dialogue to guide user in providing input.

Input data of a system may not be necessarily is raw data

captured in the system from scratch. These can also be the output of another

system or subsystem. The design of input covers all the phases of input from

the creation of initial data to actual entering of the data to the system for

processing. The design of inputs involves identifying the data needed,

specifying the characteristics of each data item, capturing and preparing data

from computer processing and ensuring correctness of data.

Input design is the process of converting user-originated inputs

to a computer-based format. Input design is one of the most expensive

phases of the operation of computerized system and is often the major

problem of a system. Any Ambiguity in input leads to a total fault in output.

The goal of designing the input data is to make data entry as easy and error

free as possible.

In the project, the forms are designed with easy to use options

such as selecting the master records through drop down list in transaction

forms.

Page 25: Grey Hole Document

25

5.7 OUTPUT DESIGN

Output design generally refers to the results and information

that are generated by the system for many end-users; it should be

understandable with the enhanced format.

The output of the software is used to make the remote

installation of the new software in the system and, it is awake the immediate

alert to the system that should be enhanced it as the input to the system.

Output is the main reason for developing the system and the basis on which

they evaluate the usefulness of the application.

Computer output is the most important direct source of

information to the user output design deals with form design efficient output

design should improve the interfacing with user.

The term output applies to any information produced by an

information system in terms of displayed. When analyst design system

output, they Identify the specific output that is needed to meet the

requirements of end user. Previewing the output reports by the user is

extremely important because the user is the ultimate judge of the quality of

the output and, in turn, the success of the system.

When designing output, system analysis accomplishes more

things like, to determine what applications, websites or documents whether

blocked or allowed. Allowing should be in various options. The output is

designed in such a way that it is attractive, convenient and informative.

Page 26: Grey Hole Document

26

Forms are designed in Java Net beans with various features,

which make the console output more pleasing. As the outputs are the most

important sources of information to the users, better design should improve

the system’s relationships with user and also will help in decision-making.

Form design elaborates the way output is presented and the layout available

for capturing information.

Page 27: Grey Hole Document

27

CHAPTER 6

SYSTEM TESTING

After the source code has been completed, documented as

related data structures. Completed the project has to undergo testing and

validation where there is subtitle and definite attempt to get errors.

The project developer treads lightly, designing and execution

test that will demonstrates that the program works rather than uncovering

errors, unfortunately errors will be present and if the project developer

doesn’t find them, the user will find out.

The project developer is always responsible for testing the

individual units i.e. modules of the program. In many cases developer also

conducts integration testing i.e. the testing step that leads to the construction

of the complete program structure.

This project has undergone the following testing procedures to

ensure its correctness.

Unit testing

User Acceptance Testing

Page 28: Grey Hole Document

28

6.1 UNIT TESTING

In unit testing, we have to test the programs making up the

system. For this reason, Unit testing sometimes called as Program testing.

The software units in a system are the modules and routines that are

assembled and integrated to perform a specific function, Unit testing first on

the modules independently of one another, to locate errors.

This enables, to detect errors in coding and logic that are

contained with the module alone. The testing was carried out during

programming stage itself.

6.2 USER ACCEPTANCE TESTING

In these testing procedures the project is given to the customer to test

whether all requirements have been fulfilled and after the user is fully

satisfied. The project is perfectly ready. If the user makes request for any

change and if they found any errors those all errors has to be taken into

consideration and to be correct it to make a project a perfect project.

Page 29: Grey Hole Document

29

CHAPTER 7

SYSTEM IMPLEMENTATION

When the initial design was done for the system, the client was

consulted for the acceptance of the design so that further proceedings of the

system development can be carried on. After the development of the system

a demonstration was given to them about the working of the system. The

aim of the system illustration was to identify any malfunction of the system.

After the management of the system was approved the system

implemented in the concern, initially the system was run parallel with

existing manual system. The system has been tested with live data and has

proved to be error free and user friendly.

Implementation is the process of converting a new or revised

system design into an operational one when the initial design was done by

the system; a demonstration was given to the end user about the working

system.

This process is uses to verify and identify any logical mess

working of the system by feeding various combinations of test data. After

the approval of the system by both end user and management the system was

implemented.

System implementation is made up of many activities. The six

major activities are as follows.

Page 30: Grey Hole Document

30

Coding

Coding is the process of whereby the physical design

specifications created by the analysis team turned into working computer

code by the programming team.

Testing

Once the coding process is begin and proceed in parallel, as

each program module can be tested.

Installation

Installation is the process during which the current system is

replaced by the new system. This includes conversion of existing data,

software, and documentation and work procedures to those consistent with

the new system.

Documentation

It is result from the installation process, user guides provides

the information of how the use the system and its flow.

Training and support

Training plan is a strategy for training user so they quickly

learn to the new system. The development of the training plan probably

began earlier in the project. The best-suited application package to develop

the system is Java Net beans under suitable java environment.

Page 31: Grey Hole Document

31

CHAPTER 8

CONCLUSION AND FUTURE ENHANCEMENTS

8.1 CONCLUSION

The Misbehavior of nodes have been caused severe damage and the

whole network has been attacked in the network layer which is a Gray hole

attack in MANET. Security is the most important feature for deployment in

MANET. In this paper we have seen the number of attacks happened in

network layer and especially for gray hole attack. Due to its dynamic nature,

MANET prone to different limitations and weakness. To overcome this

problem we have to use a new technique which should be designed. Our aim

is to detect and mitigate the false node which is acting as a normal node,

which is very hard to find out. But if we design a new approach of detecting

the attacker node we can ensure that there is a safety in the network. Once

security is lost in the network then the entire network will get failed. Gray

hole attack ultimately decrease the concert of the network. The main goal of

the gay hole attack should be the improvement of security and as well as the

performance of the network. During the survey we addressed how the attack

has been happened in the network layer.

Page 32: Grey Hole Document

32

8.2 FUTURE ENHANCEMENTS

There are several types of attacks mounted on the routing

protocol which are aimed at disrupting the operation of the network. Various

attacks on the routing protocol are described briefly below:

Routing Table Overflow: In this attack, the attacker tempts to

create routes to nonexistent nodes.

Routing Table Poisoning: The Compromised nodes in the network

send fictitious routing updates packets sent to other uncompromised

nodes.

Packet Replication: In this attack, an adversary node replicates

stale packets.

Route Cache Poisoning: Each node maintains a route cache which

holds information regarding routes that have become known to the

node in the recent past.

Rushing Attack: On demand routing protocols that use duplicate

suppression during the route discovery process are vulnerable to

this attack.

Page 33: Grey Hole Document

33

CHAPTER 9

APPENDIX

9.1 SOURCE CODE

Driver.java

import java.io.*;

import java.util.*;

import java.lang.Math;

class Driver

{

public static int Wireless_MTU = 2048;

public static void main ( String [] args) throwsIOException,

InvalidProtocolException

{

InputStreamReader reader = new InputStreamReader(System.in);

BufferedReader input = new BufferedReader(reader);

LinkedList hs = new LinkedList();

Scheduler Sched = new Scheduler( new FreeSpacePropagation() );

Node.setProtocol( new SBQProtocol() );

Node n1 = new Node(1, new RealPoint(0, 0), Sched);

Node n2 = new Node(2, new RealPoint(0, 50), Sched);

Node n3 = new Node(3, new RealPoint(0, 100), Sched);

Node n4 = new Node(4, new RealPoint(0, 150), Sched);

Node n5 = new Node(5, new RealPoint(0, 200), Sched);

Node n6 = new Node(6, new RealPoint(0, 250), Sched);

Page 34: Grey Hole Document

34

Node n7 = new Node(7, new RealPoint(0, 300), Sched);

Node n8 = new Node(8, new RealPoint(0, 350), Sched);

Node n9 = new Node(9, new RealPoint(0, 400), Sched);

Node n10 = new Node(10, new RealPoint(0, 450), Sched);

for (int i = 1; i <= 10; i++)

{

Node n = new Node(i, new RealPoint( Math.random()*5 + i*40,

Math.random()*20), Sched);

hs.add(n);

}

((Node) hs.getLast()).setVisible(true);

int cnt =0;

//for (int i=0; i<2000; i++) {

while (true)

{

Sched.run();

cnt++;

if ((cnt % 1000)==0)

{

Node s = (Node) hs.getFirst();

Node d = (Node) hs.getLast();

s.send(d.getAddr(), Wireless_MTU, "Hello this is "+s.getAddr());

}

}

}

}

Page 35: Grey Hole Document

35

Event.java

import java.io.*;

import java.util.*;

import java.lang.Math;

class Event implements Comparable

{

public static final int TYPE_SEND=0;

public static final int TYPE_RECV=1;

public static int evt_count = 0;

private double time_due;

private Packet evt_packet;

private int evt_type;

private int evt_num;

private Node recv_node;

private Node send_node;

public Event(Packet pkt, Node sendNode, Node recvNode, double

_time_due, int evtType)

{

time_due = _time_due;

evt_packet = pkt;

evt_type = evtType;

recv_node = recvNode;

send_node = sendNode;

evt_num = evt_count++;

}

public double getTimeDue()

{

Page 36: Grey Hole Document

36

return time_due;

}

public Packet getPacket()

{

return evt_packet;

}

public int getType()

{

return evt_type;

}

public int getEventNum()

{

return evt_num;

}

public void setTimeDue(double _time_due)

{

time_due = _time_due;

}

public void setPacket(Packet pkt)

{

evt_packet = pkt;

}

public void setRecvNode(Node recvNode)

{

recv_node = recvNode;

}

public Node getRecvNode() { return recv_node; }

Page 37: Grey Hole Document

37

public void setSendNode(Node sendNode)

{

send_node = sendNode;

}

public Node getSendNode() { return send_node; }

public int compareTo(Object obj)

{

Event evt = (Event) obj;

if (evt.getTimeDue() > time_due) return -1;

if (evt.getTimeDue() < time_due) return 1;

if (evt.getEventNum() > evt_num) return -1;

if (evt.getEventNum() < evt_num) return 1;

return 0;

}

}

FreeSpacePropagation.java

import java.io.*;

import java.util.*;

import java.lang.Math;

class FreeSpacePropagation extends Propagation

{

public static double transmit_power = 100;

public static double transmit_dBm = 20;

public static double transmit_antenna_gain_dBm = 0;

public static double receive_antenna_gain_dBm = 0;

public static double wavelength = 0.125;

Page 38: Grey Hole Document

38

public static double random_noise_dBm = 5;

public static double scale_amt = 100;

public double computePower(Node sendNode, Node recvNode)

{

double distance =

sendNode.getLocation().getDistance(recvNode.getLocation());

double recvPower = transmit_dBm

+ transmit_antenna_gain_dBm

+ receive_antenna_gain_dBm

+ 20 * Math.log(wavelength/(4*Math.PI)) / Math.log(10)

- 20 * Math.log(distance) / Math.log(10)

- Math.random()* random_noise_dBm;

double recvPercent = Math.min(100.0, Math.max(0.0,

(recvPower+scale_amt) / scale_amt));

if (recvPercent < 0.30) return 0.0;

return recvPercent;

}

public void propagate(Node sendNode, Node recvNode, Packet p)

{

double recvPower = computePower(sendNode, recvNode);

((WirelessPacket) p).setSignalPower(recvPower);

}

}

Page 39: Grey Hole Document

39

GUIDemo.java

import java.io.*;

import java.util.*;

import java.lang.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

interface GUIKonstants

{

public static final int SBQPROTOCOL = 1000;

public static final int CLEARPROTOCOL= 1002;

public static final int ADDNODE = 2000;

public static final int SENDPACKET= 2001;

public static final int SELECT = 2002;

public static final int DELETE = 2003;

public static final int LOADNODES = 2004;

public static final int SHOWATTACK = 2005;

public static final int SHOWTABLE = 3000;

public static final int SENDER = 3001;

public static final int DESTINATION= 3002;

public static final int MOVENODE = 3003;

public static final int MULTINODE= 3004;

public static final int XDISP = 0;

public static final int YDISP = 30;

public static final int WIDTHSIM = 500;

public static final int HEIGHTSIM = 500;

public static final int WIDTHBUTTON = 100;

Page 40: Grey Hole Document

40

public static final int HEIGHTBUTTON = 20;

public static final int packetnum = 2;

}

class GUIDemo extends JFrame implements WindowListener,

ActionListener, MouseListener, MouseMotionListener, GUIKonstants,

ScheduleListener

{

public JTextArea commandText;

public int nodeNum;

public JCanvas JC;

public GridBagLayout gridbag;

public GridBagConstraints constraints;

public String fname = "test1";

private Scheduler mySched;

private nodeProperties GUIsender = null;

private nodeProperties GUIdestination = null;

private nodeProperties activeSender = null;

int rate = 50;

int movementTimeInterval= 300;

int mouseX, mouseY;

int previousDest = -1;

int previousSender = -1;

int previousSelect = 0;

int movingNode = -1;

int ProtocolNum = SBQPROTOCOL;

int function = ADDNODE;

Hashtable nodeRef = new Hashtable();

Page 41: Grey Hole Document

41

boolean isMoving = false;

JButton nbutton5;

JToggleButton sbutton1, sbutton2, sbutton3, sbutton4;

JToggleButton nbutton1, nbutton2, nbutton3, nbutton4,nbutton6,nbutton7;

JToggleButton pbutton3;

JPanel p;

java.util.Timer schedTimer, updateTimer, simTimer, nodeTimer;

public GUIDemo (String [] args)

{

super("Mitigating Attack");

if (args.length > 0) fname = args[0];

setupSimulation();

setBackground(SystemColor.control);

mySched.addScheduleListener(this);

addWindowListener(this);

// Contents Pane

JC = new JCanvas(nodeRef, XDISP, YDISP);

JPanel pcanvas = new JPanel();

pcanvas.setLayout(new GridLayout(1,1));

pcanvas.add(JC);

// Add event listeners

addMouseMotionListener(this);

addMouseListener(this);

// Add peripherals

p = new JPanel();

p.setLayout(new GridLayout(14, 1));

JPanel panel = new JPanel();

Page 42: Grey Hole Document

42

panel.setLayout(new BorderLayout());

panel.add(pcanvas, BorderLayout.WEST);

panel.add(p, BorderLayout.EAST);

getContentPane().add(panel);

protocolButtons();

nodeButtons();

p.add(pbutton3);

p.add(nbutton1);

p.add(nbutton2);

p.add(nbutton4);

p.add(nbutton6);

p.add(nbutton3);

p.add(sbutton1);

p.add(sbutton2);

p.add(sbutton3);

p.add(sbutton4);

p.add(nbutton5);

p.add(nbutton7);

pack();

setVisible(true);

}

public void loadFile()

{

int i = 0;

try {

BufferedReader InFile = new BufferedReader( new FileReader(fname));

String Lines = InFile.readLine();

Page 43: Grey Hole Document

43

int x, y;

while (Lines != null) {

StringTokenizer s = new StringTokenizer(Lines);

Integer Int = new Integer(s.nextToken());

x = Int.intValue();

Int = new Integer(s.nextToken());

y = Int.intValue();

addNode(x,y);

if (i == 0) setSender(x,y);

else setDest(x,y);

i++;

Lines = InFile.readLine();

}

InFile.close();

} catch (FileNotFoundException e) {

} catch (IOException e) {

}

// set nodes to mobile

isMoving = true;

simTimer = new java.util.Timer();

int delay = 1000; // delay for 1 sec.

final int period = 1000; // repeat every sec.

simTimer.scheduleAtFixedRate(new TimerTask() {

int num = 0;

public void run() {

System.out.println("testnum = " + num);

num++;

Page 44: Grey Hole Document

44

if (GUIsender != null & GUIdestination != null) {

GUIsender.getNode().send(GUIdestination.getNode().getAddr(), 1000,

"This is just a normal data packet");

}

else

{

return;

}

if (num >= packetnum) {

this.cancel();

JOptionPane.showMessageDialog(null, "Completed simulation (sent

"+packetnum+" packets).",

}

}

}

public void buildConstraints (GridBagConstraints constraints, int gx,

int gy, int gw, int gh, int wx, int wy)

{

constraints.gridx = gx;

constraints.gridy = gy;

constraints.gridwidth = gw;

constraints.gridheight= gh;

constraints.weightx = wx;

constraints.weighty = wy;

}

public void addTextBox() {

buildConstraints(constraints, 0, HEIGHTSIM+HEIGHTBUTTON*2,

Page 45: Grey Hole Document

45

WIDTHBUTTON,HEIGHTBUTTON,100,10);

commandText = new JTextArea("hello everyone!", WIDTHSIM, 1);

getContentPane().add(commandText, constraints);

}

public void actionPerformed(ActionEvent e)

{

int response = JOptionPane.YES_OPTION;

int cmdval = 0;

switch((cmdval=(new Integer(e.getActionCommand())).intValue()))

{

case SBQPROTOCOL:

if (ProtocolNum != cmdval & nodeRef.size() > 0) {

response = JOptionPane.showConfirmDialog(null,

"This will delete all prior information",

"Confirm Restart",

JOptionPane.YES_NO_OPTION);

}

if (response == JOptionPane.YES_OPTION) {

clear();

disableSelectButtons();

System.out.println("changing protocol to "+cmdval);

ProtocolNum = cmdval;

switchProtocol(ProtocolNum);

}

break;

case CLEARPROTOCOL:

clear();

Page 46: Grey Hole Document

46

disableSelectButtons();

System.out.println("Resetting simulator and clearing

nodes.");

break;

case ADDNODE:

function = ADDNODE;

disableSelectButtons();

System.out.println("Adding node.");

break;

case LOADNODES:

loadFile();

break;

case SENDPACKET:

function = SENDPACKET;

previousSelect = SENDPACKET;

System.out.println("Sending packet.");

if (GUIsender != null & GUIdestination != null) {

GUIsender.getNode().send(GUIdestination.getNode().getAd

dr(), 2000, "This is just a normal data packet");

disableSelectButtons();

}

else

JOptionPane.showMessageDialog(null, "Select Sender and

Destinstion first");

break;

case SHOWATTACK:

function = SHOWATTACK;

Page 47: Grey Hole Document

47

previousSelect = SHOWATTACK;

int c;

System.out.println("Show Attack.");

if (GUIsender != null & GUIdestination != null) {

GUIsender.getNode().send(GUIdestination.getNode().getAd

dr(), 2005, "This is a attack data packet");

// GUIsender.attacknode();

//JOptionPane.showMessageDialog(null,"GUIsender.getNod

eValue()");

disableSelectButtons();

JOptionPane.showMessageDialog(null, "Message not sent

due to attack");

}

else

{

JOptionPane.showMessageDialog(null, "Select Sender and

Destinstion first");

}

break;

case SELECT:

function = previousSelect;

System.out.println("selection");

if (nodeRef.size() > 0) {

enableSelectButtons();

}

break;

Page 48: Grey Hole Document

48

case DELETE:

function = DELETE;

disableSelectButtons();

break;

case SHOWTABLE:

function = SHOWTABLE;

previousSelect = SHOWTABLE;

break;

case SENDER:

function = SENDER;

previousSelect = SENDER;

break;

case DESTINATION:

function = DESTINATION;

previousSelect = DESTINATION;

break;

case MOVENODE:

function = MOVENODE;

previousSelect = MOVENODE;

break;

case MULTINODE:

function=MULTINODE;

previousSelect= MULTINODE;

addNode(80,80);

addNode(150,150);

addNode(100,200);

Page 49: Grey Hole Document

49

addNode(200,80);

addNode(150,300);

addNode(200,200);

break;

default:

System.out.println("hello "+e.getActionCommand());

break;

}

pack();

setVisible(true);

}

public void switchProtocol(int protocolNum)

{

switch(protocolNum) {

case SBQPROTOCOL: Node.setProtocol(new SBQProtocol() );

break;

}

}

public void setupSimulation()

{

mySched = new Scheduler(new FreeSpacePropagation());

switchProtocol(ProtocolNum);

}

public void run()

{

schedTimer = new java.util.Timer();

int delay = 1; // delay for 1 sec.

Page 50: Grey Hole Document

50

final int period = 1; // repeat every sec.

schedTimer.scheduleAtFixedRate(new TimerTask()

{

public void run()

{

mySched.run((double)period);

JC.repaint();

}

}

final Random r = new Random();

r.setSeed(100);

updateTimer = new java.util.Timer();

int delay2 = 3000; // delay for 3 sec.

inal int period2 = movementTimeInterval;

updateTimer.scheduleAtFixedRate(new TimerTask()

{

public void run()

{

nodeProperties np;

Iterator itr = nodeRef.values().iterator();

if (isMoving == false) return;

while (itr.hasNext()) {

np = (nodeProperties) itr.next();

int dir = r.nextInt()%5;

int x,y;

x = np.getX();

y = np.getY();

Page 51: Grey Hole Document

51

switch(dir) {

case 1:

x = x + rate;

if (x >= WIDTHSIM-20) {

x = WIDTHSIM-rate;

}

break;

case 2:

y = y + rate;

if (y >= HEIGHTSIM-20) {

y = HEIGHTSIM-rate;

}

break;

case 3:

y = y - rate;

if (y <= 20) {

y = rate;

}

break;

}

np.setDesiredLocation(x, y);

}

JC.repaint();

}

}

}

public int searchNode(int mouseX, int mouseY)

Page 52: Grey Hole Document

52

{

int i, addr =-1, dist, shortest=10000000;

nodeProperties np;

Iterator itr = nodeRef.values().iterator();

while (itr.hasNext()) {

np = (nodeProperties) itr.next();

dist = (int) np.getNode().getLocation().getDistance((double) mouseX/2,

(double) mouseY/2);

if (dist < shortest) {

addr = np.getNode().getAddr();

shortest = dist;

}

}

return addr;

}

public void protocolButtons()

{

pbutton3 = new JToggleButton("Clear",false);

pbutton3.addActionListener(this);

pbutton3.setActionCommand((new String(CLEARPROTOCOL+"

")).trim());

ButtonGroup protocolButtonGroup = new ButtonGroup();

protocolButtonGroup.add(pbutton3);

}

public void nodeButtons()

{

nbutton1 = new JToggleButton("Add Node",true);

Page 53: Grey Hole Document

53

nbutton1.addActionListener(this);

nbutton1.setActionCommand((new String(ADDNODE+" ")).trim());

nbutton2 = new JToggleButton("Send Packet",false);

nbutton2.addActionListener(this);

nbutton2.setActionCommand((new String(SENDPACKET+" ")).trim());

nbutton3 = new JToggleButton("Select",false);

nbutton3.addActionListener(this);

nbutton3.setActionCommand((new String(SELECT+" ")).trim());

nbutton4 = new JToggleButton("Kill Node",false);

nbutton4.addActionListener(this);

nbutton4.setActionCommand((new String(DELETE+" ")).trim());

nbutton5 = new JButton("Load Nodes");

nbutton5.addActionListener(this);

nbutton5.setActionCommand((new String(LOADNODES+" ")).trim());

nbutton6 = new JToggleButton("Show Attack");

nbutton6.addActionListener(this);

nbutton6.setActionCommand((new String(SHOWATTACK+" ")).trim());

sbutton1 = new JToggleButton("Show Routing Table");

sbutton1.addActionListener(this);

sbutton1.setActionCommand((new String(SHOWTABLE+" ")).trim());

sbutton2 = new JToggleButton("Sender");

sbutton2.addActionListener(this);

sbutton2.setActionCommand((new String(SENDER+" ")).trim());

sbutton3 = new JToggleButton("Destination");

sbutton3.addActionListener(this);

sbutton3.setActionCommand((new String(DESTINATION+" ")).trim());

Page 54: Grey Hole Document

54

sbutton4 = new JToggleButton("Move Node");

sbutton4.addActionListener(this);

sbutton4.setActionCommand((new String(MOVENODE+" ")).trim());

nbutton7=new JToggleButton("Multi Node");

nbutton7.addActionListener(this);

nbutton7.setActionCommand((new String(MULTINODE+" ")).trim());

disableSelectButtons();

ButtonGroup nodeButtonGroup = new ButtonGroup();

nodeButtonGroup.add(nbutton1);

nodeButtonGroup.add(nbutton2);

nodeButtonGroup.add(nbutton3);

nodeButtonGroup.add(nbutton4);

nodeButtonGroup.add(nbutton6);

nodeButtonGroup.add(nbutton7);

ButtonGroup selectButtonGroup = new ButtonGroup();

selectButtonGroup.add(sbutton1);

selectButtonGroup.add(sbutton2);

selectButtonGroup.add(sbutton3);

selectButtonGroup.add(sbutton4);

}

public void enableZoomButtons()

{

nbutton1.setEnabled(true);

nbutton2.setEnabled(true);

nbutton3.setEnabled(true);

enableSelectButtons();

Page 55: Grey Hole Document

55

}

public void disableZoomButtons()

{

nbutton1.setEnabled(false);

nbutton2.setEnabled(false);

nbutton3.setEnabled(false);

disableSelectButtons();

}

public void disableSelectButtons()

{

sbutton1.setEnabled(false);

sbutton2.setEnabled(false);

sbutton3.setEnabled(false);

sbutton4.setEnabled(false);

}

public void enableSelectButtons()

{

sbutton1.setEnabled(true);

sbutton2.setEnabled(true);

sbutton3.setEnabled(true);

sbutton4.setEnabled(true);

}

public void mouseClicked(MouseEvent e) {}

public void mouseMoved(MouseEvent event) {}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

Page 56: Grey Hole Document

56

public void mouseDragged(MouseEvent e)

{

mouseX = e.getX()-XDISP;

mouseY = e.getY()-YDISP;

if (mouseX > WIDTHSIM | mouseY > HEIGHTSIM) return;

if (function == MOVENODE) {

nodeProperties np = (nodeProperties) nodeRef.get(new

Integer(movingNode));

np.setLocation(mouseX, mouseY);

}

JC.repaint();

}

public void mousePressed(MouseEvent e)

{

mouseX = e.getX()-XDISP;

mouseY = e.getY()-YDISP;

if (mouseX > WIDTHSIM | mouseY > HEIGHTSIM) return;

if (function == MOVENODE) {

movingNode = searchNode(mouseX, mouseY);

System.out.println("Node selected = " + movingNode);

}

}

public void mouseReleased(MouseEvent e)

{

int addr = 0;

nodeProperties p;

Page 57: Grey Hole Document

57

mouseX = e.getX()-XDISP;

mouseY = e.getY()-YDISP;

if (mouseX > WIDTHSIM | mouseY > HEIGHTSIM) return;

switch (function) {

case ADDNODE:

System.out.println(mouseX + " " + mouseY);

addNode(mouseX, mouseY);

break;

case SELECT:

break;

case SHOWTABLE:

addr = searchNode(mouseX, mouseY);

if (addr == -1) break;

Node thisNode = mySched.getNode(addr);

JFrame rtWindow = new tableWindow(thisNode);

rtWindow.pack();

rtWindow.setVisible(true);

break;

case DELETE:

deleteNode(mouseX, mouseY);

break;

case SENDER:

setSender(mouseX, mouseY);

break;

case DESTINATION:

setDest(mouseX, mouseY);

break;

Page 58: Grey Hole Document

58

default:

break;

}

JC.repaint();

}

void setSender(int mouseX, int mouseY)

{

nodeProperties p;

int addr = searchNode(mouseX, mouseY);

if (previousSender != -1) {

p = (nodeProperties) nodeRef.get(new Integer(previousSender));

p.sendSwitch();

}

if (previousSender != addr) {

p = (nodeProperties) nodeRef.get(new Integer(addr));

p.sendSwitch();

if (p.getSendFlag()) {

GUIsender = p;

}

previousSender = addr;

} else {

GUIsender = null;

Page 59: Grey Hole Document

59

previousSender = -1;

}

}

void setDest (int mouseX, int mouseY)

{

nodeProperties p;

int addr = searchNode(mouseX, mouseY);

if (previousDest != -1) {

p = (nodeProperties) nodeRef.get(new Integer(previousDest));

p.destSwitch();

}

if (addr != previousDest) {

p = (nodeProperties) nodeRef.get(new Integer(addr));

p.destSwitch();

if (p.getDestFlag()) {

GUIdestination = p;

}

previousDest = addr;

} else {

GUIdestination = null;

previousDest = -1;

}

}

public void addNode(int mouseX, int mouseY)

{

try {

Page 60: Grey Hole Document

60

Node newNode = new Node(++nodeNum, new

RealPoint((double)mouseX/2, (double)mouseY/2), mySched);

nodeProperties p = new nodeProperties(newNode, mouseX, mouseY, 0);

//nodeCentre.addElement(p);

nodeRef.put(new Integer(newNode.getAddr()), p);

JC.repaint();

} catch (InvalidProtocolException e) {

e.printStackTrace();

}

}

public void clear ()

{

mySched.reset();

nodeProperties p;

/*

if (previousSender != -1) {

p = (nodeProperties) nodeCentre.elementAt(previousSender);

p.sendSwitch();

}

if (previousDest != -1) {

p = (nodeProperties) nodeCentre.elementAt(previousDest);

p.destSwitch();

}

*/

previousDest = -1;

previousSender = -1;

Page 61: Grey Hole Document

61

nodeRef.clear();

nodeNum = 0;

GUIsender = null;

GUIdestination = null;

function = SELECT;

JC.repaint();

}

public void deleteNode(int mouseX, int mouseY)

{

int addr = searchNode(mouseX, mouseY);

if (previousDest == addr) previousDest = -1;

if (previousSender == addr) previousSender = -1;

nodeRef.remove(new Integer(addr));

mySched.removeNode(addr);

JC.repaint();

}

public void packetSent(Node node, Packet pkt)

{

activeSender = (nodeProperties) nodeRef.get(new Integer(node.getAddr()));

if (activeSender == null) return;

activeSender.stopSend();

if (pkt instanceof SBQPacket) {

SBQPacket p = (SBQPacket) pkt;

if (p.getPacketType() != SBQPacket.DATA) return;

}

int numberOfMillisecondsInTheFuture = 500;

Page 62: Grey Hole Document

62

Date timeToRun = new

Date(System.currentTimeMillis()+numberOfMillisecondsInTheFuture);

nodeTimer = new java.util.Timer();

nodeTimer.schedule(new TimerTask() {

public void run() {

activeSender.stopSend();

JC.repaint();

}

}, timeToRun);

activeSender.sendNow();

JC.repaint();

return;

}

public void windowClosing(WindowEvent event)

{

dispose();

System.exit(0);

}

public void windowClosed(WindowEvent event){}

public void windowDeiconified(WindowEvent event){}

public void windowIconified(WindowEvent event){}

public void windowActivated(WindowEvent event){}

public void windowDeactivated(WindowEvent event){}

public void windowOpened(WindowEvent event){}

public static void main(String [] args)

{

GUIDemo demo = new GUIDemo(args);

Page 63: Grey Hole Document

63

demo.run();

}

}

class tableWindow extends JFrame

{

java.util.Timer timer;

JPanel pane1 = new JPanel();

JTextArea ta;

Node thisNode;

public tableWindow(Node node) {

super();

thisNode = node;

timer = new java.util.Timer();

int delay = 1000; // delay for 5 sec.

int period = 1000; // repeat every sec.

setTitle("Node "+thisNode.getAddr());

String t = getRTtable();

ta = new JTextArea(t);

pane1.add(ta);

setContentPane(pane1);

pack();

timer.scheduleAtFixedRate(new TimerTask()

{

public void run()

{

String routeStr = getRTtable();

ta.setText(routeStr);

Page 64: Grey Hole Document

64

pack();

}

}, delay, period);

}

public String getRTtable() {

return thisNode.getProtocol().toString();

}

}

class nodeProperties {

public Point loc;

public int state;

public boolean sendFlag;

public boolean sendNow;

public boolean destFlag;

public boolean attacknode;

private boolean live;

private Node myNode;

boolean AttackNode;

public nodeProperties(Node node, int mouseX, int mouseY, int s)

{

loc = new Point();

loc.x = mouseX;

loc.y = mouseY;

live = true;

sendFlag = false;

sendNow = false;

destFlag = false;

Page 65: Grey Hole Document

65

attacknode=false;

state = s;

myNode = node;

// attackflag=false;

}

public void setNode(Node node)

{

myNode = node;

}

public Node getNode()

{

return myNode;

}

public void attacknode()

{

attacknode=true;

}

public int getZ()

{

return(int) myNode.getLocation().getX()*2;

}

public int getW()

{

return(int) myNode.getLocation().getY()*2;

}

public int getX()

Page 66: Grey Hole Document

66

{

return (int) myNode.getLocation().getX()*2;

}

public int getY()

{

return (int) myNode.getLocation().getY()*2;

}

public void setLocation(int xpos, int ypos)

{

myNode.setLocation( (int) xpos/2, (int) ypos/2);

}

public void setDesiredLocation(int xpos, int ypos)

{

myNode.setDesiredLocation( (int) xpos/2, (int) ypos/2);

loc.x = xpos;

loc.y = ypos;

}

public boolean getSendFlag()

{

return sendFlag;

}

/*public boolean getAttackFlag()

{

return attackflag;

}*/

Page 67: Grey Hole Document

67

public boolean getDestFlag()

{

return destFlag;

}

public void printNode()

{

System.out.println("heelo");

System.out.println(myNode.getAddr());

}

public void sendSwitch()

{

sendFlag = !sendFlag;

}

public void destSwitch()

{

destFlag = !destFlag;

}

public void deleteNode()

{

destFlag = false;

sendFlag = false;

live = false;

}

public boolean isAlive()

{

return live;

}

Page 68: Grey Hole Document

68

public void sendNow()

{

sendNow = true;

}

public void stopSend()

{

sendNow = false;

}

}

class JCanvas extends JComponent implements GUIKonstants {

Hashtable nodeRef;

double scale;

public JCanvas(Hashtable nR, int xDisp, int yDisp)

{

setDoubleBuffered(true);

setLocation(xDisp,yDisp);

nodeRef = nR;

setOpaque(true);

scale = 1;

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

g.setColor(Color.white);

g.fillRect(0,0,getWidth(),getHeight());

}

Page 69: Grey Hole Document

69

public void drawGrid(Graphics g)

{

double s;

int i, j;

s = scale;

for (i = 0; i < getWidth(); i = i + (int) Math.floor(50*s)) {

g.setColor(Color.green);

g.drawLine(i, 0, i, 10);

g.setColor(Color.darkGray);

g.drawLine(i, 11, i, getHeight());

}

for (j = 0; j < getHeight(); j = j + (int) Math.floor(50*s)) {

g.setColor(Color.green);

g.drawLine(0, j, 10, j);

g.setColor(Color.darkGray);

g.drawLine(11, j, getWidth(), j);

}

}

public void paint (Graphics g)

{

int i;

double s = scale;

int r = (int) Math.floor(10*s);

g.setColor(Color.black);

g.fillRect(0,0,getWidth(),getHeight());

g.setColor(Color.red);

Page 70: Grey Hole Document

70

drawGrid(g);

String node = "";

Iterator itr = nodeRef.values().iterator();

while (itr.hasNext()) {

nodeProperties p = (nodeProperties) itr.next();

String nodeString = "" + p.getNode().getAddr();

g.setColor(Color.white);

g.drawString(nodeString, p.getX()+10, p.getY());

int radius = (int) Math.floor(50*s);

if(p.attacknode)

{

g.setColor(Color.green);

g.drawOval(p.getZ()-radius/2,p.getW()-radius/2,radius,radius);

//g.drawOval(p.getX()-r/2,p.getY()-r/2,r,r);

break;

// g.setColor(Color.gray);

}

if (p.sendFlag) {

g.setColor(Color.white);

g.drawString("Sender", p.getX()+10, p.getY()+10);

// g.setColor(Color.red);

}

if (p.sendNow) {

g.setColor(Color.white);

g.drawOval(p.getX()-radius/2,p.getY()-radius/2,radius,radius);

// g.setColor(Color.red);

Page 71: Grey Hole Document

71

}

if (p.destFlag) {

g.setColor(Color.white);

g.drawString("Dest", p.getX()+10, p.getY()+10);

// g.setColor(Color.red);

}

/* p.attackflag=true;

if (p.attackflag) {

g.setColor(Color.GRAY);

g.drawOval(p.getX()-radius/2,p.getY()-radius/2,radius,radius);

}*/

g.setColor(Color.red);

g.fillOval(p.getX()-r/2,p.getY()-r/2,r,r);

}

}

public void xoomOut(int x, int y) { }

public void xoomIn(int x, int y) { }

public void update(Graphics screen)

{

paint(screen);

}

// Most layout managers need this information

public Dimension getPreferredSize() {

return new Dimension(WIDTHSIM,HEIGHTSIM);

}

public Dimension getMinimumSize() {

return getPreferredSize();

Page 72: Grey Hole Document

72

}

public Dimension getMaximumSize() {

return getPreferredSize();

}

}

Node.java

import java.io.*;

import java.util.*;

import java.lang.Math;

import java.awt.*;

import java.awt.event.*;

class Node {

public static final int MAX_RECV_BUFFER_SIZE = 256;

public static final int MAX_SEND_BUFFER_SIZE = 256;

public static int nodecount = 0;

public static Protocol default_protocol;

private int addr;

private RealPoint location;

private LinkedList sendBuffer, recvBuffer;

private Protocol protocol;

private Scheduler sched;

private boolean enabled = true;

// For movements

private RealPoint desired_location;

private double velocity;

private double heading;

Page 73: Grey Hole Document

73

private static double max_velocity = 50;

msgDialog mDialog;

private double time_step;

private double last_time_step;

// Before any nodes are created, you must run this

// static method to set the default protocol

public static void setProtocol( Protocol _defProtocol)

{

default_protocol = _defProtocol;

}

public Protocol getProtocol()

{

return protocol;

}

public Node(int _addr, RealPoint _location, Scheduler _scheduler) throws

InvalidProtocolException

{

addr = _addr;

location = _location;

sched = _scheduler;

enabled = true;

recvBuffer = new LinkedList();

sendBuffer = new LinkedList();

velocity = 0;

heading = 0;

Page 74: Grey Hole Document

74

desired_location = new RealPoint(location.getX(), location.getY() );

// get a new instance of the default protocol;

protocol = default_protocol.getInstance();

protocol.setNode(this);

protocol.setScheduler(sched);

sched.addNode(this);

mDialog = new msgDialog("Node "+addr, "Initialized...");

mDialog.setSize(300, 180);

mDialog.setVisible(false);

}

public Node(RealPoint _location, Scheduler _scheduler ) throws

InvalidProtocolException

{

this(nodecount++, _location, _scheduler);

}

public void setVisible(boolean vis)

{

mDialog.setVisible(vis);

}

public int getAddr() { return addr; }

public synchronized RealPoint getLocation() { return location; }

public synchronized void setLocation(double x, double y)

{

location.setX(x);

location.setY(y);

desired_location.setX(x);

desired_location.setY(y);

Page 75: Grey Hole Document

75

}

public synchronized boolean enable()

{

boolean oldval = enabled;

enabled = true;

return oldval;

}

public synchronized boolean disable()

{

boolean oldval = enabled;

enabled = false;

return oldval;

}

public synchronized boolean enabled() { return enabled; }

public synchronized boolean send(int dest_addr, int len, Object dataObj)

{

if (sendBuffer.size() >= MAX_SEND_BUFFER_SIZE)

return false;

Packet pkt = protocol.createPacket(dest_addr, len, dataObj);

return sendBuffer.add(pkt);

}

public synchronized boolean recv(Packet pkt)

{

if (recvBuffer.size() >= MAX_RECV_BUFFER_SIZE) return false;

return recvBuffer.add(pkt);

}

private synchronized Packet popSendBuf()

Page 76: Grey Hole Document

76

{

Packet p = (Packet) sendBuffer.removeFirst();

//System.out.println(" from buffer: "+p.toString() );

//outText(" from buffer: "+p.toString()+"\n" );

return p;

}

private synchronized Packet popRecvBuf()

{

Packet p = (Packet) recvBuffer.removeFirst();

//System.out.println(" from buffer: "+p.toString() );

//outText(" from buffer: "+p.toString()+"\n" );

return p;

}

public synchronized void run(double curr_time)

{

// Only run when we are enabled

if (!enabled()) return;

//System.out.println("Node "+addr+":");

if (!sendBuffer.isEmpty()) {

Packet p = this.popSendBuf();

Protocol.recv(p);

}

if (!recvBuffer.isEmpty()) {

Packet p = this.popRecvBuf();

protocol.recv(p);

}

last_time_step = time_step;

Page 77: Grey Hole Document

77

protocol.run(time_step = curr_time);

processMovement();

}

public synchronized void outText(String txt)

{

if (mDialog.text.getText().length()>4000)

mDialog.text.setText("");

mDialog.addText(txt);

}

public synchronized String toString()

{

return "Node "+getAddr()+"\n"+protocol.toString();

}

// Methods for movements

public synchronized void setDesiredLocation(double xpos, double ypos)

{

desired_location.setXY(xpos, ypos);

}

public synchronized void processMovement()

{

if (desired_location.nearTo(location)) return;

// 1. find distance and bearing of destination

double bearing = location.getBearing(desired_location);

double distance = location.getDistance(desired_location);

double time_interval = Math.abs(time_step-last_time_step);

heading += 0.2 * RealPoint.normalize_180(bearing - heading);

heading = RealPoint.normalize_180(heading);

Page 78: Grey Hole Document

78

// direct heading (point to point)

// heading = bearing;

// manhattan distance

Math.round(location.getX() / 50);

ym = 100 * Math.round(location.getY() / 50);

if (location.nearTo(xm, location.getY()) ||

desired_location.nearTo(location.getX(), ym)) {

double diff1 = Math.abs(xm - desired_location.getX());

double diff2 = Math.abs(ym - desired_location.getY());

if (diff1 > diff2) {

if (Math.abs(bearing) > 90)

heading = 180;

else

heading = 0;

} else {

if (bearing > 0)

heading = 90;

else

heading = -90;

}

heading = RealPoint.normalize_180( (Math.random() * 4 + 1)* 90);

//heading = (bearing % 90) * 90;

}

//System.out.println("Node "+getAddr()+" xm, ym = "+xm+","+ym+"

heading " + heading);

double ref_velocity = Math.min( max_velocity, velocity + distance/2.0f );

velocity += 0.01 * Math.abs(ref_velocity - velocity);

Page 79: Grey Hole Document

79

double vel_term = velocity * time_interval * 0.001;

double head_term = heading * Math.PI / 180.0;

location.moveBy( vel_term * Math.cos(head_term ),

- vel_term * Math.sin(head_term ));

}

}

class msgDialog extends Frame implements ActionListener,

WindowListener

{

public TextArea text;

private Button closeButton;

msgDialog(String title, String textStr)

{

super(title);

setBackground(SystemColor.control);

setLayout(new BorderLayout());

addWindowListener(this);

closeButton = new Button ("Close");

text = new TextArea(textStr);

Panel p = new Panel();

p.add(closeButton);

add("Center", text);

add("South", p);

text.setEditable(false);

Page 80: Grey Hole Document

80

closeButton.addActionListener(this);

pack();

// centreScreen();

}

public void centreScreen()

{

Toolkit kit = getToolkit();

Dimension dim = kit.getScreenSize();

Dimension win = getSize();

setLocation( (dim.width - win.width)/2, (dim.height - win.width)/2 );

}

public void actionPerformed(ActionEvent event)

{

if (event.getActionCommand().equals("Close")) {

dispose();

}

}

public void addText(String txt)

{

text.append(txt);

repaint();

}

public void windowClosing(WindowEvent event)

{

dispose();

}

Page 81: Grey Hole Document

81

public void windowClosed(WindowEvent event){}

public void windowDeiconified(WindowEvent event){}

public void windowIconified(WindowEvent event){}

public void windowActivated(WindowEvent event){}

public void windowDeactivated(WindowEvent event){}

public void windowOpened(WindowEvent event){}

}

SBQPacket.java

import java.io.*;

import java.util.*;

import java.lang.Math;

import java.text.NumberFormat;

class SBQPacket extends WirelessPacket {

public static final double BeaconSignalThreshold = 0.40;

public static final double ASSR = 0.65; // 50% signal strength

protected static NumberFormat nf = NumberFormat.getPercentInstance();

// Define packet types

public static final int UNDE= 0;

public static final int HDP_ASSOC_REQ = 1;

public static final int HDP_ASSOC_RESP = 2;

public static final int HDP_BEACON = 3;

public static final int HDP_DISASSOC = 4;

public static final int RDP_VALIDATE = 5;

public static final int RDP_INVALIDATE = 6;

public static final int RDP_ROUTE_PROBE = 7;

public static final int DATA = 8;

Page 82: Grey Hole Document

82

private String [] pkt_type = { "UNDEF", "HDP_ASSOC_REQ",

"HDP_ASSOC_RESP",

"HDP_BEACON", "HDP_DISASSOC", "RDP_VALIDATE",

"RDP_INVALIDATE", "RDP_ROUTE_PROBE", "DATA" };

private int type;

private double signal_ASSR;

private HashSet nextHopList; // the destination field

public static SBQPacket makeBeacon(int src_addr)

{

return new SBQPacket(SBQPacket.HDP_BEACON, src_addr, 0, 0, null);

}

public SBQPacket(int src, int dest, int len, Object dataObj)

{

this(SBQPacket.DATA, src, dest, len, dataObj);

}

public SBQPacket(int ptype, int src, int dest, int len, Object dataObj)

{

super(src, dest, len, dataObj);

if (dataObj != null)

System.out.println("Creating new SBQ Packet: "+src+"->"+dest+"

(size:"+len+") ["+dataObj.toString()+"]");

type = ptype;

signal_ASSR = ASSR;

nextHopList = new HashSet();

}

public void setPacketType(int _type)

{

Page 83: Grey Hole Document

83

type = _type;

}

public int getPacketType()

{

return type;

}

public boolean isAboveBeaconSignalThreshold()

{

return getSignalPower() > BeaconSignalThreshold;

}

public Object clone() throws CloneNotSupportedException

{

SBQPacket pkt = (SBQPacket) super.clone();

pkt.setPacketType(type);

pkt.setNextHopList(nextHopList);

return pkt;

}

public String toString()

{

return "Packet "+getSeqNum()+" "+getSrc()+"->"+getDest()+"

("+getSenderAddr()+") via "+nextHopList.toString()+" ("+getLength()+")

"+pkt_type[type]+" ["+getData().toString()+"] SIG

"+nf.format(getSignalPower());

}

public void resetNextHopList()

{

Page 84: Grey Hole Document

84

nextHopList.clear();

}

public boolean isNextHopDest(int addr)

{

return nextHopList.contains(new Integer(addr));

}

public void removeNextHopDest(int addr)

{

nextHopList.remove(new Integer(addr));

}

public void removeNextHopDest(Collection c)

{

if (c == null) return;

for (Iterator itr = c.iterator(); itr.hasNext(); ) {

nextHopList.remove(itr.next());

}

}

public void addNextHopDest(int addr)

{

nextHopList.add(new Integer(addr));

}

public void setNextHopList(Collection c)

{

nextHopList = new HashSet(c);

}

public Collection getNextHopList()

Page 85: Grey Hole Document

85

{

return nextHopList;

}

public void setASSR(double sig_req)

{

signal_ASSR = sig_req;

}

public double getASSR()

{

return signal_ASSR;

}

public boolean isAboveASSR( double sig ) {

return (signal_ASSR < sig);

}

}

class RDPPacket extends SBQPacket {

private int vnode_addr;

private double vnode_sig;

private int vnode_hop_addr;

public RDPPacket(int src, int dest, int len, Object dataObj)

{

super(src, dest, len, dataObj);

}

public RDPPacket(int ptype, int src, int dest, int len, Object dataObj)

{

super(ptype, src, dest, len, dataObj);

Page 86: Grey Hole Document

86

}

public void setVNodeAddr(int vaddr)

{

vnode_addr = vaddr;

}

public int getVNodeAddr()

{

return vnode_addr;

}

public void setVNodeHopAddr(int haddr)

{

vnode_hop_addr = haddr;

}

public int getVNodeHopAddr()

{

return vnode_hop_addr;

}

public void setVNodeSignal(double sig)

{

vnode_sig = sig;

}

public double getVNodeSignal()

{

return vnode_sig;

}

}

Page 87: Grey Hole Document

87

9.2 SCREEN SHOTS

Simulation Window

Page 88: Grey Hole Document

88

Placing nodes to the simulation

Page 89: Grey Hole Document

89

Setting up source and destination

Page 90: Grey Hole Document

90

Sending packets

Page 91: Grey Hole Document

91

Showing attack

Page 92: Grey Hole Document

92

Notification message on showing attack

Page 93: Grey Hole Document

93

Displaying routing table

Page 94: Grey Hole Document

94

CHAPTER 10

REFERENCES

TEXT BOOKS

[1] S. Bhargava, D. P. Agrawal, “Security Enhancements in AODV protocol

for Wireless Ad hoc Networks”, in IEEE Semi-annual Proceedings of

Vehicular Technology Conference (VCT’01), 2001.

[2] H. Deng, W. Li and D. P. Agarwal, “Routing Security in Wireless Ad

Hoc Networks”. University of Cincinnati, IEEE Communication Magazine,

October 2002.

[3] D. E. Denning, “An Intrusion Detection Model”, IEEE Transactions in

Software Engineering, Vol. 13, No2, February1987.

[4] Electronic Publication: Digital Object Identifiers (DOIs): Article in a

journal.

[5] K. Elissa, “Title of paper if known,” unpublished.[17] R. Nicole, “Title

of paper with only first word capitalized,” J.Name Stand. Abbrev., in press.

[6] K Fall and K. Varadhan, ‘The NS Manual”, November 18, 2005,

http://www.isi.edu/nsnam/ns/doc/ns_doc.pdf, 25 July2005

WEB REFERENCES

1. http://msdn.microsoft.com

2. http://www.javanetheaven.com

3. http://www.codeproject.com

4. http://www.programmersheaven.com