示例#1
0
void
ofl_structs_instruction_print(FILE *stream, struct ofl_instruction_header *inst, struct ofl_exp *exp) {
    ofl_instruction_type_print(stream, inst->type);

    switch(inst->type) {
        case (OFPIT_GOTO_TABLE): {
            struct ofl_instruction_goto_table *i = (struct ofl_instruction_goto_table*)inst;
            
            fprintf(stream, "{table=\"%u\"}", i->table_id);

            break;
        }
        case (OFPIT_WRITE_METADATA): {
            struct ofl_instruction_write_metadata *i = (struct ofl_instruction_write_metadata *)inst;

            fprintf(stream, "{meta=\"0x%"PRIx64"\", mask=\"0x%"PRIx64"\"}",
                          i->metadata, i->metadata_mask);

            break;
        }
        case (OFPIT_WRITE_ACTIONS):
        case (OFPIT_APPLY_ACTIONS): {
            struct ofl_instruction_actions *i = (struct ofl_instruction_actions *)inst;
            size_t j;

            fprintf(stream, "{acts=[");
            for(j=0; j<i->actions_num; j++) {
                ofl_action_print(stream, i->actions[j], exp);
                if (j < i->actions_num - 1) { fprintf(stream, ", "); }
            }
            fprintf(stream, "]}");

            break;
        }
        case (OFPIT_CLEAR_ACTIONS): {
            break;
        }
        case (OFPIT_METER):{
            struct ofl_instruction_meter *i = (struct ofl_instruction_meter *)inst;
            fprintf(stream, "{meter=\"%u\"}", i->meter_id);          
            break;
        }
        case (OFPIT_EXPERIMENTER): {
            if (exp == NULL || exp->inst == NULL || exp->inst->to_string == NULL) {
                struct ofl_instruction_experimenter *i = (struct ofl_instruction_experimenter *)inst;

                fprintf(stream, "{id=\"0x%"PRIx32"\"}", i->experimenter_id);
            } else {
                char *c = exp->inst->to_string(inst);
                fprintf(stream, "%s", c);
                free (c);
            }
            break;
        }
    }

}
char *
ofl_action_to_string(struct ofl_action_header *act, struct ofl_exp *exp) {
    char *str;
    size_t str_size;
    FILE *stream = open_memstream(&str, &str_size);

    ofl_action_print(stream, act, exp);
    fclose(stream);
    return str;
}
void
action_set_print(FILE *stream, struct action_set *set) {
    struct action_set_entry *entry;

    fprintf(stream, "[");

    LIST_FOR_EACH(entry, struct action_set_entry, node, &set->actions) {
        ofl_action_print(stream, entry->action, set->exp);
        if (entry->node.next != &set->actions) { fprintf(stream, ", "); }
    }

    fprintf(stream, "]");
}
static void
ofl_msg_print_packet_out(struct ofl_msg_packet_out *msg, FILE *stream, struct ofl_exp *exp) {
    size_t i;
    fprintf(stream, "{buffer=\"");
    ofl_buffer_print(stream, msg->buffer_id);
    fprintf(stream, "\", port=\"");
    ofl_port_print(stream, msg->in_port);
    fprintf(stream, "\", actions=[");

    for (i=0; i<msg->actions_num; i++) {
        ofl_action_print(stream, msg->actions[i], exp);
        if (i < msg->actions_num - 1) { fprintf(stream, ", "); }
    }

    fprintf(stream, "]}");
}
void
ofl_structs_bucket_print(FILE *stream, struct ofl_bucket *b, struct ofl_exp *exp) {
    size_t i;

    fprintf(stream, "{w=\"%u\", wprt=\"", b->weight);
    ofl_port_print(stream, b->watch_port);
    fprintf(stream, "\", wgrp=\"");
    ofl_group_print(stream, b->watch_group);
    fprintf(stream, "\", acts=[");

    for (i=0; i<b->actions_num; i++) {
        ofl_action_print(stream, b->actions[i], exp);
        if (i < b->actions_num - 1) { fprintf(stream, ", "); }
    }

    fprintf(stream, "]}");
}