blob: ea8f3b642fd6a828d5cea60742a164434edf0c30 [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.
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
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
32//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
34const (
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/"
Naveen Sampath04696f72022-06-13 15:19:14 +053067)
68
69//PresentVersionMap - map of present version for all database tables
70var PresentVersionMap = map[string]string{
71 ServicePath: "v3",
72 DevicePath: "v1",
73 DevicePortPath: "v1",
74 DeviceFlowPath: "v1",
75 DeviceGroupPath: "v1",
76 DeviceMeterPath: "v1",
77 VnetPath: "v3",
78 VpvPath: "v3",
79 MvlanPath: "v3",
80 MeterPath: "v1",
81 IgmpConfPath: "v2",
82 IgmpGroupPath: "v1",
83 IgmpDevicePath: "v1",
84 IgmpChannelPath: "v1",
85 IgmpPortPath: "v1",
86 IgmpProfPath: "v1",
87 McastConfigPath: "v1",
88 MigrationInfoPath: "v1",
89 LogLevelPath: "v1",
90 HealthPath: "v1",
91 PonCounterPath: "v1",
92 OltIgmpCounterPath: "v1",
93 ChannelCounterPath: "v1",
94 ServiceCounterPath: "v1",
95 NbDevicePath: "v1",
96 DeviceFlowHashPath: "v1",
97 PortAlarmProfilePath: "v1",
98 PortAlarmDataPath: "v1",
99 SubAlarmDataPath: "v1",
100 ServicesMigrateReqPath: "v1",
Tinoj Joseph4ead4e02023-01-30 03:12:44 +0530101 OltFlowServicePath: "v1",
Naveen Sampath04696f72022-06-13 15:19:14 +0530102}
103
104//PreviousVersionMap - map of previous version for all database tables
105var PreviousVersionMap = map[string]string{
106 ServicePath: "v2",
107 DevicePath: "v1",
108 DevicePortPath: "v1",
109 DeviceFlowPath: "v1",
110 DeviceGroupPath: "v1",
111 DeviceMeterPath: "v1",
112 VnetPath: "v2",
113 VpvPath: "v2",
114 MvlanPath: "v2",
115 MeterPath: "v1",
116 IgmpConfPath: "v1",
117 IgmpGroupPath: "v1",
118 IgmpDevicePath: "v1",
119 IgmpChannelPath: "v1",
120 IgmpPortPath: "v1",
121 IgmpProfPath: "v1",
122 McastConfigPath: "v1",
123 MigrationInfoPath: "v1",
124 LogLevelPath: "v1",
125 HealthPath: "v1",
126 PonCounterPath: "v1",
127 OltIgmpCounterPath: "v1",
128 ChannelCounterPath: "v1",
129 ServiceCounterPath: "v1",
130 NbDevicePath: "v1",
131 DeviceFlowHashPath: "v1",
132 PortAlarmProfilePath: "v1",
133 PortAlarmDataPath: "v1",
134 SubAlarmDataPath: "v1",
135 ServicesMigrateReqPath: "v1",
Tinoj Joseph4ead4e02023-01-30 03:12:44 +0530136 OltFlowServicePath: "v1",
Naveen Sampath04696f72022-06-13 15:19:14 +0530137}
138
139//DBVersionMap - Version of tables present in DB
140var DBVersionMap = PreviousVersionMap
141
142// GetModuleKeypath returns the DB keypath for particular module along with version
143func GetModuleKeypath(key, ver string) string {
144 return fmt.Sprintf(BasePath, ver) + key
145}
146
147// GetKeyPath returns the base path for the given key along with version
148func GetKeyPath(key string) string {
149 return fmt.Sprintf(BasePath, PresentVersionMap[key]) + key
150}