Newer
Older
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
module MainModule {
import from TraceParserSystem all;
function f_rsuBehaviour(inout integer p_tranDuration) runs on RsuType {
var address v_ts := 0;
var integer v_startTS := 0;
var template (present) LinkId v_linkId := ?;
var boolean v_receivedLinkId := false;
var NrOfEmptyMsg v_nrOfEmptyMsg := 0;
var PayloadStructure v_receivedMsg;
transactionRSUTimer.start;
alt {
[v_startTS==0] rsuPort.receive(mw_rsuBroadCastMsg) -> sender v_ts value v_receivedMsg{
// when the first broadcast message is received then take it's time stamp
transactionRSUTimer.stop;
//---
commonOBURSUPort.send(v_receivedMsg);
//---
v_startTS := v_ts;
transactionRSUTimer.start;
repeat;
}
[] compPort.receive(v_linkId) -> value v_linkId{
transactionRSUTimer.stop;
v_receivedLinkId := true;
transactionRSUTimer.start;
repeat;
}
[v_startTS!=0 and v_receivedLinkId == true] rsuPort.receive(mw_releaseMsg(v_linkId)) -> sender v_ts value v_receivedMsg{
// when the release message was received take it's time stamp and calculate the transaction time
// inform the rsu component
transactionRSUTimer.stop;
//---
commonOBURSUPort.send(v_receivedMsg);
//---
compPort.send(m_stop);
alt{
[] compPort.receive(NrOfEmptyMsg :?) -> value v_nrOfEmptyMsg;
[] compPort.receive {
transactionRSUTimer.stop;
setverdict(inconc, "Unexpected message received");
stop;
}
[] transactionRSUTimer.timeout {
setverdict (inconc, "No NrOfEmptyMsg was received from RSU");
stop;
}
}
p_tranDuration := v_ts - v_startTS;
if (p_tranDuration <= 100000 and v_nrOfEmptyMsg <= PX_MAX_NUM_EMPTY_UPLINK_FRAMES){
setverdict (pass, "Transaction finished in " & int2str(p_tranDuration) & " microsec." & " The Number of empty messages received is : " & int2str(v_nrOfEmptyMsg));
}
else if(p_tranDuration > 100000){
setverdict (fail, "Transaction finished in more than 100ms (" & int2str(p_tranDuration) & " micro s " &")");
}else if(v_nrOfEmptyMsg > PX_MAX_NUM_EMPTY_UPLINK_FRAMES){
setverdict (fail, "Maximum number of received empty frames exceeded! ("
& int2str(v_nrOfEmptyMsg) & " > " & int2str(PX_MAX_NUM_EMPTY_UPLINK_FRAMES) & ")");
}
stop;
}
[v_startTS!=0 and v_receivedLinkId == true] rsuPort.receive(mw_msg_withLinkId(v_linkId))-> value v_receivedMsg{
transactionRSUTimer.stop;
//---
commonOBURSUPort.send(v_receivedMsg);
//---
transactionRSUTimer.start;
repeat;
}
[v_startTS!=0 and v_receivedLinkId == true] rsuPort.receive(mw_rsuBroadCastMsg) -> value v_receivedMsg{
//If another broadcast is received than ignore
transactionRSUTimer.stop;
//---
commonOBURSUPort.send(v_receivedMsg);
//---
transactionRSUTimer.start;
repeat;
}
[v_startTS!=0 and v_receivedLinkId == true] rsuPort.receive {
transactionRSUTimer.stop;
setverdict(inconc, "Unexpected message received");
compPort.send(m_stop);
stop;
}
[] transactionRSUTimer.timeout {
setverdict (inconc, "No RSU message was received");
compPort.send(m_stop);
stop;
}
}
}
function f_obuBehaviour() runs on ObuType {
var boolean v_sentLinkId := false;
var PayloadStructure v_msg;
var NrOfEmptyMsg v_cntEmpty := 0;
var template (present) LinkId v_linkId := ?;
timer t_obuTimer := 2.0;
t_obuTimer.start;
alt{
[]obuPort.receive(mw_msg_withLinkId(v_linkId)) -> value v_msg{
t_obuTimer.stop;
//---
commonOBURSUPort.send(v_msg);
//---
if (v_sentLinkId == false) {
v_linkId := valueof(v_msg.linkMsg.linkId);
compPort.send(valueof(v_linkId));
}
v_sentLinkId := true;
t_obuTimer.start;
repeat;
}
[]obuPort.receive(mw_msg_empty) ->value v_msg{
t_obuTimer.stop;
//---
commonOBURSUPort.send(v_msg);
//---
v_cntEmpty := v_cntEmpty +1;
t_obuTimer.start;
repeat;
}
[]obuPort.receive{
t_obuTimer.stop;
setverdict (inconc, "Unexpected message received.");
stop;
}
[]compPort.receive(m_stop) {
compPort.send(v_cntEmpty);
stop;
}
[]t_obuTimer.timeout{
setverdict(inconc, "No OBU messaged received");
stop;
}
}
}
/**
* @desc This test case is seting the trace file and counts the number of transaction
*/
testcase TC_Initialization(inout integer p_nrOfTransactions) runs on MtcType system SystemType {
map(mtc:controlPort, system:controlPort);
parseFileName(PX_TRACE_PATH, v_PowerLevel, v_OBUName, v_DutyCycle, v_RepNo);
controlPort.call(setTraceFile:{PX_TRACE_PATH}, 5.0) {
[] controlPort.getreply(setTraceFile:{-} value true) {
setverdict (pass, " PowerLevel = " & v_PowerLevel&
" OBUName = " & v_OBUName &
" DutyCycle = " & v_DutyCycle &
" RepNo = " & v_RepNo );
}
[] controlPort.getreply {
setverdict (fail, "Could not set trace file");
stop;
}
[] controlPort.catch(timeout) {
setverdict (fail, "Timeout while setting trace file");
stop;
}
};
controlPort.call(getTransactionCnt:{}, 5.0) {
[] controlPort.getreply(getTransactionCnt:{} value ?) -> value p_nrOfTransactions {
if(p_nrOfTransactions != 0){
setverdict (pass, "Number of Transaction = " & int2str(p_nrOfTransactions));
}else{
setverdict (fail, "!!No Transaction Found!! Please verify the log file!!");
stop;
}
}
[] controlPort.getreply {
setverdict (fail, "Unexpected reply");
stop;
}
[] controlPort.catch(timeout) {
setverdict (fail, "Timeout while caling getTransacationCnt");
stop;
}
};
}
/**
* @desc This test case analizes a transaction, it's duration and the number of empty messages received from RSU
*/
testcase TC_AnalyzesTrace(inout integer p_traceIndex, inout integer p_tranDuration) runs on MtcType system SystemType {
var RsuType rsuComponent := RsuType.create("RSU"); //DL
var ObuType obuComponent := ObuType.create("OBU"); //UL
map(mtc:controlPort, system:controlPort);
map(rsuComponent:rsuPort, system:msgPort);
map(obuComponent:obuPort, system:msgPort);
connect(rsuComponent:compPort, obuComponent:compPort);
connect(rsuComponent:commonOBURSUPort, obuComponent:commonOBURSUPort);
rsuComponent.start(f_rsuBehaviour(p_tranDuration));
obuComponent.start(f_obuBehaviour());
log ("Starting analysis of trace: " & int2str(p_traceIndex));
controlPort.call(startAnalyzeTrace:{p_traceIndex}, 5.0) {
[] controlPort.getreply(startAnalyzeTrace:{-} value true) {
setverdict (pass);
}
[] controlPort.getreply {
setverdict (fail, "Could not start analyzing trace");
stop;
}
[] controlPort.catch(timeout) {
setverdict (fail, "Timeout while start analyzing trace");
stop;
}
};
all component.done;
}
testcase TC_LogAnalyzesTrace(inout integer p_averageTranDuration,
inout integer p_shortestTransDuration,
inout integer p_shortestTransIndex,
inout integer p_longestTransDuration,
inout integer p_longestTransIndex) runs on MtcType system SystemType {
setverdict(pass, "The average transaction duration is: " & int2str(p_averageTranDuration) & " micro s" &
" The shortest transaction was transaction: " & int2str(p_shortestTransIndex) &
" and took " & int2str(p_shortestTransDuration) & " micro s" &
" The longest transaction was transaction: " & int2str(p_longestTransIndex) &
" and took " & int2str(p_longestTransDuration)& " micro s") ;
}
control {
var integer v_nrOfTransactions := 0;
var integer v_nrOfRelevantTransactions := 0;
var integer v_longestTransDuration := 0;
var integer v_longestTransIndex := -1;
var integer v_shortestTransDuration := 0;
var integer v_shortestTransIndex := -1;
var integer v_tranDuration := 0;
var integer v_cumulativeTranDuration := 0;
var integer v_averageTranDuration;
execute(TC_Initialization(v_nrOfTransactions));
v_nrOfRelevantTransactions := v_nrOfTransactions;
for(var integer i:=0; i<v_nrOfTransactions; i:=i + 1) {
execute(TC_AnalyzesTrace(i, v_tranDuration));
v_cumulativeTranDuration := v_cumulativeTranDuration + v_tranDuration;
if (v_tranDuration == 0) {
v_nrOfRelevantTransactions := v_nrOfRelevantTransactions - 1;
}
if (v_shortestTransDuration==0) {
v_shortestTransDuration := v_tranDuration;
}
if(v_shortestTransDuration > v_tranDuration){
log("Short v_tranDuration " & int2str(v_tranDuration));
v_shortestTransDuration := v_tranDuration;
v_shortestTransIndex := i;
}
else if(v_longestTransDuration < v_tranDuration){
log("Long v_tranDuration " & int2str(v_tranDuration));
v_longestTransDuration := v_tranDuration;
v_longestTransIndex := i;
}
};
if(v_nrOfRelevantTransactions != 0){
v_averageTranDuration := float2int(int2float(v_cumulativeTranDuration) / int2float(v_nrOfRelevantTransactions));
execute(TC_LogAnalyzesTrace(v_averageTranDuration,
v_shortestTransDuration,
v_shortestTransIndex,
v_longestTransDuration,
v_longestTransIndex));
}
}