/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "openflow/openflow.h"
#include "openflow/nicira-ext.h"
#include "packets.h"
-#include "pcap.h"
#include "type-props.h"
#include "unaligned.h"
#include "util.h"
struct flow flow;
ofpbuf_use_const(&buf, data, len);
- flow_extract(&buf, 0, 0, NULL, 0, &flow);
+ flow_extract(&buf, 0, 0, NULL, NULL, &flow);
flow_format(&ds, &flow);
if (buf.l7) {
ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
int verbosity)
{
+ char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
struct ofputil_packet_in pin;
int error;
int i;
ds_put_format(string, " tun_id=0x%"PRIx64, ntohll(pin.fmd.tun_id));
}
+ if (pin.fmd.tun_src != htonl(0)) {
+ ds_put_format(string, " tun_src="IP_FMT, IP_ARGS(pin.fmd.tun_src));
+ }
+
+ if (pin.fmd.tun_dst != htonl(0)) {
+ ds_put_format(string, " tun_dst="IP_FMT, IP_ARGS(pin.fmd.tun_dst));
+ }
+
if (pin.fmd.metadata != htonll(0)) {
ds_put_format(string, " metadata=0x%"PRIx64, ntohll(pin.fmd.metadata));
}
}
ds_put_format(string, " (via %s)",
- ofputil_packet_in_reason_to_string(pin.reason));
+ ofputil_packet_in_reason_to_string(pin.reason, reasonbuf,
+ sizeof reasonbuf));
ds_put_format(string, " data_len=%zu", pin.packet_len);
if (pin.buffer_id == UINT32_MAX) {
ds_put_cstr(string, packet);
free(packet);
}
+ if (verbosity > 2) {
+ ds_put_hex_dump(string, pin.packet, pin.packet_len, 0, false);
+ }
}
static void
ds_put_cstr(string, packet);
free(packet);
}
+ if (verbosity > 2) {
+ ds_put_hex_dump(string, po.packet, po.packet_len, 0, false);
+ }
} else {
ds_put_format(string, " buffer=0x%08"PRIx32, po.buffer_id);
}
- ds_put_char(string, '\n');
ofpbuf_uninit(&ofpacts);
}
{
const struct ofputil_phy_port *a = a_;
const struct ofputil_phy_port *b = b_;
- uint16_t ap = a->port_no;
- uint16_t bp = b->port_no;
+ uint16_t ap = ofp_to_u16(a->port_no);
+ uint16_t bp = ofp_to_u16(b->port_no);
return ap < bp ? -1 : ap > bp;
}
static void
print_wild_port(struct ds *string, const char *leader, int is_wild,
- int verbosity, uint16_t port)
+ int verbosity, ofp_port_t port)
{
if (is_wild && verbosity < 2) {
return;
}
}
print_wild_port(&f, "in_port=", w & OFPFW10_IN_PORT, verbosity,
- ntohs(om->in_port));
+ u16_to_ofp(ntohs(om->in_port)));
print_wild(&f, "dl_vlan=", w & OFPFW10_DL_VLAN, verbosity,
"%d", ntohs(om->dl_vlan));
print_wild(&f, "dl_vlan_pcp=", w & OFPFW10_DL_VLAN_PCP, verbosity,
ds_put_char(string, 's');
}
+/* Returns a string form of 'reason'. The return value is either a statically
+ * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
+ * 'bufsize' should be at least OFP_FLOW_REMOVED_REASON_BUFSIZE. */
+#define OFP_FLOW_REMOVED_REASON_BUFSIZE (INT_STRLEN(int) + 1)
static const char *
-ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason)
+ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason,
+ char *reasonbuf, size_t bufsize)
{
- static char s[32];
-
switch (reason) {
case OFPRR_IDLE_TIMEOUT:
return "idle";
case OFPRR_EVICTION:
return "eviction";
default:
- sprintf(s, "%d", (int) reason);
- return s;
+ snprintf(reasonbuf, bufsize, "%d", (int) reason);
+ return reasonbuf;
}
}
static void
ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
{
+ char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
struct ofputil_flow_removed fr;
enum ofperr error;
match_format(&fr.match, string, fr.priority);
ds_put_format(string, " reason=%s",
- ofp_flow_removed_reason_to_string(fr.reason));
+ ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
+ sizeof reasonbuf));
if (fr.table_id != 255) {
ds_put_format(string, " table_id=%"PRIu8, fr.table_id);
static void
ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
{
- uint16_t ofp10_port;
+ ofp_port_t ofp10_port;
enum ofperr error;
error = ofputil_decode_port_stats_request(oh, &ofp10_port);
}
ds_put_cstr(string, " port ");
- if (ps.port_no < 10) {
+ if (ofp_to_u16(ps.port_no) < 10) {
ds_put_char(string, ' ');
}
ofputil_format_port(ps.port_no, string);
print_port_stat(string, "drop=", ps.stats.tx_dropped, 1);
print_port_stat(string, "errs=", ps.stats.tx_errors, 1);
print_port_stat(string, "coll=", ps.stats.collisions, 0);
+
+ if (ps.duration_sec != UINT32_MAX) {
+ ds_put_cstr(string, " duration=");
+ ofp_print_duration(string, ps.duration_sec, ps.duration_nsec);
+ ds_put_char(string, '\n');
+ }
}
}
}
ds_put_cstr(string, " role=");
- if (rr.request_current_role_only) {
- ds_put_cstr(string, "nochange");
- return;
- }
switch (rr.role) {
- case NX_ROLE_OTHER:
+ case OFPCR12_ROLE_NOCHANGE:
+ ds_put_cstr(string, "nochange");
+ break;
+ case OFPCR12_ROLE_EQUAL:
ds_put_cstr(string, "equal"); /* OF 1.2 wording */
break;
- case NX_ROLE_MASTER:
+ case OFPCR12_ROLE_MASTER:
ds_put_cstr(string, "master");
break;
- case NX_ROLE_SLAVE:
+ case OFPCR12_ROLE_SLAVE:
ds_put_cstr(string, "slave");
break;
default:
}
}
+/* Returns a string form of 'reason'. The return value is either a statically
+ * allocated constant string or the 'bufsize'-byte buffer 'reasonbuf'.
+ * 'bufsize' should be at least OFP_PORT_REASON_BUFSIZE. */
+#define OFP_PORT_REASON_BUFSIZE (INT_STRLEN(int) + 1)
static const char *
-ofp_port_reason_to_string(enum ofp_port_reason reason)
+ofp_port_reason_to_string(enum ofp_port_reason reason,
+ char *reasonbuf, size_t bufsize)
{
- static char s[32];
-
switch (reason) {
case OFPPR_ADD:
return "add";
return "modify";
default:
- sprintf(s, "%d", (int) reason);
- return s;
+ snprintf(reasonbuf, bufsize, "%d", (int) reason);
+ return reasonbuf;
}
}
ds_put_cstr(string, " PACKET_IN:");
for (j = 0; j < 32; j++) {
if (nac->packet_in_mask[i] & htonl(1u << j)) {
- ds_put_format(string, " %s",
- ofputil_packet_in_reason_to_string(j));
+ char reasonbuf[OFPUTIL_PACKET_IN_REASON_BUFSIZE];
+ const char *reason;
+
+ reason = ofputil_packet_in_reason_to_string(j, reasonbuf,
+ sizeof reasonbuf);
+ ds_put_format(string, " %s", reason);
}
}
if (!nac->packet_in_mask[i]) {
ds_put_cstr(string, " PORT_STATUS:");
for (j = 0; j < 32; j++) {
if (nac->port_status_mask[i] & htonl(1u << j)) {
- ds_put_format(string, " %s", ofp_port_reason_to_string(j));
+ char reasonbuf[OFP_PORT_REASON_BUFSIZE];
+ const char *reason;
+
+ reason = ofp_port_reason_to_string(j, reasonbuf,
+ sizeof reasonbuf);
+ ds_put_format(string, " %s", reason);
}
}
if (!nac->port_status_mask[i]) {
ds_put_cstr(string, " FLOW_REMOVED:");
for (j = 0; j < 32; j++) {
if (nac->flow_removed_mask[i] & htonl(1u << j)) {
- ds_put_format(string, " %s",
- ofp_flow_removed_reason_to_string(j));
+ char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
+ const char *reason;
+
+ reason = ofp_flow_removed_reason_to_string(j, reasonbuf,
+ sizeof reasonbuf);
+ ds_put_format(string, " %s", reason);
}
}
if (!nac->flow_removed_mask[i]) {
ofpbuf_use_const(&b, oh, ntohs(oh->length));
ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
for (;;) {
+ char reasonbuf[OFP_FLOW_REMOVED_REASON_BUFSIZE];
struct ofputil_flow_update update;
struct match match;
int retval;
case NXFME_DELETED:
ds_put_format(string, "DELETED reason=%s",
- ofp_flow_removed_reason_to_string(update.reason));
+ ofp_flow_removed_reason_to_string(update.reason,
+ reasonbuf,
+ sizeof reasonbuf));
break;
case NXFME_MODIFIED: