Starting with the second error... NameError: global name 'bufid' is not defined
This is because you're using the variable name "bufid", but there's no such variable. You have this in a packet-in handler because it's one of the parameters to the event handler. For a stats-in, there's obviously no associated packet, so there's no bufid parameter, so using bufid doesn't make sense here. The first error is... ERR:received Openflow error packet from dpid=000000000001: type=1, code=8, 128 bytes of data Looking that up, we see that type 1 code 8 is BAD_REQUEST, BUFFER_UNKNOWN. We can see why if we look at install_datapath_flow()'s definition versus your call to it. install_datapath_flow: self, # Passed implicitly dp_id, # You pass "dpid" attrs, # You pass "flow" (the match dict) idle_timeout, # You pass CACHE_TIMEOUT hard_timeout, # You pass DROP_TIMEOUT actions, # You pass "actions" (which is []) buffer_id=None, # You pass openflow.OFP_DEFAULT_PRIORITY priority=openflow.OFP_DEFAULT_PRIORITY, # You pass "inport" inport=None, # You pass nothing packet=None # You pass nothing As you can see, you 're passing openflow.OFP_DEFAULT_PRIORITY as if it were the buffer ID. No wonder the buffer is unknown! I don't think you need the inport here anyway, so you probably just want to do something like: self.install_datapath_flow(dpid, flow, CACHE_TIMEOUT, DROP_TIMEOUT, []) Also, note that you are always operating on the first flow even if it was some other flow that went over your threshold (because you are using flows[0] to pick out the port/match later). You probably want to not just keep track of the winning byte_count, but also the index of the flow with the winning byte_count. temp = 0 temp_index = None for index, item in enumerate(flows): val = int(item['byte_count']) # byte_count is probably a bigint... do you need the int? if val > temp: temp = val temp_index = index ... flow = flows[temp_index]['match'] Hope that helps. -- Murphy On Sep 2, 2011, at 10:21 PM, chris oleke wrote: > > Well it does make some sense and should be able to work but when I try it in > my application like shown below, I get the following errors > > def handle_flow_stats_in(self, dpid, flows, more, xid): > > print "Flow stats in from datapath", longlong_to_octstr(dpid)[6:] > > temp = 0 > > for item in flows: > > val = item['byte_count'] > > z = int(val) > > if z > temp: > > temp = z > > > print "highest", temp > > if temp > 1000: > > inport = flows[0]['match']['in_port'] > > flow = flows[0]['match'] > > print inport > > #print flow > > actions = [] > > self.install_datapath_flow(dpid, flow, CACHE_TIMEOUT, > DROP_TIMEOUT, > > actions, > openflow.OFP_DEFAULT_PRIORITY, > > inport) > > > > First error: > > > 00006|openflow-event|ERR:received Openflow error packet from > dpid=000000000001: type=1, code=8, 128 bytes of data > > > > When I change the command for installing a flow to contain the bufid and buf: > > self.install_datapath_flow(dpid, flow, CACHE_TIMEOUT, DROP_TIMEOUT, > > actions, bufid, > openflow.OFP_DEFAULT_PRIORITY, > > inport, buf) > > I get this error: > > > 00006|pyrt|ERR:unable to invoke a Python event handler: > > Traceback (most recent call last): > > File "./nox/lib/util.py", line 192, in f > > ret = f.cb(event.datapath_id, event.flows, event.more, event.xid) > > File "./nox/netapps/routing/samplerouting.py", line 181, in > handle_flow_stats_in > > actions, bufid, openflow.OFP_DEFAULT_PRIORITY, > > NameError: global name 'bufid' is not defined > > > > Where could the problem be? > > > > Thanks, > > Chris > > > > On Sat, Sep 3, 2011 at 1:47 AM, Murphy McCauley <jam...@nau.edu> wrote: > Yes. From the flow stats event, you should be able to do something like: > e.flows[0]["match"] to get the match dictionary to use with > install_datapath_flow(), send_flow_command(), etc. for that flow. > > -- Murphy > > On Sep 2, 2011, at 3:16 PM, chris oleke wrote: > > > Hi, > > > > I am trying to create a rate-limiting functionality in my application using > > the flow statistics that I obtain from the switch. I'm using the byte_count > > from the flows to match against a threshold value that when exceeded will > > be used to prompt flows to be dropped. Is it possible to create a packet > > within NOX that I would use to install a flow just like the case in a > > packet_in_event? In other words I'd like to know if I can use the details > > obtained from a particular flow statistic to create a packet and > > consequently have a flow sent to the switch that will be used to drop the > > packets that match the flow. > > > > > > Thanks, > > Chris > > _______________________________________________ > > nox-dev mailing list > > nox-dev@noxrepo.org > > http://noxrepo.org/mailman/listinfo/nox-dev > >
_______________________________________________ nox-dev mailing list nox-dev@noxrepo.org http://noxrepo.org/mailman/listinfo/nox-dev