Folks,

As stated in the first email in this patch series:

"
4) Applications must now inform the core that they have "taken ownership" of a 
Datapath object.
Previously, Datapaths could “leak” if they did not make it through the OpenFlow 
handshake. I have addressed this by adding a timer that disconnects any 
Datapath that is not claimed by an application after a certain interval 
(currently statically defined at 20 seconds - but it could be made 
user-configurable).
An application that wishes to ensure that Datapaths are properly cleaned up 
(and do not disappear out from under them) should:
i) Have a structure keeping track of what Datapaths it “owns."
ii) When handling the an EventOFPSwitchFeatures in the CONFIG_DISPATCHER, or 
any event in the MAIN_DISPATCHER, the application should ensure that the 
datapath has been tracked in its internal record-keeping structure, and set the 
“assured” field of the Datapath object to “True”.
iii) When the application discovers duplicate records for a given Datapath 
(during handling of a new Datapath having the same DPID) in its internal 
structure, it should call the close() method of the old Datapath, after first 
recording the new Datapath in its internal record-keeping structure.

Applications that do not set the “assured” field of a Datapath will find that 
the Datapath will be closed underneath them by the Ryu core.
Applications using ryu.controller.dpset or ryu.topology.switches will find that 
this has been automatically handled for them.
Furthermore, another of the patches in this series ensures that all sample 
applications have been patched.
“

This patch fixes the sample applications shipped with Ryu to follow these new 
semantics.

Signed-off-by: Victor J. Orlikowski <[email protected]>

diff --git a/ryu/app/cbench.py b/ryu/app/cbench.py
index aed83ab..c2bc648 100644
--- a/ryu/app/cbench.py
+++ b/ryu/app/cbench.py
@@ -31,6 +31,7 @@ class Cbench(app_manager.RyuApp):
 
     def __init__(self, *args, **kwargs):
         super(Cbench, self).__init__(*args, **kwargs)
+        self.dpid_to_dp = {}
 
     @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
     def packet_in_handler(self, ev):
@@ -38,6 +39,14 @@ class Cbench(app_manager.RyuApp):
         datapath = msg.datapath
         ofproto = datapath.ofproto
 
+        dpid = datapath.id
+        id2dp_entry = self.dpid_to_dp.get(dpid)
+        if ((id2dp_entry is not None) and
+            (id2dp_entry is not datapath)):
+            id2dp_entry.close()
+        dpid_to_dp[dpid] = datapath
+        datapath.assured = True
+
         match = datapath.ofproto_parser.OFPMatch(
             ofproto_v1_0.OFPFW_ALL, 0, 0, 0,
             0, 0, 0, 0, 0, 0, 0, 0, 0)
diff --git a/ryu/app/ofctl/service.py b/ryu/app/ofctl/service.py
index 0ca00c7..edde2b1 100644
--- a/ryu/app/ofctl/service.py
+++ b/ryu/app/ofctl/service.py
@@ -79,6 +79,9 @@ class OfctlService(app_manager.RyuApp):
         self.logger.debug('add dpid %s datapath %s new_info %s old_info %s',
                           id, datapath, new_info, old_info)
         self._switches[id] = new_info
+        datapath.assured = True
+        if old_info:
+            old_info.datapath.close()
 
     @set_ev_cls(ofp_event.EventOFPStateChange, DEAD_DISPATCHER)
     def _handle_dead(self, ev):
diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py
index 862b830..1c40e6b 100644
--- a/ryu/app/simple_switch.py
+++ b/ryu/app/simple_switch.py
@@ -65,7 +65,13 @@ class SimpleSwitch(app_manager.RyuApp):
         src = eth.src
 
         dpid = datapath.id
-        self.mac_to_port.setdefault(dpid, {})
+        m2p_entry = self.mac_to_port.setdefault(dpid, {})
+        m2p_datapath = m2p_entry.get('datapath')
+        if ((m2p_datapath is not None) and
+            (m2p_datapath is not datapath)):
+            m2p_datapath.close()
+        m2p_entry['datapath'] = datapath
+        datapath.assured = True
 
         self.logger.info("packet in %s %s %s %s", dpid, src, dst, msg.in_port)
 
diff --git a/ryu/app/simple_switch_12.py b/ryu/app/simple_switch_12.py
index 6895b07..e434b2c 100644
--- a/ryu/app/simple_switch_12.py
+++ b/ryu/app/simple_switch_12.py
@@ -64,7 +64,13 @@ class SimpleSwitch12(app_manager.RyuApp):
         src = eth.src
 
         dpid = datapath.id
-        self.mac_to_port.setdefault(dpid, {})
+        m2p_entry = self.mac_to_port.setdefault(dpid, {})
+        m2p_datapath = m2p_entry.get('datapath')
+        if ((m2p_datapath is not None) and
+            (m2p_datapath is not datapath)):
+            m2p_datapath.close()
+        m2p_entry['datapath'] = datapath
+        datapath.assured = True
 
         self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
 
diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
index 3e7c598..ffc8ac8 100644
--- a/ryu/app/simple_switch_13.py
+++ b/ryu/app/simple_switch_13.py
@@ -86,7 +86,13 @@ class SimpleSwitch13(app_manager.RyuApp):
         src = eth.src
 
         dpid = datapath.id
-        self.mac_to_port.setdefault(dpid, {})
+        m2p_entry = self.mac_to_port.setdefault(dpid, {})
+        m2p_datapath = m2p_entry.get('datapath')
+        if ((m2p_datapath is not None) and
+            (m2p_datapath is not datapath)):
+            m2p_datapath.close()
+        m2p_entry['datapath'] = datapath
+        datapath.assured = True
 
         self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
 
diff --git a/ryu/app/simple_switch_14.py b/ryu/app/simple_switch_14.py
index d3151bc..be9beef 100644
--- a/ryu/app/simple_switch_14.py
+++ b/ryu/app/simple_switch_14.py
@@ -77,7 +77,13 @@ class SimpleSwitch14(app_manager.RyuApp):
         src = eth.src
 
         dpid = datapath.id
-        self.mac_to_port.setdefault(dpid, {})
+        m2p_entry = self.mac_to_port.setdefault(dpid, {})
+        m2p_datapath = m2p_entry.get('datapath')
+        if ((m2p_datapath is not None) and
+            (m2p_datapath is not datapath)):
+            m2p_datapath.close()
+        m2p_entry['datapath'] = datapath
+        datapath.assured = True
 
         self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
 
diff --git a/ryu/app/simple_switch_igmp.py b/ryu/app/simple_switch_igmp.py
index b1b014f..e5656c0 100644
--- a/ryu/app/simple_switch_igmp.py
+++ b/ryu/app/simple_switch_igmp.py
@@ -67,7 +67,13 @@ class SimpleSwitchIgmp(app_manager.RyuApp):
         dst = addrconv.mac.bin_to_text(dst_)
 
         dpid = datapath.id
-        self.mac_to_port.setdefault(dpid, {})
+        m2p_entry = self.mac_to_port.setdefault(dpid, {})
+        m2p_datapath = m2p_entry.get('datapath')
+        if ((m2p_datapath is not None) and
+            (m2p_datapath is not datapath)):
+            m2p_datapath.close()
+        m2p_entry['datapath'] = datapath
+        datapath.assured = True
 
         self.logger.info("packet in %s %s %s %s",
                          dpid, src, dst, msg.in_port)
diff --git a/ryu/app/simple_switch_lacp.py b/ryu/app/simple_switch_lacp.py
index 3774163..5d27cf6 100644
--- a/ryu/app/simple_switch_lacp.py
+++ b/ryu/app/simple_switch_lacp.py
@@ -77,7 +77,13 @@ class SimpleSwitchLacp(app_manager.RyuApp):
         dst = addrconv.mac.bin_to_text(dst_)
 
         dpid = datapath.id
-        self.mac_to_port.setdefault(dpid, {})
+        m2p_entry = self.mac_to_port.setdefault(dpid, {})
+        m2p_datapath = m2p_entry.get('datapath')
+        if ((m2p_datapath is not None) and
+            (m2p_datapath is not datapath)):
+            m2p_datapath.close()
+        m2p_entry['datapath'] = datapath
+        datapath.assured = True
 
         self.logger.info("packet in %s %s %s %s",
                          dpid, src, dst, msg.in_port)
diff --git a/ryu/app/simple_switch_snort.py b/ryu/app/simple_switch_snort.py
index 553a8bb..56a2ea6 100644
--- a/ryu/app/simple_switch_snort.py
+++ b/ryu/app/simple_switch_snort.py
@@ -117,7 +117,13 @@ class SimpleSwitchSnort(app_manager.RyuApp):
         src = eth.src
 
         dpid = datapath.id
-        self.mac_to_port.setdefault(dpid, {})
+        m2p_entry = self.mac_to_port.setdefault(dpid, {})
+        m2p_datapath = m2p_entry.get('datapath')
+        if ((m2p_datapath is not None) and
+            (m2p_datapath is not datapath)):
+            m2p_datapath.close()
+        m2p_entry['datapath'] = datapath
+        datapath.assured = True
 
         # self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
 
diff --git a/ryu/app/simple_switch_stp.py b/ryu/app/simple_switch_stp.py
index a86c8a5..001bd44 100644
--- a/ryu/app/simple_switch_stp.py
+++ b/ryu/app/simple_switch_stp.py
@@ -85,7 +85,13 @@ class SimpleSwitchStp(app_manager.RyuApp):
         dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
 
         dpid = datapath.id
-        self.mac_to_port.setdefault(dpid, {})
+        m2p_entry = self.mac_to_port.setdefault(dpid, {})
+        m2p_datapath = m2p_entry.get('datapath')
+        if ((m2p_datapath is not None) and
+            (m2p_datapath is not datapath)):
+            m2p_datapath.close()
+        m2p_entry['datapath'] = datapath
+        datapath.assured = True
 
         self.logger.debug("packet in %s %s %s %s",
                           dpid, haddr_to_str(src), haddr_to_str(dst),



Best,
Victor
--
Victor J. Orlikowski <> vjo@[cs.]duke.edu

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to