X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fofp-print.c;h=d4f33daa970bf7baa1d1c5ce192099f45994fca2;hb=55eccb868b8f1da858a9f724335b5bb059276497;hp=9d1b3b0c0a5d3052171bbbe8c5a675464bebdcc4;hpb=dc4762edd02693770d392b8f6495deb7e52635bf;p=openvswitch diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 9d1b3b0c..d4f33daa 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010 Nicira Networks. + * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ #include "packets.h" #include "pcap.h" #include "type-props.h" +#include "unaligned.h" #include "util.h" static void ofp_print_port_name(struct ds *string, uint16_t port); @@ -663,6 +664,22 @@ ofp_print_switch_config(struct ds *string, const struct ofp_switch_config *osc) uint16_t flags; flags = ntohs(osc->flags); + + ds_put_cstr(string, " frags="); + switch (flags & OFPC_FRAG_MASK) { + case OFPC_FRAG_NORMAL: + ds_put_cstr(string, "normal"); + flags &= ~OFPC_FRAG_MASK; + break; + case OFPC_FRAG_DROP: + ds_put_cstr(string, "drop"); + flags &= ~OFPC_FRAG_MASK; + break; + case OFPC_FRAG_REASM: + ds_put_cstr(string, "reassemble"); + flags &= ~OFPC_FRAG_MASK; + break; + } if (flags) { ds_put_format(string, " ***unknown flags 0x%04"PRIx16"***", flags); } @@ -733,11 +750,11 @@ ofp_match_to_string(const struct ofp_match *om, int verbosity) if (om->dl_type == htons(ETH_TYPE_IP)) { if (!(w & OFPFW_NW_PROTO)) { skip_proto = true; - if (om->nw_proto == IP_TYPE_ICMP) { + if (om->nw_proto == IPPROTO_ICMP) { ds_put_cstr(&f, "icmp,"); - } else if (om->nw_proto == IP_TYPE_TCP) { + } else if (om->nw_proto == IPPROTO_TCP) { ds_put_cstr(&f, "tcp,"); - } else if (om->nw_proto == IP_TYPE_UDP) { + } else if (om->nw_proto == IPPROTO_UDP) { ds_put_cstr(&f, "udp,"); } else { ds_put_cstr(&f, "ip,"); @@ -784,7 +801,7 @@ ofp_match_to_string(const struct ofp_match *om, int verbosity) } print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity, "%u", om->nw_tos); - if (om->nw_proto == IP_TYPE_ICMP) { + if (om->nw_proto == IPPROTO_ICMP) { print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity, "%d", ntohs(om->icmp_type)); print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity, @@ -912,6 +929,7 @@ ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh) return; } + ds_put_char(string, ' '); cls_rule_format(&fr.rule, string); ds_put_cstr(string, " reason="); @@ -1022,6 +1040,7 @@ ofp_print_ofpst_desc_reply(struct ds *string, const struct ofp_header *oh) { const struct ofp_desc_stats *ods = ofputil_stats_body(oh); + ds_put_char(string, '\n'); ds_put_format(string, "Manufacturer: %.*s\n", (int) sizeof ods->mfr_desc, ods->mfr_desc); ds_put_format(string, "Hardware: %.*s\n", @@ -1055,6 +1074,10 @@ ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh) ofp_print_port_name(string, fsr.out_port); } + /* A flow stats request doesn't include a priority, but cls_rule_format() + * will print one unless it is OFP_DEFAULT_PRIORITY. */ + fsr.match.priority = OFP_DEFAULT_PRIORITY; + ds_put_char(string, ' '); cls_rule_format(&fsr.match, string); } @@ -1102,14 +1125,15 @@ ofp_print_ofpst_flow_reply(struct ds *string, const struct ofp_header *oh, } ds_put_format(string, " cookie=0x%"PRIx64", duration=", - ntohll(fs->cookie)); + ntohll(get_32aligned_be64(&fs->cookie))); ofp_print_duration(string, ntohl(fs->duration_sec), ntohl(fs->duration_nsec)); ds_put_format(string, ", table_id=%"PRIu8", ", fs->table_id); ds_put_format(string, "priority=%"PRIu16", ", ntohs(fs->priority)); ds_put_format(string, "n_packets=%"PRIu64", ", - ntohll(fs->packet_count)); - ds_put_format(string, "n_bytes=%"PRIu64", ", ntohll(fs->byte_count)); + ntohll(get_32aligned_be64(&fs->packet_count))); + ds_put_format(string, "n_bytes=%"PRIu64", ", + ntohll(get_32aligned_be64(&fs->byte_count))); if (fs->idle_timeout != htons(OFP_FLOW_PERMANENT)) { ds_put_format(string, "idle_timeout=%"PRIu16",", ntohs(fs->idle_timeout)); @@ -1205,8 +1229,10 @@ static void ofp_print_ofp_aggregate_stats_reply ( struct ds *string, const struct ofp_aggregate_stats_reply *asr) { - ds_put_format(string, " packet_count=%"PRIu64, ntohll(asr->packet_count)); - ds_put_format(string, " byte_count=%"PRIu64, ntohll(asr->byte_count)); + ds_put_format(string, " packet_count=%"PRIu64, + ntohll(get_32aligned_be64(&asr->packet_count))); + ds_put_format(string, " byte_count=%"PRIu64, + ntohll(get_32aligned_be64(&asr->byte_count))); ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count)); } @@ -1224,10 +1250,12 @@ ofp_print_nxst_aggregate_reply(struct ds *string, } static void print_port_stat(struct ds *string, const char *leader, - uint64_t stat, int more) + const ovs_32aligned_be64 *statp, int more) { + uint64_t stat = ntohll(get_32aligned_be64(statp)); + ds_put_cstr(string, leader); - if (stat != -1) { + if (stat != UINT64_MAX) { ds_put_format(string, "%"PRIu64, stat); } else { ds_put_char(string, '?'); @@ -1243,7 +1271,7 @@ static void ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh) { const struct ofp_port_stats_request *psr = ofputil_stats_body(oh); - ds_put_format(string, "port_no=%"PRIu16, ntohs(psr->port_no)); + ds_put_format(string, " port_no=%"PRIu16, ntohs(psr->port_no)); } static void @@ -1261,20 +1289,20 @@ ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh, ds_put_format(string, " port %2"PRIu16": ", ntohs(ps->port_no)); ds_put_cstr(string, "rx "); - print_port_stat(string, "pkts=", ntohll(ps->rx_packets), 1); - print_port_stat(string, "bytes=", ntohll(ps->rx_bytes), 1); - print_port_stat(string, "drop=", ntohll(ps->rx_dropped), 1); - print_port_stat(string, "errs=", ntohll(ps->rx_errors), 1); - print_port_stat(string, "frame=", ntohll(ps->rx_frame_err), 1); - print_port_stat(string, "over=", ntohll(ps->rx_over_err), 1); - print_port_stat(string, "crc=", ntohll(ps->rx_crc_err), 0); + print_port_stat(string, "pkts=", &ps->rx_packets, 1); + print_port_stat(string, "bytes=", &ps->rx_bytes, 1); + print_port_stat(string, "drop=", &ps->rx_dropped, 1); + print_port_stat(string, "errs=", &ps->rx_errors, 1); + print_port_stat(string, "frame=", &ps->rx_frame_err, 1); + print_port_stat(string, "over=", &ps->rx_over_err, 1); + print_port_stat(string, "crc=", &ps->rx_crc_err, 0); ds_put_cstr(string, " tx "); - print_port_stat(string, "pkts=", ntohll(ps->tx_packets), 1); - print_port_stat(string, "bytes=", ntohll(ps->tx_bytes), 1); - print_port_stat(string, "drop=", ntohll(ps->tx_dropped), 1); - print_port_stat(string, "errs=", ntohll(ps->tx_errors), 1); - print_port_stat(string, "coll=", ntohll(ps->collisions), 0); + print_port_stat(string, "pkts=", &ps->tx_packets, 1); + print_port_stat(string, "bytes=", &ps->tx_bytes, 1); + print_port_stat(string, "drop=", &ps->tx_dropped, 1); + print_port_stat(string, "errs=", &ps->tx_errors, 1); + print_port_stat(string, "coll=", &ps->collisions, 0); } } @@ -1291,8 +1319,7 @@ ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh, for (; n--; ts++) { char name[OFP_MAX_TABLE_NAME_LEN + 1]; - strncpy(name, ts->name, sizeof name); - name[OFP_MAX_TABLE_NAME_LEN] = '\0'; + ovs_strlcpy(name, ts->name, sizeof name); ds_put_format(string, " %d: %-8s: ", ts->table_id, name); ds_put_format(string, "wild=0x%05"PRIx32", ", ntohl(ts->wildcards)); @@ -1300,9 +1327,9 @@ ofp_print_ofpst_table_reply(struct ds *string, const struct ofp_header *oh, ds_put_format(string, "active=%"PRIu32"\n", ntohl(ts->active_count)); ds_put_cstr(string, " "); ds_put_format(string, "lookup=%"PRIu64", ", - ntohll(ts->lookup_count)); + ntohll(get_32aligned_be64(&ts->lookup_count))); ds_put_format(string, "matched=%"PRIu64"\n", - ntohll(ts->matched_count)); + ntohll(get_32aligned_be64(&ts->matched_count))); } } @@ -1346,9 +1373,9 @@ ofp_print_ofpst_queue_reply(struct ds *string, const struct ofp_header *oh, ofp_print_queue_name(string, ntohl(qs->queue_id)); ds_put_cstr(string, ": "); - print_port_stat(string, "bytes=", ntohll(qs->tx_bytes), 1); - print_port_stat(string, "pkts=", ntohll(qs->tx_packets), 1); - print_port_stat(string, "errors=", ntohll(qs->tx_errors), 0); + print_port_stat(string, "bytes=", &qs->tx_bytes, 1); + print_port_stat(string, "pkts=", &qs->tx_packets, 1); + print_port_stat(string, "errors=", &qs->tx_errors, 0); } } @@ -1401,8 +1428,8 @@ ofp_print_nxt_status_message(struct ds *string, const struct ofp_header *oh) struct ofpbuf b; ofpbuf_use_const(&b, oh, ntohs(oh->length)); - ofpbuf_pull(&b, sizeof *oh); - ds_put_char(string, '"'); + ofpbuf_pull(&b, sizeof(struct nicira_header)); + ds_put_cstr(string, " \""); ds_put_printable(string, b.data, b.size); ds_put_char(string, '"'); }