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

Commit d416ba7

Browse files
author
Joshua Reich
committed
empty set of actions means same a drop
1 parent 2d140ae commit d416ba7

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

pyretic/core/classifier.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Rule(object):
1313
"""
1414

1515
# Matches m should be of the match class. Actions acts should be a set of
16-
# modify, identity, drop, and/or Controller/CountBucket/FwdBucket policies.
16+
# modify, identity, and/or Controller/CountBucket/FwdBucket policies.
1717
# Actions is Rule are semantically meant to run in parallel
1818
# unlike OpenFlow rules.
1919
def __init__(self,m,acts):
@@ -126,14 +126,13 @@ def __copy__(self):
126126

127127
### NEGATE ###
128128
def __invert__(self):
129-
from pyretic.core.language import drop, identity
129+
from pyretic.core.language import identity
130130
c = copy.copy(self)
131131
for r in c.rules:
132-
assert len(r.actions) == 1
133-
if r.actions == {identity}:
134-
r.actions = {drop}
135-
elif r.actions == {drop}:
132+
if len(r.actions) == 0:
136133
r.actions = {identity}
134+
elif r.actions == {identity}:
135+
r.actions = set()
137136
else:
138137
raise TypeError # TODO MAKE A CompileError TYPE
139138
return c
@@ -149,8 +148,6 @@ def _cross(r1,r2):
149148
# TODO (josh) logic for detecting when sets of actions can't be combined
150149
# e.g., [modify(dstip='10.0.0.1'),fwd(1)] + [modify(srcip='10.0.0.2'),fwd(2)]
151150
actions = r1.actions | r2.actions
152-
if len(actions) > 1:
153-
actions.discard(drop)
154151
return Rule(intersection, actions)
155152
else:
156153
return None
@@ -166,7 +163,7 @@ def _cross(r1,r2):
166163
c3.append(crossed_r)
167164
# if the classifier is empty, add a drop-all rule
168165
if len(c3) == 0:
169-
c3.append(Rule(identity,{drop}))
166+
c3.append(Rule(identity,set()))
170167
# and optimize the classifier
171168
else:
172169
c3 = c3.optimize()
@@ -184,8 +181,6 @@ def _commute_test(act, pkts):
184181
act = act.policy
185182
if act == identity:
186183
return pkts
187-
elif act == drop:
188-
return drop
189184
elif act == Controller or isinstance(act, CountBucket):
190185
return identity
191186
elif isinstance(act, modify):
@@ -224,9 +219,7 @@ def _sequence_actions(a1, as2):
224219
for a2 in as2:
225220
while isinstance(a2, DerivedPolicy):
226221
a2 = a2.policy
227-
if a2 == drop:
228-
new_actions.add(drop)
229-
elif a2 == Controller or isinstance(a2, CountBucket):
222+
if a2 == Controller or isinstance(a2, CountBucket):
230223
new_actions.add(a2)
231224
elif a2 == identity:
232225
new_actions.add(a1)
@@ -276,7 +269,7 @@ def _cross(r1,r2):
276269
# then for each rule in the first classifier (self)
277270
c3 = Classifier()
278271
for r1 in c1.rules:
279-
if r1.actions == {drop}:
272+
if len(r1.actions) == 0:
280273
c3.append(r1)
281274
else:
282275
for r2 in c2.rules:

pyretic/core/language.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ def eval(self, pkt):
265265
"""
266266
return set()
267267

268+
def generate_classifier(self):
269+
return Classifier([Rule(identity,set())])
270+
268271
def intersect(self, other):
269272
return self
270273

@@ -330,7 +333,7 @@ def eval(self, pkt):
330333

331334
def generate_classifier(self):
332335
r1 = Rule(self,{identity})
333-
r2 = Rule(identity,{drop})
336+
r2 = Rule(identity,set())
334337
return Classifier([r1, r2])
335338

336339
def __eq__(self, other):

pyretic/core/runtime.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,6 @@ def install_classifier(self, classifier):
330330

331331
### CLASSIFIER TRANSFORMS
332332

333-
def remove_drop(classifier):
334-
"""
335-
Removes drop policies from the action list.
336-
337-
:param classifier: the input classifer
338-
:type classifier: Classifier
339-
:returns: the output classifier
340-
:rtype: Classifier
341-
"""
342-
return Classifier(Rule(rule.match,
343-
filter(lambda a: a != drop,rule.actions))
344-
for rule in classifier.rules)
345-
346333
def remove_identity(classifier):
347334
"""
348335
Removes identity policies from the action list.
@@ -746,7 +733,6 @@ def f(classifier):
746733

747734
# Process classifier to an openflow-compatible format before
748735
# sending out rule installs
749-
classifier = remove_drop(classifier)
750736
#classifier = send_drops_to_controller(classifier)
751737
classifier = remove_identity(classifier)
752738
classifier = controllerify(classifier)

0 commit comments

Comments
 (0)