this patch makes ofctl_rest enable use of OpenFlow1.2.

Signed-off-by: Yuichi Ito <[email protected]>
---
 ryu/app/ofctl_rest.py |   20 ++++++++++++++++++++
 ryu/lib/ofctl_v1_2.py |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py
index 61e99ed..ce6a78b 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 e768efa..1591c35 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))
-- 
1.7.10.4


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to