class SRule_r(SRule): ''' Applies the transformation on one match. ''' def __init__(self, LHS, RHS, external_matches_only=False, custom_resolution=lambda packet: False): ''' Applies the transformation as long as matches can be found. @param LHS: The pre-condition pattern (LHS + NACs). @param RHS: The post-condition pattern (RHS). @param max_iterations: The maximum number of times to apply the transformation. @param external_matches_only: Resolve conflicts ignoring the matches found in this FRule. @param custom_resolution: Override the default resolution function. ''' super(SRule_r, self).__init__() self.R = Resolver(external_matches_only=external_matches_only, custom_resolution=custom_resolution) def packet_in(self, packet): self.exception = None self.is_success = False # Match packet = self.M.packet_in(packet) if not self.M.is_success: self.exception = self.M.exception return packet # Choose the first match packet = self.I.packet_in(packet) if not self.I.is_success: self.exception = self.I.exception return packet while True: # Rewrite packet = self.W.packet_in(packet) if not self.W.is_success: self.exception = self.W.exception return packet # Resolve any conflicts if necessary packet = self.R.packet_in(packet) if not self.R.is_success: self.exception = self.R.exception return packet # Rule has been applied once, so it's a success anyway self.is_success = True if self.I.iterations == self.I.max_iterations: return packet # Re-Match packet = self.M.packet_in(packet) if not self.M.is_success: self.exception = self.M.exception return packet # Choose another match packet = self.I.next_in(packet) # No more iterations are left if not self.I.is_success: if self.I.exception: self.exception = self.I.exception return packet
class XRule_r(XRule): ''' Applies the transformation on one match with roll-back capability. ''' def __init__(self, LHS, RHS, external_matches_only=False, custom_resolution=lambda packet: False): ''' Applies the transformation on one match with roll-back capability. @param LHS: The pre-condition pattern (LHS + NACs). @param RHS: The post-condition pattern (RHS). @param external_matches_only: Resolve conflicts ignoring the matches found in this ARule. @param custom_resolution: Override the default resolution function. ''' super(XRule_r, self).__init__() self.R = Resolver(external_matches_only=external_matches_only, custom_resolution=custom_resolution) def packet_in(self, packet): packet = super(XRule_r, self).packet_in(packet) # is_success is True if self.exception is None: # Resolve any conflicts if necessary packet = self.R.packet_in(packet) if not self.R.is_success: self.exception = self.R.exception return packet # Output success packet else: self.is_success = False return packet def next_in(self, packet): packet = super(XRule_r, self).next_in(packet) # is_success is True if self.exception is None: # Resolve any conflicts if necessary packet = self.R.packet_in(packet) if not self.R.is_success: self.exception = self.R.exception return packet # Output success packet else: self.is_success = False return packet
def __init__(self, LHS, RHS, external_matches_only=False, custom_resolution=lambda packet: False): """ Applies the transformation as long as matches can be found with roll-back capability. @param LHS: The pre-condition pattern (LHS + NACs). @param RHS: The post-condition pattern (RHS). @param max_iterations: The maximum number of times to apply the rule. @param external_matches_only: Resolve conflicts ignoring the matches found in this FRule. @param custom_resolution: Override the default resolution function. """ super(XSRule_r, self).__init__() self.R = Resolver(external_matches_only=external_matches_only, custom_resolution=custom_resolution)
def __init__(self, LHS, RHS, external_matches_only=False, custom_resolution=lambda packet: False): ''' Applies the transformation on one match with roll-back capability. @param LHS: The pre-condition pattern (LHS + NACs). @param RHS: The post-condition pattern (RHS). @param external_matches_only: Resolve conflicts ignoring the matches found in this ARule. @param custom_resolution: Override the default resolution function. ''' super(XRule_r, self).__init__() self.R = Resolver(external_matches_only=external_matches_only, custom_resolution=custom_resolution)
def __init__(self, LHS, RHS, external_matches_only=False, custom_resolution=lambda packet: False): """ Applies an inner rule for each application of the outer rule. @param LHS: The pre-condition pattern (LHS + NACs). @param RHS: The post-condition pattern (RHS). @param inner_rule: The rule to apply in the loop. @param outer_first: Whether the outer rule should be applied before the inner rule. @param max_iterations: The maximum number of matches of the LHS. @param external_matches_only: Resolve conflicts ignoring the matches found in this FRule. @param custom_resolution: Override the default resolution function. """ super(LFRule_r, self).__init__() self.R = Resolver(external_matches_only=external_matches_only, custom_resolution=custom_resolution)
class XFRule_r(XFRule): ''' Applies the transformation on one match. ''' def __init__(self, LHS, RHS, external_matches_only=False, custom_resolution=lambda packet: False): ''' Applies the transformation on all matches found with roll-back capability. @param LHS: The pre-condition pattern (LHS + NACs). @param RHS: The post-condition pattern (RHS). @param max_iterations: The maximum number of times to apply the rule. @param external_matches_only: Resolve conflicts ignoring the matches found in this FRule. @param custom_resolution: Override the default resolution function. ''' super(XFRule_r, self).__init__() self.R = Resolver(external_matches_only=external_matches_only, custom_resolution=custom_resolution) def packet_in(self, packet): self.exception = None self.is_success = False # Checkpoint the original packet self.B.packet_in(packet) if not self.B.is_success: self.exception = self.B.exception return packet # Match packet = self.M.packet_in(packet) if not self.M.is_success: packet = self.B.restore(packet) if self.M.exception: self.exception = self.M.exception elif self.B.exception: self.exception = self.B.exception return packet # Choose the first match packet = self.I.packet_in(packet) if not self.I.is_success: packet = self.B.restore(packet) if self.I.exception: self.exception = self.I.exception elif self.B.exception: self.exception = self.B.exception return packet while True: # Rewrite packet = self.W.packet_in(packet) if not self.W.is_success: packet = self.B.restore(packet) if self.W.exception: self.exception = self.W.exception elif self.B.exception: self.exception = self.B.exception return packet # Resolve any conflicts if necessary packet = self.R.packet_in(packet) if not self.R.is_success: self.exception = self.R.exception return packet # Choose another match packet = self.I.next_in(packet) # No more iterations are left if not self.I.is_success: if self.I.exception: packet = self.B.restore(packet) if self.B.exception: self.exception = self.B.exception self.exception = self.I.exception self.is_success = False else: # Output success packet self.is_success = True return packet
class LFRule_r(LFRule): """ Applies an inner rule for each application of the outer rule. """ def __init__(self, LHS, RHS, external_matches_only=False, custom_resolution=lambda packet: False): """ Applies an inner rule for each application of the outer rule. @param LHS: The pre-condition pattern (LHS + NACs). @param RHS: The post-condition pattern (RHS). @param inner_rule: The rule to apply in the loop. @param outer_first: Whether the outer rule should be applied before the inner rule. @param max_iterations: The maximum number of matches of the LHS. @param external_matches_only: Resolve conflicts ignoring the matches found in this FRule. @param custom_resolution: Override the default resolution function. """ super(LFRule_r, self).__init__() self.R = Resolver(external_matches_only=external_matches_only, custom_resolution=custom_resolution) def packet_in(self, packet): self.exception = None self.is_success = False # Match packet = self.M.packet_in(packet) if not self.M.is_success: self.exception = self.M.exception return packet # Choose the first match packet = self.I.packet_in(packet) if not self.I.is_success: self.exception = self.I.exception return packet while True: if self.outer_first: # Rewrite packet = self.W.packet_in(packet) if not self.W.is_success: self.exception = self.W.exception return packet # Resolve any conflicts if necessary packet = self.R.packet_in(packet) if not self.R.is_success: self.exception = self.R.exception return packet # Apply the inner rule packet = self.inner_rule.packet_in(packet) if not self.inner_rule.is_success: self.exception = self.inner_rule.exception return packet if not self.outer_first: # Rewrite packet = self.W.packet_in(packet) if not self.W.is_success: self.exception = self.W.exception return packet # Resolve any conflicts if necessary packet = self.R.packet_in(packet) if not self.R.is_success: self.exception = self.R.exception return packet # Choose another match packet = self.I.next_in(packet) # No more iterations are left if not self.I.is_success: if self.I.exception: self.exception = self.I.exception else: # Output success packet self.is_success = True return packet