Joey Armstrong | aca03cf | 2024-04-23 09:29:52 -0400 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------- |
| 2 | * Copyright 2022-2024 Open Networking Foundation Contributors |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * ----------------------------------------------------------------------- |
| 16 | * SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors |
| 17 | * SPDX-License-Identifier: Apache-2.0 |
| 18 | * ----------------------------------------------------------------------- |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 19 | */ |
Joey Armstrong | aca03cf | 2024-04-23 09:29:52 -0400 | [diff] [blame] | 20 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 21 | // This implementation of database assumes that it is working for |
| 22 | // Open ONU adapter. Thus, it assumes some base path for all the |
| 23 | // database operations. For all database operations, the key passed is |
| 24 | // added to the database base path. |
| 25 | |
| 26 | package database |
| 27 | |
| 28 | import ( |
| 29 | "context" |
| 30 | "errors" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 31 | "fmt" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 32 | "net" |
| 33 | "strconv" |
| 34 | "time" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 35 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 36 | "voltha-go-controller/internal/pkg/errorcodes" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 37 | "voltha-go-controller/internal/pkg/of" |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 38 | "voltha-go-controller/log" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 39 | |
| 40 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 41 | ) |
| 42 | |
| 43 | var logger log.CLogger |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 44 | |
| 45 | // Database structure |
| 46 | type Database struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 47 | kvc kvstore.Client |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 48 | storeType string |
| 49 | address string |
| 50 | //timeout uint32 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // Initialize the database module. The database module runs as a singleton |
| 54 | // object and is initialized when the adapter is created. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 55 | func Initialize(ctx context.Context, storeType string, address string, timeout int) (*Database, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 56 | var err error |
| 57 | var database Database |
| 58 | logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType}) |
| 59 | database.address = address |
| 60 | database.storeType = storeType |
| 61 | switch storeType { |
| 62 | case "redis": |
| 63 | database.kvc, err = kvstore.NewRedisClient(address, time.Duration(timeout), false) |
| 64 | return &database, err |
Abhay Kumar | 6040f38 | 2024-07-12 09:29:23 +0530 | [diff] [blame^] | 65 | case "redis-sentinel": |
| 66 | database.kvc, err = kvstore.NewRedisClient(address, time.Duration(timeout), true) |
| 67 | return &database, err |
Akash Soni | dedc8ee | 2023-03-03 11:51:49 +0530 | [diff] [blame] | 68 | case "etcd": |
| 69 | database.kvc, err = kvstore.NewEtcdClient(ctx, address, time.Duration(timeout), log.ErrorLevel) |
| 70 | return &database, err |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 71 | } |
| 72 | return &database, errors.New("unsupported-kv-store") |
| 73 | } |
| 74 | |
| 75 | // Utility function that retrieves value for a key. It is assumed that |
| 76 | // the information is always a string and the data retrieved is returned |
| 77 | // as a string |
| 78 | |
| 79 | // Put to add value to database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 80 | func (db *Database) Put(ctx context.Context, fullKeyPath, value string) error { |
| 81 | return db.kvc.Put(ctx, fullKeyPath, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | // Get to retrieve value from database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 85 | func (db *Database) Get(ctx context.Context, key string) (string, error) { |
| 86 | kv, err := db.kvc.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 87 | if err != nil { |
| 88 | return "", err |
| 89 | } |
| 90 | if kv != nil { |
| 91 | return string(kv.Value.([]byte)), nil |
| 92 | } |
| 93 | return "", errors.New("Value not found") |
| 94 | } |
| 95 | |
| 96 | // Del to delete value from database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 97 | func (db *Database) Del(ctx context.Context, fullPath string) error { |
| 98 | if err := db.kvc.Delete(ctx, fullPath); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 99 | logger.Errorw(ctx, "The path doesn't exist", log.Fields{"key": fullPath, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 100 | return err |
| 101 | } |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | // DeleteAll to delete all value from database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 106 | func (db *Database) DeleteAll(ctx context.Context, fullPath string) error { |
| 107 | if err := db.kvc.DeleteWithPrefix(ctx, fullPath); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 108 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": fullPath, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 109 | return err |
| 110 | } |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | // DeleteAllUnderHashKey to delete all values under hash key |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 115 | func (db *Database) DeleteAllUnderHashKey(ctx context.Context, hashKeyPrefix string) error { |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 116 | kv, err := db.kvc.List(ctx, hashKeyPrefix) |
| 117 | if err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 118 | logger.Errorw(ctx, "The key path doesn't exist", log.Fields{"key": hashKeyPrefix, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 119 | return err |
| 120 | } |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 121 | for key := range kv { |
| 122 | if err := db.kvc.Delete(ctx, key); err != nil { |
| 123 | logger.Errorw(ctx, "Delete key from DB Failed", log.Fields{"key": key, "Error": err}) |
| 124 | } |
| 125 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 126 | return nil |
| 127 | } |
| 128 | |
| 129 | // List to list the values |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 130 | func (db *Database) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) { |
| 131 | kv, err := db.kvc.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 132 | if err != nil { |
| 133 | return nil, err |
| 134 | } |
| 135 | if kv != nil { |
| 136 | return kv, nil |
| 137 | } |
| 138 | return nil, errors.New("Value not found") |
| 139 | } |
| 140 | |
| 141 | // OLT specific database items |
| 142 | |
| 143 | // GetOlt to get olt info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 144 | func (db *Database) GetOlt(ctx context.Context, deviceID string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 145 | key := fmt.Sprintf(GetKeyPath(DevicePath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 146 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | // PutOlt to add olt info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 150 | func (db *Database) PutOlt(ctx context.Context, deviceID string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 151 | key := fmt.Sprintf(GetKeyPath(DevicePath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 152 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | // DelOlt to delete olt info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 156 | func (db *Database) DelOlt(ctx context.Context, deviceID string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 157 | key := fmt.Sprintf(GetKeyPath(DevicePath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 158 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 159 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 160 | return err |
| 161 | } |
| 162 | return nil |
| 163 | } |
| 164 | |
| 165 | // Flows specific database actions |
| 166 | |
| 167 | // PutFlow to add flow |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 168 | func (db *Database) PutFlow(ctx context.Context, deviceID string, flowID uint64, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 169 | key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) + strconv.FormatUint(flowID, 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 170 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // GetFlow to get flow |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 174 | func (db *Database) GetFlow(ctx context.Context, deviceID string, flowID uint64) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 175 | key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) + strconv.FormatUint(flowID, 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 176 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // GetFlows to get multiple flows |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 180 | func (db *Database) GetFlows(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 181 | key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 182 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | // DelFlow to delete flow |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 186 | func (db *Database) DelFlow(ctx context.Context, deviceID string, flowID uint64) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 187 | key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) + strconv.FormatUint(flowID, 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 188 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 189 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 190 | return err |
| 191 | } |
| 192 | return nil |
| 193 | } |
| 194 | |
| 195 | // Group specific database actions |
| 196 | |
| 197 | // PutGroup to add group info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 198 | func (db *Database) PutGroup(ctx context.Context, deviceID string, groupID uint32, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 199 | key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID) + strconv.FormatUint(uint64(groupID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 200 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | // GetGroup to get group info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 204 | func (db *Database) GetGroup(ctx context.Context, deviceID string, groupID uint32) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 205 | key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID) + strconv.FormatUint(uint64(groupID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 206 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | // GetGroups to get multiple group info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 210 | func (db *Database) GetGroups(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 211 | key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID) |
| 212 | logger.Infow(ctx, "key", log.Fields{"Key": key}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 213 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | // DelGroup to delete group info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 217 | func (db *Database) DelGroup(ctx context.Context, deviceID string, groupID uint32) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 218 | key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID) + strconv.FormatUint(uint64(groupID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 219 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 220 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 221 | return err |
| 222 | } |
| 223 | return nil |
| 224 | } |
| 225 | |
| 226 | // DelAllGroup to delete all group info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 227 | func (db *Database) DelAllGroup(ctx context.Context, deviceID string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 228 | key := fmt.Sprintf(GetKeyPath(DeviceGroupPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 229 | if err := db.DeleteAllUnderHashKey(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 230 | logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 231 | return err |
| 232 | } |
| 233 | logger.Infow(ctx, "Deleting all the groups for device", log.Fields{"device": deviceID}) |
| 234 | return nil |
| 235 | } |
| 236 | |
| 237 | // DelAllPorts to delete all ports info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 238 | func (db *Database) DelAllPorts(ctx context.Context, device string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 239 | key := fmt.Sprintf(GetKeyPath(DevicePortPath), device) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 240 | if err := db.DeleteAllUnderHashKey(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 241 | logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 242 | return err |
| 243 | } |
| 244 | logger.Infow(ctx, "Deleting all the ports for device", log.Fields{"device": device}) |
| 245 | return nil |
| 246 | } |
| 247 | |
| 248 | // Ports specific database actions |
| 249 | |
| 250 | // PutPort to add port info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 251 | func (db *Database) PutPort(ctx context.Context, deviceID string, portID uint32, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 252 | key := fmt.Sprintf(GetKeyPath(DevicePortPath), deviceID) + strconv.FormatUint(uint64(portID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 253 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | // GetPort to get port info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 257 | func (db *Database) GetPort(ctx context.Context, deviceID string, portID uint32) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 258 | key := fmt.Sprintf(GetKeyPath(DevicePortPath), deviceID) + strconv.FormatUint(uint64(portID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 259 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // GetPorts to get multiple ports info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 263 | func (db *Database) GetPorts(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 264 | key := fmt.Sprintf(GetKeyPath(DevicePortPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 265 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | // DelPort to delete port info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 269 | func (db *Database) DelPort(ctx context.Context, deviceID string, portID uint32) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 270 | key := fmt.Sprintf(GetKeyPath(DevicePortPath), deviceID) + strconv.FormatUint(uint64(portID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 271 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 272 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 273 | return err |
| 274 | } |
| 275 | return nil |
| 276 | } |
| 277 | |
| 278 | // Device meter specific database actions |
| 279 | |
| 280 | // PutDeviceMeter to add device meter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 281 | func (db *Database) PutDeviceMeter(ctx context.Context, deviceID string, meterID uint32, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 282 | key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), deviceID) + strconv.FormatUint(uint64(meterID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 283 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // GetDeviceMeter to get device meter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 287 | func (db *Database) GetDeviceMeter(ctx context.Context, deviceID string, meterID uint32) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 288 | key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), deviceID) + strconv.FormatUint(uint64(meterID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 289 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | // GetDeviceMeters to get multiple device meter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 293 | func (db *Database) GetDeviceMeters(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 294 | key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 295 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | // DelDeviceMeter to delete device meter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 299 | func (db *Database) DelDeviceMeter(ctx context.Context, deviceID string, meterID uint32) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 300 | key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), deviceID) + strconv.FormatUint(uint64(meterID), 10) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 301 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 302 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 303 | return err |
| 304 | } |
| 305 | return nil |
| 306 | } |
| 307 | |
| 308 | // Service specific database actions |
| 309 | |
| 310 | // GetServices to get multiple services info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 311 | func (db *Database) GetServices(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 312 | key := GetKeyPath(ServicePath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 313 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | // GetService to get service info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 317 | func (db *Database) GetService(ctx context.Context, name string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 318 | key := GetKeyPath(ServicePath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 319 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | // PutService to add service info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 323 | func (db *Database) PutService(ctx context.Context, name string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 324 | key := GetKeyPath(ServicePath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 325 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | // DelService to delete service info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 329 | func (db *Database) DelService(ctx context.Context, name string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 330 | key := GetKeyPath(ServicePath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 331 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 332 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 333 | return err |
| 334 | } |
| 335 | return nil |
| 336 | } |
| 337 | |
| 338 | // Virtual networks specific database actions |
| 339 | |
| 340 | // GetVnets to get multiple vnets info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 341 | func (db *Database) GetVnets(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 342 | key := GetKeyPath(VnetPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 343 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | // GetVnet to get vnet info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 347 | func (db *Database) GetVnet(ctx context.Context, name string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 348 | key := GetKeyPath(VnetPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 349 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | // PutVnet to add vnet info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 353 | func (db *Database) PutVnet(ctx context.Context, name string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 354 | key := GetKeyPath(VnetPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 355 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | // DelVnet to delete vnet info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 359 | func (db *Database) DelVnet(ctx context.Context, name string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 360 | key := GetKeyPath(VnetPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 361 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 362 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 363 | return err |
| 364 | } |
| 365 | return nil |
| 366 | } |
| 367 | |
| 368 | // Virtual networks on ports specific database actions |
| 369 | |
| 370 | // GetVpvs to get multiple vpvs info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 371 | func (db *Database) GetVpvs(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 372 | key := GetKeyPath(VpvPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 373 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | // GetVpv to get vpv info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 377 | func (db *Database) GetVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 378 | name := port + fmt.Sprintf("-%v-%v-%v", SVlan, CVlan, UniVlan) |
| 379 | key := GetKeyPath(VpvPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 380 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | // PutVpv to add vpv info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 384 | func (db *Database) PutVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 385 | name := port + fmt.Sprintf("-%v-%v-%v", SVlan, CVlan, UniVlan) |
| 386 | key := GetKeyPath(VpvPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 387 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | // DelVpv to delete vpv info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 391 | func (db *Database) DelVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 392 | name := port + fmt.Sprintf("-%v-%v-%v", SVlan, CVlan, UniVlan) |
| 393 | key := GetKeyPath(VpvPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 394 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 395 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 396 | return err |
| 397 | } |
| 398 | return nil |
| 399 | } |
| 400 | |
| 401 | // Virtual networks on ports specific database actions |
| 402 | |
| 403 | // GetMvlans to get multiple mvlans info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 404 | func (db *Database) GetMvlans(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 405 | key := GetKeyPath(MvlanPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 406 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | // GetMvlan to get mvlan info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 410 | func (db *Database) GetMvlan(ctx context.Context, mvlan uint16) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 411 | name := strconv.FormatInt(int64(mvlan), 10) |
| 412 | key := GetKeyPath(MvlanPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 413 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | // PutMvlan to add mvlan info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 417 | func (db *Database) PutMvlan(ctx context.Context, mvlan uint16, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 418 | name := strconv.FormatInt(int64(mvlan), 10) |
| 419 | key := GetKeyPath(MvlanPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 420 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | // DelMvlan to delete mvlan info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 424 | func (db *Database) DelMvlan(ctx context.Context, mvlan uint16) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 425 | name := strconv.FormatInt(int64(mvlan), 10) |
| 426 | key := GetKeyPath(MvlanPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 427 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 428 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 429 | return err |
| 430 | } |
| 431 | return nil |
| 432 | } |
| 433 | |
| 434 | // database specific actions on IGMP config |
| 435 | |
| 436 | // DelIGMPCfg to delete icmp config |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 437 | func (db *Database) DelIGMPCfg(ctx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 438 | key := GetKeyPath(IgmpConfPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 439 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 440 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 441 | return err |
| 442 | } |
| 443 | return nil |
| 444 | } |
| 445 | |
| 446 | // database specific actions on IGMP Profile |
| 447 | |
| 448 | // GetIgmpProfiles to get multiple igmp profile info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 449 | func (db *Database) GetIgmpProfiles(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 450 | key := GetKeyPath(IgmpProfPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 451 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | // GetIgmpProfile to get igmp profile info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 455 | func (db *Database) GetIgmpProfile(ctx context.Context, name string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 456 | key := GetKeyPath(IgmpProfPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 457 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // PutIgmpProfile to put igmp profile info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 461 | func (db *Database) PutIgmpProfile(ctx context.Context, name string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 462 | key := GetKeyPath(IgmpProfPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 463 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | // DelIgmpProfile to delete igmp profile |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 467 | func (db *Database) DelIgmpProfile(ctx context.Context, name string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 468 | key := GetKeyPath(IgmpProfPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 469 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 470 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 471 | return err |
| 472 | } |
| 473 | return nil |
| 474 | } |
| 475 | |
| 476 | // database specific actions on Mcast config Info |
| 477 | |
| 478 | // GetMcastConfigs to get multiple mcast config info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 479 | func (db *Database) GetMcastConfigs(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 480 | key := GetKeyPath(McastConfigPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 481 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | // GetMcastConfig to get igmp profile info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 485 | func (db *Database) GetMcastConfig(ctx context.Context, name string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 486 | key := GetKeyPath(McastConfigPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 487 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | // PutMcastConfig to put igmp profile info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 491 | func (db *Database) PutMcastConfig(ctx context.Context, name string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 492 | key := GetKeyPath(McastConfigPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 493 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | // DelMcastConfig to delete igmp profile |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 497 | func (db *Database) DelMcastConfig(ctx context.Context, name string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 498 | key := GetKeyPath(McastConfigPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 499 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 500 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 501 | return err |
| 502 | } |
| 503 | return nil |
| 504 | } |
| 505 | |
| 506 | // database specific actions on health |
| 507 | |
| 508 | // GetHealth to get health info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 509 | func (db *Database) GetHealth(ctx context.Context) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 510 | key := GetKeyPath(HealthPath) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 511 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | // PutHealth to add health info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 515 | func (db *Database) PutHealth(ctx context.Context, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 516 | key := GetKeyPath(HealthPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 517 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | // DelHealth to delete health info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 521 | func (db *Database) DelHealth(ctx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 522 | key := GetKeyPath(HealthPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 523 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 524 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 525 | return err |
| 526 | } |
| 527 | return nil |
| 528 | } |
| 529 | |
| 530 | // Meters |
| 531 | |
| 532 | // GetMeters to get multiple meters info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 533 | func (db *Database) GetMeters(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 534 | key := GetKeyPath(MeterPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 535 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | // GetMeter to get meter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 539 | func (db *Database) GetMeter(ctx context.Context, name string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 540 | key := GetKeyPath(MeterPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 541 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | // PutMeter to add meter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 545 | func (db *Database) PutMeter(ctx context.Context, name string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 546 | key := GetKeyPath(MeterPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 547 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | // DelMeter to delete meter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 551 | func (db *Database) DelMeter(ctx context.Context, name string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 552 | key := GetKeyPath(MeterPath) + name |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 553 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 554 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 555 | return err |
| 556 | } |
| 557 | return nil |
| 558 | } |
| 559 | |
| 560 | // DelAllMeter to delete meter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 561 | func (db *Database) DelAllMeter(ctx context.Context, device string) error { |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 562 | key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), device) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 563 | if err := db.DeleteAllUnderHashKey(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 564 | logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 565 | return err |
| 566 | } |
| 567 | logger.Infow(ctx, "Deleting all the meters for device", log.Fields{"device": device}) |
| 568 | return nil |
| 569 | } |
| 570 | |
| 571 | // IGMP groups |
| 572 | |
| 573 | // GetIgmpGroups to get multiple igmp groups info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 574 | func (db *Database) GetIgmpGroups(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 575 | key := GetKeyPath(IgmpGroupPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 576 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | // GetIgmpGroup to get igmp group info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 580 | func (db *Database) GetIgmpGroup(ctx context.Context, id string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 581 | key := GetKeyPath(IgmpGroupPath) + id |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 582 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | // PutIgmpGroup to add igmp group info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 586 | func (db *Database) PutIgmpGroup(ctx context.Context, id string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 587 | key := GetKeyPath(IgmpGroupPath) + id |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 588 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | // DelIgmpGroup to delete igmp group info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 592 | func (db *Database) DelIgmpGroup(ctx context.Context, id string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 593 | key := GetKeyPath(IgmpGroupPath) + id |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 594 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 595 | logger.Warnw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 596 | return err |
| 597 | } |
| 598 | return nil |
| 599 | } |
| 600 | |
| 601 | // IGMP group devices |
| 602 | |
| 603 | // GetAllIgmpDevices to get multiple igmp devices info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 604 | func (db *Database) GetAllIgmpDevices(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 605 | key := GetKeyPath(IgmpDevicePath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 606 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | // GetPrevIgmpDevices to get previous igmp devices |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 610 | func (db *Database) GetPrevIgmpDevices(ctx context.Context, mvlan of.VlanType, gid string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 611 | key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 612 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | // GetIgmpDevices to get igmp devices |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 616 | func (db *Database) GetIgmpDevices(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 617 | key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" + gip.String() + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 618 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | // GetIgmpDevice to get igmp device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 622 | func (db *Database) GetIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 623 | key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" + gip.String() + "/" + device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 624 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | // PutIgmpDevice to add igmp device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 628 | func (db *Database) PutIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 629 | key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" + gip.String() + "/" + device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 630 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | // DelIgmpDevice to delete igmp device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 634 | func (db *Database) DelIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 635 | key := GetKeyPath(IgmpDevicePath) + mvlan.String() + "/" + gid + "/" + gip.String() + "/" + device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 636 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 637 | logger.Warnw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 638 | return err |
| 639 | } |
| 640 | return nil |
| 641 | } |
| 642 | |
| 643 | // IGMP group channels |
| 644 | |
| 645 | // GetAllIgmpChannels to get all igmp channels |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 646 | func (db *Database) GetAllIgmpChannels(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 647 | key := GetKeyPath(IgmpChannelPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 648 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | // GetPrevIgmpChannels to get previous igmp channels |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 652 | func (db *Database) GetPrevIgmpChannels(ctx context.Context, gName, device string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 653 | key := GetKeyPath(IgmpChannelPath) + gName + "/" + device + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 654 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | // GetIgmpChannels to get multiple igmp channels |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 658 | func (db *Database) GetIgmpChannels(ctx context.Context, mvlan of.VlanType, gName, device string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 659 | key := GetKeyPath(IgmpChannelPath) + mvlan.String() + "/" + gName + "/" + device + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 660 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | // GetIgmpChannel to get igmp channel |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 664 | func (db *Database) GetIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 665 | key := GetKeyPath(IgmpChannelPath) + mvlan.String() + "/" + gName + "/" + device + "/" + gip.String() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 666 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | // PutIgmpChannel to add igmp channel info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 670 | func (db *Database) PutIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 671 | key := GetKeyPath(IgmpChannelPath) + mvlan.String() + "/" + gName + "/" + device + "/" + gip.String() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 672 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | // DelIgmpChannel to delete igmp channel info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 676 | func (db *Database) DelIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 677 | key := GetKeyPath(IgmpChannelPath) + mvlan.String() + "/" + gName + "/" + device + "/" + gip.String() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 678 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 679 | logger.Warnw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 680 | return err |
| 681 | } |
| 682 | return nil |
| 683 | } |
| 684 | |
| 685 | // IGMP group receivers |
| 686 | |
| 687 | // GetAllIgmpRcvrs to get all igmp receivers info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 688 | func (db *Database) GetAllIgmpRcvrs(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 689 | key := GetKeyPath(IgmpPortPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 690 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | // GetPrevIgmpRcvrs to get previous igmp receivers info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 694 | func (db *Database) GetPrevIgmpRcvrs(ctx context.Context, gip net.IP, device string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 695 | key := GetKeyPath(IgmpPortPath) + gip.String() + "/" + device + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 696 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | // GetIgmpRcvrs to get multiple igmp receivers info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 700 | func (db *Database) GetIgmpRcvrs(ctx context.Context, mvlan of.VlanType, gip net.IP, device string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 701 | key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 702 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | // GetIgmpRcvr to get igmp receiver info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 706 | func (db *Database) GetIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 707 | key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/" + rcvr |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 708 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | // PutIgmpRcvr to add igmp receiver info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 712 | func (db *Database) PutIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 713 | key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/" + rcvr |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 714 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | // DelIgmpRcvr to delete igmp receiver info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 718 | func (db *Database) DelIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 719 | key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/" + rcvr |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 720 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 721 | logger.Warnw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 722 | return err |
| 723 | } |
| 724 | return nil |
| 725 | } |
| 726 | |
| 727 | // DelAllIgmpRcvr to delete all igmp receiver info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 728 | func (db *Database) DelAllIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 729 | key := GetKeyPath(IgmpPortPath) + mvlan.String() + "/" + gip.String() + "/" + device + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 730 | if err := db.DeleteAll(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 731 | logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 732 | return err |
| 733 | } |
| 734 | return nil |
| 735 | } |
| 736 | |
| 737 | // DelAllRoutesForDevice to delete all routes for device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 738 | func (db *Database) DelAllRoutesForDevice(ctx context.Context, device string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 739 | /* service/vgc/v1/devices/<deviceID>/flows/ */ |
| 740 | logger.Infow(ctx, "Deleting all the flows for device", log.Fields{"device": device}) |
| 741 | key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), device) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 742 | if err := db.DeleteAllUnderHashKey(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 743 | logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 744 | return err |
| 745 | } |
| 746 | return nil |
| 747 | } |
| 748 | |
| 749 | // PutNbDevicePort to add device port info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 750 | func (db *Database) PutNbDevicePort(ctx context.Context, device string, ponPortID uint32, value string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 751 | key := GetKeyPath(NbDevicePath) + device + "/pon-port/" + fmt.Sprintf("%v", ponPortID) |
| 752 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 753 | if err := db.kvc.Put(ctx, key, value); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 754 | logger.Warnw(ctx, "Put Device Port failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 758 | // GetServices to get multiple services info |
| 759 | func (db *Database) GetDeviceConfig(ctx context.Context) (map[string]*kvstore.KVPair, error) { |
| 760 | key := GetKeyPath(DeviceConfigPath) |
| 761 | return db.List(ctx, key) |
| 762 | } |
| 763 | |
| 764 | // PutSBDeviceConfig to add device info |
| 765 | func (db *Database) PutDeviceConfig(ctx context.Context, serialNum string, value string) error { |
| 766 | key := GetKeyPath(DeviceConfigPath) + serialNum |
| 767 | |
| 768 | if err := db.kvc.Put(ctx, key, value); err != nil { |
| 769 | logger.Warnw(ctx, "Put Device Config failed", log.Fields{"key": key}) |
| 770 | return errorcodes.ErrFailedToUpdateDB |
| 771 | } |
| 772 | return nil |
| 773 | } |
| 774 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 775 | // DelNbDevicePort to delete device port |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 776 | func (db *Database) DelNbDevicePort(ctx context.Context, device string, ponPortID uint32) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 777 | key := GetKeyPath(NbDevicePath) + device + "/pon-port/" + fmt.Sprintf("%v", ponPortID) |
| 778 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 779 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 780 | logger.Warnw(ctx, "Delete Device Port failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
| 784 | // GetAllNbPorts to get all ports info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 785 | func (db *Database) GetAllNbPorts(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 786 | key := GetKeyPath(NbDevicePath) + deviceID + "/pon-port/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 787 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | //Functions for migration database |
| 791 | |
| 792 | // GetMigrationInfo to get migration info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 793 | func (db *Database) GetMigrationInfo(ctx context.Context) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 794 | key := GetKeyPath(MigrationInfoPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 795 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | // PutMigrationInfo to add migration info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 799 | func (db *Database) PutMigrationInfo(ctx context.Context, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 800 | key := GetKeyPath(MigrationInfoPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 801 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | // DelMigrationInfo to delete migration info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 805 | func (db *Database) DelMigrationInfo(ctx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 806 | key := GetKeyPath(MigrationInfoPath) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 807 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 808 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 809 | return err |
| 810 | } |
| 811 | return nil |
| 812 | } |
| 813 | |
| 814 | //PON counters |
| 815 | |
| 816 | // GetAllPonCounters to get all pon counters info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 817 | func (db *Database) GetAllPonCounters(ctx context.Context, device string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 818 | key := GetKeyPath(PonCounterPath) + device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 819 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | // GetPonCounter to get pon counter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 823 | func (db *Database) GetPonCounter(ctx context.Context, device, ponID string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 824 | key := GetKeyPath(PonCounterPath) + device + "/" + ponID |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 825 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | // PutPonCounter to add pon counter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 829 | func (db *Database) PutPonCounter(ctx context.Context, device, ponID, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 830 | key := GetKeyPath(PonCounterPath) + device + "/" + ponID |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 831 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | // DelPonCounter to delete pon counter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 835 | func (db *Database) DelPonCounter(ctx context.Context, device, ponID string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 836 | key := GetKeyPath(PonCounterPath) + device + "/" + ponID |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 837 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 838 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 839 | return err |
| 840 | } |
| 841 | return nil |
| 842 | } |
| 843 | |
| 844 | //PON Channel counters |
| 845 | |
| 846 | // GetAllPonChannelCounters to get all pon channel counters |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 847 | func (db *Database) GetAllPonChannelCounters(ctx context.Context, device, ponID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 848 | key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" + ChannelCounterPath |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 849 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | // GetPonChannelCounter to get pon channel counter |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 853 | func (db *Database) GetPonChannelCounter(ctx context.Context, device, ponID, channel string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 854 | key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" + ChannelCounterPath + channel |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 855 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | // PutPonChannelCounter to add pon channel counter |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 859 | func (db *Database) PutPonChannelCounter(ctx context.Context, device, ponID, channel, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 860 | key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" + ChannelCounterPath + channel |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 861 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | // DelPonChannelCounter to delete pon channel counter |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 865 | func (db *Database) DelPonChannelCounter(ctx context.Context, device, ponID, channel string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 866 | key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" + ChannelCounterPath + channel |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 867 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 868 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 869 | return err |
| 870 | } |
| 871 | return nil |
| 872 | } |
| 873 | |
| 874 | // DelAllPONCounters to delete all pon channel counters |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 875 | func (db *Database) DelAllPONCounters(ctx context.Context, device string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 876 | key := GetKeyPath(PonCounterPath) + device + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 877 | return db.DeleteAll(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | // DelPONCounters to delete pon counters |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 881 | func (db *Database) DelPONCounters(ctx context.Context, device string, ponID string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 882 | key := GetKeyPath(PonCounterPath) + device + "/" + ponID + "/" |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 883 | if err := db.DeleteAll(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 884 | logger.Warnw(ctx, "Delete Pon counters failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 885 | } |
| 886 | //DeletePonCounter(device, ponID) |
| 887 | } |
| 888 | |
| 889 | // PutOltIgmpCounters to add Olt Igmp counter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 890 | func (db *Database) PutOltIgmpCounters(ctx context.Context, device, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 891 | key := GetKeyPath(OltIgmpCounterPath) + device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 892 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | // GetOltIgmpCounter to get Olt Igmp counter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 896 | func (db *Database) GetOltIgmpCounter(ctx context.Context, device string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 897 | key := GetKeyPath(OltIgmpCounterPath) + device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 898 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | //Service Channel counters |
| 902 | |
| 903 | // GetAllServiceChannelCounters to get all service channel counters info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 904 | func (db *Database) GetAllServiceChannelCounters(ctx context.Context, serviceName string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 905 | key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 906 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | // GetServiceChannelCounter to get service channel counter info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 910 | func (db *Database) GetServiceChannelCounter(ctx context.Context, serviceName, channel string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 911 | key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath + channel |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 912 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | // PutServiceChannelCounter to add service channel counter |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 916 | func (db *Database) PutServiceChannelCounter(ctx context.Context, serviceName, channel, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 917 | key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath + channel |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 918 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | // DelServiceChannelCounter to delete service channel counter |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 922 | func (db *Database) DelServiceChannelCounter(ctx context.Context, serviceName, channel string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 923 | key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath + channel |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 924 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 925 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 926 | return err |
| 927 | } |
| 928 | return nil |
| 929 | } |
| 930 | |
| 931 | // DelAllServiceChannelCounter to delete all service channel counter |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 932 | func (db *Database) DelAllServiceChannelCounter(ctx context.Context, serviceName string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 933 | key := GetKeyPath(ServiceCounterPath) + serviceName + "/" + ChannelCounterPath |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 934 | return db.DeleteAllUnderHashKey(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | // OltExists to know if the ONU is added to the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 938 | func (db *Database) OltExists(ctx context.Context, deviceID string) bool { |
| 939 | if _, err := db.GetOlt(ctx, deviceID); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 940 | return false |
| 941 | } |
| 942 | return true |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | // PutFlowHash to add flowhash for the device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 946 | func (db *Database) PutFlowHash(ctx context.Context, deviceID string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 947 | key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 948 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | // GetFlowHash gets the flow hash for the device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 952 | func (db *Database) GetFlowHash(ctx context.Context, deviceID string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 953 | key := fmt.Sprintf(GetKeyPath(DeviceFlowPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 954 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | // PutPortAlarmProfile to add port alarm profile |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 958 | func (db *Database) PutPortAlarmProfile(ctx context.Context, portAlarmProfileID string, value string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 959 | key := GetKeyPath(PortAlarmProfilePath) + fmt.Sprintf("%v", portAlarmProfileID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 960 | if err := db.kvc.Put(ctx, key, value); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 961 | logger.Warnw(ctx, "Put PortAlarmProfile failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | |
| 965 | // DelPortAlarmProfile to delete port alarm profile |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 966 | func (db *Database) DelPortAlarmProfile(ctx context.Context, portAlarmProfileID string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 967 | key := GetKeyPath(PortAlarmProfilePath) + fmt.Sprintf("%v", portAlarmProfileID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 968 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 969 | logger.Warnw(ctx, "Delete PortAlarmProfile failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
| 973 | // GetPortAlarmProfile to get port alarm profile |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 974 | func (db *Database) GetPortAlarmProfile(ctx context.Context, portAlarmProfileID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 975 | key := GetKeyPath(PortAlarmProfilePath) + fmt.Sprintf("%v", portAlarmProfileID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 976 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | // PutPortAlarmData to add port alarm data |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 980 | func (db *Database) PutPortAlarmData(ctx context.Context, deviceID string, portID uint32, value string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 981 | key := fmt.Sprintf(GetKeyPath(PortAlarmDataPath), deviceID) + fmt.Sprintf("%v", portID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 982 | if err := db.kvc.Put(ctx, key, value); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 983 | logger.Warnw(ctx, "Put PortAlarmData failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | |
| 987 | // DelPortAlarmData to delete port alarm data |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 988 | func (db *Database) DelPortAlarmData(ctx context.Context, deviceID string, portID uint32) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 989 | key := fmt.Sprintf(GetKeyPath(PortAlarmDataPath), deviceID) + fmt.Sprintf("%v", portID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 990 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 991 | logger.Warnw(ctx, "Delete PortAlarmData failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
| 995 | // GetPortAlarmData to get port alarm data |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 996 | func (db *Database) GetPortAlarmData(ctx context.Context, deviceID string, portID uint32) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 997 | key := fmt.Sprintf(GetKeyPath(PortAlarmDataPath), deviceID) + fmt.Sprintf("%v", portID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 998 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | // GetAllPortAlarmData to get port alarm data for all ports |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1002 | func (db *Database) GetAllPortAlarmData(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1003 | key := fmt.Sprintf(GetKeyPath(PortAlarmDataPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1004 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | // PutSubAlarmData to add subscriber alarm data |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1008 | func (db *Database) PutSubAlarmData(ctx context.Context, deviceID string, portName string, value string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1009 | key := fmt.Sprintf(GetKeyPath(SubAlarmDataPath), deviceID) + fmt.Sprintf("%v", portName) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1010 | if err := db.kvc.Put(ctx, key, value); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 1011 | logger.Warnw(ctx, "Put Subscriber AlarmData failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | // DelSubAlarmData to delete subscriber alarm data |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1016 | func (db *Database) DelSubAlarmData(ctx context.Context, deviceID string, portName string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1017 | key := fmt.Sprintf(GetKeyPath(SubAlarmDataPath), deviceID) + fmt.Sprintf("%v", portName) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1018 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 1019 | logger.Warnw(ctx, "Delete Subscriber AlarmData failed", log.Fields{"key": key}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | // GetSubAlarmData to get subscriber alarm data |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1024 | func (db *Database) GetSubAlarmData(ctx context.Context, deviceID string, portName string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1025 | key := fmt.Sprintf(GetKeyPath(SubAlarmDataPath), deviceID) + fmt.Sprintf("%v", portName) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1026 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | // GetAllSubAlarmData to get sub alarm data for all subscribers |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1030 | func (db *Database) GetAllSubAlarmData(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1031 | key := fmt.Sprintf(GetKeyPath(SubAlarmDataPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1032 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | // Migrate Service req specific database actions |
| 1036 | |
| 1037 | // PutMigrateServicesReq to add MigrateServicesReq info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1038 | func (db *Database) PutMigrateServicesReq(ctx context.Context, deviceID string, vnet string, value string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1039 | key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID) + vnet |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1040 | return db.kvc.Put(ctx, key, value) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | // GetMigrateServicesReq to get MigrateServicesReq info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1044 | func (db *Database) GetMigrateServicesReq(ctx context.Context, deviceID string, vnet string) (string, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1045 | key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID) + vnet |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1046 | return db.Get(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | // GetAllMigrateServicesReq to get multiple MigrateServicesReq info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1050 | func (db *Database) GetAllMigrateServicesReq(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1051 | key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1052 | return db.List(ctx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | // DelMigrateServicesReq to delete MigrateServicesReq info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1056 | func (db *Database) DelMigrateServicesReq(ctx context.Context, deviceID string, vnet string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1057 | key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID) + vnet |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1058 | if err := db.kvc.Delete(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 1059 | logger.Errorw(ctx, "The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1060 | return err |
| 1061 | } |
| 1062 | return nil |
| 1063 | } |
| 1064 | |
| 1065 | // DelAllMigrateServicesReq to delete all MigrateServicesReq info |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1066 | func (db *Database) DelAllMigrateServicesReq(ctx context.Context, deviceID string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1067 | key := fmt.Sprintf(GetKeyPath(ServicesMigrateReqPath), deviceID) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1068 | if err := db.DeleteAllUnderHashKey(ctx, key); err != nil { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 1069 | logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1070 | return err |
| 1071 | } |
| 1072 | logger.Infow(ctx, "Deleting all the Update Vnet Requests for device", log.Fields{"device": deviceID}) |
| 1073 | return nil |
| 1074 | } |
Akash Soni | dedc8ee | 2023-03-03 11:51:49 +0530 | [diff] [blame] | 1075 | |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 1076 | // PutOltFlowService to add OltFlowService info |
| 1077 | func (db *Database) PutOltFlowService(ctx context.Context, value string) error { |
| 1078 | key := GetKeyPath(OltFlowServicePath) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1079 | |
Akash Soni | dedc8ee | 2023-03-03 11:51:49 +0530 | [diff] [blame] | 1080 | if err := db.kvc.Put(ctx, key, value); err != nil { |
| 1081 | logger.Warnw(ctx, "Put OltFlowService failed", log.Fields{"key": key}) |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 1082 | return err |
Akash Soni | dedc8ee | 2023-03-03 11:51:49 +0530 | [diff] [blame] | 1083 | } |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 1084 | return nil |
| 1085 | } |
| 1086 | |
| 1087 | // GetOltFlowService to get OltFlowService info |
| 1088 | func (db *Database) GetOltFlowService(ctx context.Context) (string, error) { |
| 1089 | key := GetKeyPath(OltFlowServicePath) |
| 1090 | return db.Get(ctx, key) |
| 1091 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1092 | func init() { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1093 | // Setup this package so that it's log level can be modified at run time |
| 1094 | var err error |
| 1095 | logger, err = log.AddPackageWithDefaultParam() |
| 1096 | if err != nil { |
| 1097 | panic(err) |
| 1098 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1099 | } |