1 |
66 |
ash_riple |
///*
|
2 |
|
|
// * ptpv2_timing_analyzer.sce
|
3 |
|
|
// *
|
4 |
|
|
// * Copyright (c) 2013, BABY&HW. All rights reserved.
|
5 |
|
|
// *
|
6 |
|
|
// * This library is free software; you can redistribute it and/or
|
7 |
|
|
// * modify it under the terms of the GNU Lesser General Public
|
8 |
|
|
// * License as published by the Free Software Foundation; either
|
9 |
|
|
// * version 2.1 of the License, or (at your option) any later version.
|
10 |
|
|
// *
|
11 |
|
|
// * This library is distributed in the hope that it will be useful,
|
12 |
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
// * Lesser General Public License for more details.
|
15 |
|
|
// *
|
16 |
|
|
// * You should have received a copy of the GNU Lesser General Public
|
17 |
|
|
// * License along with this library; if not, write to the Free Software
|
18 |
|
|
// * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
|
|
// * MA 02110-1301 USA
|
20 |
|
|
// */
|
21 |
|
|
|
22 |
|
|
clear;
|
23 |
|
|
clc;
|
24 |
|
|
stacksize('max');
|
25 |
|
|
/////////////////////////////////////
|
26 |
|
|
// Read pcap file for PTP
|
27 |
|
|
/////////////////////////////////////
|
28 |
|
|
pcapFile='ptpdv2_long.pcap';
|
29 |
|
|
fd1=mopen(pcapFile,'rb');
|
30 |
|
|
// skip file header
|
31 |
|
|
// check endianness
|
32 |
|
|
mseek(24); //24B
|
33 |
|
|
|
34 |
|
|
// parse capture
|
35 |
|
|
packetNum_cap = {};
|
36 |
|
|
messageId_cap = {};
|
37 |
|
|
clockId_cap = {};
|
38 |
|
|
sequenceId_cap = {};
|
39 |
|
|
embeddedTimestamp_cap = {};
|
40 |
|
|
capturedTimestamp_cap = {};
|
41 |
|
|
packetNum = 0;
|
42 |
|
|
while 1
|
43 |
|
|
// parsing capture header per frame
|
44 |
|
|
// get time stamp in second
|
45 |
|
|
capturedTimestamp_Sec =mget(1,'uil',fd1);
|
46 |
|
|
// get time stamp in nsecond
|
47 |
|
|
capturedTimestamp_NSec=mget(1,'uil',fd1);
|
48 |
|
|
// get capture length
|
49 |
|
|
lCaptr=mget(1,'uil',fd1);
|
50 |
|
|
// get frame length
|
51 |
|
|
lFrame=mget(1,'uil',fd1);
|
52 |
|
|
|
53 |
|
|
// ptp packet parsing here
|
54 |
|
|
|
55 |
|
|
// ptp packet address filter here
|
56 |
|
|
|
57 |
|
|
// ptp packet number
|
58 |
|
|
packetNum=packetNum+1;
|
59 |
|
|
|
60 |
|
|
// skip packet header
|
61 |
|
|
mseek(mtell(fd1)+(14+20+8)); //14B:MAC, 20B:IP, 8B:UDP
|
62 |
|
|
|
63 |
|
|
// messageId
|
64 |
|
|
mseek(mtell(fd1)+0); // 0B from beginning of ptp
|
65 |
|
|
messageId=modulo(mget(1,'ucb',fd1),2^4); //1B
|
66 |
|
|
mseek(mtell(fd1)-(0+1)); //return to beginning of ptp
|
67 |
|
|
|
68 |
|
|
// ClockIdentity
|
69 |
|
|
mseek(mtell(fd1)+20); // 20B from beginning of ptp
|
70 |
|
|
clockId=mget(1,'uib',fd1); //4B
|
71 |
|
|
clockId=mget(1,'uib',fd1); //4B
|
72 |
|
|
mseek(mtell(fd1)-(20+4+4)); //return to beginning of ptp
|
73 |
|
|
|
74 |
|
|
// sequenceId
|
75 |
|
|
mseek(mtell(fd1)+30); // 30B from beginning of ptp
|
76 |
|
|
sequenceId=mget(1,'usb',fd1); //2B
|
77 |
|
|
mseek(mtell(fd1)-(30+2)); //return to beginning of ptp
|
78 |
|
|
|
79 |
|
|
// embeddedTimestamp
|
80 |
|
|
mseek(mtell(fd1)+34); // 34B from beginning of ptp
|
81 |
|
|
embeddedTimestamp_SecH=mget(1,'usb',fd1); //2B
|
82 |
|
|
embeddedTimestamp_SecL=mget(1,'uib',fd1); //4B
|
83 |
|
|
embeddedTimestamp_NSec=mget(1,'uib',fd1); //4B
|
84 |
|
|
mseek(mtell(fd1)-(34+2+4+4)); //return to beginning of ptp
|
85 |
|
|
|
86 |
|
|
// return to beginning of packet
|
87 |
|
|
mseek(mtell(fd1)-(14+20+8)); //14B:MAC, 20B:IP, 8B:UDP
|
88 |
|
|
|
89 |
|
|
// go to end of packet
|
90 |
|
|
mseek(mtell(fd1)+lCaptr);
|
91 |
|
|
|
92 |
|
|
// get ptp messages
|
93 |
|
|
packetNum_cap = [packetNum_cap, packetNum];
|
94 |
|
|
messageId_cap = [messageId_cap, messageId];
|
95 |
|
|
clockId_cap = [clockId_cap, clockId];
|
96 |
|
|
sequenceId_cap = [sequenceId_cap, sequenceId];
|
97 |
|
|
embeddedTimestamp_cap = [embeddedTimestamp_cap, (embeddedTimestamp_SecH*4294967296 + embeddedTimestamp_SecL) + embeddedTimestamp_NSec*10^(-9)];
|
98 |
|
|
capturedTimestamp_cap = [capturedTimestamp_cap, capturedTimestamp_Sec + capturedTimestamp_NSec*10^(-9)];
|
99 |
|
|
|
100 |
|
|
// EOF checking
|
101 |
|
|
mget(1,'ui',fd1);
|
102 |
|
|
if meof(fd1)
|
103 |
|
|
// break from the loop
|
104 |
|
|
break;
|
105 |
|
|
else
|
106 |
|
|
// switch to the next packet
|
107 |
|
|
mseek(mtell(fd1)-4);
|
108 |
|
|
end
|
109 |
|
|
end
|
110 |
|
|
mtell;
|
111 |
|
|
mclose(fd1);
|
112 |
|
|
|
113 |
|
|
// find Master and Slave clockId
|
114 |
|
|
clockId_mastrs=clockId_cap(find(messageId_cap==0));
|
115 |
|
|
clockId_mastr =clockId_mastrs(1);
|
116 |
|
|
clockId_slaves=clockId_cap(find(clockId_cap~=clockId_mastr));
|
117 |
|
|
clockId_slave =clockId_slaves(1);
|
118 |
|
|
|
119 |
|
|
// function: calc_delta
|
120 |
|
|
funcprot(0);
|
121 |
|
|
function timestamp_delta=calc_delta(timestamp)
|
122 |
|
|
timestamp=timestamp-timestamp(1);
|
123 |
|
|
timestamp_delta=zeros(1,length(timestamp)-1);
|
124 |
|
|
for i = 1:(length(timestamp)-1)
|
125 |
|
|
timestamp_delta(i)=timestamp(i+1)-timestamp(i);
|
126 |
|
|
end
|
127 |
|
|
endfunction
|
128 |
|
|
|
129 |
|
|
///////////////////////////////////////
|
130 |
|
|
// Generate CSV
|
131 |
|
|
///////////////////////////////////////
|
132 |
|
|
// [packetNum_cap', capturedTimestamp_cap', messageId_cap', clockId_cap', sequenceId_cap', embeddedTimestamp_cap']
|
133 |
|
|
|
134 |
|
|
// Port Direction
|
135 |
|
|
clockId_str_cap={};
|
136 |
|
|
for i = 1:length(clockId_cap)
|
137 |
|
|
select clockId_cap(i)
|
138 |
|
|
case clockId_mastr then clockId_str_cap = {clockId_str_cap, 'M -> S'},
|
139 |
|
|
else clockId_str_cap = {clockId_str_cap, 'M <- S'},
|
140 |
|
|
end
|
141 |
|
|
end
|
142 |
|
|
|
143 |
|
|
// MessageId
|
144 |
|
|
messageId_str_cap={};
|
145 |
|
|
for i = 1:length(messageId_cap)
|
146 |
|
|
select messageId_cap(i)
|
147 |
|
|
case 0 then messageId_str_cap = {messageId_str_cap, '0x0: EVENT:SYNC'},
|
148 |
|
|
case 1 then messageId_str_cap = {messageId_str_cap, '0x1: EVENT:DELAY_REQ'},
|
149 |
|
|
case 2 then messageId_str_cap = {messageId_str_cap, '0x2: EVENT:PATH_DELAY_REQ'},
|
150 |
|
|
case 3 then messageId_str_cap = {messageId_str_cap, '0x3: EVENT:PATH_DELAY_RESP'},
|
151 |
|
|
//case 4- 7 Reserved
|
152 |
|
|
case 8 then messageId_str_cap = {messageId_str_cap, '0x8: GENER:FOLLOW_UP'},
|
153 |
|
|
case 9 then messageId_str_cap = {messageId_str_cap, '0x9: GENER:DELAY_RESP'},
|
154 |
|
|
case 10 then messageId_str_cap = {messageId_str_cap, '0xA: GENER:PATH_DELAY_RESP_FOLLOW_UP'},
|
155 |
|
|
case 11 then messageId_str_cap = {messageId_str_cap, '0xB: GENER:ANNOUNCE'},
|
156 |
|
|
case 12 then messageId_str_cap = {messageId_str_cap, '0xC: GENER:SIGNALLING'},
|
157 |
|
|
case 13 then messageId_str_cap = {messageId_str_cap, '0xD: GENER:MANAGEMENT'},
|
158 |
|
|
//case 14-15 Reserved
|
159 |
|
|
else messageId_str_cap = {messageId_str_cap, messageId},
|
160 |
|
|
end
|
161 |
|
|
end
|
162 |
|
|
|
163 |
|
|
// Inter-Packet Time
|
164 |
|
|
interPacketTime={0, calc_delta(capturedTimestamp_cap)};
|
165 |
|
|
|
166 |
|
|
// Inter-Message Time
|
167 |
|
|
interMessageTime=zeros(1,length(capturedTimestamp_cap));
|
168 |
|
|
indexMastr=find(clockId_cap==clockId_mastr);
|
169 |
|
|
indexSlave=find(clockId_cap==clockId_slave);
|
170 |
|
|
indexSync=indexMastr(find(messageId_cap(indexMastr)== 0));
|
171 |
|
|
indexDreq=indexMastr(find(messageId_cap(indexMastr)== 1));
|
172 |
|
|
indexPreq=indexMastr(find(messageId_cap(indexMastr)== 2));
|
173 |
|
|
indexPres=indexMastr(find(messageId_cap(indexMastr)== 3));
|
174 |
|
|
indexFlup=indexMastr(find(messageId_cap(indexMastr)== 8));
|
175 |
|
|
indexDres=indexMastr(find(messageId_cap(indexMastr)== 9));
|
176 |
|
|
indexPrfl=indexMastr(find(messageId_cap(indexMastr)==10));
|
177 |
|
|
indexAnnc=indexMastr(find(messageId_cap(indexMastr)==11));
|
178 |
|
|
indexSign=indexMastr(find(messageId_cap(indexMastr)==12));
|
179 |
|
|
indexMang=indexMastr(find(messageId_cap(indexMastr)==13));
|
180 |
|
|
interMessageTime(indexSync)={0, calc_delta(capturedTimestamp_cap(indexSync))};
|
181 |
|
|
interMessageTime(indexDreq)={0, calc_delta(capturedTimestamp_cap(indexDreq))};
|
182 |
|
|
interMessageTime(indexPreq)={0, calc_delta(capturedTimestamp_cap(indexPreq))};
|
183 |
|
|
interMessageTime(indexPres)={0, calc_delta(capturedTimestamp_cap(indexPres))};
|
184 |
|
|
interMessageTime(indexFlup)={0, calc_delta(capturedTimestamp_cap(indexFlup))};
|
185 |
|
|
interMessageTime(indexDres)={0, calc_delta(capturedTimestamp_cap(indexDres))};
|
186 |
|
|
interMessageTime(indexPrfl)={0, calc_delta(capturedTimestamp_cap(indexPrfl))};
|
187 |
|
|
interMessageTime(indexAnnc)={0, calc_delta(capturedTimestamp_cap(indexAnnc))};
|
188 |
|
|
interMessageTime(indexSign)={0, calc_delta(capturedTimestamp_cap(indexSign))};
|
189 |
|
|
interMessageTime(indexMang)={0, calc_delta(capturedTimestamp_cap(indexMang))};
|
190 |
|
|
indexSync=indexSlave(find(messageId_cap(indexSlave)== 0));
|
191 |
|
|
indexDreq=indexSlave(find(messageId_cap(indexSlave)== 1));
|
192 |
|
|
indexPreq=indexSlave(find(messageId_cap(indexSlave)== 2));
|
193 |
|
|
indexPres=indexSlave(find(messageId_cap(indexSlave)== 3));
|
194 |
|
|
indexFlup=indexSlave(find(messageId_cap(indexSlave)== 8));
|
195 |
|
|
indexDres=indexSlave(find(messageId_cap(indexSlave)== 9));
|
196 |
|
|
indexPrfl=indexSlave(find(messageId_cap(indexSlave)==10));
|
197 |
|
|
indexAnnc=indexSlave(find(messageId_cap(indexSlave)==11));
|
198 |
|
|
indexSign=indexSlave(find(messageId_cap(indexSlave)==12));
|
199 |
|
|
indexMang=indexSlave(find(messageId_cap(indexSlave)==13));
|
200 |
|
|
interMessageTime(indexSync)={0, calc_delta(capturedTimestamp_cap(indexSync))};
|
201 |
|
|
interMessageTime(indexDreq)={0, calc_delta(capturedTimestamp_cap(indexDreq))};
|
202 |
|
|
interMessageTime(indexPreq)={0, calc_delta(capturedTimestamp_cap(indexPreq))};
|
203 |
|
|
interMessageTime(indexPres)={0, calc_delta(capturedTimestamp_cap(indexPres))};
|
204 |
|
|
interMessageTime(indexFlup)={0, calc_delta(capturedTimestamp_cap(indexFlup))};
|
205 |
|
|
interMessageTime(indexDres)={0, calc_delta(capturedTimestamp_cap(indexDres))};
|
206 |
|
|
interMessageTime(indexPrfl)={0, calc_delta(capturedTimestamp_cap(indexPrfl))};
|
207 |
|
|
interMessageTime(indexAnnc)={0, calc_delta(capturedTimestamp_cap(indexAnnc))};
|
208 |
|
|
interMessageTime(indexSign)={0, calc_delta(capturedTimestamp_cap(indexSign))};
|
209 |
|
|
interMessageTime(indexMang)={0, calc_delta(capturedTimestamp_cap(indexMang))};
|
210 |
|
|
|
211 |
|
|
u=file('open',PWD+'/ptpv2_'+'parsed'+'.csv','unknown');
|
212 |
|
|
fprintf(u,"Port, Packet #, Arrival Time, Inter-Packet Time, Inter-Message Time, messageType, sequenceId, embedded Time");
|
213 |
|
|
for i = 1:(length(packetNum_cap))
|
214 |
|
|
fprintf(u,"%s, %d, %6.9f, %6.9f, %6.9f, %s, %d, %6.9f", clockId_str_cap(i), packetNum_cap(i), capturedTimestamp_cap(i)-capturedTimestamp_cap(1), interPacketTime(i), interMessageTime(i), messageId_str_cap(i), sequenceId_cap(i), embeddedTimestamp_cap(i));
|
215 |
|
|
end
|
216 |
|
|
file('close',u);
|
217 |
|
|
|
218 |
|
|
///////////////////////////////////////
|
219 |
|
|
// Generate graph
|
220 |
|
|
///////////////////////////////////////
|
221 |
|
|
|
222 |
|
|
// 1. SYNC PDV
|
223 |
|
|
subplot(8,1,1);
|
224 |
|
|
xtitle('', '', 'SYNC PDV/s');
|
225 |
|
|
indexSync=find(messageId_cap==0);
|
226 |
|
|
indexFlup=find(messageId_cap==8);
|
227 |
|
|
indexSync=indexSync(find(clockId_cap(indexSync)==clockId_mastr)); // SYNC M->S
|
228 |
|
|
indexFlup=indexFlup(find(clockId_cap(indexFlup)==clockId_mastr)); // FLUP M->S
|
229 |
|
|
capturedTimestamp_sync=capturedTimestamp_cap(indexSync); // t2
|
230 |
|
|
sequenceId_sync =sequenceId_cap (indexSync);
|
231 |
|
|
embeddedTimestamp_flup=embeddedTimestamp_cap(indexFlup); // t1
|
232 |
|
|
sequenceId_flup =sequenceId_cap (indexFlup);
|
233 |
|
|
|
234 |
|
|
captured_sync={};
|
235 |
|
|
embedded_flup={};
|
236 |
|
|
for i=1:length(sequenceId_sync)
|
237 |
|
|
index=find(sequenceId_flup==sequenceId_sync(i));
|
238 |
|
|
if index==[]
|
239 |
|
|
continue;
|
240 |
|
|
else
|
241 |
|
|
captured_sync={captured_sync, capturedTimestamp_sync(i)};
|
242 |
|
|
embedded_flup={embedded_flup, embeddedTimestamp_flup(index)};
|
243 |
|
|
end
|
244 |
|
|
end
|
245 |
|
|
|
246 |
|
|
captured_syncDelta=calc_delta(captured_sync);
|
247 |
|
|
embedded_flupDelta=calc_delta(embedded_flup);
|
248 |
|
|
plot((captured_sync(2:length(captured_sync))-capturedTimestamp_cap(1)), (captured_syncDelta-embedded_flupDelta));
|
249 |
|
|
|
250 |
|
|
// 2. DELAY_REQ PDV
|
251 |
|
|
subplot(8,1,2);
|
252 |
|
|
xtitle('', '', 'DELAY_REQ PDV/s');
|
253 |
|
|
indexReq=find(messageId_cap==2);
|
254 |
|
|
indexRes=find(messageId_cap==3);
|
255 |
|
|
indexReq=indexSync(find(clockId_cap(indexReq)==clockId_slave)); // DELAY_REQ S->M
|
256 |
|
|
indexRes=indexFlup(find(clockId_cap(indexRes)==clockId_mastr)); // DELAY_RES M->S
|
257 |
|
|
capturedTimestamp_req=capturedTimestamp_cap(indexReq); // t3
|
258 |
|
|
sequenceId_req =sequenceId_cap (indexReq);
|
259 |
|
|
embeddedTimestamp_res=embeddedTimestamp_cap(indexRes); // t4
|
260 |
|
|
sequenceId_res =sequenceId_cap (indexRes);
|
261 |
|
|
|
262 |
|
|
captured_req={};
|
263 |
|
|
embedded_res={};
|
264 |
|
|
for i=1:length(sequenceId_req)
|
265 |
|
|
index=find(sequenceId_res==sequenceId_req(i));
|
266 |
|
|
if index==[]
|
267 |
|
|
continue;
|
268 |
|
|
else
|
269 |
|
|
captured_req={captured_req, capturedTimestamp_req(i)};
|
270 |
|
|
embedded_res={embedded_res, embeddedTimestamp_res(index)};
|
271 |
|
|
end
|
272 |
|
|
end
|
273 |
|
|
|
274 |
|
|
captured_reqDelta=calc_delta(captured_req);
|
275 |
|
|
embedded_resDelta=calc_delta(embedded_res);
|
276 |
|
|
plot((captured_req(2:length(captured_req))-capturedTimestamp_cap(1)), (captured_reqDelta-embedded_resDelta));
|
277 |
|
|
|
278 |
|
|
// 3. FOLLOW_UP PDV
|
279 |
|
|
subplot(8,1,3);
|
280 |
|
|
xtitle('', '', 'FOLLOW_UP PDV/s');
|
281 |
|
|
indexSync=find(messageId_cap==0);
|
282 |
|
|
indexFlup=find(messageId_cap==8);
|
283 |
|
|
indexSync=indexSync(find(clockId_cap(indexSync)==clockId_mastr)); // SYNC M->S
|
284 |
|
|
indexFlup=indexFlup(find(clockId_cap(indexFlup)==clockId_mastr)); // FLUP M->S
|
285 |
|
|
capturedTimestamp_sync=capturedTimestamp_cap(indexSync); // t2
|
286 |
|
|
sequenceId_sync =sequenceId_cap (indexSync);
|
287 |
|
|
capturedTimestamp_flup=capturedTimestamp_cap(indexFlup);
|
288 |
|
|
sequenceId_flup =sequenceId_cap (indexFlup);
|
289 |
|
|
|
290 |
|
|
captured_sync={};
|
291 |
|
|
captured_flup={};
|
292 |
|
|
for i=1:length(sequenceId_sync)
|
293 |
|
|
index=find(sequenceId_flup==sequenceId_sync(i));
|
294 |
|
|
if index==[]
|
295 |
|
|
continue;
|
296 |
|
|
else
|
297 |
|
|
captured_sync={captured_sync, capturedTimestamp_sync(i)};
|
298 |
|
|
captured_flup={captured_flup, capturedTimestamp_flup(index)};
|
299 |
|
|
end
|
300 |
|
|
end
|
301 |
|
|
|
302 |
|
|
captured_syncDelta=calc_delta(captured_sync);
|
303 |
|
|
captured_flupDelta=calc_delta(captured_flup);
|
304 |
|
|
plot((captured_sync(2:length(captured_sync))-capturedTimestamp_cap(1)), (captured_flupDelta-captured_syncDelta));
|
305 |
|
|
|
306 |
|
|
// 4. Slave Clock Wander
|
307 |
|
|
subplot(8,1,4);
|
308 |
|
|
xtitle('', '', 'Slave Clock Wander/s');
|
309 |
|
|
indexReq=find(messageId_cap==2);
|
310 |
|
|
indexReq=indexReq(find(clockId_cap(indexReq)==clockId_slave)); // PATH_DELAY_REQ S->M
|
311 |
|
|
capturedTimestamp_req=capturedTimestamp_cap(indexReq); // t4
|
312 |
|
|
embeddedTimestamp_req=embeddedTimestamp_cap(indexReq);
|
313 |
|
|
sequenceId_req =sequenceId_cap (indexReq);
|
314 |
|
|
|
315 |
|
|
captured_req={};
|
316 |
|
|
embedded_req={};
|
317 |
|
|
for i=1:length(sequenceId_req)
|
318 |
|
|
index=find(sequenceId_req==sequenceId_req(i));
|
319 |
|
|
if index==[]
|
320 |
|
|
continue;
|
321 |
|
|
else
|
322 |
|
|
captured_req={captured_req, capturedTimestamp_req(index)};
|
323 |
|
|
embedded_req={embedded_req, embeddedTimestamp_req(index)};
|
324 |
|
|
end
|
325 |
|
|
end
|
326 |
|
|
|
327 |
|
|
embedded_reqDelta=calc_delta(embedded_req);
|
328 |
|
|
plot((captured_req(2:length(captured_req))-capturedTimestamp_cap(1)), embedded_reqDelta-mean(embedded_reqDelta));
|
329 |
|
|
|
330 |
|
|
// 5. Round Trip Delay variation
|
331 |
|
|
subplot(8,1,5);
|
332 |
|
|
xtitle('', '', 'RTD Variation/s');
|
333 |
|
|
indexSync=find(messageId_cap==0);
|
334 |
|
|
indexFlup=find(messageId_cap==8);
|
335 |
|
|
indexSync=indexSync(find(clockId_cap(indexSync)==clockId_mastr)); // SYNC M->S
|
336 |
|
|
indexFlup=indexFlup(find(clockId_cap(indexFlup)==clockId_mastr)); // FLUP M->S
|
337 |
|
|
capturedTimestamp_sync=capturedTimestamp_cap(indexSync); // t2
|
338 |
|
|
sequenceId_sync =sequenceId_cap (indexSync);
|
339 |
|
|
embeddedTimestamp_flup=embeddedTimestamp_cap(indexFlup); // t1
|
340 |
|
|
sequenceId_flup =sequenceId_cap (indexFlup);
|
341 |
|
|
|
342 |
|
|
captured_sync={};
|
343 |
|
|
embedded_flup={};
|
344 |
|
|
for i=1:length(sequenceId_sync)
|
345 |
|
|
index=find(sequenceId_flup==sequenceId_sync(i));
|
346 |
|
|
if index==[]
|
347 |
|
|
continue;
|
348 |
|
|
else
|
349 |
|
|
captured_sync={captured_sync, capturedTimestamp_sync(i)};
|
350 |
|
|
embedded_flup={embedded_flup, embeddedTimestamp_flup(index)};
|
351 |
|
|
end
|
352 |
|
|
end
|
353 |
|
|
|
354 |
|
|
indexReq=find(messageId_cap==2);
|
355 |
|
|
indexRes=find(messageId_cap==3);
|
356 |
|
|
indexReq=indexReq(find(clockId_cap(indexReq)==clockId_slave)); // DELAY_REQ S->M
|
357 |
|
|
indexRes=indexRes(find(clockId_cap(indexRes)==clockId_mastr)); // DELAY_RES M->S
|
358 |
|
|
capturedTimestamp_req=capturedTimestamp_cap(indexReq); // t3
|
359 |
|
|
sequenceId_req =sequenceId_cap (indexReq);
|
360 |
|
|
embeddedTimestamp_res=embeddedTimestamp_cap(indexRes); // t4
|
361 |
|
|
sequenceId_res =sequenceId_cap (indexRes);
|
362 |
|
|
|
363 |
|
|
captured_req={};
|
364 |
|
|
embedded_res={};
|
365 |
|
|
for i=1:length(sequenceId_req)
|
366 |
|
|
index=find(sequenceId_res==sequenceId_req(i));
|
367 |
|
|
if index==[]
|
368 |
|
|
continue;
|
369 |
|
|
else
|
370 |
|
|
captured_req={captured_req, capturedTimestamp_req(i)};
|
371 |
|
|
embedded_res={embedded_res, embeddedTimestamp_res(index)};
|
372 |
|
|
end
|
373 |
|
|
end
|
374 |
|
|
|
375 |
|
|
captured_syncDelta=calc_delta(captured_sync);
|
376 |
|
|
embedded_flupDelta=calc_delta(embedded_flup);
|
377 |
|
|
captured_reqDelta=calc_delta(captured_req);
|
378 |
|
|
embedded_resDelta=calc_delta(embedded_res);
|
379 |
|
|
commonLength=min(length(captured_sync),length(captured_req));
|
380 |
|
|
captured_syncDelta=captured_syncDelta(1:commonLength-1);
|
381 |
|
|
embedded_flupDelta=embedded_flupDelta(1:commonLength-1);
|
382 |
|
|
captured_reqDelta=captured_reqDelta(1:commonLength-1);
|
383 |
|
|
embedded_resDelta=embedded_resDelta(1:commonLength-1);
|
384 |
|
|
plot((captured_req(2:commonLength)-capturedTimestamp_cap(1)), ((captured_syncDelta-embedded_flupDelta)+(embedded_resDelta-captured_reqDelta))/2); //((t2-t1)+(t4-t3))/2
|
385 |
|
|
|
386 |
|
|
// 6. Asymmetry
|
387 |
|
|
subplot(8,1,6);
|
388 |
|
|
xtitle('', '', 'Delay Asymmetry/s');
|
389 |
|
|
indexSync=find(messageId_cap==0);
|
390 |
|
|
indexFlup=find(messageId_cap==8);
|
391 |
|
|
indexSync=indexSync(find(clockId_cap(indexSync)==clockId_mastr)); // SYNC M->S
|
392 |
|
|
indexFlup=indexFlup(find(clockId_cap(indexFlup)==clockId_mastr)); // FLUP M->S
|
393 |
|
|
capturedTimestamp_sync=capturedTimestamp_cap(indexSync); // t2
|
394 |
|
|
sequenceId_sync =sequenceId_cap (indexSync);
|
395 |
|
|
embeddedTimestamp_flup=embeddedTimestamp_cap(indexFlup); // t1
|
396 |
|
|
sequenceId_flup =sequenceId_cap (indexFlup);
|
397 |
|
|
|
398 |
|
|
captured_sync={};
|
399 |
|
|
embedded_flup={};
|
400 |
|
|
for i=1:length(sequenceId_sync)
|
401 |
|
|
index=find(sequenceId_flup==sequenceId_sync(i));
|
402 |
|
|
if index==[]
|
403 |
|
|
continue;
|
404 |
|
|
else
|
405 |
|
|
captured_sync={captured_sync, capturedTimestamp_sync(i)};
|
406 |
|
|
embedded_flup={embedded_flup, embeddedTimestamp_flup(index)};
|
407 |
|
|
end
|
408 |
|
|
end
|
409 |
|
|
|
410 |
|
|
indexReq=find(messageId_cap==2);
|
411 |
|
|
indexRes=find(messageId_cap==3);
|
412 |
|
|
indexReq=indexReq(find(clockId_cap(indexReq)==clockId_slave)); // DELAY_REQ S->M
|
413 |
|
|
indexRes=indexRes(find(clockId_cap(indexRes)==clockId_mastr)); // DELAY_RES M->S
|
414 |
|
|
capturedTimestamp_req=capturedTimestamp_cap(indexReq); // t3
|
415 |
|
|
sequenceId_req =sequenceId_cap (indexReq);
|
416 |
|
|
embeddedTimestamp_res=embeddedTimestamp_cap(indexRes); // t4
|
417 |
|
|
sequenceId_res =sequenceId_cap (indexRes);
|
418 |
|
|
|
419 |
|
|
captured_req={};
|
420 |
|
|
embedded_res={};
|
421 |
|
|
for i=1:length(sequenceId_req)
|
422 |
|
|
index=find(sequenceId_res==sequenceId_req(i));
|
423 |
|
|
if index==[]
|
424 |
|
|
continue;
|
425 |
|
|
else
|
426 |
|
|
captured_req={captured_req, capturedTimestamp_req(i)};
|
427 |
|
|
embedded_res={embedded_res, embeddedTimestamp_res(index)};
|
428 |
|
|
end
|
429 |
|
|
end
|
430 |
|
|
|
431 |
|
|
commonLength=min(length(captured_sync),length(captured_req));
|
432 |
|
|
captured_sync=captured_sync(1:commonLength);
|
433 |
|
|
embedded_flup=embedded_flup(1:commonLength);
|
434 |
|
|
captured_req=captured_req(1:commonLength);
|
435 |
|
|
embedded_res=embedded_res(1:commonLength);
|
436 |
|
|
plot((captured_req(1:commonLength)-capturedTimestamp_cap(1)), (captured_sync-embedded_flup)-(embedded_res-captured_req)); //(t2-t1)-(t4-t3)
|
437 |
|
|
|
438 |
|
|
// 7. Sync Inter-Packet Gap
|
439 |
|
|
subplot(8,1,7);
|
440 |
|
|
xtitle('', '', 'SYNC IPG/s');
|
441 |
|
|
indexSync=find(messageId_cap==0);
|
442 |
|
|
indexSync=indexSync(find(clockId_cap(indexSync)==clockId_mastr)); // SYNC M->S
|
443 |
|
|
capturedTimestamp_sync=capturedTimestamp_cap(indexSync); // t2
|
444 |
|
|
sequenceId_sync =sequenceId_cap (indexSync);
|
445 |
|
|
|
446 |
|
|
captured_sync={};
|
447 |
|
|
for i=1:length(sequenceId_sync)
|
448 |
|
|
index=find(sequenceId_sync==sequenceId_sync(i));
|
449 |
|
|
if index==[]
|
450 |
|
|
continue;
|
451 |
|
|
else
|
452 |
|
|
captured_sync={captured_sync, capturedTimestamp_sync(index)};
|
453 |
|
|
end
|
454 |
|
|
end
|
455 |
|
|
|
456 |
|
|
captured_syncDelta=calc_delta(captured_sync);
|
457 |
|
|
plot((captured_sync(2:length(captured_sync))-capturedTimestamp_cap(1)), captured_syncDelta);
|
458 |
|
|
|
459 |
|
|
// 8. Delay-Resp Round Trip Delay
|
460 |
|
|
subplot(8,1,8);
|
461 |
|
|
xtitle('', '', 'Delay-Resp Latency/s');
|
462 |
|
|
indexReq=find(messageId_cap==2);
|
463 |
|
|
indexRes=find(messageId_cap==3);
|
464 |
|
|
indexReq=indexReq(find(clockId_cap(indexReq)==clockId_slave)); // DELAY_REQ S->M
|
465 |
|
|
indexRes=indexRes(find(clockId_cap(indexRes)==clockId_mastr)); // DELAY_RES M->S
|
466 |
|
|
capturedTimestamp_req=capturedTimestamp_cap(indexReq); // t3
|
467 |
|
|
sequenceId_req =sequenceId_cap (indexReq);
|
468 |
|
|
capturedTimestamp_res=capturedTimestamp_cap(indexRes);
|
469 |
|
|
sequenceId_res =sequenceId_cap (indexRes);
|
470 |
|
|
|
471 |
|
|
captured_req={};
|
472 |
|
|
captured_res={};
|
473 |
|
|
for i=1:length(sequenceId_req)
|
474 |
|
|
index=find(sequenceId_res==sequenceId_req(i));
|
475 |
|
|
if index==[]
|
476 |
|
|
continue;
|
477 |
|
|
else
|
478 |
|
|
captured_req={captured_req, capturedTimestamp_req(i)};
|
479 |
|
|
captured_res={captured_res, capturedTimestamp_res(index)};
|
480 |
|
|
end
|
481 |
|
|
end
|
482 |
|
|
|
483 |
|
|
plot((captured_req(1:length(captured_req))-capturedTimestamp_cap(1)), (captured_res-captured_req));
|