Reputation: 1
I am trying to collect flow statistics from SDN switch using the Ryu controller. I need a code on how I can collect ip_protocol from each flow using OFPFLOWSTATREQUEST AND REPLY HANDLER and save in a CSV FILE.
This is the code I used:
def _protocol(self, dpid, flows):
for flow in flows:
m = {}
for i in flow.match.items():
key = list(i)[0] # match key
val = list(i)[1] # match value
if key == "ip_proto":
protocol = val
return protocol
I got this error message after running the code:
File "/home/ai/SDN/daapp.py", line 780, in flow_stats_reply_handler
protocol = self._protocol(dpid, gflows[dpid])
File "/home/ai/SDN/daapp.py", line 458, in _protocol
return protocol
UnboundLocalError: local variable 'protocol' referenced before assignment
Upvotes: 0
Views: 221
Reputation: 11
It may consider the protocol in return to be the same as the protocol to which the _protocol output is to be placed. When returning, consider another name for the protocol to solve the problem.
protocol = self._protocol(dpid, gflows[dpid])
def _protocol(self, dpid, flows):
for flow in flows:
m = {}
for i in flow.match.items():
key = list(i)[0] # match key
val = list(i)[1] # match value
if key == "ip_proto":
prtcl = val
return prtcl
Upvotes: 0