diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-07-17 06:57:34 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-07-17 19:32:13 +0900 |
commit | 4c2de66d32d51faf313ea14f84ce89dcbdf2e164 (patch) | |
tree | 1d99e8fb6ad6dd3e1c45b44e99153c4e3dbd10ff | |
parent | ad184686a89c8362a5b991f71d1283c93ce408fc (diff) |
stop import ofproto_v1_0 as ofproto
'from . import ofproto_v1_0 as ofproto' in ryu/ofproto/__init__.py is
a wrong assumption. We need to remove it.
This introduces ryu/ofproto/ofproto_common.py including only constatns
that OF version independent code must use. Note that I don't move data
structures there that multiple OF versions can share (like OVS does).
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/controller/controller.py | 8 | ||||
-rw-r--r-- | ryu/ofproto/__init__.py | 17 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_common.py | 25 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_parser.py | 8 | ||||
-rw-r--r-- | ryu/tests/unit/ofproto/test_ofproto_parser.py | 2 |
5 files changed, 34 insertions, 26 deletions
diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py index 5158323e..8f06c1e2 100644 --- a/ryu/controller/controller.py +++ b/ryu/controller/controller.py @@ -24,7 +24,7 @@ import greenlet from gevent.server import StreamServer from gevent.queue import Queue -from ryu.ofproto import ofproto +from ryu.ofproto import ofproto_common from ryu.ofproto import ofproto_parser from ryu.ofproto import ofproto_v1_0 from ryu.ofproto import ofproto_v1_0_parser @@ -40,7 +40,7 @@ LOG = logging.getLogger('ryu.controller.controller') FLAGS = gflags.FLAGS gflags.DEFINE_string('ofp_listen_host', '', 'openflow listen host') -gflags.DEFINE_integer('ofp_tcp_listen_port', ofproto.OFP_TCP_PORT, +gflags.DEFINE_integer('ofp_tcp_listen_port', ofproto_common.OFP_TCP_PORT, 'openflow tcp listen port') @@ -122,7 +122,7 @@ class Datapath(object): @_deactivate def _recv_loop(self): buf = bytearray() - required_len = ofproto.OFP_HEADER_SIZE + required_len = ofproto_common.OFP_HEADER_SIZE count = 0 while self.is_active: @@ -143,7 +143,7 @@ class Datapath(object): self.ev_q.queue(ofp_event.ofp_msg_to_ev(msg)) buf = buf[required_len:] - required_len = ofproto.OFP_HEADER_SIZE + required_len = ofproto_common.OFP_HEADER_SIZE # We need to schedule other greenlets. Otherwise, ryu # can't accept new switches or handle the existing diff --git a/ryu/ofproto/__init__.py b/ryu/ofproto/__init__.py index 5d889369..e69de29b 100644 --- a/ryu/ofproto/__init__.py +++ b/ryu/ofproto/__init__.py @@ -1,17 +0,0 @@ -# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation. -# Copyright (C) 2011 Isaku Yamahata <yamahata at valinux co jp> -# -# 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. - -from . import ofproto_v1_0 as ofproto diff --git a/ryu/ofproto/ofproto_common.py b/ryu/ofproto/ofproto_common.py new file mode 100644 index 00000000..49d1c12a --- /dev/null +++ b/ryu/ofproto/ofproto_common.py @@ -0,0 +1,25 @@ +# Copyright (C) 2011, 2012 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2011 Isaku Yamahata <yamahata at valinux co jp> +# +# 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. + +from struct import calcsize + + +OFP_HEADER_PACK_STR = '!BBHI' +OFP_HEADER_SIZE = 8 +assert calcsize(OFP_HEADER_PACK_STR) == OFP_HEADER_SIZE + +OFP_TCP_PORT = 6633 +OFP_SSL_PORT = 6633 diff --git a/ryu/ofproto/ofproto_parser.py b/ryu/ofproto/ofproto_parser.py index 93c0d8f9..21a86a9f 100644 --- a/ryu/ofproto/ofproto_parser.py +++ b/ryu/ofproto/ofproto_parser.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2011, 2012 Nippon Telegraph and Telephone Corporation. # Copyright (C) 2011 Isaku Yamahata <yamahata at valinux co jp> # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,15 @@ import struct from ryu import exception -from . import ofproto +from . import ofproto_common LOG = logging.getLogger('ryu.ofproto.ofproto_parser') def header(buf): - assert len(buf) >= ofproto.OFP_HEADER_SIZE + assert len(buf) >= ofproto_common.OFP_HEADER_SIZE #LOG.debug('len %d bufsize %d', len(buf), ofproto.OFP_HEADER_SIZE) - return struct.unpack_from(ofproto.OFP_HEADER_PACK_STR, buffer(buf)) + return struct.unpack_from(ofproto_common.OFP_HEADER_PACK_STR, buffer(buf)) _MSG_PARSERS = {} diff --git a/ryu/tests/unit/ofproto/test_ofproto_parser.py b/ryu/tests/unit/ofproto/test_ofproto_parser.py index 9a914c86..ea2f466d 100644 --- a/ryu/tests/unit/ofproto/test_ofproto_parser.py +++ b/ryu/tests/unit/ofproto/test_ofproto_parser.py @@ -21,7 +21,7 @@ from nose.tools import * import struct from ryu import exception -from ryu.ofproto import ofproto, ofproto_parser +from ryu.ofproto import ofproto_common, ofproto_parser from ryu.ofproto import ofproto_v1_0, ofproto_v1_0_parser import logging |