diff options
author | Yuichi Ito <ito.yuichi0@gmail.com> | 2013-12-27 10:56:40 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-12-27 15:24:18 +0900 |
commit | 988475f503fb8c65099d1718c6f4e4aebcbb4a57 (patch) | |
tree | f5c648a073fa80b5bf27567b064bbfd27630acd2 | |
parent | b8174161610efb6343acbaeac634736735274396 (diff) |
ofctl_rest: support OpenFlow1.2
this patch makes ofctl_rest enable use of OpenFlow1.2.
Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
-rw-r--r-- | ryu/app/ofctl_rest.py | 20 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_2.py | 44 |
2 files changed, 64 insertions, 0 deletions
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py index 61e99ed5..ce6a78b6 100644 --- a/ryu/app/ofctl_rest.py +++ b/ryu/app/ofctl_rest.py @@ -24,8 +24,10 @@ from ryu.controller import dpset from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import set_ev_cls from ryu.ofproto import ofproto_v1_0 +from ryu.ofproto import ofproto_v1_2 from ryu.ofproto import ofproto_v1_3 from ryu.lib import ofctl_v1_0 +from ryu.lib import ofctl_v1_2 from ryu.lib import ofctl_v1_3 from ryu.app.wsgi import ControllerBase, WSGIApplication @@ -99,6 +101,8 @@ class StatsController(ControllerBase): if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION: desc = ofctl_v1_0.get_desc_stats(dp, self.waiters) + elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION: + desc = ofctl_v1_2.get_desc_stats(dp, self.waiters) elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION: desc = ofctl_v1_3.get_desc_stats(dp, self.waiters) else: @@ -115,6 +119,8 @@ class StatsController(ControllerBase): if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION: flows = ofctl_v1_0.get_flow_stats(dp, self.waiters) + elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION: + flows = ofctl_v1_2.get_flow_stats(dp, self.waiters) elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION: flows = ofctl_v1_3.get_flow_stats(dp, self.waiters) else: @@ -131,6 +137,8 @@ class StatsController(ControllerBase): if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION: ports = ofctl_v1_0.get_port_stats(dp, self.waiters) + elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION: + ports = ofctl_v1_2.get_port_stats(dp, self.waiters) elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION: ports = ofctl_v1_3.get_port_stats(dp, self.waiters) else: @@ -205,6 +213,8 @@ class StatsController(ControllerBase): if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION: ofctl_v1_0.mod_flow_entry(dp, flow, cmd) + elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION: + ofctl_v1_2.mod_flow_entry(dp, flow, cmd) elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION: ofctl_v1_3.mod_flow_entry(dp, flow, cmd) else: @@ -220,6 +230,8 @@ class StatsController(ControllerBase): if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION: ofctl_v1_0.delete_flow_entry(dp) + elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFPVERSION: + ofctl_v1_2.mod_flow_entry(dp, {}, dp.ofproto.OFPFC_DELETE) elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION: ofctl_v1_3.mod_flow_entry(dp, {}, dp.ofproto.OFPFC_DELETE) else: @@ -260,6 +272,7 @@ class StatsController(ControllerBase): class RestStatsApi(app_manager.RyuApp): OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION, + ofproto_v1_2.OFP_VERSION, ofproto_v1_3.OFP_VERSION] _CONTEXTS = { 'dpset': dpset.DPSet, @@ -342,6 +355,8 @@ class RestStatsApi(app_manager.RyuApp): flags = 0 if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION: flags = dp.ofproto.OFPSF_REPLY_MORE + elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION: + flags = dp.ofproto.OFPSF_REPLY_MORE elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION: flags = dp.ofproto.OFPMPF_REPLY_MORE @@ -350,6 +365,11 @@ class RestStatsApi(app_manager.RyuApp): del self.waiters[dp.id][msg.xid] lock.set() + @set_ev_cls(ofp_event.EventOFPStatsReply, MAIN_DISPATCHER) + def any_stats_reply_handler(self, ev): + # for OpenFlow 1.2 + self.stats_reply_handler(ev) + @set_ev_cls(ofp_event.EventOFPDescStatsReply, MAIN_DISPATCHER) def desc_stats_reply_handler(self, ev): self.stats_reply_handler(ev) diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py index e768efa0..1591c35e 100644 --- a/ryu/lib/ofctl_v1_2.py +++ b/ryu/lib/ofctl_v1_2.py @@ -202,6 +202,23 @@ def send_stats_request(dp, stats, waiters, msgs): del waiters_per_dp[stats.xid] +def get_desc_stats(dp, waiters): + stats = dp.ofproto_parser.OFPDescStatsRequest(dp) + msgs = [] + send_stats_request(dp, stats, waiters, msgs) + + s = {} + for msg in msgs: + stats = msg.body + s = {'mfr_desc': stats.mfr_desc, + 'hw_desc': stats.hw_desc, + 'sw_desc': stats.sw_desc, + 'serial_num': stats.serial_num, + 'dp_desc': stats.dp_desc} + desc = {str(dp.id): s} + return desc + + def get_flow_stats(dp, waiters): table_id = 0 out_port = dp.ofproto.OFPP_ANY @@ -239,6 +256,33 @@ def get_flow_stats(dp, waiters): return flows +def get_port_stats(dp, waiters): + stats = dp.ofproto_parser.OFPPortStatsRequest( + dp, dp.ofproto.OFPP_ANY, 0) + msgs = [] + send_stats_request(dp, stats, waiters, msgs) + + ports = [] + for msg in msgs: + for stats in msg.body: + s = {'port_no': stats.port_no, + 'rx_packets': stats.rx_packets, + 'tx_packets': stats.tx_packets, + 'rx_bytes': stats.rx_bytes, + 'tx_bytes': stats.tx_bytes, + 'rx_dropped': stats.rx_dropped, + 'tx_dropped': stats.tx_dropped, + 'rx_errors': stats.rx_errors, + 'tx_errors': stats.tx_errors, + 'rx_frame_err': stats.rx_frame_err, + 'rx_over_err': stats.rx_over_err, + 'rx_crc_err': stats.rx_crc_err, + 'collisions': stats.collisions} + ports.append(s) + ports = {str(dp.id): ports} + return ports + + def mod_flow_entry(dp, flow, cmd): cookie = int(flow.get('cookie', 0)) cookie_mask = int(flow.get('cookie_mask', 0)) |