/*
- * Copyright (c) 2009, 2010, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct pstream {
const struct pstream_class *class;
char *name;
+ ovs_be16 bound_port;
};
void pstream_init(struct pstream *, const struct pstream_class *, const char *name);
+void pstream_set_bound_port(struct pstream *, ovs_be16 bound_port);
static inline void pstream_assert_class(const struct pstream *pstream,
const struct pstream_class *class)
{
/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
pssl = xmalloc(sizeof *pssl);
pstream_init(&pssl->pstream, &pssl_pstream_class, bound_name);
+ pstream_set_bound_port(&pssl->pstream, sin.sin_port);
pssl->fd = fd;
*pstreamp = &pssl->pstream;
return 0;
/*
- * Copyright (c) 2008, 2009, 2010, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
struct sockaddr_in sin;
char bound_name[128];
+ int error;
int fd;
fd = inet_open_passive(SOCK_STREAM, suffix, -1, &sin, dscp);
sprintf(bound_name, "ptcp:%"PRIu16":"IP_FMT,
ntohs(sin.sin_port), IP_ARGS(sin.sin_addr.s_addr));
- return new_fd_pstream(bound_name, fd, ptcp_accept, set_dscp, NULL,
- pstreamp);
+ error = new_fd_pstream(bound_name, fd, ptcp_accept, set_dscp, NULL,
+ pstreamp);
+ if (!error) {
+ pstream_set_bound_port(*pstreamp, sin.sin_port);
+ }
+ return error;
}
static int
/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
return 0;
}
+
+/* Returns the transport port on which 'pstream' is listening, or 0 if the
+ * concept doesn't apply. */
+ovs_be16
+pstream_get_bound_port(const struct pstream *pstream)
+{
+ return pstream->bound_port;
+}
\f
/* Initializes 'stream' as a new stream named 'name', implemented via 'class'.
* The initial connection status, supplied as 'connect_status', is interpreted
pstream_init(struct pstream *pstream, const struct pstream_class *class,
const char *name)
{
+ memset(pstream, 0, sizeof *pstream);
pstream->class = class;
pstream->name = xstrdup(name);
}
+
+void
+pstream_set_bound_port(struct pstream *pstream, ovs_be16 port)
+{
+ pstream->bound_port = port;
+}
\f
static int
count_fields(const char *s_)
/*
- * Copyright (c) 2009, 2010, 2011 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
int pstream_accept_block(struct pstream *, struct stream **);
void pstream_wait(struct pstream *);
int pstream_set_dscp(struct pstream *, uint8_t dscp);
+
+ovs_be16 pstream_get_bound_port(const struct pstream *);
\f
/* Convenience functions. */
struct reconnect_stats rstats;
struct ds locks_held, locks_waiting, locks_lost;
+ status->bound_port = (remote->listener
+ ? pstream_get_bound_port(remote->listener)
+ : htons(0));
+
if (list_is_empty(&remote->sessions)) {
return false;
}
-/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+/* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#define OVSDB_JSONRPC_SERVER_H 1
#include <stdbool.h>
+#include "openvswitch/types.h"
struct ovsdb;
struct shash;
char *locks_waiting;
char *locks_lost;
int n_connections;
+ ovs_be16 bound_port;
};
bool ovsdb_jsonrpc_server_get_remote_status(
const struct ovsdb_jsonrpc_server *, const char *target,
#include <errno.h>
#include <getopt.h>
+#include <inttypes.h>
#include <signal.h>
#include <unistd.h>
struct ovsdb_jsonrpc_remote_status status;
struct ovsdb_row *rw_row;
const char *target;
- char *keys[8], *values[8];
+ char *keys[9], *values[9];
size_t n = 0;
/* Get the "target" (protocol/host/port) spec. */
keys[n] = xstrdup("n_connections");
values[n++] = xasprintf("%d", status.n_connections);
}
+ if (status.bound_port != htons(0)) {
+ keys[n] = xstrdup("bound_port");
+ values[n++] = xasprintf("%"PRIu16, ntohs(status.bound_port));
+ }
write_string_string_column(rw_row, "status", keys, values, n);
ovsdb_jsonrpc_server_free_remote_status(&status);
AT_SETUP([ofproto-dpif - sFlow packet sampling])
OVS_VSWITCHD_START([set Bridge br0 fail-mode=standalone])
+ON_EXIT([kill `cat test-sflow.pid`])
AT_CHECK([test-sflow --log-file --detach --no-chdir --pidfile 0:127.0.0.1 > sflow.log], [0], [], [ignore])
AT_CAPTURE_FILE([sflow.log])
SFLOW_PORT=`parse_listening_port < test-sflow.log`
set Bridge br0 sflow=@sf -- \
--id=@sf create sflow targets=\"127.0.0.1:$SFLOW_PORT\" \
header=128 sampling=1 polling=1
-ON_EXIT([kill `cat test-sflow.pid`])
dnl open with ARP packets to seed the bridge-learning. The output
dnl ifIndex numbers should be reported predictably after that.
# parse_listening_port [SERVER]
#
-# Parses the TCP or SSL port on which a server is listening from the log,
-# given that the server was told to listen on a kernel-chosen port,
-# file provided on stdin, and prints the port number on stdout.
+# Parses the TCP or SSL port on which a server is listening from the
+# log, given that the server was told to listen on a kernel-chosen
+# port, file provided on stdin, and prints the port number on stdout.
+# You should specify the listening remote as ptcp:0:127.0.0.1 or
+# pssl:0:127.0.0.1.
#
# Here's an example of how to use this with ovsdb-server:
#
# OVS_LOGDIR=`pwd`; export OVS_LOGDIR
# ovsdb-server --log-file --remote=ptcp:0:127.0.0.1 ...
# TCP_PORT=`parse_listening_port < ovsdb-server.log`
-#
-# (Also works with pssl: in place of ptcp:.)
parse_listening_port () {
sed -n 's/.*0:127\.0\.0\.1: listening on port \([0-9]*\)$/\1/p'
}]
<dd>
<p>
Listens for SSL connections on the specified TCP <var>port</var>
- (default: 6632). If <var>ip</var>, which must be expressed as an
- IP address (not a DNS name), is specified, then connections are
- restricted to the specified local IP address.
+ (default: 6632). Specify 0 for <var>port</var> to have the
+ kernel automatically choose an available port. If <var>ip</var>,
+ which must be expressed as an IP address (not a DNS name), is
+ specified, then connections are restricted to the specified local
+ IP address.
</p>
<p>
The <ref table="Open_vSwitch" column="ssl"/> column in the <ref
<dt><code>ptcp:</code>[<var>port</var>][<code>:<var>ip</var></code>]</dt>
<dd>
Listens for connections on the specified TCP <var>port</var>
- (default: 6632). If <var>ip</var>, which must be expressed as an
- IP address (not a DNS name), is specified, then connections are
- restricted to the specified local IP address.
+ (default: 6632). Specify 0 for <var>port</var> to have the kernel
+ automatically choose an available port. If <var>ip</var>, which
+ must be expressed as an IP address (not a DNS name), is specified,
+ then connections are restricted to the specified local IP address.
</dd>
</dl>
<p>When multiple managers are configured, the <ref column="target"/>
chosen connection.
</p>
</column>
+
+ <column name="status" key="bound_port" type='{"type": "integer"}'>
+ When <ref column="target"/> is <code>ptcp:</code> or
+ <code>pssl:</code>, this is the TCP port on which the OVSDB server is
+ listening. (This is is particularly useful when <ref
+ column="target"/> specifies a port of 0, allowing the kernel to
+ choose any available port.)
+ </column>
</group>
<group title="Connection Parameters">