hi ever one
I need to apply the simple_monitor.py application in ryu controller but I got
some error :
line 21 self.logger.debug ('register datapath: %016',datapath.id)
syntaxError : invalid Syntax
the file of simple_monitro.py and the picture of error in the attachment
can any one how can I resolve this error ?
thank you in advance
Wisam Maala
# -*- coding: utf-8 -*
from operator import attrgetter
from ryu.app import simple_switch_13
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER, DEAD_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.lib import hub
class SimpleMonitor(simple_switch_13.SimpleSwitch13):
def __init__(self, *args, **kwargs):
super(SimpleMonitor, self).__init__(*args, **kwargs)
self.datapaths = {}
self.monitor_thread = hub.spawn(self._monitor)
@set_ev_cls(ofp_event.EventOFPStateChange,[MAIN_DISPATCHER, DEAD_DISPATCHER])
def _state_change_handler(self, ev):
datapath = ev.datapath
if ev.state == MAIN_DISPATCHER:
if not datapath.id in self.datapaths:
self.logger.debug(âregister datapath: %016xâ, datapath.id)
self.datapaths[datapath.id] = datapath
elif ev.state == DEAD_DISPATCHER:
if datapath.id in self.datapaths:
self.logger.debug(âunregister datapath: %016xâ, datapath.id)
del self.datapaths[datapath.id]
def _monitor(self):
while True:
for dp in self.datapaths.values():
self._request_stats(dp)
hub.sleep(10)
def _request_stats(self, datapath):
self.logger.debug(âsend stats request: %016xâ, datapath.id)
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
req = parser.OFPFlowStatsRequest(datapath)
datapath.send_msg(req)
req = parser.OFPPortStatsRequest(datapath, 0, ofproto.OFPP_ANY)
datapath.send_msg(req)
@set_ev_cls(ofp_event.EventOFPFlowStatsReply, MAIN_DISPATCHER)
def _flow_stats_reply_handler(self, ev):
body = ev.msg.body
self.logger.info(âdatapath
â
âin-port eth-dst
â
âout-port packets bytesâ)
self.logger.info(â---------------- â
â-------- ----------------- â
â-------- -------- --------â)
for stat in sorted([flow for flow in body if flow.priority == 1],
key=lambda flow: (flow.match[âin_portâ],
flow.match[âeth_dstâ])):
self.logger.info(â%016x %8x %17s %8x %8d %8dâ,
ev.msg.datapath.id,
stat.match[âin_portâ], stat.match[âeth_dstâ],
stat.instructions[0].actions[0].port,
stat.packet_count, stat.byte_count)
@set_ev_cls(ofp_event.EventOFPPortStatsReply, MAIN_DISPATCHER)
def _port_stats_reply_handler(self, ev):
body = ev.msg.body
self.logger.info(âdatapath
port
â
ârx-pkts rx-bytes rx-error â
âtx-pkts tx-bytes tx-errorâ)
self.logger.info(â---------------- -------- â
â-------- -------- -------- â
â-------- -------- --------â)
for stat in sorted(body, key=attrgetter(âport_noâ)):
self.logger.info(â%016x %8x %8d %8d %8d %8d %8d %8dâ,
ev.msg.datapath.id, stat.port_no,
stat.rx_packets, stat.rx_bytes, stat.rx_errors,
stat.tx_packets, stat.tx_bytes, stat.tx_errors)
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel