frenetic-lang / pyretic

The Pyretic language and runtime system
http://frenetic-lang.org/pyretic/
159 stars 99 forks source link

NameError: name 'dynamic' is not defined #46

Closed wj92 closed 9 years ago

wj92 commented 9 years ago

hi: I am a newer in SDN.I get a trouble about pyretic.The following is pyretic_switcher.py.

from pyretic.lib.corelib import from pyretic.lib.std import

@dynamic
def act_like_switch(self): """ Implement switch-like behavior. """

self.forward = flood()
self.query = packets(limit=1,group_by=['srcmac','switch'])
self.policy = self.forward + self.query
def learn_from_a_packet(pkt):

    self.forward = if_(match(dstmac=pkt['srcmac'],
                             switch=pkt['switch']), fwd(pkt['inport']),
                       self.policy) 

    self.policy = self.forward + self.query # hint you've already written this
    print self.policy 

self.query.register_callback(learn_from_a_packet)

def main(): return act_like_switch()

But when I input pyretic.py –v high pyretic.examples.pyretic_switch,I get these information:

Traceback (most recent call last): File "/root/pyretic/pyretic.py", line 211, in main() File "/root/pyretic/pyretic.py", line 124, in main module = import_module(module_name) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/root/pyretic/pyretic/examples/pyretic_switch.py", line 7, in @dynamic NameError: name 'dynamic' is not defined

what should I do? thanks

joshreich commented 9 years ago

the dynamic decorator has been deprecated and is no longer supported. Subclass DynamicPolicy instead---see here for documentation https://github.com/frenetic-lang/pyretic/wiki/Dynamic-Policies