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