Show warning when Datapath#ports is read
Datapath#ports is kept for compatibility with the previous openflow versions (< 1.3). Datapath#ports is not updated when received EventOFPPortStatus. This behavior may confuse users. Wherefore, showing warning message when the user accesses to Datapath#ports with the currently openflow versions (>= 1.3) is friendly. Signed-off-by: Satoshi Kobayashi <satoshi-k@stratosphere.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
325c9ae9c3
commit
172d9702ac
@ -31,6 +31,7 @@ import traceback
|
|||||||
import random
|
import random
|
||||||
import ssl
|
import ssl
|
||||||
from socket import IPPROTO_TCP, TCP_NODELAY
|
from socket import IPPROTO_TCP, TCP_NODELAY
|
||||||
|
import warnings
|
||||||
|
|
||||||
import ryu.base.app_manager
|
import ryu.base.app_manager
|
||||||
|
|
||||||
@ -120,11 +121,30 @@ class Datapath(ofproto_protocol.ProtocolDesc):
|
|||||||
|
|
||||||
self.xid = random.randint(0, self.ofproto.MAX_XID)
|
self.xid = random.randint(0, self.ofproto.MAX_XID)
|
||||||
self.id = None # datapath_id is unknown yet
|
self.id = None # datapath_id is unknown yet
|
||||||
self.ports = None
|
self._ports = None
|
||||||
self.flow_format = ofproto_v1_0.NXFF_OPENFLOW10
|
self.flow_format = ofproto_v1_0.NXFF_OPENFLOW10
|
||||||
self.ofp_brick = ryu.base.app_manager.lookup_service_brick('ofp_event')
|
self.ofp_brick = ryu.base.app_manager.lookup_service_brick('ofp_event')
|
||||||
self.set_state(handler.HANDSHAKE_DISPATCHER)
|
self.set_state(handler.HANDSHAKE_DISPATCHER)
|
||||||
|
|
||||||
|
def _get_ports(self):
|
||||||
|
if (self.ofproto_parser is not None and
|
||||||
|
self.ofproto_parser.ofproto.OFP_VERSION >= 0x04):
|
||||||
|
message = (
|
||||||
|
'Datapath#ports is kept for compatibility with the previous '
|
||||||
|
'openflow versions (< 1.3). '
|
||||||
|
'This not be updated by EventOFPPortStatus message. '
|
||||||
|
'If you want to be updated, you can use '
|
||||||
|
'\'ryu.controller.dpset\' or \'ryu.topology.switches\'.'
|
||||||
|
)
|
||||||
|
warnings.warn(message, stacklevel=2)
|
||||||
|
return self._ports
|
||||||
|
|
||||||
|
def _set_ports(self, ports):
|
||||||
|
self._ports = ports
|
||||||
|
|
||||||
|
# To show warning when Datapath#ports is read
|
||||||
|
ports = property(_get_ports, _set_ports)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.set_state(handler.DEAD_DISPATCHER)
|
self.set_state(handler.DEAD_DISPATCHER)
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ Basic OpenFlow handling including negotiation.
|
|||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
import warnings
|
||||||
|
|
||||||
import ryu.base.app_manager
|
import ryu.base.app_manager
|
||||||
|
|
||||||
@ -224,8 +225,10 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
|
|||||||
def multipart_reply_handler(self, ev):
|
def multipart_reply_handler(self, ev):
|
||||||
msg = ev.msg
|
msg = ev.msg
|
||||||
datapath = msg.datapath
|
datapath = msg.datapath
|
||||||
for port in msg.body:
|
with warnings.catch_warnings():
|
||||||
datapath.ports[port.port_no] = port
|
warnings.simplefilter('ignore')
|
||||||
|
for port in msg.body:
|
||||||
|
datapath.ports[port.port_no] = port
|
||||||
|
|
||||||
if msg.flags & datapath.ofproto.OFPMPF_REPLY_MORE:
|
if msg.flags & datapath.ofproto.OFPMPF_REPLY_MORE:
|
||||||
return
|
return
|
||||||
|
0
ryu/tests/unit/controller/__init__.py
Normal file
0
ryu/tests/unit/controller/__init__.py
Normal file
83
ryu/tests/unit/controller/test_controller.py
Normal file
83
ryu/tests/unit/controller/test_controller.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
# Copyright (C) 2015 Stratosphere Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
|
try:
|
||||||
|
import mock # Python 2
|
||||||
|
except ImportError:
|
||||||
|
from unittest import mock # Python 3
|
||||||
|
|
||||||
|
import warnings
|
||||||
|
import unittest
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import nose
|
||||||
|
from nose.tools import assert_equal
|
||||||
|
from nose.tools import assert_true
|
||||||
|
|
||||||
|
from ryu.base import app_manager # To suppress cyclic import
|
||||||
|
from ryu.controller import controller
|
||||||
|
from ryu.ofproto import ofproto_v1_3_parser
|
||||||
|
from ryu.ofproto import ofproto_v1_2_parser
|
||||||
|
from ryu.ofproto import ofproto_v1_0_parser
|
||||||
|
|
||||||
|
|
||||||
|
LOG = logging.getLogger('test_controller')
|
||||||
|
|
||||||
|
|
||||||
|
class Test_Datapath(unittest.TestCase):
|
||||||
|
|
||||||
|
""" Test case for Datapath
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _test_ports_accessibility(self, ofproto_parser, msgs_len):
|
||||||
|
with mock.patch('ryu.controller.controller.Datapath.set_state'):
|
||||||
|
|
||||||
|
# Ignore warnings
|
||||||
|
with warnings.catch_warnings(record=True) as msgs:
|
||||||
|
warnings.simplefilter('always')
|
||||||
|
|
||||||
|
# Test target
|
||||||
|
sock_mock = mock.Mock()
|
||||||
|
addr_mock = mock.Mock()
|
||||||
|
dp = controller.Datapath(sock_mock, addr_mock)
|
||||||
|
dp.ofproto_parser = ofproto_parser
|
||||||
|
|
||||||
|
# Create
|
||||||
|
dp.ports = {}
|
||||||
|
|
||||||
|
# Update
|
||||||
|
port_mock = mock.Mock()
|
||||||
|
dp.ports[0] = port_mock
|
||||||
|
|
||||||
|
# Read & Delete
|
||||||
|
del dp.ports[0]
|
||||||
|
|
||||||
|
assert_equal(len(msgs), msgs_len)
|
||||||
|
for msg in msgs:
|
||||||
|
assert_true(issubclass(msg.category, UserWarning))
|
||||||
|
|
||||||
|
def test_ports_accessibility_v13(self):
|
||||||
|
self._test_ports_accessibility(ofproto_v1_3_parser, 2)
|
||||||
|
|
||||||
|
def test_ports_accessibility_v12(self):
|
||||||
|
self._test_ports_accessibility(ofproto_v1_2_parser, 0)
|
||||||
|
|
||||||
|
def test_ports_accessibility_v10(self):
|
||||||
|
self._test_ports_accessibility(ofproto_v1_0_parser, 0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
nose.main(argv=['nosetests', '-s', '-v'], defaultTest=__file__)
|
Loading…
x
Reference in New Issue
Block a user