-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (34 loc) · 1.57 KB
/
main.py
File metadata and controls
48 lines (34 loc) · 1.57 KB
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
import sys
import time
import network_utils as nu
import binary_tree as bt
# Receiving Rule list and packet list as input arguments
rule_file = sys.argv[1]
packet_file = sys.argv[2]
# Reading all the rule entries and putting them into a list
all_rules = nu.read_rules(rule_file)
# Creating the root node
root = bt.Node()
# Converting the Rule's source and destination netIDs into the binary format and putting them into two separate lists
src_sub_binaries = [x.src_sub_binary for x in all_rules]
dst_sub_binaries = [x.dst_sub_binary for x in all_rules]
# Going through all Rule's source and destination sub binaries to create the tree
for i in range(0, len(src_sub_binaries)):
bt.add_src_nodes(root, src_sub_binaries[i], 0, dst_sub_binaries[i],i)
# Draw the tree that was created i the previous step
#bt.show(root)
# Reading all the incoming packets and putting them into a list
packets = nu.read_packets(packet_file)
# Starting the timer for measuring the Classification time
start = time.time_ns()
# Classificaton Algoritm (Matching and getting the packets actions)
actions = bt.get_packets_actions(root, packets, all_rules, False)
# Stopping the timer for measuring the Classification time
stop = time.time_ns()
# Calculating the elpased time between the start and stop of the timer
Elpased = int(stop - start)
# Calculating the average classification time
average = Elpased/len(packets)
# Printing the results of the classification (Average Time)
print("It took %d ns to classify %d packets" % (Elpased,len(packets)))
print("The average time for each packet is %d ns" % average)