" dump-ports SWITCH print port statistics\n"
" dump-flows SWITCH print all flow entries\n"
" dump-flows SWITCH FLOW print matching FLOWs\n"
+ " dump-aggregate SWITCH print aggregate flow statistics\n"
+ " dump-aggregate SWITCH FLOW print aggregate stats for FLOWs\n"
" add-flows SWITCH FILE add flows from FILE\n"
+ " del-flows SWITCH FLOW delete matching FLOWs\n"
"where each SWITCH is an active OpenFlow connection method.\n",
program_name, program_name);
vconn_usage(true, false);
printf("\nOptions:\n"
+ " -v, --verbose=MODULE:FACILITY:LEVEL configure logging levels\n"
" -v, --verbose set maximum verbosity level\n"
" -h, --help display this help message\n"
" -V, --version display version information\n");
if (retval == EOF) {
fputs(": unexpected end of file\n", stderr);
} else {
- vfprintf(stderr, ": %s\n", strerror(retval));
+ fprintf(stderr, ": %s\n", strerror(retval));
}
exit(EXIT_FAILURE);
static void do_monitor(int argc UNUSED, char *argv[])
{
struct dpif dp;
- open_nl_vconn(argv[1], false, &dp);
+ open_nl_vconn(argv[1], true, &dp);
for (;;) {
struct buffer *b;
run(dpif_recv_openflow(&dp, &b, true), "dpif_recv_openflow");
return oh;
}
+static void *
+alloc_stats_request(size_t body_len, uint16_t type, struct buffer **bufferp)
+{
+ struct ofp_stats_request *rq;
+ rq = alloc_openflow_buffer((offsetof(struct ofp_stats_request, body)
+ + body_len), OFPT_STATS_REQUEST, bufferp);
+ rq->type = htons(type);
+ rq->flags = htons(0);
+ return rq->body;
+}
+
static void
send_openflow_buffer(struct vconn *vconn, struct buffer *buffer)
{
}
static void
-dump_transaction(const char *vconn_name, uint8_t request_type)
+dump_transaction(const char *vconn_name, struct buffer *request)
{
struct vconn *vconn;
- struct buffer *request, *reply;
+ struct buffer *reply;
run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
- alloc_openflow_buffer(sizeof(struct ofp_header), request_type, &request);
reply = transact_openflow(vconn, request);
ofp_print(stdout, reply->data, reply->size, 1);
vconn_close(vconn);
}
+static void
+dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
+{
+ struct buffer *request;
+ alloc_openflow_buffer(sizeof(struct ofp_header), request_type, &request);
+ dump_transaction(vconn_name, request);
+}
+
+static void
+dump_stats_transaction(const char *vconn_name, struct buffer *request)
+{
+ uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
+ struct vconn *vconn;
+ bool done = false;
+
+ run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
+ send_openflow_buffer(vconn, request);
+ while (!done) {
+ uint32_t recv_xid;
+ struct buffer *reply;
+
+ run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
+ recv_xid = ((struct ofp_header *) reply->data)->xid;
+ if (send_xid == recv_xid) {
+ struct ofp_stats_reply *osr;
+
+ ofp_print(stdout, reply->data, reply->size, 1);
+
+ osr = buffer_at(reply, 0, sizeof *osr);
+ done = !osr || !(ntohs(osr->flags) & OFPSF_REPLY_MORE);
+ } else {
+ VLOG_DBG("received reply with xid %08"PRIx32" "
+ "!= expected %08"PRIx32, recv_xid, send_xid);
+ }
+ buffer_delete(reply);
+ }
+ vconn_close(vconn);
+}
+
+static void
+dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
+{
+ struct buffer *request;
+ alloc_stats_request(0, stats_type, &request);
+ dump_stats_transaction(vconn_name, request);
+}
+
static void
do_show(int argc UNUSED, char *argv[])
{
- dump_transaction(argv[1], OFPT_FEATURES_REQUEST);
+ dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
+ dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
}
static void
do_dump_tables(int argc, char *argv[])
{
- dump_transaction(argv[1], OFPT_TABLE_STAT_REQUEST);
+ dump_trivial_stats_transaction(argv[1], OFPST_TABLE);
}
{
uint16_t port;
- if (!strcasecmp(str, "flood")) {
+ if (!strcasecmp(str, "normal")) {
+ port = OFPP_NORMAL;
+ } else if (!strcasecmp(str, "flood")) {
port = OFPP_FLOOD;
+ } else if (!strcasecmp(str, "all")) {
+ port = OFPP_ALL;
} else if (!strcasecmp(str, "controller")) {
port = OFPP_CONTROLLER;
+ } else if (!strcasecmp(str, "local")) {
+ port = OFPP_LOCAL;
} else {
port = str_to_int(str);
}
static void
str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action,
- uint16_t *table_idx)
+ uint8_t *table_idx, uint16_t *priority)
{
struct field {
const char *name;
bool got_action = false;
if (table_idx) {
- *table_idx = htons(0xffff);
+ *table_idx = 0xff;
+ }
+ if (priority) {
+ *priority = OFP_DEFAULT_PRIORITY;
}
memset(match, 0, sizeof *match);
wildcards = OFPFW_ALL;
- for (name = strtok(string, "="), value = strtok(NULL, " \t\n");
+ for (name = strtok(string, "="), value = strtok(NULL, ", \t\r\n");
name && value;
- name = strtok(NULL, "="), value = strtok(NULL, " \t\n"))
+ name = strtok(NULL, "="), value = strtok(NULL, ", \t\r\n"))
{
const struct field *f;
void *data;
}
if (table_idx && !strcmp(name, "table")) {
- *table_idx = htons(atoi(value));
+ *table_idx = atoi(value);
+ continue;
+ }
+
+ if (priority && !strcmp(name, "priority")) {
+ *priority = atoi(value);
continue;
}
found:
data = (char *) match + f->offset;
- if (!strcmp(value, "*")) {
+ if (!strcmp(value, "*") || !strcmp(value, "ANY")) {
wildcards |= f->wildcard;
} else {
wildcards &= ~f->wildcard;
static void do_dump_flows(int argc, char *argv[])
{
- struct vconn *vconn;
- struct buffer *request, *reply;
- struct ofp_flow_stat_request *fsr;
+ struct ofp_flow_stats_request *req;
+ struct buffer *request;
- run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
- fsr = alloc_openflow_buffer(sizeof *fsr, OFPT_FLOW_STAT_REQUEST, &request);
- str_to_flow(argc > 2 ? argv[2] : "", &fsr->match, NULL, &fsr->table_id);
- fsr->type = OFPFS_INDIV;
- fsr->pad = 0;
- reply = transact_openflow(vconn, request);
- ofp_print(stdout, reply->data, reply->size, 1);
- vconn_close(vconn);
+ req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
+ str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id,
+ NULL);
+ memset(req->pad, 0, sizeof req->pad);
+
+ dump_stats_transaction(argv[1], request);
+}
+
+static void do_dump_aggregate(int argc, char *argv[])
+{
+ struct ofp_aggregate_stats_request *req;
+ struct buffer *request;
+
+ req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
+ str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id,
+ NULL);
+ memset(req->pad, 0, sizeof req->pad);
+
+ dump_stats_transaction(argv[1], request);
}
static void do_add_flows(int argc, char *argv[])
{
struct vconn *vconn;
- char vconn_name[16];
FILE *file;
char line[1024];
fatal(errno, "%s: open", argv[2]);
}
- run(vconn_open_block(vconn_name, &vconn), "connecting to %s", argv[1]);
+ run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
while (fgets(line, sizeof line, file)) {
struct buffer *buffer;
struct ofp_flow_mod *ofm;
+ uint16_t priority;
size_t size;
char *comment;
/* Parse and send. */
size = sizeof *ofm + sizeof ofm->actions[0];
ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
+ str_to_flow(line, &ofm->match, &ofm->actions[0], NULL, &priority);
ofm->command = htons(OFPFC_ADD);
ofm->max_idle = htons(50);
ofm->buffer_id = htonl(UINT32_MAX);
- ofm->group_id = htonl(0);
- str_to_flow(line, &ofm->match, &ofm->actions[0], NULL);
- run(vconn_send_block(vconn, buffer), "send OpenFlow packet");
+ ofm->priority = htons(priority);
+ ofm->reserved = htonl(0);
+
+ send_openflow_buffer(vconn, buffer);
}
vconn_close(vconn);
fclose(file);
}
+static void do_del_flows(int argc, char *argv[])
+{
+ struct vconn *vconn;
+ uint16_t priority;
+
+ run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
+ struct buffer *buffer;
+ struct ofp_flow_mod *ofm;
+ size_t size;
+
+
+ /* Parse and send. */
+ size = sizeof *ofm;
+ ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
+ str_to_flow(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, &priority);
+ ofm->command = htons(OFPFC_DELETE);
+ ofm->max_idle = htons(0);
+ ofm->buffer_id = htonl(UINT32_MAX);
+ ofm->priority = htons(priority);
+ ofm->reserved = htonl(0);
+
+ send_openflow_buffer(vconn, buffer);
+
+ vconn_close(vconn);
+}
+
static void
do_dump_ports(int argc, char *argv[])
{
- dump_transaction(argv[1], OFPT_PORT_STAT_REQUEST);
+ dump_trivial_stats_transaction(argv[1], OFPST_PORT);
}
static void do_help(int argc UNUSED, char *argv[] UNUSED)
{ "monitor", 1, 1, do_monitor },
{ "dump-tables", 1, 1, do_dump_tables },
{ "dump-flows", 1, 2, do_dump_flows },
+ { "dump-aggregate", 1, 2, do_dump_aggregate },
{ "add-flows", 2, 2, do_add_flows },
+ { "del-flows", 1, 2, do_del_flows },
{ "dump-ports", 1, 1, do_dump_ports },
+ { NULL, 0, 0, NULL },
};