-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathone_sim.py
35 lines (28 loc) · 1.04 KB
/
one_sim.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
received_packets = set()
dropped_packets = set()
count = 0
count2 = 0
count3 = 0
count4 = 0
with open('aloha_1sim.nam', 'r') as file:
for line in file:
if line.startswith('r') :
packet_info = line.split()
dest_addr = packet_info[2]
if (dest_addr) not in received_packets:
count += 1
received_packets.add(dest_addr)
if line.startswith('d'):
packet_info = line.split()
dest_addr = packet_info[2]
if (dest_addr) not in dropped_packets:
count2 += 1
dropped_packets.add(dest_addr)
if line.startswith('+'):
count3+=1
if line.startswith('-'):
count4+=1
print('Total received packets: ', count)
print('Total dropped packet count: ', count3-count)
print('Enqueued packets: ', count3)
print('Dequeued packets: ', count4)