diff options
author | Ofer Ben-Yacov <ofer.benyacov@gmail.com> | 2016-05-18 18:29:13 +0300 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2016-05-20 08:10:53 -0700 |
commit | af3582371193ad296801fe5e32803b8faa0dced6 (patch) | |
tree | b4263384dad5de76356f02ced1f781f4dcff9679 /python | |
parent | 0cfd47f9dcc3914db8d266ed834d6e2c8fc1a11d (diff) | |
download | openvswitch-af3582371193ad296801fe5e32803b8faa0dced6.tar.gz |
python: Add TCP passive-mode to IDL.
Requested-by: "D M, Vikas" <vikas.d-m@hpe.com>
Requested-by: "Kamat, Maruti Haridas" <maruti.kamat@hpe.com>
Requested-by: "Sukhdev Kapur" <sukhdev@arista.com>
Requested-by: "Migliaccio, Armando" <armando.migliaccio@hpe.com>
Signed-off-by: "Ofer Ben-Yacov" <ofer.benyacov@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/ovs/jsonrpc.py | 2 | ||||
-rw-r--r-- | python/ovs/stream.py | 33 |
2 files changed, 24 insertions, 11 deletions
diff --git a/python/ovs/jsonrpc.py b/python/ovs/jsonrpc.py index e3ef6db51..6300c6721 100644 --- a/python/ovs/jsonrpc.py +++ b/python/ovs/jsonrpc.py @@ -435,7 +435,7 @@ class Session(object): self.reconnect.connecting(ovs.timeval.msec()) else: self.reconnect.connect_failed(ovs.timeval.msec(), error) - elif self.pstream is not None: + elif self.pstream is None: error, self.pstream = ovs.stream.PassiveStream.open(name) if not error: self.reconnect.listening(ovs.timeval.msec()) diff --git a/python/ovs/stream.py b/python/ovs/stream.py index 64d954453..97b22acc7 100644 --- a/python/ovs/stream.py +++ b/python/ovs/stream.py @@ -269,9 +269,9 @@ class PassiveStream(object): @staticmethod def is_valid_name(name): """Returns True if 'name' is a passive stream name in the form - "TYPE:ARGS" and TYPE is a supported passive stream type (currently only - "punix:"), otherwise False.""" - return name.startswith("punix:") + "TYPE:ARGS" and TYPE is a supported passive stream type (currently + "punix:" or "ptcp"), otherwise False.""" + return name.startswith("punix:") | name.startswith("ptcp:") def __init__(self, sock, name, bind_path): self.name = name @@ -282,8 +282,8 @@ class PassiveStream(object): def open(name): """Attempts to start listening for remote stream connections. 'name' is a connection name in the form "TYPE:ARGS", where TYPE is an passive - stream class's name and ARGS are stream class-specific. Currently the - only supported TYPE is "punix". + stream class's name and ARGS are stream class-specific. Currently the + supported values for TYPE are "punix" and "ptcp". Returns (error, pstream): on success 'error' is 0 and 'pstream' is the new PassiveStream, on failure 'error' is a positive errno value and @@ -294,10 +294,20 @@ class PassiveStream(object): bind_path = name[6:] if name.startswith("punix:"): bind_path = ovs.util.abs_file_name(ovs.dirs.RUNDIR, bind_path) - error, sock = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, - True, bind_path, None) - if error: - return error, None + error, sock = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, + True, bind_path, + None) + if error: + return error, None + + elif name.startswith("ptcp:"): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + remote = name.split(':') + sock.bind((remote[1], int(remote[2]))) + + else: + raise Exception('Unknown connection string') try: sock.listen(10) @@ -328,7 +338,10 @@ class PassiveStream(object): try: sock, addr = self.socket.accept() ovs.socket_util.set_nonblocking(sock) - return 0, Stream(sock, "unix:%s" % addr, 0) + if (sock.family == socket.AF_UNIX): + return 0, Stream(sock, "unix:%s" % addr, 0) + return 0, Stream(sock, 'ptcp:%s:%s' % (addr[0], + str(addr[1])), 0) except socket.error as e: error = ovs.socket_util.get_exception_errno(e) if error != errno.EAGAIN: |