-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol_SCPR.m
223 lines (183 loc) · 10.3 KB
/
protocol_SCPR.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
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% Social Contact Probability Assisted Routing %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SCPR social contact probability protocol
%% 获取信息并缓存信息 目标地址
messages_x = []; %messages_x = [MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).MESSAGE(:).TO]
messages_y = []; %messages_y = [MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).MESSAGE(:).TO]
buffer_x = []; %[MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(:).TO]
buffer_y = []; %[MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(:).TO]
%刷新信息和缓存,同时读取信息和缓存
in_refresh_buffers;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% 源节点与目标节点直接相遇的状况 首先完成直接传递
%%1. 节点2是节点1的传信目标 不存入buffer
if sum ( messages_x == MN_INDEX_2 ) >= 1
% 节点1的信息保存至节点2信息的「接收信息」中
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).RECEIVED_MESSAGE( end + 1: end + sum(messages_x == MN_INDEX_2) ) = ...
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).MESSAGE(messages_x == MN_INDEX_2); %
%
for adding_time_index = 0 : sum(messages_x == MN_INDEX_2) - 1
%记录信息接收的时间
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).RECEIVED_MESSAGE(end - adding_time_index).RECEIPTION_TIME = time;
end
%移除原节点信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).MESSAGE(messages_x == MN_INDEX_2) = [];
%接收信息量 + 1
MN_DATA_ROUTING_temp.RECEIVED_COUNT = MN_DATA_ROUTING_temp.RECEIVED_COUNT + sum(messages_x == MN_INDEX_2);
%直接传递量 + 1
MN_DATA_ROUTING_temp.RECEIVED_DIRECTLY = MN_DATA_ROUTING_temp.RECEIVED_DIRECTLY + sum(messages_x == MN_INDEX_2);
in_refresh_buffers;
end
%%2.节点2是节点1缓存中传信目标
if sum(buffer_x == MN_INDEX_2) >= 1
% 节点1缓存向节点2发送信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).RECEIVED_MESSAGE(end + 1:end + sum( buffer_x == MN_INDEX_2)) = ...
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(buffer_x == MN_INDEX_2);
for adding_time_index = 0 : sum(buffer_x == MN_INDEX_2) - 1
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).RECEIVED_MESSAGE(end - adding_time_index).RECEIPTION_TIME = time;
end
%移除节点1缓存中的信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(buffer_x == MN_INDEX_2) = [];
%接收信息量 + 1
MN_DATA_ROUTING_temp.RECEIVED_COUNT = MN_DATA_ROUTING_temp.RECEIVED_COUNT + sum(buffer_x == MN_INDEX_2);
%间接传递量 + 1
MN_DATA_ROUTING_temp.RECEIVED_FROM_BUFFERED = MN_DATA_ROUTING_temp.RECEIVED_FROM_BUFFERED + sum(buffer_x == MN_INDEX_2);
in_refresh_buffers;
end
%%3.节点1是节点2的传信目标 不存入buffer
if sum(messages_y == MN_INDEX_1) >= 1
% 节点2向节点1发送信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).RECEIVED_MESSAGE(end + 1:end + sum(messages_y == MN_INDEX_1)) = ...
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).MESSAGE(messages_y == MN_INDEX_1);
for adding_time_index = 0 : sum(messages_y == MN_INDEX_1) - 1
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).RECEIVED_MESSAGE(end - adding_time_index).RECEIPTION_TIME = time;
end
%移除节点2信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).MESSAGE( messages_y == MN_INDEX_1) = [];
%接收信息量 + 1
MN_DATA_ROUTING_temp.RECEIVED_COUNT = MN_DATA_ROUTING_temp.RECEIVED_COUNT + sum(messages_y == MN_INDEX_1);
%直接传递量 + 1
MN_DATA_ROUTING_temp.RECEIVED_DIRECTLY = MN_DATA_ROUTING_temp.RECEIVED_DIRECTLY + sum(messages_y == MN_INDEX_1);
in_refresh_buffers;
end
%%4. 节点1是节点2缓存中的传信目标
if sum(buffer_y == MN_INDEX_1) >= 1
%节点2缓存向节点1发送消息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).RECEIVED_MESSAGE(end + 1:end + sum(buffer_y == MN_INDEX_1)) = ...
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(buffer_y == MN_INDEX_1);
for adding_time_index = 0:sum(buffer_y == MN_INDEX_1) - 1
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).RECEIVED_MESSAGE(end - adding_time_index).RECEIPTION_TIME = time;
end
%移除节点2缓存信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER( buffer_y == MN_INDEX_1) = [];
%接收信息量 + 1
MN_DATA_ROUTING_temp.RECEIVED_COUNT = MN_DATA_ROUTING_temp.RECEIVED_COUNT + sum(buffer_y == MN_INDEX_1);
%间接传递量 + 1
MN_DATA_ROUTING_temp.RECEIVED_FROM_BUFFERED = MN_DATA_ROUTING_temp.RECEIVED_FROM_BUFFERED + sum(buffer_y == MN_INDEX_1);
in_refresh_buffers;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%依靠中间节点传递信息
%%节点1信息传至节点2缓存
%节点1信息非空且节点1信息并节点2并非节点1目标
%%1.MSG_X -> Buffer_Y
if (~isempty( messages_x) ) && (sum(messages_x == MN_INDEX_2) == 0)
%调用传递脚本前,设定好节点与相遇节点
nodeIndex = MN_INDEX_1;
intermeet_node = MN_INDEX_2;
delete_message = [];
for forward_node = unique(messages_x)
protocol_SCPRsetForward;
%如果满足传递调剂
if forward_message == 1
%节点2缓存储存节点1的信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(end + 1 : end + sum(messages_x == forward_node)) = ...
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).MESSAGE(messages_x == forward_node);
%统计更新
for adding_forwardNode_index = 0 : sum(messages_x == forward_node) - 1
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(end - adding_forwardNode_index).NUMBER_OF_FORWARDS(end + 1) = MN_INDEX_1;
temp_TTL = MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(end - adding_forwardNode_index).TTL;
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(end - adding_forwardNode_index).TTL = temp_TTL + 1;
end
MN_DATA_ROUTING_temp.BUFFERED_COUNT = MN_DATA_ROUTING_temp.BUFFERED_COUNT + sum(messages_x == forward_node);
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).MESSAGE(messages_x == forward_node) = [];
in_refresh_buffers;
end
end
end
%%节点2信息传至节点1缓存
%%2.MSG_Y -> Buffer_X
if (~isempty(messages_y) ) && (sum(messages_y == MN_INDEX_1) == 0)
nodeIndex = MN_INDEX_2;
intermeet_node = MN_INDEX_1;
delete_message = [];
for forward_node = unique(messages_y)
protocol_SCPRsetForward;
%如果满足传递调
if forward_message == 1
%节点1缓存储存节点2的信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(end + 1 : end + sum(messages_y == forward_node)) = ...
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).MESSAGE(messages_y == forward_node);
%统计更新
for adding_forwardNode_index = 0 : sum( messages_y == forward_node ) - 1
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(end - adding_forwardNode_index ).NUMBER_OF_FORWARDS(end + 1) = MN_INDEX_2;
temp_TTL = MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(end - adding_forwardNode_index ).TTL;
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(end - adding_forwardNode_index ).TTL = temp_TTL + 1;
end
MN_DATA_ROUTING_temp.BUFFERED_COUNT = MN_DATA_ROUTING_temp.BUFFERED_COUNT + sum( messages_y == forward_node);
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).MESSAGE( messages_y == forward_node ) = [];
in_refresh_buffers;
end
end
end
%%节点1缓存传至节点2缓存
%%3.BufferX -> BufferY
if ( ~isempty( buffer_x )) && (sum (buffer_x == MN_INDEX_2 ) == 0)
nodeIndex = MN_INDEX_1;
intermeet_node = MN_INDEX_2;
delete_message = [];
for forward_node = unique(buffer_x)
protocol_SCPRsetForward;
if forward_message == 1
%节点2缓存储存节点1缓存的信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(end + 1 : end + sum(buffer_x == forward_node)) = ...
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(buffer_x == forward_node);
for adding_forwardNode_index = 0 : sum( buffer_x == forward_node) - 1 %message_x
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER( end - adding_forwardNode_index).NUMBER_OF_FORWARDS(end + 1) = MN_INDEX_1;
temp_TTL = MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER( end - adding_forwardNode_index).TTL;
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER( end - adding_forwardNode_index).TTL = temp_TTL + 1;
end
MN_DATA_ROUTING_temp.BUFFERED_COUNT = MN_DATA_ROUTING_temp.BUFFERED_COUNT + sum( buffer_x == forward_node);
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER( buffer_x == forward_node ) = [];
in_refresh_buffers;
end
end
end
%%节点2缓存传至节点1缓存
%%4.BufferY -> BufferX
if ( ~isempty( buffer_y )) && ( sum (buffer_y == MN_INDEX_1) == 0)
nodeIndex = MN_INDEX_2;
intermeet_node = MN_INDEX_1;
delete_message = [];
for forward_node = unique(buffer_y)
protocol_SCPRsetForward;
if forward_message == 1
%节点1缓存储存节点2缓存的信息
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(end + 1 : end + sum(buffer_y == forward_node)) = ...
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(buffer_y == forward_node);
for adding_forwardNode_index = 0 : sum(buffer_y == forward_node) - 1
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(end - adding_forwardNode_index).NUMBER_OF_FORWARDS(end + 1) = MN_INDEX_2;
temp_TTL = MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER(end - adding_forwardNode_index).TTL;
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_1).BUFFER( end - adding_forwardNode_index).TTL = temp_TTL + 1;
end
MN_DATA_ROUTING_temp.BUFFERED_COUNT = MN_DATA_ROUTING_temp.BUFFERED_COUNT + sum( buffer_y == forward_node);
MN_DATA_ROUTING_temp.VS_NODE(MN_INDEX_2).BUFFER(buffer_y == forward_node) = [];
in_refresh_buffers;
end
end
end