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. |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 14 | */ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 15 | |
| 16 | package database |
| 17 | |
| 18 | import ( |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 19 | "context" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 20 | "net" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 21 | |
| 22 | "voltha-go-controller/internal/pkg/of" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 23 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 25 | ) |
| 26 | |
| 27 | var dbObj DBIntf |
| 28 | |
| 29 | // DBIntf defines db related methods |
| 30 | type DBIntf interface { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 31 | Get(ctx context.Context, key string) (string, error) |
| 32 | Put(ctx context.Context, fullKeyPath string, value string) error |
| 33 | Del(ctx context.Context, path string) error |
| 34 | List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) |
| 35 | DeleteAll(ctx context.Context, path string) error |
| 36 | DeleteAllUnderHashKey(ctx context.Context, hashKeyPrefix string) error |
| 37 | GetOlt(ctx context.Context, deviceID string) (string, error) |
| 38 | PutOlt(ctx context.Context, deviceID string, value string) error |
| 39 | DelOlt(ctx context.Context, deviceID string) error |
| 40 | GetFlow(ctx context.Context, deviceID string, flowID uint64) (string, error) |
| 41 | GetFlows(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) |
| 42 | PutFlow(ctx context.Context, deviceID string, flowID uint64, value string) error |
| 43 | DelFlow(ctx context.Context, deviceID string, flowID uint64) error |
| 44 | PutGroup(ctx context.Context, deviceID string, groupID uint32, value string) error |
| 45 | GetGroup(ctx context.Context, deviceID string, groupID uint32) (string, error) |
| 46 | GetGroups(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) |
| 47 | DelGroup(ctx context.Context, deviceID string, groupID uint32) error |
| 48 | DelAllGroup(ctx context.Context, deviceID string) error |
| 49 | DelAllPorts(ctx context.Context, deviceID string) error |
| 50 | DelPort(ctx context.Context, deviceID string, portID uint32) error |
| 51 | PutPort(ctx context.Context, deviceID string, portID uint32, value string) error |
| 52 | GetPort(ctx context.Context, deviceID string, portID uint32) (string, error) |
| 53 | GetPorts(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) |
| 54 | PutDeviceMeter(ctx context.Context, deviceID string, meterID uint32, value string) error |
| 55 | GetDeviceMeter(ctx context.Context, deviceID string, meterID uint32) (string, error) |
| 56 | GetDeviceMeters(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) |
| 57 | DelDeviceMeter(ctx context.Context, deviceID string, meterID uint32) error |
| 58 | GetService(ctx context.Context, name string) (string, error) |
| 59 | GetServices(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 60 | PutService(ctx context.Context, name string, value string) error |
| 61 | DelService(ctx context.Context, name string) error |
| 62 | GetVnets(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 63 | GetVnet(ctx context.Context, name string) (string, error) |
| 64 | PutVnet(ctx context.Context, name string, value string) error |
| 65 | DelVnet(ctx context.Context, name string) error |
| 66 | GetVpvs(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 67 | GetVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16) (string, error) |
| 68 | PutVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16, value string) error |
| 69 | DelVpv(ctx context.Context, port string, SVlan uint16, CVlan uint16, UniVlan uint16) error |
| 70 | GetMvlans(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 71 | GetMvlan(ctx context.Context, mvlan uint16) (string, error) |
| 72 | PutMvlan(ctx context.Context, mvlan uint16, value string) error |
| 73 | DelMvlan(ctx context.Context, mvlan uint16) error |
| 74 | DelIGMPCfg(ctx context.Context) error |
| 75 | GetHealth(ctx context.Context) (string, error) |
| 76 | PutHealth(ctx context.Context, value string) error |
| 77 | DelHealth(ctx context.Context) error |
| 78 | GetMeters(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 79 | GetMeter(ctx context.Context, name string) (string, error) |
| 80 | PutMeter(ctx context.Context, name string, value string) error |
| 81 | DelMeter(ctx context.Context, name string) error |
| 82 | DelAllMeter(ctx context.Context, device string) error |
| 83 | GetIgmpGroups(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 84 | GetIgmpGroup(ctx context.Context, id string) (string, error) |
| 85 | PutIgmpGroup(ctx context.Context, id string, value string) error |
| 86 | DelIgmpGroup(ctx context.Context, id string) error |
| 87 | GetAllIgmpDevices(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 88 | GetPrevIgmpDevices(ctx context.Context, mvlan of.VlanType, gid string) (map[string]*kvstore.KVPair, error) |
| 89 | GetIgmpDevices(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP) (map[string]*kvstore.KVPair, error) |
| 90 | GetIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string) (string, error) |
| 91 | PutIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string, value string) error |
| 92 | DelIgmpDevice(ctx context.Context, mvlan of.VlanType, gid string, gip net.IP, device string) error |
| 93 | GetAllIgmpChannels(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 94 | GetPrevIgmpChannels(ctx context.Context, gname string, device string) (map[string]*kvstore.KVPair, error) |
| 95 | GetIgmpChannels(ctx context.Context, mvlan of.VlanType, gname string, device string) (map[string]*kvstore.KVPair, error) |
| 96 | GetIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP) (string, error) |
| 97 | PutIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP, value string) error |
| 98 | DelIgmpChannel(ctx context.Context, mvlan of.VlanType, gName string, device string, gip net.IP) error |
| 99 | GetAllIgmpRcvrs(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 100 | GetPrevIgmpRcvrs(ctx context.Context, gip net.IP, device string) (map[string]*kvstore.KVPair, error) |
| 101 | GetIgmpRcvrs(ctx context.Context, mvlan of.VlanType, gip net.IP, device string) (map[string]*kvstore.KVPair, error) |
| 102 | GetIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string) (string, error) |
| 103 | PutIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string, value string) error |
| 104 | DelIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string, rcvr string) error |
| 105 | DelAllIgmpRcvr(ctx context.Context, mvlan of.VlanType, gip net.IP, device string) error |
| 106 | DelAllRoutesForDevice(ctx context.Context, device string) error |
| 107 | DelNbDevicePort(ctx context.Context, device string, ponPortID uint32) |
| 108 | GetAllNbPorts(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) |
| 109 | GetMigrationInfo(ctx context.Context) (string, error) |
| 110 | PutMigrationInfo(ctx context.Context, value string) error |
| 111 | DelMigrationInfo(ctx context.Context) error |
| 112 | GetAllPonCounters(ctx context.Context, device string) (map[string]*kvstore.KVPair, error) |
| 113 | GetPonCounter(ctx context.Context, device string, ponID string) (string, error) |
| 114 | PutPonCounter(ctx context.Context, device string, ponID string, value string) error |
| 115 | DelPonCounter(ctx context.Context, device string, ponID string) error |
| 116 | GetAllPonChannelCounters(ctx context.Context, device string, ponID string) (map[string]*kvstore.KVPair, error) |
| 117 | GetPonChannelCounter(ctx context.Context, device string, ponID string, channel string) (string, error) |
| 118 | PutNbDevicePort(ctx context.Context, device string, ponPortID uint32, value string) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 119 | GetDeviceConfig(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 120 | PutDeviceConfig(ctx context.Context, serialNum string, value string) error |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 121 | PutPonChannelCounter(ctx context.Context, device string, ponID string, channel string, value string) error |
| 122 | DelPonChannelCounter(ctx context.Context, device string, ponID string, channel string) error |
| 123 | DelAllPONCounters(ctx context.Context, device string) error |
| 124 | DelPONCounters(ctx context.Context, device string, ponID string) |
| 125 | GetAllServiceChannelCounters(ctx context.Context, serviceName string) (map[string]*kvstore.KVPair, error) |
| 126 | GetServiceChannelCounter(ctx context.Context, serviceName string, channel string) (string, error) |
| 127 | PutServiceChannelCounter(ctx context.Context, serviceName string, channel string, value string) error |
| 128 | DelServiceChannelCounter(ctx context.Context, serviceName string, channel string) error |
| 129 | DelAllServiceChannelCounter(ctx context.Context, serviceName string) error |
| 130 | PutOltIgmpCounters(ctx context.Context, device string, value string) error |
| 131 | GetOltIgmpCounter(ctx context.Context, device string) (string, error) |
| 132 | PutFlowHash(ctx context.Context, deviceID string, value string) error |
| 133 | GetFlowHash(ctx context.Context, deviceID string) (string, error) |
| 134 | OltExists(ctx context.Context, deviceID string) bool |
| 135 | GetIgmpProfiles(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 136 | GetIgmpProfile(ctx context.Context, name string) (string, error) |
| 137 | PutIgmpProfile(ctx context.Context, name string, value string) error |
| 138 | DelIgmpProfile(ctx context.Context, name string) error |
| 139 | GetMcastConfigs(ctx context.Context) (map[string]*kvstore.KVPair, error) |
| 140 | GetMcastConfig(ctx context.Context, name string) (string, error) |
| 141 | PutMcastConfig(ctx context.Context, name string, value string) error |
| 142 | DelMcastConfig(ctx context.Context, name string) error |
| 143 | PutPortAlarmProfile(ctx context.Context, portAlarmProfileID string, value string) |
| 144 | GetPortAlarmProfile(ctx context.Context, portAlarmProfileID string) (map[string]*kvstore.KVPair, error) |
| 145 | DelPortAlarmProfile(ctx context.Context, portAlarmProfileID string) |
| 146 | PutPortAlarmData(ctx context.Context, deviceID string, portID uint32, value string) |
| 147 | GetPortAlarmData(ctx context.Context, deviceID string, portID uint32) (string, error) |
| 148 | DelPortAlarmData(ctx context.Context, deviceID string, portID uint32) |
| 149 | GetAllPortAlarmData(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) |
| 150 | PutSubAlarmData(ctx context.Context, deviceID string, portName string, value string) |
| 151 | GetSubAlarmData(ctx context.Context, deviceID string, portName string) (string, error) |
| 152 | DelSubAlarmData(ctx context.Context, deviceID string, portName string) |
| 153 | GetAllSubAlarmData(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) |
| 154 | PutMigrateServicesReq(ctx context.Context, deviceID string, vlan string, value string) error |
| 155 | GetMigrateServicesReq(ctx context.Context, deviceID string, vlan string) (string, error) |
| 156 | GetAllMigrateServicesReq(ctx context.Context, deviceID string) (map[string]*kvstore.KVPair, error) |
| 157 | DelMigrateServicesReq(ctx context.Context, deviceID string, vlan string) error |
| 158 | DelAllMigrateServicesReq(ctx context.Context, deviceID string) error |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 159 | PutOltFlowService(ctx context.Context, value string) error |
| 160 | GetOltFlowService(ctx context.Context) (string, error) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 161 | } |
| 162 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 163 | // GetDatabase - returns databse operation based on configuration |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 164 | func GetDatabase() DBIntf { |
| 165 | return dbObj |
| 166 | } |
| 167 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 168 | // SetDatabase - sets the DB object based on the type |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 169 | func SetDatabase(df DBIntf) { |
| 170 | dbObj = df |
| 171 | } |