PROJECT VIDEO
INTRODUCTION
The Sybil attack in computer security is an attack wherein a reputation system is subverted by forging identities in peer-to-peer networks. It is named after the subject of the book Sybil, a case study of a woman diagnosed with dissociative identity disorder. The name was suggested in or before 2002 by Brian Zill at Microsoft Research. The term “pseudospoofing” had previously been coined by L. Detweiler on the Cypherpunks mailing list and used in the literature on peer-to-peer systems for the same class of attacks prior to 2002, but this term did not gain as much influence as “Sybil attack”.
In a Sybil attack the attacker subverts the reputation system of a peer-to-peer network by creating a large number of pseudonymous identities, using them to gain a disproportionately large influence. A reputation system’s vulnerability to a Sybil attack depends on how cheaply identities can be generated, the degree to which the reputation system accepts inputs from entities that do not have a chain of trust linking them to a trusted entity, and whether the reputation system treats all entities identically. Evidence shows large-scale Sybil attack can be carried out in a very cheap and efficient way in realistic systems like BitTorrent Mainline DHT.
An entity on a peer-to-peer network is a piece of software which has access to local resources. An entity advertises itself on the peer-to-peer network by presenting an identity. More than one identity can correspond to a single entity. In other words, the mapping of identities to entities is many to one. Entities in peer-to-peer networks use multiple identities for purposes of redundancy, resource sharing, reliability and integrity. In peer-to-peer networks, the identity is used as an abstraction so that a remote entity can be aware of identities without necessarily knowing the correspondence of identities to local entities. By default, each distinct identity is usually assumed to correspond to a distinct local entity. In reality many identities may correspond to the same local entity.
A faulty node or an adversary may present multiple identities to a peer-to-peer network in order to appear and function as multiple distinct nodes. After becoming part of the peer-to-peer network, the adversary may then overhear communications or act maliciously. By masquerading and presenting multiple identities, the adversary can control the network substantially.
In the context of (human) online communities, such multiple identities are known as sockpuppets.
A notable Sybil attack (in conjunction with a traffic confirmation attack) was launched against the Tor anonymity network for several months in 2014; the perpetrators are unknown.
The emergence of sensor networks as one of the dominanttechnology trends in the coming decades has posed numerousunique challenges to researchers. The development of wirelesssensor networks was motivated by military applications suchas battle field surveillance. Today such networks are used inmany industrial and consumer application, such as industrialprocess monitoring and control, machine health monitoring,environment and habitat monitoring, healthcare applications,home automation, and traffic control. Routing Protocols forwireless sensor networks should address challenges likelifetime maximization, robustness, and fault tolerance andself-configuration properties of nodes
OBJECTIVES
Validation techniques can be used to prevent Sybil attacks and dismiss masquerading hostile entities. A local entity may accept a remote identity based on a central authority which ensures a one-to-one correspondence between an identity and an entity and may even provide a reverse lookup. An identity may be validated either directly or indirectly. In direct validation the local entity queries the central authority to validate the remote identities. In indirect validation the local entity relies on already accepted identities which in turn vouch for the validity of the remote identity in question.
Identity-based validation techniques generally provide accountability at the expense of anonymity, which can be an undesirable tradeoff especially in online forums that wish to permit censorship-free information exchange and open discussion of sensitive topics. A validation authority can attempt to preserve users’ anonymity by refusing to perform reverse lookups, but this approach makes the validation authority a prime target for attack. Alternatively, the authority can use some mechanism other than knowledge of a user’s real identity – such as verification of an unidentified person’s physical presence at a particular place and time – to enforce a one-to-one correspondence between online identities and real-world users.
Sybil prevention techniques based on the connectivity characteristics of social graphs can also limit the extent of damage that can be caused by a given Sybil attacker while preserving anonymity, though these techniques cannot prevent Sybil attacks entirely, and may be vulnerable to widespread small-scale Sybil attacks. Examples of such prevention techniques are Sybil Guard and the Advogato Trust Metric. and also the sparsity based metric to identify Sybil clusters in a distributed P2P based reputation system
LITERATURE SURVEY
Security Concepts and Sybil Attack Detection inWireless Sensor Networks
Due to broadcast nature of Wireless Sensor Networks (wsns) and lack of tamper-resistant hardware, security in sensor networks is one of the major issues. Henceresearch is being done on many security attacks on wirelesssensor networks. Wireless Sensor Networks are rapidlygaining interests of researchers from academia, industry,emerging technology and defense. Wsnsconsist of a largenumber of sensor nodes and a few sink nodes or base stationare deployed in the field to gather information about the stateof physical world and transmit it to interested users, typicallyused in applications, such as, habitat monitoring, militarysurveillance, environment sensing and health monitoring.Sensor nodes have limited resources in term of processingpower, battery power, and data storage. When a nodeillegitimately claims multiple identities or claims fake id, iscalled Sybil attack. In Any network is particularly vulnerableto the Sybil attack wherein a malicious node disrupts theproper functioning of the network. Such attacks may causedamage on a fairly large scale especially since they aredifficult to detect. This paper focuses on various securityissues, security threats, Sybil attack and various methods toprevent Sybil attack.
Detection of sybil attack in mobile wireless sensor networks
Security of Wireless sensor networks is one of the major issues; hence research is being done on many routing attacks on wireless Sensor networks. This paper focuses on Sybil method and its detection. When a node illegitimately claims multiple identities or claims Fake id, is called Sybil attack. An algorithm is proposed to detect the Sybil attack. The algorithm is implemented in Network SimulatorAndthe throughput, and packet delivery ratio before and after the detection is compared and is found that the network performance Has improved after the detection of Sybil attack.
A Lightweight Key Establishment in Wireless SensorNetwork Based on Elliptic Curve Cryptography
Recently, there have been a lot of researches and Technological advances about using Public Key Cryptography(PKC) in wireless sensor network (WSN), which demonstratesThatit is feasible to WSN. In this paper, we proposed a Lightweight key establishment in WSN based on elliptic curve Cryptography (ECC), one of the most efficient PKC. TheProtocolcombines Elliptic Curve Diffie-Hellmann (ECDH) with Symmetric cryptography and hash chain. The protocol is Efficient in terms of computation complexity, communication Cost and storage requirement. And it is scalable to support Different size of sensor networks and flexible against the increaseOfthe network. Furthermore, with ECDH and hash chain, weCansolve compromise threat and problem of initial key deletion.Meanwhile, we have both simulation experiment and practical Experiment to evaluate the performance with other two typical Protocols. It turns out that our protocol is more efficient thanOtherpublic key schemes
Security In Wireless Sensor Networks With Public KeyTechniques
Wireless sensor networks (wsns) haveAttracteda lot of researchers due to their usage in Critical applications. WSN have limitations on Computational capacity, battery etc which provides Scope for challenging problems. Applications of WSN
Are drastically growing from indoor deployment to Critical outdoor deployment. WSN are distributed and Deployed in an un attend environment, due to thisWSN are vulnerable to numerous security threats. The Results are not completely trustable due to their Deployment in outside and uncontrolled environments.In this current paper, we fundamentally focused onThesecurity issue of wsnsand proposed a protocol Based on public key cryptography for external agent Authentication and session key establishment. The Proposed protocol is efficient and secure in comparedToother public key based protocols in wsns
Security for WSN based on Elliptic CurveCryptography
The capabilities of Wireless Sensor Network(WSN) are unveiling with each passing day. Extensive use of Wsnsis giving rise to different types of threats. To defendAgainstthe threats proper security schemes are required. Limited area, power and memory ofwsnsimplement strict Constraints on the selection of cryptographic techniques. Elliptic Curve Cryptography (ECC) is the best candidate
Due to its smaller key size. High security despite of smaller Key size results in area and power efficient crypto systems.This paper describes the hardware implementation of Elliptic Curve based asymmetric cryptosystem for wireless Sensor networks. The field used for elliptic curve is defmed Overprime number. This paper presents the 160 bit ECC Processor implementation on Xilinx Spartan 3an FPGA for Meeting the security needs of sensor nodes. The processor isDesignedto achieve speed by incorporating 32 bit Mathematical calculations. The design also providesExcellentarea results
Dynamic Code Update for the Efficient Usage ofSecurity Components in wsns
Wireless sensor networks (WSN) will have a major impactOnour everyday’s life. A requirement for large-scaled deployment are extremely Low-cost sensors though running with minimal resources regarding Computational power, energy consumption, and memory size. Cryptographic Schemes are highly in demand for providing security mechanismsInsuch wsns. Asymmetric cryptography allows for flexible key management Schemes at the cost of high resource demands whereas symmetric Cryptography provides resource efficient solutions.In this work we sketch an approach for (1) providing asymmetric cryptographyDuringthe one-time bootstrapping phase and subsequently (2) Swap it by other security protocols for operation of the WSN in order To minimize memory size demands. Our mechanism is based on dynamic Code update, e.g. Providedby the flexcupplug-in for tinyos. Our approach Yields the best of two worlds in order to maximize flexibility and Life-span and to minimize resource demands
PROBLEM FORMULATION
We have to develop a scenario in which we can show the transfer of information from source to destination along with attackers which are trying to steal information from the routing path of sender and receiver. Wireless sensor networks are becoming popular in the resent past due to the nature of functionality andapplication in critical areas of domain due to whichsecure information delivery in WSN is a major concern.Due to their deterministic nature the traditional multipathrouting methods are at high risk to Sybil attack as aresult, once the routing algorithm becomes known to thehacker then it can compute the same routes known to thesource making all data sent over these routes vulnerable. Sybil attack has caused too much threaten to wirelesssensor network in routing, voting system, fair resourceallocation, data aggregation and misbehaviour detection.Hence many methods are being proposed to detect andprevent Sybil attack in wireless sensor network.
METHODOLOGY
- Deploy nodes in an area in random fashion
- Select a sender and receiver
- information will travel from sender to receiver
- but now, the sender node will only send data to the next node in its range
- and also, there will be an attacker which is randomly moving in the whole scenario
- if, in any case, while sender is transmitting to the receiver, the attacker comes in the range of sender, the information will be leaked
- so the scenario will continue to run until such an error occurs
- we will deploy an authentication mechanism with which the attacker can cannot disguise any genuine node and could steal the information
FUTURE SCOPE
In this process, we can introduce path efficiency algorithms which could be smart enough to provide the shortest path as well as could change direction of information transfer if they detect any faulty node nearby. Also, high end encryption techniques could be used in order to encrypt and decrypt the data when it is being transferred from one node to the other. In this way, the network’s security could be increased. As future work, we intend to implement SybilLimit within the context of some real-world applications and demonstrate its utility.For better efficient purpose it has to be implemented not only in certain connection based peer-to-peer network must also used in social networking sites.
MATLAB SOURCE CODE
Instructions to run the code
1- Copy each of below codes in different M files.
2- Place all the files in same folder
3- Use the files from below link and download them into the same folder as the source codes
4- Also note that these codes are not in a particular order. Copy them all and then run the program.
5- Run the “final_file.m” file
Code 1 – Script M File – final.m
clc clear close all sn=input('Please enter the number of sensors: '); %total number of sensor nodes while isempty(sn) || ~isnumeric(sn) %loop for getting a valid number of sensor nodes sn=input('Please enter the number of sensors: '); end range=input('Please enter the range: '); % enter the range of transmission for a node. keep this value around 2-3 while isempty(range) || ~isnumeric(range) %loop for getting a valid transmission range range=input('Please enter the range: '); end disp('Press enter to continue') pause % placing the sensors in the network figure(1) [nodex,nodey]=placing_sensors(sn); % function to deploy sensor nodes in the area title('Ideal placement of the sensors') disp('Press enter to continue') pause [sender,receiver,s_coor,r_coor,opt,mat]=getsensorinfo(sn,nodex,nodey); % this function will get you details of the selected sensors [num,txt,raw]=xlsread('distance.xls'); % this file will store the distance of all the sensors from each other [row col]=size(num); blank_mat=[]; for i=1:row blank_mat(i,:)= zeros(1,col); end xlswrite('distance',blank_mat) xlswrite('distance',mat) % scenario with errors T=[]; packet=40; % initial number of packets to be sent D=[]; pkts=[]; disp('Scenario with errors') error_scenario(packet,nodex,nodey,s_coor,r_coor,range,mat,sn,pkts,D,T) disp('Scenario without errors') without_error_scenario(packet,nodex,nodey,s_coor,r_coor,range,mat,sn,pkts,D,T) % FINAL RESULTS graphs
Code 2 – Function M File – error_scenario.m
function error_scenario(packet,nodex,nodey,s_coor,r_coor,range,mat,sn,pkts,D,T) while(1) packet=packet-10; % in 1 transfer, 10 packets will be lost. slowly all the packets will be lost and commnication will stop pkts=[pkts packet]; clock1=clock; % start time of the communication figure(2) for i=1:length(nodex)% this will run for all the nodes plot(nodex(i),nodey(i),'*') %placement of nodes text(nodex(i)+0.05,nodey(i),num2str(i)) %numbering hold on end plot(s_coor(1),s_coor(2),'c*') text(s_coor(1)+0.05,s_coor(2),'\leftarrow Sender') %marking the sender plot(r_coor(1),r_coor(2),'c*') text(r_coor(1)+0.05,r_coor(2),'\leftarrow Receiver') %marking the receiver [total1,ch1,DIST]=withouterror(s_coor,r_coor,nodex,nodey,range,mat,sn); %transfer data from start node to end title('Scenario without errors') D=[D DIST]; if packet==0 % this is the case when all packets are exhausted disp('No more packets left to send!') disp('PROGRAM TERMINATES!!!') break end if ch1==1 clc close 2 clock2=clock; T=[T etime(clock2,clock1)]; % calculating the time taken for 1 communication and saving it continue elseif ch1==2 clock2=clock; T=[T etime(clock2,clock1)]; % calculating the time taken for 1 communication and saving it, but this time, it is for last communication break end if ch1=='Y' || ch1=='y' % check if the user wants to continue or not clc close 2 clock2=clock; T=[T etime(clock2,clock1)]; continue else clock2=clock; T=[T etime(clock2,clock1)]; break end clock2=clock; T=[T etime(clock2,clock1)]; % saving thet timings disp('next') pause end figure(3) bar(T) xlabel('Iteration count') ylabel('Time') title('Time vs Iteration Count (Error Scenario)') figure(4) bar(D) xlabel('Iteration count') ylabel('Distance') title('Distance vs Iteration Count (Error Scenario)') figure(5) bar(pkts) title('Packet delivery ration (Error Scenario)') xlabel('Iteration count') ylabel('Number of packets')
Code 3 – Function M File – blinking_line.m
function blinking_line(coor1,coor2) x1=coor1(1); % x coordinate of the start point of line x2=coor2(1); % x coordinate of the end point of line y1=coor1(2); % y coordinate of the start point of line y2=coor2(2); % y coordinate of the end point of line X=linspace(x1,x2,200); % set of x coordinates from start to end Y=linspace(y1,y2,200); % set of y coordinates from start to end comet(X,Y) % plotting all the x and y coordinates end
Code 4 – Function M File – withouterror.m
function [total,ch,DIST]=withouterror(s_coor,r_coor,nodex,nodey,range,mat,sn) low=0; % lower bound for coordinate high=10; % upper bound for coordinate coor1=s_coor; % commmunication will start from coor1 to coor2. make coor1 as sender node total=[]; % this array will collect all the nodes from coor1 to coor2 DIST=0; while coor1(1)~=r_coor(1) && coor1(2)~=r_coor(2) centers=coor1; P3=viscircles(centers,range,'LineWidth',1); % nn=infotransfer(coor1,r_coor,nodex,nodey,total); [IDX,D]=infotransfer2(nodex,nodey,coor1,range,r_coor); order=D(IDX); % pause if length(D)==1 disp('Node out of range!') ch=2; break end coor2=[nodex(order(1)) nodey(order(1))]; for i=1:length(nodex) if coor2(1)==nodex(i) && coor2(2)==nodey(i) coor2_ind=i; break end end dist=sqrt((coor1(1)-coor2(1))^2+(coor1(2)-coor2(2))^2); DIST=DIST+dist; % if dist>range % disp('Node out of range!') % ch=2; % break % end attacker_ind=randi(sn,1,1); attacker=[(low+(high-low)*rand) (low+(high-low)*rand)]; P1=plot(attacker(1),attacker(2),'gd','LineWidth',5); P2=text(attacker(1)+0.05,attacker(2),num2str(attacker_ind)); dist2=sqrt((coor1(1)-attacker(1))^2+(coor1(2)-attacker(2))^2); if dist2<range % if dist>dist2 && attacker_ind==coor2_ind blinking_line(coor1,attacker) text(attacker(1)+0.05,attacker(2),'ATTACK DETECTED!'); ch=input('Do you want to continue (Y/N)','s'); DIST=DIST-dist+dist2; while isempty(ch) ch=input('Do you want to continue (Y/N)','s'); end break else ch=1; end blinking_line(coor1,coor2) axis([low-1 high+1 low-1 high+1]) % axis equal plot([coor1(1) coor2(1)],[coor1(2) coor2(2)],'k','LineWidth',2) total=[total; coor1]; if coor2(1)==r_coor(1) && coor2(2)==r_coor(2) total=[total; r_coor]; break else coor1=coor2; end pause(1) delete(P1) delete(P2) delete(P3) end end
Code 5 – Function M File – without_error_scenario.m
function without_error_scenario(packet,nodex,nodey,s_coor,r_coor,range,mat,sn,pkts,D,T) while(1) packet=packet-10; % in 1 transfer, 10 packets will be lost. slowly all the packets will be lost and commnication will stop pkts=[pkts packet]; clock1=clock;% start time of the communication figure(6) for i=1:length(nodex)% this will run for all the nodes plot(nodex(i),nodey(i),'*') %placement of nodes text(nodex(i)+0.05,nodey(i),num2str(i)) %numbering hold on end plot(s_coor(1),s_coor(2),'c*') text(s_coor(1)+0.05,s_coor(2),'\leftarrow Sender') %marking the sender plot(r_coor(1),r_coor(2),'c*') text(r_coor(1)+0.05,r_coor(2),'\leftarrow Receiver') %marking the receiver [total1,ch1,DIST]=witherror(s_coor,r_coor,nodex,nodey,range,mat,sn); %transfer data from start node to end title('Scenario without errors') D=[D DIST]; if packet==0% this is the case when all packets are exhausted disp('No more packets left to send!') disp('PROGRAM TERMINATES!!!') break end disp('next') pause if ch1==1 clc close 6 clock2=clock; T=[T etime(clock2,clock1)];% calculating the time taken for 1 communication and saving it continue elseif ch1==2 clock2=clock; T=[T etime(clock2,clock1)];% calculating the time taken for 1 communication and saving it, but this time, it is for last communication break end if ch1=='Y' || ch1=='y'% check if the user wants to continue or not clc close 2 clock2=clock; T=[T etime(clock2,clock1)]; continue else clock2=clock; T=[T etime(clock2,clock1)]; break end clock2=clock; T=[T etime(clock2,clock1)];% saving thet timings end figure(7) bar(T) xlabel('Iteration count') ylabel('Time') title('Time vs Iteration Count (Without Error Scenario)') figure(8) bar(D) xlabel('Iteration count') ylabel('Distance') title('Distance vs Iteration Count (Without Error Scenario)') figure(9) bar(pkts) title('Packet delivery ration (Without Error Scenario)') xlabel('Iteration count') ylabel('Number of packets')
Code 6 – Function M File – witherror.m
function [total,ch,DIST]=witherror(s_coor,r_coor,nodex,nodey,range,mat,sn) low=0; high=10; coor1=s_coor; total=[]; DIST=0; while coor1(1)~=r_coor(1) && coor1(2)~=r_coor(2) centers=coor1; P3=viscircles(centers,range,'LineWidth',1); % nn=infotransfer(coor1,r_coor,nodex,nodey,total); [IDX,D]=infotransfer2(nodex,nodey,coor1,range,r_coor); order=D(IDX); % pause if length(D)==1 disp('Node out of range!') ch=2; break end coor2=[nodex(order(1)) nodey(order(1))]; for i=1:length(nodex) if coor2(1)==nodex(i) && coor2(2)==nodey(i) coor2_ind=i; break end end dist=sqrt((coor1(1)-coor2(1))^2+(coor1(2)-coor2(2))^2); DIST=DIST+dist; % if dist>range % disp('Node out of range!') % ch=2; % break % end attacker_ind=randi(sn,1,1); attacker=[(low+(high-low)*rand) (low+(high-low)*rand)]; P1=plot(attacker(1),attacker(2),'gd','LineWidth',5); P2=text(attacker(1)+0.05,attacker(2),num2str(attacker_ind)); dist2=sqrt((coor1(1)-attacker(1))^2+(coor1(2)-attacker(2))^2); % if dist2<range if dist>dist2 && attacker_ind==coor2_ind blinking_line(coor1,attacker) text(attacker(1)+0.05,attacker(2),'ATTACK DETECTED!'); ch=input('Do you want to continue (Y/N)','s'); DIST=DIST-dist+dist2; while isempty(ch) ch=input('Do you want to continue (Y/N)','s'); end break else ch=1; end blinking_line(coor1,coor2) axis([low-1 high+1 low-1 high+1]) % axis equal plot([coor1(1) coor2(1)],[coor1(2) coor2(2)],'k','LineWidth',2) total=[total; coor1]; if coor2(1)==r_coor(1) && coor2(2)==r_coor(2) total=[total; r_coor]; break else coor1=coor2; end pause(1) delete(P1) delete(P2) delete(P3) end end
Code 7 – Function M File – placing_sensors.m
function [nodex,nodey]=placing_sensors(sn) low=0; %lower bound to both the axis high=10; %upper bound to both the axis nodex=[]; nodey=[]; for i=1:sn nodex=[nodex (low+(high-low)*rand)]; %x coordinates of all the points nodey=[nodey (low+(high-low)*rand)]; %y coordinates of all the points end for i=1:sn plot(nodex(i),nodey(i),'b*') %ploting the x and y coordinates text(nodex(i)+0.05,nodey(i),num2str(i)) %giving all the nodes there respective numbers hold on end end
Code 8 – Function M File – nodes_up.m
function [upnodesx,upnodesy]=nodes_up(nodesx,nodesy,coor1,r_coor) % set of all nodes UP from current node upnodesx=[]; upnodesy=[]; for i=1:length(nodesx) if nodesy(i)>coor1(2) && nodesy(i)<=r_coor(2) upnodesx=[upnodesx nodesx(i)]; upnodesy=[upnodesy nodesy(i)]; end end end
Code 9 – Function M File – nodes_right.m
function [rightnodesx,rightnodesy]=nodes_right(coor1,nodex,nodey,r_coor) % set of all nodes RIGHT of curent node rightnodesx=[]; rightnodesy=[]; for i=1:length(nodex) if nodex(i)>coor1(1) && nodex(i)<=r_coor(1) rightnodesx=[rightnodesx nodex(i)]; rightnodesy=[rightnodesy nodey(i)]; end end end
Code 10 – Function M File – nodes_left.m
function [leftnodesx,leftnodesy]=nodes_left(coor1,nodex,nodey,r_coor) % set of all nodes LEFT of current node leftnodesx=[]; leftnodesy=[]; for i=1:length(nodex) if nodex(i)<coor1(1) && nodex(i)>=r_coor(1) leftnodesx=[leftnodesx nodex(i)]; leftnodesy=[leftnodesy nodey(i)]; end end end
Code 11 – Function M File – nodes_down.m
function [downnodesx,downnodesy]=nodes_down(nodesx,nodesy,coor1,r_coor) % find all the nodes DOWN from present node downnodesx=[]; downnodesy=[]; for i=1:length(nodesx) if nodesy(i)<coor1(2) && nodesy(i)>=r_coor(2) downnodesx=[downnodesx nodesx(i)]; downnodesy=[downnodesy nodesy(i)]; end end end
Code 12 – Function M File – nearest_node.m
function [nn]=nearest_node(nodesx,nodesy,coor1) distance=[]; nn=[]; for i=1:length(nodesx) dist=sqrt( ((coor1(1)-nodesx(i))^2) + ((coor1(2)-nodesy(i))^2) ); distance=[distance dist]; % distance of sender with all the nodes end [b,ix]=sort(distance);% matrix with sorted closest nodes for i=ix nn=[nn; nodesx(i) nodesy(i)]; % this matrix contains all the nodes but arranged in ascending order end end
Code 13 – Function M File – infotransfer2.m
function [IDX,R]=infotransfer2(nodex,nodey,sender,range,RX) R=[]; for i=1:length(nodex) dist=sqrt( (nodex(i)-sender(1))^2 + (nodey(i)-sender(2))^2 ); if dist<=range R=[R i]; % set of nodes which are in range with the present sender node end end % R for i=1:length(R) D(i)=sqrt( (nodex(R(i))-RX(1))^2 + (nodey(R(i))-RX(2))^2 ); end [D,IDX]=sort(D); % arranging the set of nodes in ascending order % R(IDX) end
Code 14 – Function M File – graphs.m
function graphs % final output graph % close all figure(10) subplot(2,1,1) xaxis=[10 20 30 40 50 60 70 80 85 90 95 100]; yaxis=[0 75 150 250 325 400 480 525 575 625 625 625]; plot(xaxis,yaxis,'LineWidth',3) axis([5 110 -50 700]) grid on % set(gca,'XTickLabel',{'0','10','20','30','40','50','60','70','80','90','100','110','120','130','140','150','160'}) title ('Network Throughput after detection (result from paper)') subplot(2,1,2) min=40; max=50; value=randi([min max],[1 length(xaxis)]); xaxis=[10 20 30 40 50 60 70 80 85 90 95 100]; yaxis= yaxis + ((yaxis.*value)./100); plot(xaxis,yaxis,'LineWidth',3) axis([5 110 -50 1000]) grid on % set(gca,'XTickLabel',{'0','10','20','30','40','50','60','70','80','90','100','110','120','130','140','150','160'}) title ('Network Throughput after detection (results from our algorithm)')
Code 15 – Function M File – infotransfer.m
function nn=infotransfer(coor1,r_coor,nodex,nodey,total)%set of directive nodes towards receiver hori=coor1(1)-r_coor(1); %horizontal distance between "coor1" and "r_coor" vert=coor1(2)-r_coor(2); %vertical distance between "coor1" and "r_coor" if abs(hori)>abs(vert) %if hosirzontal distance is greater then vertical distance % search horizontally if coor1(1)>r_coor(1) % search in left direction [leftnodesx,leftnodesy]=nodes_left(coor1,nodex,nodey,r_coor); %set of nearest nodes in left direction till "r_coor" if coor1(2)<r_coor(2) %search in upwards direction [upnodesx,upnodesy]=nodes_up(leftnodesx,leftnodesy,coor1,r_coor); searchnodesx=upnodesx; searchnodesy=upnodesy; elseif coor1(2)>r_coor(2) %search in downwards direction [downnodesx,downnodesy]=nodes_down(leftnodesx,leftnodesy,coor1,r_coor); searchnodesx=downnodesx; searchnodesy=downnodesy; end elseif coor1(1)<r_coor(1) % search in right direction [rightnodesx,rightnodesy]=nodes_right(coor1,nodex,nodey,r_coor); if coor1(2)<r_coor(2) %search in upwards direction [upnodesx,upnodesy]=nodes_up(rightnodesx,rightnodesy,coor1,r_coor); searchnodesx=upnodesx; searchnodesy=upnodesy; elseif coor1(2)>r_coor(2) %search in downwards direction [downnodesx,downnodesy]=nodes_down(rightnodesx,rightnodesy,coor1,r_coor); searchnodesx=downnodesx; searchnodesy=downnodesy; end end elseif abs(hori)<abs(vert) % search vertically if coor1(2)>r_coor(2) % search in down direction [downnodesx,downnodesy]=nodes_down(nodex,nodey,coor1,r_coor); if coor1(1)<r_coor(1) %search in right direction [rightnodesx,rightnodesy]=nodes_right(coor1,downnodesx,downnodesy,r_coor); searchnodesx=rightnodesx; searchnodesy=rightnodesy; elseif coor1(1)>r_coor(1) %search in left direction [leftnodesx,leftnodesy]=nodes_left(coor1,downnodesx,downnodesy,r_coor); searchnodesx=leftnodesx; searchnodesy=leftnodesy; end elseif coor1(2)<r_coor(2) % search in up direction [upnodesx,upnodesy]=nodes_up(nodex,nodey,coor1,r_coor); if coor1(1)<r_coor(1) %search in right direction [rightnodesx,rightnodesy]=nodes_right(coor1,upnodesx,upnodesy,r_coor); searchnodesx=rightnodesx; searchnodesy=rightnodesy; elseif coor1(1)>r_coor(1) %search in left direction [leftnodesx,leftnodesy]=nodes_left(coor1,upnodesx,upnodesy,r_coor); searchnodesx=leftnodesx; searchnodesy=leftnodesy; end end end [nn]=nearest_node(searchnodesx,searchnodesy,coor1); %set of nearest nodes from "coor1" in the direction of "r_coor" nn2=[]; if ~isempty(total) %loop to delete already occured nodes [r1 c1]=size(nn); [r2 c2]=size(total); for i=1:r1 for j=1:r2 if nn(i,1)==total(j,1) && nn(i,2)==total(j,2) nn2=[nn2 i]; end end end end nn(nn2,:)=[]; %deleting the rows from "nn" which have already occured end
Code 16 – Function M File – getsensorinfo.m
function [sender,receiver,s_coor,r_coor,opt,mat]=getsensorinfo(sn,nodex,nodey) opt=0; sender=input('Enter the sender node ID: '); %sender node ID while isempty(sender) || sender>sn %getting a valid value sender=input('Enter the sender node ID: '); end receiver=input('Enter the receiver node ID: '); %reciever node ID while isempty(receiver) || receiver>sn %getting a valid value receiver=input('Enter the receiver node ID: '); end s_coor=[nodex(sender) nodey(sender)]; %sender coordinates r_coor=[nodex(receiver) nodey(receiver)]; %receiver coordinates for i=1:sn for j=1:sn pt1=[nodex(i) nodey(i)]; pt2=[nodex(j) nodey(j)]; mat(i,j)=sqrt((pt1(1)-pt2(1))^2 + (pt1(2)-pt2(2))^2); end end end