[nox-dev] a code problem about “util.py”
Hi all: when I look at the code in nox/src/nox/lib/util.py written in python. I was confused about some codes there. Because I am newbie to python. def gen_datapath_join_callback(handler): > def f(event): > attrs = {} > attrs[core.N_BUFFERS] = event.n_buffers > attrs[core.N_TABLES] = event.n_tables > attrs[core.CAPABILITES] = event.capabilities > attrs[core.ACTIONS] = event.actions > attrs[core.PORTS] = event.ports > for i in range(0, len(attrs[core.PORTS])): > port = attrs[core.PORTS][i] > config = port['config'] > state = port['state'] > attrs[core.PORTS][i]['link']= (state & > openflow.OFPPS_LINK_DOWN) == 0 > attrs[core.PORTS][i]['enabled'] = (config & > openflow.OFPPC_PORT_DOWN) == 0 > attrs[core.PORTS][i]['flood'] = (config & > openflow.OFPPC_NO_FLOOD) == 0 > > ret = f.cb(event.datapath_id, attrs) > if ret == None: > return CONTINUE > return ret > f.cb = handler > return f > Python can define a function in a function really confused me. I do not know how the function f(event) is invoked. and what the f.cb mean. Any ideas? Thanks forward. hzy ___ nox-dev mailing list nox-dev@noxrepo.org http://noxrepo.org/mailman/listinfo/nox-dev
Re: [nox-dev] a code problem about “util.py”
The reason why I need to look at the code is that I want to know how does NOX handle the Datapath_join_event. I know the gen_datapath_join_callback was invoked by function register_for_datapath_join in core.py. I am very interested in the architecture of NOX. I am eager to know how the NOX works. Any information will be appreciated. Thanks for advance. hzy 2011/11/2 hzy > Hi all: > when I look at the code in nox/src/nox/lib/util.py written in python. I > was confused about some codes there. Because I am newbie to python. > > def gen_datapath_join_callback(handler): >> def f(event): >> attrs = {} >> attrs[core.N_BUFFERS] = event.n_buffers >> attrs[core.N_TABLES] = event.n_tables >> attrs[core.CAPABILITES] = event.capabilities >> attrs[core.ACTIONS] = event.actions >> attrs[core.PORTS] = event.ports >> for i in range(0, len(attrs[core.PORTS])): >> port = attrs[core.PORTS][i] >> config = port['config'] >> state = port['state'] >> attrs[core.PORTS][i]['link']= (state & >> openflow.OFPPS_LINK_DOWN) == 0 >> attrs[core.PORTS][i]['enabled'] = (config & >> openflow.OFPPC_PORT_DOWN) == 0 >> attrs[core.PORTS][i]['flood'] = (config & >> openflow.OFPPC_NO_FLOOD) == 0 >> >> ret = f.cb(event.datapath_id, attrs) >> if ret == None: >> return CONTINUE >> return ret >> f.cb = handler >> return f >> > > Python can define a function in a function really confused me. I do not > know how the function f(event) is invoked. and what the f.cb mean. > Any ideas? > Thanks forward. > hzy > ___ nox-dev mailing list nox-dev@noxrepo.org http://noxrepo.org/mailman/listinfo/nox-dev
[nox-dev] what is the difference between pyswitch and routing module?
I'm wondering what's the different between routing module and pyswitch module? I can find from wiki that routing is basically a forwarding module. but what about pyswitch? Because after i connected 3 openvswitchs(like this:host1 -- ovs1 -- ovs2 -- ovs3 --host2),i firstly ran pyswitch module,then host1 can ping host2, however,i tried to run UDP traffic test,and found that the larger bandwidth i use, the more packet loss there are. Then i stopped pyswitch module and ran routing module, then host1 still can ping host2, and the UDP traffic test works well, almost all the packets are transfered from host1 to host2. why this happened? Shan ___ nox-dev mailing list nox-dev@noxrepo.org http://noxrepo.org/mailman/listinfo/nox-dev
Re: [nox-dev] a code problem about “util.py”
the code problem I have solved after I looked the python books about function. but, when I look the codes in the core.py. def register_handler(self, event_name, handler): """\brief Register an event handler. The handler will be called with: handler(event). 'event' is a dictionary containing data for the specific event. @param event_name name of the event @param handler handler function """ return self.ctxt.register_handler(event_name, handler) I can't find the ctxt.register_handler function's definition. I want to see how the register_handler works. which file can I find the definition? any ideas? 2011/11/2 hzy > The reason why I need to look at the code is that I want to know how does > NOX handle the Datapath_join_event. > I know the gen_datapath_join_callback was invoked by function > register_for_datapath_join in core.py. > > I am very interested in the architecture of NOX. I am eager to know how > the NOX works. Any information will be appreciated. > Thanks for advance. > hzy > > > 2011/11/2 hzy > >> Hi all: >> when I look at the code in nox/src/nox/lib/util.py written in python. I >> was confused about some codes there. Because I am newbie to python. >> >> def gen_datapath_join_callback(handler): >>> def f(event): >>> attrs = {} >>> attrs[core.N_BUFFERS] = event.n_buffers >>> attrs[core.N_TABLES] = event.n_tables >>> attrs[core.CAPABILITES] = event.capabilities >>> attrs[core.ACTIONS] = event.actions >>> attrs[core.PORTS] = event.ports >>> for i in range(0, len(attrs[core.PORTS])): >>> port = attrs[core.PORTS][i] >>> config = port['config'] >>> state = port['state'] >>> attrs[core.PORTS][i]['link']= (state & >>> openflow.OFPPS_LINK_DOWN) == 0 >>> attrs[core.PORTS][i]['enabled'] = (config & >>> openflow.OFPPC_PORT_DOWN) == 0 >>> attrs[core.PORTS][i]['flood'] = (config & >>> openflow.OFPPC_NO_FLOOD) == 0 >>> >>> ret = f.cb(event.datapath_id, attrs) >>> if ret == None: >>> return CONTINUE >>> return ret >>> f.cb = handler >>> return f >>> >> >> Python can define a function in a function really confused me. I do not >> know how the function f(event) is invoked. and what the f.cb mean. >> Any ideas? >> Thanks forward. >> hzy >> > > ___ nox-dev mailing list nox-dev@noxrepo.org http://noxrepo.org/mailman/listinfo/nox-dev
Re: [nox-dev] a code problem about “util.py”
what the ctxt mean? 2011/11/3 hzy > the code problem I have solved after I looked the python books about > function. > > but, when I look the codes in the core.py. > def register_handler(self, event_name, handler): > """\brief Register an event handler. > > The handler will be called with: handler(event). > 'event' is a dictionary containing data for the > specific event. > > @param event_name name of the event > @param handler handler function > """ > return self.ctxt.register_handler(event_name, handler) > > I can't find the ctxt.register_handler function's definition. I want to > see how the register_handler works. which file can I find the definition? > any ideas? > > > 2011/11/2 hzy > >> The reason why I need to look at the code is that I want to know how does >> NOX handle the Datapath_join_event. >> I know the gen_datapath_join_callback was invoked by function >> register_for_datapath_join in core.py. >> >> I am very interested in the architecture of NOX. I am eager to know how >> the NOX works. Any information will be appreciated. >> Thanks for advance. >> hzy >> >> >> 2011/11/2 hzy >> >>> Hi all: >>> when I look at the code in nox/src/nox/lib/util.py written in python. I >>> was confused about some codes there. Because I am newbie to python. >>> >>> def gen_datapath_join_callback(handler): def f(event): attrs = {} attrs[core.N_BUFFERS] = event.n_buffers attrs[core.N_TABLES] = event.n_tables attrs[core.CAPABILITES] = event.capabilities attrs[core.ACTIONS] = event.actions attrs[core.PORTS] = event.ports for i in range(0, len(attrs[core.PORTS])): port = attrs[core.PORTS][i] config = port['config'] state = port['state'] attrs[core.PORTS][i]['link']= (state & openflow.OFPPS_LINK_DOWN) == 0 attrs[core.PORTS][i]['enabled'] = (config & openflow.OFPPC_PORT_DOWN) == 0 attrs[core.PORTS][i]['flood'] = (config & openflow.OFPPC_NO_FLOOD) == 0 ret = f.cb(event.datapath_id, attrs) if ret == None: return CONTINUE return ret f.cb = handler return f >>> >>> Python can define a function in a function really confused me. I do not >>> know how the function f(event) is invoked. and what the f.cb mean. >>> Any ideas? >>> Thanks forward. >>> hzy >>> >> >> > ___ nox-dev mailing list nox-dev@noxrepo.org http://noxrepo.org/mailman/listinfo/nox-dev