#!/bin/bash

langwell_raw_counters ()
{
    dmem 0x1000011008000 2048 8 | grep -v '0000000000000000 0000000000000000'
}

langwell_setup_rx_class ()
{
    langwell_table_fill rx_class <<___

# Device 0  Table 0x01 RX_CLASS
0x0001
        S_VID:  0x0
        S_CFI:  0x0
        S_PRI:  0x0
        DA_MAC: 0x0
        SA_MAC: 0x0
        S_VID_mask:     0x1
        S_PCP_mask:     0x1
        DA_mask:        0x1
        SA_mask:        0x1
        service_id:     0x1
        action: 0x2
        frame_type:     0x1
        seq_num_en:     0x1
        time_stamp_en:  0x3
        seq_num_offset: 0x2e
        time_stamp_offset:      0x32
        ip_src_mask:    0x0
        ip_dst_mask:    0x0
        dst_port_mask:  0x0
        src_port_mask:  0x0
        C_VID:  0x0
        C_CFI:  0x0
        C_PRI:  0x0
        SRC_IP: 0xc0a832f6
        DST_IP: 0xc0a832f5
        DST_PORT:       0xcaae
        SRC_PORT:       0x35d
        C_VID_mask:     0x1
        C_PCP_mask:     0x1
        valid:  0x1
___

    langwell_table_dump rx_class 1 1
}


langwell_setup_time_gen ()
{
    langwell_table_fill time_gen <<___

# Device 0  Table 0x02 TIME_GEN
0x0001
        rsvd:   0x0
        continuous:     0x0
        custom_type:    0x7
        seq_num_offset: 0x0
        timestamp_offset:       0x32
        frame_length:   0xa4
        rate:   0x10
        credit: 0x1f
        fill_start_pos: 0x0
        current_credit_level:   0xb1
        frame_count:    0x2328
        fill_type:      0x0
        time_stamp_type:        0x0
        use_idt:        0x0
        reserved:       0x0
        valid:  0x1

___

    langwell_table_dump time_gen 1 1
}


langwell_table_modify ()
{
    local field="$1"
    local value="$2"
    local table_id="$3"
    shift 3

    langwell_table_dump "$table_id" "$@" | sed "/$field/s/:.*/: $value/" | langwell_table_fill "$table_id"
}

langwell_table_clear ()
{
    local table_id="$1"
    shift 1

    langwell_table_dump "$table_id" "$@" | grep ^0 | langwell_table_fill "$table_id"
}

