diff --git a/proto/sonic.pb.go b/proto/sonic.pb.go index f6f026fc..762ca357 100644 --- a/proto/sonic.pb.go +++ b/proto/sonic.pb.go @@ -25,6 +25,7 @@ const ( Target_PFC_WD_DB Target = 5 Target_FLEX_COUNTER_DB Target = 5 Target_STATE_DB Target = 6 + Target_BMP_STATE_DB Target = 20 // For none-DB data Target_OTHERS Target = 100 ) @@ -37,6 +38,7 @@ var Target_name = map[int32]string{ 5: "PFC_WD_DB", // Duplicate value: 5: "FLEX_COUNTER_DB", 6: "STATE_DB", + 20: "BMP_STATE_DB", 100: "OTHERS", } var Target_value = map[string]int32{ @@ -47,6 +49,7 @@ var Target_value = map[string]int32{ "PFC_WD_DB": 5, "FLEX_COUNTER_DB": 5, "STATE_DB": 6, + "BMP_STATE_DB": 20, "OTHERS": 100, } diff --git a/sonic_db_config/db_config_test.go b/sonic_db_config/db_config_test.go index c61ad0e9..d879a1fa 100644 --- a/sonic_db_config/db_config_test.go +++ b/sonic_db_config/db_config_test.go @@ -40,6 +40,37 @@ func TestGetDb(t *testing.T) { }) } +func TestGetBMPDb(t *testing.T) { + ns, _ := GetDbDefaultNamespace() + t.Run("Id", func(t *testing.T) { + db_id, _ := GetDbId("BMP_STATE_DB", ns) + if db_id != 20 { + t.Fatalf(`Id("") = %d, want 20, error`, db_id) + } + }) + t.Run("Sock", func(t *testing.T) { + sock_path, _ := GetDbSock("BMP_STATE_DB", ns) + if sock_path != "/var/run/redis/redis_bmp.sock" { + t.Fatalf(`Sock("") = %q, want "/var/run/redis/redis_bmp.sock", error`, sock_path) + } + }) + t.Run("AllNamespaces", func(t *testing.T) { + ns_list, _ := GetDbAllNamespaces() + if len(ns_list) != 1 { + t.Fatalf(`AllNamespaces("") = %q, want "1", error`, len(ns_list)) + } + if ns_list[0] != ns { + t.Fatalf(`AllNamespaces("") = %q, want default, error`, ns_list[0]) + } + }) + t.Run("TcpAddr", func(t *testing.T) { + tcp_addr, _ := GetDbTcpAddr("BMP_STATE_DB", ns) + if tcp_addr != "127.0.0.1:6400" { + t.Fatalf(`TcpAddr("") = %q, want 127.0.0.1:6400, error`, tcp_addr) + } + }) +} + func TestGetDbMultiNs(t *testing.T) { Init() err := test_utils.SetupMultiNamespace() diff --git a/testdata/database_config.json b/testdata/database_config.json index d96eb827..a7ba15b1 100644 --- a/testdata/database_config.json +++ b/testdata/database_config.json @@ -4,6 +4,11 @@ "hostname" : "127.0.0.1", "port" : 6379, "unix_socket_path" : "/var/run/redis/redis.sock" + }, + "redis_bmp": { + "hostname": "127.0.0.1", + "port": 6400, + "unix_socket_path": "/var/run/redis/redis_bmp.sock" } }, "DATABASES" : { @@ -46,6 +51,11 @@ "id" : 7, "separator": "|", "instance" : "redis" + }, + "BMP_STATE_DB": { + "id": 20, + "separator": "|", + "instance": "redis_bmp" } }, "VERSION" : "1.0"