blob: 6b5117c1f2b4823ad8a57729db3277585f3d9d3c [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
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 Sonia8246972023-01-03 10:37:08 +053014 */
Naveen Sampath04696f72022-06-13 15:19:14 +053015// 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
20package database
21
22import "fmt"
23
24const (
25 // PresentVersion represnts the Present version
26 // Modify this as we give Major version releases
27 PresentVersion = "v1"
28 // PreviousVersion represnts the Previous version
29 PreviousVersion = "v1"
30)
31
vinokuma926cb3e2023-03-29 11:41:06 +053032// These are present path where different database elements are store in database
33// In case any of these paths change, update the present and previous version
Naveen Sampath04696f72022-06-13 15:19:14 +053034const (
35 BasePath string = "service/vgc/%s/"
36 ServicePath string = "services/"
37 DevicePath string = "devices/%s/"
38 DevicePortPath string = DevicePath + "ports/"
39 DeviceFlowPath string = DevicePath + "flows/"
40 DeviceGroupPath string = DevicePath + "groups/"
41 DeviceMeterPath string = DevicePath + "meters/"
42 VnetPath string = "vnets/"
43 VpvPath string = "vpvs/"
44 MvlanPath string = "mvlans/"
45 MeterPath string = "meters/"
46 IgmpConfPath string = "igmp/conf/"
47 IgmpGroupPath string = "igmp/groups/"
48 IgmpDevicePath string = "igmp/devices/"
49 IgmpChannelPath string = "igmp/channels/"
50 IgmpPortPath string = "igmp/ports/"
51 IgmpProfPath string = "igmp/prof/"
52 McastConfigPath string = "igmp/mcastconfig/"
53 MigrationInfoPath string = "data/migration/"
54 LogLevelPath string = "log-level/"
55 HealthPath string = "health/"
56 PonCounterPath string = "pon-counter/"
57 OltIgmpCounterPath string = "olt-igmp-counter/"
58 ChannelCounterPath string = "channel-counter/"
59 ServiceCounterPath string = "service-counter/"
60 NbDevicePath string = "nb-device/"
61 DeviceFlowHashPath string = DevicePath + "flowhash"
62 PortAlarmProfilePath string = "port-alarm-profile/"
63 PortAlarmDataPath string = DevicePortPath + "portalarmdata/"
64 SubAlarmDataPath string = DevicePath + "sub-alarm-data/"
65 ServicesMigrateReqPath string = DevicePath + "migrateServicesReq/"
Tinoj Joseph4ead4e02023-01-30 03:12:44 +053066 OltFlowServicePath string = "olt-flow-service/"
Akash Sonia8246972023-01-03 10:37:08 +053067 DeviceConfigPath string = "device-config/"
Naveen Sampath04696f72022-06-13 15:19:14 +053068)
69
vinokuma926cb3e2023-03-29 11:41:06 +053070// PresentVersionMap - map of present version for all database tables
Naveen Sampath04696f72022-06-13 15:19:14 +053071var PresentVersionMap = map[string]string{
72 ServicePath: "v3",
73 DevicePath: "v1",
74 DevicePortPath: "v1",
75 DeviceFlowPath: "v1",
76 DeviceGroupPath: "v1",
77 DeviceMeterPath: "v1",
78 VnetPath: "v3",
79 VpvPath: "v3",
80 MvlanPath: "v3",
81 MeterPath: "v1",
82 IgmpConfPath: "v2",
83 IgmpGroupPath: "v1",
84 IgmpDevicePath: "v1",
85 IgmpChannelPath: "v1",
86 IgmpPortPath: "v1",
87 IgmpProfPath: "v1",
88 McastConfigPath: "v1",
89 MigrationInfoPath: "v1",
90 LogLevelPath: "v1",
91 HealthPath: "v1",
92 PonCounterPath: "v1",
93 OltIgmpCounterPath: "v1",
94 ChannelCounterPath: "v1",
95 ServiceCounterPath: "v1",
96 NbDevicePath: "v1",
97 DeviceFlowHashPath: "v1",
98 PortAlarmProfilePath: "v1",
99 PortAlarmDataPath: "v1",
100 SubAlarmDataPath: "v1",
101 ServicesMigrateReqPath: "v1",
Tinoj Joseph4ead4e02023-01-30 03:12:44 +0530102 OltFlowServicePath: "v1",
Akash Sonia8246972023-01-03 10:37:08 +0530103 DeviceConfigPath: "v1",
Naveen Sampath04696f72022-06-13 15:19:14 +0530104}
105
vinokuma926cb3e2023-03-29 11:41:06 +0530106// PreviousVersionMap - map of previous version for all database tables
Naveen Sampath04696f72022-06-13 15:19:14 +0530107var PreviousVersionMap = map[string]string{
108 ServicePath: "v2",
109 DevicePath: "v1",
110 DevicePortPath: "v1",
111 DeviceFlowPath: "v1",
112 DeviceGroupPath: "v1",
113 DeviceMeterPath: "v1",
114 VnetPath: "v2",
115 VpvPath: "v2",
116 MvlanPath: "v2",
117 MeterPath: "v1",
118 IgmpConfPath: "v1",
119 IgmpGroupPath: "v1",
120 IgmpDevicePath: "v1",
121 IgmpChannelPath: "v1",
122 IgmpPortPath: "v1",
123 IgmpProfPath: "v1",
124 McastConfigPath: "v1",
125 MigrationInfoPath: "v1",
126 LogLevelPath: "v1",
127 HealthPath: "v1",
128 PonCounterPath: "v1",
129 OltIgmpCounterPath: "v1",
130 ChannelCounterPath: "v1",
131 ServiceCounterPath: "v1",
132 NbDevicePath: "v1",
133 DeviceFlowHashPath: "v1",
134 PortAlarmProfilePath: "v1",
135 PortAlarmDataPath: "v1",
136 SubAlarmDataPath: "v1",
137 ServicesMigrateReqPath: "v1",
Tinoj Joseph4ead4e02023-01-30 03:12:44 +0530138 OltFlowServicePath: "v1",
Akash Sonia8246972023-01-03 10:37:08 +0530139 DeviceConfigPath: "v1",
Naveen Sampath04696f72022-06-13 15:19:14 +0530140}
141
vinokuma926cb3e2023-03-29 11:41:06 +0530142// DBVersionMap - Version of tables present in DB
Naveen Sampath04696f72022-06-13 15:19:14 +0530143var DBVersionMap = PreviousVersionMap
144
145// GetModuleKeypath returns the DB keypath for particular module along with version
146func GetModuleKeypath(key, ver string) string {
147 return fmt.Sprintf(BasePath, ver) + key
148}
149
150// GetKeyPath returns the base path for the given key along with version
151func GetKeyPath(key string) string {
152 return fmt.Sprintf(BasePath, PresentVersionMap[key]) + key
153}