@@ -534,7 +534,7 @@ def concretize_action(a):
534
534
crs = filter (lambda cr : not cr is None ,crs )
535
535
return Classifier (crs )
536
536
537
- def portize (classifier , switch_to_attrs ):
537
+ def OF_inportize (classifier ):
538
538
"""
539
539
Specialize classifier to ensure that packets to be forwarded
540
540
out the inport on which they arrived are handled correctly.
@@ -545,25 +545,42 @@ def portize(classifier,switch_to_attrs):
545
545
:rtype: Classifier
546
546
"""
547
547
import copy
548
+ def specialize_actions (actions ,outport ):
549
+ new_actions = copy .deepcopy (actions )
550
+ for action in new_actions :
551
+ try :
552
+ if action ['outport' ] == outport :
553
+ action ['outport' ] = OFPP_IN_PORT
554
+ except :
555
+ raise TypeError # INVARIANT: every set of actions must go out a port
556
+ # this may not hold when we move to OF 1.3
557
+ return new_actions
558
+
548
559
specialized_rules = []
549
560
for rule in classifier .rules :
561
+ phys_actions = filter (lambda a : (a ['outport' ] != OFPP_CONTROLLER
562
+ and a ['outport' ] != OFPP_IN_PORT ),
563
+ rule .actions )
564
+ outports_used = map (lambda a : a ['outport' ], phys_actions )
550
565
if not 'inport' in rule .match :
551
- phys_actions = filter (lambda a : a ['outport' ] != OFPP_CONTROLLER and a ['outport' ] != OFPP_IN_PORT ,rule .actions )
552
- outports_used = map (lambda a : a ['outport' ], phys_actions )
566
+ # Add a modified rule for each of the outports_used
553
567
switch = rule .match ['switch' ]
554
568
for outport in outports_used :
555
569
new_match = copy .deepcopy (rule .match )
556
570
new_match ['inport' ] = outport
557
- new_actions = copy .deepcopy (rule .actions )
558
- for action in new_actions :
559
- try :
560
- if action ['outport' ] == outport :
561
- action ['outport' ] = OFPP_IN_PORT
562
- except :
563
- raise TypeError # INVARIANT: every set of actions must go out a port
564
- # this may not hold when we move to OF 1.3
571
+ new_actions = specialize_actions (rule .actions ,outport )
565
572
specialized_rules .append (Rule (new_match ,new_actions ))
566
- specialized_rules .append (rule )
573
+ # And a default rule for any inport outside the set of outports_used
574
+ specialized_rules .append (rule )
575
+ else :
576
+ if rule .match ['inport' ] in outports_used :
577
+ # Modify the set of actions
578
+ new_actions = specialize_actions (rule .actions ,rule .match ['inport' ])
579
+ specialized_rules .append (Rule (rule .match ,new_actions ))
580
+ else :
581
+ # Leave as before
582
+ specialized_rules .append (rule )
583
+
567
584
return Classifier (specialized_rules )
568
585
569
586
def prioritize (classifier ):
@@ -601,7 +618,7 @@ def nuclear_install(classifier):
601
618
switches = switch_to_attrs .keys ()
602
619
classifier = switchify (classifier ,switches )
603
620
classifier = concretize (classifier )
604
- classifier = portize (classifier , switch_to_attrs )
621
+ classifier = OF_inportize (classifier )
605
622
new_rules = prioritize (classifier )
606
623
607
624
for s in switches :
@@ -643,7 +660,7 @@ def install_diff_rules(classifier):
643
660
switches = switch_to_attrs .keys ()
644
661
classifier = switchify (classifier ,switches )
645
662
classifier = concretize (classifier )
646
- classifier = portize (classifier , switch_to_attrs )
663
+ classifier = OF_inportize (classifier )
647
664
new_rules = prioritize (classifier )
648
665
649
666
# calculate diff
0 commit comments