Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 17 | //Package resourcemanager provides the utility for managing resources |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 18 | package resourcemanager |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 21 | "encoding/json" |
| 22 | "errors" |
| 23 | "fmt" |
| 24 | "strconv" |
| 25 | "strings" |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 26 | |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 27 | "github.com/opencord/voltha-lib-go/v2/pkg/db" |
Scott Baker | 5129015 | 2019-10-24 14:23:20 -0700 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v2/pkg/db/kvstore" |
Scott Baker | 5129015 | 2019-10-24 14:23:20 -0700 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 30 | ponrmgr "github.com/opencord/voltha-lib-go/v2/pkg/ponresourcemanager" |
Scott Baker | c6e54cb | 2019-11-04 09:31:25 -0800 | [diff] [blame] | 31 | ofp "github.com/opencord/voltha-protos/v2/go/openflow_13" |
| 32 | "github.com/opencord/voltha-protos/v2/go/openolt" |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 33 | ) |
| 34 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 35 | const ( |
| 36 | // KvstoreTimeout specifies the time out for KV Store Connection |
| 37 | KvstoreTimeout = 5 |
| 38 | // BasePathKvStore - service/voltha/openolt/<device_id> |
| 39 | BasePathKvStore = "service/voltha/openolt/{%s}" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 40 | // TpIDPathSuffix - <(pon_id, onu_id, uni_id)>/tp_id |
| 41 | TpIDPathSuffix = "{%d,%d,%d}/tp_id" |
| 42 | //MeterIDPathSuffix - <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| 43 | MeterIDPathSuffix = "{%d,%d,%d}/{%d}/meter_id/{%s}" |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 44 | //NnniIntfID - nniintfids |
| 45 | NnniIntfID = "nniintfids" |
| 46 | // OnuPacketINPath path on the kvstore to store packetin gemport,which will be used for packetin, pcketout |
| 47 | //format: onu_packetin/<intfid>,<onuid>,<logicalport> |
| 48 | OnuPacketINPath = "onu_packetin/{%d,%d,%d}" |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 49 | //FlowIDsForGem flowids_per_gem/<intfid> |
| 50 | FlowIDsForGem = "flowids_per_gem/{%d}" |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 51 | ) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 52 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 53 | // FlowInfo holds the flow information |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 54 | type FlowInfo struct { |
| 55 | Flow *openolt.Flow |
| 56 | FlowStoreCookie uint64 |
| 57 | FlowCategory string |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 58 | LogicalFlowID uint64 |
| 59 | } |
| 60 | |
| 61 | // OnuGemInfo holds onu information along with gem port list and uni port list |
| 62 | type OnuGemInfo struct { |
| 63 | OnuID uint32 |
| 64 | SerialNumber string |
| 65 | IntfID uint32 |
| 66 | GemPorts []uint32 |
| 67 | UniPorts []uint32 |
| 68 | } |
| 69 | |
| 70 | // PacketInInfoKey is the key for packet in gemport |
| 71 | type PacketInInfoKey struct { |
| 72 | IntfID uint32 |
| 73 | OnuID uint32 |
| 74 | LogicalPort uint32 |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 75 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 76 | |
| 77 | // OpenOltResourceMgr holds resource related information as provided below for each field |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 78 | type OpenOltResourceMgr struct { |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 79 | DeviceID string // OLT device id |
| 80 | HostAndPort string // Host and port of the kv store to connect to |
| 81 | Args string // args |
| 82 | KVStore *db.Backend // backend kv store connection handle |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 83 | DeviceType string |
| 84 | Host string // Host ip of the kv store |
| 85 | Port int // port of the kv store |
| 86 | DevInfo *openolt.DeviceInfo // device information |
| 87 | // array of pon resource managers per interface technology |
| 88 | ResourceMgrs map[uint32]*ponrmgr.PONResourceManager |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 89 | } |
| 90 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 91 | func newKVClient(storeType string, address string, timeout uint32) (kvstore.Client, error) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 92 | log.Infow("kv-store-type", log.Fields{"store": storeType}) |
| 93 | switch storeType { |
| 94 | case "consul": |
| 95 | return kvstore.NewConsulClient(address, int(timeout)) |
| 96 | case "etcd": |
| 97 | return kvstore.NewEtcdClient(address, int(timeout)) |
| 98 | } |
| 99 | return nil, errors.New("unsupported-kv-store") |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 100 | } |
| 101 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 102 | // SetKVClient sets the KV client and return a kv backend |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 103 | func SetKVClient(backend string, Host string, Port int, DeviceID string) *db.Backend { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 104 | addr := Host + ":" + strconv.Itoa(Port) |
| 105 | // TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some |
| 106 | // issue between kv store and backend , core is not calling NewBackend directly |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 107 | kvClient, err := newKVClient(backend, addr, KvstoreTimeout) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 108 | if err != nil { |
| 109 | log.Fatalw("Failed to init KV client\n", log.Fields{"err": err}) |
| 110 | return nil |
| 111 | } |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 112 | kvbackend := &db.Backend{ |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 113 | Client: kvClient, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 114 | StoreType: backend, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 115 | Host: Host, |
| 116 | Port: Port, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 117 | Timeout: KvstoreTimeout, |
| 118 | PathPrefix: fmt.Sprintf(BasePathKvStore, DeviceID)} |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 119 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 120 | return kvbackend |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 121 | } |
| 122 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 123 | // NewResourceMgr init a New resource manager instance which in turn instantiates pon resource manager |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 124 | // instances according to technology. Initializes the default resource ranges for all |
| 125 | // the resources. |
| 126 | func NewResourceMgr(deviceID string, KVStoreHostPort string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo) *OpenOltResourceMgr { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 127 | var ResourceMgr OpenOltResourceMgr |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 128 | log.Debugf("Init new resource manager , host_port: %s, deviceid: %s", KVStoreHostPort, deviceID) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 129 | ResourceMgr.HostAndPort = KVStoreHostPort |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 130 | ResourceMgr.DeviceType = deviceType |
| 131 | ResourceMgr.DevInfo = devInfo |
| 132 | IPPort := strings.Split(KVStoreHostPort, ":") |
| 133 | ResourceMgr.Host = IPPort[0] |
| 134 | ResourceMgr.Port, _ = strconv.Atoi(IPPort[1]) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 135 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 136 | Backend := kvStoreType |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 137 | ResourceMgr.KVStore = SetKVClient(Backend, ResourceMgr.Host, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 138 | ResourceMgr.Port, deviceID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 139 | if ResourceMgr.KVStore == nil { |
| 140 | log.Error("Failed to setup KV store") |
| 141 | } |
| 142 | Ranges := make(map[string]*openolt.DeviceInfo_DeviceResourceRanges) |
| 143 | RsrcMgrsByTech := make(map[string]*ponrmgr.PONResourceManager) |
| 144 | ResourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 145 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 146 | // TODO self.args = registry('main').get_args() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 147 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 148 | /* |
| 149 | If a legacy driver returns protobuf without any ranges,s synthesize one from |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 150 | the legacy global per-device information. This, in theory, is temporary until |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 151 | the legacy drivers are upgrade to support pool ranges. |
| 152 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 153 | if devInfo.Ranges == nil { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 154 | var ranges openolt.DeviceInfo_DeviceResourceRanges |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 155 | ranges.Technology = devInfo.GetTechnology() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 156 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 157 | NumPONPorts := devInfo.GetPonPorts() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 158 | var index uint32 |
| 159 | for index = 0; index < NumPONPorts; index++ { |
| 160 | ranges.IntfIds = append(ranges.IntfIds, index) |
| 161 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 162 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 163 | var Pool openolt.DeviceInfo_DeviceResourceRanges_Pool |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 164 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 165 | Pool.Start = devInfo.OnuIdStart |
| 166 | Pool.End = devInfo.OnuIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 167 | Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 168 | onuPool := Pool |
| 169 | ranges.Pools = append(ranges.Pools, &onuPool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 170 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 171 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 172 | Pool.Start = devInfo.AllocIdStart |
| 173 | Pool.End = devInfo.AllocIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 174 | Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 175 | allocPool := Pool |
| 176 | ranges.Pools = append(ranges.Pools, &allocPool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 177 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 178 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 179 | Pool.Start = devInfo.GemportIdStart |
| 180 | Pool.End = devInfo.GemportIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 181 | Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 182 | gemPool := Pool |
| 183 | ranges.Pools = append(ranges.Pools, &gemPool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 184 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 185 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 186 | Pool.Start = devInfo.FlowIdStart |
| 187 | Pool.End = devInfo.FlowIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 188 | Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 189 | ranges.Pools = append(ranges.Pools, &Pool) |
| 190 | // Add to device info |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 191 | devInfo.Ranges = append(devInfo.Ranges, &ranges) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 192 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 193 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 194 | // Create a separate Resource Manager instance for each range. This assumes that |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 195 | // each technology is represented by only a single range |
| 196 | var GlobalPONRsrcMgr *ponrmgr.PONResourceManager |
| 197 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 198 | for _, TechRange := range devInfo.Ranges { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 199 | technology := TechRange.Technology |
| 200 | log.Debugf("Device info technology %s", technology) |
| 201 | Ranges[technology] = TechRange |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 202 | RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(technology, deviceType, deviceID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 203 | Backend, ResourceMgr.Host, ResourceMgr.Port) |
| 204 | if err != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 205 | log.Errorf("Failed to create pon resource manager instance for technology %s", technology) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 206 | return nil |
| 207 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 208 | // resource_mgrs_by_tech[technology] = resource_mgr |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 209 | if GlobalPONRsrcMgr == nil { |
| 210 | GlobalPONRsrcMgr = RsrcMgrsByTech[technology] |
| 211 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 212 | for _, IntfID := range TechRange.IntfIds { |
| 213 | ResourceMgr.ResourceMgrs[uint32(IntfID)] = RsrcMgrsByTech[technology] |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 214 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 215 | // self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 216 | InitializeDeviceResourceRangeAndPool(RsrcMgrsByTech[technology], GlobalPONRsrcMgr, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 217 | TechRange, devInfo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 218 | } |
| 219 | // After we have initialized resource ranges, initialize the |
| 220 | // resource pools accordingly. |
| 221 | for _, PONRMgr := range RsrcMgrsByTech { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 222 | _ = PONRMgr.InitDeviceResourcePool() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 223 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 224 | log.Info("Initialization of resource manager success!") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 225 | return &ResourceMgr |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 226 | } |
| 227 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 228 | // InitializeDeviceResourceRangeAndPool initializes the resource range pool according to the sharing type, then apply |
| 229 | // device specific information. If KV doesn't exist |
| 230 | // or is broader than the device, the device's information will |
| 231 | // dictate the range limits |
| 232 | func InitializeDeviceResourceRangeAndPool(ponRMgr *ponrmgr.PONResourceManager, globalPONRMgr *ponrmgr.PONResourceManager, |
| 233 | techRange *openolt.DeviceInfo_DeviceResourceRanges, devInfo *openolt.DeviceInfo) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 234 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 235 | // init the resource range pool according to the sharing type |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 236 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 237 | log.Debugf("Resource range pool init for technology %s", ponRMgr.Technology) |
| 238 | // first load from KV profiles |
| 239 | status := ponRMgr.InitResourceRangesFromKVStore() |
| 240 | if !status { |
| 241 | log.Debugf("Failed to load resource ranges from KV store for tech %s", ponRMgr.Technology) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 242 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 243 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 244 | /* |
| 245 | Then apply device specific information. If KV doesn't exist |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 246 | or is broader than the device, the device's information will |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 247 | dictate the range limits |
| 248 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 249 | log.Debugf("Using device info to init pon resource ranges for tech", ponRMgr.Technology) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 250 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 251 | ONUIDStart := devInfo.OnuIdStart |
| 252 | ONUIDEnd := devInfo.OnuIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 253 | ONUIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF |
| 254 | ONUIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 255 | AllocIDStart := devInfo.AllocIdStart |
| 256 | AllocIDEnd := devInfo.AllocIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 257 | AllocIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 258 | AllocIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 259 | GEMPortIDStart := devInfo.GemportIdStart |
| 260 | GEMPortIDEnd := devInfo.GemportIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 261 | GEMPortIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 262 | GEMPortIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 263 | FlowIDStart := devInfo.FlowIdStart |
| 264 | FlowIDEnd := devInfo.FlowIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 265 | FlowIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 266 | FlowIDSharedPoolID := uint32(0) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 267 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 268 | var FirstIntfPoolID uint32 |
| 269 | var SharedPoolID uint32 |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 270 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 271 | /* |
| 272 | * As a zero check is made against SharedPoolID to check whether the resources are shared across all intfs |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 273 | * if resources are shared across interfaces then SharedPoolID is given a positive number. |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 274 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 275 | for _, FirstIntfPoolID = range techRange.IntfIds { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 276 | // skip the intf id 0 |
| 277 | if FirstIntfPoolID == 0 { |
| 278 | continue |
| 279 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 280 | break |
| 281 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 282 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 283 | for _, RangePool := range techRange.Pools { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 284 | if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 285 | SharedPoolID = FirstIntfPoolID |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 286 | } else if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_SAME_TECH { |
| 287 | SharedPoolID = FirstIntfPoolID |
| 288 | } else { |
| 289 | SharedPoolID = 0 |
| 290 | } |
| 291 | if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID { |
| 292 | ONUIDStart = RangePool.Start |
| 293 | ONUIDEnd = RangePool.End |
| 294 | ONUIDShared = RangePool.Sharing |
| 295 | ONUIDSharedPoolID = SharedPoolID |
| 296 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID { |
| 297 | AllocIDStart = RangePool.Start |
| 298 | AllocIDEnd = RangePool.End |
| 299 | AllocIDShared = RangePool.Sharing |
| 300 | AllocIDSharedPoolID = SharedPoolID |
| 301 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID { |
| 302 | GEMPortIDStart = RangePool.Start |
| 303 | GEMPortIDEnd = RangePool.End |
| 304 | GEMPortIDShared = RangePool.Sharing |
| 305 | GEMPortIDSharedPoolID = SharedPoolID |
| 306 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID { |
| 307 | FlowIDStart = RangePool.Start |
| 308 | FlowIDEnd = RangePool.End |
| 309 | FlowIDShared = RangePool.Sharing |
| 310 | FlowIDSharedPoolID = SharedPoolID |
| 311 | } |
| 312 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 313 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 314 | log.Debugw("Device info init", log.Fields{"technology": techRange.Technology, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 315 | "onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID, |
| 316 | "alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd, |
| 317 | "alloc_id_shared_pool_id": AllocIDSharedPoolID, |
| 318 | "gemport_id_start": GEMPortIDStart, "gemport_id_end": GEMPortIDEnd, |
| 319 | "gemport_id_shared_pool_id": GEMPortIDSharedPoolID, |
| 320 | "flow_id_start": FlowIDStart, |
| 321 | "flow_id_end_idx": FlowIDEnd, |
| 322 | "flow_id_shared_pool_id": FlowIDSharedPoolID, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 323 | "intf_ids": techRange.IntfIds, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 324 | "uni_id_start": 0, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 325 | "uni_id_end_idx": 1, /*MaxUNIIDperONU()*/ |
| 326 | }) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 327 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 328 | ponRMgr.InitDefaultPONResourceRanges(ONUIDStart, ONUIDEnd, ONUIDSharedPoolID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 329 | AllocIDStart, AllocIDEnd, AllocIDSharedPoolID, |
| 330 | GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID, |
| 331 | FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 332 | devInfo.PonPorts, techRange.IntfIds) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 333 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 334 | // For global sharing, make sure to refresh both local and global resource manager instances' range |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 335 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 336 | if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 337 | globalPONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 338 | "", 0, nil) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 339 | ponRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd, |
| 340 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 341 | } |
| 342 | if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 343 | globalPONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 344 | "", 0, nil) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 345 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 346 | ponRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd, |
| 347 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 348 | } |
| 349 | if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 350 | globalPONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 351 | "", 0, nil) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 352 | ponRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd, |
| 353 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 354 | } |
| 355 | if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 356 | globalPONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 357 | "", 0, nil) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 358 | ponRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd, |
| 359 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 360 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 361 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 362 | // Make sure loaded range fits the platform bit encoding ranges |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 363 | ponRMgr.UpdateRanges(ponrmgr.UNI_ID_START_IDX, 0, ponrmgr.UNI_ID_END_IDX /* TODO =OpenOltPlatform.MAX_UNIS_PER_ONU-1*/, 1, "", 0, nil) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 364 | } |
| 365 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 366 | // Delete clears used resources for the particular olt device being deleted |
| 367 | func (RsrcMgr *OpenOltResourceMgr) Delete() error { |
| 368 | /* TODO |
| 369 | def __del__(self): |
| 370 | self.log.info("clearing-device-resource-pool") |
| 371 | for key, resource_mgr in self.resource_mgrs.iteritems(): |
| 372 | resource_mgr.clear_device_resource_pool() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 373 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 374 | def assert_pon_id_limit(self, pon_intf_id): |
| 375 | assert pon_intf_id in self.resource_mgrs |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 376 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 377 | def assert_onu_id_limit(self, pon_intf_id, onu_id): |
| 378 | self.assert_pon_id_limit(pon_intf_id) |
| 379 | self.resource_mgrs[pon_intf_id].assert_resource_limits(onu_id, PONResourceManager.ONU_ID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 380 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 381 | @property |
| 382 | def max_uni_id_per_onu(self): |
| 383 | return 0 #OpenOltPlatform.MAX_UNIS_PER_ONU-1, zero-based indexing Uncomment or override to make default multi-uni |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 384 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 385 | def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id): |
| 386 | self.assert_onu_id_limit(pon_intf_id, onu_id) |
| 387 | self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID) |
| 388 | */ |
| 389 | for _, rsrcMgr := range RsrcMgr.ResourceMgrs { |
| 390 | if err := rsrcMgr.ClearDeviceResourcePool(); err != nil { |
| 391 | log.Debug("Failed to clear device resource pool") |
| 392 | return err |
| 393 | } |
| 394 | } |
| 395 | log.Debug("Cleared device resource pool") |
| 396 | return nil |
| 397 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 398 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 399 | // GetONUID returns the available OnuID for the given pon-port |
| 400 | func (RsrcMgr *OpenOltResourceMgr) GetONUID(ponIntfID uint32) (uint32, error) { |
salmansiddiqui | 352a45c | 2019-08-19 10:15:36 +0000 | [diff] [blame] | 401 | // Check if Pon Interface ID is present in Resource-manager-map |
| 402 | if _, ok := RsrcMgr.ResourceMgrs[ponIntfID]; !ok { |
| 403 | err := errors.New("invalid-pon-interface-" + strconv.Itoa(int(ponIntfID))) |
| 404 | return 0, err |
| 405 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 406 | // Get ONU id for a provided pon interface ID. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 407 | ONUID, err := RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(ponIntfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 408 | ponrmgr.ONU_ID, 1) |
| 409 | if err != nil { |
| 410 | log.Errorf("Failed to get resource for interface %d for type %s", |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 411 | ponIntfID, ponrmgr.ONU_ID) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 412 | return 0, err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 413 | } |
| 414 | if ONUID != nil { |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 415 | RsrcMgr.ResourceMgrs[ponIntfID].InitResourceMap(fmt.Sprintf("%d,%d", ponIntfID, ONUID[0])) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 416 | return ONUID[0], err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 417 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 418 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 419 | return 0, err // return OnuID 0 on error |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 420 | } |
| 421 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 422 | // GetFlowIDInfo returns the slice of flow info of the given pon-port |
| 423 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 424 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 425 | func (RsrcMgr *OpenOltResourceMgr) GetFlowIDInfo(ponIntfID uint32, onuID int32, uniID int32, flowID uint32) *[]FlowInfo { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 426 | var flows []FlowInfo |
| 427 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 428 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 429 | if err := RsrcMgr.ResourceMgrs[ponIntfID].GetFlowIDInfo(FlowPath, flowID, &flows); err != nil { |
| 430 | log.Errorw("Error while getting flows from KV store", log.Fields{"flowId": flowID}) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 431 | return nil |
| 432 | } |
| 433 | if len(flows) == 0 { |
| 434 | log.Debugw("No flowInfo found in KV store", log.Fields{"flowPath": FlowPath}) |
| 435 | return nil |
| 436 | } |
| 437 | return &flows |
| 438 | } |
| 439 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 440 | // GetCurrentFlowIDsForOnu fetches flow ID from the resource manager |
| 441 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 442 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 443 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentFlowIDsForOnu(PONIntfID uint32, ONUID int32, UNIID int32) []uint32 { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 444 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 445 | FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID) |
Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 446 | if mgrs, exist := RsrcMgr.ResourceMgrs[PONIntfID]; exist { |
| 447 | return mgrs.GetCurrentFlowIDsForOnu(FlowPath) |
| 448 | } |
| 449 | return nil |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 450 | } |
| 451 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 452 | // UpdateFlowIDInfo updates flow info for the given pon interface, onu id, and uni id |
| 453 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 454 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
| 455 | func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDInfo(ponIntfID int32, onuID int32, uniID int32, |
| 456 | flowID uint32, flowData *[]FlowInfo) error { |
| 457 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 458 | return RsrcMgr.ResourceMgrs[uint32(ponIntfID)].UpdateFlowIDInfoForOnu(FlowPath, flowID, *flowData) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 459 | } |
| 460 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 461 | // GetFlowID return flow ID for a given pon interface id, onu id and uni id |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 462 | func (RsrcMgr *OpenOltResourceMgr) GetFlowID(ponIntfID uint32, ONUID int32, uniID int32, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 463 | gemportID uint32, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 464 | flowStoreCookie uint64, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 465 | flowCategory string, vlanPcp ...uint32) (uint32, error) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 466 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 467 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 468 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, ONUID, uniID) |
| 469 | FlowIDs := RsrcMgr.ResourceMgrs[ponIntfID].GetCurrentFlowIDsForOnu(FlowPath) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 470 | if FlowIDs != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 471 | log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "ONUID": ONUID, "uniID": uniID, "KVpath": FlowPath}) |
| 472 | for _, flowID := range FlowIDs { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 473 | FlowInfo := RsrcMgr.GetFlowIDInfo(ponIntfID, int32(ONUID), int32(uniID), uint32(flowID)) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 474 | er := getFlowIDFromFlowInfo(FlowInfo, flowID, gemportID, flowStoreCookie, flowCategory, vlanPcp...) |
| 475 | if er == nil { |
| 476 | return flowID, er |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 477 | } |
| 478 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 479 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 480 | log.Debug("No matching flows with flow cookie or flow category, allocating new flowid") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 481 | FlowIDs, err = RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(ponIntfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 482 | ponrmgr.FLOW_ID, 1) |
| 483 | if err != nil { |
| 484 | log.Errorf("Failed to get resource for interface %d for type %s", |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 485 | ponIntfID, ponrmgr.FLOW_ID) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 486 | return uint32(0), err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 487 | } |
| 488 | if FlowIDs != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 489 | _ = RsrcMgr.ResourceMgrs[ponIntfID].UpdateFlowIDForOnu(FlowPath, FlowIDs[0], true) |
| 490 | return FlowIDs[0], err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 491 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 492 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 493 | return 0, err |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 494 | } |
| 495 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 496 | // GetAllocID return the first Alloc ID for a given pon interface id and onu id and then update the resource map on |
| 497 | // the KV store with the list of alloc_ids allocated for the pon_intf_onu_id tuple |
| 498 | // Currently of all the alloc_ids available, it returns the first alloc_id in the list for tha given ONU |
| 499 | func (RsrcMgr *OpenOltResourceMgr) GetAllocID(intfID uint32, onuID uint32, uniID uint32) uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 500 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 501 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 502 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
| 503 | AllocID := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 504 | if AllocID != nil { |
| 505 | // Since we support only one alloc_id for the ONU at the moment, |
| 506 | // return the first alloc_id in the list, if available, for that |
| 507 | // ONU. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 508 | log.Debugw("Retrieved alloc ID from pon resource mgr", log.Fields{"AllocID": AllocID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 509 | return AllocID[0] |
| 510 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 511 | AllocID, err = RsrcMgr.ResourceMgrs[intfID].GetResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 512 | ponrmgr.ALLOC_ID, 1) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 513 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 514 | if AllocID == nil || err != nil { |
| 515 | log.Error("Failed to allocate alloc id") |
| 516 | return 0 |
| 517 | } |
| 518 | // update the resource map on KV store with the list of alloc_id |
| 519 | // allocated for the pon_intf_onu_id tuple |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 520 | err = RsrcMgr.ResourceMgrs[intfID].UpdateAllocIdsForOnu(IntfOnuIDUniID, AllocID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 521 | if err != nil { |
| 522 | log.Error("Failed to update Alloc ID") |
| 523 | return 0 |
| 524 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 525 | log.Debugw("Allocated new Tcont from pon resource mgr", log.Fields{"AllocID": AllocID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 526 | return AllocID[0] |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 527 | } |
| 528 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 529 | // UpdateAllocIdsForOnu updates alloc ids in kv store for a given pon interface id, onu id and uni id |
| 530 | func (RsrcMgr *OpenOltResourceMgr) UpdateAllocIdsForOnu(ponPort uint32, onuID uint32, uniID uint32, allocID []uint32) error { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 531 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 532 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
| 533 | return RsrcMgr.ResourceMgrs[ponPort].UpdateAllocIdsForOnu(IntfOnuIDUniID, |
| 534 | allocID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 535 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 536 | |
| 537 | // GetCurrentGEMPortIDsForOnu returns gem ports for given pon interface , onu id and uni id |
| 538 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentGEMPortIDsForOnu(intfID uint32, onuID uint32, |
| 539 | uniID uint32) []uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 540 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 541 | /* Get gem ports for given pon interface , onu id and uni id. */ |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 542 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 543 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
| 544 | return RsrcMgr.ResourceMgrs[intfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 545 | } |
| 546 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 547 | // GetCurrentAllocIDsForOnu returns alloc ids for given pon interface and onu id |
| 548 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentAllocIDsForOnu(intfID uint32, onuID uint32, uniID uint32) []uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 549 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 550 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
| 551 | AllocID := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 552 | if AllocID != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 553 | return AllocID |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 554 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 555 | return []uint32{} |
| 556 | } |
| 557 | |
| 558 | // RemoveAllocIDForOnu removes the alloc id for given pon interface, onu id, uni id and alloc id |
| 559 | func (RsrcMgr *OpenOltResourceMgr) RemoveAllocIDForOnu(intfID uint32, onuID uint32, uniID uint32, allocID uint32) { |
| 560 | allocIDs := RsrcMgr.GetCurrentAllocIDsForOnu(intfID, onuID, uniID) |
| 561 | for i := 0; i < len(allocIDs); i++ { |
| 562 | if allocIDs[i] == allocID { |
| 563 | allocIDs = append(allocIDs[:i], allocIDs[i+1:]...) |
| 564 | break |
| 565 | } |
| 566 | } |
| 567 | err := RsrcMgr.UpdateAllocIdsForOnu(intfID, onuID, uniID, allocIDs) |
| 568 | if err != nil { |
| 569 | log.Errorf("Failed to Remove Alloc Id For Onu. IntfID %d onuID %d uniID %d allocID %d", |
| 570 | intfID, onuID, uniID, allocID) |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | // RemoveGemPortIDForOnu removes the gem port id for given pon interface, onu id, uni id and gem port id |
| 575 | func (RsrcMgr *OpenOltResourceMgr) RemoveGemPortIDForOnu(intfID uint32, onuID uint32, uniID uint32, gemPortID uint32) { |
| 576 | gemPortIDs := RsrcMgr.GetCurrentGEMPortIDsForOnu(intfID, onuID, uniID) |
| 577 | for i := 0; i < len(gemPortIDs); i++ { |
| 578 | if gemPortIDs[i] == gemPortID { |
| 579 | gemPortIDs = append(gemPortIDs[:i], gemPortIDs[i+1:]...) |
| 580 | break |
| 581 | } |
| 582 | } |
| 583 | err := RsrcMgr.UpdateGEMPortIDsForOnu(intfID, onuID, uniID, gemPortIDs) |
| 584 | if err != nil { |
| 585 | log.Errorf("Failed to Remove Gem Id For Onu. IntfID %d onuID %d uniID %d gemPortId %d", |
| 586 | intfID, onuID, uniID, gemPortID) |
| 587 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 588 | } |
| 589 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 590 | // UpdateGEMportsPonportToOnuMapOnKVStore updates onu and uni id associated with the gem port to the kv store |
| 591 | // This stored information is used when packet_indication is received and we need to derive the ONU Id for which |
| 592 | // the packet arrived based on the pon_intf and gemport available in the packet_indication |
| 593 | func (RsrcMgr *OpenOltResourceMgr) UpdateGEMportsPonportToOnuMapOnKVStore(gemPorts []uint32, PonPort uint32, |
| 594 | onuID uint32, uniID uint32) error { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 595 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 596 | /* Update onu and uni id associated with the gem port to the kv store. */ |
| 597 | var IntfGEMPortPath string |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 598 | Data := fmt.Sprintf("%d %d", onuID, uniID) |
| 599 | for _, GEM := range gemPorts { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 600 | IntfGEMPortPath = fmt.Sprintf("%d,%d", PonPort, GEM) |
| 601 | Val, err := json.Marshal(Data) |
| 602 | if err != nil { |
| 603 | log.Error("failed to Marshal") |
| 604 | return err |
| 605 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 606 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 607 | if err = RsrcMgr.KVStore.Put(IntfGEMPortPath, Val); err != nil { |
| 608 | log.Errorf("Failed to update resource %s", IntfGEMPortPath) |
| 609 | return err |
| 610 | } |
| 611 | } |
| 612 | return nil |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 613 | } |
| 614 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 615 | // RemoveGEMportPonportToOnuMapOnKVStore removes the relationship between the gem port and pon port |
| 616 | func (RsrcMgr *OpenOltResourceMgr) RemoveGEMportPonportToOnuMapOnKVStore(GemPort uint32, PonPort uint32) { |
| 617 | IntfGEMPortPath := fmt.Sprintf("%d,%d", PonPort, GemPort) |
| 618 | err := RsrcMgr.KVStore.Delete(IntfGEMPortPath) |
| 619 | if err != nil { |
| 620 | log.Errorf("Failed to Remove Gem port-Pon port to onu map on kv store. Gem %d PonPort %d", GemPort, PonPort) |
| 621 | } |
| 622 | } |
| 623 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 624 | // GetGEMPortID gets gem port id for a particular pon port, onu id and uni id and then update the resource map on |
| 625 | // the KV store with the list of gemport_id allocated for the pon_intf_onu_id tuple |
| 626 | func (RsrcMgr *OpenOltResourceMgr) GetGEMPortID(ponPort uint32, onuID uint32, |
| 627 | uniID uint32, NumOfPorts uint32) ([]uint32, error) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 628 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 629 | /* Get gem port id for a particular pon port, onu id |
| 630 | and uni id. |
| 631 | */ |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 632 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 633 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 634 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 635 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 636 | GEMPortList := RsrcMgr.ResourceMgrs[ponPort].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 637 | if GEMPortList != nil { |
| 638 | return GEMPortList, nil |
| 639 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 640 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 641 | GEMPortList, err = RsrcMgr.ResourceMgrs[ponPort].GetResourceID(ponPort, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 642 | ponrmgr.GEMPORT_ID, NumOfPorts) |
| 643 | if err != nil && GEMPortList == nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 644 | log.Errorf("Failed to get gem port id for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 645 | return nil, err |
| 646 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 647 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 648 | // update the resource map on KV store with the list of gemport_id |
| 649 | // allocated for the pon_intf_onu_id tuple |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 650 | err = RsrcMgr.ResourceMgrs[ponPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 651 | GEMPortList) |
| 652 | if err != nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 653 | log.Errorf("Failed to update GEM ports to kv store for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 654 | return nil, err |
| 655 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 656 | _ = RsrcMgr.UpdateGEMportsPonportToOnuMapOnKVStore(GEMPortList, ponPort, |
| 657 | onuID, uniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 658 | return GEMPortList, err |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 659 | } |
| 660 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 661 | // UpdateGEMPortIDsForOnu updates gemport ids on to the kv store for a given pon port, onu id and uni id |
| 662 | func (RsrcMgr *OpenOltResourceMgr) UpdateGEMPortIDsForOnu(ponPort uint32, onuID uint32, |
| 663 | uniID uint32, GEMPortList []uint32) error { |
| 664 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
| 665 | return RsrcMgr.ResourceMgrs[ponPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 666 | GEMPortList) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 667 | |
| 668 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 669 | |
| 670 | // FreeonuID releases(make free) onu id for a particular pon-port |
| 671 | func (RsrcMgr *OpenOltResourceMgr) FreeonuID(intfID uint32, onuID []uint32) { |
| 672 | |
| 673 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, ponrmgr.ONU_ID, onuID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 674 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 675 | /* Free onu id for a particular interface.*/ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 676 | var IntfonuID string |
| 677 | for _, onu := range onuID { |
| 678 | IntfonuID = fmt.Sprintf("%d,%d", intfID, onu) |
| 679 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(IntfonuID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 680 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 681 | } |
| 682 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 683 | // FreeFlowID returns the free flow id for a given interface, onu id and uni id |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 684 | func (RsrcMgr *OpenOltResourceMgr) FreeFlowID(IntfID uint32, onuID int32, |
| 685 | uniID int32, FlowID uint32) { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 686 | var IntfONUID string |
| 687 | var err error |
Abhilash Laxmeshwar | 8369591 | 2019-10-01 14:37:19 +0530 | [diff] [blame] | 688 | FlowIds := make([]uint32, 0) |
| 689 | |
| 690 | FlowIds = append(FlowIds, FlowID) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 691 | IntfONUID = fmt.Sprintf("%d,%d,%d", IntfID, onuID, uniID) |
| 692 | err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(IntfONUID, FlowID, false) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 693 | if err != nil { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 694 | log.Errorw("Failed to Update flow id for", log.Fields{"intf": IntfONUID}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 695 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 696 | RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(IntfONUID, FlowID) |
Abhilash Laxmeshwar | 8369591 | 2019-10-01 14:37:19 +0530 | [diff] [blame] | 697 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.FLOW_ID, FlowIds) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 698 | } |
| 699 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 700 | // FreeFlowIDs releases the flow Ids |
| 701 | func (RsrcMgr *OpenOltResourceMgr) FreeFlowIDs(IntfID uint32, onuID uint32, |
| 702 | uniID uint32, FlowID []uint32) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 703 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 704 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.FLOW_ID, FlowID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 705 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 706 | var IntfOnuIDUniID string |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 707 | var err error |
| 708 | for _, flow := range FlowID { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 709 | IntfOnuIDUniID = fmt.Sprintf("%d,%d,%d", IntfID, onuID, uniID) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 710 | err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(IntfOnuIDUniID, flow, false) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 711 | if err != nil { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 712 | log.Errorw("Failed to Update flow id for", log.Fields{"intf": IntfOnuIDUniID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 713 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 714 | RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(IntfOnuIDUniID, flow) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 715 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 716 | } |
| 717 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 718 | // FreeAllocID frees AllocID on the PON resource pool and also frees the allocID association |
| 719 | // for the given OLT device. |
| 720 | func (RsrcMgr *OpenOltResourceMgr) FreeAllocID(IntfID uint32, onuID uint32, |
| 721 | uniID uint32, allocID uint32) { |
| 722 | RsrcMgr.RemoveAllocIDForOnu(IntfID, onuID, uniID, allocID) |
| 723 | allocIDs := make([]uint32, 0) |
| 724 | allocIDs = append(allocIDs, allocID) |
| 725 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.ALLOC_ID, allocIDs) |
| 726 | } |
| 727 | |
| 728 | // FreeGemPortID frees GemPortID on the PON resource pool and also frees the gemPortID association |
| 729 | // for the given OLT device. |
| 730 | func (RsrcMgr *OpenOltResourceMgr) FreeGemPortID(IntfID uint32, onuID uint32, |
| 731 | uniID uint32, gemPortID uint32) { |
| 732 | RsrcMgr.RemoveGemPortIDForOnu(IntfID, onuID, uniID, gemPortID) |
| 733 | gemPortIDs := make([]uint32, 0) |
| 734 | gemPortIDs = append(gemPortIDs, gemPortID) |
| 735 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.GEMPORT_ID, gemPortIDs) |
| 736 | } |
| 737 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 738 | // FreePONResourcesForONU make the pon resources free for a given pon interface and onu id, and the clears the |
| 739 | // resource map and the onuID associated with (pon_intf_id, gemport_id) tuple, |
| 740 | func (RsrcMgr *OpenOltResourceMgr) FreePONResourcesForONU(intfID uint32, onuID uint32, uniID uint32) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 741 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 742 | var onuIDs []uint32 |
| 743 | onuIDs = append(onuIDs, onuID) |
| 744 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 745 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 746 | AllocIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 747 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 748 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 749 | ponrmgr.ALLOC_ID, |
| 750 | AllocIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 751 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 752 | GEMPortIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
| 753 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 754 | ponrmgr.GEMPORT_ID, |
| 755 | GEMPortIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 756 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 757 | FlowIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentFlowIDsForOnu(IntfOnuIDUniID) |
| 758 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 759 | ponrmgr.FLOW_ID, |
| 760 | FlowIDs) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 761 | if int32(onuID) >= 0 { |
| 762 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
| 763 | ponrmgr.ONU_ID, |
| 764 | onuIDs) |
| 765 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 766 | // Clear resource map associated with (pon_intf_id, gemport_id) tuple. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 767 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 768 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 769 | // Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple. |
| 770 | for _, GEM := range GEMPortIDs { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 771 | _ = RsrcMgr.KVStore.Delete(fmt.Sprintf("%d,%d", intfID, GEM)) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 772 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 773 | } |
| 774 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 775 | // IsFlowCookieOnKVStore checks if the given flow cookie is present on the kv store |
| 776 | // Returns true if the flow cookie is found, otherwise it returns false |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 777 | func (RsrcMgr *OpenOltResourceMgr) IsFlowCookieOnKVStore(ponIntfID uint32, onuID int32, uniID int32, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 778 | flowStoreCookie uint64) bool { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 779 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 780 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 781 | FlowIDs := RsrcMgr.ResourceMgrs[ponIntfID].GetCurrentFlowIDsForOnu(FlowPath) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 782 | if FlowIDs != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 783 | log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "onuID": onuID, "uniID": uniID, "KVpath": FlowPath}) |
| 784 | for _, flowID := range FlowIDs { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 785 | FlowInfo := RsrcMgr.GetFlowIDInfo(ponIntfID, int32(onuID), int32(uniID), uint32(flowID)) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 786 | if FlowInfo != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 787 | log.Debugw("Found flows", log.Fields{"flows": *FlowInfo, "flowId": flowID}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 788 | for _, Info := range *FlowInfo { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 789 | if Info.FlowStoreCookie == flowStoreCookie { |
| 790 | log.Debug("Found flow matching with flowStore cookie", log.Fields{"flowId": flowID, "flowStoreCookie": flowStoreCookie}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 791 | return true |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | return false |
| 798 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 799 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 800 | // GetTechProfileIDForOnu fetches Tech-Profile-ID from the KV-Store for the given onu based on the path |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 801 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
| 802 | func (RsrcMgr *OpenOltResourceMgr) GetTechProfileIDForOnu(IntfID uint32, OnuID uint32, UniID uint32) []uint32 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 803 | Path := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 804 | var Data []uint32 |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 805 | Value, err := RsrcMgr.KVStore.Get(Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 806 | if err == nil { |
| 807 | if Value != nil { |
| 808 | Val, err := kvstore.ToByte(Value.Value) |
| 809 | if err != nil { |
| 810 | log.Errorw("Failed to convert into byte array", log.Fields{"error": err}) |
| 811 | return Data |
| 812 | } |
| 813 | if err = json.Unmarshal(Val, &Data); err != nil { |
| 814 | log.Error("Failed to unmarshal", log.Fields{"error": err}) |
| 815 | return Data |
| 816 | } |
| 817 | } |
| 818 | } else { |
| 819 | log.Errorf("Failed to get TP id from kvstore for path %s", Path) |
| 820 | } |
| 821 | log.Debugf("Getting TP id %d from path %s", Data, Path) |
| 822 | return Data |
| 823 | |
| 824 | } |
| 825 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 826 | // RemoveTechProfileIDsForOnu deletes all tech profile ids from the KV-Store for the given onu based on the path |
| 827 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
| 828 | func (RsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDsForOnu(IntfID uint32, OnuID uint32, UniID uint32) error { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 829 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
| 830 | if err := RsrcMgr.KVStore.Delete(IntfOnuUniID); err != nil { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 831 | log.Errorw("Failed to delete techprofile id resource in KV store", log.Fields{"path": IntfOnuUniID}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 832 | return err |
| 833 | } |
| 834 | return nil |
| 835 | } |
| 836 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 837 | // RemoveTechProfileIDForOnu deletes a specific tech profile id from the KV-Store for the given onu based on the path |
| 838 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
| 839 | func (RsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDForOnu(IntfID uint32, OnuID uint32, UniID uint32, TpID uint32) error { |
| 840 | tpIDList := RsrcMgr.GetTechProfileIDForOnu(IntfID, OnuID, UniID) |
| 841 | for i, tpIDInList := range tpIDList { |
| 842 | if tpIDInList == TpID { |
| 843 | tpIDList = append(tpIDList[:i], tpIDList[i+1:]...) |
| 844 | } |
| 845 | } |
| 846 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
| 847 | Value, err := json.Marshal(tpIDList) |
| 848 | if err != nil { |
| 849 | log.Error("failed to Marshal") |
| 850 | return err |
| 851 | } |
| 852 | if err = RsrcMgr.KVStore.Put(IntfOnuUniID, Value); err != nil { |
| 853 | log.Errorf("Failed to update resource %s", IntfOnuUniID) |
| 854 | return err |
| 855 | } |
| 856 | return err |
| 857 | } |
| 858 | |
| 859 | // UpdateTechProfileIDForOnu updates (put) already present tech-profile-id for the given onu based on the path |
| 860 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 861 | func (RsrcMgr *OpenOltResourceMgr) UpdateTechProfileIDForOnu(IntfID uint32, OnuID uint32, |
| 862 | UniID uint32, TpID uint32) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 863 | var Value []byte |
| 864 | var err error |
| 865 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 866 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 867 | |
| 868 | tpIDList := RsrcMgr.GetTechProfileIDForOnu(IntfID, OnuID, UniID) |
| 869 | for _, value := range tpIDList { |
| 870 | if value == TpID { |
| 871 | log.Debugf("TpID %d is already in tpIdList for the path %s", TpID, IntfOnuUniID) |
| 872 | return err |
| 873 | } |
| 874 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 875 | log.Debugf("updating tp id %d on path %s", TpID, IntfOnuUniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 876 | tpIDList = append(tpIDList, TpID) |
| 877 | Value, err = json.Marshal(tpIDList) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 878 | if err != nil { |
| 879 | log.Error("failed to Marshal") |
| 880 | return err |
| 881 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 882 | if err = RsrcMgr.KVStore.Put(IntfOnuUniID, Value); err != nil { |
| 883 | log.Errorf("Failed to update resource %s", IntfOnuUniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 884 | return err |
| 885 | } |
| 886 | return err |
| 887 | } |
| 888 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 889 | // UpdateMeterIDForOnu updates the meter id in the KV-Store for the given onu based on the path |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 890 | // This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 891 | func (RsrcMgr *OpenOltResourceMgr) UpdateMeterIDForOnu(Direction string, IntfID uint32, OnuID uint32, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 892 | UniID uint32, TpID uint32, MeterConfig *ofp.OfpMeterConfig) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 893 | var Value []byte |
| 894 | var err error |
| 895 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 896 | IntfOnuUniID := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 897 | Value, err = json.Marshal(*MeterConfig) |
| 898 | if err != nil { |
| 899 | log.Error("failed to Marshal meter config") |
| 900 | return err |
| 901 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 902 | if err = RsrcMgr.KVStore.Put(IntfOnuUniID, Value); err != nil { |
| 903 | log.Errorf("Failed to store meter into KV store %s", IntfOnuUniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 904 | return err |
| 905 | } |
| 906 | return err |
| 907 | } |
| 908 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 909 | // GetMeterIDForOnu fetches the meter id from the kv store for the given onu based on the path |
| 910 | // This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| 911 | func (RsrcMgr *OpenOltResourceMgr) GetMeterIDForOnu(Direction string, IntfID uint32, OnuID uint32, |
| 912 | UniID uint32, TpID uint32) (*ofp.OfpMeterConfig, error) { |
| 913 | Path := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 914 | var meterConfig ofp.OfpMeterConfig |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 915 | Value, err := RsrcMgr.KVStore.Get(Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 916 | if err == nil { |
| 917 | if Value != nil { |
| 918 | log.Debug("Found meter in KV store", log.Fields{"Direction": Direction}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 919 | Val, er := kvstore.ToByte(Value.Value) |
| 920 | if er != nil { |
| 921 | log.Errorw("Failed to convert into byte array", log.Fields{"error": er}) |
| 922 | return nil, er |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 923 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 924 | if er = json.Unmarshal(Val, &meterConfig); er != nil { |
| 925 | log.Error("Failed to unmarshal meterconfig", log.Fields{"error": er}) |
| 926 | return nil, er |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 927 | } |
| 928 | } else { |
| 929 | log.Debug("meter-does-not-exists-in-KVStore") |
| 930 | return nil, err |
| 931 | } |
| 932 | } else { |
| 933 | log.Errorf("Failed to get Meter config from kvstore for path %s", Path) |
| 934 | |
| 935 | } |
| 936 | return &meterConfig, err |
| 937 | } |
| 938 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 939 | // RemoveMeterIDForOnu deletes the meter id from the kV-Store for the given onu based on the path |
| 940 | // This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| 941 | func (RsrcMgr *OpenOltResourceMgr) RemoveMeterIDForOnu(Direction string, IntfID uint32, OnuID uint32, |
| 942 | UniID uint32, TpID uint32) error { |
| 943 | Path := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 944 | if err := RsrcMgr.KVStore.Delete(Path); err != nil { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 945 | log.Errorf("Failed to delete meter id %s from kvstore ", Path) |
| 946 | return err |
| 947 | } |
| 948 | return nil |
| 949 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 950 | |
| 951 | func getFlowIDFromFlowInfo(FlowInfo *[]FlowInfo, flowID, gemportID uint32, flowStoreCookie uint64, flowCategory string, vlanPcp ...uint32) error { |
| 952 | if FlowInfo != nil { |
| 953 | for _, Info := range *FlowInfo { |
| 954 | if int32(gemportID) == Info.Flow.GemportId && flowCategory != "" && Info.FlowCategory == flowCategory { |
| 955 | log.Debug("Found flow matching with flow category", log.Fields{"flowId": flowID, "FlowCategory": flowCategory}) |
| 956 | if Info.FlowCategory == "HSIA_FLOW" && Info.Flow.Classifier.OPbits == vlanPcp[0] { |
| 957 | log.Debug("Found matching vlan pcp ", log.Fields{"flowId": flowID, "Vlanpcp": vlanPcp[0]}) |
| 958 | return nil |
| 959 | } |
| 960 | } |
| 961 | if int32(gemportID) == Info.Flow.GemportId && flowStoreCookie != 0 && Info.FlowStoreCookie == flowStoreCookie { |
| 962 | if flowCategory != "" && Info.FlowCategory == flowCategory { |
| 963 | log.Debug("Found flow matching with flow category", log.Fields{"flowId": flowID, "FlowCategory": flowCategory}) |
| 964 | return nil |
| 965 | } |
| 966 | } |
| 967 | } |
| 968 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 969 | log.Debugw("the flow can be related to a different service", log.Fields{"flow_info": FlowInfo}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 970 | return errors.New("invalid flow-info") |
| 971 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 972 | |
| 973 | //AddGemToOnuGemInfo adds gemport to onugem info kvstore |
| 974 | func (RsrcMgr *OpenOltResourceMgr) AddGemToOnuGemInfo(intfID uint32, onuID uint32, gemPort uint32) error { |
| 975 | var onuGemData []OnuGemInfo |
| 976 | var err error |
| 977 | |
| 978 | if err = RsrcMgr.ResourceMgrs[intfID].GetOnuGemInfo(intfID, &onuGemData); err != nil { |
| 979 | log.Errorf("failed to get onuifo for intfid %d", intfID) |
| 980 | return err |
| 981 | } |
| 982 | if len(onuGemData) == 0 { |
| 983 | log.Errorw("failed to ger Onuid info ", log.Fields{"intfid": intfID, "onuid": onuID}) |
| 984 | return err |
| 985 | } |
| 986 | |
| 987 | for idx, onugem := range onuGemData { |
| 988 | if onugem.OnuID == onuID { |
| 989 | for _, gem := range onuGemData[idx].GemPorts { |
| 990 | if gem == gemPort { |
| 991 | log.Debugw("Gem already present in onugem info, skpping addition", log.Fields{"gem": gem}) |
| 992 | return nil |
| 993 | } |
| 994 | } |
| 995 | log.Debugw("Added gem to onugem info", log.Fields{"gem": gemPort}) |
| 996 | onuGemData[idx].GemPorts = append(onuGemData[idx].GemPorts, gemPort) |
| 997 | break |
| 998 | } |
| 999 | } |
| 1000 | err = RsrcMgr.ResourceMgrs[intfID].AddOnuGemInfo(intfID, onuGemData) |
| 1001 | if err != nil { |
| 1002 | log.Error("Failed to add onugem to kv store") |
| 1003 | return err |
| 1004 | } |
| 1005 | return err |
| 1006 | } |
| 1007 | |
| 1008 | //GetOnuGemInfo gets onu gem info from the kvstore per interface |
| 1009 | func (RsrcMgr *OpenOltResourceMgr) GetOnuGemInfo(IntfID uint32) ([]OnuGemInfo, error) { |
| 1010 | var onuGemData []OnuGemInfo |
| 1011 | |
| 1012 | if err := RsrcMgr.ResourceMgrs[IntfID].GetOnuGemInfo(IntfID, &onuGemData); err != nil { |
| 1013 | log.Errorf("failed to get onuifo for intfid %d", IntfID) |
| 1014 | return nil, err |
| 1015 | } |
| 1016 | |
| 1017 | return onuGemData, nil |
| 1018 | } |
| 1019 | |
| 1020 | // AddOnuInfo adds onu info on to the kvstore per interface |
| 1021 | func (RsrcMgr *OpenOltResourceMgr) AddOnuInfo(IntfID uint32, onuGem OnuGemInfo) error { |
| 1022 | var onuGemData []OnuGemInfo |
| 1023 | var err error |
| 1024 | |
| 1025 | if err = RsrcMgr.ResourceMgrs[IntfID].GetOnuGemInfo(IntfID, &onuGemData); err != nil { |
| 1026 | log.Errorf("failed to get onuifo for intfid %d", IntfID) |
| 1027 | return err |
| 1028 | } |
| 1029 | onuGemData = append(onuGemData, onuGem) |
| 1030 | err = RsrcMgr.ResourceMgrs[IntfID].AddOnuGemInfo(IntfID, onuGemData) |
| 1031 | if err != nil { |
| 1032 | log.Error("Failed to add onugem to kv store") |
| 1033 | return err |
| 1034 | } |
| 1035 | |
| 1036 | log.Debugw("added onu to onugeminfo", log.Fields{"intf": IntfID, "onugem": onuGem}) |
| 1037 | return err |
| 1038 | } |
| 1039 | |
| 1040 | // UpdateOnuInfo updates Onuinfo on the kvstore per interface |
| 1041 | func (RsrcMgr *OpenOltResourceMgr) UpdateOnuInfo(IntfID uint32, onuGem []OnuGemInfo) error { |
| 1042 | var onuGemData []OnuGemInfo |
| 1043 | var err error |
| 1044 | |
| 1045 | err = RsrcMgr.ResourceMgrs[IntfID].AddOnuGemInfo(IntfID, onuGemData) |
| 1046 | if err != nil { |
| 1047 | log.Error("Failed to add onugem to kv store") |
| 1048 | return err |
| 1049 | } |
| 1050 | |
| 1051 | log.Debugw("updated onugeminfo", log.Fields{"intf": IntfID, "onugem": onuGem}) |
| 1052 | return err |
| 1053 | } |
| 1054 | |
| 1055 | // AddUniPortToOnuInfo adds uni port to the onuinfo kvstore. check if the uni is already present if not update the kv store. |
| 1056 | func (RsrcMgr *OpenOltResourceMgr) AddUniPortToOnuInfo(intfID uint32, onuID uint32, portNo uint32) { |
| 1057 | var onuGemData []OnuGemInfo |
| 1058 | var err error |
| 1059 | |
| 1060 | if err = RsrcMgr.ResourceMgrs[intfID].GetOnuGemInfo(intfID, &onuGemData); err != nil { |
| 1061 | log.Errorf("failed to get onuifo for intfid %d", intfID) |
| 1062 | return |
| 1063 | } |
| 1064 | for idx, onu := range onuGemData { |
| 1065 | if onu.OnuID == onuID { |
| 1066 | for _, uni := range onu.UniPorts { |
| 1067 | if uni == portNo { |
| 1068 | log.Debugw("uni already present in onugem info", log.Fields{"uni": portNo}) |
| 1069 | return |
| 1070 | } |
| 1071 | } |
| 1072 | onuGemData[idx].UniPorts = append(onuGemData[idx].UniPorts, portNo) |
| 1073 | break |
| 1074 | } |
| 1075 | } |
| 1076 | err = RsrcMgr.ResourceMgrs[intfID].AddOnuGemInfo(intfID, onuGemData) |
| 1077 | if err != nil { |
| 1078 | log.Errorw("Failed to add uin port in onugem to kv store", log.Fields{"uni": portNo}) |
| 1079 | return |
| 1080 | } |
| 1081 | return |
| 1082 | } |
| 1083 | |
| 1084 | //UpdateGemPortForPktIn updates gemport for pkt in path to kvstore, path being intfid, onuid, portno |
| 1085 | func (RsrcMgr *OpenOltResourceMgr) UpdateGemPortForPktIn(pktIn PacketInInfoKey, gemPort uint32) { |
| 1086 | |
| 1087 | path := fmt.Sprintf(OnuPacketINPath, pktIn.IntfID, pktIn.OnuID, pktIn.LogicalPort) |
| 1088 | Value, err := json.Marshal(gemPort) |
| 1089 | if err != nil { |
| 1090 | log.Error("Failed to marshal data") |
| 1091 | return |
| 1092 | } |
| 1093 | if err = RsrcMgr.KVStore.Put(path, Value); err != nil { |
| 1094 | log.Errorw("Failed to put to kvstore", log.Fields{"path": path, "value": gemPort}) |
| 1095 | return |
| 1096 | } |
| 1097 | log.Debugw("added gem packet in successfully", log.Fields{"path": path, "gem": gemPort}) |
| 1098 | |
| 1099 | return |
| 1100 | } |
| 1101 | |
| 1102 | // GetGemPortFromOnuPktIn gets the gem port from onu pkt in path, path being intfid, onuid, portno |
| 1103 | func (RsrcMgr *OpenOltResourceMgr) GetGemPortFromOnuPktIn(intfID uint32, onuID uint32, logicalPort uint32) (uint32, error) { |
| 1104 | |
| 1105 | var Val []byte |
| 1106 | var gemPort uint32 |
| 1107 | |
| 1108 | path := fmt.Sprintf(OnuPacketINPath, intfID, onuID, logicalPort) |
| 1109 | |
| 1110 | value, err := RsrcMgr.KVStore.Get(path) |
| 1111 | if err != nil { |
| 1112 | log.Errorw("Failed to get from kv store", log.Fields{"path": path}) |
| 1113 | return uint32(0), err |
| 1114 | } else if value == nil { |
| 1115 | log.Debugw("No pkt in gem found", log.Fields{"path": path}) |
| 1116 | return uint32(0), nil |
| 1117 | } |
| 1118 | |
| 1119 | if Val, err = kvstore.ToByte(value.Value); err != nil { |
| 1120 | log.Error("Failed to convert to byte array") |
| 1121 | return uint32(0), err |
| 1122 | } |
| 1123 | if err = json.Unmarshal(Val, &gemPort); err != nil { |
| 1124 | log.Error("Failed to unmarshall") |
| 1125 | return uint32(0), err |
| 1126 | } |
| 1127 | log.Debugw("found packein gemport from path", log.Fields{"path": path, "gem": gemPort}) |
| 1128 | |
| 1129 | return gemPort, nil |
| 1130 | } |
| 1131 | |
| 1132 | // DelGemPortPktIn deletes the gemport from the pkt in path |
| 1133 | func (RsrcMgr *OpenOltResourceMgr) DelGemPortPktIn(intfID uint32, onuID uint32, logicalPort uint32) error { |
| 1134 | |
| 1135 | path := fmt.Sprintf(OnuPacketINPath, intfID, onuID, logicalPort) |
| 1136 | if err := RsrcMgr.KVStore.Delete(path); err != nil { |
| 1137 | log.Errorf("Falied to remove resource %s", path) |
| 1138 | return err |
| 1139 | } |
| 1140 | return nil |
| 1141 | } |
| 1142 | |
| 1143 | // DelOnuGemInfoForIntf deletes the onugem info from kvstore per interface |
| 1144 | func (RsrcMgr *OpenOltResourceMgr) DelOnuGemInfoForIntf(intfID uint32) error { |
| 1145 | if err := RsrcMgr.ResourceMgrs[intfID].DelOnuGemInfoForIntf(intfID); err != nil { |
| 1146 | log.Errorw("failed to delete onu gem info for", log.Fields{"intfid": intfID}) |
| 1147 | return err |
| 1148 | } |
| 1149 | return nil |
| 1150 | } |
| 1151 | |
| 1152 | //GetNNIFromKVStore gets NNi intfids from kvstore. path being per device |
| 1153 | func (RsrcMgr *OpenOltResourceMgr) GetNNIFromKVStore() ([]uint32, error) { |
| 1154 | |
| 1155 | var nni []uint32 |
| 1156 | var Val []byte |
| 1157 | |
| 1158 | path := fmt.Sprintf(NnniIntfID) |
| 1159 | value, err := RsrcMgr.KVStore.Get(path) |
| 1160 | if err != nil { |
| 1161 | log.Error("failed to get data from kv store") |
| 1162 | return nil, err |
| 1163 | } |
| 1164 | if value != nil { |
| 1165 | if Val, err = kvstore.ToByte(value.Value); err != nil { |
| 1166 | log.Error("Failed to convert to byte array") |
| 1167 | return nil, err |
| 1168 | } |
| 1169 | if err = json.Unmarshal(Val, &nni); err != nil { |
| 1170 | log.Error("Failed to unmarshall") |
| 1171 | return nil, err |
| 1172 | } |
| 1173 | } |
| 1174 | return nni, err |
| 1175 | } |
| 1176 | |
| 1177 | // AddNNIToKVStore adds Nni interfaces to kvstore, path being per device. |
| 1178 | func (RsrcMgr *OpenOltResourceMgr) AddNNIToKVStore(nniIntf uint32) error { |
| 1179 | var Value []byte |
| 1180 | |
| 1181 | nni, err := RsrcMgr.GetNNIFromKVStore() |
| 1182 | if err != nil { |
| 1183 | log.Error("failed to fetch nni interfaces from kv store") |
| 1184 | return err |
| 1185 | } |
| 1186 | |
| 1187 | path := fmt.Sprintf(NnniIntfID) |
| 1188 | nni = append(nni, nniIntf) |
| 1189 | Value, err = json.Marshal(nni) |
| 1190 | if err != nil { |
| 1191 | log.Error("Failed to marshal data") |
| 1192 | } |
| 1193 | if err = RsrcMgr.KVStore.Put(path, Value); err != nil { |
| 1194 | log.Errorw("Failed to put to kvstore", log.Fields{"path": path, "value": Value}) |
| 1195 | return err |
| 1196 | } |
| 1197 | log.Debugw("added nni to kv successfully", log.Fields{"path": path, "nni": nniIntf}) |
| 1198 | return nil |
| 1199 | } |
| 1200 | |
| 1201 | // DelNNiFromKVStore deletes nni interface list from kv store. |
| 1202 | func (RsrcMgr *OpenOltResourceMgr) DelNNiFromKVStore() error { |
| 1203 | |
| 1204 | path := fmt.Sprintf(NnniIntfID) |
| 1205 | |
| 1206 | if err := RsrcMgr.KVStore.Delete(path); err != nil { |
| 1207 | log.Errorw("Failed to delete nni interfaces from kv store", log.Fields{"path": path}) |
| 1208 | return err |
| 1209 | } |
| 1210 | return nil |
| 1211 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1212 | |
| 1213 | //UpdateFlowIDsForGem updates flow id per gemport |
| 1214 | func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDsForGem(intf uint32, gem uint32, flowIDs []uint32) error { |
| 1215 | var val []byte |
| 1216 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1217 | |
| 1218 | flowsForGem, err := RsrcMgr.GetFlowIDsGemMapForInterface(intf) |
| 1219 | if err != nil { |
| 1220 | log.Error("Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf}) |
| 1221 | return err |
| 1222 | } |
| 1223 | if flowsForGem == nil { |
| 1224 | flowsForGem = make(map[uint32][]uint32) |
| 1225 | } |
| 1226 | flowsForGem[gem] = flowIDs |
| 1227 | val, err = json.Marshal(flowsForGem) |
| 1228 | if err != nil { |
| 1229 | log.Error("Failed to marshal data", log.Fields{"error": err}) |
| 1230 | return err |
| 1231 | } |
| 1232 | if err = RsrcMgr.KVStore.Put(path, val); err != nil { |
| 1233 | log.Errorw("Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val}) |
| 1234 | return err |
| 1235 | } |
| 1236 | log.Debugw("added flowid list for gem to kv successfully", log.Fields{"path": path, "flowidlist": flowsForGem[gem]}) |
| 1237 | return nil |
| 1238 | } |
| 1239 | |
| 1240 | //DeleteFlowIDsForGem deletes the flowID list entry per gem from kvstore. |
| 1241 | func (RsrcMgr *OpenOltResourceMgr) DeleteFlowIDsForGem(intf uint32, gem uint32) { |
| 1242 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1243 | var val []byte |
| 1244 | |
| 1245 | flowsForGem, err := RsrcMgr.GetFlowIDsGemMapForInterface(intf) |
| 1246 | if err != nil { |
| 1247 | log.Error("Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf}) |
| 1248 | return |
| 1249 | } |
| 1250 | if flowsForGem == nil { |
| 1251 | log.Error("No flowids found ", log.Fields{"intf": intf, "gemport": gem}) |
| 1252 | return |
| 1253 | } |
| 1254 | // once we get the flows per gem map from kv , just delete the gem entry from the map |
| 1255 | delete(flowsForGem, gem) |
| 1256 | // once gem entry is deleted update the kv store. |
| 1257 | val, err = json.Marshal(flowsForGem) |
| 1258 | if err != nil { |
| 1259 | log.Error("Failed to marshal data", log.Fields{"error": err}) |
| 1260 | return |
| 1261 | } |
| 1262 | if err = RsrcMgr.KVStore.Put(path, val); err != nil { |
| 1263 | log.Errorw("Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val}) |
| 1264 | return |
| 1265 | } |
| 1266 | return |
| 1267 | } |
| 1268 | |
| 1269 | //GetFlowIDsGemMapForInterface gets flowids per gemport and interface |
| 1270 | func (RsrcMgr *OpenOltResourceMgr) GetFlowIDsGemMapForInterface(intf uint32) (map[uint32][]uint32, error) { |
| 1271 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1272 | var flowsForGem map[uint32][]uint32 |
| 1273 | var val []byte |
| 1274 | |
| 1275 | value, err := RsrcMgr.KVStore.Get(path) |
| 1276 | if err != nil { |
| 1277 | log.Error("failed to get data from kv store") |
| 1278 | return nil, err |
| 1279 | } |
| 1280 | if value != nil { |
| 1281 | if val, err = kvstore.ToByte(value.Value); err != nil { |
| 1282 | log.Error("Failed to convert to byte array", log.Fields{"error": err}) |
| 1283 | return nil, err |
| 1284 | } |
| 1285 | if err = json.Unmarshal(val, &flowsForGem); err != nil { |
| 1286 | log.Error("Failed to unmarshall", log.Fields{"error": err}) |
| 1287 | return nil, err |
| 1288 | } |
| 1289 | } |
| 1290 | return flowsForGem, nil |
| 1291 | } |