-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcentralized_verification.py
More file actions
31 lines (30 loc) · 1.15 KB
/
centralized_verification.py
File metadata and controls
31 lines (30 loc) · 1.15 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
# DFA: nx.DiGraph()
# FIB: list of rules/dicts?
def centralized_verification(DFA, FIB):
# Local check
for vnode in DFA.nodes():
vnode.violation = set()
for entry in get_fib(FIB, vnode.node):
if entry.action not in vnode.next_hop:
vnode.violation.add(entry.match)
# Back propagation. Reverse topological sort.
degrees = dict()
queue = []
for vnode in DFA.nodes():
degrees[vnode] = len(DFA.successors(vnode))
if degrees[vnode] == 0:
queue.append(vnode)
while queue:
cur = queue.pop(0)
# Update violation set from next_hop
for entry in get_fib(FIB, vnode.node):
if entry.action in vnode.next_hop:
vnode.violation = vnode.violation \
.union( vnode.next_hop[entry.action].violation
.intersection(entry.match) )
# Decrease the remaining out-degrees of predecessors
for pred in DFA.predecessors(vnode):
degrees[pred] = degrees[pred] - 1
# Add to queue when all successors are done
if degrees[pred] == 0:
queue.append(pred)