Skip to content

Commit 0afd3cf

Browse files
authored
save dst port in json (#34)
1 parent 17b143e commit 0afd3cf

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

utils/trace.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,47 +214,56 @@ def initialize_first_nodes(request_ips):
214214

215215

216216
def initialize_json_first_nodes(
217-
request_ips, annotation_1, annotation_2, packet_1_proto, packet_2_proto):
217+
request_ips, annotation_1, annotation_2, packet_1_proto, packet_2_proto,
218+
packet_1_port, packet_2_port):
218219
# source_address = get_if_addr(conf.iface) #todo: xhdix
219220
source_address = SOURCE_IP_ADDRESS
220221
start_time = int(datetime.utcnow().timestamp())
221222
for request_ip in request_ips:
222223
measurement_data[0].append(
223224
traceroute_data(
224225
dst_addr=request_ip, annotation=annotation_1,
225-
src_addr=source_address, proto=packet_1_proto, timestamp=start_time
226+
src_addr=source_address, proto=packet_1_proto, port=packet_1_port,
227+
timestamp=start_time
226228
)
227229
)
228230
if have_2_packet:
229231
measurement_data[1].append(
230232
traceroute_data(
231233
dst_addr=request_ip, annotation=annotation_2,
232-
src_addr=source_address, proto=packet_2_proto, timestamp=start_time
234+
src_addr=source_address, proto=packet_2_proto, port=packet_2_port,
235+
timestamp=start_time
233236
)
234237
)
235238

236239

237-
def get_proto(request_packets):
240+
def get_packets_info(request_packets):
238241
packet_1_proto = ""
239242
packet_2_proto = ""
243+
packet_1_port = -1
244+
packet_2_port = -1
240245
if (request_packets[0]).haslayer(IP):
241246
packet_1_proto = "IP"
242247
if (request_packets[0]).haslayer(TCP):
243248
packet_1_proto = "TCP"
249+
packet_1_port = request_packets[0][TCP].dport
244250
elif (request_packets[0]).haslayer(UDP):
245251
packet_1_proto = "UDP"
252+
packet_1_port = request_packets[0][UDP].dport
246253
elif(request_packets[0]).haslayer(ICMP):
247254
packet_1_proto = "ICMP"
248255
if have_2_packet:
249256
if (request_packets[1]).haslayer(IP):
250257
packet_2_proto = "IP"
251258
if (request_packets[1]).haslayer(TCP):
252259
packet_2_proto = "TCP"
260+
packet_2_port = request_packets[1][TCP].dport
253261
elif (request_packets[1]).haslayer(UDP):
254262
packet_2_proto = "UDP"
263+
packet_2_port = request_packets[1][UDP].dport
255264
elif(request_packets[1]).haslayer(ICMP):
256265
packet_2_proto = "ICMP"
257-
return packet_1_proto, packet_2_proto
266+
return packet_1_proto, packet_2_proto, packet_1_port, packet_2_port
258267

259268

260269
def save_measurement_data(
@@ -352,10 +361,11 @@ def trace_route(
352361
else:
353362
measurement_name = "tracevis-" + datetime.utcnow().strftime("%Y%m%d-%H%M")
354363
repeat_all_steps = 0
355-
packet_1_proto, packet_2_proto = get_proto(request_packets)
364+
packet_1_proto, packet_2_proto, packet_1_port, packet_2_port = get_packets_info(request_packets)
356365
initialize_json_first_nodes(
357366
request_ips=request_ips, annotation_1=annotation_1, annotation_2=annotation_2,
358-
packet_1_proto=packet_1_proto, packet_2_proto=packet_2_proto
367+
packet_1_proto=packet_1_proto, packet_2_proto=packet_2_proto,
368+
packet_1_port=packet_1_port, packet_2_port=packet_2_port
359369
)
360370
print("- · - · - - · - · - - · - · - - · - · -")
361371
while repeat_all_steps < 3:

utils/traceroute_struct.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class traceroute_data:
66
def __init__(
7-
self, dst_addr: str, annotation: str, proto: str, timestamp: int,
7+
self, dst_addr: str, annotation: str, proto: str, port: int, timestamp: int,
88
src_addr: str = "127.0.0.2", from_ip: str = "127.0.0.1",
99
prb_id: int = -1, msm_id: int = -1, msm_name: str = "traceroute",
1010
ttr: float = -1, af: int = 4, lts: int = -1, paris_id: int = -1,
@@ -22,6 +22,7 @@ def __init__(
2222
self.paris_id = paris_id
2323
self.prb_id = prb_id
2424
self.proto = proto
25+
self.port = port
2526
self.result = []
2627
self.size = size
2728
self.src_addr = src_addr

0 commit comments

Comments
 (0)