2011-03-29 12:24:28 -07:00
|
|
|
|
/*
|
2019-06-11 09:55:16 -07:00
|
|
|
|
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2019 Nicira, Inc.
|
2011-03-29 12:24:28 -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:
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2016-04-14 15:20:19 -07:00
|
|
|
|
#include "bundles.h"
|
|
|
|
|
#include "connmgr.h"
|
2011-03-29 12:24:28 -07:00
|
|
|
|
#include "coverage.h"
|
|
|
|
|
#include "fail-open.h"
|
|
|
|
|
#include "in-band.h"
|
|
|
|
|
#include "odp-util.h"
|
2016-04-04 21:32:10 -04:00
|
|
|
|
#include "ofproto-provider.h"
|
|
|
|
|
#include "openvswitch/dynamic-string.h"
|
2016-04-14 15:20:19 -07:00
|
|
|
|
#include "openvswitch/ofp-actions.h"
|
2016-04-04 21:32:10 -04:00
|
|
|
|
#include "openvswitch/ofp-msgs.h"
|
2018-02-09 10:04:26 -08:00
|
|
|
|
#include "openvswitch/ofp-monitor.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"
|
2016-09-13 14:46:16 -07:00
|
|
|
|
#include "ovs-atomic.h"
|
2011-03-29 12:24:28 -07:00
|
|
|
|
#include "pinsched.h"
|
2017-11-03 13:53:53 +08:00
|
|
|
|
#include "openvswitch/poll-loop.h"
|
2017-08-17 00:06:24 +08:00
|
|
|
|
#include "openvswitch/rconn.h"
|
2016-07-12 16:37:34 -05:00
|
|
|
|
#include "openvswitch/shash.h"
|
2018-04-19 14:09:38 -03:00
|
|
|
|
#include "sat-math.h"
|
2012-05-08 15:44:21 -07:00
|
|
|
|
#include "simap.h"
|
2011-12-21 09:59:16 -08:00
|
|
|
|
#include "stream.h"
|
2011-03-29 12:24:28 -07:00
|
|
|
|
#include "timeval.h"
|
2016-07-12 16:37:34 -05:00
|
|
|
|
#include "util.h"
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
VLOG_DEFINE_THIS_MODULE(connmgr);
|
|
|
|
|
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
|
|
|
|
|
|
2013-10-11 10:04:32 -07:00
|
|
|
|
/* An OpenFlow connection.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Thread-safety
|
|
|
|
|
* =============
|
|
|
|
|
*
|
|
|
|
|
* 'ofproto_mutex' must be held whenever an ofconn is created or destroyed or,
|
|
|
|
|
* more or less equivalently, whenever an ofconn is added to or removed from a
|
2013-10-10 23:11:09 -07:00
|
|
|
|
* connmgr. 'ofproto_mutex' doesn't protect the data inside the ofconn, except
|
|
|
|
|
* as specifically noted below. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct ofconn {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct connmgr *connmgr; /* Connection's manager. */
|
|
|
|
|
struct ovs_list connmgr_node; /* In connmgr->conns. */
|
2012-01-25 15:54:22 -08:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofservice *ofservice; /* Connection's service. */
|
|
|
|
|
struct ovs_list ofservice_node; /* In service->conns. */
|
2012-01-25 15:54:22 -08:00
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct rconn *rconn; /* OpenFlow connection. */
|
|
|
|
|
enum ofconn_type type; /* Type. */
|
2012-01-25 15:54:22 -08:00
|
|
|
|
enum ofproto_band band; /* In-band or out-of-band? */
|
2016-09-13 14:46:16 -07:00
|
|
|
|
bool want_packet_in_on_miss;
|
2012-01-25 15:54:22 -08:00
|
|
|
|
|
|
|
|
|
/* OpenFlow state. */
|
2013-02-11 23:55:31 -08:00
|
|
|
|
enum ofp12_controller_role role; /* Role. */
|
2012-02-10 13:30:23 -08:00
|
|
|
|
enum ofputil_protocol protocol; /* Current protocol variant. */
|
2018-02-16 11:43:56 -08:00
|
|
|
|
enum ofputil_packet_in_format packet_in_format;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* OFPT_PACKET_IN related data. */
|
2019-08-02 10:29:52 +02:00
|
|
|
|
int packet_in_queue_size;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct rconn_packet_counter *packet_in_counter; /* # queued on 'rconn'. */
|
|
|
|
|
#define N_SCHEDULERS 2
|
|
|
|
|
struct pinsched *schedulers[N_SCHEDULERS];
|
|
|
|
|
int miss_send_len; /* Bytes to send of buffered packets. */
|
2012-02-09 14:17:33 -08:00
|
|
|
|
uint16_t controller_id; /* Connection controller ID. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* Number of OpenFlow messages queued on 'rconn' as replies to OpenFlow
|
|
|
|
|
* requests, and the maximum number before we stop reading OpenFlow
|
|
|
|
|
* requests. */
|
|
|
|
|
#define OFCONN_REPLY_MAX 100
|
|
|
|
|
struct rconn_packet_counter *reply_counter;
|
2012-02-09 14:06:35 -08:00
|
|
|
|
|
2016-01-14 21:03:23 -08:00
|
|
|
|
/* Asynchronous message configuration in each possible role.
|
2012-02-09 14:06:35 -08:00
|
|
|
|
*
|
|
|
|
|
* A 1-bit enables sending an asynchronous message for one possible reason
|
|
|
|
|
* that the message might be generated, a 0-bit disables it. */
|
2016-01-14 21:03:23 -08:00
|
|
|
|
struct ofputil_async_cfg *async_cfg;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|
2014-04-30 10:50:32 -07:00
|
|
|
|
/* Flow table operation logging. */
|
|
|
|
|
int n_add, n_delete, n_modify; /* Number of unreported ops of each kind. */
|
|
|
|
|
long long int first_op, last_op; /* Range of times for unreported ops. */
|
|
|
|
|
long long int next_op_report; /* Time to report ops, or LLONG_MAX. */
|
|
|
|
|
long long int op_backoff; /* Earliest time to report ops again. */
|
|
|
|
|
|
2018-08-29 11:14:31 -07:00
|
|
|
|
/* Reassembly of multipart requests. */
|
|
|
|
|
struct hmap assembler;
|
|
|
|
|
|
2013-10-10 23:11:09 -07:00
|
|
|
|
/* Flow monitors (e.g. NXST_FLOW_MONITOR). */
|
|
|
|
|
|
|
|
|
|
/* Configuration. Contains "struct ofmonitor"s. */
|
|
|
|
|
struct hmap monitors OVS_GUARDED_BY(ofproto_mutex);
|
|
|
|
|
|
|
|
|
|
/* Flow control.
|
|
|
|
|
*
|
|
|
|
|
* When too many flow monitor notifications back up in the transmit buffer,
|
|
|
|
|
* we pause the transmission of further notifications. These members track
|
|
|
|
|
* the flow control state.
|
|
|
|
|
*
|
|
|
|
|
* When notifications are flowing, 'monitor_paused' is 0. When
|
|
|
|
|
* notifications are paused, 'monitor_paused' is the value of
|
|
|
|
|
* 'monitor_seqno' at the point we paused.
|
|
|
|
|
*
|
|
|
|
|
* 'monitor_counter' counts the OpenFlow messages and bytes currently in
|
|
|
|
|
* flight. This value growing too large triggers pausing. */
|
|
|
|
|
uint64_t monitor_paused OVS_GUARDED_BY(ofproto_mutex);
|
|
|
|
|
struct rconn_packet_counter *monitor_counter OVS_GUARDED_BY(ofproto_mutex);
|
|
|
|
|
|
|
|
|
|
/* State of monitors for a single ongoing flow_mod.
|
|
|
|
|
*
|
|
|
|
|
* 'updates' is a list of "struct ofpbuf"s that contain
|
|
|
|
|
* NXST_FLOW_MONITOR_REPLY messages representing the changes made by the
|
|
|
|
|
* current flow_mod.
|
|
|
|
|
*
|
|
|
|
|
* When 'updates' is nonempty, 'sent_abbrev_update' is true if 'updates'
|
|
|
|
|
* contains an update event of type NXFME_ABBREV and false otherwise.. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
struct ovs_list updates OVS_GUARDED_BY(ofproto_mutex);
|
2013-10-10 23:11:09 -07:00
|
|
|
|
bool sent_abbrev_update OVS_GUARDED_BY(ofproto_mutex);
|
2014-05-02 09:54:27 +03:00
|
|
|
|
|
|
|
|
|
/* Active bundles. Contains "struct ofp_bundle"s. */
|
|
|
|
|
struct hmap bundles;
|
2016-09-13 14:46:16 -07:00
|
|
|
|
long long int next_bundle_expiry_check;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* vswitchd/ovs-vswitchd.8.in documents the value of BUNDLE_IDLE_LIFETIME in
|
|
|
|
|
* seconds. That documentation must be kept in sync with the value below. */
|
2018-04-19 14:09:38 -03:00
|
|
|
|
#define BUNDLE_EXPIRY_INTERVAL 1000 /* Check bundle expiry every 1 sec. */
|
|
|
|
|
#define BUNDLE_IDLE_TIMEOUT_DEFAULT 10000 /* Expire idle bundles after
|
|
|
|
|
* 10 seconds. */
|
|
|
|
|
|
|
|
|
|
static unsigned int bundle_idle_timeout = BUNDLE_IDLE_TIMEOUT_DEFAULT;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-26 15:53:55 -07:00
|
|
|
|
static void ofconn_create(struct ofservice *, struct rconn *,
|
2018-10-24 14:23:38 -07:00
|
|
|
|
const struct ofproto_controller *settings)
|
|
|
|
|
OVS_EXCLUDED(ofproto_mutex);
|
2013-10-11 10:04:32 -07:00
|
|
|
|
static void ofconn_destroy(struct ofconn *) OVS_REQUIRES(ofproto_mutex);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
static void ofconn_reconfigure(struct ofconn *,
|
|
|
|
|
const struct ofproto_controller *);
|
|
|
|
|
|
|
|
|
|
static void ofconn_run(struct ofconn *,
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
void (*handle_openflow)(struct ofconn *,
|
2018-08-29 11:14:31 -07:00
|
|
|
|
const struct ovs_list *msgs));
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
static void ofconn_wait(struct ofconn *);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2014-04-30 10:50:32 -07:00
|
|
|
|
static void ofconn_log_flow_mods(struct ofconn *);
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
static char *ofconn_make_name(const struct connmgr *, const char *target);
|
|
|
|
|
|
|
|
|
|
static void ofconn_set_rate_limit(struct ofconn *, int rate, int burst);
|
|
|
|
|
|
|
|
|
|
static void ofconn_send(const struct ofconn *, struct ofpbuf *,
|
|
|
|
|
struct rconn_packet_counter *);
|
|
|
|
|
|
2014-12-15 14:10:38 +01:00
|
|
|
|
static void do_send_packet_ins(struct ofconn *, struct ovs_list *txq);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
/* A listener for incoming OpenFlow connections or for establishing an
|
|
|
|
|
* outgoing connection. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct ofservice {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct hmap_node hmap_node; /* In connmgr->services, by target. */
|
|
|
|
|
struct connmgr *connmgr;
|
|
|
|
|
|
|
|
|
|
char *target; /* e.g. "tcp:..." or "pssl:...". */
|
|
|
|
|
struct ovs_list conns; /* "ofconn"s generated by this service. */
|
|
|
|
|
enum ofconn_type type; /* OFCONN_PRIMARY or OFCONN_SERVICE. */
|
|
|
|
|
|
|
|
|
|
/* Source of connections. */
|
|
|
|
|
struct rconn *rconn; /* Active connection only. */
|
|
|
|
|
struct pvconn *pvconn; /* Passive listener only. */
|
|
|
|
|
|
|
|
|
|
/* Settings for "struct ofconn"s established by this service. */
|
|
|
|
|
struct ofproto_controller s;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
static void ofservice_run(struct ofservice *);
|
|
|
|
|
static void ofservice_wait(struct ofservice *);
|
2020-08-12 16:07:55 -04:00
|
|
|
|
static int ofservice_reconfigure(struct ofservice *,
|
|
|
|
|
const struct ofproto_controller *)
|
2018-10-24 14:23:38 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex);
|
|
|
|
|
static void ofservice_create(struct connmgr *mgr, const char *target,
|
|
|
|
|
const struct ofproto_controller *)
|
|
|
|
|
OVS_REQUIRES(ofproto_mutex);
|
|
|
|
|
static void ofservice_destroy(struct ofservice *) OVS_REQUIRES(ofproto_mutex);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
static struct ofservice *ofservice_lookup(struct connmgr *,
|
|
|
|
|
const char *target);
|
|
|
|
|
|
|
|
|
|
/* Connection manager for an OpenFlow switch. */
|
|
|
|
|
struct connmgr {
|
|
|
|
|
struct ofproto *ofproto;
|
|
|
|
|
char *name;
|
|
|
|
|
char *local_port_name;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
/* OpenFlow connections.
|
|
|
|
|
*
|
|
|
|
|
* All modifications to 'conns' protected by ofproto_mutex, so that any
|
|
|
|
|
* traversals from other threads can be made safe by holding the
|
|
|
|
|
* ofproto_mutex.*/
|
|
|
|
|
struct ovs_list conns; /* All ofconns. */
|
2020-06-17 14:55:45 -07:00
|
|
|
|
uint64_t primary_election_id; /* monotonically increasing sequence number
|
|
|
|
|
* for primary election */
|
|
|
|
|
bool primary_election_id_defined;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
/* OpenFlow connection establishment. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct hmap services; /* Contains "struct ofservice"s. */
|
|
|
|
|
struct pvconn **snoops;
|
|
|
|
|
size_t n_snoops;
|
|
|
|
|
|
|
|
|
|
/* Fail open. */
|
|
|
|
|
struct fail_open *fail_open;
|
|
|
|
|
enum ofproto_fail_mode fail_mode;
|
|
|
|
|
|
|
|
|
|
/* In-band control. */
|
|
|
|
|
struct in_band *in_band;
|
|
|
|
|
struct sockaddr_in *extra_in_band_remotes;
|
|
|
|
|
size_t n_extra_remotes;
|
|
|
|
|
int in_band_queue;
|
2016-09-13 14:46:16 -07:00
|
|
|
|
|
|
|
|
|
ATOMIC(int) want_packet_in_on_miss; /* Sum of ofconns' values. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void update_in_band_remotes(struct connmgr *);
|
|
|
|
|
static void add_snooper(struct connmgr *, struct vconn *);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
static void ofmonitor_run(struct connmgr *);
|
|
|
|
|
static void ofmonitor_wait(struct connmgr *);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* Creates and returns a new connection manager owned by 'ofproto'. 'name' is
|
|
|
|
|
* a name for the ofproto suitable for using in log messages.
|
|
|
|
|
* 'local_port_name' is the name of the local port (OFPP_LOCAL) within
|
|
|
|
|
* 'ofproto'. */
|
|
|
|
|
struct connmgr *
|
|
|
|
|
connmgr_create(struct ofproto *ofproto,
|
|
|
|
|
const char *name, const char *local_port_name)
|
|
|
|
|
{
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct connmgr *mgr = xmalloc(sizeof *mgr);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
mgr->ofproto = ofproto;
|
|
|
|
|
mgr->name = xstrdup(name);
|
|
|
|
|
mgr->local_port_name = xstrdup(local_port_name);
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ovs_list_init(&mgr->conns);
|
2020-06-17 14:55:45 -07:00
|
|
|
|
mgr->primary_election_id = 0;
|
|
|
|
|
mgr->primary_election_id_defined = false;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
hmap_init(&mgr->services);
|
|
|
|
|
mgr->snoops = NULL;
|
|
|
|
|
mgr->n_snoops = 0;
|
|
|
|
|
|
|
|
|
|
mgr->fail_open = NULL;
|
|
|
|
|
mgr->fail_mode = OFPROTO_FAIL_SECURE;
|
|
|
|
|
|
|
|
|
|
mgr->in_band = NULL;
|
|
|
|
|
mgr->extra_in_band_remotes = NULL;
|
|
|
|
|
mgr->n_extra_remotes = 0;
|
|
|
|
|
mgr->in_band_queue = -1;
|
|
|
|
|
|
2016-09-13 14:46:16 -07:00
|
|
|
|
atomic_init(&mgr->want_packet_in_on_miss, 0);
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
return mgr;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-13 14:46:16 -07:00
|
|
|
|
/* The default "table-miss" behaviour for OpenFlow1.3+ is to drop the
|
|
|
|
|
* packet rather than to send the packet to the controller.
|
|
|
|
|
*
|
|
|
|
|
* This function maintains the count of pre-OpenFlow1.3 with controller_id 0,
|
|
|
|
|
* as we assume these are the controllers that should receive "table-miss"
|
|
|
|
|
* notifications. */
|
|
|
|
|
static void
|
|
|
|
|
update_want_packet_in_on_miss(struct ofconn *ofconn)
|
|
|
|
|
{
|
|
|
|
|
/* We want a packet-in on miss when controller_id is zero and OpenFlow is
|
|
|
|
|
* lower than version 1.3. */
|
|
|
|
|
enum ofputil_protocol p = ofconn->protocol;
|
|
|
|
|
int new_want = (ofconn->controller_id == 0 &&
|
|
|
|
|
(p == OFPUTIL_P_NONE ||
|
|
|
|
|
ofputil_protocol_to_ofp_version(p) < OFP13_VERSION));
|
|
|
|
|
|
|
|
|
|
/* Update the setting and the count if necessary. */
|
|
|
|
|
int old_want = ofconn->want_packet_in_on_miss;
|
|
|
|
|
if (old_want != new_want) {
|
|
|
|
|
atomic_int *dst = &ofconn->connmgr->want_packet_in_on_miss;
|
|
|
|
|
int count;
|
|
|
|
|
atomic_read_relaxed(dst, &count);
|
|
|
|
|
atomic_store_relaxed(dst, count - old_want + new_want);
|
|
|
|
|
|
|
|
|
|
ofconn->want_packet_in_on_miss = new_want;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
/* Frees 'mgr' and all of its resources. */
|
|
|
|
|
void
|
|
|
|
|
connmgr_destroy(struct connmgr *mgr)
|
2016-09-13 14:46:16 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
|
|
|
|
if (!mgr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 12:56:17 +01:00
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH_SAFE (ofservice, hmap_node, &mgr->services) {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofservice_destroy(ofservice);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
hmap_destroy(&mgr->services);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ovs_assert(ovs_list_is_empty(&mgr->conns));
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (size_t i = 0; i < mgr->n_snoops; i++) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
pvconn_close(mgr->snoops[i]);
|
|
|
|
|
}
|
|
|
|
|
free(mgr->snoops);
|
|
|
|
|
|
|
|
|
|
fail_open_destroy(mgr->fail_open);
|
|
|
|
|
mgr->fail_open = NULL;
|
|
|
|
|
|
|
|
|
|
in_band_destroy(mgr->in_band);
|
|
|
|
|
mgr->in_band = NULL;
|
|
|
|
|
free(mgr->extra_in_band_remotes);
|
|
|
|
|
free(mgr->name);
|
|
|
|
|
free(mgr->local_port_name);
|
|
|
|
|
|
|
|
|
|
free(mgr);
|
|
|
|
|
}
|
|
|
|
|
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
/* Does all of the periodic maintenance required by 'mgr'. Calls
|
|
|
|
|
* 'handle_openflow' for each message received on an OpenFlow connection,
|
|
|
|
|
* passing along the OpenFlow connection itself and the message that was sent.
|
|
|
|
|
* 'handle_openflow' must not modify or free the message. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
void
|
|
|
|
|
connmgr_run(struct connmgr *mgr,
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
void (*handle_openflow)(struct ofconn *,
|
2018-08-29 11:14:31 -07:00
|
|
|
|
const struct ovs_list *msgs))
|
2013-09-12 20:45:15 -07:00
|
|
|
|
OVS_EXCLUDED(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
if (mgr->in_band) {
|
2011-08-03 15:01:11 -07:00
|
|
|
|
if (!in_band_run(mgr->in_band)) {
|
|
|
|
|
in_band_destroy(mgr->in_band);
|
|
|
|
|
mgr->in_band = NULL;
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 12:56:14 +01:00
|
|
|
|
struct ofconn *ofconn;
|
|
|
|
|
LIST_FOR_EACH_SAFE (ofconn, connmgr_node, &mgr->conns) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
ofconn_run(ofconn, handle_openflow);
|
|
|
|
|
}
|
2012-07-12 14:18:05 -07:00
|
|
|
|
ofmonitor_run(mgr);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* Fail-open maintenance. Do this after processing the ofconns since
|
|
|
|
|
* fail-open checks the status of the controller rconn. */
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
if (mgr->fail_open) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
fail_open_run(mgr->fail_open);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofservice *ofservice;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
|
|
|
|
ofservice_run(ofservice);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (size_t i = 0; i < mgr->n_snoops; i++) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct vconn *vconn;
|
2018-10-25 10:34:41 -07:00
|
|
|
|
int retval = pvconn_accept(mgr->snoops[i], &vconn);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
if (!retval) {
|
|
|
|
|
add_snooper(mgr, vconn);
|
|
|
|
|
} else if (retval != EAGAIN) {
|
2013-06-24 10:54:49 -07:00
|
|
|
|
VLOG_WARN_RL(&rl, "accept failed (%s)", ovs_strerror(retval));
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
/* Causes the poll loop to wake up when connmgr_run() needs to run. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
void
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
connmgr_wait(struct connmgr *mgr)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
|
|
|
|
struct ofconn *ofconn;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
ofconn_wait(ofconn);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
2018-10-25 10:34:41 -07:00
|
|
|
|
|
2012-07-12 14:18:05 -07:00
|
|
|
|
ofmonitor_wait(mgr);
|
2018-10-25 10:34:41 -07:00
|
|
|
|
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
if (mgr->in_band) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
in_band_wait(mgr->in_band);
|
|
|
|
|
}
|
2018-10-25 10:34:41 -07:00
|
|
|
|
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
if (mgr->fail_open) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
fail_open_wait(mgr->fail_open);
|
|
|
|
|
}
|
2018-10-25 10:34:41 -07:00
|
|
|
|
|
|
|
|
|
struct ofservice *ofservice;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
|
|
|
|
ofservice_wait(ofservice);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
2018-10-25 10:34:41 -07:00
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mgr->n_snoops; i++) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
pvconn_wait(mgr->snoops[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-08 15:44:21 -07:00
|
|
|
|
/* Adds some memory usage statistics for 'mgr' into 'usage', for use with
|
|
|
|
|
* memory_report(). */
|
|
|
|
|
void
|
|
|
|
|
connmgr_get_memory_usage(const struct connmgr *mgr, struct simap *usage)
|
|
|
|
|
{
|
|
|
|
|
unsigned int packets = 0;
|
|
|
|
|
unsigned int ofconns = 0;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofconn *ofconn;
|
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2012-05-08 15:44:21 -07:00
|
|
|
|
ofconns++;
|
|
|
|
|
|
|
|
|
|
packets += rconn_count_txqlen(ofconn->rconn);
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (int i = 0; i < N_SCHEDULERS; i++) {
|
2014-07-17 10:31:03 -07:00
|
|
|
|
struct pinsched_stats stats;
|
|
|
|
|
|
|
|
|
|
pinsched_get_stats(ofconn->schedulers[i], &stats);
|
2015-07-22 08:30:15 -07:00
|
|
|
|
packets += stats.n_queued;
|
2012-05-08 15:44:21 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
simap_increase(usage, "ofconns", ofconns);
|
|
|
|
|
simap_increase(usage, "packets", packets);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
/* Returns the ofproto that owns 'ofconn''s connmgr. */
|
|
|
|
|
struct ofproto *
|
|
|
|
|
ofconn_get_ofproto(const struct ofconn *ofconn)
|
|
|
|
|
{
|
|
|
|
|
return ofconn->connmgr->ofproto;
|
|
|
|
|
}
|
2018-04-19 14:09:38 -03:00
|
|
|
|
|
|
|
|
|
/* Sets the bundle idle timeout to 'timeout' seconds, interpreting 0 as
|
|
|
|
|
* requesting the default timeout.
|
|
|
|
|
*
|
|
|
|
|
* The OpenFlow spec mandates the timeout to be at least one second; . */
|
|
|
|
|
void
|
|
|
|
|
connmgr_set_bundle_idle_timeout(unsigned timeout)
|
|
|
|
|
{
|
|
|
|
|
bundle_idle_timeout = (timeout
|
|
|
|
|
? sat_mul(timeout, 1000)
|
|
|
|
|
: BUNDLE_IDLE_TIMEOUT_DEFAULT);
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* OpenFlow configuration. */
|
|
|
|
|
|
2014-01-10 11:36:35 -08:00
|
|
|
|
static void update_fail_open(struct connmgr *) OVS_EXCLUDED(ofproto_mutex);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
static int set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
|
2011-03-25 15:04:12 -07:00
|
|
|
|
const struct sset *);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* Returns true if 'mgr' has any configured primary controllers.
|
|
|
|
|
*
|
|
|
|
|
* Service controllers do not count, but configured primary controllers do
|
|
|
|
|
* count whether or not they are currently connected. */
|
|
|
|
|
bool
|
|
|
|
|
connmgr_has_controllers(const struct connmgr *mgr)
|
|
|
|
|
{
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
|
|
|
|
if (ofservice->type == OFCONN_PRIMARY) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct ofconn *
|
|
|
|
|
ofservice_first_conn(const struct ofservice *ofservice)
|
|
|
|
|
{
|
|
|
|
|
return (ovs_list_is_empty(&ofservice->conns)
|
|
|
|
|
? NULL
|
|
|
|
|
: CONTAINER_OF(ofservice->conns.next,
|
|
|
|
|
struct ofconn, ofservice_node));
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initializes 'info' and populates it with information about each configured
|
|
|
|
|
* primary controller. The keys in 'info' are the controllers' targets; the
|
|
|
|
|
* data values are corresponding "struct ofproto_controller_info".
|
|
|
|
|
*
|
|
|
|
|
* The caller owns 'info' and everything in it and should free it when it is no
|
|
|
|
|
* longer needed. */
|
|
|
|
|
void
|
|
|
|
|
connmgr_get_controller_info(struct connmgr *mgr, struct shash *info)
|
|
|
|
|
{
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
|
|
|
|
const struct rconn *rconn = ofservice->rconn;
|
|
|
|
|
if (!rconn) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-06-30 15:15:46 -07:00
|
|
|
|
const char *target = rconn_get_target(rconn);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2011-06-30 15:15:46 -07:00
|
|
|
|
if (!shash_find(info, target)) {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofconn *ofconn = ofservice_first_conn(ofservice);
|
2011-06-30 15:15:46 -07:00
|
|
|
|
struct ofproto_controller_info *cinfo = xmalloc(sizeof *cinfo);
|
2019-06-11 09:55:16 -07:00
|
|
|
|
long long int now = time_msec();
|
|
|
|
|
long long int last_connection = rconn_get_last_connection(rconn);
|
|
|
|
|
long long int last_disconnect = rconn_get_last_disconnect(rconn);
|
2011-06-30 15:15:46 -07:00
|
|
|
|
int last_error = rconn_get_last_error(rconn);
|
2014-07-17 10:31:03 -07:00
|
|
|
|
int i;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2011-06-30 15:15:46 -07:00
|
|
|
|
shash_add(info, target, cinfo);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2011-06-30 15:15:46 -07:00
|
|
|
|
cinfo->is_connected = rconn_is_connected(rconn);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
cinfo->role = ofconn ? ofconn->role : OFPCR12_ROLE_NOCHANGE;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2014-07-17 10:27:00 -07:00
|
|
|
|
smap_init(&cinfo->pairs);
|
2011-06-30 15:15:46 -07:00
|
|
|
|
if (last_error) {
|
2014-07-17 10:27:00 -07:00
|
|
|
|
smap_add(&cinfo->pairs, "last_error",
|
|
|
|
|
ovs_retval_to_string(last_error));
|
2011-06-30 15:15:46 -07:00
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2014-07-17 10:27:00 -07:00
|
|
|
|
smap_add(&cinfo->pairs, "state", rconn_get_state(rconn));
|
2011-06-30 15:15:46 -07:00
|
|
|
|
|
2019-06-11 09:55:16 -07:00
|
|
|
|
if (last_connection != LLONG_MIN) {
|
2014-07-17 10:27:00 -07:00
|
|
|
|
smap_add_format(&cinfo->pairs, "sec_since_connect",
|
2019-06-11 09:55:16 -07:00
|
|
|
|
"%lld", (now - last_connection) / 1000);
|
2011-06-30 15:15:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 09:55:16 -07:00
|
|
|
|
if (last_disconnect != LLONG_MIN) {
|
2014-07-17 10:27:00 -07:00
|
|
|
|
smap_add_format(&cinfo->pairs, "sec_since_disconnect",
|
2019-06-11 09:55:16 -07:00
|
|
|
|
"%lld", (now - last_disconnect) / 1000);
|
2011-06-30 15:15:46 -07:00
|
|
|
|
}
|
2014-07-17 10:31:03 -07:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < N_SCHEDULERS; i++) {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
if (ofconn && ofconn->schedulers[i]) {
|
2014-07-17 10:31:03 -07:00
|
|
|
|
const char *name = i ? "miss" : "action";
|
|
|
|
|
struct pinsched_stats stats;
|
|
|
|
|
|
|
|
|
|
pinsched_get_stats(ofconn->schedulers[i], &stats);
|
|
|
|
|
smap_add_nocopy(&cinfo->pairs,
|
|
|
|
|
xasprintf("packet-in-%s-backlog", name),
|
|
|
|
|
xasprintf("%u", stats.n_queued));
|
|
|
|
|
smap_add_nocopy(&cinfo->pairs,
|
|
|
|
|
xasprintf("packet-in-%s-bypassed", name),
|
|
|
|
|
xasprintf("%llu", stats.n_normal));
|
|
|
|
|
smap_add_nocopy(&cinfo->pairs,
|
|
|
|
|
xasprintf("packet-in-%s-queued", name),
|
|
|
|
|
xasprintf("%llu", stats.n_limited));
|
|
|
|
|
smap_add_nocopy(&cinfo->pairs,
|
|
|
|
|
xasprintf("packet-in-%s-dropped", name),
|
|
|
|
|
xasprintf("%llu", stats.n_queue_dropped));
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-30 18:08:59 -07:00
|
|
|
|
void
|
|
|
|
|
connmgr_free_controller_info(struct shash *info)
|
|
|
|
|
{
|
|
|
|
|
struct shash_node *node;
|
|
|
|
|
|
|
|
|
|
SHASH_FOR_EACH (node, info) {
|
|
|
|
|
struct ofproto_controller_info *cinfo = node->data;
|
2014-07-17 10:27:00 -07:00
|
|
|
|
smap_destroy(&cinfo->pairs);
|
2011-06-30 18:08:59 -07:00
|
|
|
|
free(cinfo);
|
|
|
|
|
}
|
|
|
|
|
shash_destroy(info);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
/* Changes 'mgr''s set of controllers to the 'n_controllers' controllers in
|
|
|
|
|
* 'controllers'. */
|
|
|
|
|
void
|
2018-10-24 14:23:38 -07:00
|
|
|
|
connmgr_set_controllers(struct connmgr *mgr, struct shash *controllers)
|
2013-10-11 10:04:32 -07:00
|
|
|
|
OVS_EXCLUDED(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2011-04-08 13:44:38 -07:00
|
|
|
|
bool had_controllers = connmgr_has_controllers(mgr);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2013-10-11 10:04:32 -07:00
|
|
|
|
/* Required to add and remove ofconns. This could probably be narrowed to
|
|
|
|
|
* cover a smaller amount of code, if that yielded some benefit. */
|
|
|
|
|
ovs_mutex_lock(&ofproto_mutex);
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
/* Create newly configured services. */
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct shash_node *node;
|
|
|
|
|
SHASH_FOR_EACH (node, controllers) {
|
|
|
|
|
const char *target = node->name;
|
|
|
|
|
const struct ofproto_controller *c = node->data;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
if (!ofservice_lookup(mgr, target)) {
|
|
|
|
|
ofservice_create(mgr, target, c);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Delete services that are no longer configured.
|
|
|
|
|
* Update configuration of all now-existing services. */
|
2022-03-23 12:56:17 +01:00
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH_SAFE (ofservice, hmap_node, &mgr->services) {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
const char *target = ofservice->target;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofproto_controller *c = shash_find_data(controllers, target);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
if (!c) {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
VLOG_INFO("%s: removed %s controller \"%s\"",
|
|
|
|
|
mgr->name, ofconn_type_to_string(ofservice->type),
|
|
|
|
|
target);
|
|
|
|
|
ofservice_destroy(ofservice);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
} else {
|
2020-08-12 16:07:55 -04:00
|
|
|
|
if (ofservice_reconfigure(ofservice, c)) {
|
|
|
|
|
char *target_to_restore = xstrdup(target);
|
|
|
|
|
VLOG_INFO("%s: Changes to controller \"%s\" "
|
|
|
|
|
"expects re-initialization: Re-initializing now.",
|
|
|
|
|
mgr->name, target);
|
|
|
|
|
ofservice_destroy(ofservice);
|
|
|
|
|
ofservice_create(mgr, target_to_restore, c);
|
|
|
|
|
free(target_to_restore);
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-16 10:58:29 -08:00
|
|
|
|
ovs_mutex_unlock(&ofproto_mutex);
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
update_in_band_remotes(mgr);
|
|
|
|
|
update_fail_open(mgr);
|
2011-04-08 13:44:38 -07:00
|
|
|
|
if (had_controllers != connmgr_has_controllers(mgr)) {
|
|
|
|
|
ofproto_flush_flows(mgr->ofproto);
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Drops the connections between 'mgr' and all of its primary and secondary
|
|
|
|
|
* controllers, forcing them to reconnect. */
|
|
|
|
|
void
|
|
|
|
|
connmgr_reconnect(const struct connmgr *mgr)
|
|
|
|
|
{
|
|
|
|
|
struct ofconn *ofconn;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
rconn_reconnect(ofconn->rconn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sets the "snoops" for 'mgr' to the pvconn targets listed in 'snoops'.
|
|
|
|
|
*
|
|
|
|
|
* A "snoop" is a pvconn to which every OpenFlow message to or from the most
|
|
|
|
|
* important controller on 'mgr' is mirrored. */
|
|
|
|
|
int
|
2011-03-25 15:04:12 -07:00
|
|
|
|
connmgr_set_snoops(struct connmgr *mgr, const struct sset *snoops)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
|
|
|
|
return set_pvconns(&mgr->snoops, &mgr->n_snoops, snoops);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Adds each of the snoops currently configured on 'mgr' to 'snoops'. */
|
|
|
|
|
void
|
2011-03-25 15:04:12 -07:00
|
|
|
|
connmgr_get_snoops(const struct connmgr *mgr, struct sset *snoops)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (size_t i = 0; i < mgr->n_snoops; i++) {
|
2011-03-25 15:04:12 -07:00
|
|
|
|
sset_add(snoops, pvconn_get_name(mgr->snoops[i]));
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-25 15:04:12 -07:00
|
|
|
|
/* Returns true if 'mgr' has at least one snoop, false if it has none. */
|
|
|
|
|
bool
|
|
|
|
|
connmgr_has_snoops(const struct connmgr *mgr)
|
|
|
|
|
{
|
|
|
|
|
return mgr->n_snoops > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
static void
|
|
|
|
|
update_in_band_remotes(struct connmgr *mgr)
|
|
|
|
|
{
|
|
|
|
|
/* Allocate enough memory for as many remotes as we could possibly have. */
|
2018-10-24 14:23:38 -07:00
|
|
|
|
size_t max_addrs = mgr->n_extra_remotes + hmap_count(&mgr->services);
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct sockaddr_in *addrs = xmalloc(max_addrs * sizeof *addrs);
|
|
|
|
|
size_t n_addrs = 0;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* Add all the remotes. */
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
|
|
|
|
const char *target = ofservice->target;
|
2014-08-05 13:51:19 -07:00
|
|
|
|
union {
|
|
|
|
|
struct sockaddr_storage ss;
|
|
|
|
|
struct sockaddr_in in;
|
|
|
|
|
} sa;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
if (ofservice->s.band == OFPROTO_IN_BAND
|
2015-03-11 13:32:01 -07:00
|
|
|
|
&& stream_parse_target_with_default_port(target, OFP_PORT, &sa.ss)
|
2014-08-05 13:51:19 -07:00
|
|
|
|
&& sa.ss.ss_family == AF_INET) {
|
|
|
|
|
addrs[n_addrs++] = sa.in;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (size_t i = 0; i < mgr->n_extra_remotes; i++) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
addrs[n_addrs++] = mgr->extra_in_band_remotes[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create or update or destroy in-band. */
|
|
|
|
|
if (n_addrs) {
|
|
|
|
|
if (!mgr->in_band) {
|
|
|
|
|
in_band_create(mgr->ofproto, mgr->local_port_name, &mgr->in_band);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2011-08-03 15:01:11 -07:00
|
|
|
|
/* in_band_run() needs a chance to delete any existing in-band flows.
|
|
|
|
|
* We will destroy mgr->in_band after it's done with that. */
|
|
|
|
|
}
|
|
|
|
|
if (mgr->in_band) {
|
2017-07-17 09:54:54 -07:00
|
|
|
|
in_band_set_queue(mgr->in_band, mgr->in_band_queue);
|
2011-08-03 15:01:11 -07:00
|
|
|
|
in_band_set_remotes(mgr->in_band, addrs, n_addrs);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Clean up. */
|
|
|
|
|
free(addrs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_fail_open(struct connmgr *mgr)
|
2014-01-10 11:36:35 -08:00
|
|
|
|
OVS_EXCLUDED(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
|
|
|
|
if (connmgr_has_controllers(mgr)
|
|
|
|
|
&& mgr->fail_mode == OFPROTO_FAIL_STANDALONE) {
|
|
|
|
|
if (!mgr->fail_open) {
|
|
|
|
|
mgr->fail_open = fail_open_create(mgr->ofproto, mgr);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-09-13 14:46:16 -07:00
|
|
|
|
ovs_mutex_lock(&ofproto_mutex);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
fail_open_destroy(mgr->fail_open);
|
2016-09-13 14:46:16 -07:00
|
|
|
|
ovs_mutex_unlock(&ofproto_mutex);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
mgr->fail_open = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
|
2011-03-25 15:04:12 -07:00
|
|
|
|
const struct sset *sset)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2018-10-25 10:34:41 -07:00
|
|
|
|
/* Free the old pvconns. */
|
|
|
|
|
struct pvconn **old_pvconns = *pvconnsp;
|
|
|
|
|
size_t old_n_pvconns = *n_pvconnsp;
|
|
|
|
|
for (size_t i = 0; i < old_n_pvconns; i++) {
|
|
|
|
|
pvconn_close(old_pvconns[i]);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
2018-10-25 10:34:41 -07:00
|
|
|
|
free(old_pvconns);
|
|
|
|
|
|
|
|
|
|
/* Populate the new pvconns. */
|
|
|
|
|
struct pvconn **new_pvconns = xmalloc(sset_count(sset)
|
|
|
|
|
* sizeof *new_pvconns);
|
|
|
|
|
size_t new_n_pvconns = 0;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
int retval = 0;
|
|
|
|
|
const char *name;
|
2011-03-25 15:04:12 -07:00
|
|
|
|
SSET_FOR_EACH (name, sset) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct pvconn *pvconn;
|
2018-10-25 10:34:41 -07:00
|
|
|
|
int error = pvconn_open(name, 0, 0, &pvconn);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
if (!error) {
|
2018-10-25 10:34:41 -07:00
|
|
|
|
new_pvconns[new_n_pvconns++] = pvconn;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
} else {
|
2013-06-24 10:54:49 -07:00
|
|
|
|
VLOG_ERR("failed to listen on %s: %s", name, ovs_strerror(error));
|
2011-03-29 12:24:28 -07:00
|
|
|
|
if (!retval) {
|
|
|
|
|
retval = error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
*pvconnsp = new_pvconns;
|
|
|
|
|
*n_pvconnsp = new_n_pvconns;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns a "preference level" for snooping 'ofconn'. A higher return value
|
|
|
|
|
* means that 'ofconn' is more interesting for monitoring than a lower return
|
|
|
|
|
* value. */
|
|
|
|
|
static int
|
2018-10-24 14:23:38 -07:00
|
|
|
|
snoop_preference(const struct ofservice *ofservice)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofconn *ofconn = ofservice_first_conn(ofservice);
|
|
|
|
|
if (!ofconn) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
switch (ofconn->role) {
|
2020-06-17 14:55:45 -07:00
|
|
|
|
case OFPCR12_ROLE_PRIMARY:
|
2011-03-29 12:24:28 -07:00
|
|
|
|
return 3;
|
2013-02-11 23:55:31 -08:00
|
|
|
|
case OFPCR12_ROLE_EQUAL:
|
2011-03-29 12:24:28 -07:00
|
|
|
|
return 2;
|
2020-06-17 14:55:45 -07:00
|
|
|
|
case OFPCR12_ROLE_SECONDARY:
|
2011-03-29 12:24:28 -07:00
|
|
|
|
return 1;
|
2013-02-11 23:55:31 -08:00
|
|
|
|
case OFPCR12_ROLE_NOCHANGE:
|
2011-03-29 12:24:28 -07:00
|
|
|
|
default:
|
|
|
|
|
/* Shouldn't happen. */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* One of 'mgr''s "snoop" pvconns has accepted a new connection on 'vconn'.
|
|
|
|
|
* Connects this vconn to a controller. */
|
|
|
|
|
static void
|
|
|
|
|
add_snooper(struct connmgr *mgr, struct vconn *vconn)
|
|
|
|
|
{
|
|
|
|
|
/* Pick a controller for monitoring. */
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofservice *best = NULL;
|
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
|
|
|
|
if (ofservice->rconn &&
|
|
|
|
|
(!best || snoop_preference(ofservice) > snoop_preference(best))) {
|
|
|
|
|
best = ofservice;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (best) {
|
|
|
|
|
rconn_add_monitor(best->rconn, vconn);
|
|
|
|
|
} else {
|
|
|
|
|
VLOG_INFO_RL(&rl, "no controller connection to snoop");
|
|
|
|
|
vconn_close(vconn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Public ofconn functions. */
|
|
|
|
|
|
|
|
|
|
/* Returns the connection type, either OFCONN_PRIMARY or OFCONN_SERVICE. */
|
|
|
|
|
enum ofconn_type
|
|
|
|
|
ofconn_get_type(const struct ofconn *ofconn)
|
|
|
|
|
{
|
|
|
|
|
return ofconn->type;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 14:55:45 -07:00
|
|
|
|
/* If a primary election id is defined, stores it into '*idp' and returns
|
2013-02-12 00:00:42 -08:00
|
|
|
|
* true. Otherwise, stores UINT64_MAX into '*idp' and returns false. */
|
|
|
|
|
bool
|
2020-06-17 14:55:45 -07:00
|
|
|
|
ofconn_get_primary_election_id(const struct ofconn *ofconn, uint64_t *idp)
|
2013-02-12 00:00:42 -08:00
|
|
|
|
{
|
2020-06-17 14:55:45 -07:00
|
|
|
|
*idp = (ofconn->connmgr->primary_election_id_defined
|
|
|
|
|
? ofconn->connmgr->primary_election_id
|
2013-02-12 00:00:42 -08:00
|
|
|
|
: UINT64_MAX);
|
2020-06-17 14:55:45 -07:00
|
|
|
|
return ofconn->connmgr->primary_election_id_defined;
|
2013-02-12 00:00:42 -08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 14:55:45 -07:00
|
|
|
|
/* Sets the primary election id.
|
2012-12-28 18:28:49 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns true if successful, false if the id is stale
|
|
|
|
|
*/
|
|
|
|
|
bool
|
2020-06-17 14:55:45 -07:00
|
|
|
|
ofconn_set_primary_election_id(struct ofconn *ofconn, uint64_t id)
|
2012-12-28 18:28:49 +02:00
|
|
|
|
{
|
2020-06-17 14:55:45 -07:00
|
|
|
|
if (ofconn->connmgr->primary_election_id_defined
|
2012-12-28 18:28:49 +02:00
|
|
|
|
&&
|
|
|
|
|
/* Unsigned difference interpreted as a two's complement signed
|
|
|
|
|
* value */
|
2020-06-17 14:55:45 -07:00
|
|
|
|
(int64_t)(id - ofconn->connmgr->primary_election_id) < 0) {
|
2012-12-28 18:28:49 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-06-17 14:55:45 -07:00
|
|
|
|
ofconn->connmgr->primary_election_id = id;
|
|
|
|
|
ofconn->connmgr->primary_election_id_defined = true;
|
2012-12-28 18:28:49 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
/* Returns the role configured for 'ofconn'.
|
|
|
|
|
*
|
2013-02-11 23:55:31 -08:00
|
|
|
|
* The default role, if no other role has been set, is OFPCR12_ROLE_EQUAL. */
|
|
|
|
|
enum ofp12_controller_role
|
2011-03-29 12:24:28 -07:00
|
|
|
|
ofconn_get_role(const struct ofconn *ofconn)
|
|
|
|
|
{
|
|
|
|
|
return ofconn->role;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-22 11:40:03 +03:00
|
|
|
|
void
|
|
|
|
|
ofconn_send_role_status(struct ofconn *ofconn, uint32_t role, uint8_t reason)
|
|
|
|
|
{
|
|
|
|
|
struct ofputil_role_status status;
|
|
|
|
|
status.reason = reason;
|
|
|
|
|
status.role = role;
|
2020-06-17 14:55:45 -07:00
|
|
|
|
ofconn_get_primary_election_id(ofconn, &status.generation_id);
|
2013-10-22 11:40:03 +03:00
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofpbuf *buf
|
|
|
|
|
= ofputil_encode_role_status(&status, ofconn_get_protocol(ofconn));
|
2014-07-22 15:54:55 -07:00
|
|
|
|
if (buf) {
|
|
|
|
|
ofconn_send(ofconn, buf, NULL);
|
|
|
|
|
}
|
2013-10-22 11:40:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 14:55:45 -07:00
|
|
|
|
/* Changes 'ofconn''s role to 'role'. If 'role' is OFPCR12_ROLE_PRIMARY then
|
|
|
|
|
* any existing primary is demoted to a secondary. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
void
|
2013-02-11 23:55:31 -08:00
|
|
|
|
ofconn_set_role(struct ofconn *ofconn, enum ofp12_controller_role role)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2020-06-17 14:55:45 -07:00
|
|
|
|
if (role != ofconn->role && role == OFPCR12_ROLE_PRIMARY) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct ofconn *other;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (other, connmgr_node, &ofconn->connmgr->conns) {
|
2020-06-17 14:55:45 -07:00
|
|
|
|
if (other->role == OFPCR12_ROLE_PRIMARY) {
|
|
|
|
|
other->role = OFPCR12_ROLE_SECONDARY;
|
|
|
|
|
ofconn_send_role_status(other, OFPCR12_ROLE_SECONDARY,
|
|
|
|
|
OFPCRR_PRIMARY_REQUEST);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ofconn->role = role;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-13 17:54:04 -08:00
|
|
|
|
void
|
2012-02-09 14:06:35 -08:00
|
|
|
|
ofconn_set_invalid_ttl_to_controller(struct ofconn *ofconn, bool enable)
|
2012-01-13 17:54:04 -08:00
|
|
|
|
{
|
2016-01-14 21:03:23 -08:00
|
|
|
|
struct ofputil_async_cfg ac = ofconn_get_async_config(ofconn);
|
2012-02-09 14:06:35 -08:00
|
|
|
|
uint32_t bit = 1u << OFPR_INVALID_TTL;
|
|
|
|
|
if (enable) {
|
2020-06-17 14:55:45 -07:00
|
|
|
|
ac.primary[OAM_PACKET_IN] |= bit;
|
2012-02-09 14:06:35 -08:00
|
|
|
|
} else {
|
2020-06-17 14:55:45 -07:00
|
|
|
|
ac.primary[OAM_PACKET_IN] &= ~bit;
|
2012-02-09 14:06:35 -08:00
|
|
|
|
}
|
2016-01-14 21:03:23 -08:00
|
|
|
|
ofconn_set_async_config(ofconn, &ac);
|
2012-01-13 17:54:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ofconn_get_invalid_ttl_to_controller(struct ofconn *ofconn)
|
|
|
|
|
{
|
2016-01-14 21:03:23 -08:00
|
|
|
|
struct ofputil_async_cfg ac = ofconn_get_async_config(ofconn);
|
2012-02-09 14:06:35 -08:00
|
|
|
|
uint32_t bit = 1u << OFPR_INVALID_TTL;
|
2020-06-17 14:55:45 -07:00
|
|
|
|
return (ac.primary[OAM_PACKET_IN] & bit) != 0;
|
2012-01-13 17:54:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 13:30:23 -08:00
|
|
|
|
/* Returns the currently configured protocol for 'ofconn', one of OFPUTIL_P_*.
|
2011-03-29 12:24:28 -07:00
|
|
|
|
*
|
2012-11-19 09:49:13 -08:00
|
|
|
|
* Returns OFPUTIL_P_NONE, which is not a valid protocol, if 'ofconn' hasn't
|
|
|
|
|
* completed version negotiation. This can't happen if at least one OpenFlow
|
|
|
|
|
* message, other than OFPT_HELLO, has been received on the connection (such as
|
|
|
|
|
* in ofproto.c's message handling code), since version negotiation is a
|
|
|
|
|
* prerequisite for starting to receive messages. This means that
|
|
|
|
|
* OFPUTIL_P_NONE is a special case that most callers need not worry about. */
|
2012-02-10 13:30:23 -08:00
|
|
|
|
enum ofputil_protocol
|
2012-11-19 09:50:44 -08:00
|
|
|
|
ofconn_get_protocol(const struct ofconn *ofconn)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2012-11-19 09:49:13 -08:00
|
|
|
|
if (ofconn->protocol == OFPUTIL_P_NONE &&
|
|
|
|
|
rconn_is_connected(ofconn->rconn)) {
|
|
|
|
|
int version = rconn_get_version(ofconn->rconn);
|
|
|
|
|
if (version > 0) {
|
|
|
|
|
ofconn_set_protocol(CONST_CAST(struct ofconn *, ofconn),
|
|
|
|
|
ofputil_protocol_from_ofp_version(version));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 13:30:23 -08:00
|
|
|
|
return ofconn->protocol;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 13:30:23 -08:00
|
|
|
|
/* Sets the protocol for 'ofconn' to 'protocol' (one of OFPUTIL_P_*).
|
|
|
|
|
*
|
|
|
|
|
* (This doesn't actually send anything to accomplish this. Presumably the
|
|
|
|
|
* caller already did that.) */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
void
|
2012-02-10 13:30:23 -08:00
|
|
|
|
ofconn_set_protocol(struct ofconn *ofconn, enum ofputil_protocol protocol)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2012-02-10 13:30:23 -08:00
|
|
|
|
ofconn->protocol = protocol;
|
2016-09-13 14:46:16 -07:00
|
|
|
|
update_want_packet_in_on_miss(ofconn);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-09 15:48:26 -08:00
|
|
|
|
/* Returns the currently configured packet in format for 'ofconn', one of
|
|
|
|
|
* NXPIF_*.
|
|
|
|
|
*
|
2016-02-19 15:31:37 -08:00
|
|
|
|
* The default, if no other format has been set, is NXPIF_STANDARD. */
|
2018-02-16 11:43:56 -08:00
|
|
|
|
enum ofputil_packet_in_format
|
2011-12-09 15:48:26 -08:00
|
|
|
|
ofconn_get_packet_in_format(struct ofconn *ofconn)
|
|
|
|
|
{
|
|
|
|
|
return ofconn->packet_in_format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sets the packet in format for 'ofconn' to 'packet_in_format' (one of
|
|
|
|
|
* NXPIF_*). */
|
|
|
|
|
void
|
|
|
|
|
ofconn_set_packet_in_format(struct ofconn *ofconn,
|
2018-02-16 11:43:56 -08:00
|
|
|
|
enum ofputil_packet_in_format packet_in_format)
|
2011-12-09 15:48:26 -08:00
|
|
|
|
{
|
|
|
|
|
ofconn->packet_in_format = packet_in_format;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-09 14:17:33 -08:00
|
|
|
|
/* Sets the controller connection ID for 'ofconn' to 'controller_id'.
|
|
|
|
|
*
|
|
|
|
|
* The connection controller ID is used for OFPP_CONTROLLER and
|
|
|
|
|
* NXAST_CONTROLLER actions. See "struct nx_action_controller" for details. */
|
|
|
|
|
void
|
|
|
|
|
ofconn_set_controller_id(struct ofconn *ofconn, uint16_t controller_id)
|
|
|
|
|
{
|
|
|
|
|
ofconn->controller_id = controller_id;
|
2016-09-13 14:46:16 -07:00
|
|
|
|
update_want_packet_in_on_miss(ofconn);
|
2012-02-09 14:17:33 -08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
/* Returns the default miss send length for 'ofconn'. */
|
|
|
|
|
int
|
|
|
|
|
ofconn_get_miss_send_len(const struct ofconn *ofconn)
|
|
|
|
|
{
|
|
|
|
|
return ofconn->miss_send_len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sets the default miss send length for 'ofconn' to 'miss_send_len'. */
|
|
|
|
|
void
|
|
|
|
|
ofconn_set_miss_send_len(struct ofconn *ofconn, int miss_send_len)
|
|
|
|
|
{
|
|
|
|
|
ofconn->miss_send_len = miss_send_len;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-09 14:06:35 -08:00
|
|
|
|
void
|
|
|
|
|
ofconn_set_async_config(struct ofconn *ofconn,
|
2016-01-14 21:03:23 -08:00
|
|
|
|
const struct ofputil_async_cfg *ac)
|
2012-02-09 14:06:35 -08:00
|
|
|
|
{
|
2016-01-14 21:03:23 -08:00
|
|
|
|
if (!ofconn->async_cfg) {
|
|
|
|
|
ofconn->async_cfg = xmalloc(sizeof *ofconn->async_cfg);
|
|
|
|
|
}
|
|
|
|
|
*ofconn->async_cfg = *ac;
|
2017-04-17 14:11:29 -07:00
|
|
|
|
|
|
|
|
|
if (ofputil_protocol_to_ofp_version(ofconn_get_protocol(ofconn))
|
|
|
|
|
< OFP14_VERSION) {
|
2020-06-17 14:55:45 -07:00
|
|
|
|
if (ofconn->async_cfg->primary[OAM_PACKET_IN] & (1u << OFPR_ACTION)) {
|
|
|
|
|
ofconn->async_cfg->primary[OAM_PACKET_IN] |= OFPR14_ACTION_BITS;
|
2017-04-17 14:11:29 -07:00
|
|
|
|
}
|
2020-06-17 14:55:45 -07:00
|
|
|
|
if (ofconn->async_cfg->secondary[OAM_PACKET_IN] & (1u << OFPR_ACTION)) {
|
|
|
|
|
ofconn->async_cfg->secondary[OAM_PACKET_IN] |= OFPR14_ACTION_BITS;
|
2017-04-17 14:11:29 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-09 14:06:35 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 21:03:23 -08:00
|
|
|
|
struct ofputil_async_cfg
|
|
|
|
|
ofconn_get_async_config(const struct ofconn *ofconn)
|
2013-09-07 15:36:21 +03:00
|
|
|
|
{
|
2016-01-14 21:03:23 -08:00
|
|
|
|
if (ofconn->async_cfg) {
|
|
|
|
|
return *ofconn->async_cfg;
|
2014-11-25 16:32:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 21:03:23 -08:00
|
|
|
|
int version = rconn_get_version(ofconn->rconn);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
return (version < 0 || !ofconn->ofservice->s.enable_async_msgs
|
2016-01-14 21:03:23 -08:00
|
|
|
|
? OFPUTIL_ASYNC_CFG_INIT
|
|
|
|
|
: ofputil_async_cfg_default(version));
|
2013-09-07 15:36:21 +03:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
/* Sends 'msg' on 'ofconn', accounting it as a reply. (If there is a
|
|
|
|
|
* sufficient number of OpenFlow replies in-flight on a single ofconn, then the
|
|
|
|
|
* connmgr will stop accepting new OpenFlow requests on that ofconn until the
|
|
|
|
|
* controller has accepted some of the replies.) */
|
|
|
|
|
void
|
|
|
|
|
ofconn_send_reply(const struct ofconn *ofconn, struct ofpbuf *msg)
|
|
|
|
|
{
|
|
|
|
|
ofconn_send(ofconn, msg, ofconn->reply_counter);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 16:49:06 -07:00
|
|
|
|
/* Sends each of the messages in list 'replies' on 'ofconn' in order,
|
|
|
|
|
* accounting them as replies. */
|
|
|
|
|
void
|
2014-12-15 14:10:38 +01:00
|
|
|
|
ofconn_send_replies(const struct ofconn *ofconn, struct ovs_list *replies)
|
2011-05-31 16:49:06 -07:00
|
|
|
|
{
|
2015-04-06 14:02:28 -07:00
|
|
|
|
struct ofpbuf *reply;
|
2011-05-31 16:49:06 -07:00
|
|
|
|
|
2015-04-06 14:02:28 -07:00
|
|
|
|
LIST_FOR_EACH_POP (reply, list_node, replies) {
|
2011-05-31 16:49:06 -07:00
|
|
|
|
ofconn_send_reply(ofconn, reply);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-09 10:38:31 -08:00
|
|
|
|
/* Sends 'error' on 'ofconn', as a reply to 'request'. */
|
2011-05-26 16:41:52 -07:00
|
|
|
|
void
|
|
|
|
|
ofconn_send_error(const struct ofconn *ofconn,
|
2012-01-12 15:48:19 -08:00
|
|
|
|
const struct ofp_header *request, enum ofperr error)
|
2011-05-26 16:41:52 -07:00
|
|
|
|
{
|
2012-11-30 16:22:52 -08:00
|
|
|
|
static struct vlog_rate_limit err_rl = VLOG_RATE_LIMIT_INIT(10, 10);
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofpbuf *reply = ofperr_encode_reply(error, request);
|
2012-11-30 16:22:52 -08:00
|
|
|
|
if (!VLOG_DROP_INFO(&err_rl)) {
|
2018-10-25 10:34:41 -07:00
|
|
|
|
size_t request_len = ntohs(request->length);
|
2012-11-30 16:22:52 -08:00
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
enum ofpraw raw;
|
|
|
|
|
const char *type_name = (!ofpraw_decode_partial(&raw, request,
|
|
|
|
|
MIN(64, request_len))
|
|
|
|
|
? ofpraw_get_name(raw)
|
|
|
|
|
: "invalid");
|
2012-11-30 16:22:52 -08:00
|
|
|
|
|
|
|
|
|
VLOG_INFO("%s: sending %s error reply to %s message",
|
|
|
|
|
rconn_get_name(ofconn->rconn), ofperr_to_string(error),
|
|
|
|
|
type_name);
|
|
|
|
|
}
|
|
|
|
|
ofconn_send_reply(ofconn, reply);
|
2011-05-26 16:41:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 10:50:32 -07:00
|
|
|
|
/* Reports that a flow_mod operation of the type specified by 'command' was
|
|
|
|
|
* successfully executed by 'ofconn', so that the connmgr can log it. */
|
|
|
|
|
void
|
|
|
|
|
ofconn_report_flow_mod(struct ofconn *ofconn,
|
|
|
|
|
enum ofp_flow_mod_command command)
|
|
|
|
|
{
|
|
|
|
|
switch (command) {
|
|
|
|
|
case OFPFC_ADD:
|
|
|
|
|
ofconn->n_add++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OFPFC_MODIFY:
|
|
|
|
|
case OFPFC_MODIFY_STRICT:
|
|
|
|
|
ofconn->n_modify++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OFPFC_DELETE:
|
|
|
|
|
case OFPFC_DELETE_STRICT:
|
|
|
|
|
ofconn->n_delete++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
long long int now = time_msec();
|
2014-04-30 10:50:32 -07:00
|
|
|
|
if (ofconn->next_op_report == LLONG_MAX) {
|
|
|
|
|
ofconn->first_op = now;
|
|
|
|
|
ofconn->next_op_report = MAX(now + 10 * 1000, ofconn->op_backoff);
|
|
|
|
|
ofconn->op_backoff = ofconn->next_op_report + 60 * 1000;
|
|
|
|
|
}
|
|
|
|
|
ofconn->last_op = now;
|
|
|
|
|
}
|
2015-05-29 11:28:38 -07:00
|
|
|
|
|
|
|
|
|
/* OpenFlow 1.4 bundles. */
|
2014-04-30 10:50:32 -07:00
|
|
|
|
|
2015-05-29 11:28:38 -07:00
|
|
|
|
static inline uint32_t
|
|
|
|
|
bundle_hash(uint32_t id)
|
2014-05-02 09:54:27 +03:00
|
|
|
|
{
|
2015-05-29 11:28:38 -07:00
|
|
|
|
return hash_int(id, 0);
|
2014-05-02 09:54:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 11:28:38 -07:00
|
|
|
|
struct ofp_bundle *
|
|
|
|
|
ofconn_get_bundle(struct ofconn *ofconn, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct ofp_bundle *bundle;
|
|
|
|
|
|
|
|
|
|
HMAP_FOR_EACH_IN_BUCKET(bundle, node, bundle_hash(id), &ofconn->bundles) {
|
|
|
|
|
if (bundle->id == id) {
|
|
|
|
|
return bundle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-09 10:38:31 -08:00
|
|
|
|
void
|
2015-05-29 11:28:38 -07:00
|
|
|
|
ofconn_insert_bundle(struct ofconn *ofconn, struct ofp_bundle *bundle)
|
|
|
|
|
{
|
|
|
|
|
hmap_insert(&ofconn->bundles, &bundle->node, bundle_hash(bundle->id));
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-09 10:38:31 -08:00
|
|
|
|
void
|
2015-05-29 11:28:38 -07:00
|
|
|
|
ofconn_remove_bundle(struct ofconn *ofconn, struct ofp_bundle *bundle)
|
|
|
|
|
{
|
|
|
|
|
hmap_remove(&ofconn->bundles, &bundle->node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bundle_remove_all(struct ofconn *ofconn)
|
|
|
|
|
{
|
2022-03-23 12:56:17 +01:00
|
|
|
|
struct ofp_bundle *b;
|
2015-05-29 11:28:38 -07:00
|
|
|
|
|
2022-03-23 12:56:17 +01:00
|
|
|
|
HMAP_FOR_EACH_SAFE (b, node, &ofconn->bundles) {
|
2016-09-15 13:59:52 -07:00
|
|
|
|
ofp_bundle_remove__(ofconn, b);
|
2015-05-29 11:28:38 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-13 14:46:16 -07:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bundle_remove_expired(struct ofconn *ofconn, long long int now)
|
|
|
|
|
{
|
2018-04-19 14:09:38 -03:00
|
|
|
|
long long int limit = now - bundle_idle_timeout;
|
2016-09-13 14:46:16 -07:00
|
|
|
|
|
2022-03-23 12:56:17 +01:00
|
|
|
|
struct ofp_bundle *b;
|
|
|
|
|
HMAP_FOR_EACH_SAFE (b, node, &ofconn->bundles) {
|
2016-09-13 14:46:16 -07:00
|
|
|
|
if (b->used <= limit) {
|
2018-01-09 10:38:31 -08:00
|
|
|
|
ofconn_send_error(ofconn, b->msg, OFPERR_OFPBFC_TIMEOUT);
|
2016-09-15 13:59:52 -07:00
|
|
|
|
ofp_bundle_remove__(ofconn, b);
|
2016-09-13 14:46:16 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* Private ofconn functions. */
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
static void
|
|
|
|
|
ofconn_create(struct ofservice *ofservice, struct rconn *rconn,
|
2018-10-26 15:53:55 -07:00
|
|
|
|
const struct ofproto_controller *settings)
|
2018-10-24 14:23:38 -07:00
|
|
|
|
OVS_EXCLUDED(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ovs_mutex_lock(&ofproto_mutex);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofconn *ofconn = xzalloc(sizeof *ofconn);
|
2012-01-25 15:54:22 -08:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofconn->connmgr = ofservice->connmgr;
|
|
|
|
|
ovs_list_push_back(&ofservice->connmgr->conns, &ofconn->connmgr_node);
|
2014-05-02 09:54:27 +03:00
|
|
|
|
|
2018-08-29 11:14:31 -07:00
|
|
|
|
hmap_init(&ofconn->assembler);
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofconn->ofservice = ofservice;
|
|
|
|
|
ovs_list_push_back(&ofservice->conns, &ofconn->ofservice_node);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofconn->rconn = rconn;
|
2018-10-26 15:53:55 -07:00
|
|
|
|
ofconn->type = settings->type;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofconn->band = settings->band;
|
2014-04-30 10:50:32 -07:00
|
|
|
|
|
2013-02-11 23:55:31 -08:00
|
|
|
|
ofconn->role = OFPCR12_ROLE_EQUAL;
|
2012-11-19 09:49:13 -08:00
|
|
|
|
ofconn_set_protocol(ofconn, OFPUTIL_P_NONE);
|
2018-02-16 11:43:56 -08:00
|
|
|
|
ofconn->packet_in_format = OFPUTIL_PACKET_IN_STD;
|
2012-01-25 15:54:22 -08:00
|
|
|
|
|
2019-08-02 10:29:52 +02:00
|
|
|
|
ofconn->packet_in_queue_size = settings->max_pktq_size;
|
2012-01-25 15:54:22 -08:00
|
|
|
|
ofconn->packet_in_counter = rconn_packet_counter_create();
|
|
|
|
|
ofconn->miss_send_len = (ofconn->type == OFCONN_PRIMARY
|
|
|
|
|
? OFP_DEFAULT_MISS_SEND_LEN
|
|
|
|
|
: 0);
|
2012-02-09 14:17:33 -08:00
|
|
|
|
ofconn->controller_id = 0;
|
2012-01-25 15:54:22 -08:00
|
|
|
|
|
|
|
|
|
ofconn->reply_counter = rconn_packet_counter_create();
|
2012-02-09 14:06:35 -08:00
|
|
|
|
|
2016-01-14 21:03:23 -08:00
|
|
|
|
ofconn->async_cfg = NULL;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|
2014-04-30 10:50:32 -07:00
|
|
|
|
ofconn->n_add = ofconn->n_delete = ofconn->n_modify = 0;
|
|
|
|
|
ofconn->first_op = ofconn->last_op = LLONG_MIN;
|
|
|
|
|
ofconn->next_op_report = LLONG_MAX;
|
|
|
|
|
ofconn->op_backoff = LLONG_MIN;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
hmap_init(&ofconn->monitors);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
ofconn->monitor_counter = rconn_packet_counter_create();
|
2018-08-29 11:14:31 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ovs_list_init(&ofconn->updates);
|
|
|
|
|
|
|
|
|
|
hmap_init(&ofconn->bundles);
|
|
|
|
|
ofconn->next_bundle_expiry_check = time_msec() + BUNDLE_EXPIRY_INTERVAL;
|
|
|
|
|
|
2023-09-28 21:44:24 +00:00
|
|
|
|
ofservice_reconfigure(ofservice, settings);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
|
|
|
|
|
ovs_mutex_unlock(&ofproto_mutex);
|
2011-06-07 16:21:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
static void
|
|
|
|
|
ofconn_destroy(struct ofconn *ofconn)
|
2013-10-11 10:04:32 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2018-10-24 14:23:38 -07:00
|
|
|
|
if (!ofconn) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofconn_log_flow_mods(ofconn);
|
|
|
|
|
|
|
|
|
|
ovs_list_remove(&ofconn->connmgr_node);
|
|
|
|
|
ovs_list_remove(&ofconn->ofservice_node);
|
|
|
|
|
|
|
|
|
|
if (ofconn->rconn != ofconn->ofservice->rconn) {
|
|
|
|
|
rconn_destroy(ofconn->rconn);
|
|
|
|
|
}
|
2011-06-07 16:21:59 -07:00
|
|
|
|
|
2016-09-13 14:46:16 -07:00
|
|
|
|
/* Force clearing of want_packet_in_on_miss to keep the global count
|
|
|
|
|
* accurate. */
|
|
|
|
|
ofconn->controller_id = 1;
|
|
|
|
|
update_want_packet_in_on_miss(ofconn);
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
rconn_packet_counter_destroy(ofconn->packet_in_counter);
|
|
|
|
|
for (int i = 0; i < N_SCHEDULERS; i++) {
|
|
|
|
|
if (ofconn->schedulers[i]) {
|
|
|
|
|
pinsched_destroy(ofconn->schedulers[i]);
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
rconn_packet_counter_destroy(ofconn->reply_counter);
|
|
|
|
|
|
|
|
|
|
free(ofconn->async_cfg);
|
2014-05-02 09:54:27 +03:00
|
|
|
|
|
2022-03-23 12:56:17 +01:00
|
|
|
|
struct ofmonitor *monitor;
|
|
|
|
|
HMAP_FOR_EACH_SAFE (monitor, ofconn_node,
|
2018-10-24 14:23:38 -07:00
|
|
|
|
&ofconn->monitors) {
|
|
|
|
|
ofmonitor_destroy(monitor);
|
|
|
|
|
}
|
2013-01-18 15:17:15 -08:00
|
|
|
|
hmap_destroy(&ofconn->monitors);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
rconn_packet_counter_destroy(ofconn->monitor_counter);
|
2018-08-29 11:14:31 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofpbuf_list_delete(&ofconn->updates); /* ...but it should be empty. */
|
|
|
|
|
|
|
|
|
|
bundle_remove_all(ofconn);
|
|
|
|
|
hmap_destroy(&ofconn->bundles);
|
2018-08-29 11:14:31 -07:00
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
free(ofconn);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
/* Reconfigures 'ofconn' to match 'c'. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
static void
|
|
|
|
|
ofconn_reconfigure(struct ofconn *ofconn, const struct ofproto_controller *c)
|
|
|
|
|
{
|
|
|
|
|
rconn_set_max_backoff(ofconn->rconn, c->max_backoff);
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
int probe_interval = c->probe_interval ? MAX(c->probe_interval, 5) : 0;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
rconn_set_probe_interval(ofconn->rconn, probe_interval);
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofconn->band = c->band;
|
2019-08-02 10:29:52 +02:00
|
|
|
|
ofconn->packet_in_queue_size = c->max_pktq_size;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
ofconn_set_rate_limit(ofconn, c->rate_limit, c->burst_limit);
|
2012-06-21 12:22:42 -07:00
|
|
|
|
|
|
|
|
|
if (c->dscp != rconn_get_dscp(ofconn->rconn)) {
|
|
|
|
|
rconn_set_dscp(ofconn->rconn, c->dscp);
|
|
|
|
|
rconn_reconnect(ofconn->rconn);
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 16:21:59 -07:00
|
|
|
|
/* Returns true if it makes sense for 'ofconn' to receive and process OpenFlow
|
|
|
|
|
* messages. */
|
|
|
|
|
static bool
|
|
|
|
|
ofconn_may_recv(const struct ofconn *ofconn)
|
|
|
|
|
{
|
2013-09-13 15:07:35 -07:00
|
|
|
|
int count = rconn_packet_counter_n_packets(ofconn->reply_counter);
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
return count < OFCONN_REPLY_MAX;
|
2011-06-07 16:21:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
static void
|
|
|
|
|
ofconn_run(struct ofconn *ofconn,
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
void (*handle_openflow)(struct ofconn *,
|
2018-08-29 11:14:31 -07:00
|
|
|
|
const struct ovs_list *msgs))
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
|
|
|
|
struct connmgr *mgr = ofconn->connmgr;
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (size_t i = 0; i < N_SCHEDULERS; i++) {
|
2014-12-15 14:10:38 +01:00
|
|
|
|
struct ovs_list txq;
|
2013-10-22 21:58:58 -07:00
|
|
|
|
|
|
|
|
|
pinsched_run(ofconn->schedulers[i], &txq);
|
|
|
|
|
do_send_packet_ins(ofconn, &txq);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rconn_run(ofconn->rconn);
|
|
|
|
|
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
/* Limit the number of iterations to avoid starving other tasks. */
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (int i = 0; i < 50 && ofconn_may_recv(ofconn); i++) {
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
struct ofpbuf *of_msg = rconn_recv(ofconn->rconn);
|
|
|
|
|
if (!of_msg) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-07 16:21:59 -07:00
|
|
|
|
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
if (mgr->fail_open) {
|
|
|
|
|
fail_open_maybe_recover(mgr->fail_open);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 11:14:31 -07:00
|
|
|
|
struct ovs_list msgs;
|
|
|
|
|
enum ofperr error = ofpmp_assembler_execute(&ofconn->assembler, of_msg,
|
|
|
|
|
&msgs, time_msec());
|
|
|
|
|
if (error) {
|
|
|
|
|
ofconn_send_error(ofconn, of_msg->data, error);
|
|
|
|
|
ofpbuf_delete(of_msg);
|
|
|
|
|
} else if (!ovs_list_is_empty(&msgs)) {
|
|
|
|
|
handle_openflow(ofconn, &msgs);
|
|
|
|
|
ofpbuf_list_delete(&msgs);
|
|
|
|
|
}
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
}
|
2014-04-30 10:50:32 -07:00
|
|
|
|
|
2016-09-13 14:46:16 -07:00
|
|
|
|
long long int now = time_msec();
|
|
|
|
|
|
|
|
|
|
if (now >= ofconn->next_bundle_expiry_check) {
|
|
|
|
|
ofconn->next_bundle_expiry_check = now + BUNDLE_EXPIRY_INTERVAL;
|
|
|
|
|
bundle_remove_expired(ofconn, now);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (now >= ofconn->next_op_report) {
|
2014-04-30 10:50:32 -07:00
|
|
|
|
ofconn_log_flow_mods(ofconn);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 11:14:31 -07:00
|
|
|
|
struct ofpbuf *error = ofpmp_assembler_run(&ofconn->assembler,
|
|
|
|
|
time_msec());
|
|
|
|
|
if (error) {
|
|
|
|
|
ofconn_send(ofconn, error, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-11 10:04:32 -07:00
|
|
|
|
ovs_mutex_lock(&ofproto_mutex);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
if (rconn_is_reliable(ofconn->rconn)
|
|
|
|
|
? !rconn_is_connected(ofconn->rconn)
|
|
|
|
|
: !rconn_is_alive(ofconn->rconn)) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
ofconn_destroy(ofconn);
|
|
|
|
|
}
|
2013-10-11 10:04:32 -07:00
|
|
|
|
ovs_mutex_unlock(&ofproto_mutex);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
ofconn_wait(struct ofconn *ofconn)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (int i = 0; i < N_SCHEDULERS; i++) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
pinsched_wait(ofconn->schedulers[i]);
|
|
|
|
|
}
|
|
|
|
|
rconn_run_wait(ofconn->rconn);
|
ofproto: Do straightforward removal of asynchronous flow operations.
Open vSwitch has supported datapaths that cannot update their flow tables
synchronously for many versions. In that time, I have talked to many
hardware implementers. None of them has ever mentioned the asynchronous
interface. Furthermore, the only public hardware implementation of an Open
vSwitch datapath (from Centec), does not use the asynchronous interface.
At the same time, the asynchronous interface makes ofproto hard to read and
hard to understand. It also makes it hard to maintain and extend. An
extension in an upcoming commit would be very difficult to implement
asynchronously.
Therefore, this commit begins to remove the asynchronous interface. This
initial commit does only the most straightforward parts of the removal, the
ones that do not significantly change the structure of the code. For
example, this commit does not remove the ofoperation or ofopgroup data
structures at the core of the asynchronous interface, but instead reduces
them to a vestigial form: where previously an ofoperation might span
multiple trips through the main loop (if the operation were truly
asynchronous), now it always completes immediately.
The following commit will do more structural changes. It will also update
all the comments, which are mostly left alone here.
The hope is that this structuring of the asynchronous removal into two
stages will make it easier to understand and review. If not, the commits
could be squashed.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2014-06-03 17:12:46 -07:00
|
|
|
|
if (ofconn_may_recv(ofconn)) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
rconn_recv_wait(ofconn->rconn);
|
|
|
|
|
}
|
2014-04-30 10:50:32 -07:00
|
|
|
|
if (ofconn->next_op_report != LLONG_MAX) {
|
|
|
|
|
poll_timer_wait_until(ofconn->next_op_report);
|
|
|
|
|
}
|
2018-08-29 11:14:31 -07:00
|
|
|
|
poll_timer_wait_until(ofpmp_assembler_wait(&ofconn->assembler));
|
2014-04-30 10:50:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ofconn_log_flow_mods(struct ofconn *ofconn)
|
|
|
|
|
{
|
|
|
|
|
int n_flow_mods = ofconn->n_add + ofconn->n_delete + ofconn->n_modify;
|
|
|
|
|
if (n_flow_mods) {
|
|
|
|
|
long long int ago = (time_msec() - ofconn->first_op) / 1000;
|
|
|
|
|
long long int interval = (ofconn->last_op - ofconn->first_op) / 1000;
|
|
|
|
|
struct ds s;
|
|
|
|
|
|
|
|
|
|
ds_init(&s);
|
|
|
|
|
ds_put_format(&s, "%d flow_mods ", n_flow_mods);
|
|
|
|
|
if (interval == ago) {
|
|
|
|
|
ds_put_format(&s, "in the last %lld s", ago);
|
|
|
|
|
} else if (interval) {
|
|
|
|
|
ds_put_format(&s, "in the %lld s starting %lld s ago",
|
|
|
|
|
interval, ago);
|
|
|
|
|
} else {
|
|
|
|
|
ds_put_format(&s, "%lld s ago", ago);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ds_put_cstr(&s, " (");
|
|
|
|
|
if (ofconn->n_add) {
|
|
|
|
|
ds_put_format(&s, "%d adds, ", ofconn->n_add);
|
|
|
|
|
}
|
|
|
|
|
if (ofconn->n_delete) {
|
|
|
|
|
ds_put_format(&s, "%d deletes, ", ofconn->n_delete);
|
|
|
|
|
}
|
|
|
|
|
if (ofconn->n_modify) {
|
|
|
|
|
ds_put_format(&s, "%d modifications, ", ofconn->n_modify);
|
|
|
|
|
}
|
|
|
|
|
s.length -= 2;
|
|
|
|
|
ds_put_char(&s, ')');
|
|
|
|
|
|
|
|
|
|
VLOG_INFO("%s: %s", rconn_get_name(ofconn->rconn), ds_cstr(&s));
|
|
|
|
|
ds_destroy(&s);
|
|
|
|
|
|
|
|
|
|
ofconn->n_add = ofconn->n_delete = ofconn->n_modify = 0;
|
|
|
|
|
}
|
|
|
|
|
ofconn->next_op_report = LLONG_MAX;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-09 14:06:35 -08:00
|
|
|
|
/* Returns true if 'ofconn' should receive asynchronous messages of the given
|
|
|
|
|
* OAM_* 'type' and 'reason', which should be a OFPR_* value for OAM_PACKET_IN,
|
|
|
|
|
* a OFPPR_* value for OAM_PORT_STATUS, or an OFPRR_* value for
|
|
|
|
|
* OAM_FLOW_REMOVED. Returns false if the message should not be sent on
|
|
|
|
|
* 'ofconn'. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
static bool
|
2012-02-09 14:06:35 -08:00
|
|
|
|
ofconn_receives_async_msg(const struct ofconn *ofconn,
|
ofproto: Implement OF1.4 Set/Get asynchronous configuration messages.
This patch adds support for Openflow1.4 set/get asynchronous configuration
messages. OpenVSwitch already supports set/get asynchronous configuration
messages for Openflow1.3. In this patch OFPT_SET_ASYNC_CONFIG message
allows the controllers to set the configuration for OFPT_ROLE_STATUS,
OFPT_TABLE_STATUS and OFPT_REQUESTFORWARD in addition to the Openflow1.3
messages. In a OFPT_SET_ASYNC, only the properties that shall be changed
need to be included, properties that are omitted from the message are
unchanged.
The OFPT_GET_ASYNC_CONFIG is used to query the asynchronous configuration
of switch. In a OFPT_GET_ASYNC_REPLY message, all properties must be
included.
According to Openflow1.4 the initial configuration shall be:
- In the “master” or “equal” role, enable all OFPT_PACKET_IN messages,
except those with reason OFPR_INVALID_TTL, enable all OFPT_PORT_STATUS
and OFPT_FLOW_REMOVED messages, and disable all OFPT_ROLE_STATUS,
OFPT_TABLE_STATUS and OFPT_REQUESTFORWARD messages.
- In the “slave” role, enable all OFPT_PORT_STATUS messages and disable
all OFPT_PACKET_IN, OFPT_FLOW_REMOVED, OFPT_ROLE_STATUS,
OFPT_TABLE_STATUS and OFPT_REQUESTFORWARD messages.
Signed-off-by: Niti Rohilla <niti.rohilla@tcs.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2015-07-23 17:05:44 +05:30
|
|
|
|
enum ofputil_async_msg_type type,
|
2012-02-09 14:06:35 -08:00
|
|
|
|
unsigned int reason)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2012-11-06 13:14:55 -08:00
|
|
|
|
ovs_assert(reason < 32);
|
|
|
|
|
ovs_assert((unsigned int) type < OAM_N_TYPES);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-12-12 12:28:34 -08:00
|
|
|
|
if (!rconn_is_connected(ofconn->rconn) || !ofconn_get_protocol(ofconn)) {
|
2018-10-18 16:47:05 +05:30
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-09 14:06:35 -08:00
|
|
|
|
/* Keep the following code in sync with the documentation in the
|
2016-12-08 12:55:26 +00:00
|
|
|
|
* "Asynchronous Messages" section in 'topics/design' */
|
2012-02-09 14:06:35 -08:00
|
|
|
|
|
|
|
|
|
if (ofconn->type == OFCONN_SERVICE && !ofconn->miss_send_len) {
|
|
|
|
|
/* Service connections don't get asynchronous messages unless they have
|
|
|
|
|
* explicitly asked for them by setting a nonzero miss send length. */
|
2012-01-13 17:54:04 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-02-09 14:06:35 -08:00
|
|
|
|
|
2016-01-14 21:03:23 -08:00
|
|
|
|
struct ofputil_async_cfg ac = ofconn_get_async_config(ofconn);
|
2020-06-17 14:55:45 -07:00
|
|
|
|
uint32_t *masks = (ofconn->role == OFPCR12_ROLE_SECONDARY
|
|
|
|
|
? ac.secondary
|
|
|
|
|
: ac.primary);
|
2016-01-14 21:03:23 -08:00
|
|
|
|
return (masks[type] & (1u << reason)) != 0;
|
2012-01-13 17:54:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-13 14:46:16 -07:00
|
|
|
|
/* This function returns true to indicate that a packet_in message
|
2014-04-02 18:04:27 +09:00
|
|
|
|
* for a "table-miss" should be sent to at least one controller.
|
|
|
|
|
*
|
2016-09-13 14:46:16 -07:00
|
|
|
|
* False otherwise. */
|
2014-04-02 18:04:27 +09:00
|
|
|
|
bool
|
2016-09-13 14:46:16 -07:00
|
|
|
|
connmgr_wants_packet_in_on_miss(struct connmgr *mgr)
|
2014-04-02 18:04:27 +09:00
|
|
|
|
{
|
2016-09-13 14:46:16 -07:00
|
|
|
|
int count;
|
2014-07-29 10:50:07 -07:00
|
|
|
|
|
2016-09-13 14:46:16 -07:00
|
|
|
|
atomic_read_relaxed(&mgr->want_packet_in_on_miss, &count);
|
|
|
|
|
return count > 0;
|
2014-04-02 18:04:27 +09:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
/* Returns a human-readable name for an OpenFlow connection between 'mgr' and
|
|
|
|
|
* 'target', suitable for use in log messages for identifying the connection.
|
|
|
|
|
*
|
|
|
|
|
* The name is dynamically allocated. The caller should free it (with free())
|
|
|
|
|
* when it is no longer needed. */
|
|
|
|
|
static char *
|
|
|
|
|
ofconn_make_name(const struct connmgr *mgr, const char *target)
|
|
|
|
|
{
|
|
|
|
|
return xasprintf("%s<->%s", mgr->name, target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ofconn_set_rate_limit(struct ofconn *ofconn, int rate, int burst)
|
|
|
|
|
{
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (int i = 0; i < N_SCHEDULERS; i++) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
struct pinsched **s = &ofconn->schedulers[i];
|
|
|
|
|
|
|
|
|
|
if (rate > 0) {
|
|
|
|
|
if (!*s) {
|
|
|
|
|
*s = pinsched_create(rate, burst);
|
|
|
|
|
} else {
|
|
|
|
|
pinsched_set_limits(*s, rate, burst);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
pinsched_destroy(*s);
|
|
|
|
|
*s = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ofconn_send(const struct ofconn *ofconn, struct ofpbuf *msg,
|
|
|
|
|
struct rconn_packet_counter *counter)
|
|
|
|
|
{
|
2012-07-19 23:23:17 -07:00
|
|
|
|
ofpmsg_update_length(msg);
|
2012-04-25 21:12:18 -07:00
|
|
|
|
rconn_send(ofconn->rconn, msg, counter);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sending asynchronous messages. */
|
|
|
|
|
|
2018-08-22 14:59:24 -07:00
|
|
|
|
/* Sends an OFPT_PORT_STATUS message with 'new_pp' and 'reason' to appropriate
|
2014-02-26 11:12:57 -08:00
|
|
|
|
* controllers managed by 'mgr'. For messages caused by a controller
|
|
|
|
|
* OFPT_PORT_MOD, specify 'source' as the controller connection that sent the
|
2018-08-22 14:59:24 -07:00
|
|
|
|
* request; otherwise, specify 'source' as NULL.
|
|
|
|
|
*
|
|
|
|
|
* If 'reason' is OFPPR_MODIFY and 'old_pp' is nonnull, then messages are
|
|
|
|
|
* suppressed in the case where the change would not be visible to a particular
|
|
|
|
|
* controller. For example, OpenFlow 1.0 does not have the OFPPS_LIVE flag, so
|
|
|
|
|
* this would suppress a change solely to that flag from being sent to an
|
|
|
|
|
* OpenFlow 1.0 controller. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
void
|
2014-02-26 11:12:57 -08:00
|
|
|
|
connmgr_send_port_status(struct connmgr *mgr, struct ofconn *source,
|
2018-08-22 14:59:24 -07:00
|
|
|
|
const struct ofputil_phy_port *old_pp,
|
|
|
|
|
const struct ofputil_phy_port *new_pp,
|
|
|
|
|
uint8_t reason)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
|
|
|
|
/* XXX Should limit the number of queued port status change messages. */
|
2018-08-22 14:59:24 -07:00
|
|
|
|
struct ofputil_port_status new_ps = { reason, *new_pp };
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-08-22 14:59:24 -07:00
|
|
|
|
struct ofconn *ofconn;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2012-02-09 14:06:35 -08:00
|
|
|
|
if (ofconn_receives_async_msg(ofconn, OAM_PORT_STATUS, reason)) {
|
2014-02-26 11:12:57 -08:00
|
|
|
|
/* Before 1.5, OpenFlow specified that OFPT_PORT_MOD should not
|
|
|
|
|
* generate OFPT_PORT_STATUS messages. That requirement was a
|
|
|
|
|
* relic of how OpenFlow originally supported a single controller,
|
|
|
|
|
* so that one could expect the controller to already know the
|
|
|
|
|
* changes it had made.
|
|
|
|
|
*
|
|
|
|
|
* EXT-338 changes OpenFlow 1.5 OFPT_PORT_MOD to send
|
|
|
|
|
* OFPT_PORT_STATUS messages to every controller. This is
|
|
|
|
|
* obviously more useful in the multi-controller case. We could
|
|
|
|
|
* always implement it that way in OVS, but that would risk
|
|
|
|
|
* confusing controllers that are intended for single-controller
|
|
|
|
|
* use only. (Imagine a controller that generates an OFPT_PORT_MOD
|
|
|
|
|
* in response to any OFPT_PORT_STATUS!)
|
|
|
|
|
*
|
|
|
|
|
* So this compromises: for OpenFlow 1.4 and earlier, it generates
|
|
|
|
|
* OFPT_PORT_STATUS for OFPT_PORT_MOD, but not back to the
|
|
|
|
|
* originating controller. In a single-controller environment, in
|
|
|
|
|
* particular, this means that it will never generate
|
|
|
|
|
* OFPT_PORT_STATUS for OFPT_PORT_MOD at all. */
|
|
|
|
|
if (ofconn == source
|
|
|
|
|
&& rconn_get_version(ofconn->rconn) < OFP15_VERSION) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-22 14:59:24 -07:00
|
|
|
|
enum ofputil_protocol protocol = ofconn_get_protocol(ofconn);
|
|
|
|
|
struct ofpbuf *msg = ofputil_encode_port_status(&new_ps, protocol);
|
|
|
|
|
if (reason == OFPPR_MODIFY && old_pp) {
|
|
|
|
|
struct ofputil_port_status old_ps = { reason, *old_pp };
|
|
|
|
|
struct ofpbuf *old_msg = ofputil_encode_port_status(&old_ps,
|
|
|
|
|
protocol);
|
|
|
|
|
bool suppress = ofpbuf_equal(msg, old_msg);
|
|
|
|
|
ofpbuf_delete(old_msg);
|
|
|
|
|
|
|
|
|
|
if (suppress) {
|
|
|
|
|
ofpbuf_delete(msg);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-15 16:33:04 -08:00
|
|
|
|
ofconn_send(ofconn, msg, NULL);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-09 17:33:42 +05:30
|
|
|
|
/* Sends an OFPT_REQUESTFORWARD message with 'request' and 'reason' to
|
|
|
|
|
* appropriate controllers managed by 'mgr'. For messages caused by a
|
|
|
|
|
* controller OFPT_GROUP_MOD and OFPT_METER_MOD, specify 'source' as the
|
|
|
|
|
* controller connection that sent the request; otherwise, specify 'source'
|
|
|
|
|
* as NULL. */
|
|
|
|
|
void
|
|
|
|
|
connmgr_send_requestforward(struct connmgr *mgr, const struct ofconn *source,
|
|
|
|
|
const struct ofputil_requestforward *rf)
|
|
|
|
|
{
|
|
|
|
|
struct ofconn *ofconn;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2018-10-26 15:06:28 -07:00
|
|
|
|
/* METER_MOD only supported in OF13 and up. */
|
|
|
|
|
if (rf->reason == OFPRFR_METER_MOD
|
|
|
|
|
&& rconn_get_version(ofconn->rconn) < OFP13_VERSION) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-09 17:33:42 +05:30
|
|
|
|
if (ofconn_receives_async_msg(ofconn, OAM_REQUESTFORWARD, rf->reason)
|
|
|
|
|
&& ofconn != source) {
|
|
|
|
|
enum ofputil_protocol protocol = ofconn_get_protocol(ofconn);
|
|
|
|
|
ofconn_send(ofconn, ofputil_encode_requestforward(rf, protocol),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 12:24:28 -07:00
|
|
|
|
/* Sends an OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED message based on 'fr' to
|
2016-09-13 14:46:16 -07:00
|
|
|
|
* appropriate controllers managed by 'mgr'.
|
|
|
|
|
*
|
|
|
|
|
* This may be called from the RCU thread. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
void
|
|
|
|
|
connmgr_send_flow_removed(struct connmgr *mgr,
|
|
|
|
|
const struct ofputil_flow_removed *fr)
|
2016-09-13 14:46:16 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
|
|
|
|
struct ofconn *ofconn;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2012-02-09 14:06:35 -08:00
|
|
|
|
if (ofconn_receives_async_msg(ofconn, OAM_FLOW_REMOVED, fr->reason)) {
|
|
|
|
|
/* Account flow expirations as replies to OpenFlow requests. That
|
|
|
|
|
* works because preventing OpenFlow requests from being processed
|
|
|
|
|
* also prevents new flows from being added (and expiring). (It
|
|
|
|
|
* also prevents processing OpenFlow requests that would not add
|
|
|
|
|
* new flows, so it is imperfect.) */
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofpbuf *msg = ofputil_encode_flow_removed(
|
|
|
|
|
fr, ofconn_get_protocol(ofconn));
|
2012-02-09 14:06:35 -08:00
|
|
|
|
ofconn_send_reply(ofconn, msg);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
2016-02-18 15:54:26 +05:30
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sends an OFPT_TABLE_STATUS message with 'reason' to appropriate controllers
|
|
|
|
|
* managed by 'mgr'. When the table state changes, the controller needs to be
|
|
|
|
|
* informed with the OFPT_TABLE_STATUS message. The reason values
|
|
|
|
|
* OFPTR_VACANCY_DOWN and OFPTR_VACANCY_UP identify a vacancy message. The
|
|
|
|
|
* vacancy events are generated when the remaining space in the flow table
|
|
|
|
|
* changes and crosses one of the vacancy thereshold specified by
|
|
|
|
|
* OFPT_TABLE_MOD. */
|
|
|
|
|
void
|
|
|
|
|
connmgr_send_table_status(struct connmgr *mgr,
|
|
|
|
|
const struct ofputil_table_desc *td,
|
|
|
|
|
uint8_t reason)
|
|
|
|
|
{
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofputil_table_status ts = {
|
|
|
|
|
.reason = reason,
|
|
|
|
|
.desc = *td
|
|
|
|
|
};
|
2016-02-18 15:54:26 +05:30
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofconn *ofconn;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2016-02-18 15:54:26 +05:30
|
|
|
|
if (ofconn_receives_async_msg(ofconn, OAM_TABLE_STATUS, reason)) {
|
|
|
|
|
struct ofpbuf *msg;
|
|
|
|
|
|
|
|
|
|
msg = ofputil_encode_table_status(&ts,
|
|
|
|
|
ofconn_get_protocol(ofconn));
|
|
|
|
|
if (msg) {
|
|
|
|
|
ofconn_send(ofconn, msg, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 13:12:15 +02:00
|
|
|
|
COVERAGE_DEFINE(connmgr_async_unsent);
|
|
|
|
|
|
2011-04-26 12:31:12 -07:00
|
|
|
|
/* Given 'pin', sends an OFPT_PACKET_IN message to each OpenFlow controller as
|
Implement serializing the state of packet traversal in "continuations".
One purpose of OpenFlow packet-in messages is to allow a controller to
interpose on the path of a packet through the flow tables. If, for
example, the controller needs to modify a packet in some way that the
switch doesn't directly support, the controller should be able to
program the switch to send it the packet, then modify the packet and
send it back to the switch to continue through the flow table.
That's the theory. In practice, this doesn't work with any but the
simplest flow tables. Packet-in messages simply don't include enough
context to allow the flow table traversal to continue. For example:
* Via "resubmit" actions, an Open vSwitch packet can have an
effective "call stack", but a packet-in can't describe it, and
so it would be lost.
* A packet-in can't preserve the stack used by NXAST_PUSH and
NXAST_POP actions.
* A packet-in can't preserve the OpenFlow 1.1+ action set.
* A packet-in can't preserve the state of Open vSwitch mirroring
or connection tracking.
This commit introduces a solution called "continuations". A continuation
is the state of a packet's traversal through OpenFlow flow tables. A
"controller" action with the "pause" flag, which is newly implemented in
this commit, generates a continuation and sends it to the OpenFlow
controller in a packet-in asynchronous message (only NXT_PACKET_IN2
supports continuations, so the controller must configure them with
NXT_SET_PACKET_IN_FORMAT). The controller processes the packet-in,
possibly modifying some of its data, and sends it back to the switch with
an NXT_RESUME request, which causes flow table traversal to continue. In
principle, a single packet can be paused and resumed multiple times.
Another way to look at it is:
- "pause" is an extension of the existing OFPAT_CONTROLLER
action. It sends the packet to the controller, with full
pipeline context (some of which is switch implementation
dependent, and may thus vary from switch to switch).
- A continuation is an extension of OFPT_PACKET_IN, allowing for
implementation dependent metadata.
- NXT_RESUME is an extension of OFPT_PACKET_OUT, with the
semantics that the pipeline processing is continued with the
original translation context from where it was left at the time
it was paused.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-02-19 16:10:06 -08:00
|
|
|
|
* necessary according to their individual configurations. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
void
|
2016-01-18 20:12:30 -08:00
|
|
|
|
connmgr_send_async_msg(struct connmgr *mgr,
|
|
|
|
|
const struct ofproto_async_msg *am)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2012-01-03 14:22:44 -08:00
|
|
|
|
struct ofconn *ofconn;
|
2023-08-05 13:12:15 +02:00
|
|
|
|
bool sent = false;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
openflow: Better abstract handling of packet-in messages.
Packet-in messages have been a bit of a mess. First, their abstraction
in the form of struct ofputil_packet_in has some fields that are used
in a clear way for incoming and outgoing packet-ins, and others
(packet_len, total_len, buffer_id) have have confusing meanings or
usage pattern depending on their direction.
Second, it's very confusing how a packet-in has both a reason (OFPR_*)
and a miss type (OFPROTO_PACKET_IN_*) and how those add up to the
actual reason that is used "on the wire" for each OpenFlow version (and
even whether the packet-in is sent at all!).
Finally, there's all kind of low-level detail randomly scattered between
connmgr, ofproto-dpif-xlate, and ofp-util.
This commit attempts to clear up some of the confusion. It simplifies
the struct ofputil_packet_in abstraction by removing the members that
didn't have a clear and consistent meaning between incoming and outgoing
packet-ins. It gets rid of OFPROTO_PACKET_IN_*, instead adding a couple
of nonstandard OFPR_* reasons that add up to what OFPROTO_PACKET_IN_*
was meant to say (in what I hope is a clearer way). And it consolidates
the tricky parts into ofp-util, where I hope it will be easier to
understand all in one place.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-01-20 09:57:16 -08:00
|
|
|
|
enum ofputil_protocol protocol = ofconn_get_protocol(ofconn);
|
|
|
|
|
if (protocol == OFPUTIL_P_NONE || !rconn_is_connected(ofconn->rconn)
|
2016-01-18 20:12:30 -08:00
|
|
|
|
|| ofconn->controller_id != am->controller_id
|
|
|
|
|
|| !ofconn_receives_async_msg(ofconn, am->oam,
|
2017-07-30 17:40:32 -07:00
|
|
|
|
am->pin.up.base.reason)) {
|
openflow: Better abstract handling of packet-in messages.
Packet-in messages have been a bit of a mess. First, their abstraction
in the form of struct ofputil_packet_in has some fields that are used
in a clear way for incoming and outgoing packet-ins, and others
(packet_len, total_len, buffer_id) have have confusing meanings or
usage pattern depending on their direction.
Second, it's very confusing how a packet-in has both a reason (OFPR_*)
and a miss type (OFPROTO_PACKET_IN_*) and how those add up to the
actual reason that is used "on the wire" for each OpenFlow version (and
even whether the packet-in is sent at all!).
Finally, there's all kind of low-level detail randomly scattered between
connmgr, ofproto-dpif-xlate, and ofp-util.
This commit attempts to clear up some of the confusion. It simplifies
the struct ofputil_packet_in abstraction by removing the members that
didn't have a clear and consistent meaning between incoming and outgoing
packet-ins. It gets rid of OFPROTO_PACKET_IN_*, instead adding a couple
of nonstandard OFPR_* reasons that add up to what OFPROTO_PACKET_IN_*
was meant to say (in what I hope is a clearer way). And it consolidates
the tricky parts into ofp-util, where I hope it will be easier to
understand all in one place.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-01-20 09:57:16 -08:00
|
|
|
|
continue;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
openflow: Better abstract handling of packet-in messages.
Packet-in messages have been a bit of a mess. First, their abstraction
in the form of struct ofputil_packet_in has some fields that are used
in a clear way for incoming and outgoing packet-ins, and others
(packet_len, total_len, buffer_id) have have confusing meanings or
usage pattern depending on their direction.
Second, it's very confusing how a packet-in has both a reason (OFPR_*)
and a miss type (OFPROTO_PACKET_IN_*) and how those add up to the
actual reason that is used "on the wire" for each OpenFlow version (and
even whether the packet-in is sent at all!).
Finally, there's all kind of low-level detail randomly scattered between
connmgr, ofproto-dpif-xlate, and ofp-util.
This commit attempts to clear up some of the confusion. It simplifies
the struct ofputil_packet_in abstraction by removing the members that
didn't have a clear and consistent meaning between incoming and outgoing
packet-ins. It gets rid of OFPROTO_PACKET_IN_*, instead adding a couple
of nonstandard OFPR_* reasons that add up to what OFPROTO_PACKET_IN_*
was meant to say (in what I hope is a clearer way). And it consolidates
the tricky parts into ofp-util, where I hope it will be easier to
understand all in one place.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-01-20 09:57:16 -08:00
|
|
|
|
|
Implement serializing the state of packet traversal in "continuations".
One purpose of OpenFlow packet-in messages is to allow a controller to
interpose on the path of a packet through the flow tables. If, for
example, the controller needs to modify a packet in some way that the
switch doesn't directly support, the controller should be able to
program the switch to send it the packet, then modify the packet and
send it back to the switch to continue through the flow table.
That's the theory. In practice, this doesn't work with any but the
simplest flow tables. Packet-in messages simply don't include enough
context to allow the flow table traversal to continue. For example:
* Via "resubmit" actions, an Open vSwitch packet can have an
effective "call stack", but a packet-in can't describe it, and
so it would be lost.
* A packet-in can't preserve the stack used by NXAST_PUSH and
NXAST_POP actions.
* A packet-in can't preserve the OpenFlow 1.1+ action set.
* A packet-in can't preserve the state of Open vSwitch mirroring
or connection tracking.
This commit introduces a solution called "continuations". A continuation
is the state of a packet's traversal through OpenFlow flow tables. A
"controller" action with the "pause" flag, which is newly implemented in
this commit, generates a continuation and sends it to the OpenFlow
controller in a packet-in asynchronous message (only NXT_PACKET_IN2
supports continuations, so the controller must configure them with
NXT_SET_PACKET_IN_FORMAT). The controller processes the packet-in,
possibly modifying some of its data, and sends it back to the switch with
an NXT_RESUME request, which causes flow table traversal to continue. In
principle, a single packet can be paused and resumed multiple times.
Another way to look at it is:
- "pause" is an extension of the existing OFPAT_CONTROLLER
action. It sends the packet to the controller, with full
pipeline context (some of which is switch implementation
dependent, and may thus vary from switch to switch).
- A continuation is an extension of OFPT_PACKET_IN, allowing for
implementation dependent metadata.
- NXT_RESUME is an extension of OFPT_PACKET_OUT, with the
semantics that the pipeline processing is continued with the
original translation context from where it was left at the time
it was paused.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-02-19 16:10:06 -08:00
|
|
|
|
struct ofpbuf *msg = ofputil_encode_packet_in_private(
|
2016-08-30 10:20:51 -07:00
|
|
|
|
&am->pin.up, protocol, ofconn->packet_in_format);
|
openflow: Better abstract handling of packet-in messages.
Packet-in messages have been a bit of a mess. First, their abstraction
in the form of struct ofputil_packet_in has some fields that are used
in a clear way for incoming and outgoing packet-ins, and others
(packet_len, total_len, buffer_id) have have confusing meanings or
usage pattern depending on their direction.
Second, it's very confusing how a packet-in has both a reason (OFPR_*)
and a miss type (OFPROTO_PACKET_IN_*) and how those add up to the
actual reason that is used "on the wire" for each OpenFlow version (and
even whether the packet-in is sent at all!).
Finally, there's all kind of low-level detail randomly scattered between
connmgr, ofproto-dpif-xlate, and ofp-util.
This commit attempts to clear up some of the confusion. It simplifies
the struct ofputil_packet_in abstraction by removing the members that
didn't have a clear and consistent meaning between incoming and outgoing
packet-ins. It gets rid of OFPROTO_PACKET_IN_*, instead adding a couple
of nonstandard OFPR_* reasons that add up to what OFPROTO_PACKET_IN_*
was meant to say (in what I hope is a clearer way). And it consolidates
the tricky parts into ofp-util, where I hope it will be easier to
understand all in one place.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-01-20 09:57:16 -08:00
|
|
|
|
|
|
|
|
|
struct ovs_list txq;
|
2017-07-30 17:40:32 -07:00
|
|
|
|
bool is_miss = (am->pin.up.base.reason == OFPR_NO_MATCH ||
|
|
|
|
|
am->pin.up.base.reason == OFPR_EXPLICIT_MISS ||
|
|
|
|
|
am->pin.up.base.reason == OFPR_IMPLICIT_MISS);
|
openflow: Better abstract handling of packet-in messages.
Packet-in messages have been a bit of a mess. First, their abstraction
in the form of struct ofputil_packet_in has some fields that are used
in a clear way for incoming and outgoing packet-ins, and others
(packet_len, total_len, buffer_id) have have confusing meanings or
usage pattern depending on their direction.
Second, it's very confusing how a packet-in has both a reason (OFPR_*)
and a miss type (OFPROTO_PACKET_IN_*) and how those add up to the
actual reason that is used "on the wire" for each OpenFlow version (and
even whether the packet-in is sent at all!).
Finally, there's all kind of low-level detail randomly scattered between
connmgr, ofproto-dpif-xlate, and ofp-util.
This commit attempts to clear up some of the confusion. It simplifies
the struct ofputil_packet_in abstraction by removing the members that
didn't have a clear and consistent meaning between incoming and outgoing
packet-ins. It gets rid of OFPROTO_PACKET_IN_*, instead adding a couple
of nonstandard OFPR_* reasons that add up to what OFPROTO_PACKET_IN_*
was meant to say (in what I hope is a clearer way). And it consolidates
the tricky parts into ofp-util, where I hope it will be easier to
understand all in one place.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-01-20 09:57:16 -08:00
|
|
|
|
pinsched_send(ofconn->schedulers[is_miss],
|
2017-07-30 17:40:32 -07:00
|
|
|
|
am->pin.up.base.flow_metadata.flow.in_port.ofp_port,
|
2016-01-18 20:12:30 -08:00
|
|
|
|
msg, &txq);
|
openflow: Better abstract handling of packet-in messages.
Packet-in messages have been a bit of a mess. First, their abstraction
in the form of struct ofputil_packet_in has some fields that are used
in a clear way for incoming and outgoing packet-ins, and others
(packet_len, total_len, buffer_id) have have confusing meanings or
usage pattern depending on their direction.
Second, it's very confusing how a packet-in has both a reason (OFPR_*)
and a miss type (OFPROTO_PACKET_IN_*) and how those add up to the
actual reason that is used "on the wire" for each OpenFlow version (and
even whether the packet-in is sent at all!).
Finally, there's all kind of low-level detail randomly scattered between
connmgr, ofproto-dpif-xlate, and ofp-util.
This commit attempts to clear up some of the confusion. It simplifies
the struct ofputil_packet_in abstraction by removing the members that
didn't have a clear and consistent meaning between incoming and outgoing
packet-ins. It gets rid of OFPROTO_PACKET_IN_*, instead adding a couple
of nonstandard OFPR_* reasons that add up to what OFPROTO_PACKET_IN_*
was meant to say (in what I hope is a clearer way). And it consolidates
the tricky parts into ofp-util, where I hope it will be easier to
understand all in one place.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-01-20 09:57:16 -08:00
|
|
|
|
do_send_packet_ins(ofconn, &txq);
|
2023-08-05 13:12:15 +02:00
|
|
|
|
sent = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sent) {
|
|
|
|
|
COVERAGE_INC(connmgr_async_unsent);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-12-15 14:10:38 +01:00
|
|
|
|
do_send_packet_ins(struct ofconn *ofconn, struct ovs_list *txq)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2015-04-06 14:02:28 -07:00
|
|
|
|
struct ofpbuf *pin;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2015-04-06 14:02:28 -07:00
|
|
|
|
LIST_FOR_EACH_POP (pin, list_node, txq) {
|
2013-12-05 09:21:14 -08:00
|
|
|
|
if (rconn_send_with_limit(ofconn->rconn, pin,
|
2019-08-02 10:29:52 +02:00
|
|
|
|
ofconn->packet_in_counter,
|
|
|
|
|
ofconn->packet_in_queue_size) == EAGAIN) {
|
2018-02-27 10:44:13 -08:00
|
|
|
|
static struct vlog_rate_limit rll = VLOG_RATE_LIMIT_INIT(5, 5);
|
2013-12-05 09:21:14 -08:00
|
|
|
|
|
2018-02-27 10:44:13 -08:00
|
|
|
|
VLOG_INFO_RL(&rll, "%s: dropping packet-in due to queue overflow",
|
2013-12-05 09:21:14 -08:00
|
|
|
|
rconn_get_name(ofconn->rconn));
|
|
|
|
|
}
|
2013-10-22 21:58:58 -07:00
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fail-open settings. */
|
|
|
|
|
|
|
|
|
|
/* Returns the failure handling mode (OFPROTO_FAIL_SECURE or
|
|
|
|
|
* OFPROTO_FAIL_STANDALONE) for 'mgr'. */
|
|
|
|
|
enum ofproto_fail_mode
|
|
|
|
|
connmgr_get_fail_mode(const struct connmgr *mgr)
|
|
|
|
|
{
|
|
|
|
|
return mgr->fail_mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sets the failure handling mode for 'mgr' to 'fail_mode' (either
|
|
|
|
|
* OFPROTO_FAIL_SECURE or OFPROTO_FAIL_STANDALONE). */
|
|
|
|
|
void
|
|
|
|
|
connmgr_set_fail_mode(struct connmgr *mgr, enum ofproto_fail_mode fail_mode)
|
|
|
|
|
{
|
2011-04-08 13:44:38 -07:00
|
|
|
|
if (mgr->fail_mode != fail_mode) {
|
|
|
|
|
mgr->fail_mode = fail_mode;
|
|
|
|
|
update_fail_open(mgr);
|
|
|
|
|
if (!connmgr_has_controllers(mgr)) {
|
|
|
|
|
ofproto_flush_flows(mgr->ofproto);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fail-open implementation. */
|
|
|
|
|
|
|
|
|
|
/* Returns the longest probe interval among the primary controllers configured
|
|
|
|
|
* on 'mgr'. Returns 0 if there are no primary controllers. */
|
|
|
|
|
int
|
|
|
|
|
connmgr_get_max_probe_interval(const struct connmgr *mgr)
|
|
|
|
|
{
|
2018-10-25 10:34:41 -07:00
|
|
|
|
int max_probe_interval = 0;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
|
|
|
|
if (ofservice->type == OFCONN_PRIMARY) {
|
|
|
|
|
int probe_interval = ofservice->s.probe_interval;
|
|
|
|
|
max_probe_interval = MAX(max_probe_interval, probe_interval);
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
return max_probe_interval;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-26 15:53:55 -07:00
|
|
|
|
/* Returns the number of seconds for which all of 'mgr's active, primary
|
|
|
|
|
* controllers have been disconnected. Returns 0 if 'mgr' has no active,
|
|
|
|
|
* primary controllers. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
int
|
|
|
|
|
connmgr_failure_duration(const struct connmgr *mgr)
|
|
|
|
|
{
|
2018-10-25 10:34:41 -07:00
|
|
|
|
int min_failure_duration = INT_MAX;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
2018-10-26 15:53:55 -07:00
|
|
|
|
if (ofservice->s.type == OFCONN_PRIMARY && ofservice->rconn) {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
int failure_duration = rconn_failure_duration(ofservice->rconn);
|
|
|
|
|
min_failure_duration = MIN(min_failure_duration, failure_duration);
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
2018-10-24 14:23:38 -07:00
|
|
|
|
|
|
|
|
|
return min_failure_duration != INT_MAX ? min_failure_duration : 0;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns true if at least one primary controller is connected (regardless of
|
|
|
|
|
* whether those controllers are believed to have authenticated and accepted
|
|
|
|
|
* this switch), false if none of them are connected. */
|
|
|
|
|
bool
|
|
|
|
|
connmgr_is_any_controller_connected(const struct connmgr *mgr)
|
|
|
|
|
{
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
HMAP_FOR_EACH (ofservice, hmap_node, &mgr->services) {
|
2018-10-26 15:53:55 -07:00
|
|
|
|
if (ofservice->s.type == OFCONN_PRIMARY
|
|
|
|
|
&& !ovs_list_is_empty(&ofservice->conns)) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns true if at least one primary controller is believed to have
|
|
|
|
|
* authenticated and accepted this switch, false otherwise. */
|
|
|
|
|
bool
|
|
|
|
|
connmgr_is_any_controller_admitted(const struct connmgr *mgr)
|
|
|
|
|
{
|
|
|
|
|
const struct ofconn *ofconn;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
|
|
|
|
if (ofconn->type == OFCONN_PRIMARY
|
|
|
|
|
&& rconn_is_admitted(ofconn->rconn)) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* In-band configuration. */
|
|
|
|
|
|
|
|
|
|
static bool any_extras_changed(const struct connmgr *,
|
|
|
|
|
const struct sockaddr_in *extras, size_t n);
|
|
|
|
|
|
|
|
|
|
/* Sets the 'n' TCP port addresses in 'extras' as ones to which 'mgr''s
|
|
|
|
|
* in-band control should guarantee access, in the same way that in-band
|
|
|
|
|
* control guarantees access to OpenFlow controllers. */
|
|
|
|
|
void
|
|
|
|
|
connmgr_set_extra_in_band_remotes(struct connmgr *mgr,
|
|
|
|
|
const struct sockaddr_in *extras, size_t n)
|
|
|
|
|
{
|
|
|
|
|
if (!any_extras_changed(mgr, extras, n)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(mgr->extra_in_band_remotes);
|
|
|
|
|
mgr->n_extra_remotes = n;
|
|
|
|
|
mgr->extra_in_band_remotes = xmemdup(extras, n * sizeof *extras);
|
|
|
|
|
|
|
|
|
|
update_in_band_remotes(mgr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sets the OpenFlow queue used by flows set up by in-band control on
|
|
|
|
|
* 'mgr' to 'queue_id'. If 'queue_id' is negative, then in-band control
|
|
|
|
|
* flows will use the default queue. */
|
|
|
|
|
void
|
|
|
|
|
connmgr_set_in_band_queue(struct connmgr *mgr, int queue_id)
|
|
|
|
|
{
|
|
|
|
|
if (queue_id != mgr->in_band_queue) {
|
|
|
|
|
mgr->in_band_queue = queue_id;
|
|
|
|
|
update_in_band_remotes(mgr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
any_extras_changed(const struct connmgr *mgr,
|
|
|
|
|
const struct sockaddr_in *extras, size_t n)
|
|
|
|
|
{
|
|
|
|
|
if (n != mgr->n_extra_remotes) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
for (size_t i = 0; i < n; i++) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
const struct sockaddr_in *old = &mgr->extra_in_band_remotes[i];
|
|
|
|
|
const struct sockaddr_in *new = &extras[i];
|
|
|
|
|
|
|
|
|
|
if (old->sin_addr.s_addr != new->sin_addr.s_addr ||
|
|
|
|
|
old->sin_port != new->sin_port) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* In-band implementation. */
|
|
|
|
|
|
|
|
|
|
bool
|
2013-06-22 10:48:42 -07:00
|
|
|
|
connmgr_has_in_band(struct connmgr *mgr)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2013-06-22 10:48:42 -07:00
|
|
|
|
return mgr->in_band != NULL;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fail-open and in-band implementation. */
|
|
|
|
|
|
|
|
|
|
/* Called by 'ofproto' after all flows have been flushed, to allow fail-open
|
2011-06-07 16:21:59 -07:00
|
|
|
|
* and standalone mode to re-create their flows.
|
|
|
|
|
*
|
|
|
|
|
* In-band control has more sophisticated code that manages flows itself. */
|
2011-03-29 12:24:28 -07:00
|
|
|
|
void
|
|
|
|
|
connmgr_flushed(struct connmgr *mgr)
|
2013-09-12 20:45:15 -07:00
|
|
|
|
OVS_EXCLUDED(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
|
|
|
|
if (mgr->fail_open) {
|
|
|
|
|
fail_open_flushed(mgr->fail_open);
|
|
|
|
|
}
|
2011-04-08 13:44:38 -07:00
|
|
|
|
|
|
|
|
|
/* If there are no controllers and we're in standalone mode, set up a flow
|
|
|
|
|
* that matches every packet and directs them to OFPP_NORMAL (which goes to
|
|
|
|
|
* us). Otherwise, the switch is in secure mode and we won't pass any
|
|
|
|
|
* traffic until a controller has been defined and it tells us to do so. */
|
|
|
|
|
if (!connmgr_has_controllers(mgr)
|
|
|
|
|
&& mgr->fail_mode == OFPROTO_FAIL_STANDALONE) {
|
2012-07-03 22:17:14 -07:00
|
|
|
|
struct ofpbuf ofpacts;
|
2012-08-07 15:28:18 -07:00
|
|
|
|
struct match match;
|
2011-04-08 13:44:38 -07:00
|
|
|
|
|
ofp-actions: Make all actions a multiple of OFPACT_ALIGNTO bytes.
The functions to put ofpacts into ofpbufs have always padded them to
OFPACT_ALIGNTO boundaries, but the underlying structures weren't
necessarily padded out. That led to difficulties in a few places where
structures were allocated on the stack instead in an ofpbuf, because
functions like ofpact_init_*() would access beyond the end of the actual
structure. This is true, for example, in test_multipath_main() in
tests/test-multipath.c, which allocates a struct ofpact_multipath on the
stack, and in lswitch_handshake() in learning-switch.c, which allocates
a struct ofpact_output on the stack.
It's possible to fix these individual cases, but it's possible that there
are others that haven't been identified. This commit addresses the issue
another way, by padding all of the ofpact structures to a full multiple
of OFPACT_ALIGNTO and adding assertions to ensure that it can't be screwed
up in the future.
This commit removes the OFPACT_*_SIZE enums, because they are now
equivalent to sizeof(struct ofpact_*) in every case.
Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-11-14 16:07:30 -08:00
|
|
|
|
ofpbuf_init(&ofpacts, sizeof(struct ofpact_output));
|
2012-07-03 22:17:14 -07:00
|
|
|
|
ofpact_put_OUTPUT(&ofpacts)->port = OFPP_NORMAL;
|
|
|
|
|
|
2012-08-07 15:28:18 -07:00
|
|
|
|
match_init_catchall(&match);
|
2015-03-02 17:29:44 -08:00
|
|
|
|
ofproto_add_flow(mgr->ofproto, &match, 0, ofpacts.data,
|
|
|
|
|
ofpacts.size);
|
2012-07-03 22:17:14 -07:00
|
|
|
|
|
|
|
|
|
ofpbuf_uninit(&ofpacts);
|
2011-04-08 13:44:38 -07:00
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
2015-01-06 09:27:32 -08:00
|
|
|
|
|
|
|
|
|
/* Returns the number of hidden rules created by the in-band and fail-open
|
|
|
|
|
* implementations in table 0. (Subtracting this count from the number of
|
2015-06-11 15:53:43 -07:00
|
|
|
|
* rules in the table 0 classifier, as maintained in struct oftable, yields
|
2015-01-06 09:27:32 -08:00
|
|
|
|
* the number of flows that OVS should report via OpenFlow for table 0.) */
|
|
|
|
|
int
|
|
|
|
|
connmgr_count_hidden_rules(const struct connmgr *mgr)
|
|
|
|
|
{
|
|
|
|
|
int n_hidden = 0;
|
|
|
|
|
if (mgr->in_band) {
|
|
|
|
|
n_hidden += in_band_count_rules(mgr->in_band);
|
|
|
|
|
}
|
|
|
|
|
if (mgr->fail_open) {
|
|
|
|
|
n_hidden += fail_open_count_rules(mgr->fail_open);
|
|
|
|
|
}
|
|
|
|
|
return n_hidden;
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
|
|
|
|
/* Creates a new ofservice for 'target' in 'mgr'. Returns 0 if successful,
|
2023-09-28 21:44:24 +00:00
|
|
|
|
* otherwise a positive errno value. */
|
2018-10-24 14:23:38 -07:00
|
|
|
|
static void
|
2012-10-26 11:35:52 +09:00
|
|
|
|
ofservice_create(struct connmgr *mgr, const char *target,
|
2018-10-24 14:23:38 -07:00
|
|
|
|
const struct ofproto_controller *c)
|
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2018-10-24 14:23:38 -07:00
|
|
|
|
struct pvconn *pvconn = NULL;
|
|
|
|
|
struct rconn *rconn = NULL;
|
|
|
|
|
if (!vconn_verify_name(target)) {
|
|
|
|
|
char *name = ofconn_make_name(mgr, target);
|
2023-09-28 21:44:24 +00:00
|
|
|
|
rconn = rconn_create(c->probe_interval, c->max_backoff,
|
|
|
|
|
c->dscp, c->allowed_versions);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
rconn_connect(rconn, target, name);
|
|
|
|
|
free(name);
|
|
|
|
|
} else if (!pvconn_verify_name(target)) {
|
|
|
|
|
int error = pvconn_open(target, c->allowed_versions, c->dscp, &pvconn);
|
|
|
|
|
if (error) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
VLOG_WARN_RL(&rl, "%s: unsupported controller \"%s\"",
|
|
|
|
|
mgr->name, target);
|
|
|
|
|
return;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofservice *ofservice = xzalloc(sizeof *ofservice);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
hmap_insert(&mgr->services, &ofservice->hmap_node, hash_string(target, 0));
|
|
|
|
|
ofservice->connmgr = mgr;
|
|
|
|
|
ofservice->target = xstrdup(target);
|
|
|
|
|
ovs_list_init(&ofservice->conns);
|
2018-10-26 15:53:55 -07:00
|
|
|
|
ofservice->type = c->type;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofservice->rconn = rconn;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
ofservice->pvconn = pvconn;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofservice->s = *c;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
VLOG_INFO("%s: added %s controller \"%s\"",
|
|
|
|
|
mgr->name, ofconn_type_to_string(ofservice->type), target);
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofservice_close_all(struct ofservice *ofservice)
|
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2022-03-23 12:56:14 +01:00
|
|
|
|
struct ofconn *ofconn;
|
|
|
|
|
LIST_FOR_EACH_SAFE (ofconn, ofservice_node, &ofservice->conns) {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
ofconn_destroy(ofconn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ofservice_destroy(struct ofservice *ofservice)
|
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
|
|
|
|
{
|
|
|
|
|
if (!ofservice) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofservice_close_all(ofservice);
|
|
|
|
|
|
|
|
|
|
hmap_remove(&ofservice->connmgr->services, &ofservice->hmap_node);
|
|
|
|
|
free(ofservice->target);
|
|
|
|
|
if (ofservice->pvconn) {
|
|
|
|
|
pvconn_close(ofservice->pvconn);
|
|
|
|
|
}
|
|
|
|
|
if (ofservice->rconn) {
|
|
|
|
|
rconn_destroy(ofservice->rconn);
|
|
|
|
|
}
|
2011-03-29 12:24:28 -07:00
|
|
|
|
free(ofservice);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
static void
|
|
|
|
|
ofservice_run(struct ofservice *ofservice)
|
|
|
|
|
{
|
|
|
|
|
if (ofservice->pvconn) {
|
|
|
|
|
struct vconn *vconn;
|
|
|
|
|
int retval = pvconn_accept(ofservice->pvconn, &vconn);
|
|
|
|
|
if (!retval) {
|
|
|
|
|
/* Passing default value for creation of the rconn */
|
|
|
|
|
struct rconn *rconn = rconn_create(
|
|
|
|
|
ofservice->s.probe_interval, ofservice->s.max_backoff,
|
|
|
|
|
ofservice->s.dscp, ofservice->s.allowed_versions);
|
|
|
|
|
char *name = ofconn_make_name(ofservice->connmgr,
|
|
|
|
|
vconn_get_name(vconn));
|
|
|
|
|
rconn_connect_unreliably(rconn, vconn, name);
|
|
|
|
|
free(name);
|
|
|
|
|
|
2018-10-26 15:53:55 -07:00
|
|
|
|
ofconn_create(ofservice, rconn, &ofservice->s);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
} else if (retval != EAGAIN) {
|
|
|
|
|
VLOG_WARN_RL(&rl, "accept failed (%s)", ovs_strerror(retval));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rconn_run(ofservice->rconn);
|
|
|
|
|
|
|
|
|
|
bool connected = rconn_is_connected(ofservice->rconn);
|
|
|
|
|
bool has_ofconn = !ovs_list_is_empty(&ofservice->conns);
|
|
|
|
|
if (connected && !has_ofconn) {
|
2018-10-26 15:53:55 -07:00
|
|
|
|
ofconn_create(ofservice, ofservice->rconn, &ofservice->s);
|
2018-10-24 14:23:38 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ofservice_wait(struct ofservice *ofservice)
|
|
|
|
|
{
|
|
|
|
|
if (ofservice->pvconn) {
|
|
|
|
|
pvconn_wait(ofservice->pvconn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 16:07:55 -04:00
|
|
|
|
static int
|
2011-03-29 12:24:28 -07:00
|
|
|
|
ofservice_reconfigure(struct ofservice *ofservice,
|
2018-10-24 14:23:38 -07:00
|
|
|
|
const struct ofproto_controller *settings)
|
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2011-03-29 12:24:28 -07:00
|
|
|
|
{
|
2020-08-12 16:07:55 -04:00
|
|
|
|
/* If the allowed OpenFlow versions change, a full cleanup is needed
|
|
|
|
|
* for the ofservice and connections. */
|
2018-10-24 14:23:38 -07:00
|
|
|
|
if (ofservice->s.allowed_versions != settings->allowed_versions) {
|
2020-08-12 16:07:55 -04:00
|
|
|
|
return -EINVAL;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofservice->s = *settings;
|
|
|
|
|
|
|
|
|
|
struct ofconn *ofconn;
|
|
|
|
|
LIST_FOR_EACH (ofconn, ofservice_node, &ofservice->conns) {
|
|
|
|
|
ofconn_reconfigure(ofconn, settings);
|
|
|
|
|
}
|
2020-08-12 16:07:55 -04:00
|
|
|
|
|
|
|
|
|
return 0;
|
2011-03-29 12:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Finds and returns the ofservice within 'mgr' that has the given
|
|
|
|
|
* 'target', or a null pointer if none exists. */
|
|
|
|
|
static struct ofservice *
|
|
|
|
|
ofservice_lookup(struct connmgr *mgr, const char *target)
|
|
|
|
|
{
|
|
|
|
|
struct ofservice *ofservice;
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
HMAP_FOR_EACH_WITH_HASH (ofservice, hmap_node, hash_string(target, 0),
|
2011-03-29 12:24:28 -07:00
|
|
|
|
&mgr->services) {
|
2018-10-24 14:23:38 -07:00
|
|
|
|
if (!strcmp(ofservice->target, target)) {
|
2011-03-29 12:24:28 -07:00
|
|
|
|
return ofservice;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|
|
|
|
|
/* Flow monitors (NXST_FLOW_MONITOR). */
|
|
|
|
|
|
|
|
|
|
/* A counter incremented when something significant happens to an OpenFlow
|
|
|
|
|
* rule.
|
|
|
|
|
*
|
|
|
|
|
* - When a rule is added, its 'add_seqno' and 'modify_seqno' are set to
|
|
|
|
|
* the current value (which is then incremented).
|
|
|
|
|
*
|
|
|
|
|
* - When a rule is modified, its 'modify_seqno' is set to the current
|
|
|
|
|
* value (which is then incremented).
|
|
|
|
|
*
|
|
|
|
|
* Thus, by comparing an old value of monitor_seqno against a rule's
|
|
|
|
|
* 'add_seqno', one can tell whether the rule was added before or after the old
|
|
|
|
|
* value was read, and similarly for 'modify_seqno'.
|
|
|
|
|
*
|
|
|
|
|
* 32 bits should normally be sufficient (and would be nice, to save space in
|
|
|
|
|
* each rule) but then we'd have to have some special cases for wraparound.
|
|
|
|
|
*
|
|
|
|
|
* We initialize monitor_seqno to 1 to allow 0 to be used as an invalid
|
|
|
|
|
* value. */
|
|
|
|
|
static uint64_t monitor_seqno = 1;
|
|
|
|
|
|
|
|
|
|
COVERAGE_DEFINE(ofmonitor_pause);
|
|
|
|
|
COVERAGE_DEFINE(ofmonitor_resume);
|
|
|
|
|
|
|
|
|
|
enum ofperr
|
|
|
|
|
ofmonitor_create(const struct ofputil_flow_monitor_request *request,
|
|
|
|
|
struct ofconn *ofconn, struct ofmonitor **monitorp)
|
2013-10-10 23:11:09 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2012-07-12 14:18:05 -07:00
|
|
|
|
{
|
|
|
|
|
*monitorp = NULL;
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofmonitor *m = ofmonitor_lookup(ofconn, request->id);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
if (m) {
|
2014-06-10 19:27:07 +09:00
|
|
|
|
return OFPERR_OFPMOFC_MONITOR_EXISTS;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m = xmalloc(sizeof *m);
|
|
|
|
|
m->ofconn = ofconn;
|
|
|
|
|
hmap_insert(&ofconn->monitors, &m->ofconn_node, hash_int(request->id, 0));
|
|
|
|
|
m->id = request->id;
|
|
|
|
|
m->flags = request->flags;
|
|
|
|
|
m->out_port = request->out_port;
|
2021-12-08 18:05:23 -05:00
|
|
|
|
m->out_group = request->out_group;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
m->table_id = request->table_id;
|
2012-09-04 12:43:53 -07:00
|
|
|
|
minimatch_init(&m->match, &request->match);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|
|
|
|
|
*monitorp = m;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ofmonitor *
|
|
|
|
|
ofmonitor_lookup(struct ofconn *ofconn, uint32_t id)
|
2013-10-10 23:11:09 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2012-07-12 14:18:05 -07:00
|
|
|
|
{
|
|
|
|
|
struct ofmonitor *m;
|
|
|
|
|
|
|
|
|
|
HMAP_FOR_EACH_IN_BUCKET (m, ofconn_node, hash_int(id, 0),
|
|
|
|
|
&ofconn->monitors) {
|
|
|
|
|
if (m->id == id) {
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ofmonitor_destroy(struct ofmonitor *m)
|
2013-10-10 23:11:09 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2012-07-12 14:18:05 -07:00
|
|
|
|
{
|
|
|
|
|
if (m) {
|
2012-12-26 09:42:33 -08:00
|
|
|
|
minimatch_destroy(&m->match);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
hmap_remove(&m->ofconn->monitors, &m->ofconn_node);
|
|
|
|
|
free(m);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ofmonitor_report(struct connmgr *mgr, struct rule *rule,
|
2021-12-08 18:05:23 -05:00
|
|
|
|
enum ofp_flow_update_event event,
|
2012-07-12 14:18:05 -07:00
|
|
|
|
enum ofp_flow_removed_reason reason,
|
2014-06-14 08:33:13 +09:00
|
|
|
|
const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid,
|
|
|
|
|
const struct rule_actions *old_actions)
|
2013-09-12 20:45:15 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2012-07-12 14:18:05 -07:00
|
|
|
|
{
|
connmgr: Check nullptr inside ofmonitor_report().
ovs-vswitchd could crash under these circumstances:
1. When one bridge is being destroyed, ofproto_destroy() is called and
connmgr pointer of its ofproto struct is nullified. This ofproto struct is
deallocated through 'ovsrcu_postpone(ofproto_destroy_defer__, p);'.
2. Before RCU enters quiesce state to actually free this ofproto struct,
revalidator thread calls udpif_revalidator(), which could handle
a learn flow and calls ofproto_flow_mod_learn(), it later calls
ofmonitor_report() and ofproto struct's connmgr pointer is accessed.
The crash stack trace is shown below:
0 ofmonitor_report (mgr=0x0, rule=0x7f..30, event=NXFME_ADDED,
reason=OFPRR_IDLE_TIMEOUT, abbrev_ofconn=0x0, abbrev_xid=0, old_actions=0x0)
at ofproto/connmgr.c:2160
1 add_flow_finish (ofproto=0x55..b0, ofm=<optimized out>, req=0x0)
at ofproto/ofproto.c:5221
2 modify_flows_finish (req=0x0, ofm=0x7f..f0, ofproto=0x55..b0)
at ofproto/ofproto.c:5823
3 ofproto_flow_mod_finish (ofproto=0x55..b0, ofm=0x7f..f0, req=0x0)
at ofproto/ofproto.c:8088
4 ofproto_flow_mod_learn_finish (ofm=0x7f..f0, orig_ofproto=0x0)
at ofproto/ofproto.c:5439
5 ofproto_flow_mod_learn (ofm=0x7f..f0, keep_ref=true, below_limitp=0x0)
at ofproto/ofproto.c:5499
6 xlate_push_stats_entry (entry=0x7f..48, stats=0x7f..10, offloaded=false)
at ofproto/ofproto-dpif-xlate-cache.c:127
7 xlate_push_stats (xcache=<optimized out>, stats=0x7f..10, offloaded=false)
at ofproto/ofproto-dpif-xlate-cache.c:181
8 revalidate_ukey (udpif=0x55..40, ukey=0x7f..60, stats=0x7f..18,
odp_actions=0x7f..50, reval_seq=5655486242,
recircs=0x7f..40, offloaded=false)
at ofproto/ofproto-dpif-upcall.c:2294
9 revalidate at ofproto/ofproto-dpif-upcall.c:2683
10 udpif_revalidator at ofproto/ofproto-dpif-upcall.c:936
11 ovsthread_wrapper at lib/ovs-thread.c:423
12 start_thread () from /usr/lib64/libpthread.so.0
13 clone () from /usr/lib64/libc.so.6
At the time of crash, the involved ofproto was already deallocated:
(gdb) print *ofproto
$1 = ..., name = 0x55d907602820 "nsx-managed", ..., ports = {...,
one = 0x0, mask = 63, n = 0}, ..., connmgr = 0x0, ...
This patch fixes it.
VMware-BZ: #2700626
Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>
Acked-by: William Tu < u9012063@gmail.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2021-02-17 13:09:05 -08:00
|
|
|
|
if (!mgr || rule_is_hidden(rule)) {
|
2014-06-12 14:30:24 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 18:05:23 -05:00
|
|
|
|
enum ofp14_flow_monitor_flags update;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
switch (event) {
|
2021-12-08 18:05:23 -05:00
|
|
|
|
case OFPFME_ADDED:
|
|
|
|
|
update = OFPFMF_ADD;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
rule->add_seqno = rule->modify_seqno = monitor_seqno++;
|
|
|
|
|
break;
|
|
|
|
|
|
2021-12-08 18:05:23 -05:00
|
|
|
|
case OFPFME_REMOVED:
|
|
|
|
|
update = OFPFMF_REMOVED;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
break;
|
|
|
|
|
|
2021-12-08 18:05:23 -05:00
|
|
|
|
case OFPFME_MODIFIED:
|
|
|
|
|
update = OFPFMF_MODIFY;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
rule->modify_seqno = monitor_seqno++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2021-12-08 18:05:23 -05:00
|
|
|
|
case OFPFME_INITIAL:
|
|
|
|
|
case OFPFME_PAUSED:
|
|
|
|
|
case OFPFME_RESUMED:
|
|
|
|
|
case OFPFME_ABBREV:
|
2013-12-17 10:32:12 -08:00
|
|
|
|
OVS_NOT_REACHED();
|
2012-07-12 14:18:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofconn *ofconn;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2012-07-12 14:18:05 -07:00
|
|
|
|
if (ofconn->monitor_paused) {
|
2021-12-08 18:05:23 -05:00
|
|
|
|
/* Only send OFPFME_REMOVED notifications for flows that were added
|
2012-07-12 14:18:05 -07:00
|
|
|
|
* before we paused. */
|
2021-12-08 18:05:23 -05:00
|
|
|
|
if (event != OFPFME_REMOVED
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|| rule->add_seqno > ofconn->monitor_paused) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 18:05:23 -05:00
|
|
|
|
enum ofp14_flow_monitor_flags flags = 0;
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofmonitor *m;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
HMAP_FOR_EACH (m, ofconn_node, &ofconn->monitors) {
|
|
|
|
|
if (m->flags & update
|
|
|
|
|
&& (m->table_id == 0xff || m->table_id == rule->table_id)
|
2014-06-14 08:33:13 +09:00
|
|
|
|
&& (ofproto_rule_has_out_port(rule, m->out_port)
|
|
|
|
|
|| (old_actions
|
|
|
|
|
&& ofpacts_output_to_port(old_actions->ofpacts,
|
|
|
|
|
old_actions->ofpacts_len,
|
|
|
|
|
m->out_port)))
|
2021-12-08 18:05:23 -05:00
|
|
|
|
&& ofproto_rule_has_out_group(rule, m->out_group)
|
2012-07-12 14:18:05 -07:00
|
|
|
|
&& cls_rule_is_loose_match(&rule->cr, &m->match)) {
|
|
|
|
|
flags |= m->flags;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags) {
|
2016-03-25 14:10:22 -07:00
|
|
|
|
if (ovs_list_is_empty(&ofconn->updates)) {
|
2021-12-08 18:05:22 -05:00
|
|
|
|
ofputil_start_flow_update(&ofconn->updates,
|
|
|
|
|
ofconn_get_protocol(ofconn));
|
2012-07-12 14:18:05 -07:00
|
|
|
|
ofconn->sent_abbrev_update = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 18:05:23 -05:00
|
|
|
|
if (flags & OFPFMF_ONLY_OWN || ofconn != abbrev_ofconn
|
2014-06-13 11:40:24 +09:00
|
|
|
|
|| ofconn->monitor_paused) {
|
2012-07-12 14:18:05 -07:00
|
|
|
|
struct ofputil_flow_update fu;
|
|
|
|
|
|
|
|
|
|
fu.event = event;
|
2021-12-08 18:05:23 -05:00
|
|
|
|
fu.reason = event == OFPFME_REMOVED ? reason : 0;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
fu.table_id = rule->table_id;
|
|
|
|
|
fu.cookie = rule->flow_cookie;
|
ofproto: Fix crash on flow monitor request with tun_metadata.
nx_put_match() needs a non-NULL tunnel metadata table, otherwise it will
crash if a flow matches on tunnel metadata.
This wasn't handled in ofputil_append_flow_update(), causing a crash
when the controller sent a flow monitor request.
To fix the problem, this commit changes ofputil_append_flow_update() to
behave like ofputil_append_flow_stats_reply().
Since ofputil_append_flow_update() now needs to temporarily modify the
match, this commits also embeds 'struct match' into 'struct
ofputil_flow_update', to be safer. This is more similar to
'struct ofputil_flow_stats'.
A regression test is added and a comment is updated in ovs-ofctl.c
#0 0x000055699bd82fa0 in memcpy_from_metadata (dst=0x7ffc770930d0, src=0x7ffc77093698, loc=0x18) at ../lib/tun-metadata.c:451
#1 0x000055699bd83c2e in metadata_loc_from_match_read (map=0x0, match=0x7ffc77093410, idx=0, mask=0x7ffc77093658, is_masked=0x7ffc77093287) at ../lib/tun-metadata.c:848
#2 0x000055699bd83d9b in tun_metadata_to_nx_match (b=0x55699d3f0300, oxm=0, match=0x7ffc77093410) at ../lib/tun-metadata.c:871
#3 0x000055699bce523d in nx_put_raw (b=0x55699d3f0300, oxm=0, match=0x7ffc77093410, cookie=0, cookie_mask=0) at ../lib/nx-match.c:1052
#4 0x000055699bce5580 in nx_put_match (b=0x55699d3f0300, match=0x7ffc77093410, cookie=0, cookie_mask=0) at ../lib/nx-match.c:1116
#5 0x000055699bd3926f in ofputil_append_flow_update (update=0x7ffc770940b0, replies=0x7ffc77094e00) at ../lib/ofp-util.c:6805
#6 0x000055699bc4b5a9 in ofproto_compose_flow_refresh_update (rule=0x55699d405b40, flags=(NXFMF_INITIAL | NXFMF_ACTIONS), msgs=0x7ffc77094e00) at ../ofproto/ofproto.c:5915
#7 0x000055699bc4b5f6 in ofmonitor_compose_refresh_updates (rules=0x7ffc77094e10, msgs=0x7ffc77094e00) at ../ofproto/ofproto.c:5929
#8 0x000055699bc4bafc in handle_flow_monitor_request (ofconn=0x55699d404090, oh=0x55699d404220) at ../ofproto/ofproto.c:6082
#9 0x000055699bc4f46d in handle_openflow__ (ofconn=0x55699d404090, msg=0x55699d404910) at ../ofproto/ofproto.c:7912
#10 0x000055699bc4f5df in handle_openflow (ofconn=0x55699d404090, ofp_msg=0x55699d404910) at ../ofproto/ofproto.c:8002
#11 0x000055699bc88154 in ofconn_run (ofconn=0x55699d404090, handle_openflow=0x55699bc4f5bc <handle_openflow>) at ../ofproto/connmgr.c:1427
#12 0x000055699bc85934 in connmgr_run (mgr=0x55699d3adb90, handle_openflow=0x55699bc4f5bc <handle_openflow>) at ../ofproto/connmgr.c:363
#13 0x000055699bc422c9 in ofproto_run (p=0x55699d3c85e0) at ../ofproto/ofproto.c:1798
#14 0x000055699bc31ec6 in bridge_run__ () at ../vswitchd/bridge.c:2881
#15 0x000055699bc320a6 in bridge_run () at ../vswitchd/bridge.c:2938
#16 0x000055699bc3784e in main (argc=10, argv=0x7ffc770952c8) at ../vswitchd/ovs-vswitchd.c:111
Fixes: 8d8ab6c2d574 ("tun-metadata: Manage tunnel TLV mapping table on a
per-bridge basis.")
Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Acked-by: Ben Pfaff <blp@ovn.org>
2016-12-27 19:02:23 -08:00
|
|
|
|
minimatch_expand(&rule->cr.match, &fu.match);
|
2012-09-20 10:35:52 -07:00
|
|
|
|
fu.priority = rule->cr.priority;
|
2013-08-07 13:06:49 -07:00
|
|
|
|
|
2013-09-10 21:18:09 -07:00
|
|
|
|
ovs_mutex_lock(&rule->mutex);
|
2013-08-07 13:06:49 -07:00
|
|
|
|
fu.idle_timeout = rule->idle_timeout;
|
|
|
|
|
fu.hard_timeout = rule->hard_timeout;
|
2013-09-10 21:18:09 -07:00
|
|
|
|
ovs_mutex_unlock(&rule->mutex);
|
2013-08-07 13:06:49 -07:00
|
|
|
|
|
2021-12-08 18:05:23 -05:00
|
|
|
|
if (flags & OFPFMF_INSTRUCTIONS) {
|
2018-10-25 10:34:41 -07:00
|
|
|
|
const struct rule_actions *actions
|
|
|
|
|
= rule_get_actions(rule);
|
2014-03-14 10:47:50 -07:00
|
|
|
|
fu.ofpacts = actions->ofpacts;
|
|
|
|
|
fu.ofpacts_len = actions->ofpacts_len;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
} else {
|
|
|
|
|
fu.ofpacts = NULL;
|
|
|
|
|
fu.ofpacts_len = 0;
|
|
|
|
|
}
|
ofproto: Fix crash on flow monitor request with tun_metadata.
nx_put_match() needs a non-NULL tunnel metadata table, otherwise it will
crash if a flow matches on tunnel metadata.
This wasn't handled in ofputil_append_flow_update(), causing a crash
when the controller sent a flow monitor request.
To fix the problem, this commit changes ofputil_append_flow_update() to
behave like ofputil_append_flow_stats_reply().
Since ofputil_append_flow_update() now needs to temporarily modify the
match, this commits also embeds 'struct match' into 'struct
ofputil_flow_update', to be safer. This is more similar to
'struct ofputil_flow_stats'.
A regression test is added and a comment is updated in ovs-ofctl.c
#0 0x000055699bd82fa0 in memcpy_from_metadata (dst=0x7ffc770930d0, src=0x7ffc77093698, loc=0x18) at ../lib/tun-metadata.c:451
#1 0x000055699bd83c2e in metadata_loc_from_match_read (map=0x0, match=0x7ffc77093410, idx=0, mask=0x7ffc77093658, is_masked=0x7ffc77093287) at ../lib/tun-metadata.c:848
#2 0x000055699bd83d9b in tun_metadata_to_nx_match (b=0x55699d3f0300, oxm=0, match=0x7ffc77093410) at ../lib/tun-metadata.c:871
#3 0x000055699bce523d in nx_put_raw (b=0x55699d3f0300, oxm=0, match=0x7ffc77093410, cookie=0, cookie_mask=0) at ../lib/nx-match.c:1052
#4 0x000055699bce5580 in nx_put_match (b=0x55699d3f0300, match=0x7ffc77093410, cookie=0, cookie_mask=0) at ../lib/nx-match.c:1116
#5 0x000055699bd3926f in ofputil_append_flow_update (update=0x7ffc770940b0, replies=0x7ffc77094e00) at ../lib/ofp-util.c:6805
#6 0x000055699bc4b5a9 in ofproto_compose_flow_refresh_update (rule=0x55699d405b40, flags=(NXFMF_INITIAL | NXFMF_ACTIONS), msgs=0x7ffc77094e00) at ../ofproto/ofproto.c:5915
#7 0x000055699bc4b5f6 in ofmonitor_compose_refresh_updates (rules=0x7ffc77094e10, msgs=0x7ffc77094e00) at ../ofproto/ofproto.c:5929
#8 0x000055699bc4bafc in handle_flow_monitor_request (ofconn=0x55699d404090, oh=0x55699d404220) at ../ofproto/ofproto.c:6082
#9 0x000055699bc4f46d in handle_openflow__ (ofconn=0x55699d404090, msg=0x55699d404910) at ../ofproto/ofproto.c:7912
#10 0x000055699bc4f5df in handle_openflow (ofconn=0x55699d404090, ofp_msg=0x55699d404910) at ../ofproto/ofproto.c:8002
#11 0x000055699bc88154 in ofconn_run (ofconn=0x55699d404090, handle_openflow=0x55699bc4f5bc <handle_openflow>) at ../ofproto/connmgr.c:1427
#12 0x000055699bc85934 in connmgr_run (mgr=0x55699d3adb90, handle_openflow=0x55699bc4f5bc <handle_openflow>) at ../ofproto/connmgr.c:363
#13 0x000055699bc422c9 in ofproto_run (p=0x55699d3c85e0) at ../ofproto/ofproto.c:1798
#14 0x000055699bc31ec6 in bridge_run__ () at ../vswitchd/bridge.c:2881
#15 0x000055699bc320a6 in bridge_run () at ../vswitchd/bridge.c:2938
#16 0x000055699bc3784e in main (argc=10, argv=0x7ffc770952c8) at ../vswitchd/ovs-vswitchd.c:111
Fixes: 8d8ab6c2d574 ("tun-metadata: Manage tunnel TLV mapping table on a
per-bridge basis.")
Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Acked-by: Ben Pfaff <blp@ovn.org>
2016-12-27 19:02:23 -08:00
|
|
|
|
ofputil_append_flow_update(&fu, &ofconn->updates,
|
|
|
|
|
ofproto_get_tun_tab(rule->ofproto));
|
2012-07-12 14:18:05 -07:00
|
|
|
|
} else if (!ofconn->sent_abbrev_update) {
|
|
|
|
|
struct ofputil_flow_update fu;
|
|
|
|
|
|
2021-12-08 18:05:23 -05:00
|
|
|
|
fu.event = OFPFME_ABBREV;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
fu.xid = abbrev_xid;
|
ofproto: Fix crash on flow monitor request with tun_metadata.
nx_put_match() needs a non-NULL tunnel metadata table, otherwise it will
crash if a flow matches on tunnel metadata.
This wasn't handled in ofputil_append_flow_update(), causing a crash
when the controller sent a flow monitor request.
To fix the problem, this commit changes ofputil_append_flow_update() to
behave like ofputil_append_flow_stats_reply().
Since ofputil_append_flow_update() now needs to temporarily modify the
match, this commits also embeds 'struct match' into 'struct
ofputil_flow_update', to be safer. This is more similar to
'struct ofputil_flow_stats'.
A regression test is added and a comment is updated in ovs-ofctl.c
#0 0x000055699bd82fa0 in memcpy_from_metadata (dst=0x7ffc770930d0, src=0x7ffc77093698, loc=0x18) at ../lib/tun-metadata.c:451
#1 0x000055699bd83c2e in metadata_loc_from_match_read (map=0x0, match=0x7ffc77093410, idx=0, mask=0x7ffc77093658, is_masked=0x7ffc77093287) at ../lib/tun-metadata.c:848
#2 0x000055699bd83d9b in tun_metadata_to_nx_match (b=0x55699d3f0300, oxm=0, match=0x7ffc77093410) at ../lib/tun-metadata.c:871
#3 0x000055699bce523d in nx_put_raw (b=0x55699d3f0300, oxm=0, match=0x7ffc77093410, cookie=0, cookie_mask=0) at ../lib/nx-match.c:1052
#4 0x000055699bce5580 in nx_put_match (b=0x55699d3f0300, match=0x7ffc77093410, cookie=0, cookie_mask=0) at ../lib/nx-match.c:1116
#5 0x000055699bd3926f in ofputil_append_flow_update (update=0x7ffc770940b0, replies=0x7ffc77094e00) at ../lib/ofp-util.c:6805
#6 0x000055699bc4b5a9 in ofproto_compose_flow_refresh_update (rule=0x55699d405b40, flags=(NXFMF_INITIAL | NXFMF_ACTIONS), msgs=0x7ffc77094e00) at ../ofproto/ofproto.c:5915
#7 0x000055699bc4b5f6 in ofmonitor_compose_refresh_updates (rules=0x7ffc77094e10, msgs=0x7ffc77094e00) at ../ofproto/ofproto.c:5929
#8 0x000055699bc4bafc in handle_flow_monitor_request (ofconn=0x55699d404090, oh=0x55699d404220) at ../ofproto/ofproto.c:6082
#9 0x000055699bc4f46d in handle_openflow__ (ofconn=0x55699d404090, msg=0x55699d404910) at ../ofproto/ofproto.c:7912
#10 0x000055699bc4f5df in handle_openflow (ofconn=0x55699d404090, ofp_msg=0x55699d404910) at ../ofproto/ofproto.c:8002
#11 0x000055699bc88154 in ofconn_run (ofconn=0x55699d404090, handle_openflow=0x55699bc4f5bc <handle_openflow>) at ../ofproto/connmgr.c:1427
#12 0x000055699bc85934 in connmgr_run (mgr=0x55699d3adb90, handle_openflow=0x55699bc4f5bc <handle_openflow>) at ../ofproto/connmgr.c:363
#13 0x000055699bc422c9 in ofproto_run (p=0x55699d3c85e0) at ../ofproto/ofproto.c:1798
#14 0x000055699bc31ec6 in bridge_run__ () at ../vswitchd/bridge.c:2881
#15 0x000055699bc320a6 in bridge_run () at ../vswitchd/bridge.c:2938
#16 0x000055699bc3784e in main (argc=10, argv=0x7ffc770952c8) at ../vswitchd/ovs-vswitchd.c:111
Fixes: 8d8ab6c2d574 ("tun-metadata: Manage tunnel TLV mapping table on a
per-bridge basis.")
Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Acked-by: Ben Pfaff <blp@ovn.org>
2016-12-27 19:02:23 -08:00
|
|
|
|
ofputil_append_flow_update(&fu, &ofconn->updates,
|
|
|
|
|
ofproto_get_tun_tab(rule->ofproto));
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|
|
|
|
|
ofconn->sent_abbrev_update = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ofmonitor_flush(struct connmgr *mgr)
|
2013-10-10 23:11:09 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2012-07-12 14:18:05 -07:00
|
|
|
|
{
|
|
|
|
|
struct ofconn *ofconn;
|
2021-12-08 18:05:22 -05:00
|
|
|
|
enum ofputil_protocol protocol;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|
connmgr: Check nullptr inside ofmonitor_report().
ovs-vswitchd could crash under these circumstances:
1. When one bridge is being destroyed, ofproto_destroy() is called and
connmgr pointer of its ofproto struct is nullified. This ofproto struct is
deallocated through 'ovsrcu_postpone(ofproto_destroy_defer__, p);'.
2. Before RCU enters quiesce state to actually free this ofproto struct,
revalidator thread calls udpif_revalidator(), which could handle
a learn flow and calls ofproto_flow_mod_learn(), it later calls
ofmonitor_report() and ofproto struct's connmgr pointer is accessed.
The crash stack trace is shown below:
0 ofmonitor_report (mgr=0x0, rule=0x7f..30, event=NXFME_ADDED,
reason=OFPRR_IDLE_TIMEOUT, abbrev_ofconn=0x0, abbrev_xid=0, old_actions=0x0)
at ofproto/connmgr.c:2160
1 add_flow_finish (ofproto=0x55..b0, ofm=<optimized out>, req=0x0)
at ofproto/ofproto.c:5221
2 modify_flows_finish (req=0x0, ofm=0x7f..f0, ofproto=0x55..b0)
at ofproto/ofproto.c:5823
3 ofproto_flow_mod_finish (ofproto=0x55..b0, ofm=0x7f..f0, req=0x0)
at ofproto/ofproto.c:8088
4 ofproto_flow_mod_learn_finish (ofm=0x7f..f0, orig_ofproto=0x0)
at ofproto/ofproto.c:5439
5 ofproto_flow_mod_learn (ofm=0x7f..f0, keep_ref=true, below_limitp=0x0)
at ofproto/ofproto.c:5499
6 xlate_push_stats_entry (entry=0x7f..48, stats=0x7f..10, offloaded=false)
at ofproto/ofproto-dpif-xlate-cache.c:127
7 xlate_push_stats (xcache=<optimized out>, stats=0x7f..10, offloaded=false)
at ofproto/ofproto-dpif-xlate-cache.c:181
8 revalidate_ukey (udpif=0x55..40, ukey=0x7f..60, stats=0x7f..18,
odp_actions=0x7f..50, reval_seq=5655486242,
recircs=0x7f..40, offloaded=false)
at ofproto/ofproto-dpif-upcall.c:2294
9 revalidate at ofproto/ofproto-dpif-upcall.c:2683
10 udpif_revalidator at ofproto/ofproto-dpif-upcall.c:936
11 ovsthread_wrapper at lib/ovs-thread.c:423
12 start_thread () from /usr/lib64/libpthread.so.0
13 clone () from /usr/lib64/libc.so.6
At the time of crash, the involved ofproto was already deallocated:
(gdb) print *ofproto
$1 = ..., name = 0x55d907602820 "nsx-managed", ..., ports = {...,
one = 0x0, mask = 63, n = 0}, ..., connmgr = 0x0, ...
This patch fixes it.
VMware-BZ: #2700626
Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>
Acked-by: William Tu < u9012063@gmail.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2021-02-17 13:09:05 -08:00
|
|
|
|
if (!mgr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2017-09-28 09:27:25 -07:00
|
|
|
|
struct rconn_packet_counter *counter = ofconn->monitor_counter;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|
2017-09-28 09:27:25 -07:00
|
|
|
|
struct ofpbuf *msg;
|
2015-04-06 14:02:28 -07:00
|
|
|
|
LIST_FOR_EACH_POP (msg, list_node, &ofconn->updates) {
|
2017-09-28 09:27:25 -07:00
|
|
|
|
ofconn_send(ofconn, msg, counter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ofconn->monitor_paused
|
|
|
|
|
&& rconn_packet_counter_n_bytes(counter) > 128 * 1024) {
|
|
|
|
|
COVERAGE_INC(ofmonitor_pause);
|
|
|
|
|
ofconn->monitor_paused = monitor_seqno++;
|
2021-12-08 18:05:22 -05:00
|
|
|
|
protocol = ofconn_get_protocol(ofconn);
|
2021-12-08 18:05:23 -05:00
|
|
|
|
struct ofpbuf *pause = ofputil_encode_flow_monitor_pause(
|
|
|
|
|
OFPFME_PAUSED,protocol);
|
2017-09-28 09:27:25 -07:00
|
|
|
|
ofconn_send(ofconn, pause, counter);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ofmonitor_resume(struct ofconn *ofconn)
|
2013-10-10 23:11:09 -07:00
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
2012-07-12 14:18:05 -07:00
|
|
|
|
{
|
2021-12-08 18:05:22 -05:00
|
|
|
|
enum ofputil_protocol protocol;
|
2013-09-11 16:41:32 -07:00
|
|
|
|
struct rule_collection rules;
|
|
|
|
|
rule_collection_init(&rules);
|
2018-10-25 10:34:41 -07:00
|
|
|
|
|
|
|
|
|
struct ofmonitor *m;
|
2012-07-12 14:18:05 -07:00
|
|
|
|
HMAP_FOR_EACH (m, ofconn_node, &ofconn->monitors) {
|
|
|
|
|
ofmonitor_collect_resume_rules(m, ofconn->monitor_paused, &rules);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ovs_list msgs = OVS_LIST_INITIALIZER(&msgs);
|
2021-12-08 18:05:22 -05:00
|
|
|
|
ofmonitor_compose_refresh_updates(&rules, &msgs,
|
|
|
|
|
ofconn_get_protocol(ofconn));
|
2012-07-12 14:18:05 -07:00
|
|
|
|
|
2021-12-08 18:05:22 -05:00
|
|
|
|
protocol = ofconn_get_protocol(ofconn);
|
2021-12-08 18:05:23 -05:00
|
|
|
|
struct ofpbuf *resumed = ofputil_encode_flow_monitor_pause(
|
|
|
|
|
OFPFME_RESUMED, protocol);
|
2016-03-25 14:10:22 -07:00
|
|
|
|
ovs_list_push_back(&msgs, &resumed->list_node);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
ofconn_send_replies(ofconn, &msgs);
|
|
|
|
|
|
|
|
|
|
ofconn->monitor_paused = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 23:11:09 -07:00
|
|
|
|
static bool
|
|
|
|
|
ofmonitor_may_resume(const struct ofconn *ofconn)
|
|
|
|
|
OVS_REQUIRES(ofproto_mutex)
|
|
|
|
|
{
|
|
|
|
|
return (ofconn->monitor_paused != 0
|
|
|
|
|
&& !rconn_packet_counter_n_packets(ofconn->monitor_counter));
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-12 14:18:05 -07:00
|
|
|
|
static void
|
|
|
|
|
ofmonitor_run(struct connmgr *mgr)
|
|
|
|
|
{
|
2013-10-10 23:11:09 -07:00
|
|
|
|
ovs_mutex_lock(&ofproto_mutex);
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofconn *ofconn;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2013-10-10 23:11:09 -07:00
|
|
|
|
if (ofmonitor_may_resume(ofconn)) {
|
2012-07-12 14:18:05 -07:00
|
|
|
|
COVERAGE_INC(ofmonitor_resume);
|
|
|
|
|
ofmonitor_resume(ofconn);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-10 23:11:09 -07:00
|
|
|
|
ovs_mutex_unlock(&ofproto_mutex);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ofmonitor_wait(struct connmgr *mgr)
|
|
|
|
|
{
|
2013-10-10 23:11:09 -07:00
|
|
|
|
ovs_mutex_lock(&ofproto_mutex);
|
2018-10-25 10:34:41 -07:00
|
|
|
|
struct ofconn *ofconn;
|
2018-10-24 14:23:38 -07:00
|
|
|
|
LIST_FOR_EACH (ofconn, connmgr_node, &mgr->conns) {
|
2013-10-10 23:11:09 -07:00
|
|
|
|
if (ofmonitor_may_resume(ofconn)) {
|
2012-07-12 14:18:05 -07:00
|
|
|
|
poll_immediate_wake();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-10 23:11:09 -07:00
|
|
|
|
ovs_mutex_unlock(&ofproto_mutex);
|
2012-07-12 14:18:05 -07:00
|
|
|
|
}
|
2016-01-18 20:12:30 -08:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ofproto_async_msg_free(struct ofproto_async_msg *am)
|
|
|
|
|
{
|
2017-07-30 17:40:32 -07:00
|
|
|
|
free(am->pin.up.base.packet);
|
|
|
|
|
free(am->pin.up.base.userdata);
|
Implement serializing the state of packet traversal in "continuations".
One purpose of OpenFlow packet-in messages is to allow a controller to
interpose on the path of a packet through the flow tables. If, for
example, the controller needs to modify a packet in some way that the
switch doesn't directly support, the controller should be able to
program the switch to send it the packet, then modify the packet and
send it back to the switch to continue through the flow table.
That's the theory. In practice, this doesn't work with any but the
simplest flow tables. Packet-in messages simply don't include enough
context to allow the flow table traversal to continue. For example:
* Via "resubmit" actions, an Open vSwitch packet can have an
effective "call stack", but a packet-in can't describe it, and
so it would be lost.
* A packet-in can't preserve the stack used by NXAST_PUSH and
NXAST_POP actions.
* A packet-in can't preserve the OpenFlow 1.1+ action set.
* A packet-in can't preserve the state of Open vSwitch mirroring
or connection tracking.
This commit introduces a solution called "continuations". A continuation
is the state of a packet's traversal through OpenFlow flow tables. A
"controller" action with the "pause" flag, which is newly implemented in
this commit, generates a continuation and sends it to the OpenFlow
controller in a packet-in asynchronous message (only NXT_PACKET_IN2
supports continuations, so the controller must configure them with
NXT_SET_PACKET_IN_FORMAT). The controller processes the packet-in,
possibly modifying some of its data, and sends it back to the switch with
an NXT_RESUME request, which causes flow table traversal to continue. In
principle, a single packet can be paused and resumed multiple times.
Another way to look at it is:
- "pause" is an extension of the existing OFPAT_CONTROLLER
action. It sends the packet to the controller, with full
pipeline context (some of which is switch implementation
dependent, and may thus vary from switch to switch).
- A continuation is an extension of OFPT_PACKET_IN, allowing for
implementation dependent metadata.
- NXT_RESUME is an extension of OFPT_PACKET_OUT, with the
semantics that the pipeline processing is continued with the
original translation context from where it was left at the time
it was paused.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-02-19 16:10:06 -08:00
|
|
|
|
free(am->pin.up.stack);
|
|
|
|
|
free(am->pin.up.actions);
|
|
|
|
|
free(am->pin.up.action_set);
|
2016-01-18 20:12:30 -08:00
|
|
|
|
free(am);
|
|
|
|
|
}
|