From 765899376740486ca111c62a851b6120864f5698 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 8 Sep 2011 11:17:54 -0700 Subject: [PATCH] ofproto: Consistently log OpenFlow error replies. Until now, logging of OpenFlow error replies sent to controllers has been haphazard. This commit logs them centrally, ensuring that every OpenFlow error sent to a controller is logged. At the same time, we can eliminate the individual log messages that a few OpenFlow errors triggered. --- ofproto/connmgr.c | 24 +++++++++++++++++++++++- ofproto/ofproto.c | 24 +++++------------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 2d0b8c5d..6432ba66 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -828,8 +828,30 @@ void ofconn_send_error(const struct ofconn *ofconn, const struct ofp_header *request, int error) { - struct ofpbuf *msg = ofputil_encode_error_msg(error, request); + struct ofpbuf *msg; + + msg = ofputil_encode_error_msg(error, request); if (msg) { + static struct vlog_rate_limit err_rl = VLOG_RATE_LIMIT_INIT(10, 10); + + if (!VLOG_DROP_INFO(&err_rl)) { + const struct ofputil_msg_type *type; + const char *type_name; + size_t request_len; + char *error_s; + + request_len = ntohs(request->length); + type_name = (!ofputil_decode_msg_type_partial(request, + MIN(64, request_len), + &type) + ? ofputil_msg_type_name(type) + : "invalid"); + + error_s = ofputil_error_to_string(error); + VLOG_INFO("%s: sending %s error reply to %s message", + rconn_get_name(ofconn->rconn), error_s, type_name); + free(error_s); + } ofconn_send_reply(ofconn, msg); } } diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 50c52983..2d41704f 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1707,18 +1707,12 @@ handle_set_config(struct ofconn *ofconn, const struct ofp_switch_config *osc) /* Checks whether 'ofconn' is a slave controller. If so, returns an OpenFlow * error message code (composed with ofp_mkerr()) for the caller to propagate - * upward. Otherwise, returns 0. - * - * The log message mentions 'msg_type'. */ + * upward. Otherwise, returns 0. */ static int -reject_slave_controller(struct ofconn *ofconn, const char *msg_type) +reject_slave_controller(const struct ofconn *ofconn) { if (ofconn_get_type(ofconn) == OFCONN_PRIMARY && ofconn_get_role(ofconn) == NX_ROLE_SLAVE) { - static struct vlog_rate_limit perm_rl = VLOG_RATE_LIMIT_INIT(1, 5); - VLOG_WARN_RL(&perm_rl, "rejecting %s message from slave controller", - msg_type); - return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_EPERM); } else { return 0; @@ -1739,7 +1733,7 @@ handle_packet_out(struct ofconn *ofconn, const struct ofp_header *oh) COVERAGE_INC(ofproto_packet_out); - error = reject_slave_controller(ofconn, "OFPT_PACKET_OUT"); + error = reject_slave_controller(ofconn); if (error) { return error; } @@ -1807,7 +1801,7 @@ handle_port_mod(struct ofconn *ofconn, const struct ofp_header *oh) struct ofport *port; int error; - error = reject_slave_controller(ofconn, "OFPT_PORT_MOD"); + error = reject_slave_controller(ofconn); if (error) { return error; } @@ -2621,7 +2615,7 @@ handle_flow_mod(struct ofconn *ofconn, const struct ofp_header *oh) struct ofputil_flow_mod fm; int error; - error = reject_slave_controller(ofconn, "flow_mod"); + error = reject_slave_controller(ofconn); if (error) { return error; } @@ -2687,15 +2681,12 @@ handle_role_request(struct ofconn *ofconn, const struct ofp_header *oh) uint32_t role; if (ofconn_get_type(ofconn) != OFCONN_PRIMARY) { - VLOG_WARN_RL(&rl, "ignoring role request on service connection"); return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_EPERM); } role = ntohl(nrr->role); if (role != NX_ROLE_OTHER && role != NX_ROLE_MASTER && role != NX_ROLE_SLAVE) { - VLOG_WARN_RL(&rl, "received request for unknown role %"PRIu32, role); - /* There's no good error code for this. */ return ofp_mkerr(OFPET_BAD_REQUEST, -1); } @@ -2860,11 +2851,6 @@ handle_openflow__(struct ofconn *ofconn, const struct ofpbuf *msg) case OFPUTIL_NXST_FLOW_REPLY: case OFPUTIL_NXST_AGGREGATE_REPLY: default: - if (VLOG_IS_WARN_ENABLED()) { - char *s = ofp_to_string(oh, ntohs(oh->length), 2); - VLOG_DBG_RL(&rl, "OpenFlow message ignored: %s", s); - free(s); - } if (oh->type == OFPT_STATS_REQUEST || oh->type == OFPT_STATS_REPLY) { return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_STAT); } else { -- 2.30.2