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