Skip to content

Commit

Permalink
Allow configuring DSCP on controller and manager connections.
Browse files Browse the repository at this point in the history
The changes allow the user to specify a separate dscp value for the
controller connection and the manager connection. The value will take
effect on resetting the connections. If no value is specified a default
value of 192 is chosen for each of the connections.

Feature #10074
Requested-by: Rajiv Ramanathan <[email protected]>
Signed-off-by: Mehak Mahajan <[email protected]>
  • Loading branch information
Mehak Mahajan committed Mar 24, 2012
1 parent 11460e2 commit f125905
Show file tree
Hide file tree
Showing 37 changed files with 361 additions and 97 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ post-v1.6.0
- kernel modules are renamed. openvswitch_mod.ko is now
openvswitch.ko and brcompat_mod.ko is now brcompat.ko.
- Increased the number of NXM registers to 8.
- Added ability to configure dscp setting for manager and controller
connections. By default, these connections have a DSCP value of
Internetwork Control (0xc0).


v1.6.0 - xx xxx xxxx
Expand Down
21 changes: 21 additions & 0 deletions include/sparse/netinet/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ extern const struct in6_addr in6addr_any;
#define IPPROTO_NONE 59
#define IPPROTO_DSTOPTS 60

/* All the IP options documented in Linux ip(7). */
#define IP_ADD_MEMBERSHIP 0
#define IP_DROP_MEMBERSHIP 1
#define IP_HDRINCL 2
#define IP_MTU 3
#define IP_MTU_DISCOVER 4
#define IP_MULTICAST_IF 5
#define IP_MULTICAST_LOOP 6
#define IP_MULTICAST_TTL 7
#define IP_NODEFRAG 8
#define IP_OPTIONS 9
#define IP_PKTINFO 10
#define IP_RECVERR 11
#define IP_RECVOPTS 12
#define IP_RECVTOS 13
#define IP_RECVTTL 14
#define IP_RETOPTS 15
#define IP_ROUTER_ALERT 16
#define IP_TOS 17
#define IP_TTL 18

#define INADDR_ANY 0x00000000
#define INADDR_BROADCAST 0xffffffff
#define INADDR_NONE 0xffffffff
Expand Down
22 changes: 16 additions & 6 deletions lib/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ static void jsonrpc_error(struct jsonrpc *, int error);
/* This is just the same as stream_open() except that it uses the default
* JSONRPC ports if none is specified. */
int
jsonrpc_stream_open(const char *name, struct stream **streamp)
jsonrpc_stream_open(const char *name, struct stream **streamp, uint8_t dscp)
{
return stream_open_with_default_ports(name, JSONRPC_TCP_PORT,
JSONRPC_SSL_PORT, streamp);
JSONRPC_SSL_PORT, streamp,
dscp);
}

/* This is just the same as pstream_open() except that it uses the default
* JSONRPC ports if none is specified. */
int
jsonrpc_pstream_open(const char *name, struct pstream **pstreamp)
jsonrpc_pstream_open(const char *name, struct pstream **pstreamp, uint8_t dscp)
{
return pstream_open_with_default_ports(name, JSONRPC_TCP_PORT,
JSONRPC_SSL_PORT, pstreamp);
JSONRPC_SSL_PORT, pstreamp, dscp);
}

/* Returns a new JSON-RPC stream that uses 'stream' for input and output. The
Expand Down Expand Up @@ -825,12 +826,14 @@ jsonrpc_session_connect(struct jsonrpc_session *s)

jsonrpc_session_disconnect(s);
if (!reconnect_is_passive(s->reconnect)) {
error = jsonrpc_stream_open(name, &s->stream);
error = jsonrpc_stream_open(name, &s->stream,
reconnect_get_dscp(s->reconnect));
if (!error) {
reconnect_connecting(s->reconnect, time_msec());
}
} else {
error = s->pstream ? 0 : jsonrpc_pstream_open(name, &s->pstream);
error = s->pstream ? 0 : jsonrpc_pstream_open(name, &s->pstream,
reconnect_get_dscp(s->reconnect));
if (!error) {
reconnect_listening(s->reconnect, time_msec());
}
Expand Down Expand Up @@ -1041,3 +1044,10 @@ jsonrpc_session_set_probe_interval(struct jsonrpc_session *s,
{
reconnect_set_probe_interval(s->reconnect, probe_interval);
}

void
jsonrpc_session_set_dscp(struct jsonrpc_session *s,
uint8_t dscp)
{
reconnect_set_dscp(s->reconnect, dscp);
}
7 changes: 5 additions & 2 deletions lib/jsonrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <stdbool.h>
#include <stddef.h>
#include "openvswitch/types.h"

struct json;
struct jsonrpc_msg;
Expand All @@ -38,8 +39,8 @@ struct stream;
#define JSONRPC_TCP_PORT 6632
#define JSONRPC_SSL_PORT 6632

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

struct jsonrpc *jsonrpc_open(struct stream *);
void jsonrpc_close(struct jsonrpc *);
Expand Down Expand Up @@ -123,5 +124,7 @@ void jsonrpc_session_set_max_backoff(struct jsonrpc_session *,
int max_backofF);
void jsonrpc_session_set_probe_interval(struct jsonrpc_session *,
int probe_interval);
void jsonrpc_session_set_dscp(struct jsonrpc_session *,
uint8_t dscp);

#endif /* jsonrpc.h */
1 change: 0 additions & 1 deletion lib/netdev-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <linux/gen_stats.h>
#include <linux/if_ether.h>
#include <linux/if_tun.h>
#include <linux/ip.h>
#include <linux/types.h>
#include <linux/ethtool.h>
#include <linux/mii.h>
Expand Down
12 changes: 10 additions & 2 deletions lib/rconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct rconn {
* attempt to the next. */
ovs_be32 local_ip, remote_ip;
ovs_be16 remote_port;
uint8_t dscp;

/* Messages sent or received are copied to the monitor connections. */
#define MAX_MONITORS 8
Expand Down Expand Up @@ -160,7 +161,7 @@ static bool rconn_logging_connection_attempts__(const struct rconn *);
* The new rconn is initially unconnected. Use rconn_connect() or
* rconn_connect_unreliably() to connect it. */
struct rconn *
rconn_create(int probe_interval, int max_backoff)
rconn_create(int probe_interval, int max_backoff, uint8_t dscp)
{
struct rconn *rc = xzalloc(sizeof *rc);

Expand Down Expand Up @@ -194,6 +195,7 @@ rconn_create(int probe_interval, int max_backoff)
rc->total_time_connected = 0;

rconn_set_probe_interval(rc, probe_interval);
rconn_set_dscp(rc, dscp);

rc->n_monitors = 0;

Expand All @@ -218,6 +220,12 @@ rconn_get_max_backoff(const struct rconn *rc)
return rc->max_backoff;
}

void
rconn_set_dscp(struct rconn *rc, uint8_t dscp)
{
rc->dscp = dscp;
}

void
rconn_set_probe_interval(struct rconn *rc, int probe_interval)
{
Expand Down Expand Up @@ -335,7 +343,7 @@ reconnect(struct rconn *rc)
VLOG_INFO("%s: connecting...", rc->name);
}
rc->n_attempted_connections++;
retval = vconn_open(rc->target, OFP10_VERSION, &rc->vconn);
retval = vconn_open(rc->target, OFP10_VERSION, &rc->vconn, rc->dscp);
if (!retval) {
rc->remote_ip = vconn_get_remote_ip(rc->vconn);
rc->local_ip = vconn_get_local_ip(rc->vconn);
Expand Down
5 changes: 3 additions & 2 deletions lib/rconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
struct vconn;
struct rconn_packet_counter;

struct rconn *rconn_create(int inactivity_probe_interval, int max_backoff);

struct rconn *rconn_create(int inactivity_probe_interval,
int max_backoff, uint8_t dscp);
void rconn_set_dscp(struct rconn *rc, uint8_t dscp);
void rconn_set_max_backoff(struct rconn *, int max_backoff);
int rconn_get_max_backoff(const struct rconn *);
void rconn_set_probe_interval(struct rconn *, int inactivity_probe_interval);
Expand Down
18 changes: 18 additions & 0 deletions lib/reconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct reconnect {
bool passive;
enum vlog_level info; /* Used for informational messages. */

uint8_t dscp;

/* State. */
enum state state;
long long int state_entered;
Expand Down Expand Up @@ -186,6 +188,14 @@ reconnect_get_probe_interval(const struct reconnect *fsm)
return fsm->probe_interval;
}

/* Returns the dscp value used for establishing the connection between the
* manager and the database. */
uint8_t
reconnect_get_dscp(const struct reconnect *fsm)
{
return fsm->dscp;
}

/* Limits the maximum number of times that 'fsm' will ask the client to try to
* reconnect to 'max_tries'. UINT_MAX (the default) means an unlimited number
* of tries.
Expand Down Expand Up @@ -245,6 +255,14 @@ reconnect_set_probe_interval(struct reconnect *fsm, int probe_interval)
fsm->probe_interval = probe_interval ? MAX(1000, probe_interval) : 0;
}

/* Sets the dscp value to be used for establishing a connection between the
* manager and the database. */
void
reconnect_set_dscp(struct reconnect *fsm, uint8_t dscp)
{
fsm->dscp = dscp;
}

/* Returns true if 'fsm' is in passive mode, false if 'fsm' is in active mode
* (the default). */
bool
Expand Down
3 changes: 3 additions & 0 deletions lib/reconnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* revisited later.) */

#include <stdbool.h>
#include "openvswitch/types.h"

struct reconnect *reconnect_create(long long int now);
void reconnect_destroy(struct reconnect *);
Expand All @@ -48,13 +49,15 @@ void reconnect_set_name(struct reconnect *, const char *name);
int reconnect_get_min_backoff(const struct reconnect *);
int reconnect_get_max_backoff(const struct reconnect *);
int reconnect_get_probe_interval(const struct reconnect *);
uint8_t reconnect_get_dscp(const struct reconnect *);

void reconnect_set_max_tries(struct reconnect *, unsigned int max_tries);
unsigned int reconnect_get_max_tries(struct reconnect *);

void reconnect_set_backoff(struct reconnect *,
int min_backoff, int max_backoff);
void reconnect_set_probe_interval(struct reconnect *, int probe_interval);
void reconnect_set_dscp(struct reconnect *, uint8_t dscp);

bool reconnect_is_passive(const struct reconnect *);
void reconnect_set_passive(struct reconnect *, bool passive,
Expand Down
36 changes: 32 additions & 4 deletions lib/socket-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,13 @@ inet_parse_active(const char *target_, uint16_t default_port,
* and stores -1 into '*fdp'.
*
* If 'sinp' is non-null, then on success the target address is stored into
* '*sinp'. */
* '*sinp'.
*
* 'dscp' If not DSCP_INVALID, its value becomes the DSCP bits in the IP
* headers for the new connection. */
int
inet_open_active(int style, const char *target, uint16_t default_port,
struct sockaddr_in *sinp, int *fdp)
struct sockaddr_in *sinp, int *fdp, uint8_t dscp)
{
struct sockaddr_in sin;
int fd = -1;
Expand All @@ -571,6 +574,17 @@ inet_open_active(int style, const char *target, uint16_t default_port,
goto exit_close;
}

/* The socket options set here ensure that the TOS bits are set during
* the connection establishment. If set after connect(), the handshake
* SYN frames will be sent with a TOS of 0. */
if (dscp != DSCP_INVALID) {
if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
VLOG_ERR("%s: socket: %s", target, strerror(errno));
error = errno;
goto exit;
}
}

/* Connect. */
error = connect(fd, (struct sockaddr *) &sin, sizeof sin) == 0 ? 0 : errno;
if (error == EINPROGRESS) {
Expand Down Expand Up @@ -663,10 +677,13 @@ inet_parse_passive(const char *target_, int default_port,
* negative errno value.
*
* If 'sinp' is non-null, then on success the bound address is stored into
* '*sinp'. */
* '*sinp'.
*
* 'dscp' If not DSCP_INVALID, its value becomes the DSCP bits in the IP
* headers for the new connection. */
int
inet_open_passive(int style, const char *target, int default_port,
struct sockaddr_in *sinp)
struct sockaddr_in *sinp, uint8_t dscp)
{
struct sockaddr_in sin;
int fd = 0, error;
Expand Down Expand Up @@ -701,6 +718,17 @@ inet_open_passive(int style, const char *target, int default_port,
goto error;
}

/* The socket options set here ensure that the TOS bits are set during
* the connection establishment. If set after connect(), the handshake
* SYN frames will be sent with a TOS of 0. */
if (dscp != DSCP_INVALID) {
if (setsockopt(fd, IPPROTO_IP, IP_TOS, &dscp, sizeof dscp)) {
VLOG_ERR("%s: socket: %s", target, strerror(errno));
error = errno;
goto error;
}
}

/* Listen. */
if (style == SOCK_STREAM && listen(fd, 10) < 0) {
error = errno;
Expand Down
15 changes: 13 additions & 2 deletions lib/socket-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <netinet/in.h>
#include <stdbool.h>
#include "openvswitch/types.h"
#include <netinet/ip.h>

int set_nonblocking(int fd);
int get_max_fds(void);
Expand All @@ -46,12 +47,12 @@ int get_null_fd(void);
bool inet_parse_active(const char *target, uint16_t default_port,
struct sockaddr_in *sinp);
int inet_open_active(int style, const char *target, uint16_t default_port,
struct sockaddr_in *sinp, int *fdp);
struct sockaddr_in *sinp, int *fdp, uint8_t dscp);

bool inet_parse_passive(const char *target, int default_port,
struct sockaddr_in *sinp);
int inet_open_passive(int style, const char *target, int default_port,
struct sockaddr_in *sinp);
struct sockaddr_in *sinp, uint8_t dscp);

int read_fully(int fd, void *, size_t, size_t *bytes_read);
int write_fully(int fd, const void *, size_t, size_t *bytes_written);
Expand All @@ -63,4 +64,14 @@ void xpipe(int fds[2]);

char *describe_fd(int fd);

/* Default value of dscp bits for connection between controller and manager.
* Value of IPTOS_PREC_INTERNETCONTROL = 0xc0 which is defined
* in <netinet/ip.h> is used. */
#define DSCP_DEFAULT IPTOS_PREC_INTERNETCONTROL

/* Invalid dscp value. If the dscp value will not be used, the dscp value
* passed must be invalid. Set to 0xFF as the TOS bits passed can only be
* 6 bits. */
#define DSCP_INVALID 0xFF

#endif /* socket-util.h */
Loading

0 comments on commit f125905

Please sign in to comment.