#!/bin/bash

greylin_raw_counters ()
{
    dmem 0x1000010108000 2048 8 | grep -v '0000000000000000 0000000000000000'
}

greylin_setup_reflector ()
{
    greylinreg GREYLIN_REG_CNTRL.greylin_loopback_en 0 -e

    greylin_table_fill rx_class <<___

# Device 0  Table 0x01 RX_CLASS
0x0000
         VID:            0x0
         CFI:            0x0
         PRI:            0x0
         DA_MAC:         0x00025a01b072
         SA_MAC:         0x0
         VID_mask:       0x1
         PCP_mask:       0x1
         DA_mask:        0x0
         SA_mask:        0x1
         service_id:     0x1
         action:         0x1
         enable_1:       0x0
         offset_1:       0x0
         enable_2:       0x0
         offset_2:       0x0
         enable_3:       0x0
         offset_3:       0x0
         valid:          0x1
___

    greylin_table_dump rx_class 0 1
}

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

    greylin_table_dump "$table_id" "$@" | sed "/$field/s/:.*/: $value/" | greylin_table_fill "$table_id"
}

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

    greylin_table_dump "$table_id" "$@" | grep ^0 | greylin_table_fill "$table_id"
}

