-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgenerateTraffic.m
68 lines (58 loc) · 2.44 KB
/
generateTraffic.m
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
function stats = generateTraffic(packets,movement)
% Check args
if(nargin == 1)
movement = 50;
elseif(nargin ~=2)
return
end
% Bring globals into scope
global nodes colors showRoutesBtn distance;
% Initialize variables
numNodes = numel(nodes);
stats.transmissions.RREPL = zeros(1,packets+1);
stats.transmissions.RREQ = zeros(1,packets+1);
stats.transmissions.RERR = zeros(1,packets+1);
stats.transmissions.Data = zeros(1,packets+1);
propDelay = zeros(1,packets);
for i = 1:packets
if(mod(i,movement) == 0)
move(true);
end
% Choose source and destination
src = ceil(rand * numNodes);
dest = ceil(rand * numNodes);
while(src == dest)
dest = ceil(rand * numNodes);
end
% Send
paths = sendPacket(src,dest,true);
idx = find(paths.Node==paths.From & paths.Color ~= colors.RERR);
paths(idx,:) = [];
% Parse table of path utilized
stats.transmissions.RREPL(i+1) = stats.transmissions.RREPL(i) + numel(find(paths.Color==colors.RREPL));
stats.transmissions.RREQ(i+1) = stats.transmissions.RREQ(i) + numel(find(paths.Color==colors.RREQ));
stats.transmissions.RERR(i+1) = stats.transmissions.RERR(i) + numel(find(paths.Color==colors.RERR));
stats.transmissions.Data(i+1) = stats.transmissions.Data(i) + numel(find(paths.Color==colors.Data));
% Calculate propagation delay
dist = 0;
for path = find(paths.Color==colors.Data)'
dist = dist + sqrt((nodes(paths(path,:).Node).x - nodes(paths(path,:).From).x)^2 ...
+ (nodes(paths(path,:).Node).y - nodes(paths(path,:).Node).y)^2);
end
for depth = 1:max(paths.Depth)
distTemp = 0;
for path = find(paths.Color~=colors.Data)'
distTemp = [distTemp,sqrt((nodes(paths(path,:).Node).x - nodes(paths(path,:).From).x)^2 ...
+ (nodes(paths(path,:).Node).y - nodes(paths(path,:).Node).y)^2)];
end
dist = dist + max(distTemp);
end
stats.propDelay(i) = dist / (3*10^8);
stats.hops(i) = numel(find(paths.Node ~= paths.From));
end
% Update all the GUIs
updateTableData();
updateGraphView()
calcConnections(distance,showRoutesBtn.Value);
updateSeqNums()
end