diff --git a/tcore_package/tcore_package/examples/mutex/ALAP.py b/tcore_package/tcore_package/examples/mutex/ALAP.py new file mode 100644 index 0000000..bacb7fc --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/ALAP.py @@ -0,0 +1,72 @@ + +from t_core.composer import Composer +from tc_python.frule import FRule +from HGiveRuleLHS import HGiveRuleLHS +from HGiveRuleRHS import HGiveRuleRHS +from HReleaseRuleLHS import HReleaseRuleLHS +from HReleaseRuleRHS import HReleaseRuleRHS +from HRequestSimpleRuleLHS import HRequestSimpleRuleLHS +from HRequestSimpleRuleRHS import HRequestSimpleRuleRHS +from HTakeRuleLHS import HTakeRuleLHS +from HTakeRuleRHS import HTakeRuleRHS + + +class AsLongAsPossible(Composer): + def __init__(self, N, debug_folder=''): + super(AsLongAsPossible, self).__init__() + self.length = 0 + self.debug_suffix = 'alap' + self.debug_folder = debug_folder + self.N = N + self.ReleaseRule = FRule(HReleaseRuleLHS(), HReleaseRuleRHS(), max_iterations=N, ignore_resolver=True) + self.GiveRule = FRule(HGiveRuleLHS(), HGiveRuleRHS(), max_iterations=N, ignore_resolver=True) + self.RequestSimpleRule = FRule(HRequestSimpleRuleLHS(), HRequestSimpleRuleRHS(), max_iterations=N, ignore_resolver=True) + self.TakeRule = FRule(HTakeRuleLHS(), HTakeRuleRHS(), max_iterations=N, ignore_resolver=True) + + def packet_in(self, packet): + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Release + packet = self.ReleaseRule.packet_in(packet) + packet.clean() + if not self.ReleaseRule.is_success: + if self.ReleaseRule.exception is not None: + self.exception = self.ReleaseRule.exception + return packet + self.length += self.ReleaseRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Give + packet = self.GiveRule.packet_in(packet) + packet.clean() + if not self.GiveRule.is_success: + if self.GiveRule.exception is not None: + self.exception = self.GiveRule.exception + return packet + self.length += self.GiveRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Request + packet = self.RequestSimpleRule.packet_in(packet) + packet.clean() + if not self.RequestSimpleRule.is_success: + if self.RequestSimpleRule.exception is not None: + self.exception = self.RequestSimpleRule.exception + return packet + self.length += self.RequestSimpleRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Take + packet = self.TakeRule.packet_in(packet) + packet.clean() + if not self.TakeRule.is_success: + if self.TakeRule.exception is not None: + self.exception = self.TakeRule.exception + return packet + self.length += self.TakeRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + self.is_success = True + return packet + + diff --git a/tcore_package/tcore_package/examples/mutex/HBlockedRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HBlockedRuleLHS.py new file mode 100644 index 0000000..febf869 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HBlockedRuleLHS.py @@ -0,0 +1,240 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HBlockedRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HBlockedRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 4), (2, 1), (3, 2)] + + super(HBlockedRuleLHS, self).__init__(name='HBlockedRuleLHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L25781605398516429218136079497349662553L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L189113243710121451020345705446107178214L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L207744363826058715471754082471395483563L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L6878234180695968092962607642541102622L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L181383295724235727119496965625160452114L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L161807320235662615371860062293447749265L +sb.""") + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name3(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HBlockedRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HBlockedRuleRHS.py new file mode 100644 index 0000000..dafda0e --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HBlockedRuleRHS.py @@ -0,0 +1,241 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HBlockedRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HBlockedRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 5), (2, 1), (1, 4), (3, 2), (4, 3)] + + super(HBlockedRuleRHS, self).__init__(name='HBlockedRuleRHS', num_nodes=6, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L100896971736948143022784878634694417234L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__held_by' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L160717945013025537791357737329216865250L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__blocked' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L4862158333764715425947464047751435922L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L277589306330164231117928931416996662185L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__request' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L167464972996026318641572818034734176383L +sb.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[4]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L125348223819439882815511594077665482746L +sb.""") + self.vs[5]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[5]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[5]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[5]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L245089764832913966601134154146518028839L +sb.""") + from HBlockedRuleLHS import HBlockedRuleLHS + self.pre = HBlockedRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__blocked6 + new_node = graph.add_node() + labels[6] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'blocked' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource2 -> MT_post__blocked6 + graph.add_edges((labels[2], labels[6])) + # MT_post__blocked6 -> MT_post__Process1 + graph.add_edges((labels[6], labels[1])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HGiveRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HGiveRuleLHS.py new file mode 100644 index 0000000..bd65153 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HGiveRuleLHS.py @@ -0,0 +1,240 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HGiveRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HGiveRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 4), (2, 1), (1, 3)] + + super(HGiveRuleLHS, self).__init__(name='HGiveRuleLHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L295694224874499617722562245406856054238L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__next' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L74798338898880959666359291853016310140L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__release' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L209110483131573210641075243874804993633L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L7532088393639482233260012186506655256L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L66168221871693779345546476866374842977L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L201207913961595287827335360106594822920L +sb.""") + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HGiveRulePivotLHS.py b/tcore_package/tcore_package/examples/mutex/HGiveRulePivotLHS.py new file mode 100644 index 0000000..c4b9405 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HGiveRulePivotLHS.py @@ -0,0 +1,242 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HGiveRulePivotLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HGiveRulePivotLHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 4), (2, 1), (1, 3)] + + super(HGiveRulePivotLHS, self).__init__(name='HGiveRulePivotLHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L12981422283108575041802580714357437051L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__next' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L17016231759602513030309902885660816476L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__release' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L135551964233503244077595512429499526981L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L47638695076110829248083297052131318589L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pivotIn__"] = pickle.loads("""S'p' +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L253002741093312474840776146489905966105L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L290412129272398026906174733005688635255L +sb.""") + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HGiveRulePivotRHS.py b/tcore_package/tcore_package/examples/mutex/HGiveRulePivotRHS.py new file mode 100644 index 0000000..6a66c1e --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HGiveRulePivotRHS.py @@ -0,0 +1,227 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HGiveRulePivotRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HGiveRulePivotRHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 4), (2, 1), (1, 4)] + + super(HGiveRulePivotRHS, self).__init__(name='HGiveRulePivotRHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L103894334520555524908552411050948419035L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__next' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L244892450394539695654450390355630639793L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__toke' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L94924446692125151457483248639338204991L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L111429489186084446836648947732257142765L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L286241585800288031289268680248722855868L +sb.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[4]["MT_pivotOut__"] = pickle.loads("""S'p' +.""") + self.vs[4]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L46887196848973466511837996779135938972L +sb.""") + from HGiveRulePivotLHS import HGiveRulePivotLHS + self.pre = HGiveRulePivotLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__toke6 + new_node = graph.add_node() + labels[6] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'toke' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource4 -> MT_post__toke6 + graph.add_edges((labels[4], labels[6])) + # MT_post__toke6 -> MT_post__Process2 + graph.add_edges((labels[6], labels[2])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__release5 + graph.delete_nodes([labels[5]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + # MT_post__Process2 + packet.global_pivots['p'] = graph.vs[labels[2]][Himesis.Constants.GUID] + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HGiveRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HGiveRuleRHS.py new file mode 100644 index 0000000..3527390 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HGiveRuleRHS.py @@ -0,0 +1,223 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HGiveRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HGiveRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 4), (2, 1), (1, 4)] + + super(HGiveRuleRHS, self).__init__(name='HGiveRuleRHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L128109589447366193026876325095916544650L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__next' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L177624418768214664019156108454313732585L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__toke' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L65279578244024242503641241558378633882L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L80242969720223182778476110579653009519L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L63470687038304575917707628194018684606L +sb.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[4]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L67506875502750692194397584738302981614L +sb.""") + from HGiveRuleLHS import HGiveRuleLHS + self.pre = HGiveRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__toke6 + new_node = graph.add_node() + labels[6] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'toke' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource4 -> MT_post__toke6 + graph.add_edges((labels[4], labels[6])) + # MT_post__toke6 -> MT_post__Process2 + graph.add_edges((labels[6], labels[2])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__release5 + graph.delete_nodes([labels[5]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HHoldRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HHoldRuleLHS.py new file mode 100644 index 0000000..714bbdd --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HHoldRuleLHS.py @@ -0,0 +1,152 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HHoldRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HHoldRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HHoldRuleLHS, self).__init__(name='HHoldRuleLHS', num_nodes=2, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L159805472501531992406939813172861382676L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L77933946834667379458068160696837287375L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L163261784310981906636000487760777815800L +sb.""") + + # Load the NACs + from HHoldRuleNAC0 import HHoldRuleNAC0 + from HHoldRuleNAC1 import HHoldRuleNAC1 + self.NACs = [HHoldRuleNAC0(LHS=self), HHoldRuleNAC1(LHS=self)] + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC0.py b/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC0.py new file mode 100644 index 0000000..e43b926 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC0.py @@ -0,0 +1,135 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle + +class HHoldRuleNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HHoldRuleNAC0. + """ + # Create the himesis graph + EDGE_LIST = [(0, 1)] + + super(HHoldRuleNAC0, self).__init__(name='HHoldRuleNAC0', num_nodes=2, edges=EDGE_LIST, LHS=LHS) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the NAC have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True forbids the rule from being applied,@n# returning False enables the rule to be applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L222028338710187840387138979806697109571L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L40232462954029693879868670309131989115L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L108679568784113939371717218743259774649L +sb.""") + + # Load the bridge between this NAC and its LHS + from HHoldRuleNAC0Bridge import HHoldRuleNAC0Bridge + self.bridge = HHoldRuleNAC0Bridge() + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC0Bridge.py b/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC0Bridge.py new file mode 100644 index 0000000..796f84d --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC0Bridge.py @@ -0,0 +1,77 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle + +class HHoldRuleNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HHoldRuleNAC0Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HHoldRuleNAC0Bridge, self).__init__(name='HHoldRuleNAC0Bridge', num_nodes=1, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L139629033620370382135647365923532198194L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S'from HHoldRuleNAC0 import HHoldRuleNAC0@nfrom HHoldRuleLHS import HHoldRuleLHS@nreturn HHoldRuleNAC0().eval_name1(attr_value, PreNode) and HHoldRuleLHS().eval_name1(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L108679568784113939371717218743259774649L +sb.""") + def eval_name1(self, attr_value, PreNode, graph): + from HHoldRuleNAC0 import HHoldRuleNAC0 + from HHoldRuleLHS import HHoldRuleLHS + return HHoldRuleNAC0().eval_name1(attr_value, PreNode) and HHoldRuleLHS().eval_name1(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC1.py b/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC1.py new file mode 100644 index 0000000..aceb4ce --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC1.py @@ -0,0 +1,135 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle + +class HHoldRuleNAC1(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HHoldRuleNAC1. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0)] + + super(HHoldRuleNAC1, self).__init__(name='HHoldRuleNAC1', num_nodes=2, edges=EDGE_LIST, LHS=LHS) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the NAC have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True forbids the rule from being applied,@n# returning False enables the rule to be applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L160179377637520873875861494974975545758L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L125465582863726898435674588919499575544L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L226802655720759481614389774357601028373L +sb.""") + + # Load the bridge between this NAC and its LHS + from HHoldRuleNAC1Bridge import HHoldRuleNAC1Bridge + self.bridge = HHoldRuleNAC1Bridge() + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC1Bridge.py b/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC1Bridge.py new file mode 100644 index 0000000..9d083ff --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HHoldRuleNAC1Bridge.py @@ -0,0 +1,77 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle + +class HHoldRuleNAC1Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HHoldRuleNAC1Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HHoldRuleNAC1Bridge, self).__init__(name='HHoldRuleNAC1Bridge', num_nodes=1, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L91887268072828218732508076701595401833L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S'from HHoldRuleNAC1 import HHoldRuleNAC1@nfrom HHoldRuleLHS import HHoldRuleLHS@nreturn HHoldRuleNAC1().eval_name2(attr_value, PreNode) and HHoldRuleLHS().eval_name2(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L226802655720759481614389774357601028373L +sb.""") + def eval_name2(self, attr_value, PreNode, graph): + from HHoldRuleNAC1 import HHoldRuleNAC1 + from HHoldRuleLHS import HHoldRuleLHS + return HHoldRuleNAC1().eval_name2(attr_value, PreNode) and HHoldRuleLHS().eval_name2(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HHoldRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HHoldRuleRHS.py new file mode 100644 index 0000000..ae21e27 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HHoldRuleRHS.py @@ -0,0 +1,200 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HHoldRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HHoldRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 1)] + + super(HHoldRuleRHS, self).__init__(name='HHoldRuleRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L38641006692660173983700281202040018981L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__held_by' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L289799567242132261050849004497791080383L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L158156922296549320497477739511808230488L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""V\u000a#===============================================================================\u000a# You can access the value of the current node's attribute value by: attr_value.\u000a# You can access a matched node labelled n by: PreNode('n').\u000a# To access attribute x of node n, use: PreNode('n')['x'].\u000a# Note that the attribute values are those before the match is rewritten.\u000a# The order in which this code is executed depends on the label value of the encapsulating node.\u000a# The given action must return the new value of the attribute.\u000a#===============================================================================\u000a\u000a# Named after the process it is held by\u000areturn 'R' + PreNode(1)['name'][1:]\u000a +p1 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L240024568362262431479771014317214999024L +sb.""") + from HHoldRuleLHS import HHoldRuleLHS + self.pre = HHoldRuleLHS() + + def set_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # Note that the attribute values are those before the match is rewritten. + # The order in which this code is executed depends on the label value of the encapsulating node. + # The given action must return the new value of the attribute. + #=============================================================================== + + # Named after the process it is held by + return 'R' + PreNode(1)['name'][1:] + + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + # MT_post__Resource2 + try: + graph.vs[labels[2]]['name'] = self.set_name2(graph.vs[labels[2]]['name'], lambda i: graph.vs[match[i]], graph) + except Exception, e: + raise Exception('An error has occurred while computing the value of the attribute \'name\'', e) + + graph.vs[labels[2]][Himesis.Constants.MT_DIRTY] = True + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__held_by3 + new_node = graph.add_node() + labels[3] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'held_by' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource2 -> MT_post__held_by3 + graph.add_edges((labels[2], labels[3])) + # MT_post__held_by3 -> MT_post__Process1 + graph.add_edges((labels[3], labels[1])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HIgnoreRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HIgnoreRuleLHS.py new file mode 100644 index 0000000..18b26ff --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HIgnoreRuleLHS.py @@ -0,0 +1,133 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle +from uuid import UUID + +class HIgnoreRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HIgnoreRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2)] + + # Flag this instance as compiled now + self.is_compiled = True + + super(HIgnoreRuleLHS, self).__init__(name='HIgnoreRuleLHS', num_nodes=3, edges=EDGE_LIST) + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = """#=============================================================================== +# This code is executed after the nodes in the LHS have been matched. +# You can access a matched node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression: +# returning True enables the rule to be applied, +# returning False forbids the rule from being applied. +#=============================================================================== + +return True +""" + self["name"] = """""" + self["GUID__"] = UUID('128a43cb-5cef-4fb6-9115-600908a157c1') + + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = False + self.vs[0]["MT_label__"] = """3""" + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = """MT_pre__blocked""" + self.vs[0]["MT_dirty__"] = False + self.vs[0]["GUID__"] = UUID('e5c691a4-748c-48f0-a51b-f7104552383f') + self.vs[1]["MT_subtypeMatching__"] = False + self.vs[1]["MT_label__"] = """2""" + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = """MT_pre__Resource""" + self.vs[1]["MT_dirty__"] = False + self.vs[1]["MT_pre__name"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access a matched node 'n' by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[1]["GUID__"] = UUID('fa1a418b-921d-4f89-ae47-bfbb6506e385') + self.vs[2]["MT_subtypeMatching__"] = False + self.vs[2]["MT_label__"] = """1""" + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = """MT_pre__Process""" + self.vs[2]["MT_dirty__"] = False + self.vs[2]["MT_pre__name"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access a matched node 'n' by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[2]["GUID__"] = UUID('db75ed88-990c-4654-a7a5-568fe7b3179e') + + # Load the NACs + from HIgnoreRuleNAC0 import HIgnoreRuleNAC0 + self.NACs = [HIgnoreRuleNAC0(LHS=self)] + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HIgnoreRuleNAC0.py b/tcore_package/tcore_package/examples/mutex/HIgnoreRuleNAC0.py new file mode 100644 index 0000000..cedd6b6 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HIgnoreRuleNAC0.py @@ -0,0 +1,133 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle +from uuid import UUID + +class HIgnoreRuleNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HIgnoreRuleNAC0. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2)] + + # Flag this instance as compiled now + self.is_compiled = True + + super(HIgnoreRuleNAC0, self).__init__(name='HIgnoreRuleNAC0', num_nodes=3, edges=EDGE_LIST, LHS=LHS) + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = """#=============================================================================== +# This code is executed after the nodes in the NAC have been matched. +# You can access a matched node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression: +# returning True forbids the rule from being applied, +# returning False enables the rule to be applied. +#=============================================================================== + +return True +""" + self["name"] = """""" + self["GUID__"] = UUID('e7b125bc-601d-45cd-bd93-94bf2458403b') + + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = False + self.vs[0]["MT_label__"] = """5""" + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = """MT_pre__held_by""" + self.vs[0]["MT_dirty__"] = False + self.vs[0]["GUID__"] = UUID('b5c13282-57af-43e8-9c0d-b2ba70fa3e80') + self.vs[1]["MT_subtypeMatching__"] = False + self.vs[1]["MT_label__"] = """4""" + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = """MT_pre__Resource""" + self.vs[1]["MT_dirty__"] = False + self.vs[1]["MT_pre__name"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access a matched node 'n' by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[1]["GUID__"] = UUID('a2180a79-1b82-4100-ae03-de9961620a9e') + self.vs[2]["MT_subtypeMatching__"] = False + self.vs[2]["MT_label__"] = """1""" + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = """MT_pre__Process""" + self.vs[2]["MT_dirty__"] = False + self.vs[2]["MT_pre__name"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access a matched node 'n' by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[2]["GUID__"] = UUID('736cb7ae-597e-4f29-8075-133e21668d5a') + + # Load the bridge between this NAC and its LHS + from HIgnoreRuleNAC0Bridge import HIgnoreRuleNAC0Bridge + self.bridge = HIgnoreRuleNAC0Bridge() + + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HIgnoreRuleNAC0Bridge.py b/tcore_package/tcore_package/examples/mutex/HIgnoreRuleNAC0Bridge.py new file mode 100644 index 0000000..15fd772 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HIgnoreRuleNAC0Bridge.py @@ -0,0 +1,48 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle +from uuid import UUID + +class HIgnoreRuleNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HIgnoreRuleNAC0Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + # Flag this instance as compiled now + self.is_compiled = True + + super(HIgnoreRuleNAC0Bridge, self).__init__(name='HIgnoreRuleNAC0Bridge', num_nodes=1, edges=EDGE_LIST) + + # Set the graph attributes + self["GUID__"] = UUID('cf936002-72b6-4506-a2ac-93c4e15ac8c6') + + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = False + self.vs[0]["MT_label__"] = """1""" + self.vs[0]["mm__"] = """MT_pre__Process""" + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_dirty__"] = False + self.vs[0]["MT_pre__name"] = """from HIgnoreRuleNAC0 import HIgnoreRuleNAC0 +from HIgnoreRuleLHS import HIgnoreRuleLHS +return HIgnoreRuleNAC0().eval_name1(attr_value, PreNode) and HIgnoreRuleLHS().eval_name1(attr_value, PreNode)""" + self.vs[0]["GUID__"] = UUID('736cb7ae-597e-4f29-8075-133e21668d5a') + def eval_name1(self, attr_value, PreNode, graph): + from HIgnoreRuleNAC0 import HIgnoreRuleNAC0 + from HIgnoreRuleLHS import HIgnoreRuleLHS + return HIgnoreRuleNAC0().eval_name1(attr_value, PreNode) and HIgnoreRuleLHS().eval_name1(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HIgnoreRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HIgnoreRuleRHS.py new file mode 100644 index 0000000..d826e19 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HIgnoreRuleRHS.py @@ -0,0 +1,130 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle +from uuid import UUID + +class HIgnoreRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HIgnoreRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [] + + # Flag this instance as compiled now + self.is_compiled = True + + super(HIgnoreRuleRHS, self).__init__(name='HIgnoreRuleRHS', num_nodes=2, edges=EDGE_LIST) + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = """#=============================================================================== +# This code is executed after the rule has been applied. +# You can access a node labelled n matched by this rule by: PostNode('n'). +# To access attribute x of node n, use: PostNode('n')['x']. +#=============================================================================== + +pass +""" + self["name"] = """""" + self["GUID__"] = UUID('db9ed6ec-1fa9-4c67-aba2-db780d5f661b') + + # Set the node attributes + self.vs[0]["mm__"] = """MT_post__Process""" + self.vs[0]["MT_label__"] = """1""" + self.vs[0]["MT_post__name"] = """ +#=============================================================================== +# You can access the value of the current node's attribute value by: attr_value. +# You can access a matched node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# Note that the attribute values are those before the match is rewritten. +# The order in which this code is executed depends on the label value of the encapsulating node. +# The given action must return the new value of the attribute. +#=============================================================================== + +return attr_value +""" + self.vs[0]["GUID__"] = UUID('714d5d4e-7462-419e-8f15-0048fad93f5f') + self.vs[1]["mm__"] = """MT_post__Resource""" + self.vs[1]["MT_label__"] = """2""" + self.vs[1]["MT_post__name"] = """ +#=============================================================================== +# You can access the value of the current node's attribute value by: attr_value. +# You can access a matched node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# Note that the attribute values are those before the match is rewritten. +# The order in which this code is executed depends on the label value of the encapsulating node. +# The given action must return the new value of the attribute. +#=============================================================================== + +return attr_value +""" + self.vs[1]["GUID__"] = UUID('c425bf69-170c-4d66-bbeb-a637c0d67852') + from HIgnoreRuleLHS import HIgnoreRuleLHS + self.pre = HIgnoreRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + + #=============================================================================== + # Create new edges + #=============================================================================== + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__blocked3 + graph.delete_nodes([labels[3]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HInit2Processes.py b/tcore_package/tcore_package/examples/mutex/HInit2Processes.py new file mode 100644 index 0000000..1fed4d1 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HInit2Processes.py @@ -0,0 +1,39 @@ + + +from core.himesis import Himesis +import cPickle as pickle +from uuid import UUID + +class HInit2Processes(Himesis): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HInit2Processes. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 2), (2, 1), (1, 3)] + + # Flag this instance as compiled now + self.is_compiled = True + + super(HInit2Processes, self).__init__(name='HInit2Processes', num_nodes=4, edges=EDGE_LIST) + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'Mutex' +p2 +a.""") + self["name"] = """Init2Processes""" + self["GUID__"] = UUID('54f6831c-7013-4f5b-aae6-2d0668512e2c') + + # Set the node attributes + self.vs[0]["mm__"] = """Process""" + self.vs[0]["name"] = """P0""" + self.vs[0]["GUID__"] = UUID('80c78d1d-fd5d-4bd8-a224-d8a73651525a') + self.vs[1]["mm__"] = """Process""" + self.vs[1]["name"] = """P1""" + self.vs[1]["GUID__"] = UUID('2a116b48-c6bb-41af-a208-ce7693285082') + self.vs[2]["mm__"] = """next""" + self.vs[2]["GUID__"] = UUID('6873525d-fba9-453b-8193-634befefe5a0') + self.vs[3]["mm__"] = """next""" + self.vs[3]["GUID__"] = UUID('498a7840-d6b5-49fb-b2a3-548ff5809cbf') + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HKillRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HKillRuleLHS.py new file mode 100644 index 0000000..3584411 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HKillRuleLHS.py @@ -0,0 +1,235 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HKillRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HKillRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 3), (3, 1), (1, 4)] + + super(HKillRuleLHS, self).__init__(name='HKillRuleLHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HKillRuleLHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L18442321865415244356622957945051150877L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__next' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L30273376065343805843958472981264470130L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__next' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L328554853358455331346205911493797456672L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L165009034650108222987415177235648016564L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L73980624501117965779453092797674415786L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L292064108001480532935557560315945411793L +sb.""") + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name3(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HKillRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HKillRuleRHS.py new file mode 100644 index 0000000..3ccddc9 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HKillRuleRHS.py @@ -0,0 +1,175 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HKillRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HKillRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2)] + + super(HKillRuleRHS, self).__init__(name='HKillRuleRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HKillRuleRHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L139842207730391867649959791870174970756L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__next' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L62645959304628031181905625317070703431L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L35039735801621166585301262957624254163L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L339526573624143007135485048208645884513L +sb.""") + from HKillRuleLHS import HKillRuleLHS + self.pre = HKillRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__next6 + new_node = graph.add_node() + labels[6] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'next' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Process1 -> MT_post__next6 + graph.add_edges((labels[1], labels[6])) + # MT_post__next6 -> MT_post__Process3 + graph.add_edges((labels[6], labels[3])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__Process2, MT_pre__next5, MT_pre__next4 + graph.delete_nodes([labels[2], labels[5], labels[4]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HMountRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HMountRuleLHS.py new file mode 100644 index 0000000..0ec4894 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HMountRuleLHS.py @@ -0,0 +1,99 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HMountRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HMountRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HMountRuleLHS, self).__init__(name='HMountRuleLHS', num_nodes=1, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HMountRuleLHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L180016063263888998616812906613918609953L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L82437144822067329940789048898186268483L +sb.""") + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HMountRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HMountRuleRHS.py new file mode 100644 index 0000000..dc91abf --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HMountRuleRHS.py @@ -0,0 +1,202 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HMountRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HMountRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 1)] + + super(HMountRuleRHS, self).__init__(name='HMountRuleRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HMountRuleRHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L204181169989380058006610160678131469781L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__toke' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L194618085095321478715411846101328385378L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L146735793891330158366608615282295876673L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""V\u000a#===============================================================================\u000a# You can access the value of the current node's attribute value by: attr_value.\u000a# You can access a matched node labelled n by: PreNode('n').\u000a# To access attribute x of node n, use: PreNode('n')['x'].\u000a# Note that the attribute values are those before the match is rewritten.\u000a# The order in which this code is executed depends on the label value of the encapsulating node.\u000a# The given action must return the new value of the attribute.\u000a#===============================================================================\u000a\u000avs = graph.vs.select(mm__ = 'Resource')\u000amaxId = -1\u000afor v in vs:\u000a if v['name']:\u000a id = int(v['name'][1:])\u000a if id > maxId:\u000a maxId = id\u000areturn 'R' + str(maxId + 1)\u000a +p1 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L179332148605988684518009168156561057543L +sb.""") + from HMountRuleLHS import HMountRuleLHS + self.pre = HMountRuleLHS() + + def set_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # Note that the attribute values are those before the match is rewritten. + # The order in which this code is executed depends on the label value of the encapsulating node. + # The given action must return the new value of the attribute. + #=============================================================================== + + vs = graph.vs.select(mm__ = 'Resource') + maxId = -1 + for v in vs: + if v['name']: + id = int(v['name'][1:]) + if id > maxId: + maxId = id + return 'R' + str(maxId + 1) + + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__toke3 + new_node = graph.add_node() + labels[3] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'toke' + # MT_post__Resource2 + new_node = graph.add_node() + labels[2] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'Resource' + try: + graph.vs[new_node]['name'] = self.set_name2(None, lambda i: graph.vs[match[i]], graph) + except Exception, e: + raise Exception('An error has occurred while computing the value of the attribute \'name\'', e) + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource2 -> MT_post__toke3 + graph.add_edges((labels[2], labels[3])) + # MT_post__toke3 -> MT_post__Process1 + graph.add_edges((labels[3], labels[1])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HNewRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HNewRuleLHS.py new file mode 100644 index 0000000..0448027 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HNewRuleLHS.py @@ -0,0 +1,167 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HNewRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HNewRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2)] + + super(HNewRuleLHS, self).__init__(name='HNewRuleLHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HNewRuleLHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L8387374956881615269111586304651502669L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__next' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L210530681916693618659972630116464552921L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L61909895586652568424096053170927638299L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L169214136227357809773417410649120568746L +sb.""") + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HNewRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HNewRuleRHS.py new file mode 100644 index 0000000..70a1b47 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HNewRuleRHS.py @@ -0,0 +1,255 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HNewRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HNewRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 4), (4, 1), (1, 3)] + + super(HNewRuleRHS, self).__init__(name='HNewRuleRHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HNewRuleRHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L216252046786439829870692571573926113871L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__next' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L265398458179928414982637964388342547225L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__next' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L114621590887504245237000617794008652191L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L212607478986061461350152077805400419080L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[3]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L256358921611709246543309184649991082021L +sb.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[4]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nvs = graph.vs.select(mm__ = 'Process')@nmaxId = -1@nfor v in vs:@n if v['name']:@n \tid = int(v['name'][1:])@n if id > maxId:@n \t maxId = id@nreturn 'P' + str(maxId + 1)@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L99004324448409785593819361867936230344L +sb.""") + from HNewRuleLHS import HNewRuleLHS + self.pre = HNewRuleLHS() + + def set_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # Note that the attribute values are those before the match is rewritten. + # The order in which this code is executed depends on the label value of the encapsulating node. + # The given action must return the new value of the attribute. + #=============================================================================== + + vs = graph.vs.select(mm__ = 'Process') + maxId = -1 + for v in vs: + if v['name']: + id = int(v['name'][1:]) + if id > maxId: + maxId = id + return 'P' + str(maxId + 1) + + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__next5 + new_node = graph.add_node() + labels[5] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'next' + # MT_post__next6 + new_node = graph.add_node() + labels[6] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'next' + # MT_post__Process4 + new_node = graph.add_node() + labels[4] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'Process' + try: + graph.vs[new_node]['name'] = self.set_name4(None, lambda i: graph.vs[match[i]], graph) + except Exception, e: + raise Exception('An error has occurred while computing the value of the attribute \'name\'', e) + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__next5 -> MT_post__Process4 + graph.add_edges((labels[5], labels[4])) + # MT_post__Process4 -> MT_post__next6 + graph.add_edges((labels[4], labels[6])) + # MT_post__Process1 -> MT_post__next5 + graph.add_edges((labels[1], labels[5])) + # MT_post__next6 -> MT_post__Process2 + graph.add_edges((labels[6], labels[2])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__next3 + graph.delete_nodes([labels[3]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HPassRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HPassRuleLHS.py new file mode 100644 index 0000000..a3b4e37 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HPassRuleLHS.py @@ -0,0 +1,240 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HPassRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HPassRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 3), (3, 1), (1, 4)] + + super(HPassRuleLHS, self).__init__(name='HPassRuleLHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HPassRuleLHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L340162085546935200826583909614432669546L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__toke' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L293466630252002472721698758093846659709L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__next' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L132282679834203224017995897564917391423L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L223703983066034199373580776955633305104L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L129502108721697209564448704196520239714L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L318986935317827181168424217992621571791L +sb.""") + + # Load the NACs + from HPassRuleNAC0 import HPassRuleNAC0 + self.NACs = [HPassRuleNAC0(LHS=self)] + + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HPassRuleNAC0.py b/tcore_package/tcore_package/examples/mutex/HPassRuleNAC0.py new file mode 100644 index 0000000..7b651f3 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HPassRuleNAC0.py @@ -0,0 +1,172 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle + +class HPassRuleNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HPassRuleNAC0. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (1, 2)] + + super(HPassRuleNAC0, self).__init__(name='HPassRuleNAC0', num_nodes=3, edges=EDGE_LIST, LHS=LHS) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the NAC have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True forbids the rule from being applied,@n# returning False enables the rule to be applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HPassRuleNAC0' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L115463966035367520473704701271523039316L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L83668040719144100420851862217826048603L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L322646064774436585476852049513129943841L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L314698708587429013560569209317735942661L +sb.""") + + # Load the bridge between this NAC and its LHS + from HPassRuleNAC0Bridge import HPassRuleNAC0Bridge + self.bridge = HPassRuleNAC0Bridge() + + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HPassRuleNAC0Bridge.py b/tcore_package/tcore_package/examples/mutex/HPassRuleNAC0Bridge.py new file mode 100644 index 0000000..cb80fc5 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HPassRuleNAC0Bridge.py @@ -0,0 +1,112 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle + +class HPassRuleNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HPassRuleNAC0Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HPassRuleNAC0Bridge, self).__init__(name='HPassRuleNAC0Bridge', num_nodes=2, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L111801797885248063557279015331552882760L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S'from HPassRuleLHS import HPassRuleLHS@nfrom HPassRuleNAC0 import HPassRuleNAC0@nreturn HPassRuleLHS().eval_name5(attr_value, PreNode) and HPassRuleNAC0().eval_name4(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L83668040719144100420851862217826048603L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S'from HPassRuleLHS import HPassRuleLHS@nfrom HPassRuleNAC0 import HPassRuleNAC0@nreturn HPassRuleLHS().eval_name3(attr_value, PreNode) and HPassRuleNAC0().eval_name1(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L322646064774436585476852049513129943841L +sb.""") + def eval_name4(self, attr_value, PreNode, graph): + from HPassRuleLHS import HPassRuleLHS + from HPassRuleNAC0 import HPassRuleNAC0 + return HPassRuleLHS().eval_name5(attr_value, PreNode) and HPassRuleNAC0().eval_name4(attr_value, PreNode) + + + def eval_name1(self, attr_value, PreNode, graph): + from HPassRuleLHS import HPassRuleLHS + from HPassRuleNAC0 import HPassRuleNAC0 + return HPassRuleLHS().eval_name3(attr_value, PreNode) and HPassRuleNAC0().eval_name1(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HPassRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HPassRuleRHS.py new file mode 100644 index 0000000..e2af436 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HPassRuleRHS.py @@ -0,0 +1,218 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HPassRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HPassRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 4), (2, 1), (1, 4)] + + super(HPassRuleRHS, self).__init__(name='HPassRuleRHS', num_nodes=5, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HPassRuleRHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L125574966889889872500382374054681047273L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__next' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L196686460342300917440785140690447607417L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__toke' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L13717354398703184989716447421721648986L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L33827841268236302024623171411680384218L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L238350784918438927757042458975403903149L +sb.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[4]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L44996985395786454121306452830736141613L +sb.""") + from HPassRuleLHS import HPassRuleLHS + self.pre = HPassRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__toke6 + new_node = graph.add_node() + labels[6] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'toke' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource4 -> MT_post__toke6 + graph.add_edges((labels[4], labels[6])) + # MT_post__toke6 -> MT_post__Process2 + graph.add_edges((labels[6], labels[2])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__toke5 + graph.delete_nodes([labels[5]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HReleaseRuleLHS.py new file mode 100644 index 0000000..f383c7f --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseRuleLHS.py @@ -0,0 +1,177 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HReleaseRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HReleaseRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2)] + + super(HReleaseRuleLHS, self).__init__(name='HReleaseRuleLHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L217260776091196668739631124106900106936L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L64490514369909174388328034020111979685L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L6356676060386038058414243922939428314L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L26713368957169204818348666042117152057L +sb.""") + + # Load the NACs + from HReleaseRuleNAC0 import HReleaseRuleNAC0 + self.NACs = [HReleaseRuleNAC0(LHS=self)] + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseRuleNAC0.py b/tcore_package/tcore_package/examples/mutex/HReleaseRuleNAC0.py new file mode 100644 index 0000000..796ca6d --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseRuleNAC0.py @@ -0,0 +1,177 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle + +class HReleaseRuleNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HReleaseRuleNAC0. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (1, 2)] + + super(HReleaseRuleNAC0, self).__init__(name='HReleaseRuleNAC0', num_nodes=3, edges=EDGE_LIST, LHS=LHS) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the NAC have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True forbids the rule from being applied,@n# returning False enables the rule to be applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L242580904126300241053846154793939493732L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L293106342214416328390688397337429730265L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L83615215737654088064135540601591418602L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L229632518997480035825079081227934310374L +sb.""") + + # Load the bridge between this NAC and its LHS + from HReleaseRuleNAC0Bridge import HReleaseRuleNAC0Bridge + self.bridge = HReleaseRuleNAC0Bridge() + + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseRuleNAC0Bridge.py b/tcore_package/tcore_package/examples/mutex/HReleaseRuleNAC0Bridge.py new file mode 100644 index 0000000..84f35b8 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseRuleNAC0Bridge.py @@ -0,0 +1,77 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle + +class HReleaseRuleNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HReleaseRuleNAC0Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HReleaseRuleNAC0Bridge, self).__init__(name='HReleaseRuleNAC0Bridge', num_nodes=1, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L190412927260092338697445483992440745833L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S'from HReleaseRuleNAC0 import HReleaseRuleNAC0@nfrom HReleaseRuleLHS import HReleaseRuleLHS@nreturn HReleaseRuleNAC0().eval_name1(attr_value, PreNode) and HReleaseRuleLHS().eval_name1(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L83615215737654088064135540601591418602L +sb.""") + def eval_name1(self, attr_value, PreNode, graph): + from HReleaseRuleNAC0 import HReleaseRuleNAC0 + from HReleaseRuleLHS import HReleaseRuleLHS + return HReleaseRuleNAC0().eval_name1(attr_value, PreNode) and HReleaseRuleLHS().eval_name1(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotLHS.py b/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotLHS.py new file mode 100644 index 0000000..085019c --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotLHS.py @@ -0,0 +1,179 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HReleaseRulePivotLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HReleaseRulePivotLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2)] + + super(HReleaseRulePivotLHS, self).__init__(name='HReleaseRulePivotLHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L110771575284051222755816592876061876048L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L75521414981770462599036796701584635887L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L278979674152276671616899428704625047456L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pivotIn__"] = pickle.loads("""S'p' +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L203709663595164370087872903730417269772L +sb.""") + + # Load the NACs + from HReleaseRulePivotNAC0 import HReleaseRulePivotNAC0 + self.NACs = [HReleaseRulePivotNAC0(LHS=self)] + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotNAC0.py b/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotNAC0.py new file mode 100644 index 0000000..0265677 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotNAC0.py @@ -0,0 +1,177 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle + +class HReleaseRulePivotNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HReleaseRulePivotNAC0. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (1, 2)] + + super(HReleaseRulePivotNAC0, self).__init__(name='HReleaseRulePivotNAC0', num_nodes=3, edges=EDGE_LIST, LHS=LHS) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the NAC have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True forbids the rule from being applied,@n# returning False enables the rule to be applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L94224743539979633993487413480626122726L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L272549578259224044649192042195280222873L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L31486481323517052367969376531104164394L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L8523105835582321039251205449097727101L +sb.""") + + # Load the bridge between this NAC and its LHS + from HReleaseRulePivotNAC0Bridge import HReleaseRulePivotNAC0Bridge + self.bridge = HReleaseRulePivotNAC0Bridge() + + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotNAC0Bridge.py b/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotNAC0Bridge.py new file mode 100644 index 0000000..1a07e50 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotNAC0Bridge.py @@ -0,0 +1,79 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle + +class HReleaseRulePivotNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HReleaseRulePivotNAC0Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HReleaseRulePivotNAC0Bridge, self).__init__(name='HReleaseRulePivotNAC0Bridge', num_nodes=1, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L125584505795864303200695096754868014581L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_pivotIn__"] = pickle.loads("""S'p' +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S'from HReleaseRulePivotNAC0 import HReleaseRulePivotNAC0@nfrom HReleaseRulePivotLHS import HReleaseRulePivotLHS@nreturn HReleaseRulePivotNAC0().eval_name1(attr_value, PreNode) and HReleaseRulePivotLHS().eval_name1(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L31486481323517052367969376531104164394L +sb.""") + def eval_name1(self, attr_value, PreNode, graph): + from HReleaseRulePivotNAC0 import HReleaseRulePivotNAC0 + from HReleaseRulePivotLHS import HReleaseRulePivotLHS + return HReleaseRulePivotNAC0().eval_name1(attr_value, PreNode) and HReleaseRulePivotLHS().eval_name1(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotRHS.py b/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotRHS.py new file mode 100644 index 0000000..b9fbb42 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseRulePivotRHS.py @@ -0,0 +1,170 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HReleaseRulePivotRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HReleaseRulePivotRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 1)] + + super(HReleaseRulePivotRHS, self).__init__(name='HReleaseRulePivotRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L54718949582657985530227949708710718148L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__release' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L303891911525732987251186087532029333633L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L148381046541047846076593011693402756380L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L191751947581455322461465139637743829927L +sb.""") + from HReleaseRulePivotLHS import HReleaseRulePivotLHS + self.pre = HReleaseRulePivotLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + + #=============================================================================== + # Create new edges + #=============================================================================== + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HReleaseRuleRHS.py new file mode 100644 index 0000000..0282058 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseRuleRHS.py @@ -0,0 +1,170 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HReleaseRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HReleaseRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 1)] + + super(HReleaseRuleRHS, self).__init__(name='HReleaseRuleRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L46743183046126606436615199237694700684L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__release' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L211848812055874249992669172301174006086L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L138556920039092330529511123723737169345L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L253619199632218721198589314834502907101L +sb.""") + from HReleaseRuleLHS import HReleaseRuleLHS + self.pre = HReleaseRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + + #=============================================================================== + # Create new edges + #=============================================================================== + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseStarRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HReleaseStarRuleLHS.py new file mode 100644 index 0000000..a85f4c9 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseStarRuleLHS.py @@ -0,0 +1,308 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HReleaseStarRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HReleaseStarRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 1), (1, 6), (4, 2), (2, 6), (0, 3), (5, 0)] + + super(HReleaseStarRuleLHS, self).__init__(name='HReleaseStarRuleLHS', num_nodes=7, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L338773285111513540841248158136696961931L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L123670300902723730116479219858648150822L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L157650492058930432575113213159495237411L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'7' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L314272328505568214668678477633593982741L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L208359043985631955633030242772968592291L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L174698540246318241177542310483915474766L +sb.""") + self.vs[5]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[5]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[5]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[5]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[5]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[5]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[5]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L44547975727984116737867038415554936499L +sb.""") + self.vs[6]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[6]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[6]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[6]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[6]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[6]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[6]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L226070289041516036774104601843553369395L +sb.""") + def eval_name3(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HReleaseStarRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HReleaseStarRuleRHS.py new file mode 100644 index 0000000..641a8e7 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HReleaseStarRuleRHS.py @@ -0,0 +1,266 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HReleaseStarRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HReleaseStarRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 6), (4, 1), (1, 6), (2, 3), (5, 2)] + + super(HReleaseStarRuleRHS, self).__init__(name='HReleaseStarRuleRHS', num_nodes=7, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L275342879871712987182831716975335400395L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__release' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'8' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L127660524158242123192194902481588065043L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__held_by' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'7' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L172463930727310080946475282605668615304L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__request' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L271861368933388930861877912992458843782L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[3]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L37667417383731107038707424221284694450L +sb.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[4]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L14058129745318233217905725061677395409L +sb.""") + self.vs[5]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[5]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[5]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[5]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L45412691984527298822013851144206475597L +sb.""") + self.vs[6]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[6]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[6]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[6]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L59675172891408720859339814351054246416L +sb.""") + from HReleaseStarRuleLHS import HReleaseStarRuleLHS + self.pre = HReleaseStarRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__release8 + new_node = graph.add_node() + labels[8] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'release' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource3 -> MT_post__release8 + graph.add_edges((labels[3], labels[8])) + # MT_post__release8 -> MT_post__Process2 + graph.add_edges((labels[8], labels[2])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__held_by6 + graph.delete_nodes([labels[6]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HRequestRuleLHS.py new file mode 100644 index 0000000..02b2804 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestRuleLHS.py @@ -0,0 +1,151 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HRequestRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HRequestRuleLHS, self).__init__(name='HRequestRuleLHS', num_nodes=2, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L71615516216911659871572190042084773306L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L59220834963385838387804245136877070439L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L142266437717570675343785330397529243846L +sb.""") + + # Load the NACs + from HRequestRuleNAC0 import HRequestRuleNAC0 + self.NACs = [HRequestRuleNAC0(LHS=self)] + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestRuleNAC0.py b/tcore_package/tcore_package/examples/mutex/HRequestRuleNAC0.py new file mode 100644 index 0000000..4459d66 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestRuleNAC0.py @@ -0,0 +1,245 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle + +class HRequestRuleNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HRequestRuleNAC0. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 1), (2, 4), (1, 2)] + + super(HRequestRuleNAC0, self).__init__(name='HRequestRuleNAC0', num_nodes=5, edges=EDGE_LIST, LHS=LHS) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the NAC have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True forbids the rule from being applied,@n# returning False enables the rule to be applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L294857366286203551603529973469871452817L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L118675385239306709975236536046841364997L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L67115021767075456899599496114103751668L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L170586602450123909748373337875440342345L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L107602115318223042149806979354853347618L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L268490510992271139794629837696880387455L +sb.""") + + # Load the bridge between this NAC and its LHS + from HRequestRuleNAC0Bridge import HRequestRuleNAC0Bridge + self.bridge = HRequestRuleNAC0Bridge() + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name3(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestRuleNAC0Bridge.py b/tcore_package/tcore_package/examples/mutex/HRequestRuleNAC0Bridge.py new file mode 100644 index 0000000..901906c --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestRuleNAC0Bridge.py @@ -0,0 +1,112 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle + +class HRequestRuleNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestRuleNAC0Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HRequestRuleNAC0Bridge, self).__init__(name='HRequestRuleNAC0Bridge', num_nodes=2, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L50075768468146850644405256679903317947L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S'from HRequestRuleLHS import HRequestRuleLHS@nfrom HRequestRuleNAC0 import HRequestRuleNAC0@nreturn HRequestRuleLHS().eval_name2(attr_value, PreNode) and HRequestRuleNAC0().eval_name2(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L59220834963385838387804245136877070439L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S'from HRequestRuleLHS import HRequestRuleLHS@nfrom HRequestRuleNAC0 import HRequestRuleNAC0@nreturn HRequestRuleLHS().eval_name1(attr_value, PreNode) and HRequestRuleNAC0().eval_name1(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L142266437717570675343785330397529243846L +sb.""") + def eval_name2(self, attr_value, PreNode, graph): + from HRequestRuleLHS import HRequestRuleLHS + from HRequestRuleNAC0 import HRequestRuleNAC0 + return HRequestRuleLHS().eval_name2(attr_value, PreNode) and HRequestRuleNAC0().eval_name2(attr_value, PreNode) + + + def eval_name1(self, attr_value, PreNode, graph): + from HRequestRuleLHS import HRequestRuleLHS + from HRequestRuleNAC0 import HRequestRuleNAC0 + return HRequestRuleLHS().eval_name1(attr_value, PreNode) and HRequestRuleNAC0().eval_name1(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HRequestRuleRHS.py new file mode 100644 index 0000000..662617b --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestRuleRHS.py @@ -0,0 +1,178 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HRequestRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (2, 1)] + + super(HRequestRuleRHS, self).__init__(name='HRequestRuleRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L41684465285947293551732772746935516003L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[0]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L77592234428356781905393312738776199068L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__request' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L297977194106896737797414278751494936503L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L317491003004862446499477032477063593911L +sb.""") + from HRequestRuleLHS import HRequestRuleLHS + self.pre = HRequestRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__request3 + new_node = graph.add_node() + labels[3] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'request' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__request3 -> MT_post__Resource2 + graph.add_edges((labels[3], labels[2])) + # MT_post__Process1 -> MT_post__request3 + graph.add_edges((labels[1], labels[3])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleLHS.py new file mode 100644 index 0000000..73f3dc2 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleLHS.py @@ -0,0 +1,177 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HRequestSimpleRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestSimpleRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2)] + + super(HRequestSimpleRuleLHS, self).__init__(name='HRequestSimpleRuleLHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L214910639994839212756517232768300576996L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__toke' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L296116341577855731091878962971903840797L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L105746297214318212486613811288221714486L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L231148587890454236329664412322237016901L +sb.""") + + # Load the NACs + from HRequestSimpleRuleNAC0 import HRequestSimpleRuleNAC0 + self.NACs = [HRequestSimpleRuleNAC0(LHS=self)] + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleNAC0.py b/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleNAC0.py new file mode 100644 index 0000000..71dc8e7 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleNAC0.py @@ -0,0 +1,177 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle + +class HRequestSimpleRuleNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HRequestSimpleRuleNAC0. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (1, 2)] + + super(HRequestSimpleRuleNAC0, self).__init__(name='HRequestSimpleRuleNAC0', num_nodes=3, edges=EDGE_LIST, LHS=LHS) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the NAC have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True forbids the rule from being applied,@n# returning False enables the rule to be applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L54570948111353959965479959327960326654L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L339665020396135801221171508913979770898L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L119841419163540126656299293599774230373L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L77183823705861350046401569684963149040L +sb.""") + + # Load the bridge between this NAC and its LHS + from HRequestSimpleRuleNAC0Bridge import HRequestSimpleRuleNAC0Bridge + self.bridge = HRequestSimpleRuleNAC0Bridge() + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleNAC0Bridge.py b/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleNAC0Bridge.py new file mode 100644 index 0000000..d31c95e --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleNAC0Bridge.py @@ -0,0 +1,112 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle + +class HRequestSimpleRuleNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestSimpleRuleNAC0Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HRequestSimpleRuleNAC0Bridge, self).__init__(name='HRequestSimpleRuleNAC0Bridge', num_nodes=2, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L146637052767111949362208920316723548035L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S'from HRequestSimpleRuleNAC0 import HRequestSimpleRuleNAC0@nfrom HRequestSimpleRuleLHS import HRequestSimpleRuleLHS@nreturn HRequestSimpleRuleNAC0().eval_name2(attr_value, PreNode) and HRequestSimpleRuleLHS().eval_name2(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L339665020396135801221171508913979770898L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S'from HRequestSimpleRuleNAC0 import HRequestSimpleRuleNAC0@nfrom HRequestSimpleRuleLHS import HRequestSimpleRuleLHS@nreturn HRequestSimpleRuleNAC0().eval_name1(attr_value, PreNode) and HRequestSimpleRuleLHS().eval_name1(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L119841419163540126656299293599774230373L +sb.""") + def eval_name2(self, attr_value, PreNode, graph): + from HRequestSimpleRuleNAC0 import HRequestSimpleRuleNAC0 + from HRequestSimpleRuleLHS import HRequestSimpleRuleLHS + return HRequestSimpleRuleNAC0().eval_name2(attr_value, PreNode) and HRequestSimpleRuleLHS().eval_name2(attr_value, PreNode) + + + def eval_name1(self, attr_value, PreNode, graph): + from HRequestSimpleRuleNAC0 import HRequestSimpleRuleNAC0 + from HRequestSimpleRuleLHS import HRequestSimpleRuleLHS + return HRequestSimpleRuleNAC0().eval_name1(attr_value, PreNode) and HRequestSimpleRuleLHS().eval_name1(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleRHS.py new file mode 100644 index 0000000..a22c813 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestSimpleRuleRHS.py @@ -0,0 +1,198 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HRequestSimpleRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestSimpleRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 1), (1, 3), (3, 2)] + + super(HRequestSimpleRuleRHS, self).__init__(name='HRequestSimpleRuleRHS', num_nodes=4, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L131403220858852331485851938195167683442L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[0]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L91843473873931061495282203256654274462L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__toke' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L223273930967227009550565362407257640603L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__request' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L64170808271385160335266210660312157723L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L196402025368589689680348712801920473065L +sb.""") + from HRequestSimpleRuleLHS import HRequestSimpleRuleLHS + self.pre = HRequestSimpleRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__request4 + new_node = graph.add_node() + labels[4] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'request' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__request4 -> MT_post__Resource2 + graph.add_edges((labels[4], labels[2])) + # MT_post__Process1 -> MT_post__request4 + graph.add_edges((labels[1], labels[4])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestStarRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HRequestStarRuleLHS.py new file mode 100644 index 0000000..ae7b097 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestStarRuleLHS.py @@ -0,0 +1,313 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HRequestStarRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestStarRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(6, 0), (0, 5), (3, 1), (1, 5), (4, 2), (2, 6)] + + super(HRequestStarRuleLHS, self).__init__(name='HRequestStarRuleLHS', num_nodes=7, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L115644504663591746348408747712662185774L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__next' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L87546905463634645980238342433186527642L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L135086883271216594617549435373038021640L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'7' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L283024234280666470275326010286503962876L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L183047571664669192023764395506257419599L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L306179920007191007256394316752200471721L +sb.""") + self.vs[5]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[5]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[5]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[5]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[5]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[5]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[5]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L289445025727589419955206479309331047360L +sb.""") + self.vs[6]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[6]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[6]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[6]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[6]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[6]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[6]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L319888832854284699342509785859455610954L +sb.""") + + # Load the NACs + from HRequestStarRuleNAC0 import HRequestStarRuleNAC0 + self.NACs = [HRequestStarRuleNAC0(LHS=self)] + + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name5(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestStarRuleNAC0.py b/tcore_package/tcore_package/examples/mutex/HRequestStarRuleNAC0.py new file mode 100644 index 0000000..047ff9e --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestStarRuleNAC0.py @@ -0,0 +1,177 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle + +class HRequestStarRuleNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HRequestStarRuleNAC0. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (1, 2)] + + super(HRequestStarRuleNAC0, self).__init__(name='HRequestStarRuleNAC0', num_nodes=3, edges=EDGE_LIST, LHS=LHS) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the NAC have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True forbids the rule from being applied,@n# returning False enables the rule to be applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L279590811255854037561210139892396449060L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L274966528288541626611720680788409477996L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L144395182965853596662250778849471302941L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'8' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L46819431027326638697963918096443500841L +sb.""") + + # Load the bridge between this NAC and its LHS + from HRequestStarRuleNAC0Bridge import HRequestStarRuleNAC0Bridge + self.bridge = HRequestStarRuleNAC0Bridge() + + def eval_name5(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestStarRuleNAC0Bridge.py b/tcore_package/tcore_package/examples/mutex/HRequestStarRuleNAC0Bridge.py new file mode 100644 index 0000000..d98e359 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestStarRuleNAC0Bridge.py @@ -0,0 +1,112 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle + +class HRequestStarRuleNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestStarRuleNAC0Bridge. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HRequestStarRuleNAC0Bridge, self).__init__(name='HRequestStarRuleNAC0Bridge', num_nodes=2, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L271594817068501154406645432777552248950L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_pre__name"] = pickle.loads("""S'from HRequestStarRuleNAC0 import HRequestStarRuleNAC0@nfrom HRequestStarRuleLHS import HRequestStarRuleLHS@nreturn HRequestStarRuleNAC0().eval_name5(attr_value, PreNode) and HRequestStarRuleLHS().eval_name5(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L274966528288541626611720680788409477996L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S'from HRequestStarRuleNAC0 import HRequestStarRuleNAC0@nfrom HRequestStarRuleLHS import HRequestStarRuleLHS@nreturn HRequestStarRuleNAC0().eval_name1(attr_value, PreNode) and HRequestStarRuleLHS().eval_name1(attr_value, PreNode)' +p1 +.""").replace("@n", "\n") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L144395182965853596662250778849471302941L +sb.""") + def eval_name5(self, attr_value, PreNode, graph): + from HRequestStarRuleNAC0 import HRequestStarRuleNAC0 + from HRequestStarRuleLHS import HRequestStarRuleLHS + return HRequestStarRuleNAC0().eval_name5(attr_value, PreNode) and HRequestStarRuleLHS().eval_name5(attr_value, PreNode) + + + def eval_name1(self, attr_value, PreNode, graph): + from HRequestStarRuleNAC0 import HRequestStarRuleNAC0 + from HRequestStarRuleLHS import HRequestStarRuleLHS + return HRequestStarRuleNAC0().eval_name1(attr_value, PreNode) and HRequestStarRuleLHS().eval_name1(attr_value, PreNode) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HRequestStarRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HRequestStarRuleRHS.py new file mode 100644 index 0000000..daaa6ab --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HRequestStarRuleRHS.py @@ -0,0 +1,284 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HRequestStarRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HRequestStarRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(7, 0), (0, 6), (4, 2), (2, 6), (5, 3), (3, 7), (1, 5), (6, 1)] + + super(HRequestStarRuleRHS, self).__init__(name='HRequestStarRuleRHS', num_nodes=8, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L214335785930873195020391295761774577732L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__next' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L105924531793100168514427249540918345215L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__request' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'8' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L219499173069212584499748791394950879954L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__held_by' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L37600491152265032997634932849808842926L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__held_by' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'7' +.""") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L285159668704691673716825369101547553020L +sb.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[4]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L304540369837320421215556073483302626889L +sb.""") + self.vs[5]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[5]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[5]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[5]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L24838993284220751218144905017334310404L +sb.""") + self.vs[6]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[6]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[6]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[6]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L301762324691333981314239678023052652031L +sb.""") + self.vs[7]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[7]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[7]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[7]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L86005413328042174069962393206296386838L +sb.""") + from HRequestStarRuleLHS import HRequestStarRuleLHS + self.pre = HRequestStarRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__request8 + new_node = graph.add_node() + labels[8] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'request' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__request8 -> MT_post__Resource5 + graph.add_edges((labels[8], labels[5])) + # MT_post__Process1 -> MT_post__request8 + graph.add_edges((labels[1], labels[8])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HResourceRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HResourceRuleLHS.py new file mode 100644 index 0000000..7e9f6cf --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HResourceRuleLHS.py @@ -0,0 +1,61 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HResourceRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HResourceRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HResourceRuleLHS, self).__init__(name='HResourceRuleLHS', num_nodes=0, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MoTifRule' +p2 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'resourceRule' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L105607935948054044945830258901554412824L +sb.""") + # Set the node attributes + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HResourceRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HResourceRuleRHS.py new file mode 100644 index 0000000..dbffdc1 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HResourceRuleRHS.py @@ -0,0 +1,132 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HResourceRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HResourceRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HResourceRuleRHS, self).__init__(name='HResourceRuleRHS', num_nodes=1, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'resourceRule' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L86181050991677219302139407556373342600L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[0]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L272935098229562527704936518104601082053L +sb.""") + from HResourceRuleLHS import HResourceRuleLHS + self.pre = HResourceRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__Resource1 + new_node = graph.add_node() + labels[1] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'Resource' + + #=============================================================================== + # Create new edges + #=============================================================================== + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HTakeRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HTakeRuleLHS.py new file mode 100644 index 0000000..844480d --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HTakeRuleLHS.py @@ -0,0 +1,198 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HTakeRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HTakeRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2), (3, 1), (2, 3)] + + super(HTakeRuleLHS, self).__init__(name='HTakeRuleLHS', num_nodes=4, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L214246997689318139221355354937947139953L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__toke' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L141498651505025347561106548932410539903L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L311671574581788299884129749197781079618L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L279751639621699513341853321104483965194L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L135122033828660477739169514012106915017L +sb.""") + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HTakeRulePivotLHS.py b/tcore_package/tcore_package/examples/mutex/HTakeRulePivotLHS.py new file mode 100644 index 0000000..696c6ca --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HTakeRulePivotLHS.py @@ -0,0 +1,200 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HTakeRulePivotLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HTakeRulePivotLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2), (3, 1), (2, 3)] + + super(HTakeRulePivotLHS, self).__init__(name='HTakeRulePivotLHS', num_nodes=4, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L66613134182183156760649441909829310981L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__toke' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L101478540246274308243670670373967117124L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L234957555377491434960538458538073441619L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pivotIn__"] = pickle.loads("""S'p' +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L44671250922236119758829670160080311637L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L275539598258230508610242844206271449731L +sb.""") + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HTakeRulePivotRHS.py b/tcore_package/tcore_package/examples/mutex/HTakeRulePivotRHS.py new file mode 100644 index 0000000..51db4e4 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HTakeRulePivotRHS.py @@ -0,0 +1,184 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HTakeRulePivotRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HTakeRulePivotRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 1)] + + super(HTakeRulePivotRHS, self).__init__(name='HTakeRulePivotRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L177184248977566067407519061715160582110L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__held_by' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L327468026380999584779519446649229225705L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_pivotOut__"] = pickle.loads("""S'p' +.""") + self.vs[1]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L307306096358356756191155922592500254709L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L155582527659668895370133264659473414121L +sb.""") + from HTakeRulePivotLHS import HTakeRulePivotLHS + self.pre = HTakeRulePivotLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__held_by5 + new_node = graph.add_node() + labels[5] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'held_by' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource2 -> MT_post__held_by5 + graph.add_edges((labels[2], labels[5])) + # MT_post__held_by5 -> MT_post__Process1 + graph.add_edges((labels[5], labels[1])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__toke3, MT_pre__request4 + graph.delete_nodes([labels[3], labels[4]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + # MT_post__Process1 + packet.global_pivots['p'] = graph.vs[labels[1]][Himesis.Constants.GUID] + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HTakeRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HTakeRuleRHS.py new file mode 100644 index 0000000..c2d5191 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HTakeRuleRHS.py @@ -0,0 +1,180 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HTakeRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HTakeRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 1)] + + super(HTakeRuleRHS, self).__init__(name='HTakeRuleRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L279045862316403260946314971313193102995L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__held_by' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L158350772038903817286361436259146439733L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L324506222296820921592298491159903208905L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L230036789737900129212649521188190682802L +sb.""") + from HTakeRuleLHS import HTakeRuleLHS + self.pre = HTakeRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__held_by5 + new_node = graph.add_node() + labels[5] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'held_by' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource2 -> MT_post__held_by5 + graph.add_edges((labels[2], labels[5])) + # MT_post__held_by5 -> MT_post__Process1 + graph.add_edges((labels[5], labels[1])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__toke3, MT_pre__request4 + graph.delete_nodes([labels[3], labels[4]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HUnlockRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HUnlockRuleLHS.py new file mode 100644 index 0000000..bc0a2bd --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HUnlockRuleLHS.py @@ -0,0 +1,198 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HUnlockRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HUnlockRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 3), (2, 1), (1, 3)] + + super(HUnlockRuleLHS, self).__init__(name='HUnlockRuleLHS', num_nodes=4, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L244865194599059437099551254223833685279L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L17798216907319587723110452966882408230L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__blocked' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L299309329986608680380895518689701932810L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L217939205784801279257202689665291555229L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L233168384718587547436225817521095356033L +sb.""") + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HUnlockRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HUnlockRuleRHS.py new file mode 100644 index 0000000..49a6d10 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HUnlockRuleRHS.py @@ -0,0 +1,180 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HUnlockRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HUnlockRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(2, 0), (0, 1)] + + super(HUnlockRuleRHS, self).__init__(name='HUnlockRuleRHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L236330333721038762759918883580935329097L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__release' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L242596861024661575415880495873090921931L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[1]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L265855687177069279495750872515141701475L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[2]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L245065933067066430635535615320368142241L +sb.""") + from HUnlockRuleLHS import HUnlockRuleLHS + self.pre = HUnlockRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__release5 + new_node = graph.add_node() + labels[5] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'release' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource2 -> MT_post__release5 + graph.add_edges((labels[2], labels[5])) + # MT_post__release5 -> MT_post__Process1 + graph.add_edges((labels[5], labels[1])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__held_by3, MT_pre__blocked4 + graph.delete_nodes([labels[3], labels[4]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HUnmountRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HUnmountRuleLHS.py new file mode 100644 index 0000000..114ba36 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HUnmountRuleLHS.py @@ -0,0 +1,167 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HUnmountRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HUnmountRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(1, 0), (0, 2)] + + super(HUnmountRuleLHS, self).__init__(name='HUnmountRuleLHS', num_nodes=3, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HUnmountRuleLHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L90739289541963968947944255094043503701L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__toke' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L261535793464051523386075996363672597440L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L147034935548865215324405896544932507307L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L286142996698506142871093029059336796140L +sb.""") + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HUnmountRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HUnmountRuleRHS.py new file mode 100644 index 0000000..b01edd4 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HUnmountRuleRHS.py @@ -0,0 +1,124 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HUnmountRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HUnmountRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [] + + super(HUnmountRuleRHS, self).__init__(name='HUnmountRuleRHS', num_nodes=1, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'HUnmountRuleRHS' +p1 +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L158205461654898256849172665349371182019L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[0]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L307642038807194310826003982673192242643L +sb.""") + from HUnmountRuleLHS import HUnmountRuleLHS + self.pre = HUnmountRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + + #=============================================================================== + # Create new edges + #=============================================================================== + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__toke3, MT_pre__Resource2 + graph.delete_nodes([labels[3], labels[2]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HWaitingRuleLHS.py b/tcore_package/tcore_package/examples/mutex/HWaitingRuleLHS.py new file mode 100644 index 0000000..462ba3d --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HWaitingRuleLHS.py @@ -0,0 +1,308 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle + +class HWaitingRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HWaitingRuleLHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 5), (4, 1), (1, 5), (2, 3), (6, 2)] + + super(HWaitingRuleLHS, self).__init__(name='HWaitingRuleLHS', num_nodes=7, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L3277550863639785529332917267335178559L +sb.""") + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' +p1 +.""") + self.vs[0]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L72490072080382963330180439758308723887L +sb.""") + self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'7' +.""") + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__blocked' +p1 +.""") + self.vs[1]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L81122773032648319620206128728610011363L +sb.""") + self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' +p1 +.""") + self.vs[2]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L43628909232077438900949031236016664630L +sb.""") + self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[3]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L236893906032470449657487004851290020376L +sb.""") + self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Resource' +p1 +.""") + self.vs[4]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L270342823131535439241940617825124864812L +sb.""") + self.vs[5]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[5]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[5]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[5]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[5]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[5]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[5]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L177741816679941888370877730297682793919L +sb.""") + self.vs[6]["MT_subtypeMatching__"] = pickle.loads("""I00 +.""") + self.vs[6]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[6]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[6]["mm__"] = pickle.loads("""S'MT_pre__Process' +p1 +.""") + self.vs[6]["MT_dirty__"] = pickle.loads("""I00 +.""") + self.vs[6]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" +p1 +.""").replace("@n", "\n") + self.vs[6]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L191977859277208521439236097331207801259L +sb.""") + def eval_name3(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name4(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access a matched node 'n' by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/HWaitingRuleRHS.py b/tcore_package/tcore_package/examples/mutex/HWaitingRuleRHS.py new file mode 100644 index 0000000..1c53300 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/HWaitingRuleRHS.py @@ -0,0 +1,266 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle + +class HWaitingRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HWaitingRuleRHS. + """ + # Create the himesis graph + EDGE_LIST = [(3, 0), (0, 5), (4, 1), (1, 6), (2, 3), (6, 2)] + + super(HWaitingRuleRHS, self).__init__(name='HWaitingRuleRHS', num_nodes=7, edges=EDGE_LIST) + self.is_compiled = True # now this instance has been compiled + + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__Mutex' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the rule has been applied.@n# You can access a node labelled n matched by this rule by: PostNode('n').@n# To access attribute x of node n, use: PostNode('n')['x'].@n#===============================================================================@n@npass@n" +p1 +.""").replace("@n", "\n") + self["name"] = pickle.loads("""S'' +.""") + self["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L257481235057332382413537065771931272955L +sb.""") + # Set the node attributes + self.vs[0]["mm__"] = pickle.loads("""S'MT_post__held_by' +p1 +.""") + self.vs[0]["MT_label__"] = pickle.loads("""S'6' +.""") + self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L187141640991501823242532206984504703958L +sb.""") + self.vs[1]["mm__"] = pickle.loads("""S'MT_post__blocked' +p1 +.""") + self.vs[1]["MT_label__"] = pickle.loads("""S'8' +.""") + self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L268432440701473653754274545431305960489L +sb.""") + self.vs[2]["mm__"] = pickle.loads("""S'MT_post__request' +p1 +.""") + self.vs[2]["MT_label__"] = pickle.loads("""S'5' +.""") + self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L150904577221229516020194429906973138606L +sb.""") + self.vs[3]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[3]["MT_label__"] = pickle.loads("""S'3' +.""") + self.vs[3]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L149964336610848715219811580256994450020L +sb.""") + self.vs[4]["mm__"] = pickle.loads("""S'MT_post__Resource' +p1 +.""") + self.vs[4]["MT_label__"] = pickle.loads("""S'4' +.""") + self.vs[4]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L241890303715578712671800362821588516011L +sb.""") + self.vs[5]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[5]["MT_label__"] = pickle.loads("""S'1' +.""") + self.vs[5]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[5]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L335422119893259233240666099414958081237L +sb.""") + self.vs[6]["mm__"] = pickle.loads("""S'MT_post__Process' +p1 +.""") + self.vs[6]["MT_label__"] = pickle.loads("""S'2' +.""") + self.vs[6]["MT_post__name"] = pickle.loads("""S"@n#===============================================================================@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# Note that the attribute values are those before the match is rewritten.@n# The order in which this code is executed depends on the label value of the encapsulating node.@n# The given action must return the new value of the attribute.@n#===============================================================================@n@nreturn attr_value@n" +p1 +.""").replace("@n", "\n") + self.vs[6]["GUID__"] = pickle.loads("""ccopy_reg +_reconstructor +p1 +(cuuid +UUID +p2 +c__builtin__ +object +p3 +NtRp4 +(dp5 +S'int' +p6 +L101873217664447082891691439661545114095L +sb.""") + from HWaitingRuleLHS import HWaitingRuleLHS + self.pre = HWaitingRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # MT_post__blocked8 + new_node = graph.add_node() + labels[8] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'blocked' + + #=============================================================================== + # Create new edges + #=============================================================================== + # MT_post__Resource4 -> MT_post__blocked8 + graph.add_edges((labels[4], labels[8])) + # MT_post__blocked8 -> MT_post__Process2 + graph.add_edges((labels[8], labels[2])) + + #=============================================================================== + # Delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + # MT_pre__blocked7 + graph.delete_nodes([labels[7]]) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Finally, perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + + \ No newline at end of file diff --git a/tcore_package/tcore_package/examples/mutex/InitModel.py b/tcore_package/tcore_package/examples/mutex/InitModel.py new file mode 100644 index 0000000..a9b2b55 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/InitModel.py @@ -0,0 +1,48 @@ + +from t_core.composer import Composer +from tc_python.srule import SRule +from HHoldRuleLHS import HHoldRuleLHS +from HHoldRuleRHS import HHoldRuleRHS +from HNewRuleLHS import HNewRuleLHS +from HNewRuleRHS import HNewRuleRHS +from HResourceRuleLHS import HResourceRuleLHS +from HResourceRuleRHS import HResourceRuleRHS + + +class InitModel(Composer): + def __init__(self, N, R): + super(InitModel, self).__init__() + self.N = N + self.R = R + self.NewRule = SRule(HNewRuleLHS(), HNewRuleRHS(), max_iterations=N - 2, ignore_resolver=True) + self.ResourceRule = SRule(HResourceRuleLHS(), HResourceRuleRHS(), max_iterations=R, ignore_resolver=True) + self.HoldRule = SRule(HHoldRuleLHS(), HHoldRuleRHS(), max_iterations=N, ignore_resolver=True) + + def packet_in(self, packet): + # Processes + packet = self.NewRule.packet_in(packet) + packet.clean() + if not self.NewRule.is_success: + if self.NewRule.exception is not None: + self.exception = self.NewRule.exception + return packet + + # Resources + packet = self.ResourceRule.packet_in(packet) + packet.clean() + if not self.ResourceRule.is_success: + if self.NewRule.exception is not None: + self.exception = self.ResourceRule.exception + return packet + + # Holding + packet = self.HoldRule.packet_in(packet) + packet.clean() + if not self.HoldRule.is_success: + if self.HoldRule.exception is not None: + self.exception = self.HoldRule.exception + return packet + self.is_success = True + return packet + + diff --git a/tcore_package/tcore_package/examples/mutex/LTS.py b/tcore_package/tcore_package/examples/mutex/LTS.py new file mode 100644 index 0000000..fe7dc4f --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/LTS.py @@ -0,0 +1,168 @@ + +from t_core.composer import Composer +from tc_python.arule import ARule +from tc_python.srule import SRule +from tc_python.frule import FRule +from HBlockedRuleLHS import HBlockedRuleLHS +from HBlockedRuleRHS import HBlockedRuleRHS +from HGiveRuleLHS import HGiveRuleLHS +from HGiveRuleRHS import HGiveRuleRHS +from HIgnoreRuleLHS import HIgnoreRuleLHS +from HIgnoreRuleRHS import HIgnoreRuleRHS +from HReleaseStarRuleLHS import HReleaseStarRuleLHS +from HReleaseStarRuleRHS import HReleaseStarRuleRHS +from HRequestStarRuleLHS import HRequestStarRuleLHS +from HRequestStarRuleRHS import HRequestStarRuleRHS +from HTakeRuleLHS import HTakeRuleLHS +from HTakeRuleRHS import HTakeRuleRHS +from HUnlockRuleLHS import HUnlockRuleLHS +from HUnlockRuleRHS import HUnlockRuleRHS +from HWaitingRuleLHS import HWaitingRuleLHS +from HWaitingRuleRHS import HWaitingRuleRHS + + +class LongTransformationSequence(Composer): + def __init__(self, N, debug_folder=''): + super(LongTransformationSequence, self).__init__() + self.length = 0 + self.debug_suffix = 'lts' + self.debug_folder = debug_folder + self.N = N + self.RequestStarRule = FRule(HRequestStarRuleLHS(), HRequestStarRuleRHS(), max_iterations=N, ignore_resolver=True) + self.BlockedRule = ARule(HBlockedRuleLHS(), HBlockedRuleRHS(), ignore_resolver=True) + self.WaitingRule = SRule(HWaitingRuleLHS(), HWaitingRuleRHS(), max_iterations=N - 1, ignore_resolver=True) + self.UnlockRule = ARule(HUnlockRuleLHS(), HUnlockRuleRHS(), ignore_resolver=True) + self.IgnoreRule = ARule(HIgnoreRuleLHS(), HIgnoreRuleRHS(), ignore_resolver=True) + self.GiveRule = ARule(HGiveRuleLHS(), HGiveRuleRHS(), ignore_resolver=True) + self.TakeRule = ARule(HTakeRuleLHS(), HTakeRuleRHS(), ignore_resolver=True) + self.ReleaseStarRule = ARule(HReleaseStarRuleLHS(), HReleaseStarRuleRHS(), ignore_resolver=True) + + def packet_in(self, packet): + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Request + packet = self.RequestStarRule.packet_in(packet) + packet.clean() + if not self.RequestStarRule.is_success: + if self.RequestStarRule.exception is not None: + self.exception = self.HRequestStarRule.exception + return packet + self.length += self.RequestStarRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Block + packet = self.BlockedRule.packet_in(packet) + packet.clean() + if not self.BlockedRule.is_success: + if self.BlockedRule.exception is not None: + self.exception = self.HBlockedRule.exception + return packet + self.length += self.BlockedRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Wait + packet = self.WaitingRule.packet_in(packet) + packet.clean() + if not self.WaitingRule.is_success: + if self.WaitingRule.exception is not None: + self.exception = self.WaitingRule.exception + return packet + self.length += self.WaitingRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Unlock + packet = self.UnlockRule.packet_in(packet) + packet.clean() + if not self.UnlockRule.is_success: + if self.UnlockRule.exception is not None: + self.exception = self.UnlockRule.exception + return packet + self.length += self.UnlockRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Block + packet = self.BlockedRule.packet_in(packet) + packet.clean() + if not self.BlockedRule.is_success: + if self.BlockedRule.exception is not None: + self.exception = self.HBlockedRule.exception + return packet + self.length += self.BlockedRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Wait + packet = self.WaitingRule.packet_in(packet) + packet.clean() + if not self.WaitingRule.is_success: + if self.WaitingRule.exception is not None: + self.exception = self.WaitingRule.exception + return packet + self.length += self.WaitingRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Ignore + packet = self.IgnoreRule.packet_in(packet) + packet.clean() + if not self.IgnoreRule.is_success: + if self.IgnoreRule.exception is not None: + self.exception = self.IgnoreRule.exception + return packet + self.length += self.IgnoreRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Circle around + for _ in range(self.N - 1): + # Give + packet = self.GiveRule.packet_in(packet) + packet.clean() + if not self.GiveRule.is_success: + if self.GiveRule.exception is not None: + self.exception = self.GiveRule.exception + return packet + self.length += self.GiveRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Take + packet = self.TakeRule.packet_in(packet) + packet.clean() + if not self.TakeRule.is_success: + if self.TakeRule.exception is not None: + self.exception = self.TakeRule.exception + return packet + self.length += self.TakeRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Release + packet = self.ReleaseStarRule.packet_in(packet) + packet.clean() + if not self.ReleaseStarRule.is_success: + if self.ReleaseStarRule.exception is not None: + self.exception = self.ReleaseStarRule.exception + return packet + self.length += self.ReleaseStarRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Give + packet = self.GiveRule.packet_in(packet) + packet.clean() + if not self.GiveRule.is_success: + if self.GiveRule.exception is not None: + self.exception = self.GiveRule.exception + return packet + self.length += self.GiveRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Take + packet = self.TakeRule.packet_in(packet) + packet.clean() + if not self.TakeRule.is_success: + if self.TakeRule.exception is not None: + self.exception = self.TakeRule.exception + return packet + self.length += self.TakeRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + self.is_success = True + return packet + + diff --git a/tcore_package/tcore_package/examples/mutex/STS.py b/tcore_package/tcore_package/examples/mutex/STS.py new file mode 100644 index 0000000..dc47569 --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/STS.py @@ -0,0 +1,118 @@ + +from t_core.composer import Composer +from tc_python.arule import ARule +from tc_python.srule import SRule +from tc_python.frule import FRule +from HGiveRuleLHS import HGiveRuleLHS +from HGiveRuleRHS import HGiveRuleRHS +from HMountRuleLHS import HMountRuleLHS +from HMountRuleRHS import HMountRuleRHS +from HNewRuleLHS import HNewRuleLHS +from HNewRuleRHS import HNewRuleRHS +from HReleaseRuleLHS import HReleaseRuleLHS +from HReleaseRuleRHS import HReleaseRuleRHS +from HRequestRuleLHS import HRequestRuleLHS +from HRequestRuleRHS import HRequestRuleRHS +from HTakeRuleLHS import HTakeRuleLHS +from HTakeRuleRHS import HTakeRuleRHS + +from HGiveRulePivotLHS import HGiveRulePivotLHS +from HGiveRulePivotRHS import HGiveRulePivotRHS +from HReleaseRulePivotLHS import HReleaseRulePivotLHS +from HReleaseRulePivotRHS import HReleaseRulePivotRHS +from HTakeRulePivotLHS import HTakeRulePivotLHS +from HTakeRulePivotRHS import HTakeRulePivotRHS + + +class ShortTransformationSequence(Composer): + def __init__(self, N, debug_folder=''): + super(ShortTransformationSequence, self).__init__() + self.length = 0 + self.debug_suffix = 'sts' + self.debug_folder = debug_folder + self.N = N + self.NewRule = SRule(HNewRuleLHS(), HNewRuleRHS(), max_iterations=N - 2, ignore_resolver=True) + self.MountRule = ARule(HMountRuleLHS(), HMountRuleRHS(), ignore_resolver=True) + self.RequestRule = FRule(HRequestRuleLHS(), HRequestRuleRHS(), max_iterations=N, ignore_resolver=True) + self.TakeRule = ARule(HTakeRuleLHS(), HTakeRuleRHS(), ignore_resolver=True) + self.ReleaseRule = ARule(HReleaseRuleLHS(), HReleaseRuleRHS(), ignore_resolver=True) + self.GiveRule = ARule(HGiveRuleLHS(), HGiveRuleRHS(), ignore_resolver=True) + + def packet_in(self, packet): + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # New Processes + packet = self.NewRule.packet_in(packet) + packet.clean() + if not self.NewRule.is_success: + if self.NewRule.exception is not None: + self.exception = self.NewRule.exception + return packet + self.length += self.NewRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Mount + packet = self.MountRule.packet_in(packet) + packet.clean() + if not self.MountRule.is_success: + if self.MountRule.exception is not None: + self.exception = self.MountRule.exception + return packet + self.length += self.MountRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Request + packet = self.RequestRule.packet_in(packet) + packet.clean() + if not self.RequestRule.is_success: + if self.RequestRule.exception is not None: + self.exception = self.RequestRule.exception + return packet + self.length += self.RequestRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Pass it around + for _ in range(self.N): + # Take + packet = self.TakeRule.packet_in(packet) + packet.clean() + if not self.TakeRule.is_success: + if self.TakeRule.exception is not None: + self.exception = self.TakeRule.exception + return packet + self.length += self.TakeRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Release + packet = self.ReleaseRule.packet_in(packet) + packet.clean() + if not self.ReleaseRule.is_success: + if self.ReleaseRule.exception is not None: + self.exception = self.ReleaseRule.exception + return packet + self.length += self.ReleaseRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + # Give + packet = self.GiveRule.packet_in(packet) + packet.clean() + if not self.GiveRule.is_success: + if self.GiveRule.exception is not None: + self.exception = self.GiveRule.exception + return packet + self.length += self.GiveRule.I.iterations + if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) + + self.is_success = True + return packet + + +class ShortTransformationSequencePivot(ShortTransformationSequence): + def __init__(self, N, debug_folder=''): + super(ShortTransformationSequencePivot, self).__init__(N, debug_folder) + self.debug_suffix = 'sts_pivot' + self.TakeRule = ARule(HTakeRulePivotLHS(), HTakeRulePivotRHS(), ignore_resolver=True) + self.ReleaseRule = ARule(HReleaseRulePivotLHS(), HReleaseRulePivotRHS(), ignore_resolver=True) + self.GiveRule = ARule(HGiveRulePivotLHS(), HGiveRulePivotRHS(), ignore_resolver=True) + + diff --git a/tcore_package/tcore_package/examples/mutex/get_all_files.py b/tcore_package/tcore_package/examples/mutex/get_all_files.py new file mode 100644 index 0000000..9aaea7d --- /dev/null +++ b/tcore_package/tcore_package/examples/mutex/get_all_files.py @@ -0,0 +1,5 @@ + +import os.path + +for fname in os.listdir(os.path.curdir): + print 'from %s import %s' % (fname[:-3], fname[:-3]) diff --git a/tcore_package/tcore_package/examples/simple/HA.py b/tcore_package/tcore_package/examples/simple/HA.py new file mode 100644 index 0000000..5e89f4b --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HA.py @@ -0,0 +1,32 @@ + + +from core.himesis import Himesis +import cPickle as pickle +from uuid import UUID + +class HA(Himesis): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HA. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HA, self).__init__(name='HA', num_nodes=1, edges=[]) + + # Add the edges + self.add_edges([]) + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'CDMetaModel' +p2 +a.""") + self["name"] = """a""" + self["GUID__"] = UUID('f86d10ce-c06f-4e24-a86c-9790e120704e') + + # Set the node attributes + self.vs[0]["mm__"] = """Clazz""" + self.vs[0]["is_persistent"] = True + self.vs[0]["name"] = """a""" + self.vs[0]["GUID__"] = UUID('2131d6d9-b9cf-48b7-8dbe-7161f4fba3ac') + diff --git a/tcore_package/tcore_package/examples/simple/HAb.py b/tcore_package/tcore_package/examples/simple/HAb.py new file mode 100644 index 0000000..ee06f72 --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HAb.py @@ -0,0 +1,40 @@ + + +from core.himesis import Himesis +import cPickle as pickle +from uuid import UUID + +class HAb(Himesis): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HAb. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HAb, self).__init__(name='HAb', num_nodes=4, edges=[]) + + # Add the edges + self.add_edges([(1, 0), (0, 2), (2, 3), (3, 1)]) + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'CDMetaModel' +p2 +a.""") + self["name"] = """ab""" + self["GUID__"] = UUID('c0345fb9-28f5-43fb-8a71-d0efd555dd41') + + # Set the node attributes + self.vs[0]["mm__"] = """Parent""" + self.vs[0]["GUID__"] = UUID('8d6c3270-1b59-46cc-91b2-51c861cca7b9') + self.vs[1]["mm__"] = """Clazz""" + self.vs[1]["is_persistent"] = True + self.vs[1]["name"] = """a""" + self.vs[1]["GUID__"] = UUID('928d0fc0-adb3-43c7-b6d2-97e300448d79') + self.vs[2]["mm__"] = """Clazz""" + self.vs[2]["is_persistent"] = True + self.vs[2]["name"] = """b""" + self.vs[2]["GUID__"] = UUID('0feab044-6354-4e64-8bd4-2aa31f2dfc43') + self.vs[3]["mm__"] = """Parent""" + self.vs[3]["GUID__"] = UUID('b6bd3d53-cad8-4e0b-9967-e5b7a5e31b98') + diff --git a/tcore_package/tcore_package/examples/simple/HFirstRuleLHS.py b/tcore_package/tcore_package/examples/simple/HFirstRuleLHS.py new file mode 100644 index 0000000..baf4174 --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HFirstRuleLHS.py @@ -0,0 +1,91 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle +from uuid import UUID + +class HFirstRuleLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HFirstRuleLHS. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HFirstRuleLHS, self).__init__(name='HFirstRuleLHS', num_nodes=1, edges=[]) + + # Add the edges + self.add_edges([]) + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__SimpleDSLTrans' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = """#=============================================================================== +# This code is executed after the nodes in the LHS have been matched. +# You can access a matched node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression: +# returning True enables the rule to be applied, +# returning False forbids the rule from being applied. +#=============================================================================== + +return True +""" + self["name"] = """""" + self["GUID__"] = UUID('5c3880b8-0c0c-43b6-b83c-cfea598b6d0e') + + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = False + self.vs[0]["MT_label__"] = """1""" + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = """MT_pre__Station_S""" + self.vs[0]["MT_pre__name"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access any attribute x of this node by: this['x']. +# If the constraint relies on attribute values from other nodes, +# use the LHS/NAC constraint instead. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[0]["MT_dirty__"] = False + self.vs[0]["GUID__"] = UUID('c3ebf5ce-2ec5-419b-ba7b-0045e69e06ba') + + def eval_name1(self, attr_value, this): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access any attribute x of this node by: this['x']. + # If the constraint relies on attribute values from other nodes, + # use the LHS/NAC constraint instead. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + diff --git a/tcore_package/tcore_package/examples/simple/HFirstRuleRHS.py b/tcore_package/tcore_package/examples/simple/HFirstRuleRHS.py new file mode 100644 index 0000000..e85b771 --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HFirstRuleRHS.py @@ -0,0 +1,113 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle +from uuid import UUID + +class HFirstRuleRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HFirstRuleRHS. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HFirstRuleRHS, self).__init__(name='HFirstRuleRHS', num_nodes=1, edges=[]) + + # Add the edges + self.add_edges([]) + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__SimpleDSLTrans' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = """#=============================================================================== +# This code is executed after the rule has been applied. +# You can access a node labelled n matched by this rule by: PostNode('n'). +# To access attribute x of node n, use: PostNode('n')['x']. +#=============================================================================== + +pass +""" + self["name"] = """""" + self["GUID__"] = UUID('b91859df-feae-4990-8c52-0a3bee2f81e9') + + # Set the node attributes + self.vs[0]["mm__"] = """MT_post__Station_T""" + self.vs[0]["MT_label__"] = """1""" + self.vs[0]["MT_post__name"] = """ +#=============================================================================== +# You can access the value of the current node's attribute value by: attr_value. +# If the current node shall be created you MUST initialize it here! +# You can access a node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# Note that the attribute values are those before the match is rewritten. +# The order in which this code is executed depends on the label value +# of the encapsulating node. +# The given action must return the new value of the attribute. +#=============================================================================== + +return attr_value +""" + self.vs[0]["GUID__"] = UUID('d5401d2c-2a29-4d86-9dbe-a95d0163327c') + + from HFirstRuleLHS import HFirstRuleLHS + self.pre = HFirstRuleLHS() + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + + #=============================================================================== + # Create new edges + #=============================================================================== + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + #=============================================================================== + # Finally, delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + diff --git a/tcore_package/tcore_package/examples/simple/HSource.py b/tcore_package/tcore_package/examples/simple/HSource.py new file mode 100644 index 0000000..307b2ca --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HSource.py @@ -0,0 +1,35 @@ + + +from core.himesis import Himesis + +import cPickle as pickle +from uuid import UUID + +class HSource(Himesis): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HSource. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HSource, self).__init__(name='HSource', num_nodes=2, edges=[]) + + # Add the edges + self.add_edges([]) + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'SimpleDSLTransMM' +p2 +a.""") + self["name"] = """source""" + self["GUID__"] = UUID('fe8250c4-134c-49b4-961e-2695baa47547') + + # Set the node attributes + self.vs[0]["mm__"] = """Station_S""" + self.vs[0]["name"] = """s1""" + self.vs[0]["GUID__"] = UUID('6f05ef17-a1be-4b68-b028-28c8ddaa5d98') + self.vs[1]["mm__"] = """Station_S""" + self.vs[1]["name"] = """s2""" + self.vs[1]["GUID__"] = UUID('247bd54b-129e-4b2b-88cd-b1a8a1cfd73d') + diff --git a/tcore_package/tcore_package/examples/simple/HTopClass2TableLHS.py b/tcore_package/tcore_package/examples/simple/HTopClass2TableLHS.py new file mode 100644 index 0000000..f584d9e --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HTopClass2TableLHS.py @@ -0,0 +1,118 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternLHS +import cPickle as pickle +from uuid import UUID + +class HTopClass2TableLHS(HimesisPreConditionPatternLHS): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HTopClass2TableLHS. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HTopClass2TableLHS, self).__init__(name='HTopClass2TableLHS', num_nodes=1, edges=[]) + + # Add the edges + self.add_edges([]) + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__CD2RDBMSMetaModel' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = """#=============================================================================== +# This code is executed after the nodes in the LHS have been matched. +# You can access a matched node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression: +# returning True enables the rule to be applied, +# returning False forbids the rule from being applied. +#=============================================================================== + +return True +""" + self["name"] = """""" + self["GUID__"] = UUID('68ac1d3e-b9eb-4c40-a421-bc3f328d2a98') + + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = False + self.vs[0]["MT_pre__is_persistent"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access any attribute x of this node by: this['x']. +# If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return attr_value +""" + self.vs[0]["MT_label__"] = """1""" + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = """MT_pre__Clazz""" + self.vs[0]["MT_pre__name"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access any attribute x of this node by: this['x']. +# If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[0]["MT_dirty__"] = False + self.vs[0]["GUID__"] = UUID('96977051-8531-40e0-952d-fabad1d8489b') + + + # Load the NACs + from HTopClass2TableNAC0 import HTopClass2TableNAC0 + self.NACs = [HTopClass2TableNAC0(LHS=self)] + + def eval_is_persistent1(self, attr_value, this): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access any attribute x of this node by: this['x']. + # If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return attr_value + + + def eval_name1(self, attr_value, this): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access any attribute x of this node by: this['x']. + # If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the LHS have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True enables the rule to be applied, + # returning False forbids the rule from being applied. + #=============================================================================== + + return True + diff --git a/tcore_package/tcore_package/examples/simple/HTopClass2TableNAC0.py b/tcore_package/tcore_package/examples/simple/HTopClass2TableNAC0.py new file mode 100644 index 0000000..7cb414d --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HTopClass2TableNAC0.py @@ -0,0 +1,180 @@ + + +from core.himesis import Himesis, HimesisPreConditionPatternNAC +import cPickle as pickle +from uuid import UUID + +class HTopClass2TableNAC0(HimesisPreConditionPatternNAC): + def __init__(self, LHS): + """ + Creates the himesis graph representing the AToM3 model HTopClass2TableNAC0. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HTopClass2TableNAC0, self).__init__(name='HTopClass2TableNAC0', num_nodes=3, edges=[], LHS=LHS) + + # Add the edges + self.add_edges([(1, 0), (0, 2)]) + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_pre__CD2RDBMSMetaModel' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_constraint__"] = """#=============================================================================== +# This code is executed after the nodes in the NAC have been matched. +# You can access a matched node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# The given constraint must evaluate to a boolean expression: +# returning True forbids the rule from being applied, +# returning False enables the rule to be applied. +#=============================================================================== + +return True +""" + self["name"] = """""" + self["GUID__"] = UUID('d74c9eae-e470-4aa6-8817-2e15a1b64aab') + + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = False + self.vs[0]["MT_label__"] = """3""" + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["mm__"] = """MT_pre__Parent""" + self.vs[0]["MT_dirty__"] = False + self.vs[0]["GUID__"] = UUID('94914a38-3999-44e8-8ecc-1e356a6b3e23') + self.vs[1]["MT_subtypeMatching__"] = False + self.vs[1]["MT_pre__is_persistent"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access any attribute x of this node by: this['x']. +# If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[1]["MT_label__"] = """1""" + self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[1]["mm__"] = """MT_pre__Clazz""" + self.vs[1]["MT_pre__name"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access any attribute x of this node by: this['x']. +# If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[1]["MT_dirty__"] = False + self.vs[1]["GUID__"] = UUID('a2616a97-3c66-4aa2-928f-52a37b14147b') + self.vs[2]["MT_subtypeMatching__"] = False + self.vs[2]["MT_pre__is_persistent"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access any attribute x of this node by: this['x']. +# If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[2]["MT_label__"] = """2""" + self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[2]["mm__"] = """MT_pre__Clazz""" + self.vs[2]["MT_pre__name"] = """ +#=============================================================================== +# This code is executed when evaluating if a node shall be matched by this rule. +# You can access the value of the current node's attribute value by: attr_value. +# You can access any attribute x of this node by: this['x']. +# If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. +# The given constraint must evaluate to a boolean expression. +#=============================================================================== + +return True +""" + self.vs[2]["MT_dirty__"] = False + self.vs[2]["GUID__"] = UUID('4a053f4e-83f0-474b-af5a-6e2e58e5ea12') + + + # Load the bridge between this NAC and its LHS + from HTopClass2TableNAC0Bridge import HTopClass2TableNAC0Bridge + self.bridge = HTopClass2TableNAC0Bridge() + + def eval_is_persistent1(self, attr_value, this): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access any attribute x of this node by: this['x']. + # If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name1(self, attr_value, this): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access any attribute x of this node by: this['x']. + # If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_is_persistent2(self, attr_value, this): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access any attribute x of this node by: this['x']. + # If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def eval_name2(self, attr_value, this): + + #=============================================================================== + # This code is executed when evaluating if a node shall be matched by this rule. + # You can access the value of the current node's attribute value by: attr_value. + # You can access any attribute x of this node by: this['x']. + # If the constraint relies on attribute values from other nodes, use the LHS/NAC constraint instead. + # The given constraint must evaluate to a boolean expression. + #=============================================================================== + + return True + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the nodes in the NAC have been matched. + # You can access a matched node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # The given constraint must evaluate to a boolean expression: + # returning True forbids the rule from being applied, + # returning False enables the rule to be applied. + #=============================================================================== + + return True + diff --git a/tcore_package/tcore_package/examples/simple/HTopClass2TableNAC0Bridge.py b/tcore_package/tcore_package/examples/simple/HTopClass2TableNAC0Bridge.py new file mode 100644 index 0000000..05a6730 --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HTopClass2TableNAC0Bridge.py @@ -0,0 +1,60 @@ + + +from core.himesis import Himesis, HimesisPreConditionPattern +import cPickle as pickle +from uuid import UUID + +class HTopClass2TableNAC0Bridge(HimesisPreConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HTopClass2TableNAC0Bridge. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HTopClass2TableNAC0Bridge, self).__init__(name='HTopClass2TableNAC0Bridge', num_nodes=1, edges=[]) + + # Add the edges + self.add_edges([]) + # Set the graph attributes + self["GUID__"] = UUID('0c4bc850-0acf-4395-80fd-98c56a0fb82c') + + # Set the node attributes + self.vs[0]["MT_subtypeMatching__"] = False + self.vs[0]["MT_pre__is_persistent"] = """from HTopClass2TableLHS import HTopClass2TableLHS +from HTopClass2TableNAC0 import HTopClass2TableNAC0 +lhs = HTopClass2TableLHS() +return HTopClass2TableLHS().eval_is_persistent1(attr_value, this) and HTopClass2TableNAC0(lhs).eval_is_persistent1(attr_value, this)""" + self.vs[0]["MT_label__"] = """1""" + self.vs[0]["mm__"] = """MT_pre__Clazz""" + self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 +.""") + self.vs[0]["MT_pre__name"] = """from HTopClass2TableLHS import HTopClass2TableLHS +from HTopClass2TableNAC0 import HTopClass2TableNAC0 +lhs = HTopClass2TableLHS() +return HTopClass2TableLHS().eval_name1(attr_value, this) and HTopClass2TableNAC0(lhs).eval_name1(attr_value, this)""" + self.vs[0]["MT_dirty__"] = False + self.vs[0]["GUID__"] = UUID('96977051-8531-40e0-952d-fabad1d8489b') + + def eval_is_persistent1(self, attr_value, this): + from HTopClass2TableLHS import HTopClass2TableLHS + from HTopClass2TableNAC0 import HTopClass2TableNAC0 + lhs = HTopClass2TableLHS() + return HTopClass2TableLHS().eval_is_persistent1(attr_value, this) and HTopClass2TableNAC0(lhs).eval_is_persistent1(attr_value, this) + + + def eval_name1(self, attr_value, this): + from HTopClass2TableLHS import HTopClass2TableLHS + from HTopClass2TableNAC0 import HTopClass2TableNAC0 + lhs = HTopClass2TableLHS() + return HTopClass2TableLHS().eval_name1(attr_value, this) and HTopClass2TableNAC0(lhs).eval_name1(attr_value, this) + + + def constraint(self, PreNode, graph): + """ + Executable constraint code. + @param PreNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + return True + diff --git a/tcore_package/tcore_package/examples/simple/HTopClass2TableRHS.py b/tcore_package/tcore_package/examples/simple/HTopClass2TableRHS.py new file mode 100644 index 0000000..8837919 --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/HTopClass2TableRHS.py @@ -0,0 +1,173 @@ + + +from core.himesis import Himesis, HimesisPostConditionPattern +import cPickle as pickle +from uuid import UUID + +class HTopClass2TableRHS(HimesisPostConditionPattern): + def __init__(self): + """ + Creates the himesis graph representing the AToM3 model HTopClass2TableRHS. + """ + # Flag this instance as compiled now + self.is_compiled = True + + super(HTopClass2TableRHS, self).__init__(name='HTopClass2TableRHS', num_nodes=5, edges=[]) + + # Add the edges + self.add_edges([(4, 0), (3, 1), (2, 3), (2, 4)]) + # Set the graph attributes + self["mm__"] = pickle.loads("""(lp1 +S'MT_post__CD2RDBMSMetaModel' +p2 +aS'MoTifRule' +p3 +a.""") + self["MT_action__"] = """#=============================================================================== +# This code is executed after the rule has been applied. +# You can access a node labelled n matched by this rule by: PostNode('n'). +# To access attribute x of node n, use: PostNode('n')['x']. +#=============================================================================== + +pass +""" + self["name"] = """""" + self["GUID__"] = UUID('772d2291-465f-4976-ba63-96c042623685') + + # Set the node attributes + self.vs[0]["mm__"] = """MT_post__Table""" + self.vs[0]["MT_label__"] = """2""" + self.vs[0]["MT_post__name"] = pickle.loads("""V\u000a#===============================================================================\u000a# You can access the value of the current node's attribute value by: attr_value.\u000a# If the current node shall be created you MUST initialize it here!\u000a# You can access a node labelled n by: PreNode('n').\u000a# To access attribute x of node n, use: PreNode('n')['x'].\u000a# Note that the attribute values are those before the match is rewritten.\u000a# The order in which this code is executed depends on the label value of the encapsulating node.\u000a# The given action must return the new value of the attribute.\u000a#===============================================================================\u000a\u000areturn PreNode('1')['name']\u000a +p1 +.""") + self.vs[0]["GUID__"] = UUID('8605e1e5-bf8e-4d72-8747-eb7ef1d953fc') + self.vs[1]["mm__"] = """MT_post__Clazz""" + self.vs[1]["MT_label__"] = """1""" + self.vs[1]["MT_post__is_persistent"] = """ +#=============================================================================== +# You can access the value of the current node's attribute value by: attr_value. +# If the current node shall be created you MUST initialize it here! +# You can access a node labelled n by: PreNode('n'). +# To access attribute x of node n, use: PreNode('n')['x']. +# Note that the attribute values are those before the match is rewritten. +# The order in which this code is executed depends on the label value of the encapsulating node. +# The given action must return the new value of the attribute. +#=============================================================================== + +return attr_value +""" + self.vs[1]["MT_post__name"] = pickle.loads("""V\u000a#===============================================================================\u000a# You can access the value of the current node's attribute value by: attr_value.\u000a# If the current node shall be created you MUST initialize it here!\u000a# You can access a node labelled n by: PreNode('n').\u000a# To access attribute x of node n, use: PreNode('n')['x'].\u000a# Note that the attribute values are those before the match is rewritten.\u000a# The order in which this code is executed depends on the label value of the encapsulating node.\u000a# The given action must return the new value of the attribute.\u000a#===============================================================================\u000a\u000areturn attr_value\u000a +p1 +.""") + self.vs[1]["GUID__"] = UUID('52241dfa-a743-4205-b401-b9ad7b5bf60e') + self.vs[2]["mm__"] = """MT_post__GenericNode""" + self.vs[2]["MT_label__"] = """3""" + self.vs[2]["GUID__"] = UUID('c382757d-ccb2-4df3-ac75-206bf005571c') + self.vs[3]["mm__"] = """MT_post__GenericEdge""" + self.vs[3]["MT_label__"] = """4""" + self.vs[3]["GUID__"] = UUID('ca02ea46-72dc-4bb5-8efc-636c5cc732e4') + self.vs[4]["mm__"] = """MT_post__GenericEdge""" + self.vs[4]["MT_label__"] = """5""" + self.vs[4]["GUID__"] = UUID('2625d00b-5065-4d65-b02f-e697104fee03') + + from HTopClass2TableLHS import HTopClass2TableLHS + self.pre = HTopClass2TableLHS() + + def set_name2(self, attr_value, PreNode, graph): + + #=============================================================================== + # You can access the value of the current node's attribute value by: attr_value. + # If the current node shall be created you MUST initialize it here! + # You can access a node labelled n by: PreNode('n'). + # To access attribute x of node n, use: PreNode('n')['x']. + # Note that the attribute values are those before the match is rewritten. + # The order in which this code is executed depends on the label value of the encapsulating node. + # The given action must return the new value of the attribute. + #=============================================================================== + + return PreNode('1')['name'] + + + def action(self, PostNode, graph): + """ + Executable constraint code. + @param PostNode: Function taking an integer as parameter + and returns the node corresponding to that label. + """ + #=============================================================================== + # This code is executed after the rule has been applied. + # You can access a node labelled n matched by this rule by: PostNode('n'). + # To access attribute x of node n, use: PostNode('n')['x']. + #=============================================================================== + + pass + + def execute(self, packet, match): + """ + Transforms the current match of the packet according to the rule %s. + Pivots are also assigned, if any. + @param packet: The input packet. + @param match: The match to rewrite. + """ + graph = packet.graph + + # Build a dictionary {label: node index} mapping each label of the pattern to a node in the graph to rewrite. + # Because of the uniqueness property of labels in a rule, we can store all LHS labels + # and subsequently add the labels corresponding to the nodes to be created. + labels = match.copy() + + #=============================================================================== + # Update attribute values + #=============================================================================== + + #=============================================================================== + # Create new nodes + #=============================================================================== + # Table2 + new_node = graph.add_node() + labels['2'] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'Table' + try: + graph.vs[new_node]['name'] = self.set_name2(None, lambda i: graph.vs[match[i]], graph) + except Exception, e: + raise Exception('An error has occurred while computing the value of the attribute \'name\'', e) + # GenericEdge4 + new_node = graph.add_node() + labels['4'] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'GenericEdge' + # GenericEdge5 + new_node = graph.add_node() + labels['5'] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'GenericEdge' + # GenericNode3 + new_node = graph.add_node() + labels['3'] = new_node + graph.vs[new_node][Himesis.Constants.META_MODEL] = 'GenericNode' + + #=============================================================================== + # Create new edges + #=============================================================================== + # GenericEdge5 -> Table2 + graph.add_edges((labels['5'], labels['2'])) + # GenericNode3 -> GenericEdge4 + graph.add_edges((labels['3'], labels['4'])) + # GenericNode3 -> GenericEdge5 + graph.add_edges((labels['3'], labels['5'])) + # GenericEdge4 -> Clazz1 + graph.add_edges((labels['4'], labels['1'])) + + #=============================================================================== + # Set the output pivots + #=============================================================================== + + #=============================================================================== + # Perform the post-action + #=============================================================================== + try: + self.action(lambda i: graph.vs[labels[i]], graph) + except Exception, e: + raise Exception('An error has occurred while applying the post-action', e) + #=============================================================================== + # Finally, delete nodes (this will automatically delete the adjacent edges) + #=============================================================================== + diff --git a/tcore_package/tcore_package/examples/simple/main.py b/tcore_package/tcore_package/examples/simple/main.py new file mode 100644 index 0000000..b8aa2e7 --- /dev/null +++ b/tcore_package/tcore_package/examples/simple/main.py @@ -0,0 +1,30 @@ +# To correctly import tc_python and t_core, place this folder at the root + +from tc_python.arule import ARule +from t_core.messages import Packet +from HA import HA +from HAb import HAb +from HTopClass2TableLHS import HTopClass2TableLHS +from HTopClass2TableRHS import HTopClass2TableRHS + +r1 = ARule(HTopClass2TableLHS(), HTopClass2TableRHS()) +p = Packet() +p.graph = HA() +p1 = r1.packet_in(p) +print p1 + +print r1.is_success + +if r1.exception: + raise r1.exception + +r2 = ARule(HTopClass2TableLHS(), HTopClass2TableRHS()) +p = Packet() +p.graph = HAb() +p2 = r2.packet_in(p) +print p2 + +print r2.is_success + +if r2.exception: + raise r2.exception \ No newline at end of file