[ovs-dev] [PATCH] ovn-controller: add local address setting for ovn-remote connection

2016-04-27 Thread Huang Lei
From: Huang Lei 

In some environments, an interface may have multiple IP addresses
in same subnet, if TCP client socket doesn't call bind() explicitly,
OS will chooses an local IP and port for it, usually the primary IP of
the subnet will be chosen. With this patch, a secondary IP of the
subnet can be specified as local address of TCP connection.

Signed-off-by: Huang Lei 
---
 lib/socket-util.c   |  44 ++---
 lib/socket-util.h   |   3 +-
 lib/stream.c|   8 +--
 ofproto/ofproto-dpif-sflow.c|   2 +-
 ovn/controller/ovn-controller.8.xml |  15 -
 tests/library.at|   5 ++
 tests/test-util.c   | 121 
 7 files changed, 183 insertions(+), 15 deletions(-)

diff --git a/lib/socket-util.c b/lib/socket-util.c
index 5a36f3b..7ea25ec 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -392,7 +392,8 @@ exit:
 return false;
 }

-/* Parses 'target', which should be a string in the format "[:]".
+/* Parses 'target', which should be a string in the format
+ * "[:[:[:]]]".
  * , which is required, may be an IPv4 address or an IPv6 address
  * enclosed in square brackets.  If 'default_port' is nonzero then  is
  * optional and defaults to 'default_port'.
@@ -401,7 +402,8 @@ exit:
  * On failure, logs an error, stores zeros into '*ss', and returns false. */
 bool
 inet_parse_active(const char *target_, uint16_t default_port,
-  struct sockaddr_storage *ss)
+  struct sockaddr_storage *foreign_ss,
+  struct sockaddr_storage *local_ss)
 {
 char *target = xstrdup(target_);
 const char *port;
@@ -415,15 +417,32 @@ inet_parse_active(const char *target_, uint16_t 
default_port,
 if (!host) {
 VLOG_ERR("%s: host must be specified", target_);
 ok = false;
-} else if (!port && !default_port) {
+} else if ((!port || !port[0]) && !default_port) {
 VLOG_ERR("%s: port must be specified", target_);
 ok = false;
 } else {
-ok = parse_sockaddr_components(ss, host, port, default_port, target_);
+ok = parse_sockaddr_components(foreign_ss, host, port, default_port, 
target_);
 }
 if (!ok) {
-memset(ss, 0, sizeof *ss);
+memset(foreign_ss, 0, sizeof *foreign_ss);
+goto exit;
+}
+
+if (local_ss) {
+const char *local;
+const char *local_port;
+
+local = parse_bracketed_token(&p);
+local_port = parse_bracketed_token(&p);
+
+local = (!local || !local[0]) ? "0.0.0.0" : local;
+ok = parse_sockaddr_components(local_ss, local, local_port, 0, 
target_);
+if (!ok) {
+memset(local_ss, 0, sizeof *local_ss);
+}
 }
+
+exit:
 free(target);
 return ok;
 }
@@ -431,7 +450,8 @@ inet_parse_active(const char *target_, uint16_t 
default_port,

 /* Opens a non-blocking IPv4 or IPv6 socket of the specified 'style' and
  * connects to 'target', which should be a string in the format
- * "[:]".  , which is required, may be an IPv4 address or an
+ * "[:[:[:]]]".
+ * , which is required, may be an IPv4 address or an
  * IPv6 address enclosed in square brackets.  If 'default_port' is nonzero then
  *  is optional and defaults to 'default_port'.
  *
@@ -452,11 +472,12 @@ inet_open_active(int style, const char *target, uint16_t 
default_port,
  struct sockaddr_storage *ssp, int *fdp, uint8_t dscp)
 {
 struct sockaddr_storage ss;
+struct sockaddr_storage local_ss;
 int fd = -1;
 int error;

 /* Parse. */
-if (!inet_parse_active(target, default_port, &ss)) {
+if (!inet_parse_active(target, default_port, &ss, &local_ss)) {
 error = EAFNOSUPPORT;
 goto exit;
 }
@@ -482,6 +503,15 @@ inet_open_active(int style, const char *target, uint16_t 
default_port,
 goto exit;
 }

+error = bind(fd, (struct sockaddr *) &local_ss,
+ ss_length(&local_ss)) == 0
+ ? 0
+ : sock_errno();
+if (error) {
+VLOG_ERR("%s: bind failed", target);
+goto exit;
+}
+
 /* Connect. */
 error = connect(fd, (struct sockaddr *) &ss, ss_length(&ss)) == 0
 ? 0
diff --git a/lib/socket-util.h b/lib/socket-util.h
index c3c1224..1653483 100644
--- a/lib/socket-util.h
+++ b/lib/socket-util.h
@@ -44,7 +44,8 @@ void drain_fd(int fd, size_t n_packets);
 ovs_be32 guess_netmask(ovs_be32 ip);

 bool inet_parse_active(const char *target, uint16_t default_port,
-   struct sockaddr_storage *ssp);
+   struct sockaddr_storage *foreign_ssp,
+   struct sockaddr_storage *local_ssp

Re: [ovs-dev] [PATCH 2/2] ovn-controller: add local address for ovn-remote connection

2016-04-22 Thread Huang, Lei

On 4/22/16, 11:21 PM, "dev on behalf of Ben Pfaff"  wrote:

>On Fri, Apr 22, 2016 at 04:14:25PM +0800, Huang Lei wrote:
>> From: Huang Lei 
>> 
>> Add a local address option for ovn-controller's TCP socket which
>> connect to southbound ovsdb-server.
>> 
>> In a test environment, an interface may have multiple IP addresses
>> in same subnet, if TCP client socket doesn't call bind() explicitly,
>> OS chooses an ip and port for it, and the IP is the primary IP of
>> the subnet on an interface. With this patch, a secondary IP of the
>> subnet can be used as local address of TCP connection.
>> 
>> Signed-off-by: Huang Lei 
>
>Why not just extend the syntax for streams to allow a local address (and
>possibly local port) to be specified?
>e.g. remote-ip:remote-port:local-ip:local-port.

Hmmm, so the possible values of ‘external-ids:ovn-remote’ will be as follow:
external-ids:ovn-remote=tcp:192.168.0.1:6640:192.168.0.2:1

external-ids:ovn-remote=tcp:192.168.0.1:6640:192.168.0.2

external-ids:ovn-remote=tcp:192.168.0.1:6640


Right?

BR
Huang Lei

>___
>dev mailing list
>dev@openvswitch.org
>http://openvswitch.org/mailman/listinfo/dev
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 1/2] lib: parse_sockaddr_components() ignores bad port

2016-04-22 Thread Huang Lei
From: Huang Lei 

Bad port number erro is ignored in parse_sockaddr_components(),
if port number is invalid, it ouputs a error log and set port
to 0.

Signed-off-by: Huang Lei 
---
 lib/socket-util.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/socket-util.c b/lib/socket-util.c
index 5463c93..5a36f3b 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -359,6 +359,7 @@ parse_sockaddr_components(struct sockaddr_storage *ss,
 if (port_s && port_s[0]) {
 if (!str_to_int(port_s, 10, &port) || port < 0 || port > 65535) {
 VLOG_ERR("%s: bad port number \"%s\"", s, port_s);
+goto exit;
 }
 } else {
 port = default_port;
--
1.9.1



___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 2/2] ovn-controller: add local address for ovn-remote connection

2016-04-22 Thread Huang Lei
From: Huang Lei 

Add a local address option for ovn-controller's TCP socket which
connect to southbound ovsdb-server.

In a test environment, an interface may have multiple IP addresses
in same subnet, if TCP client socket doesn't call bind() explicitly,
OS chooses an ip and port for it, and the IP is the primary IP of
the subnet on an interface. With this patch, a secondary IP of the
subnet can be used as local address of TCP connection.

Signed-off-by: Huang Lei 
---
 lib/jsonrpc.c   | 16 +---
 lib/jsonrpc.h   |  6 --
 lib/netdev-dummy.c  |  3 ++-
 lib/ovsdb-idl.c | 10 ++
 lib/ovsdb-idl.h |  1 +
 lib/reconnect.c | 20 
 lib/reconnect.h |  2 ++
 lib/socket-util.c   | 23 ++-
 lib/socket-util.h   |  1 +
 lib/stream-provider.h   |  6 --
 lib/stream-ssl.c|  5 +++--
 lib/stream-tcp.c| 11 ++-
 lib/stream-unix.c   |  5 +++--
 lib/stream.c|  8 +---
 lib/stream.h|  4 +++-
 lib/syslog-direct.c |  2 +-
 lib/unixctl.c   |  2 +-
 lib/vconn-stream.c  |  2 +-
 lib/vlog.c  |  2 +-
 ofproto/collectors.c|  3 ++-
 ovn/controller/ovn-controller.c | 22 +-
 ovsdb/ovsdb-client.c|  2 +-
 tests/test-jsonrpc.c|  4 ++--
 tests/test-ovsdb.c  |  4 ++--
 24 files changed, 131 insertions(+), 33 deletions(-)

diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index 1112b4a..c79f3ec 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -61,9 +61,10 @@ static void jsonrpc_error(struct jsonrpc *, int error);
 /* This is just the same as stream_open() except that it uses the default
  * JSONRPC port if none is specified. */
 int
-jsonrpc_stream_open(const char *name, struct stream **streamp, uint8_t dscp)
+jsonrpc_stream_open(const char *name, const char *local,
+struct stream **streamp, uint8_t dscp)
 {
-return stream_open_with_default_port(name, OVSDB_PORT, streamp, dscp);
+return stream_open_with_default_port(name, local, OVSDB_PORT, streamp, 
dscp);
 }

 /* This is just the same as pstream_open() except that it uses the default
@@ -862,11 +863,12 @@ static void
 jsonrpc_session_connect(struct jsonrpc_session *s)
 {
 const char *name = reconnect_get_name(s->reconnect);
+const char *local = reconnect_get_local(s->reconnect);
 int error;

 jsonrpc_session_disconnect(s);
 if (!reconnect_is_passive(s->reconnect)) {
-error = jsonrpc_stream_open(name, &s->stream, s->dscp);
+error = jsonrpc_stream_open(name, local, &s->stream, s->dscp);
 if (!error) {
 reconnect_connecting(s->reconnect, time_msec());
 } else {
@@ -1164,3 +1166,11 @@ jsonrpc_session_set_dscp(struct jsonrpc_session *s, 
uint8_t dscp)
 jsonrpc_session_force_reconnect(s);
 }
 }
+
+/* Set the 'local' address used to connect to the remote host in active mode
+ * for TCP stream. */
+void
+jsonrpc_session_set_local(struct jsonrpc_session *s, const char *local)
+{
+reconnect_set_local(s->reconnect, local);
+}
diff --git a/lib/jsonrpc.h b/lib/jsonrpc.h
index 5f46e3b..8db0690 100644
--- a/lib/jsonrpc.h
+++ b/lib/jsonrpc.h
@@ -39,7 +39,8 @@ struct stream;
 #define OVSDB_OLD_PORT 6632
 #define OVSDB_PORT 6640

-int jsonrpc_stream_open(const char *name, struct stream **, uint8_t dscp);
+int jsonrpc_stream_open(const char *name, const char *local,
+struct stream **, uint8_t dscp);
 int jsonrpc_pstream_open(const char *name, struct pstream **, uint8_t dscp);

 struct jsonrpc *jsonrpc_open(struct stream *);
@@ -130,5 +131,6 @@ void jsonrpc_session_set_probe_interval(struct 
jsonrpc_session *,
 int probe_interval);
 void jsonrpc_session_set_dscp(struct jsonrpc_session *,
   uint8_t dscp);
-
+void jsonrpc_session_set_local(struct jsonrpc_session *,
+  const char *local);
 #endif /* jsonrpc.h */
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index 5acb4e1..09f9d31 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -400,7 +400,7 @@ dummy_packet_conn_set_config(struct dummy_packet_conn *conn,
 conn->u.rconn.reconnect = reconnect;
 conn->type = ACTIVE;

-error = stream_open(stream, &active_stream, DSCP_DEFAULT);
+error = stream_open(stream, NULL, &active_stream, DSCP_DEFAULT);
 conn->u.rconn.rstream = dummy_packet_stream_create(active_stream);

 switch (error) {
@@ -476,6 +476,7 @@ OVS_REQUIRES(dev->mutex)
 error = stream_connect(rconn->rstream->stream);
 

Re: [ovs-dev] [PATCH V4] ovn-controller: reload configured SB probe timer

2016-04-18 Thread Huang, Lei
vnsb_idl_loop.idl);
Need a whitespace after comma.
> 
> /* Contains "struct local_datpath" nodes whose hash values are the
>  * tunnel_key of datapaths with at least one local port binding. */
>@@ -561,3 +545,55 @@ ct_zone_list(struct unixctl_conn *conn, int argc 
>OVS_UNUSED,
> unixctl_command_reply(conn, ds_cstr(&ds));
> ds_destroy(&ds);
> }
>+
>+/* If SB probe timer is changed using ovs-vsctl command, this function
>+ * will set that probe timer value for the session.
>+ * cfg: Holding the external-id values read from southbound DB.
>+ * sb_idl: pointer to the ovs_idl connection to OVN southbound.
>+ */
>+static void
>+set_probe_timer_if_changed(const struct ovsrec_open_vswitch *cfg,
>+   const struct ovsdb_idl *sb_idl)
>+{
>+static int probe_int_sb = DEFAULT_PROBE_INTERVAL * 1000;
>+int probe_int_sb_new = probe_int_sb;
>+
>+extract_probe_timer(cfg, "ovn-remote-probe-interval", &probe_int_sb_new);
>+if (probe_int_sb_new != probe_int_sb) {
>+ovsdb_idl_set_probe_interval(sb_idl, probe_int_sb_new);
>+VLOG_INFO("OVN SB probe interval changed %d->%d ",
>+  probe_int_sb,
>+  probe_int_sb_new);
>+probe_int_sb = probe_int_sb_new;
>+}
>+}
>+
>+/* Given key_name, the following function retrieves probe_timer value from the
>+ * configuration passed, this configuration comes from the "external-ids"
>+ * which were configured via ovs-vsctl command.
>+ *
>+ * cfg: Holding the external-id values read from NB database.
>+ * keyname: Name to extract the value for.
>+ * ret_value_ptr: Pointer to integer location where the value read
>+ * should be copied.
>+ * The function returns true if success, keeps the original
>+ * value of ret_value_ptr intact in case of a failure.
Above style of the param doc strings is not found in other code in ovs, you may
need to change it. Not sure, just look around and find a suitable way ;)
>+ */
>+static bool
>+extract_probe_timer(const struct ovsrec_open_vswitch *cfg,
>+char *key_name,
>+int *ret_value_ptr)
>+{
>+const char *probe_interval= smap_get(&cfg->external_ids, key_name);
>+int ret_value_temp=0; /* Temporary location to hold the value, in case of
>+   * failure, str_to_int() sets the ret_value to 0,
>+   * which is a valid value of probe_timer. */
Wrap ‘=‘ with whitespace :)
>+if ((!probe_interval) ||
>+(!str_to_int(probe_interval, 10, &ret_value_temp)))  {
>+VLOG_WARN("OVN OVSDB invalid remote probe interval:%s for %s",
>+ probe_interval, key_name);
>+return false;
>+}
>+*ret_value_ptr = ret_value_temp;
>+return true;
>+}

Have tested the patch, works very well. 

BR
Huang Lei


>
>___
>dev mailing list
>dev@openvswitch.org
>http://openvswitch.org/mailman/listinfo/dev
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH v2] ovn-controller: optimize lex_token memory usage

2016-03-31 Thread Huang Lei
From: Huang Lei 

During our scalability test '2k HVs + 20k lports' we found that lexer is a
major user of heap memory:
-   5.22%  ovn-controller  libjemalloc.so.1[.] free
   - free
  + 27.46% lexer_get
  + 18.00% ofctrl_put
  ...
-   1.85%  ovn-controller  libjemalloc.so.1[.] malloc
   - malloc
   - xmalloc
  - 55.03% xmemdup0
 - 90.58% lex_parse_id.isra.0
- lexer_get
  ...

So lex_token is modified to usage a 'buffer' defined in it for tokens smaller
than 128 bytes, and for tokens bigger than 128 bytes it turn to use heap
memory. This change makes our test case run at least 10% faster.

Tested with 'ovn -- lexer' case.

Signed-off-by: Huang Lei 
---
 ovn/lib/lex.c | 78 ---
 ovn/lib/lex.h | 15 +---
 2 files changed, 86 insertions(+), 7 deletions(-)

diff --git a/ovn/lib/lex.c b/ovn/lib/lex.c
index 9cad5c7..f18fe3d 100644
--- a/ovn/lib/lex.c
+++ b/ovn/lib/lex.c
@@ -56,7 +56,11 @@ lex_token_init(struct lex_token *token)
 void
 lex_token_destroy(struct lex_token *token)
 {
-free(token->s);
+if (token->s && token->s != token->buffer) {
+free(token->s);
+}
+
+token->s = NULL;
 }

 /* Exchanges 'a' and 'b'. */
@@ -66,6 +70,70 @@ lex_token_swap(struct lex_token *a, struct lex_token *b)
 struct lex_token tmp = *a;
 *a = *b;
 *b = tmp;
+
+/* before swap, if 's' was pointed to 'buffer', its value shall be
+ * changed to point to the 'buffer' with the copied value.
+ */
+if (a->s == b->buffer) {
+a->s = a->buffer;
+}
+
+if (b->s == a->buffer) {
+b->s = b->buffer;
+}
+}
+
+/* the string 's' may not terminate by '\0' at 'length'. */
+void
+lex_token_strcpy(struct lex_token *token, const char *s, size_t length)
+{
+if (token->s == NULL || token->s == token->buffer) {
+if (length + 1 <= sizeof(token->buffer)) {
+memcpy(token->buffer, s, length);
+token->buffer[length] = '\0';
+token->s = token->buffer;
+return;
+}
+
+token->s = xmemdup0(s, length);
+} else {
+token->s = xrealloc(token->s, length + 1);
+memcpy(token->s, s, length);
+token->s[length] = '\0';
+}
+}
+
+void
+lex_token_strset(struct lex_token *token, char *s)
+{
+if (token->s && token->s != token->buffer) {
+free(token->s);
+}
+
+token->s = s;
+}
+
+void
+lex_token_vsprintf(struct lex_token *token, const char *format, va_list args)
+{
+va_list args2;
+size_t length;
+
+va_copy(args2, args);
+length = vsnprintf(NULL, 0, format, args);
+
+if (token->s == NULL || token->s == token->buffer) {
+if (length + 1 <= sizeof(token->buffer)) {
+token->s = token->buffer;
+} else {
+token->s = xmalloc(length + 1);
+}
+} else {
+token->s = xrealloc(token->s, length + 1);
+}
+
+vsnprintf(token->s, length + 1, format, args2);
+va_end(args2);
 }
 
 /* lex_token_format(). */
@@ -261,7 +329,7 @@ lex_error(struct lex_token *token, const char *message, ...)

 va_list args;
 va_start(args, message);
-token->s = xvasprintf(message, args);
+lex_token_vsprintf(token, message, args);
 va_end(args);
 }

@@ -428,6 +496,7 @@ static const char *
 lex_parse_string(const char *p, struct lex_token *token)
 {
 const char *start = ++p;
+char * s = NULL;
 for (;;) {
 switch (*p) {
 case '\0':
@@ -435,8 +504,9 @@ lex_parse_string(const char *p, struct lex_token *token)
 return p;

 case '"':
-token->type = (json_string_unescape(start, p - start, &token->s)
+token->type = (json_string_unescape(start, p - start, &s)
? LEX_T_STRING : LEX_T_ERROR);
+lex_token_strset(token, s);
 return p + 1;

 case '\\':
@@ -476,7 +546,7 @@ lex_parse_id(const char *p, struct lex_token *token)
 } while (lex_is_idn(*p));

 token->type = LEX_T_ID;
-token->s = xmemdup0(start, p - start);
+lex_token_strcpy(token, start, p - start);
 return p;
 }

diff --git a/ovn/lib/lex.h b/ovn/lib/lex.h
index 3c2bb6a..4f78c09 100644
--- a/ovn/lib/lex.h
+++ b/ovn/lib/lex.h
@@ -79,18 +79,27 @@ const char *lex_format_to_string(enum lex_format);

 /* A token.
  *
- * 's' is owned by the token. */
+ * 's' may point to 'buffer'; otherwise, it points to malloc()ed memory owned
+ * by the token. */
 struct lex_token {
 enum lex_type type; /* One of LEX_*. */
 char *s;

[ovs-dev] [PATCH] ovn-controller: optimize lex_token memory usage

2016-03-24 Thread Huang Lei
From: Huang Lei 

During our scalability test '2k HVs + 20k lports' we found that lexer is a
major user of heap memory:
-   5.22%  ovn-controller  libjemalloc.so.1[.] free
   - free
  + 27.46% lexer_get
  + 18.00% ofctrl_put
  ...
-   1.85%  ovn-controller  libjemalloc.so.1[.] malloc
   - malloc
   - xmalloc
  - 55.03% xmemdup0
 - 90.58% lex_parse_id.isra.0
- lexer_get
  ...

So lex_token is modified to usage a 'buffer' defined in it for tokens smaller
than 128 bytes, and for tokens bigger than 128 bytes it turn to use heap
memory. This change makes our test case run at least 10% faster.

Signed-off-by: Huang Lei 
---
 ovn/lib/lex.c | 77 +++
 ovn/lib/lex.h | 11 +
 2 files changed, 84 insertions(+), 4 deletions(-)

diff --git a/ovn/lib/lex.c b/ovn/lib/lex.c
index 9cad5c7..6dba223 100644
--- a/ovn/lib/lex.c
+++ b/ovn/lib/lex.c
@@ -50,13 +50,20 @@ lex_token_init(struct lex_token *token)
 {
 token->type = LEX_T_END;
 token->s = NULL;
+token->source = LEX_TOKEN_FIXED;
 }

 /* Frees memory owned by 'token'. */
 void
 lex_token_destroy(struct lex_token *token)
 {
-free(token->s);
+if (token->source == LEX_TOKEN_MALLOC) {
+ovs_assert(token->s != NULL);
+free(token->s);
+token->source = LEX_TOKEN_FIXED;
+}
+
+token->s = NULL;
 }

 /* Exchanges 'a' and 'b'. */
@@ -66,6 +73,66 @@ lex_token_swap(struct lex_token *a, struct lex_token *b)
 struct lex_token tmp = *a;
 *a = *b;
 *b = tmp;
+
+if (a->source == LEX_TOKEN_FIXED && a->s != NULL) {
+a->s = a->buffer;
+}
+
+if (b->source == LEX_TOKEN_FIXED && b->s != NULL) {
+b->s = b->buffer;
+}
+}
+
+/* the string 's' may not terminate by '\0' at 'length'. */
+void
+lex_token_strcpy(struct lex_token *token, const char *s, size_t length)
+{
+if (token->source == LEX_TOKEN_FIXED) {
+if (length + 1 <= sizeof(token->buffer)) {
+memcpy(token->buffer, s, length);
+token->buffer[length] = '\0';
+token->s = token->buffer;
+return;
+}
+
+token->source = LEX_TOKEN_MALLOC;
+token->s = xmemdup0(s, length);
+} else {
+token->s = xrealloc(token->s, length + 1);
+memcpy(token->s, s, length);
+token->s[length] = '\0';
+}
+}
+
+void
+lex_token_strset(struct lex_token *token, char *s)
+{
+token->source = LEX_TOKEN_MALLOC;
+token->s = s;
+}
+
+void
+lex_token_vsprintf(struct lex_token *token, const char *format, va_list args)
+{
+va_list args2;
+size_t length;
+
+va_copy(args2, args);
+length = vsnprintf(NULL, 0, format, args);
+
+if (token->source == LEX_TOKEN_FIXED) {
+if (length + 1 <= sizeof(token->buffer)) {
+token->s = token->buffer;
+} else {
+token->source = LEX_TOKEN_MALLOC;
+token->s = xmalloc(length + 1);
+}
+} else {
+token->s = xrealloc(token->s, length + 1);
+}
+
+vsnprintf(token->s, length + 1, format, args2);
+va_end(args2);
 }
 
 /* lex_token_format(). */
@@ -261,7 +328,7 @@ lex_error(struct lex_token *token, const char *message, ...)

 va_list args;
 va_start(args, message);
-token->s = xvasprintf(message, args);
+lex_token_vsprintf(token, message, args);
 va_end(args);
 }

@@ -428,6 +495,7 @@ static const char *
 lex_parse_string(const char *p, struct lex_token *token)
 {
 const char *start = ++p;
+char * s = NULL;
 for (;;) {
 switch (*p) {
 case '\0':
@@ -435,8 +503,9 @@ lex_parse_string(const char *p, struct lex_token *token)
 return p;

 case '"':
-token->type = (json_string_unescape(start, p - start, &token->s)
+token->type = (json_string_unescape(start, p - start, &s)
? LEX_T_STRING : LEX_T_ERROR);
+lex_token_strset(token, s);
 return p + 1;

 case '\\':
@@ -476,7 +545,7 @@ lex_parse_id(const char *p, struct lex_token *token)
 } while (lex_is_idn(*p));

 token->type = LEX_T_ID;
-token->s = xmemdup0(start, p - start);
+lex_token_strcpy(token, start, p - start);
 return p;
 }

diff --git a/ovn/lib/lex.h b/ovn/lib/lex.h
index 3c2bb6a..ae3a4ad 100644
--- a/ovn/lib/lex.h
+++ b/ovn/lib/lex.h
@@ -77,6 +77,11 @@ enum lex_format {
 };
 const char *lex_format_to_string(enum lex_format);

+enum lex_token_source {
+LEX_TOKEN_FIXED, /* use the buffer defined in lex_token */
+LEX_TOKEN_MALLOC, /* expand into head */
+};
+
 /* A token.
  *
  * 's' is owned by the token. *

[ovs-dev] [PATH v4] ovn-controller: Add external-id 'ovn-remote-probe-interval'

2016-03-24 Thread Huang Lei
From: Huang Lei 

Add a external-id 'ovn-remote-probe-interval' for setting the activity probe
interval of the json session from ovn-controller to the OVN southbound database.

Signed-off-by: Huang Lei 
---
 lib/ovsdb-idl.c |  9 +
 lib/ovsdb-idl.h |  2 ++
 ovn/controller/ovn-controller.8.xml | 14 ++
 ovn/controller/ovn-controller.c | 36 
 4 files changed, 61 insertions(+)

diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 4cb1c81..ac665c7 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -565,6 +565,15 @@ ovsdb_idl_get_last_error(const struct ovsdb_idl *idl)
 {
 return jsonrpc_session_get_last_error(idl->session);
 }
+
+/* Sets the "probe interval" for 'idl->session' to 'probe_interval', in
+ * milliseconds.
+ */
+void
+ovsdb_idl_set_probe_interval(const struct ovsdb_idl *idl, int probe_interval)
+{
+   jsonrpc_session_set_probe_interval(idl->session, probe_interval);
+}
 
 static unsigned char *
 ovsdb_idl_get_mode(struct ovsdb_idl *idl,
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 136c38c..e2e2a5e 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -68,6 +68,8 @@ void ovsdb_idl_verify_write_only(struct ovsdb_idl *);

 bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
 int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
+
+void ovsdb_idl_set_probe_interval(const struct ovsdb_idl *, int 
probe_interval);
 
 /* Choosing columns and tables to replicate. */

diff --git a/ovn/controller/ovn-controller.8.xml 
b/ovn/controller/ovn-controller.8.xml
index b261af9..6e57fc6 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -100,6 +100,20 @@
 
   

+  external_ids:ovn-remote-probe-interval
+  
+
+  The inactivity probe interval of the connection to the OVN database,
+  in milliseconds.
+  If the value is zero, it disables the connection keepalive feature.
+
+
+
+  If the value is nonzero, then it will be forced to a value of
+  at least 1000 ms.
+
+  
+
   external_ids:ovn-encap-type
   
 
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 5852e35..1822c2e 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -198,6 +198,35 @@ get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
 }
 }

+/* Retrieves the OVN Southbound remote's json session probe interval from the
+ * "external-ids:ovn-remote-probe-interval" key in 'ovs_idl' and returns it.
+ *
+ * This function must be called after get_ovnsb_remote().
+ *
+ */
+static bool
+get_ovnsb_remote_probe_interval(struct ovsdb_idl *ovs_idl, int *value)
+{
+const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
+if (!cfg) {
+return false;
+}
+
+const char * probe_interval =
+smap_get(&cfg->external_ids, "ovn-remote-probe-interval");
+if (probe_interval) {
+if (str_to_int(probe_interval, 10, value)) {
+VLOG_INFO("OVN remote probe interval is set to %d ms", *value);
+return true;
+}
+
+VLOG_WARN("Invalid value for OVN remote probe interval: %s",
+probe_interval);
+}
+
+return false;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -261,6 +290,13 @@ main(int argc, char *argv[])
 ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
 ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);

+int probe_interval = 0;
+if (get_ovnsb_remote_probe_interval(ovs_idl_loop.idl, &probe_interval)) {
+/* If 'probe_interval' is nonzero, then it will be forced to a value
+ * of at least 1000 ms.*/
+ovsdb_idl_set_probe_interval(ovnsb_idl_loop.idl, probe_interval);
+}
+
 /* Initialize connection tracking zones. */
 struct simap ct_zones = SIMAP_INITIALIZER(&ct_zones);
 unsigned long ct_zone_bitmap[BITMAP_N_LONGS(MAX_CT_ZONES)];
--
1.9.1



___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH v8 00/10] Implement incremental processing in ovn-controller

2016-03-20 Thread Huang, Lei
Hi Ryan,

I plan to test this patch in our scalability test environment, but it conflicts 
with bce7cf on master, lfow_run()’s definition had been changed a lot.

Would it be possible to get a rebase of this patch on current master?

BR
Huang Lei

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH] Add --enable-jemalloc argument to build

2016-03-13 Thread Huang, Lei
Hi,

I tested the patch in our scalability test environment, the test case as blow:
- 1000 sandboxes are created
- Each time create 5 lswitches each has 200 lports, that is, 1000 lport in 
total, then bind lports one by one to sandboxes randomly

After linked ovsdb-server, ovn-controller with jemalloc, the case running speed 
is faster about 10%:

lportbind 1k ports time(in seconds)
number(k)without jemallocwith jemalloc
-- -   --
21059.813   951.821
31193.991075.32
41215.679   1070.924
51236.211   1087.07
61218.208   1066.675
71245.089   1085.023
81265.645   1124.438
91260.462   1105.621
10   1229.317   1103.637



So I suggest this patch should be merged into mainstream. 

BR
Huang Lei
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATH v3] ovn-controller: Add external-ids:ovn-remote-probe-interval

2016-02-29 Thread Huang Lei
From: Huang Lei 

For setting the inactivity probe interval of the json session from 
ovn-controller to the OVN southbound database.

Signed-off-by: Huang Lei 
---
 lib/ovsdb-idl.c | 10 ++
 lib/ovsdb-idl.h |  4 
 ovn/controller/ovn-controller.8.xml | 14 ++
 ovn/controller/ovn-controller.c | 32 
 4 files changed, 60 insertions(+)

diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 4cb1c81..022f0cf 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -565,6 +565,16 @@ ovsdb_idl_get_last_error(const struct ovsdb_idl *idl)
 {
 return jsonrpc_session_get_last_error(idl->session);
 }
+
+/* Sets the "probe interval" for 'idl->session' to 'probe_interval', in
+ * milliseconds.
+ */
+void
+ovsdb_idl_set_probe_interval(const struct ovsdb_idl *idl, int probe_interval)
+{
+   jsonrpc_session_set_probe_interval(idl->session, probe_interval);
+}
+
 
 static unsigned char *
 ovsdb_idl_get_mode(struct ovsdb_idl *idl,
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 136c38c..96d9436 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -68,7 +68,11 @@ void ovsdb_idl_verify_write_only(struct ovsdb_idl *);

 bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
 int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
+
+void ovsdb_idl_set_probe_interval(const struct ovsdb_idl *, int 
probe_interval);
+
 
+
 /* Choosing columns and tables to replicate. */

 /* Modes with which the IDL can monitor a column.
diff --git a/ovn/controller/ovn-controller.8.xml 
b/ovn/controller/ovn-controller.8.xml
index b261af9..6e57fc6 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -100,6 +100,20 @@
 
   

+  external_ids:ovn-remote-probe-interval
+  
+
+  The inactivity probe interval of the connection to the OVN database,
+  in milliseconds.
+  If the value is zero, it disables the connection keepalive feature.
+
+
+
+  If the value is nonzero, then it will be forced to a value of
+  at least 1000 ms.
+
+  
+
   external_ids:ovn-encap-type
   
 
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index f5769b5..358b69d 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -34,7 +34,9 @@
 #include "poll-loop.h"
 #include "fatal-signal.h"
 #include "lib/hmap.h"
+#include "lib/ovsdb-idl.h"
 #include "lib/vswitch-idl.h"
+#include "lib/util.h"
 #include "smap.h"
 #include "stream.h"
 #include "stream-ssl.h"
@@ -198,6 +200,31 @@ get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
 }
 }

+/* Retrieves the OVN Southbound remote's json session probe interval from the
+ * "external-ids:ovn-remote-probe-interval" key in 'ovs_idl' and returns it.
+ *
+ * This function must be called after get_ovnsb_remote().
+ *
+ */
+static bool
+get_ovnsb_remote_probe_interval(struct ovsdb_idl *ovs_idl, int *value)
+{
+const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
+if (cfg) {
+const char * probe_interval =
+smap_get(&cfg->external_ids, "ovn-remote-probe-interval");
+if (probe_interval) {
+if (str_to_int(probe_interval, 10, value))
+{
+VLOG_INFO("OVN OVSDB remote probe interval is %d ms", *value);
+return true;
+}
+}
+}
+
+return false;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -261,6 +288,11 @@ main(int argc, char *argv[])
 ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
 ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);

+int probe_interval = 0;
+if (get_ovnsb_remote_probe_interval(ovs_idl_loop.idl, &probe_interval)) {
+ovsdb_idl_set_probe_interval(ovnsb_idl_loop.idl, probe_interval);
+}
+
 /* Initialize connection tracking zones. */
 struct simap ct_zones = SIMAP_INITIALIZER(&ct_zones);
 unsigned long ct_zone_bitmap[BITMAP_N_LONGS(MAX_CT_ZONES)];
--
2.5.4 (Apple Git-61)



___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH v2] ovn-controller: Add external-ids:ovn-remote-probe-interval

2016-02-24 Thread Huang, Lei
Comments line.

On Mon, Feb 22, 2016 at 12:50 AM, Huang Lei 
<148012...@qq.com<mailto:148012...@qq.com>> wrote:
From: Huang Lei mailto:lhua...@ebay.com>>

For setting the inactivity probe interval of the json session to the OVN 
southbound database.

Signed-off-by: Huang Lei mailto:lhua...@ebay.com>>
---
 lib/jsonrpc.c   |  4 +++-
 lib/ovsdb-idl.c | 10 ++
 lib/ovsdb-idl.h |  4 
 ovn/controller/ovn-controller.8.xml | 14 ++
 ovn/controller/ovn-controller.c | 33 +
 5 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index 35428a6..0985d52 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -1147,7 +1147,9 @@ void
 jsonrpc_session_set_probe_interval(struct jsonrpc_session *s,
int probe_interval)
 {
-reconnect_set_probe_interval(s->reconnect, probe_interval);
+if (stream_or_pstream_needs_probes(reconnect_get_name(s->reconnect))) {
+reconnect_set_probe_interval(s->reconnect, probe_interval);

This may cause subtle  behavior changes to current 
jsonrpc_session_set_probe_interval() users (ovsdb-idl and jsonrpc-server). It 
may not matter
much in practice, but would be nice not to introduce them, at least not within 
this patch.

[HL] Is it ok to move the stream_or_pstream_needs_probes() check into 
ovsdb_idl_set_probe_interval(), or simply keep 
jsonrpc_session_set_probe_interval() unchanged? Any suggestion?
+}
 }

 /* Sets the DSCP value used for 's''s connection to 'dscp'.  If this is
diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 4cb1c81..022f0cf 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -565,6 +565,16 @@ ovsdb_idl_get_last_error(const struct ovsdb_idl *idl)
 {
 return jsonrpc_session_get_last_error(idl->session);
 }
+
+/* Sets the "probe interval" for 'idl->session' to 'probe_interval', in
+ * milliseconds.
+ */
+void
+ovsdb_idl_set_probe_interval(const struct ovsdb_idl *idl, int probe_interval)
+{
+jsonrpc_session_set_probe_interval(idl->session, probe_interval);
+}
+

 static unsigned char *
 ovsdb_idl_get_mode(struct ovsdb_idl *idl,
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 136c38c..96d9436 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -68,7 +68,11 @@ void ovsdb_idl_verify_write_only(struct ovsdb_idl *);

 bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
 int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
+
+void ovsdb_idl_set_probe_interval(const struct ovsdb_idl *, int 
probe_interval);
+

+
 /* Choosing columns and tables to replicate. */

 /* Modes with which the IDL can monitor a column.
diff --git a/ovn/controller/ovn-controller.8.xml 
b/ovn/controller/ovn-controller.8.xml
index b261af9..6e57fc6 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -100,6 +100,20 @@
 
   

+  external_ids:ovn-remote-probe-interval
+  
+
+  The inactivity probe interval of the connection to the OVN database,
+  in milliseconds.
+  If the value is zero, it disables the connection keepalive feature.
+
+
+
+  If the value is nonzero, then it will be forced to a value of
+  at least 1000 ms.
+
+  
+
   external_ids:ovn-encap-type
   
 
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 3638342..7a1b966 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -34,7 +34,9 @@
 #include "poll-loop.h"
 #include "fatal-signal.h"
 #include "lib/hmap.h"
+#include "lib/ovsdb-idl.h"
 #include "lib/vswitch-idl.h"
+#include "lib/util.h"
 #include "smap.h"
 #include "stream.h"
 #include "stream-ssl.h"
@@ -198,6 +200,32 @@ get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
 }
 }

+/* Retrieves the OVN Southbound remote's json session probe interval from the
+ * "external-ids:ovn-remote-probe-interval" key in 'ovs_idl' and returns it.
+ *
+ * This function must be called after get_ovnsb_remote().
+ *
+ */
+static bool
+get_ovnsb_remote_probe_interval(struct ovsdb_idl *ovs_idl, int * value)
No need for a space between "*" and value.
+{
+const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
+if (cfg) {
+const char * probe_interval =
+smap_get(&cfg->external_ids, "ovn-remote-probe-interval");
+if (probe_interval) {
+if (str_to_int(probe_interval, 10, value))
+{
+VLOG_INFO("OVN OVSDB remote probe interval is %d ms", *value);
+return true;
+}
+}
+}
+
+return false;
+}
+
+
extra blan

Re: [ovs-dev] [PATCH] ovn-controller: Add external-ids:ovn-remote-probe-interval

2016-02-22 Thread Huang, Lei
Thanks for your review.

BR
Huang Lei


From: Andy Zhou mailto:az...@ovn.org>>
Date: Monday, February 22, 2016 at 7:38 AM
To: Huang Lei <148012...@qq.com<mailto:148012...@qq.com>>
Cc: "dev@openvswitch.org<mailto:dev@openvswitch.org>" 
mailto:dev@openvswitch.org>>, "Huang, Lei" 
mailto:lhua...@ebay.com>>
Subject: Re: [ovs-dev] [PATCH] ovn-controller: Add 
external-ids:ovn-remote-probe-interval



On Sun, Feb 21, 2016 at 1:26 PM, Huang Lei 
<148012...@qq.com<mailto:148012...@qq.com>> wrote:
From: Huang Lei mailto:lhua...@ebay.com>>

For setting the inactivity probe interval of the json session to the OVN 
southbound database.

Signed-off-by: Huang Lei mailto:lhua...@ebay.com>>

Thanks for contributing!. Please see comments in line.
---
 lib/ovsdb-idl.c | 10 ++
 lib/ovsdb-idl.h |  3 +++
 ovn/controller/ovn-controller.8.xml | 14 ++
 ovn/controller/ovn-controller.c | 33 +
 4 files changed, 60 insertions(+)

diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 7e84138..844d5b1 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -557,6 +557,16 @@ ovsdb_idl_get_last_error(const struct ovsdb_idl *idl)
 {
 return jsonrpc_session_get_last_error(idl->session);
 }
+
+/* Sets the "probe interval" for 'idl->session' to 'probe_interval', in
+ * milliseconds.
+ */
+void
+ovsdb_set_probe_interval(const struct ovsdb_idl *idl, int probe_interval)
+{
+   jsonrpc_session_set_probe_interval(idl->session, probe_interval);
+}
+
Should this function be called ovsdb_idl_set_probe_interval()?

 static unsigned char *
 ovsdb_idl_get_mode(struct ovsdb_idl *idl,
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 136c38c..224914f 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -68,6 +68,9 @@ void ovsdb_idl_verify_write_only(struct ovsdb_idl *);

 bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
 int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
+
+void ovsdb_set_probe_interval(const struct ovsdb_idl *, int probe_interval);
+
 /* Choosing columns and tables to replicate. */

diff --git a/ovn/controller/ovn-controller.8.xml 
b/ovn/controller/ovn-controller.8.xml
index 6dcc579..4202b59 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -100,6 +100,20 @@
 
   

+  external_ids:ovn-remote-probe-interval
+  
+
+  The inactivity probe interval of the connection to the OVN database,
+  in milliseconds.
+  If the value is zero, it disables the connection keepalive feature.
+
+
+
+  If 'probe_interval' is nonzero, then it will be forced to a value of
+  at least 1000 ms
+
+  
+
   external_ids:ovn-encap-type
   
 
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 02ecb3e..427d121 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -33,7 +33,10 @@
 #include "ovn/lib/ovn-sb-idl.h"
 #include "poll-loop.h"
 #include "fatal-signal.h"
+#include "lib/ovsdb-idl.h"
 #include "lib/vswitch-idl.h"
+#include "lib/util.h"
+#include "lib/reconnect.h"
 #include "smap.h"
 #include "stream.h"
 #include "stream-ssl.h"
@@ -197,6 +200,33 @@ get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
 }
 }

+/* Retrieves the OVN Southbound remote's json session probe interval from the
+ * "external-ids:ovn-remote-probe-interval" key in 'ovs_idl' and returns it.
+ *
+ * This function Must be called after get_ovnsb_remote().
+ *
+ */
s /Must/must

+static int
+get_ovnsb_remote_probe_interval(struct ovsdb_idl *ovs_idl)
+{
+const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
+if (cfg) {
+const char * probe_interval =
+smap_get(&cfg->external_ids, "ovn-remote-probe-interval");
+if (probe_interval) {
+int ret = 0;
+if (str_to_int(probe_interval, 10, & ret))
+{
+VLOG_INFO("OVN OVSDB remote probe interval is %d ms", ret);
+return ret;
+}
+}
+}
+
+return RECONNECT_DEFAULT_PROBE_INTERVAL;
+}
+
I think I will be slightly better if get_ovnsb_remote_probe_interval() returns 
whether the field is set
in OVSDB. if it is not set, or can not be read correctly.  In those case, we 
can simply
skip the call to ovsdb_set_probe_interval(). This way, we don't have to provide 
the default from here.

+
 int
 main(int argc, char *argv[])
 {
@@ -260,6 +290,9 @@ main(int argc, char *argv[])
 ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
 ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);


[ovs-dev] [PATCH v2] ovn-controller: Add external-ids:ovn-remote-probe-interval

2016-02-22 Thread Huang Lei
From: Huang Lei 

For setting the inactivity probe interval of the json session to the OVN 
southbound database.

Signed-off-by: Huang Lei 
---
 lib/jsonrpc.c   |  4 +++-
 lib/ovsdb-idl.c | 10 ++
 lib/ovsdb-idl.h |  4 
 ovn/controller/ovn-controller.8.xml | 14 ++
 ovn/controller/ovn-controller.c | 33 +
 5 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index 35428a6..0985d52 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -1147,7 +1147,9 @@ void
 jsonrpc_session_set_probe_interval(struct jsonrpc_session *s,
int probe_interval)
 {
-reconnect_set_probe_interval(s->reconnect, probe_interval);
+if (stream_or_pstream_needs_probes(reconnect_get_name(s->reconnect))) {
+reconnect_set_probe_interval(s->reconnect, probe_interval);
+}
 }

 /* Sets the DSCP value used for 's''s connection to 'dscp'.  If this is
diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 4cb1c81..022f0cf 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -565,6 +565,16 @@ ovsdb_idl_get_last_error(const struct ovsdb_idl *idl)
 {
 return jsonrpc_session_get_last_error(idl->session);
 }
+
+/* Sets the "probe interval" for 'idl->session' to 'probe_interval', in
+ * milliseconds.
+ */
+void
+ovsdb_idl_set_probe_interval(const struct ovsdb_idl *idl, int probe_interval)
+{
+jsonrpc_session_set_probe_interval(idl->session, probe_interval);
+}
+
 
 static unsigned char *
 ovsdb_idl_get_mode(struct ovsdb_idl *idl,
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 136c38c..96d9436 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -68,7 +68,11 @@ void ovsdb_idl_verify_write_only(struct ovsdb_idl *);

 bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
 int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
+
+void ovsdb_idl_set_probe_interval(const struct ovsdb_idl *, int 
probe_interval);
+
 
+
 /* Choosing columns and tables to replicate. */

 /* Modes with which the IDL can monitor a column.
diff --git a/ovn/controller/ovn-controller.8.xml 
b/ovn/controller/ovn-controller.8.xml
index b261af9..6e57fc6 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -100,6 +100,20 @@
 
   

+  external_ids:ovn-remote-probe-interval
+  
+
+  The inactivity probe interval of the connection to the OVN database,
+  in milliseconds.
+  If the value is zero, it disables the connection keepalive feature.
+
+
+
+  If the value is nonzero, then it will be forced to a value of
+  at least 1000 ms.
+
+  
+
   external_ids:ovn-encap-type
   
 
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 3638342..7a1b966 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -34,7 +34,9 @@
 #include "poll-loop.h"
 #include "fatal-signal.h"
 #include "lib/hmap.h"
+#include "lib/ovsdb-idl.h"
 #include "lib/vswitch-idl.h"
+#include "lib/util.h"
 #include "smap.h"
 #include "stream.h"
 #include "stream-ssl.h"
@@ -198,6 +200,32 @@ get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
 }
 }

+/* Retrieves the OVN Southbound remote's json session probe interval from the
+ * "external-ids:ovn-remote-probe-interval" key in 'ovs_idl' and returns it.
+ *
+ * This function must be called after get_ovnsb_remote().
+ *
+ */
+static bool
+get_ovnsb_remote_probe_interval(struct ovsdb_idl *ovs_idl, int * value)
+{
+const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
+if (cfg) {
+const char * probe_interval =
+smap_get(&cfg->external_ids, "ovn-remote-probe-interval");
+if (probe_interval) {
+if (str_to_int(probe_interval, 10, value))
+{
+VLOG_INFO("OVN OVSDB remote probe interval is %d ms", *value);
+return true;
+}
+}
+}
+
+return false;
+}
+
+
 int
 main(int argc, char *argv[])
 {
@@ -261,6 +289,11 @@ main(int argc, char *argv[])
 ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
 ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);

+int probe_interval = 0;
+if (get_ovnsb_remote_probe_interval(ovs_idl_loop.idl, &probe_interval)) {
+ovsdb_idl_set_probe_interval(ovnsb_idl_loop.idl, probe_interval);
+}
+
 /* Initialize connection tracking zones. */
 struct simap ct_zones = SIMAP_INITIALIZER(&ct_zones);
 unsigned long ct_zone_bitmap[BITMAP_N_LONGS(MAX_CT_ZONES)];
--
2.5.4 (Apple Git-61)


___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH] ovn-controller: Add external-ids:ovn-remote-probe-interval

2016-02-21 Thread Huang Lei
From: Huang Lei 

For setting the inactivity probe interval of the json session to the OVN 
southbound database.

Signed-off-by: Huang Lei 
---
 lib/ovsdb-idl.c | 10 ++
 lib/ovsdb-idl.h |  3 +++
 ovn/controller/ovn-controller.8.xml | 14 ++
 ovn/controller/ovn-controller.c | 33 +
 4 files changed, 60 insertions(+)

diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 7e84138..844d5b1 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -557,6 +557,16 @@ ovsdb_idl_get_last_error(const struct ovsdb_idl *idl)
 {
 return jsonrpc_session_get_last_error(idl->session);
 }
+
+/* Sets the "probe interval" for 'idl->session' to 'probe_interval', in
+ * milliseconds.
+ */
+void
+ovsdb_set_probe_interval(const struct ovsdb_idl *idl, int probe_interval)
+{
+   jsonrpc_session_set_probe_interval(idl->session, probe_interval);
+}
+
 
 static unsigned char *
 ovsdb_idl_get_mode(struct ovsdb_idl *idl,
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 136c38c..224914f 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -68,6 +68,9 @@ void ovsdb_idl_verify_write_only(struct ovsdb_idl *);

 bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
 int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
+
+void ovsdb_set_probe_interval(const struct ovsdb_idl *, int probe_interval);
+
 
 /* Choosing columns and tables to replicate. */

diff --git a/ovn/controller/ovn-controller.8.xml 
b/ovn/controller/ovn-controller.8.xml
index 6dcc579..4202b59 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -100,6 +100,20 @@
 
   

+  external_ids:ovn-remote-probe-interval
+  
+
+  The inactivity probe interval of the connection to the OVN database,
+  in milliseconds.
+  If the value is zero, it disables the connection keepalive feature.
+
+
+
+  If 'probe_interval' is nonzero, then it will be forced to a value of
+  at least 1000 ms
+
+  
+
   external_ids:ovn-encap-type
   
 
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 02ecb3e..427d121 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -33,7 +33,10 @@
 #include "ovn/lib/ovn-sb-idl.h"
 #include "poll-loop.h"
 #include "fatal-signal.h"
+#include "lib/ovsdb-idl.h"
 #include "lib/vswitch-idl.h"
+#include "lib/util.h"
+#include "lib/reconnect.h"
 #include "smap.h"
 #include "stream.h"
 #include "stream-ssl.h"
@@ -197,6 +200,33 @@ get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
 }
 }

+/* Retrieves the OVN Southbound remote's json session probe interval from the
+ * "external-ids:ovn-remote-probe-interval" key in 'ovs_idl' and returns it.
+ *
+ * This function Must be called after get_ovnsb_remote().
+ *
+ */
+static int
+get_ovnsb_remote_probe_interval(struct ovsdb_idl *ovs_idl)
+{
+const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
+if (cfg) {
+const char * probe_interval =
+smap_get(&cfg->external_ids, "ovn-remote-probe-interval");
+if (probe_interval) {
+int ret = 0;
+if (str_to_int(probe_interval, 10, & ret))
+{
+VLOG_INFO("OVN OVSDB remote probe interval is %d ms", ret);
+return ret;
+}
+}
+}
+
+return RECONNECT_DEFAULT_PROBE_INTERVAL;
+}
+
+
 int
 main(int argc, char *argv[])
 {
@@ -260,6 +290,9 @@ main(int argc, char *argv[])
 ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
 ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);

+int probe_interval = get_ovnsb_remote_probe_interval(ovs_idl_loop.idl);
+ovsdb_set_probe_interval(ovnsb_idl_loop.idl, probe_interval);
+
 /* Initialize connection tracking zones. */
 struct simap ct_zones = SIMAP_INITIALIZER(&ct_zones);
 unsigned long ct_zone_bitmap[BITMAP_N_LONGS(MAX_CT_ZONES)];
--
2.5.4 (Apple Git-61)



___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] Need a probe_interval option for jsonrpc session to southbound ovsdb-server in ovn-controller

2016-02-16 Thread Huang, Lei
Hi Andy,

I has configured ovn southbound ovsdb-server's inactivity_probe option to 0 by 
Open_vSwitch Manger table, and the ovsdb-server doesn’t set inactivity probe 
messages anymore.

But I found ovn-contorller still send inactivity probe message to ovsdb-server, 
because ovn-controller gets ovsdb-server database remote by 
"external-ids:ovn-remote” and there are no options to set the remote’s 
probe_interval, it’s default to 5 seconds. After 500 ovn-controller startup, 
the southbound ovsdb-server’s cpu usage becomes high obviously, so I want to 
add a 'external-ids:ovn-remote-inactivity-probe’ option, is it viable? Do you 
have other suggestions?


BR.
Huang Lei
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev