2009-06-12 17:10:09 -07:00
|
|
|
/*
|
2014-04-01 00:47:01 -07:00
|
|
|
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
|
2009-06-12 17:10:09 -07:00
|
|
|
*
|
2009-06-15 16:08:34 -07:00
|
|
|
* 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:
|
2009-06-12 17:10:09 -07:00
|
|
|
*
|
2009-06-15 16:08:34 -07:00
|
|
|
* 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.
|
2009-06-12 17:10:09 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2014-10-29 11:34:40 -07:00
|
|
|
#undef NDEBUG
|
|
|
|
|
#include <assert.h>
|
2009-06-12 17:10:09 -07:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
2010-01-08 09:41:29 -08:00
|
|
|
#include "command-line.h"
|
2014-02-26 10:44:46 -08:00
|
|
|
#include "fatal-signal.h"
|
2016-04-04 21:32:10 -04:00
|
|
|
#include "openflow/openflow.h"
|
|
|
|
|
#include "openvswitch/ofp-msgs.h"
|
2016-04-04 21:32:09 -04:00
|
|
|
#include "openvswitch/ofp-util.h"
|
2016-03-25 14:10:24 -07:00
|
|
|
#include "openvswitch/ofpbuf.h"
|
2016-04-04 21:32:10 -04:00
|
|
|
#include "openvswitch/vconn.h"
|
|
|
|
|
#include "openvswitch/vlog.h"
|
2014-10-29 11:34:40 -07:00
|
|
|
#include "ovstest.h"
|
2009-06-12 17:10:09 -07:00
|
|
|
#include "poll-loop.h"
|
|
|
|
|
#include "socket-util.h"
|
2010-01-07 14:00:58 -08:00
|
|
|
#include "stream.h"
|
|
|
|
|
#include "stream-ssl.h"
|
2009-06-12 17:10:09 -07:00
|
|
|
#include "timeval.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
struct fake_pvconn {
|
|
|
|
|
const char *type;
|
|
|
|
|
char *pvconn_name;
|
|
|
|
|
char *vconn_name;
|
2010-01-07 14:00:58 -08:00
|
|
|
struct pstream *pstream;
|
2009-06-12 17:10:09 -07:00
|
|
|
};
|
|
|
|
|
|
2010-01-07 14:00:58 -08:00
|
|
|
static void
|
|
|
|
|
check(int a, int b, const char *as, const char *file, int line)
|
|
|
|
|
{
|
|
|
|
|
if (a != b) {
|
|
|
|
|
ovs_fatal(0, "%s:%d: %s is %d but should be %d", file, line, as, a, b);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define CHECK(A, B) check(A, B, #A, __FILE__, __LINE__)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
check_errno(int a, int b, const char *as, const char *file, int line)
|
|
|
|
|
{
|
|
|
|
|
if (a != b) {
|
2014-07-22 15:46:25 -07:00
|
|
|
char *str_b = xstrdup(ovs_strerror(abs(b)));
|
2010-01-07 14:00:58 -08:00
|
|
|
ovs_fatal(0, "%s:%d: %s is %d (%s) but should be %d (%s)",
|
2013-06-24 10:54:49 -07:00
|
|
|
file, line, as, a, ovs_strerror(abs(a)), b, str_b);
|
2010-01-07 14:00:58 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define CHECK_ERRNO(A, B) check_errno(A, B, #A, __FILE__, __LINE__)
|
|
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
static void
|
|
|
|
|
fpv_create(const char *type, struct fake_pvconn *fpv)
|
|
|
|
|
{
|
2010-01-08 10:01:27 -08:00
|
|
|
#ifdef HAVE_OPENSSL
|
2010-01-08 09:41:29 -08:00
|
|
|
if (!strcmp(type, "ssl")) {
|
|
|
|
|
stream_ssl_set_private_key_file("testpki-privkey.pem");
|
|
|
|
|
stream_ssl_set_certificate_file("testpki-cert.pem");
|
|
|
|
|
stream_ssl_set_ca_cert_file("testpki-cacert.pem", false);
|
|
|
|
|
}
|
2010-01-08 10:01:27 -08:00
|
|
|
#endif
|
2010-01-08 09:41:29 -08:00
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv->type = type;
|
|
|
|
|
if (!strcmp(type, "unix")) {
|
|
|
|
|
static int unix_count = 0;
|
|
|
|
|
char *bind_path;
|
|
|
|
|
|
|
|
|
|
bind_path = xasprintf("fake-pvconn.%d", unix_count++);
|
|
|
|
|
fpv->pvconn_name = xasprintf("punix:%s", bind_path);
|
|
|
|
|
fpv->vconn_name = xasprintf("unix:%s", bind_path);
|
2012-03-10 15:58:10 -08:00
|
|
|
CHECK_ERRNO(pstream_open(fpv->pvconn_name, &fpv->pstream,
|
|
|
|
|
DSCP_DEFAULT), 0);
|
2009-06-12 17:10:09 -07:00
|
|
|
free(bind_path);
|
2010-01-07 14:00:58 -08:00
|
|
|
} else if (!strcmp(type, "tcp") || !strcmp(type, "ssl")) {
|
2010-02-10 10:55:45 -08:00
|
|
|
char *s, *port, *save_ptr = NULL;
|
2010-01-07 14:00:58 -08:00
|
|
|
char *open_name;
|
2009-06-12 17:10:09 -07:00
|
|
|
|
2010-01-07 14:00:58 -08:00
|
|
|
open_name = xasprintf("p%s:0:127.0.0.1", type);
|
2012-03-10 15:58:10 -08:00
|
|
|
CHECK_ERRNO(pstream_open(open_name, &fpv->pstream, DSCP_DEFAULT), 0);
|
2009-06-12 17:10:09 -07:00
|
|
|
|
2010-01-07 14:00:58 -08:00
|
|
|
/* Extract bound port number from pstream name. */
|
|
|
|
|
s = xstrdup(pstream_get_name(fpv->pstream));
|
2010-02-10 10:55:45 -08:00
|
|
|
strtok_r(s, ":", &save_ptr);
|
2010-01-07 14:00:58 -08:00
|
|
|
port = strtok_r(NULL, ":", &save_ptr);
|
2009-06-12 17:10:09 -07:00
|
|
|
|
|
|
|
|
/* Save info. */
|
2010-01-07 14:00:58 -08:00
|
|
|
fpv->pvconn_name = xstrdup(pstream_get_name(fpv->pstream));
|
|
|
|
|
fpv->vconn_name = xasprintf("%s:127.0.0.1:%s", type, port);
|
|
|
|
|
|
|
|
|
|
free(open_name);
|
|
|
|
|
free(s);
|
2009-06-12 17:10:09 -07:00
|
|
|
} else {
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 14:00:58 -08:00
|
|
|
static struct stream *
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_accept(struct fake_pvconn *fpv)
|
|
|
|
|
{
|
2010-01-07 14:00:58 -08:00
|
|
|
struct stream *stream;
|
2009-06-12 17:10:09 -07:00
|
|
|
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(pstream_accept_block(fpv->pstream, &stream), 0);
|
|
|
|
|
|
|
|
|
|
return stream;
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fpv_close(struct fake_pvconn *fpv)
|
|
|
|
|
{
|
2010-01-07 14:00:58 -08:00
|
|
|
pstream_close(fpv->pstream);
|
|
|
|
|
fpv->pstream = NULL;
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fpv_destroy(struct fake_pvconn *fpv)
|
|
|
|
|
{
|
|
|
|
|
fpv_close(fpv);
|
|
|
|
|
free(fpv->pvconn_name);
|
|
|
|
|
free(fpv->vconn_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Connects to a fake_pvconn with vconn_open(), then closes the listener and
|
|
|
|
|
* verifies that vconn_connect() reports 'expected_error'. */
|
|
|
|
|
static void
|
2015-03-17 10:35:26 -04:00
|
|
|
test_refuse_connection(struct ovs_cmdl_context *ctx)
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
const char *type = ctx->argv[1];
|
2009-06-12 17:10:09 -07:00
|
|
|
struct fake_pvconn fpv;
|
|
|
|
|
struct vconn *vconn;
|
2012-07-31 10:12:21 -07:00
|
|
|
int error;
|
2010-01-08 09:41:29 -08:00
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_create(type, &fpv);
|
2013-01-02 17:10:43 -08:00
|
|
|
CHECK_ERRNO(vconn_open(fpv.vconn_name, 0, DSCP_DEFAULT, &vconn), 0);
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_close(&fpv);
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run(vconn);
|
2012-07-31 10:12:21 -07:00
|
|
|
|
|
|
|
|
error = vconn_connect_block(vconn);
|
|
|
|
|
if (!strcmp(type, "tcp")) {
|
2014-06-25 02:52:54 +00:00
|
|
|
if (error != ECONNRESET && error != EPIPE
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
&& error != WSAECONNRESET
|
|
|
|
|
#endif
|
|
|
|
|
) {
|
2012-07-31 10:12:21 -07:00
|
|
|
ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)",
|
2013-06-24 10:54:49 -07:00
|
|
|
error, ovs_strerror(error));
|
2012-07-31 10:12:21 -07:00
|
|
|
}
|
2012-10-23 13:50:10 +00:00
|
|
|
} else if (!strcmp(type, "unix")) {
|
2014-06-25 02:52:54 +00:00
|
|
|
#ifndef _WIN32
|
2012-10-23 13:50:10 +00:00
|
|
|
CHECK_ERRNO(error, EPIPE);
|
2014-06-25 02:52:54 +00:00
|
|
|
#else
|
|
|
|
|
CHECK_ERRNO(error, WSAECONNRESET);
|
|
|
|
|
#endif
|
2012-10-23 13:50:10 +00:00
|
|
|
} else if (!strcmp(type, "ssl")) {
|
|
|
|
|
if (error != EPROTO && error != ECONNRESET) {
|
|
|
|
|
ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)",
|
2013-06-24 10:54:49 -07:00
|
|
|
error, ovs_strerror(error));
|
2012-10-23 13:50:10 +00:00
|
|
|
}
|
2012-07-31 10:12:21 -07:00
|
|
|
} else {
|
2012-10-23 13:50:10 +00:00
|
|
|
ovs_fatal(0, "invalid connection type %s", type);
|
2012-07-31 10:12:21 -07:00
|
|
|
}
|
|
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
vconn_close(vconn);
|
|
|
|
|
fpv_destroy(&fpv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Connects to a fake_pvconn with vconn_open(), accepts that connection and
|
|
|
|
|
* closes it immediately, and verifies that vconn_connect() reports
|
|
|
|
|
* 'expected_error'. */
|
|
|
|
|
static void
|
2015-03-17 10:35:26 -04:00
|
|
|
test_accept_then_close(struct ovs_cmdl_context *ctx)
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
const char *type = ctx->argv[1];
|
2009-06-12 17:10:09 -07:00
|
|
|
struct fake_pvconn fpv;
|
|
|
|
|
struct vconn *vconn;
|
2012-08-07 11:45:44 -07:00
|
|
|
int error;
|
2010-01-08 09:41:29 -08:00
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_create(type, &fpv);
|
2013-01-02 17:10:43 -08:00
|
|
|
CHECK_ERRNO(vconn_open(fpv.vconn_name, 0, DSCP_DEFAULT, &vconn), 0);
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run(vconn);
|
2010-01-07 14:00:58 -08:00
|
|
|
stream_close(fpv_accept(&fpv));
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_close(&fpv);
|
2012-08-07 11:45:44 -07:00
|
|
|
|
|
|
|
|
error = vconn_connect_block(vconn);
|
|
|
|
|
if (!strcmp(type, "tcp") || !strcmp(type, "unix")) {
|
2014-06-25 02:52:54 +00:00
|
|
|
if (error != ECONNRESET && error != EPIPE
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
&& error != WSAECONNRESET
|
|
|
|
|
#endif
|
|
|
|
|
) {
|
2012-08-07 11:45:44 -07:00
|
|
|
ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)",
|
2013-06-24 10:54:49 -07:00
|
|
|
error, ovs_strerror(error));
|
2012-08-07 11:45:44 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
CHECK_ERRNO(error, EPROTO);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
vconn_close(vconn);
|
|
|
|
|
fpv_destroy(&fpv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Connects to a fake_pvconn with vconn_open(), accepts that connection and
|
|
|
|
|
* reads the hello message from it, then closes the connection and verifies
|
|
|
|
|
* that vconn_connect() reports 'expected_error'. */
|
|
|
|
|
static void
|
2015-03-17 10:35:26 -04:00
|
|
|
test_read_hello(struct ovs_cmdl_context *ctx)
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
const char *type = ctx->argv[1];
|
2009-06-12 17:10:09 -07:00
|
|
|
struct fake_pvconn fpv;
|
|
|
|
|
struct vconn *vconn;
|
2010-01-07 14:00:58 -08:00
|
|
|
struct stream *stream;
|
2012-07-31 10:12:21 -07:00
|
|
|
int error;
|
2009-06-12 17:10:09 -07:00
|
|
|
|
|
|
|
|
fpv_create(type, &fpv);
|
2013-01-02 17:10:43 -08:00
|
|
|
CHECK_ERRNO(vconn_open(fpv.vconn_name, 0, DSCP_DEFAULT, &vconn), 0);
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run(vconn);
|
2010-01-07 14:00:58 -08:00
|
|
|
stream = fpv_accept(&fpv);
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_destroy(&fpv);
|
|
|
|
|
for (;;) {
|
|
|
|
|
struct ofp_header hello;
|
|
|
|
|
int retval;
|
|
|
|
|
|
2010-01-07 14:00:58 -08:00
|
|
|
retval = stream_recv(stream, &hello, sizeof hello);
|
2009-06-12 17:10:09 -07:00
|
|
|
if (retval == sizeof hello) {
|
2012-07-19 23:23:17 -07:00
|
|
|
enum ofpraw raw;
|
|
|
|
|
|
Enable OpenFlow 1.0, 1.1, 1.2, and 1.3 by default.
The Open vSwitch software switch now supports all the required features of
OpenFlow 1.0 through 1.3, with one known trivial exception[*]. Enable them
by default in ovs-vswitchd.
For now, ovs-ofctl only enables OpenFlow 1.0 by default. This is
because ovs-ofctl implements command such as "add-flow" as raw
OpenFlow requests, but those requests have subtly different semantics
in different OpenFlow versions. For example:
- In OpenFlow 1.0, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow.
- In OpenFlow 1.1, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow, but only if the
mod-flow did not match on the flow cookie.
- In OpenFlow 1.2 and a later, a "mod-flow" operation never adds a
new flow.
[*] OpenFlow 1.1, but not any earlier or later version of OpenFlow,
requires support for VLANs introduced by Ethertype 0x88a8, but Open
vSwitch does not support this Ethertype.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
2014-04-30 06:54:09 -07:00
|
|
|
CHECK(hello.version, OFP13_VERSION);
|
2012-07-19 23:23:17 -07:00
|
|
|
CHECK(ofpraw_decode_partial(&raw, &hello, sizeof hello), 0);
|
|
|
|
|
CHECK(raw, OFPRAW_OFPT_HELLO);
|
2011-05-06 11:27:05 -07:00
|
|
|
CHECK(ntohs(hello.length), sizeof hello);
|
2009-06-12 17:10:09 -07:00
|
|
|
break;
|
|
|
|
|
} else {
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(retval, -EAGAIN);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run(vconn);
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(vconn_connect(vconn), EAGAIN);
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run_wait(vconn);
|
2009-06-12 17:10:09 -07:00
|
|
|
vconn_connect_wait(vconn);
|
2010-01-07 14:00:58 -08:00
|
|
|
stream_recv_wait(stream);
|
2009-06-12 17:10:09 -07:00
|
|
|
poll_block();
|
|
|
|
|
}
|
2010-01-07 14:00:58 -08:00
|
|
|
stream_close(stream);
|
2012-07-31 10:12:21 -07:00
|
|
|
error = vconn_connect_block(vconn);
|
|
|
|
|
if (error != ECONNRESET && error != EPIPE) {
|
|
|
|
|
ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)",
|
2013-06-24 10:54:49 -07:00
|
|
|
error, ovs_strerror(error));
|
2012-07-31 10:12:21 -07:00
|
|
|
}
|
2009-06-12 17:10:09 -07:00
|
|
|
vconn_close(vconn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Connects to a fake_pvconn with vconn_open(), accepts that connection and
|
|
|
|
|
* sends the 'out' bytes in 'out_size' to it (presumably an OFPT_HELLO
|
|
|
|
|
* message), then verifies that vconn_connect() reports
|
|
|
|
|
* 'expect_connect_error'. */
|
|
|
|
|
static void
|
|
|
|
|
test_send_hello(const char *type, const void *out, size_t out_size,
|
|
|
|
|
int expect_connect_error)
|
|
|
|
|
{
|
|
|
|
|
struct fake_pvconn fpv;
|
|
|
|
|
struct vconn *vconn;
|
|
|
|
|
bool read_hello, connected;
|
|
|
|
|
struct ofpbuf *msg;
|
2010-01-07 14:00:58 -08:00
|
|
|
struct stream *stream;
|
|
|
|
|
size_t n_sent;
|
2009-06-12 17:10:09 -07:00
|
|
|
|
|
|
|
|
fpv_create(type, &fpv);
|
2013-01-02 17:10:43 -08:00
|
|
|
CHECK_ERRNO(vconn_open(fpv.vconn_name, 0, DSCP_DEFAULT, &vconn), 0);
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run(vconn);
|
2010-01-07 14:00:58 -08:00
|
|
|
stream = fpv_accept(&fpv);
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_destroy(&fpv);
|
|
|
|
|
|
2010-01-07 14:00:58 -08:00
|
|
|
n_sent = 0;
|
|
|
|
|
while (n_sent < out_size) {
|
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
|
|
retval = stream_send(stream, (char *) out + n_sent, out_size - n_sent);
|
|
|
|
|
if (retval > 0) {
|
|
|
|
|
n_sent += retval;
|
|
|
|
|
} else if (retval == -EAGAIN) {
|
|
|
|
|
stream_run(stream);
|
|
|
|
|
vconn_run(vconn);
|
|
|
|
|
stream_recv_wait(stream);
|
|
|
|
|
vconn_connect_wait(vconn);
|
|
|
|
|
vconn_run_wait(vconn);
|
|
|
|
|
poll_block();
|
|
|
|
|
} else {
|
|
|
|
|
ovs_fatal(0, "stream_send returned unexpected value %d", retval);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-06-12 17:10:09 -07:00
|
|
|
|
|
|
|
|
read_hello = connected = false;
|
|
|
|
|
for (;;) {
|
|
|
|
|
if (!read_hello) {
|
|
|
|
|
struct ofp_header hello;
|
2010-01-07 14:00:58 -08:00
|
|
|
int retval = stream_recv(stream, &hello, sizeof hello);
|
2009-06-12 17:10:09 -07:00
|
|
|
if (retval == sizeof hello) {
|
2012-07-19 23:23:17 -07:00
|
|
|
enum ofpraw raw;
|
|
|
|
|
|
Enable OpenFlow 1.0, 1.1, 1.2, and 1.3 by default.
The Open vSwitch software switch now supports all the required features of
OpenFlow 1.0 through 1.3, with one known trivial exception[*]. Enable them
by default in ovs-vswitchd.
For now, ovs-ofctl only enables OpenFlow 1.0 by default. This is
because ovs-ofctl implements command such as "add-flow" as raw
OpenFlow requests, but those requests have subtly different semantics
in different OpenFlow versions. For example:
- In OpenFlow 1.0, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow.
- In OpenFlow 1.1, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow, but only if the
mod-flow did not match on the flow cookie.
- In OpenFlow 1.2 and a later, a "mod-flow" operation never adds a
new flow.
[*] OpenFlow 1.1, but not any earlier or later version of OpenFlow,
requires support for VLANs introduced by Ethertype 0x88a8, but Open
vSwitch does not support this Ethertype.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
2014-04-30 06:54:09 -07:00
|
|
|
CHECK(hello.version, OFP13_VERSION);
|
2012-07-19 23:23:17 -07:00
|
|
|
CHECK(ofpraw_decode_partial(&raw, &hello, sizeof hello), 0);
|
|
|
|
|
CHECK(raw, OFPRAW_OFPT_HELLO);
|
2011-05-06 11:27:05 -07:00
|
|
|
CHECK(ntohs(hello.length), sizeof hello);
|
2009-06-12 17:10:09 -07:00
|
|
|
read_hello = true;
|
|
|
|
|
} else {
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(retval, -EAGAIN);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run(vconn);
|
2009-06-12 17:10:09 -07:00
|
|
|
if (!connected) {
|
|
|
|
|
int error = vconn_connect(vconn);
|
|
|
|
|
if (error == expect_connect_error) {
|
|
|
|
|
if (!error) {
|
|
|
|
|
connected = true;
|
|
|
|
|
} else {
|
2010-01-07 14:00:58 -08:00
|
|
|
stream_close(stream);
|
2009-06-12 17:10:09 -07:00
|
|
|
vconn_close(vconn);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(error, EAGAIN);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (read_hello && connected) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run_wait(vconn);
|
2009-06-12 17:10:09 -07:00
|
|
|
if (!connected) {
|
|
|
|
|
vconn_connect_wait(vconn);
|
|
|
|
|
}
|
|
|
|
|
if (!read_hello) {
|
2010-01-07 14:00:58 -08:00
|
|
|
stream_recv_wait(stream);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
poll_block();
|
|
|
|
|
}
|
2010-01-07 14:00:58 -08:00
|
|
|
stream_close(stream);
|
2012-07-31 10:12:20 -07:00
|
|
|
CHECK_ERRNO(vconn_recv_block(vconn, &msg), EOF);
|
2009-06-12 17:10:09 -07:00
|
|
|
vconn_close(vconn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try connecting and sending a normal hello, which should succeed. */
|
|
|
|
|
static void
|
2015-03-17 10:35:26 -04:00
|
|
|
test_send_plain_hello(struct ovs_cmdl_context *ctx)
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
const char *type = ctx->argv[1];
|
2012-07-19 23:23:17 -07:00
|
|
|
struct ofpbuf *hello;
|
2009-06-12 17:10:09 -07:00
|
|
|
|
Enable OpenFlow 1.0, 1.1, 1.2, and 1.3 by default.
The Open vSwitch software switch now supports all the required features of
OpenFlow 1.0 through 1.3, with one known trivial exception[*]. Enable them
by default in ovs-vswitchd.
For now, ovs-ofctl only enables OpenFlow 1.0 by default. This is
because ovs-ofctl implements command such as "add-flow" as raw
OpenFlow requests, but those requests have subtly different semantics
in different OpenFlow versions. For example:
- In OpenFlow 1.0, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow.
- In OpenFlow 1.1, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow, but only if the
mod-flow did not match on the flow cookie.
- In OpenFlow 1.2 and a later, a "mod-flow" operation never adds a
new flow.
[*] OpenFlow 1.1, but not any earlier or later version of OpenFlow,
requires support for VLANs introduced by Ethertype 0x88a8, but Open
vSwitch does not support this Ethertype.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
2014-04-30 06:54:09 -07:00
|
|
|
hello = ofpraw_alloc_xid(OFPRAW_OFPT_HELLO, OFP13_VERSION,
|
2012-07-19 23:23:17 -07:00
|
|
|
htonl(0x12345678), 0);
|
2015-03-02 17:29:44 -08:00
|
|
|
test_send_hello(type, hello->data, hello->size, 0);
|
2012-07-19 23:23:17 -07:00
|
|
|
ofpbuf_delete(hello);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try connecting and sending an extra-long hello, which should succeed (since
|
|
|
|
|
* the specification says that implementations must accept and ignore extra
|
|
|
|
|
* data). */
|
|
|
|
|
static void
|
2015-03-17 10:35:26 -04:00
|
|
|
test_send_long_hello(struct ovs_cmdl_context *ctx)
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
const char *type = ctx->argv[1];
|
2012-07-19 23:23:17 -07:00
|
|
|
struct ofpbuf *hello;
|
|
|
|
|
enum { EXTRA_BYTES = 8 };
|
|
|
|
|
|
Enable OpenFlow 1.0, 1.1, 1.2, and 1.3 by default.
The Open vSwitch software switch now supports all the required features of
OpenFlow 1.0 through 1.3, with one known trivial exception[*]. Enable them
by default in ovs-vswitchd.
For now, ovs-ofctl only enables OpenFlow 1.0 by default. This is
because ovs-ofctl implements command such as "add-flow" as raw
OpenFlow requests, but those requests have subtly different semantics
in different OpenFlow versions. For example:
- In OpenFlow 1.0, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow.
- In OpenFlow 1.1, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow, but only if the
mod-flow did not match on the flow cookie.
- In OpenFlow 1.2 and a later, a "mod-flow" operation never adds a
new flow.
[*] OpenFlow 1.1, but not any earlier or later version of OpenFlow,
requires support for VLANs introduced by Ethertype 0x88a8, but Open
vSwitch does not support this Ethertype.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
2014-04-30 06:54:09 -07:00
|
|
|
hello = ofpraw_alloc_xid(OFPRAW_OFPT_HELLO, OFP13_VERSION,
|
2012-07-19 23:23:17 -07:00
|
|
|
htonl(0x12345678), EXTRA_BYTES);
|
|
|
|
|
ofpbuf_put_zeros(hello, EXTRA_BYTES);
|
|
|
|
|
ofpmsg_update_length(hello);
|
2015-03-02 17:29:44 -08:00
|
|
|
test_send_hello(type, hello->data, hello->size, 0);
|
2012-07-19 23:23:17 -07:00
|
|
|
ofpbuf_delete(hello);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try connecting and sending an echo request instead of a hello, which should
|
|
|
|
|
* fail with EPROTO. */
|
|
|
|
|
static void
|
2015-03-17 10:35:26 -04:00
|
|
|
test_send_echo_hello(struct ovs_cmdl_context *ctx)
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
const char *type = ctx->argv[1];
|
2012-07-19 23:23:17 -07:00
|
|
|
struct ofpbuf *echo;
|
2009-06-12 17:10:09 -07:00
|
|
|
|
Enable OpenFlow 1.0, 1.1, 1.2, and 1.3 by default.
The Open vSwitch software switch now supports all the required features of
OpenFlow 1.0 through 1.3, with one known trivial exception[*]. Enable them
by default in ovs-vswitchd.
For now, ovs-ofctl only enables OpenFlow 1.0 by default. This is
because ovs-ofctl implements command such as "add-flow" as raw
OpenFlow requests, but those requests have subtly different semantics
in different OpenFlow versions. For example:
- In OpenFlow 1.0, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow.
- In OpenFlow 1.1, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow, but only if the
mod-flow did not match on the flow cookie.
- In OpenFlow 1.2 and a later, a "mod-flow" operation never adds a
new flow.
[*] OpenFlow 1.1, but not any earlier or later version of OpenFlow,
requires support for VLANs introduced by Ethertype 0x88a8, but Open
vSwitch does not support this Ethertype.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
2014-04-30 06:54:09 -07:00
|
|
|
echo = ofpraw_alloc_xid(OFPRAW_OFPT_ECHO_REQUEST, OFP13_VERSION,
|
2012-07-19 23:23:17 -07:00
|
|
|
htonl(0x12345678), 0);
|
2015-03-02 17:29:44 -08:00
|
|
|
test_send_hello(type, echo->data, echo->size, EPROTO);
|
2012-07-19 23:23:17 -07:00
|
|
|
ofpbuf_delete(echo);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try connecting and sending a hello packet that has its length field as 0,
|
|
|
|
|
* which should fail with EPROTO. */
|
|
|
|
|
static void
|
2015-03-17 10:35:26 -04:00
|
|
|
test_send_short_hello(struct ovs_cmdl_context *ctx)
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
const char *type = ctx->argv[1];
|
2009-06-12 17:10:09 -07:00
|
|
|
struct ofp_header hello;
|
|
|
|
|
|
|
|
|
|
memset(&hello, 0, sizeof hello);
|
|
|
|
|
test_send_hello(type, &hello, sizeof hello, EPROTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try connecting and sending a hello packet that has a bad version, which
|
|
|
|
|
* should fail with EPROTO. */
|
|
|
|
|
static void
|
2015-03-17 10:35:26 -04:00
|
|
|
test_send_invalid_version_hello(struct ovs_cmdl_context *ctx)
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
const char *type = ctx->argv[1];
|
2012-07-19 23:23:17 -07:00
|
|
|
struct ofpbuf *hello;
|
2009-06-12 17:10:09 -07:00
|
|
|
|
Enable OpenFlow 1.0, 1.1, 1.2, and 1.3 by default.
The Open vSwitch software switch now supports all the required features of
OpenFlow 1.0 through 1.3, with one known trivial exception[*]. Enable them
by default in ovs-vswitchd.
For now, ovs-ofctl only enables OpenFlow 1.0 by default. This is
because ovs-ofctl implements command such as "add-flow" as raw
OpenFlow requests, but those requests have subtly different semantics
in different OpenFlow versions. For example:
- In OpenFlow 1.0, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow.
- In OpenFlow 1.1, a "mod-flow" operation that does not find any
existing flow to modify adds a new flow, but only if the
mod-flow did not match on the flow cookie.
- In OpenFlow 1.2 and a later, a "mod-flow" operation never adds a
new flow.
[*] OpenFlow 1.1, but not any earlier or later version of OpenFlow,
requires support for VLANs introduced by Ethertype 0x88a8, but Open
vSwitch does not support this Ethertype.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
2014-04-30 06:54:09 -07:00
|
|
|
hello = ofpraw_alloc_xid(OFPRAW_OFPT_HELLO, OFP13_VERSION,
|
2012-07-19 23:23:17 -07:00
|
|
|
htonl(0x12345678), 0);
|
2015-03-02 17:29:44 -08:00
|
|
|
((struct ofp_header *) hello->data)->version = 0;
|
|
|
|
|
test_send_hello(type, hello->data, hello->size, EPROTO);
|
2012-07-19 23:23:17 -07:00
|
|
|
ofpbuf_delete(hello);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 12:01:55 -04:00
|
|
|
static const struct ovs_cmdl_command commands[] = {
|
2014-10-16 13:27:32 -07:00
|
|
|
{"refuse-connection", NULL, 1, 1, test_refuse_connection},
|
|
|
|
|
{"accept-then-close", NULL, 1, 1, test_accept_then_close},
|
|
|
|
|
{"read-hello", NULL, 1, 1, test_read_hello},
|
|
|
|
|
{"send-plain-hello", NULL, 1, 1, test_send_plain_hello},
|
|
|
|
|
{"send-long-hello", NULL, 1, 1, test_send_long_hello},
|
|
|
|
|
{"send-echo-hello", NULL, 1, 1, test_send_echo_hello},
|
|
|
|
|
{"send-short-hello", NULL, 1, 1, test_send_short_hello},
|
|
|
|
|
{"send-invalid-version-hello", NULL, 1, 1, test_send_invalid_version_hello},
|
|
|
|
|
{NULL, NULL, 0, 0, NULL},
|
2010-01-08 09:41:29 -08:00
|
|
|
};
|
|
|
|
|
|
2014-04-01 00:47:01 -07:00
|
|
|
static void
|
|
|
|
|
test_vconn_main(int argc, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2015-03-17 10:35:26 -04:00
|
|
|
struct ovs_cmdl_context ctx = {
|
|
|
|
|
.argc = argc - 1,
|
|
|
|
|
.argv = argv + 1,
|
|
|
|
|
};
|
|
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
set_program_name(argv[0]);
|
2015-01-06 13:05:00 -08:00
|
|
|
vlog_set_levels(NULL, VLF_ANY_DESTINATION, VLL_EMER);
|
2010-07-16 10:53:14 -07:00
|
|
|
vlog_set_levels(NULL, VLF_CONSOLE, VLL_DBG);
|
2014-02-26 10:44:46 -08:00
|
|
|
fatal_ignore_sigpipe();
|
2009-06-12 17:10:09 -07:00
|
|
|
|
|
|
|
|
time_alarm(10);
|
|
|
|
|
|
2015-03-17 10:35:26 -04:00
|
|
|
ovs_cmdl_run_command(&ctx, commands);
|
2009-06-12 17:10:09 -07:00
|
|
|
}
|
2014-04-01 00:47:01 -07:00
|
|
|
|
|
|
|
|
OVSTEST_REGISTER("test-vconn", test_vconn_main);
|