This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
profile-builder.py
executable file
·222 lines (199 loc) · 11.2 KB
/
profile-builder.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
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
#!/bin/python
from __future__ import print_function
import argparse
from trex_tg_lib import *
class t_global(object):
args = None
def process_options ():
parser = argparse.ArgumentParser(usage="postprocess a TRex profile")
parser.add_argument('--frame-size',
dest='frame_size',
help='L2 frame size in bytes',
default="64",
type = int
)
parser.add_argument('--num-flows',
dest='num_flows',
help='Number of unique network flows',
default=1024,
type = int,
)
parser.add_argument('--use-src-ip-flows',
dest='use_src_ip_flows',
help='Implement flows by source IP',
action = 'store_true',
)
parser.add_argument('--use-dst-ip-flows',
dest='use_dst_ip_flows',
help='Implement flows by destination IP',
action = 'store_true',
)
parser.add_argument('--use-src-mac-flows',
dest='use_src_mac_flows',
help='Implement flows by source MAC',
action = 'store_true',
)
parser.add_argument('--use-dst-mac-flows',
dest='use_dst_mac_flows',
help='Implement flows by destination MAC',
action = 'store_true',
)
parser.add_argument('--use-src-port-flows',
dest='use_src_port_flows',
help='Implement flows by source port',
action = 'store_true',
)
parser.add_argument('--use-dst-port-flows',
dest='use_dst_port_flows',
help='Implement flows by destination port',
action = 'store_true',
)
parser.add_argument('--use-protocol-flows',
dest='use_protocol_flows',
help='Implement flows by IP protocol',
action = 'store_true',
)
parser.add_argument('--rate',
dest='rate',
help='Packet rate per device per stream (mpps)',
default = 1.0,
type = float
)
parser.add_argument('--measure-latency',
dest='measure_latency',
help='Collect latency statistics or not',
action = 'store_true',
)
parser.add_argument('--send-teaching-warmup',
dest='send_teaching_warmup',
help='Send teaching packets from the receiving port during a warmup phase',
action = 'store_true',
)
parser.add_argument('--send-teaching-measurement',
dest='send_teaching_measurement',
help='Send teaching packets from the receiving port during the measurement phase',
action = 'store_true',
)
parser.add_argument('--teaching-warmup-packet-type',
dest='teaching_warmup_packet_type',
help='Type of packet to send for the teaching warmup from the receiving port',
default = 'generic',
choices = ['garp', 'icmp', 'generic']
)
parser.add_argument('--teaching-measurement-packet-type',
dest='teaching_measurement_packet_type',
help='Type of packet to send for the teaching measurement from the receiving port',
default = 'generic',
choices = ['garp', 'icmp', 'generic']
)
parser.add_argument('--teaching-warmup-packet-rate',
dest='teaching_warmup_packet_rate',
help='Rate to send teaching packets at from the receiving port in packets per second (pps) during the warmup',
default = 1000,
type = int
)
parser.add_argument('--teaching-measurement-packet-rate',
dest='teaching_measurement_packet_rate',
help='Rate to send teaching packets at from the receiving port in packets per second (pps) during the measurement phase',
default = 1000,
type = int
)
parser.add_argument('--traffic-direction',
dest='traffic_direction',
help='What direction is the traffic flow?',
default = 'bidirectional',
choices = ['bidirectional', 'unidirectional', 'revunidirectional']
)
parser.add_argument('--packet-protocol',
dest='packet_protocol',
help='IP protocol to use when constructing packets',
default = "UDP",
choices = [ 'UDP', 'TCP' ]
)
t_global.args = parser.parse_args()
return(0)
def main ():
ret_val = process_options()
if ret_val:
print(error("Input Error"))
return(ret_val)
profile = { 'streams': [] }
flow_mods = create_flow_mod_object(use_src_mac_flows = t_global.args.use_src_mac_flows,
use_dst_mac_flows = t_global.args.use_dst_mac_flows,
use_src_ip_flows = t_global.args.use_src_ip_flows,
use_dst_ip_flows = t_global.args.use_dst_ip_flows,
use_src_port_flows = t_global.args.use_src_port_flows,
use_dst_port_flows = t_global.args.use_dst_port_flows,
use_protocol_flows = t_global.args.use_protocol_flows)
stream_id = "built-by-profile-builder"
integrated_teaching_warmup = t_global.args.send_teaching_warmup
dedicated_teaching_warmup = False
if t_global.args.send_teaching_warmup and t_global.args.teaching_warmup_packet_type != 'generic':
dedicated_teaching_warmup = True
integrated_teaching_warmup = False
integrated_teaching_measurement = t_global.args.send_teaching_measurement
dedicated_teaching_measurement = False
if t_global.args.send_teaching_measurement and t_global.args.teaching_measurement_packet_type != 'generic':
dedicated_teaching_measurement = True
integrated_teaching_measurement = False
stream = create_profile_stream(flows = t_global.args.num_flows,
frame_size = t_global.args.frame_size,
flow_mods = flow_mods,
rate = t_global.args.rate * 1000000.0,
frame_type = 'generic',
measurement = True,
teaching_warmup = integrated_teaching_warmup,
teaching_measurement = integrated_teaching_measurement,
latency = t_global.args.measure_latency,
protocol = t_global.args.packet_protocol,
traffic_direction = t_global.args.traffic_direction,
stream_id = stream_id)
profile['streams'].append(stream)
if dedicated_teaching_warmup or dedicated_teaching_measurement:
if dedicated_teaching_warmup and dedicated_teaching_measurement and t_global.args.teaching_warmup_packet_type == t_global.args.teaching_measurement_packet_type and t_global.args.teaching_warmup_packet_rate == t_global.args.teaching_measurement_packet_rate:
stream = create_profile_stream(flows = t_global.args.num_flows,
frame_size = t_global.args.frame_size,
flow_mods = flow_mods,
rate = t_global.args.teaching_warmup_packet_rate,
frame_type = t_global.args.teaching_warmup_packet_type,
measurement = False,
teaching_warmup = True,
teaching_measurement = True,
latency = False,
protocol = t_global.args.packet_protocol,
traffic_direction = t_global.args.traffic_direction,
stream_id = stream_id)
profile['streams'].append(stream)
else:
if dedicated_teaching_warmup:
stream = create_profile_stream(flows = t_global.args.num_flows,
frame_size = t_global.args.frame_size,
flow_mods = flow_mods,
rate = t_global.args.teaching_warmup_packet_rate,
frame_type = t_global.args.teaching_warmup_packet_type,
measurement = False,
teaching_warmup = True,
teaching_measurement = False,
latency = False,
protocol = t_global.args.packet_protocol,
traffic_direction = t_global.args.traffic_direction,
stream_id = stream_id)
profile['streams'].append(stream)
if dedicated_teaching_measurement:
stream = create_profile_stream(flows = t_global.args.num_flows,
frame_size = t_global.args.frame_size,
flow_mods = flow_mods,
rate = t_global.args.teaching_measurement_packet_rate,
frame_type = t_global.args.teaching_measurement_packet_type,
measurement = False,
teaching_warmup = False,
teaching_measurement = True,
latency = False,
protocol = t_global.args.packet_protocol,
traffic_direction = t_global.args.traffic_direction,
stream_id = stream_id)
profile['streams'].append(stream)
print(dump_json_readable(profile))
return(0)
if __name__ == "__main__":
exit(main())