From: Valentin Kautz <[email protected]>
Signed-off-by: Valentin Kautz <[email protected]>
---
ryu/contrib/ovs/socket_util.py | 29 ++++++++++++++++++++++++++++-
ryu/contrib/ovs/stream.py | 7 +++----
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/ryu/contrib/ovs/socket_util.py b/ryu/contrib/ovs/socket_util.py
index 1fc80fd..f349ddd 100644
--- a/ryu/contrib/ovs/socket_util.py
+++ b/ryu/contrib/ovs/socket_util.py
@@ -85,8 +85,19 @@ def check_connection_completion(sock):
def inet_parse_active(target, default_port):
- address = target.split(":")
+ """Splits the given target ip-address at the last occuring ':' to
+ separate address from port. Ipv6 addresses may be given with square
+ brackets at the beginning and the end.
+
+ example:
+ ipv4 target: "tcp:127.0.0.1:6632"
+ ipv6 target: "tcp:[2001:DB8:0:0::1]:6632"
+ """
+ address = target.rsplit(":", 1)
host_name = address[0]
+ host_name = host_name.rstrip("]")
+ host_name = host_name.lstrip("[")
+
if not host_name:
raise ValueError("%s: bad peer name format" % target)
if len(address) >= 2:
@@ -119,6 +130,22 @@ def inet_open_active(style, target, default_port, dscp):
return get_exception_errno(e), None
+def inet_open_active_stream(target, default_port, dscp):
+ address = inet_parse_active(target, default_port)
+ try:
+ sock = socket.create_connection(address)
+ except socket.error, e:
+ return get_exception_errno(e), None
+
+ try:
+ set_nonblocking(sock)
+ set_dscp(sock, dscp)
+ return 0, sock
+ except socket.error, e:
+ sock.close()
+ return get_exception_errno(e), None
+
+
def get_socket_error(sock):
"""Returns the errno value associated with 'socket' (0 if no error) and
resets the socket's error status."""
diff --git a/ryu/contrib/ovs/stream.py b/ryu/contrib/ovs/stream.py
index c640ebf..ccd9619 100644
--- a/ryu/contrib/ovs/stream.py
+++ b/ryu/contrib/ovs/stream.py
@@ -346,16 +346,15 @@ class UnixStream(Stream):
@staticmethod
def _open(suffix, dscp):
connect_path = suffix
- return ovs.socket_util.make_unix_socket(socket.SOCK_STREAM,
- True, None, connect_path)
+ return ovs.socket_util.make_unix_socket(socket.SOCK_STREAM,
+ True, None, connect_path)
Stream.register_method("unix", UnixStream)
class TCPStream(Stream):
@staticmethod
def _open(suffix, dscp):
- error, sock = ovs.socket_util.inet_open_active(socket.SOCK_STREAM,
- suffix, 0, dscp)
+ error, sock = ovs.socket_util.inet_open_active_stream(suffix, 0, dscp)
if not error:
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
return error, sock
--
2.4.3
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel