2009-06-12 17:10:09 -07:00
|
|
|
/*
|
2010-01-07 14:00:58 -08:00
|
|
|
* Copyright (c) 2009, 2010 Nicira Networks.
|
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>
|
|
|
|
|
#include "vconn.h"
|
|
|
|
|
#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"
|
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"
|
|
|
|
|
#include "vlog.h"
|
|
|
|
|
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#include <assert.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) {
|
|
|
|
|
ovs_fatal(0, "%s:%d: %s is %d (%s) but should be %d (%s)",
|
|
|
|
|
file, line, as, a, strerror(abs(a)), b, strerror(abs(b)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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);
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(pstream_open(fpv->pvconn_name, &fpv->pstream), 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);
|
|
|
|
|
CHECK_ERRNO(pstream_open(open_name, &fpv->pstream), 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
|
2010-02-11 11:11:23 -08:00
|
|
|
test_refuse_connection(int argc OVS_UNUSED, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2010-01-08 09:41:29 -08:00
|
|
|
const char *type = argv[1];
|
|
|
|
|
int expected_error;
|
2009-06-12 17:10:09 -07:00
|
|
|
struct fake_pvconn fpv;
|
|
|
|
|
struct vconn *vconn;
|
|
|
|
|
|
2010-06-11 15:58:14 -07:00
|
|
|
expected_error = (!strcmp(type, "unix") ? EPIPE
|
|
|
|
|
: !strcmp(type, "tcp") ? ECONNRESET
|
|
|
|
|
: EPROTO);
|
2010-01-08 09:41:29 -08:00
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_create(type, &fpv);
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP_VERSION, &vconn), 0);
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_close(&fpv);
|
2010-01-06 14:27:46 -08:00
|
|
|
vconn_run(vconn);
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(vconn_connect(vconn), expected_error);
|
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
|
2010-02-11 11:11:23 -08:00
|
|
|
test_accept_then_close(int argc OVS_UNUSED, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2010-01-08 09:41:29 -08:00
|
|
|
const char *type = argv[1];
|
|
|
|
|
int expected_error;
|
2009-06-12 17:10:09 -07:00
|
|
|
struct fake_pvconn fpv;
|
|
|
|
|
struct vconn *vconn;
|
|
|
|
|
|
2010-01-08 09:41:29 -08:00
|
|
|
expected_error = (!strcmp(type, "unix") ? EPIPE
|
|
|
|
|
: !strcmp(type, "tcp") ? ECONNRESET
|
|
|
|
|
: EPROTO);
|
|
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
fpv_create(type, &fpv);
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP_VERSION, &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);
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(vconn_connect(vconn), expected_error);
|
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
|
2010-02-11 11:11:23 -08:00
|
|
|
test_read_hello(int argc OVS_UNUSED, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2010-01-08 09:41:29 -08:00
|
|
|
const char *type = 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;
|
2009-06-12 17:10:09 -07:00
|
|
|
|
|
|
|
|
fpv_create(type, &fpv);
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP_VERSION, &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) {
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK(hello.version, OFP_VERSION);
|
|
|
|
|
CHECK(hello.type, OFPT_HELLO);
|
|
|
|
|
CHECK(hello.length, htons(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);
|
2010-01-08 09:41:29 -08:00
|
|
|
CHECK_ERRNO(vconn_connect(vconn), ECONNRESET);
|
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);
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP_VERSION, &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) {
|
2010-01-07 14:00:58 -08:00
|
|
|
CHECK(hello.version, OFP_VERSION);
|
|
|
|
|
CHECK(hello.type, OFPT_HELLO);
|
|
|
|
|
CHECK(hello.length, htons(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);
|
|
|
|
|
CHECK_ERRNO(vconn_recv(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
|
2010-02-11 11:11:23 -08:00
|
|
|
test_send_plain_hello(int argc OVS_UNUSED, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2010-01-08 09:41:29 -08:00
|
|
|
const char *type = argv[1];
|
2009-06-12 17:10:09 -07:00
|
|
|
struct ofp_header hello;
|
|
|
|
|
|
|
|
|
|
hello.version = OFP_VERSION;
|
|
|
|
|
hello.type = OFPT_HELLO;
|
|
|
|
|
hello.length = htons(sizeof hello);
|
|
|
|
|
hello.xid = htonl(0x12345678);
|
|
|
|
|
test_send_hello(type, &hello, sizeof hello, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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
|
2010-02-11 11:11:23 -08:00
|
|
|
test_send_long_hello(int argc OVS_UNUSED, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2010-01-08 09:41:29 -08:00
|
|
|
const char *type = argv[1];
|
2009-06-12 17:10:09 -07:00
|
|
|
struct ofp_header hello;
|
|
|
|
|
char buffer[sizeof hello * 2];
|
|
|
|
|
|
|
|
|
|
hello.version = OFP_VERSION;
|
|
|
|
|
hello.type = OFPT_HELLO;
|
|
|
|
|
hello.length = htons(sizeof buffer);
|
|
|
|
|
hello.xid = htonl(0x12345678);
|
|
|
|
|
memset(buffer, 0, sizeof buffer);
|
|
|
|
|
memcpy(buffer, &hello, sizeof hello);
|
|
|
|
|
test_send_hello(type, buffer, sizeof buffer, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try connecting and sending an echo request instead of a hello, which should
|
|
|
|
|
* fail with EPROTO. */
|
|
|
|
|
static void
|
2010-02-11 11:11:23 -08:00
|
|
|
test_send_echo_hello(int argc OVS_UNUSED, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2010-01-08 09:41:29 -08:00
|
|
|
const char *type = argv[1];
|
2009-06-12 17:10:09 -07:00
|
|
|
struct ofp_header echo;
|
|
|
|
|
|
|
|
|
|
echo.version = OFP_VERSION;
|
|
|
|
|
echo.type = OFPT_ECHO_REQUEST;
|
|
|
|
|
echo.length = htons(sizeof echo);
|
|
|
|
|
echo.xid = htonl(0x89abcdef);
|
|
|
|
|
test_send_hello(type, &echo, sizeof echo, EPROTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try connecting and sending a hello packet that has its length field as 0,
|
|
|
|
|
* which should fail with EPROTO. */
|
|
|
|
|
static void
|
2010-02-11 11:11:23 -08:00
|
|
|
test_send_short_hello(int argc OVS_UNUSED, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2010-01-08 09:41:29 -08:00
|
|
|
const char *type = 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
|
2010-02-11 11:11:23 -08:00
|
|
|
test_send_invalid_version_hello(int argc OVS_UNUSED, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
2010-01-08 09:41:29 -08:00
|
|
|
const char *type = argv[1];
|
2009-06-12 17:10:09 -07:00
|
|
|
struct ofp_header hello;
|
|
|
|
|
|
|
|
|
|
hello.version = OFP_VERSION - 1;
|
|
|
|
|
hello.type = OFPT_HELLO;
|
|
|
|
|
hello.length = htons(sizeof hello);
|
|
|
|
|
hello.xid = htonl(0x12345678);
|
|
|
|
|
test_send_hello(type, &hello, sizeof hello, EPROTO);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-08 09:41:29 -08:00
|
|
|
static const struct command commands[] = {
|
|
|
|
|
{"refuse-connection", 1, 1, test_refuse_connection},
|
|
|
|
|
{"accept-then-close", 1, 1, test_accept_then_close},
|
|
|
|
|
{"read-hello", 1, 1, test_read_hello},
|
|
|
|
|
{"send-plain-hello", 1, 1, test_send_plain_hello},
|
|
|
|
|
{"send-long-hello", 1, 1, test_send_long_hello},
|
|
|
|
|
{"send-echo-hello", 1, 1, test_send_echo_hello},
|
|
|
|
|
{"send-short-hello", 1, 1, test_send_short_hello},
|
|
|
|
|
{"send-invalid-version-hello", 1, 1, test_send_invalid_version_hello},
|
|
|
|
|
{NULL, 0, 0, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
int
|
2010-05-26 12:52:06 -07:00
|
|
|
main(int argc, char *argv[])
|
2009-06-12 17:10:09 -07:00
|
|
|
{
|
|
|
|
|
set_program_name(argv[0]);
|
2010-07-16 10:53:14 -07:00
|
|
|
vlog_set_levels(NULL, VLF_ANY_FACILITY, VLL_EMER);
|
|
|
|
|
vlog_set_levels(NULL, VLF_CONSOLE, VLL_DBG);
|
2009-06-12 17:10:09 -07:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
|
|
|
|
|
time_alarm(10);
|
|
|
|
|
|
2010-01-08 09:41:29 -08:00
|
|
|
run_command(argc - 1, argv + 1, commands);
|
2010-01-07 14:00:58 -08:00
|
|
|
|
2009-06-12 17:10:09 -07:00
|
|
|
return 0;
|
|
|
|
|
}
|