forked from ameycu/Wormhole-Detection-in-WSN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.py
59 lines (45 loc) · 1.43 KB
/
Node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import random as r
import math as m
from Location import *
# CONSTANTS
RANGE = 100 # Range over which nodes will be distributed
NORMAL_NODE_RANGE = 5
ATTACKER_NODE_RANGE = 10
BASE_STATION_RANGE = 5
field = Field()
class node():
def __init__(self, name):
self.name = name
self.loc = Location(r.randrange(-RANGE,RANGE+1),r.randrange(-RANGE,RANGE+1))
field.addNode(self, self.loc)
def getLinks(self):
return self.links
def getLinksnames(self):
Links_names = []
for link in self.links:
Links_names.append(link.name)
Links_names.sort()
return Links_names
def __str__(self):
return self.name
class normalnode(node):
def __init__(self, name):
self.rang = NORMAL_NODE_RANGE
node.__init__(self, name)
class attackernode(node):
def __init__(self, name):
self.rang = ATTACKER_NODE_RANGE
node.__init__(self, name)
class basestation(node):
def __init__(self):
self.name = 'Base'
self.rang = BASE_STATION_RANGE
self.loc = Location(0,0)
field.addNode(self, self.loc)
def setLinks():
for node1 in field.nodes.keys():
node1.links=[]
for node in field.nodes.keys():
distance = node1.loc.distFrom(field.nodes[node])
if ((distance != 0)and(distance < max(node1.rang,node.rang))):
node1.links.append(node)