Merge branch 'master' of github.com:osrg/ryu

This commit is contained in:
FUJITA Tomonori 2013-05-23 07:40:02 +09:00
commit ce48a7da70
8 changed files with 62 additions and 45 deletions

View File

@ -1,5 +1,9 @@
#!/bin/sh
if [ -z "${PYTHON}" ]; then
PYTHON=python
fi
usage() {
echo "Usage: $0 [OPTION]..."
echo "Run Ryu's test suite(s)"
@ -116,7 +120,7 @@ run_integrated() {
sudo PYTHONPATH=. nosetests -s $INTEGRATED_TEST_RUNNER
}
#NOSETESTS="nosetests $noseopts $noseargs"
NOSETESTS="python ./ryu/tests/run_tests.py $noseopts $noseargs"
NOSETESTS="${PYTHON} ./ryu/tests/run_tests.py $noseopts $noseargs"
#if [ -n "$PLUGIN_DIR" ]
#then
@ -139,14 +143,14 @@ then
else
if [ $always_venv -eq 1 ]; then
# Automatically install the virtualenv
python tools/install_venv.py
${PYTHON} tools/install_venv.py
wrapper="${with_venv}"
else
echo -e "No virtual environment found...create one? (Y/n) \c"
read use_ve
if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
# Install the virtualenv and run the test suite in it
python tools/install_venv.py
${PYTHON} tools/install_venv.py
wrapper=${with_venv}
fi
fi

View File

@ -15,7 +15,6 @@
# limitations under the License.
import collections
import logging
from ryu import exception as ryu_exc
from ryu.app.rest_nw_id import (NW_ID_VPORT_GRE,
@ -57,7 +56,7 @@ class PortSet(app_manager.RyuApp):
class EventTunnelKeyDel(event.EventBase):
def __init__(self, tunnel_key):
super(EventTunnelKeyDel, self).__init__()
super(PortSet.EventTunnelKeyDel, self).__init__()
self.tunnel_key = tunnel_key
class EventPortBase(event.EventBase):

View File

@ -209,14 +209,7 @@ class OVSSwitch(object):
return
port_data = {
'datapath_id': dpid_lib.dpid_to_str(self.dpid),
'port_no': port.ofport,
# In order to set
# port.status = quantum.common.constants.PORT_STATUS_DOWN
# port.status can't be changed via rest api directly,
# so resort to ryu-specical parameter to tell it.
'deleted': True
'status': 'DOWN'
}
body = {'port': port_data}
# self.logger.debug("port-body = %s", body)

View File

@ -38,6 +38,8 @@ from ryu.ofproto import nx_match
from ryu.controller import handler
from ryu.controller import ofp_event
from ryu.lib.dpid import dpid_to_str
LOG = logging.getLogger('ryu.controller.controller')
CONF = cfg.CONF
@ -314,5 +316,5 @@ def datapath_connection_factory(socket, address):
# the parser raise exception.
# Can we do anything more graceful?
LOG.error("Error in the datapath %s from %s",
datapath.id, address)
dpid_to_str(datapath.id), address)
raise

View File

@ -24,6 +24,8 @@ from ryu.controller import ofp_event
from ryu.controller.handler import set_ev_cls
import ryu.exception as ryu_exc
from ryu.lib.dpid import dpid_to_str
LOG = logging.getLogger('ryu.controller.dpset')
DPSET_EV_DISPATCHER = "dpset"
@ -174,20 +176,20 @@ class DPSet(app_manager.RyuApp):
if reason == ofproto.OFPPR_ADD:
LOG.debug('DPSET: A port was added.' +
'(datapath id = %s, port number = %s)',
datapath.id, port.port_no)
dpid_to_str(datapath.id), port.port_no)
self._port_added(datapath, port)
self.send_event_to_observers(EventPortAdd(datapath, port))
elif reason == ofproto.OFPPR_DELETE:
LOG.debug('DPSET: A port was deleted.' +
'(datapath id = %s, port number = %s)',
datapath.id, port.port_no)
dpid_to_str(datapath.id), port.port_no)
self._port_deleted(datapath, port)
self.send_event_to_observers(EventPortDelete(datapath, port))
else:
assert reason == ofproto.OFPPR_MODIFY
LOG.debug('DPSET: A port was modified.' +
'(datapath id = %s, port number = %s)',
datapath.id, port.port_no)
dpid_to_str(datapath.id), port.port_no)
self.port_state[datapath.id].modify(port.port_no, port)
self.send_event_to_observers(EventPortModify(datapath, port))

View File

@ -17,6 +17,7 @@
import logging
import struct
import functools
import inspect
from ryu import exception
@ -51,17 +52,29 @@ def msg(datapath, version, msg_type, msg_len, xid, buf):
return msg_parser(datapath, version, msg_type, msg_len, xid, buf)
def create_list_of_attributes(f):
def create_list_of_base_attributes(f):
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
ret = f(self, *args, **kwargs)
self._attributes = set(dir(self))
self._base_attributes = set(dir(self))
return ret
return wrapper
class MsgBase(object):
@create_list_of_attributes
class StringifyMixin(object):
def __str__(self):
buf = ''
sep = ''
for k, v in ofp_attrs(self):
buf += sep
buf += "%s=%s" % (k, repr(v)) # repr() to escape binaries
sep = ','
return self.__class__.__name__ + '(' + buf + ')'
__repr__ = __str__ # note: str(list) uses __repr__ for elements
class MsgBase(StringifyMixin):
@create_list_of_base_attributes
def __init__(self, datapath):
self.datapath = datapath
self.version = None
@ -86,10 +99,10 @@ class MsgBase(object):
self.buf = buffer(buf)
def __str__(self):
buf = 'version: 0x%x msg_type 0x%x xid 0x%x' % (self.version,
self.msg_type,
self.xid)
return msg_str_attr(self, buf)
buf = 'version: 0x%x msg_type 0x%x xid 0x%x ' % (self.version,
self.msg_type,
self.xid)
return buf + StringifyMixin.__str__(self)
@classmethod
def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
@ -147,11 +160,23 @@ def msg_pack_into(fmt, buf, offset, *args):
struct.pack_into(fmt, buf, offset, *args)
def ofp_attrs(msg):
base = getattr(msg, '_base_attributes', [])
for k, v in inspect.getmembers(msg):
if k.startswith('_'):
continue
if callable(v):
continue
if k in base:
continue
if hasattr(msg.__class__, k):
continue
yield (k, v)
def msg_str_attr(msg, buf, attr_list=None):
if attr_list is None:
exclude = ['_attributes']
exclude += getattr(msg, '_attributes', [])
attr_list = set(dir(msg)) - set(exclude)
attr_list = ofp_attr(msg)
for attr in attr_list:
val = getattr(msg, attr, None)
if val is not None:

View File

@ -18,7 +18,7 @@ import collections
import struct
import binascii
from ofproto_parser import MsgBase, msg_pack_into, msg_str_attr
from ofproto_parser import StringifyMixin, MsgBase, msg_pack_into, msg_str_attr
from ryu.lib import mac
from . import ofproto_parser
from . import ofproto_v1_0
@ -90,7 +90,7 @@ class OFPPhyPort(collections.namedtuple('OFPPhyPort', (
return cls(*port)
class OFPMatch(object):
class OFPMatch(StringifyMixin):
def __init__(self, wildcards=None, in_port=None, dl_src=None, dl_dst=None,
dl_vlan=None, dl_vlan_pcp=None, dl_type=None, nw_tos=None,
nw_proto=None, nw_src=None, nw_dst=None,
@ -195,7 +195,7 @@ class OFPMatch(object):
return cls(*match)
class OFPActionHeader(object):
class OFPActionHeader(StringifyMixin):
def __init__(self, type_, len_):
self.type = type_
self.len = len_
@ -981,7 +981,7 @@ class OFPDescStats(collections.namedtuple('OFPDescStats', (
return stats
class OFPFlowStats(object):
class OFPFlowStats(StringifyMixin):
def __init__(self):
super(OFPFlowStats, self).__init__()
self.length = None
@ -1087,7 +1087,7 @@ class OFPVendorStats(collections.namedtuple('OFPVendorStats',
return stats
class NXFlowStats(object):
class NXFlowStats(StringifyMixin):
def __init__(self):
super(NXFlowStats, self).__init__()
self.length = None
@ -1153,7 +1153,7 @@ class NXAggregateStats(collections.namedtuple('NXAggregateStats', (
return stats
class OFPQueuePropHeader(object):
class OFPQueuePropHeader(StringifyMixin):
_QUEUE_PROPERTIES = {}
@staticmethod
@ -1169,10 +1169,6 @@ class OFPQueuePropHeader(object):
self.property = self.cls_prop_type
self.len = self.cls_prop_len
def __str__(self):
buf = super(OFPQueuePropHeader, self).__str__()
return msg_str_attr(self, buf, ('property', 'len'))
@classmethod
def parser(cls, buf, offset):
property_, len_ = struct.unpack_from(
@ -1203,10 +1199,6 @@ class OFPQueuePropMinRate(OFPQueuePropHeader):
super(OFPQueuePropMinRate, self).__init__()
self.rate = rate
def __str__(self):
buf = super(OFPQueuePropMinRate, self).__str__()
return msg_str_attr(self, buf, ('rate',))
@classmethod
def parser(cls, buf, offset):
(rate,) = struct.unpack_from(
@ -1215,7 +1207,7 @@ class OFPQueuePropMinRate(OFPQueuePropHeader):
return cls(rate)
class OFPPacketQueue(object):
class OFPPacketQueue(StringifyMixin):
def __init__(self, queue_id, len_):
self.queue_id = queue_id
self.len = len_

View File

@ -2739,7 +2739,7 @@ class OFPPacketQueue(MsgBase):
@classmethod
def parser(cls, buf, offset):
(msg.queue_id, msg.port, msg.len) = struct.unpack_from(
ofproto_v1_3.OFP_PACKET_QUEUE_PACK_STR, buf, offset)
ofproto_v1_3.OFP_PACKET_QUEUE_PACK_STR, msg.buf, offset)
length = ofproto_v1_3.OFP_PACKET_QUEUE_SIZE
offset += ofproto_v1_3.OFP_PACKET_QUEUE_SIZE
@ -2771,7 +2771,7 @@ class OFPQueueGetConfigReply(MsgBase):
msg.queues = []
offset += ofproto_v1_3.OFP_QUEUE_GET_CONFIG_REPLY_SIZE
while offset < msg.length:
while offset < msg_len:
queue = OFPPacketQueue.parser(buf, offset)
msg.queues.append(queue)
offset += queue.len