#include "openflow-netlink.h"
#endif
-#include "buffer.h"
#include "command-line.h"
#include "compiler.h"
#include "dpif.h"
#include "nicira-ext.h"
#include "ofp-print.h"
+#include "ofpbuf.h"
#include "openflow.h"
#include "packets.h"
#include "random.h"
argc -= optind;
argv += optind;
if (argc < 1)
- fatal(0, "missing command name; use --help for help");
+ ofp_fatal(0, "missing command name; use --help for help");
for (p = all_commands; p->name != NULL; p++) {
if (!strcmp(p->name, argv[0])) {
int n_arg = argc - 1;
if (n_arg < p->min_args)
- fatal(0, "'%s' command requires at least %d arguments",
- p->name, p->min_args);
+ ofp_fatal(0, "'%s' command requires at least %d arguments",
+ p->name, p->min_args);
else if (n_arg > p->max_args)
- fatal(0, "'%s' command takes at most %d arguments",
- p->name, p->max_args);
+ ofp_fatal(0, "'%s' command takes at most %d arguments",
+ p->name, p->max_args);
else {
p->handler(argc, argv);
exit(0);
}
}
}
- fatal(0, "unknown command '%s'; use --help for help", argv[0]);
+ ofp_fatal(0, "unknown command '%s'; use --help for help", argv[0]);
return 0;
}
case 't':
timeout = strtoul(optarg, NULL, 10);
if (timeout <= 0) {
- fatal(0, "value %s on -t or --timeout is not at least 1",
- optarg);
+ ofp_fatal(0, "value %s on -t or --timeout is not at least 1",
+ optarg);
} else {
time_alarm(timeout);
}
if (strncmp(name, "nl:", 3)
|| strlen(name) < 4
|| name[strspn(name + 3, "0123456789") + 3]) {
- fatal(0, "%s: argument is not of the form \"nl:DP_ID\"", name);
+ ofp_fatal(0, "%s: argument is not of the form \"nl:DP_ID\"", name);
}
run(dpif_open(atoi(name + 3), subscribe, dpif), "opening datapath");
}
for (i = 2; i < argc; i++) {
int retval = function(&dp, argv[i]);
if (retval) {
- error(retval, "failed to %s %s %s %s",
- operation, argv[i], preposition, argv[1]);
+ ofp_error(retval, "failed to %s %s %s %s",
+ operation, argv[i], preposition, argv[1]);
failure = true;
}
}
}
static void *
-alloc_stats_request(size_t body_len, uint16_t type, struct buffer **bufferp)
+alloc_stats_request(size_t body_len, uint16_t type, struct ofpbuf **bufferp)
{
struct ofp_stats_request *rq;
rq = make_openflow((offsetof(struct ofp_stats_request, body)
}
static void
-send_openflow_buffer(struct vconn *vconn, struct buffer *buffer)
+send_openflow_buffer(struct vconn *vconn, struct ofpbuf *buffer)
{
update_openflow_length(buffer);
run(vconn_send_block(vconn, buffer), "failed to send packet to switch");
}
static void
-dump_transaction(const char *vconn_name, struct buffer *request)
+dump_transaction(const char *vconn_name, struct ofpbuf *request)
{
struct vconn *vconn;
- struct buffer *reply;
+ struct ofpbuf *reply;
update_openflow_length(request);
open_vconn(vconn_name, &vconn);
static void
dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
{
- struct buffer *request;
+ struct ofpbuf *request;
make_openflow(sizeof(struct ofp_header), request_type, &request);
dump_transaction(vconn_name, request);
}
static void
-dump_stats_transaction(const char *vconn_name, struct buffer *request)
+dump_stats_transaction(const char *vconn_name, struct ofpbuf *request)
{
uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
struct vconn *vconn;
send_openflow_buffer(vconn, request);
while (!done) {
uint32_t recv_xid;
- struct buffer *reply;
+ struct ofpbuf *reply;
run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
recv_xid = ((struct ofp_header *) reply->data)->xid;
ofp_print(stdout, reply->data, reply->size, 1);
- osr = buffer_at(reply, 0, sizeof *osr);
+ osr = ofpbuf_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);
+ ofpbuf_delete(reply);
}
vconn_close(vconn);
}
static void
dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
{
- struct buffer *request;
+ struct ofpbuf *request;
alloc_stats_request(0, stats_type, &request);
dump_stats_transaction(vconn_name, request);
}
{
struct nicira_header *request, *reply;
struct vconn *vconn;
- struct buffer *b;
+ 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) {
- buffer_put(b, argv[2], strlen(argv[2]));
+ ofpbuf_put(b, argv[2], strlen(argv[2]));
}
open_vconn(argv[1], &vconn);
run(vconn_transact(vconn, b, &b), "talking to %s", argv[1]);
vconn_close(vconn);
if (b->size < sizeof *reply) {
- fatal(0, "short reply (%zu bytes)", b->size);
+ 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);
- fatal(0, "bad reply");
+ ofp_fatal(0, "bad reply");
}
fwrite(reply + 1, b->size, 1, stdout);
errno = 0;
value = strtoul(str, &tail, 0);
if (errno == EINVAL || errno == ERANGE || *tail) {
- fatal(0, "invalid numeric format %s", str);
+ ofp_fatal(0, "invalid numeric format %s", str);
}
return value;
}
{
if (sscanf(str, "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8,
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6) {
- fatal(0, "invalid mac address %s", str);
+ ofp_fatal(0, "invalid mac address %s", str);
}
}
name = strtok_r(str, "//", &save_ptr);
retval = name ? lookup_ip(name, &in_addr) : EINVAL;
if (retval) {
- fatal(0, "%s: could not convert to IP address", str);
+ ofp_fatal(0, "%s: could not convert to IP address", str);
}
*ip = in_addr.s_addr;
/* Verify that the rest of the bits are 1-bits. */
for (; i < 32; i++) {
if (!(nm & (1u << i))) {
- fatal(0, "%s: %s is not a valid netmask", str, netmask);
+ ofp_fatal(0, "%s: %s is not a valid netmask",
+ str, netmask);
}
}
} else {
int prefix = atoi(netmask);
if (prefix <= 0 || prefix > 32) {
- fatal(0, "%s: network prefix bits not between 1 and 32", str);
+ ofp_fatal(0, "%s: network prefix bits not between 1 and 32",
+ str);
}
n_wild = 32 - prefix;
}
} else if (strspn(act, "0123456789") == strlen(act)) {
port = str_to_int(act);
} else {
- fatal(0, "Unknown action: %s", act);
+ ofp_fatal(0, "Unknown action: %s", act);
}
if (port != OFPP_MAX) {
if (action) {
char *act_str = strstr(string, "action");
if (!act_str) {
- fatal(0, "must specify an action");
+ ofp_fatal(0, "must specify an action");
}
*(act_str-1) = '\0';
act_str = strchr(act_str, '=');
if (!act_str) {
- fatal(0, "must specify an action");
+ ofp_fatal(0, "must specify an action");
}
act_str++;
value = strtok(NULL, ", \t\r\n");
if (!value) {
- fatal(0, "field %s missing value", name);
+ ofp_fatal(0, "field %s missing value", name);
}
if (table_idx && !strcmp(name, "table")) {
}
}
} else {
- fatal(0, "unknown keyword %s", name);
+ ofp_fatal(0, "unknown keyword %s", name);
}
}
}
static void do_dump_flows(int argc, char *argv[])
{
struct ofp_flow_stats_request *req;
- struct buffer *request;
+ struct ofpbuf *request;
req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, 0,
static void do_dump_aggregate(int argc, char *argv[])
{
struct ofp_aggregate_stats_request *req;
- struct buffer *request;
+ struct ofpbuf *request;
req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, 0,
static void do_add_flow(int argc, char *argv[])
{
struct vconn *vconn;
- struct buffer *buffer;
+ struct ofpbuf *buffer;
struct ofp_flow_mod *ofm;
uint16_t priority, idle_timeout, hard_timeout;
size_t size;
ofm->priority = htons(priority);
ofm->reserved = htonl(0);
- /* xxx Should we use the buffer library? */
+ /* xxx Should we use the ofpbuf library? */
buffer->size -= (MAX_ADD_ACTS - n_actions) * sizeof ofm->actions[0];
send_openflow_buffer(vconn, buffer);
file = fopen(argv[2], "r");
if (file == NULL) {
- fatal(errno, "%s: open", argv[2]);
+ ofp_fatal(errno, "%s: open", argv[2]);
}
open_vconn(argv[1], &vconn);
while (fgets(line, sizeof line, file)) {
- struct buffer *buffer;
+ struct ofpbuf *buffer;
struct ofp_flow_mod *ofm;
uint16_t priority, idle_timeout, hard_timeout;
size_t size;
ofm->priority = htons(priority);
ofm->reserved = htonl(0);
- /* xxx Should we use the buffer library? */
+ /* xxx Should we use the ofpbuf library? */
buffer->size -= (MAX_ADD_ACTS - n_actions) * sizeof ofm->actions[0];
send_openflow_buffer(vconn, buffer);
uint16_t priority;
open_vconn(argv[1], &vconn);
- struct buffer *buffer;
+ struct ofpbuf *buffer;
struct ofp_flow_mod *ofm;
size_t size;
}
open_vconn(argv[1], &vconn);
for (;;) {
- struct buffer *b;
+ struct ofpbuf *b;
run(vconn_recv_block(vconn, &b), "vconn_recv");
ofp_print(stderr, b->data, b->size, 2);
- buffer_delete(b);
+ ofpbuf_delete(b);
}
}
static void
do_probe(int argc, char *argv[])
{
- struct buffer *request;
+ struct ofpbuf *request;
struct vconn *vconn;
- struct buffer *reply;
+ struct ofpbuf *reply;
make_openflow(sizeof(struct ofp_header), OFPT_ECHO_REQUEST, &request);
open_vconn(argv[1], &vconn);
run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
if (reply->size != request->size) {
- fatal(0, "reply does not match request");
+ ofp_fatal(0, "reply does not match request");
}
- buffer_delete(reply);
+ ofpbuf_delete(reply);
vconn_close(vconn);
}
static void
do_mod_port(int argc, char *argv[])
{
- struct buffer *request, *reply;
+ struct ofpbuf *request, *reply;
struct ofp_switch_features *osf;
struct ofp_port_mod *opm;
struct vconn *vconn;
}
}
if (port_idx == n_ports) {
- fatal(0, "couldn't find monitored port: %s", argv[2]);
+ ofp_fatal(0, "couldn't find monitored port: %s", argv[2]);
}
opm = make_openflow(sizeof(struct ofp_port_mod), OFPT_PORT_MOD, &request);
opm->mask |= htonl(OFPPFL_NO_FLOOD);
opm->desc.flags |= htonl(OFPPFL_NO_FLOOD);
} else {
- fatal(0, "unknown mod-port command '%s'", argv[3]);
+ ofp_fatal(0, "unknown mod-port command '%s'", argv[3]);
}
send_openflow_buffer(vconn, request);
- buffer_delete(reply);
+ ofpbuf_delete(reply);
vconn_close(vconn);
}
payload = argc > 2 ? atoi(argv[2]) : 64;
if (payload > max_payload) {
- fatal(0, "payload must be between 0 and %zu bytes", max_payload);
+ ofp_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
}
open_vconn(argv[1], &vconn);
for (i = 0; i < 10; i++) {
struct timeval start, end;
- struct buffer *request, *reply;
+ struct ofpbuf *request, *reply;
struct ofp_header *rq_hdr, *rpy_hdr;
rq_hdr = make_openflow(sizeof(struct ofp_header) + payload,
random_bytes(rq_hdr + 1, payload);
gettimeofday(&start, NULL);
- run(vconn_transact(vconn, buffer_clone(request), &reply), "transact");
+ run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact");
gettimeofday(&end, NULL);
rpy_hdr = reply->data;
reply->size - sizeof *rpy_hdr, argv[1], rpy_hdr->xid,
(1000*(double)(end.tv_sec - start.tv_sec))
+ (.001*(end.tv_usec - start.tv_usec)));
- buffer_delete(request);
- buffer_delete(reply);
+ ofpbuf_delete(request);
+ ofpbuf_delete(reply);
}
vconn_close(vconn);
}
payload_size = atoi(argv[2]);
if (payload_size > max_payload) {
- fatal(0, "payload must be between 0 and %zu bytes", max_payload);
+ ofp_fatal(0, "payload must be between 0 and %zu bytes", max_payload);
}
message_size = sizeof(struct ofp_header) + payload_size;
open_vconn(argv[1], &vconn);
gettimeofday(&start, NULL);
for (i = 0; i < count; i++) {
- struct buffer *request, *reply;
+ struct ofpbuf *request, *reply;
struct ofp_header *rq_hdr;
rq_hdr = make_openflow(message_size, OFPT_ECHO_REQUEST, &request);
memset(rq_hdr + 1, 0, payload_size);
run(vconn_transact(vconn, request, &reply), "transact");
- buffer_delete(reply);
+ ofpbuf_delete(reply);
}
gettimeofday(&end, NULL);
vconn_close(vconn);