X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ofproto%2Fofproto.c;h=1a653ec4113bf46fd04675747c486ad40c6c5452;hb=ee402caec46c116a862b716cb4851ff5be371c9f;hp=0a3534d0134160db1456ec4f9a296b91b1df0236;hpb=0254ae23d4a3ca6d9287ac0b6bd07a17a6dc448d;p=openvswitch diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 0a3534d0..1a653ec4 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -187,10 +187,10 @@ struct ofproto { /* Settings. */ uint64_t datapath_id; /* Datapath ID. */ uint64_t fallback_dpid; /* Datapath ID if no better choice found. */ - char *manufacturer; /* Manufacturer. */ - char *hardware; /* Hardware. */ - char *software; /* Software version. */ - char *serial; /* Serial number. */ + char *mfr_desc; /* Manufacturer. */ + char *hw_desc; /* Hardware. */ + char *sw_desc; /* Software version. */ + char *serial_desc; /* Serial number. */ char *dp_desc; /* Datapath description. */ /* Datapath. */ @@ -299,11 +299,11 @@ ofproto_create(const char *datapath, const char *datapath_type, p = xzalloc(sizeof *p); p->fallback_dpid = pick_fallback_dpid(); p->datapath_id = p->fallback_dpid; - p->manufacturer = xstrdup("Nicira Networks, Inc."); - p->hardware = xstrdup("Reference Implementation"); - p->software = xstrdup(VERSION BUILDNR); - p->serial = xstrdup("None"); - p->dp_desc = xstrdup("None"); + p->mfr_desc = xstrdup(DEFAULT_MFR_DESC); + p->hw_desc = xstrdup(DEFAULT_HW_DESC); + p->sw_desc = xstrdup(DEFAULT_SW_DESC); + p->serial_desc = xstrdup(DEFAULT_SERIAL_DESC); + p->dp_desc = xstrdup(DEFAULT_DP_DESC); /* Initialize datapath. */ p->dpif = dpif; @@ -390,27 +390,50 @@ ofproto_set_max_backoff(struct ofproto *p, int max_backoff) void ofproto_set_desc(struct ofproto *p, - const char *manufacturer, const char *hardware, - const char *software, const char *serial, + const char *mfr_desc, const char *hw_desc, + const char *sw_desc, const char *serial_desc, const char *dp_desc) { - if (manufacturer) { - free(p->manufacturer); - p->manufacturer = xstrdup(manufacturer); - } - if (hardware) { - free(p->hardware); - p->hardware = xstrdup(hardware); + struct ofp_desc_stats *ods; + + if (mfr_desc) { + if (strlen(mfr_desc) >= sizeof ods->mfr_desc) { + VLOG_WARN("truncating mfr_desc, must be less than %zu characters", + sizeof ods->mfr_desc); + } + free(p->mfr_desc); + p->mfr_desc = xstrdup(mfr_desc); } - if (software) { - free(p->software); - p->software = xstrdup(software); + if (hw_desc) { + if (strlen(hw_desc) >= sizeof ods->hw_desc) { + VLOG_WARN("truncating hw_desc, must be less than %zu characters", + sizeof ods->hw_desc); + } + free(p->hw_desc); + p->hw_desc = xstrdup(hw_desc); } - if (serial) { - free(p->serial); - p->serial = xstrdup(serial); + if (sw_desc) { + if (strlen(sw_desc) >= sizeof ods->sw_desc) { + VLOG_WARN("truncating sw_desc, must be less than %zu characters", + sizeof ods->sw_desc); + } + free(p->sw_desc); + p->sw_desc = xstrdup(sw_desc); + } + if (serial_desc) { + if (strlen(serial_desc) >= sizeof ods->serial_num) { + VLOG_WARN("truncating serial_desc, must be less than %zu " + "characters", + sizeof ods->serial_num); + } + free(p->serial_desc); + p->serial_desc = xstrdup(serial_desc); } if (dp_desc) { + if (strlen(dp_desc) >= sizeof ods->dp_desc) { + VLOG_WARN("truncating dp_desc, must be less than %zu characters", + sizeof ods->dp_desc); + } free(p->dp_desc); p->dp_desc = xstrdup(dp_desc); } @@ -731,6 +754,14 @@ ofproto_destroy(struct ofproto *p) mac_learning_destroy(p->ml); + free(p->mfr_desc); + free(p->hw_desc); + free(p->sw_desc); + free(p->serial_desc); + free(p->dp_desc); + + port_array_destroy(&p->ports); + free(p); } @@ -777,8 +808,8 @@ ofproto_run1(struct ofproto *p) /* Someone destroyed the datapath behind our back. The caller * better destroy us and give up, because we're just going to * spin from here on out. */ - static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); - VLOG_ERR_RL(&rl, "%s: datapath was destroyed externally", + static struct vlog_rate_limit rl2 = VLOG_RATE_LIMIT_INIT(1, 5); + VLOG_ERR_RL(&rl2, "%s: datapath was destroyed externally", dpif_name(p->dpif)); return ENODEV; } @@ -2182,6 +2213,7 @@ do_xlate_actions(const union ofp_action *in, size_t n_in, case OFPAT_SET_NW_DST: oa = odp_actions_add(ctx->out, ODPAT_SET_NW_DST); oa->nw_addr.nw_addr = ia->nw_addr.nw_addr; + break; case OFPAT_SET_NW_TOS: oa = odp_actions_add(ctx->out, ODPAT_SET_NW_TOS); @@ -2391,11 +2423,12 @@ handle_desc_stats_request(struct ofproto *p, struct ofconn *ofconn, msg = start_stats_reply(request, sizeof *ods); ods = append_stats_reply(sizeof *ods, ofconn, &msg); - strncpy(ods->mfr_desc, p->manufacturer, sizeof ods->mfr_desc); - strncpy(ods->hw_desc, p->hardware, sizeof ods->hw_desc); - strncpy(ods->sw_desc, p->software, sizeof ods->sw_desc); - strncpy(ods->serial_num, p->serial, sizeof ods->serial_num); - strncpy(ods->dp_desc, p->dp_desc, sizeof ods->dp_desc); + memset(ods, 0, sizeof *ods); + ovs_strlcpy(ods->mfr_desc, p->mfr_desc, sizeof ods->mfr_desc); + ovs_strlcpy(ods->hw_desc, p->hw_desc, sizeof ods->hw_desc); + ovs_strlcpy(ods->sw_desc, p->sw_desc, sizeof ods->sw_desc); + ovs_strlcpy(ods->serial_num, p->serial_desc, sizeof ods->serial_num); + ovs_strlcpy(ods->dp_desc, p->dp_desc, sizeof ods->dp_desc); queue_tx(msg, ofconn, ofconn->reply_counter); return 0; @@ -2526,6 +2559,9 @@ struct flow_stats_cbdata { struct ofpbuf *msg; }; +/* Obtains statistic counters for 'rule' within 'p' and stores them into + * '*packet_countp' and '*byte_countp'. If 'rule' is a wildcarded rule, the + * returned statistic include statistics for all of 'rule''s subrules. */ static void query_stats(struct ofproto *p, struct rule *rule, uint64_t *packet_countp, uint64_t *byte_countp) @@ -2535,9 +2571,19 @@ query_stats(struct ofproto *p, struct rule *rule, struct odp_flow *odp_flows; size_t n_odp_flows; + /* Start from historical data for 'rule' itself that are no longer tracked + * by the datapath. This counts, for example, subrules that have + * expired. */ packet_count = rule->packet_count; byte_count = rule->byte_count; + /* Prepare to ask the datapath for statistics on 'rule', or if it is + * wildcarded then on all of its subrules. + * + * Also, add any statistics that are not tracked by the datapath for each + * subrule. This includes, for example, statistics for packets that were + * executed "by hand" by ofproto via dpif_execute() but must be accounted + * to a flow. */ n_odp_flows = rule->cr.wc.wildcards ? list_size(&rule->list) : 1; odp_flows = xzalloc(n_odp_flows * sizeof *odp_flows); if (rule->cr.wc.wildcards) { @@ -2551,8 +2597,7 @@ query_stats(struct ofproto *p, struct rule *rule, odp_flows[0].key = rule->cr.flow; } - packet_count = rule->packet_count; - byte_count = rule->byte_count; + /* Fetch up-to-date statistics from the datapath and add them in. */ if (!dpif_flow_get_multiple(p->dpif, odp_flows, n_odp_flows)) { size_t i; for (i = 0; i < n_odp_flows; i++) { @@ -2563,6 +2608,7 @@ query_stats(struct ofproto *p, struct rule *rule, } free(odp_flows); + /* Return the stats to the caller. */ *packet_countp = packet_count; *byte_countp = byte_count; }