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