forked from MattWoelk/DirectedDiffusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.java
131 lines (112 loc) · 3.55 KB
/
Node.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.util.ArrayList;
import java.sql.Date;
public class Node
{
int nodeID, xCoord, yCoord, radioRange, numNodes, neighborSize;
ArrayList<Node> allNodes = new ArrayList<Node>();
ArrayList<Node> myNeighbors = new ArrayList<Node>();
EDReceive eRecv = new EDReceive();
PacketTransmitter pktTrans = new PacketTransmitter();
PacketReceiver pktRecv = new PacketReceiver();
RnFDataSend rnfSend = new RnFDataSend(10110, this);
ArrayList<ExpDataSend> expSends = new ArrayList<ExpDataSend>();
ArrayList<Gradient> gradients = new ArrayList<Gradient>();
boolean TESTING = false;
public Node(int nodeID, int xCoord, int yCoord, int radioRange, int numNodes)
{
this.nodeID = nodeID;
this.xCoord = xCoord;
this.yCoord = yCoord;
this.radioRange = radioRange;
this.numNodes = numNodes;
if(TESTING)System.out.print("Node: "+nodeID+" has been created: ("+this.xCoord+","+this.yCoord+")\n");
//System.out.print("numNodes = "+this.numNodes);
}
public int getID()
{
return this.nodeID;
}
public int getXCoord()
{
return this.xCoord;
}
public int getYCoord()
{
return this.yCoord;
}
public void setAllNodes(ArrayList<Node> allNodes)
{
this.allNodes = allNodes;
}
public void findNeighbors()
{
//System.out.println("numNodes: " + numNodes);
for(int i=0; i<numNodes; i++)
{
if(this.xCoord != allNodes.get(i).xCoord || this.yCoord != allNodes.get(i).yCoord)
{
int xDiff = Math.abs(allNodes.get(i).xCoord - this.xCoord);
int yDiff = Math.abs(allNodes.get(i).yCoord - this.yCoord);
//System.out.print("xDiff = "+xDiff+"\n");
if(xDiff <= radioRange && yDiff <= radioRange)
{
myNeighbors.add(allNodes.get(i));
//System.out.print("Found Neighbor: "+ allNodes.get(i).xCoord+","+allNodes.get(i).yCoord+ ")\n");
}
}
}
int neighborSize = myNeighbors.size();
if(neighborSize==0)
{
if(TESTING)System.out.print("Neighbor size = "+neighborSize+" Exit now.\n");
if(TESTING)System.exit(0);
}else{
if(TESTING)System.out.print("Neighbor size = "+neighborSize+"\n");
}
if(TESTING)System.out.print("Neigbors of Node ("+ xCoord+","+yCoord+ "):\n");
for(int i=0; i<neighborSize; i++)
{
if(TESTING)System.out.print("\t("+ myNeighbors.get(i).getXCoord()+","+myNeighbors.get(i).getYCoord()+ ")\n");
}
pktTrans.setNeighbors(myNeighbors);
}
public boolean processNode()
{
if(TESTING)System.out.print("Node = "+this.nodeID+" is processing its node"+"\n");
return false; //or true depending on if processing was successful
}
public void broadcastInterestMessage(Interest intr)
{
//just some values for now TODO: change them to make sense.
char packetType = 'a';
String senderID = "senderIDtest";
double seqNumber = 1337;
Date interval = new Date(1337);
Packet pkt = new Packet(packetType, senderID, seqNumber, interval);
//TODO: build broad interest message to be sent to PacketTransmitter
// PTrans.addPacket(pkt);
}
public ArrayList<Node> getNeighbours()
{
return myNeighbors;
}
public void receivePacket(Packet pkt)
{
pktRecv.receivePacket(pkt);
}
public Packet lastReceivedPacketTest()
{
return pktRecv.getPacket();
}
public void run()
{
eRecv.run();
pktTrans.run();
pktRecv.run();
rnfSend.run();
for (ExpDataSend e : expSends)
{
e.run();
}
}
}