Beispiel #1
0
def transform_hlir16(hlir16):
    main = get_main(hlir16)
    pipeline_elements = main.arguments 
	
    for pe in pipeline_elements:
        c = hlir16.declarations.get(pe.type.name, 'P4Control')
        if c is not None:
            c.body.components = map(search_for_annotations, c.body.components)
Beispiel #2
0
#[ uint8_t* emit_addr;
#[ uint32_t ingress_pkt_len;

#[ extern ctrl_plane_backend bg;
#[ extern char* action_names[];

#[ extern void parse_packet(STDPARAMS);
#[ extern void increase_counter (int counterid, int index);

# note: 0 is for the special case where there are no tables
max_key_length = max([t.key_length_bytes for t in hlir16.tables if hasattr(t, 'key')] + [0])
#[ uint8_t reverse_buffer[${max_key_length}];

################################################################################

main = get_main(hlir16)
packet_name = main.type.baseType.type_ref.name
pipeline_elements = main.arguments

#{ struct apply_result_s {
#[     bool hit;
#[     enum actions action_run;
#} };

for pe in pipeline_elements:
    c = hlir16.objects.get(pe.expression.type.name, 'P4Control')
    if c is None:
        continue

    #[ void control_${pe.expression.type.name}(STDPARAMS);
    for t in c.controlLocals['P4Table']:
Beispiel #3
0
    for action in table.actions:
        # TODO what if the action is not a method call?
        # TODO what if there are more actions?
        action_method_name = action.expression.method.ref.name
        #[         struct action_${action.action_object.name}_params ${action_method_name}_params;
    #}     };
    #} };



for table in hlir16.tables:
    #[ void apply_table_${table.name}(packet_descriptor_t *pd, lookup_table_t** tables);
    for action in table.actions:
        aname = action.action_object.name
        mname = action.expression.method.ref.name

        #[ void action_code_$aname(packet_descriptor_t *pd, lookup_table_t **tables, struct action_${mname}_params);


# TODO: The controls shouldn't be accessed through an instance declaration parameter
for pe in get_main(hlir16).arguments:
    ctl = hlir16.declarations.get(pe.type.name, 'P4Control')

    if ctl is not None:
        #[ typedef struct control_locals_${pe.type.name}_s {
        for local_var_decl in ctl.controlLocals['Declaration_Variable']:
            #[ ${format_type(local_var_decl.type, False)} ${local_var_decl.name};
        #[ } control_locals_${pe.type.name}_t;

#[ #endif