- while (fgets(line, sizeof line, file)) {
- struct ofpbuf *buffer;
- struct ofp_flow_mod *ofm;
- uint16_t priority, idle_timeout, hard_timeout;
- uint64_t cookie;
- struct ofp_match match;
-
- char *comment;
-
- /* Delete comments. */
- comment = strchr(line, '#');
- if (comment) {
- *comment = '\0';
- }
-
- /* Drop empty lines. */
- if (line[strspn(line, " \t\n")] == '\0') {
- continue;
- }
-
- /* Parse and send. parse_ofp_str() will expand and reallocate
- * the data in 'buffer', so we can't keep pointers to across the
- * parse_ofp_str() call. */
- make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
- parse_ofp_str(line, &match, buffer, &table_idx, NULL, &priority,
- &idle_timeout, &hard_timeout, &cookie);
- ofm = buffer->data;
- ofm->match = match;
- ofm->command = htons(OFPFC_ADD);
- ofm->cookie = htonll(cookie);
- ofm->idle_timeout = htons(idle_timeout);
- ofm->hard_timeout = htons(hard_timeout);
- ofm->buffer_id = htonl(UINT32_MAX);
- ofm->priority = htons(priority);
-
- if (table_idx != 0xff) {
- if (!table_id_enabled) {
- enable_flow_mod_table_id_ext(vconn, 1);
- table_id_enabled = 1;
- }
- ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
- } else {
- if (table_id_enabled) {
- enable_flow_mod_table_id_ext(vconn, 0);
- table_id_enabled = 0;
- }
+ while ((b = parse_ofp_add_flow_file(file, &table_idx)) != NULL) {
+ if ((table_idx != 0xff) != table_id_enabled) {
+ table_id_enabled = table_idx != 0xff;
+ enable_flow_mod_table_id_ext(vconn, table_id_enabled);