-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol_NULL.m
101 lines (81 loc) · 4.69 KB
/
protocol_NULL.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%% NULL 直接传递,无协议 %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SCPR social contact probability protocol
%% 获取信息并缓存信息 目标地址
messages_x = []; %messages_x = [MN_DATA_ROUTING_temp.VS_NODE(MN_INTEX_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_INTEX_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