-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDevice.m
More file actions
245 lines (210 loc) · 7.73 KB
/
Copy pathDevice.m
File metadata and controls
245 lines (210 loc) · 7.73 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
%% the model of the device.
%Written by: Behnaz Arzani
classdef Device
properties
%%properties of a device. its type specifies where in the topology
%%the switch is.
type_=deviceType.Unknown;
%%downstream and upstream neighbor lists.
LowerNeighbors_=[]
UpperNeighbors_=[]
%%the drop rates of its links
NeighborDropRates_={}
%% the index of the pod it belongs to
podIndex_ = 0
%the node index (an identifier for this switch)
Name_ = 0
%%global index. keeps track of the total number of switches,
% can be used to index new switches.
numCreated_ = 0
%% a copy of the simulation settings
connInfo=ConnectionInfo
%
LinkList_=[];
%%noise rate to use on its links.
noiseRate_ = 0.000001
%change this if you dont want any noise to be added.
addNoise = true
end
properties(Constant)
%%number of Tors in each pod, number of T1s in each pod
%and number of t2 switches.
ToRs_=20
K_=8
R_=10
end
methods (Static)
%%We need to test each of these functions later on.
function out = updateGetNumCreated(update)
persistent totalNumCreated_;
if nargin
if update
totalNumCreated_ = totalNumCreated_+1;
else
totalNumCreated_=0;
end
end
out = totalNumCreated_;
end
end
methods
%%checks to see if there are links that are dropping packets
function [res, numRetrans]=checkForPacketDrops(obj, nextLink,...
numPackets,source,dest)
%checks to see if this link is dropping any packets for that
%connection. Outputs the number of packets dropped and an
%indicator.
found=false;
%% assertion checks if the route makes sense.
assert(ismember(nextLink,obj.UpperNeighbors_) || ismember(nextLink,obj.LowerNeighbors_));
%If this link is not one that drops packets go here and apply
%noise appropriately.
if isempty(find(nextLink==obj.NeighborDropRates_, 1))
if obj.addNoise
%%finds how many packets should be dropped on this link.
droprate=random('unif',obj.connInfo.defaultLinkDropRate, ...
obj.noiseRate_);
numRetrans=binornd(numPackets,droprate);
else
droprate=0;
numRetrans=0;
end
else
%this is a failed link so use the drop rate that is in the
%link object itself.
index = (nextLink==obj.NeighborDropRates_);
droprate=obj.LinkList_(obj.NeighborDropRates_(index)).Object.dropRate_;
numRetrans=binornd(numPackets,droprate);
found=true;
end
prob=1-(1-droprate)^numPackets;
p=rand();
if((p<=prob && ~obj.connInfo.sourcebiased) && ~obj.connInfo.destbiased)
res=true;
return;
else if (obj.connInfo.sourcebiased && found)
if(rem(source.Object.Name_,10)==0)
res=true;
return;
end
else if (obj.connInfo.destbiased && found)
if(rem(dest.Object.Name_,10)==0)
res=true;
return;
end
end
end
end
res=false;
return;
end
function res=ne(obj,comp)
res=~eq(obj,comp);
end
function res=eq(obj,comp)
if isempty(comp)
res=false;
return;
end
if isempty(obj)
res=false;
return;
end
if length(obj)>1
res=[];
for i=1:length(obj)
if ~eq(obj(i),comp)
res=[res,false];
else
res=[res,true];
end
end
return;
end
if length(comp)>1
res=[];
for i=1:length(comp)
if ~eq(obj,comp(i))
res=[res,false];
else
res=[res,true];
end
end
return;
end
if (obj.type_~=comp.type_)
res=false;
return;
end
if obj.podIndex_ ~=comp.podIndex_
res=false;
return;
end
if obj.Name_ ~=comp.Name_
res=false;
return;
end
res=true;
return;
end
%%routing function.
function link=routeToDest(obj,source,dest,destToR)
if obj==destToR.Object
link=nan;
return;
end
if obj.type_==deviceType.ToR
index=random('unid',obj.K_);
link= obj.UpperNeighbors_(index);
return;
end
if obj.type_==deviceType.T1
tmp=arrayfun(@(x){x.Object.dest_.Object},obj.LinkList_(obj.LowerNeighbors_));
tmp=[tmp{:}];
if ~isempty(find(ismember(obj.LinkList_(source.Object.UpperNeighbors_(1)).Object.dest_.Object,tmp)==1, 1))
if(~isempty(find(tmp==destToR.Object, 1)))
link=obj.LowerNeighbors_(find(destToR.Object==tmp));
return
end
end
if(~isempty(find(ismember(destToR.Object,tmp)==1,1)))
link=obj.LowerNeighbors_(find(destToR.Object==tmp));
return;
end
if ~isempty(find(ismember(obj.LinkList_(source.Object.UpperNeighbors_(1)).Object.dest_.Object,tmp)==1, 1))
index= random('unid',obj.R_);
link=obj.UpperNeighbors_(index);
return;
end
assert(0)
end
if obj.type_==deviceType.T2
lowerneighbors=obj.LinkList_(obj.LowerNeighbors_);
tmp=arrayfun(@(x){x.Object.dest_.Object},lowerneighbors);
tmp=[tmp{:}];
tmp=arrayfun(@(x){x.podIndex_==destToR.Object.podIndex_},tmp);
tmp=[tmp{:}];
%tmp
res=obj.LowerNeighbors_(tmp);
% res=obj.LinkList_(res);
% res(1).Object.dest_.Object
% destToR.Object
assert(length(res)==obj.K_);
index=random('unid',obj.K_);
link=res(index);
end
end
function obj=setLowerNeighbors(obj,lowerNeighbors)
obj.LowerNeighbors_=[obj.LowerNeighbors_,lowerNeighbors];
end
function obj=setUpperNeighbors(obj,upperNeighbors)
obj.UpperNeighbors_=[obj.UpperNeighbors_,upperNeighbors];
end
function obj=setpodIndex(obj,index)
obj.podIndex_=index;
end
function obj=setNeighborDropRates(obj,dropRateMap)
obj.NeighborDropRates_=[obj.NeighborDropRates_,dropRateMap];
end
end
end