-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_ikev2_handshake.py
70 lines (52 loc) · 1.77 KB
/
process_ikev2_handshake.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2020-08-17 02:51:30
import os
import sys
import glob
import dpkt
import numpy as np
def process_ipsec_ecc_handshake_pcap(pcap_filepath):
assert os.path.exists(pcap_filepath)
assert os.path.isfile(pcap_filepath)
start = 0
ret = []
cnt = 0
with open(pcap_filepath, 'rb') as fp:
pcap_reader = dpkt.pcap.Reader(fp)
for ts, buf in pcap_reader:
if start == 0:
start = ts
eth = dpkt.ethernet.Ethernet(buf)
ip = eth.data
udp = ip.data
ret.append((ts - start, len(udp.data)))
cnt += 1
if cnt >= 4:
break
key_exchange_time = ret[1][0]
total_time = ret[3][0]
total_packet_size = sum([pkt[1] for pkt in ret])
return key_exchange_time, total_time, total_packet_size
def main(data_dir):
pcap_path_pattern = os.path.join(data_dir, 'ipsec_eval_handshake_*.pcap')
pcap_list = glob.glob(pcap_path_pattern)
key_exchange_times = []
total_times = []
total_packet_sizes = []
for pcap_filepath in pcap_list:
data = process_ipsec_ecc_handshake_pcap(pcap_filepath)
key_exchange_times.append(data[0])
total_times.append(data[1])
total_packet_sizes.append(data[2])
print('Key exchange time: %f (avg), %f (std dev)' % (
np.mean(key_exchange_times), np.std(key_exchange_times)))
print('Total time: %f (avg), %f (std dev)' % (
np.mean(total_times), np.std(total_times)))
print('Total packet size: %f (avg), %f (std dev)' % (
np.mean(total_packet_sizes), np.std(total_packet_sizes)))
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.exit(1)
data_dir = sys.argv[1]
main(data_dir)