+\f
+/* Undocumented commands for unit testing. */
+
+/* "parse-flows FILENAME": reads the named file as a sequence of flows (like
+ * add-flows) and prints each of the flows back to stdout. */
+static void
+do_parse_flows(int argc OVS_UNUSED, char *argv[])
+{
+ enum nx_flow_format flow_format;
+ struct list packets;
+ FILE *file;
+
+ file = fopen(argv[1], "r");
+ if (file == NULL) {
+ ovs_fatal(errno, "%s: open", argv[2]);
+ }
+
+ list_init(&packets);
+ flow_format = NXFF_OPENFLOW10;
+ if (preferred_flow_format > 0) {
+ flow_format = preferred_flow_format;
+ }
+
+ while (parse_ofp_add_flow_file(&packets, &flow_format, file)) {
+ struct ofpbuf *packet, *next;
+
+ LIST_FOR_EACH_SAFE (packet, next, list_node, &packets) {
+ ofp_print(stdout, packet->data, packet->size, verbosity);
+ list_remove(&packet->list_node);
+ ofpbuf_delete(packet);
+ }
+ }
+ fclose(file);
+}
+
+/* "parse-nx-match": reads a series of nx_match specifications as strings from
+ * stdin, does some internal fussing with them, and then prints them back as
+ * strings on stdout. */
+static void
+do_parse_nx_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
+{
+ struct ds in;
+
+ ds_init(&in);
+ while (!ds_get_line(&in, stdin)) {
+ struct ofpbuf nx_match;
+ struct cls_rule rule;
+ int match_len;
+ int error;
+ char *s;
+
+ /* Delete comments, skip blank lines. */
+ s = ds_cstr(&in);
+ if (*s == '#') {
+ puts(s);
+ continue;
+ }
+ if (strchr(s, '#')) {
+ *strchr(s, '#') = '\0';
+ }
+ if (s[strspn(s, " ")] == '\0') {
+ putchar('\n');
+ continue;
+ }
+
+ /* Convert string to nx_match. */
+ ofpbuf_init(&nx_match, 0);
+ match_len = nx_match_from_string(ds_cstr(&in), &nx_match);
+
+ /* Convert nx_match to cls_rule. */
+ error = nx_pull_match(&nx_match, match_len, 0, &rule);
+ if (!error) {
+ char *out;
+
+ /* Convert cls_rule back to nx_match. */
+ ofpbuf_uninit(&nx_match);
+ ofpbuf_init(&nx_match, 0);
+ match_len = nx_put_match(&nx_match, &rule);
+
+ /* Convert nx_match to string. */
+ out = nx_match_to_string(nx_match.data, match_len);
+ puts(out);
+ free(out);
+ } else {
+ printf("nx_pull_match() returned error %x\n", error);
+ }
+
+ ofpbuf_uninit(&nx_match);
+ }
+ ds_destroy(&in);
+}
+
+/* "ofp-print HEXSTRING [VERBOSITY]": Converts the hex digits in HEXSTRING into
+ * binary data, interpreting them as an OpenFlow message, and prints the
+ * OpenFlow message on stdout, at VERBOSITY (level 2 by default). */
+static void
+do_ofp_print(int argc, char *argv[])
+{
+ struct ofpbuf packet;
+
+ ofpbuf_init(&packet, strlen(argv[1]) / 2);
+ if (ofpbuf_put_hex(&packet, argv[1], NULL)[0] != '\0') {
+ ovs_fatal(0, "trailing garbage following hex bytes");
+ }
+ ofp_print(stdout, packet.data, packet.size, argc > 2 ? atoi(argv[2]) : 2);
+ ofpbuf_uninit(&packet);
+}