#include "command-line.h"
#include "compiler.h"
#include "dpif.h"
+#include "nicira-ext.h"
#include "ofp-print.h"
#include "ofpbuf.h"
#include "openflow.h"
" deldp nl:DP_ID delete local datapath DP_ID\n"
" addif nl:DP_ID IFACE... add each IFACE as a port on DP_ID\n"
" delif nl:DP_ID IFACE... delete each IFACE from DP_ID\n"
- " monitor nl:DP_ID print packets received\n"
#endif
"\nFor local datapaths and remote switches:\n"
" show SWITCH show basic information\n"
" add-flow SWITCH FLOW add flow described by FLOW\n"
" add-flows SWITCH FILE add flows from FILE\n"
" del-flows SWITCH FLOW delete matching FLOWs\n"
+ " monitor SWITCH print packets received from SWITCH\n"
"\nFor local datapaths, remote switches, and controllers:\n"
" probe VCONN probe whether VCONN is up\n"
" ping VCONN [N] latency of N-byte echos\n"
{
add_del_ports(argc, argv, dpif_del_port, "remove", "from");
}
-
-static void do_monitor(int argc UNUSED, char *argv[])
-{
- struct dpif dp;
- open_nl_vconn(argv[1], true, &dp);
- for (;;) {
- struct ofpbuf *b;
- run(dpif_recv_openflow(&dp, &b, true), "dpif_recv_openflow");
- ofp_print(stderr, b->data, b->size, 2);
- ofpbuf_delete(b);
- }
-}
#endif /* HAVE_NETLINK */
\f
/* Generic commands. */
+static void
+open_vconn(const char *name, struct vconn **vconnp)
+{
+ run(vconn_open_block(name, OFP_VERSION, vconnp), "connecting to %s", name);
+}
+
static void *
alloc_stats_request(size_t body_len, uint16_t type, struct ofpbuf **bufferp)
{
struct ofpbuf *reply;
update_openflow_length(request);
- run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
+ open_vconn(vconn_name, &vconn);
run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
ofp_print(stdout, reply->data, reply->size, 1);
vconn_close(vconn);
struct vconn *vconn;
bool done = false;
- run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
+ open_vconn(vconn_name, &vconn);
send_openflow_buffer(vconn, request);
while (!done) {
uint32_t recv_xid;
static void
do_status(int argc, char *argv[])
{
- struct ofpbuf *request;
- alloc_stats_request(0, OFPST_SWITCH, &request);
+ struct nicira_header *request, *reply;
+ struct vconn *vconn;
+ struct ofpbuf *b;
+
+ request = make_openflow(sizeof *request, OFPT_VENDOR, &b);
+ request->vendor_id = htonl(NX_VENDOR_ID);
+ request->subtype = htonl(NXT_STATUS_REQUEST);
if (argc > 2) {
- ofpbuf_put(request, argv[2], strlen(argv[2]));
+ ofpbuf_put(b, argv[2], strlen(argv[2]));
}
- dump_stats_transaction(argv[1], request);
+ open_vconn(argv[1], &vconn);
+ run(vconn_transact(vconn, b, &b), "talking to %s", argv[1]);
+ vconn_close(vconn);
+
+ if (b->size < sizeof *reply) {
+ ofp_fatal(0, "short reply (%zu bytes)", b->size);
+ }
+ reply = b->data;
+ if (reply->header.type != OFPT_VENDOR
+ || reply->vendor_id != ntohl(NX_VENDOR_ID)
+ || reply->subtype != ntohl(NXT_STATUS_REPLY)) {
+ ofp_print(stderr, b->data, b->size, 2);
+ ofp_fatal(0, "bad reply");
+ }
+
+ fwrite(reply + 1, b->size, 1, stdout);
}
static void
size_t size;
int n_actions = MAX_ADD_ACTS;
- run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
+ open_vconn(argv[1], &vconn);
/* Parse and send. */
size = sizeof *ofm + (sizeof ofm->actions[0] * MAX_ADD_ACTS);
ofp_fatal(errno, "%s: open", argv[2]);
}
- run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
+ open_vconn(argv[1], &vconn);
while (fgets(line, sizeof line, file)) {
struct ofpbuf *buffer;
struct ofp_flow_mod *ofm;
struct vconn *vconn;
uint16_t priority;
- run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
+ open_vconn(argv[1], &vconn);
struct ofpbuf *buffer;
struct ofp_flow_mod *ofm;
size_t size;
vconn_close(vconn);
}
+static void
+do_monitor(int argc UNUSED, char *argv[])
+{
+ struct vconn *vconn;
+ const char *name;
+
+ /* If the user specified, e.g., "nl:0", append ":1" to it to ensure that
+ * the connection will subscribe to listen for asynchronous messages, such
+ * as packet-in messages. */
+ if (!strncmp(argv[1], "nl:", 3) && strrchr(argv[1], ':') == &argv[1][2]) {
+ name = xasprintf("%s:1", argv[1]);
+ } else {
+ name = argv[1];
+ }
+ open_vconn(argv[1], &vconn);
+ for (;;) {
+ struct ofpbuf *b;
+ run(vconn_recv_block(vconn, &b), "vconn_recv");
+ ofp_print(stderr, b->data, b->size, 2);
+ ofpbuf_delete(b);
+ }
+}
+
static void
do_dump_ports(int argc, char *argv[])
{
struct ofpbuf *reply;
make_openflow(sizeof(struct ofp_header), OFPT_ECHO_REQUEST, &request);
- run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
+ open_vconn(argv[1], &vconn);
run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
if (reply->size != request->size) {
ofp_fatal(0, "reply does not match request");
/* Send a "Features Request" to get the information we need in order
* to modify the port. */
make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
- run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
+ open_vconn(argv[1], &vconn);
run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
osf = reply->data;
ofp_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
}
- run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
+ open_vconn(argv[1], &vconn);
for (i = 0; i < 10; i++) {
struct timeval start, end;
struct ofpbuf *request, *reply;
printf("Sending %d packets * %u bytes (with header) = %u bytes total\n",
count, message_size, count * message_size);
- run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
+ open_vconn(argv[1], &vconn);
gettimeofday(&start, NULL);
for (i = 0; i < count; i++) {
struct ofpbuf *request, *reply;