Пример #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;
        }
    }

}
Пример #2
0
char *
ofl_instruction_type_to_string(uint16_t type) {
    char *str;
    size_t str_size;
    FILE *stream = open_memstream(&str, &str_size);

    ofl_instruction_type_print(stream, type);
    fclose(stream);
    return str;
}
Пример #3
0
void
ofl_structs_table_properties_print(FILE * stream, struct ofl_table_feature_prop_header* s){
    int i;    
    fprintf(stream, "{property=\"");
    ofl_properties_type_print(stream, s->type);
    switch(s->type){
        case OFPTFPT_INSTRUCTIONS:
        case OFPTFPT_INSTRUCTIONS_MISS:{
            struct ofl_table_feature_prop_instructions *insts = (struct ofl_table_feature_prop_instructions*) s; 
            fprintf(stream, "[");        
	    if(insts->ids_num) {
                for(i = 0; i < insts->ids_num -1; i++){
                    ofl_instruction_type_print(stream, insts->instruction_ids[i].type);
                    fprintf(stream, ", ");        
                }
                ofl_instruction_type_print(stream, insts->instruction_ids[insts->ids_num-1].type);
	    }
            fprintf(stream, "]");        
            break;
        }
        case OFPTFPT_NEXT_TABLES:
        case OFPTFPT_NEXT_TABLES_MISS:{
            struct ofl_table_feature_prop_next_tables *tbls = (struct ofl_table_feature_prop_next_tables*) s;
            fprintf(stream, "[");
	    if(tbls->table_num) {
                for(i = 0; i < tbls->table_num -1; i++){
                    fprintf(stream, "%d, ", tbls->next_table_ids[i]);
                }
                fprintf(stream, "%d]", tbls->next_table_ids[tbls->table_num -1]);
	    }
            break;
        }
        case OFPTFPT_APPLY_ACTIONS:
        case OFPTFPT_APPLY_ACTIONS_MISS:
        case OFPTFPT_WRITE_ACTIONS:
        case OFPTFPT_WRITE_ACTIONS_MISS:{
            struct ofl_table_feature_prop_actions *acts = (struct ofl_table_feature_prop_actions*) s;
            fprintf(stream, "[");
	    if(acts->actions_num) {
                for(i = 0; i < acts->actions_num -1; i++){
                    ofl_action_type_print(stream, acts->action_ids[i].type);
                    fprintf(stream, ", ");
                }
                ofl_action_type_print(stream, acts->action_ids[acts->actions_num-1].type);
	    }
            fprintf(stream, "]");                                    
            break;
        }
        case OFPTFPT_MATCH:
        case OFPTFPT_WILDCARDS:
        case OFPTFPT_APPLY_SETFIELD:
        case OFPTFPT_APPLY_SETFIELD_MISS:
        case OFPTFPT_WRITE_SETFIELD:
        case OFPTFPT_WRITE_SETFIELD_MISS:{
            struct ofl_table_feature_prop_oxm *oxms = (struct ofl_table_feature_prop_oxm*) s;
            fprintf(stream, "[");
	    if(oxms->oxm_num) {
                for(i = 0; i < oxms->oxm_num -1; i++){
                    ofl_oxm_type_print(stream, oxms->oxm_ids[i]);
                    fprintf(stream, ", " );
                }
                ofl_oxm_type_print(stream, oxms->oxm_ids[oxms->oxm_num -1]);
	    }
            fprintf(stream, "]");                                    
            break;
        }
        
        
    }
    fprintf(stream, "\"} ");
}