Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit d542003

Browse files
author
Joshua Reich
committed
detect sub_policies whose classifiers have been invalidated
1 parent 2b939ee commit d542003

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

pyretic/core/language.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def eval(self, pkt):
7373
"""
7474
raise NotImplementedError
7575

76+
def invalidate_classifier(self):
77+
self._classifier = None
78+
7679
def compile(self):
7780
"""
7881
Produce a Classifier for this policy
@@ -1064,7 +1067,7 @@ def detach(self):
10641067

10651068
def changed(self):
10661069
if self.notify:
1067-
self.notify()
1070+
self.notify(self)
10681071

10691072
@property
10701073
def policy(self):
@@ -1242,6 +1245,38 @@ def queries_in_eval(acc, policy):
12421245
return acc
12431246

12441247

1248+
def on_recompile_path(acc,pol_id,policy):
1249+
if ( policy == identity or
1250+
policy == drop or
1251+
isinstance(policy,match) or
1252+
isinstance(policy,modify) or
1253+
policy == Controller or
1254+
isinstance(policy,Query)):
1255+
return set()
1256+
elif (isinstance(policy,negate) or
1257+
isinstance(policy,parallel) or
1258+
isinstance(policy,union) or
1259+
isinstance(policy,sequential) or
1260+
isinstance(policy,intersection)):
1261+
sub_acc = set()
1262+
for sub_policy in policy.policies:
1263+
sub_acc |= on_recompile_path(sub_acc,pol_id,sub_policy)
1264+
if sub_acc:
1265+
return acc | {policy} | sub_acc
1266+
else:
1267+
return sub_acc
1268+
elif isinstance(policy,DerivedPolicy):
1269+
if id(policy) == pol_id:
1270+
return acc | {policy}
1271+
else:
1272+
sub_acc = on_recompile_path(set(),pol_id,policy.policy)
1273+
if sub_acc:
1274+
return acc | {policy} | sub_acc
1275+
else:
1276+
return set()
1277+
else:
1278+
raise NotImplementedError
1279+
12451280

12461281
###############################################################################
12471282
# Classifiers

pyretic/core/runtime.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ def handle_packet_in(self, concrete_pkt):
124124
# DYNAMICS
125125
#############
126126

127-
def handle_policy_change(self):
127+
def handle_policy_change(self,sub_pol):
128128
"""
129129
Updates runtime behavior (both interpreter and switch classifiers)
130130
some sub-policy in self.policy changes.
131131
"""
132+
map(lambda p: p.invalidate_classifier(),
133+
on_recompile_path(set(),id(sub_pol),self.policy))
134+
132135
if self.in_update_network:
133136
return
134137

0 commit comments

Comments
 (0)