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 Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 249 | log.Debugw("Using device info to init pon resource ranges", log.Fields{"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 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 743 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 744 | AllocIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
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 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 747 | ponrmgr.ALLOC_ID, |
| 748 | AllocIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 749 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 750 | GEMPortIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
| 751 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 752 | ponrmgr.GEMPORT_ID, |
| 753 | GEMPortIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 754 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 755 | FlowIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentFlowIDsForOnu(IntfOnuIDUniID) |
| 756 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 757 | ponrmgr.FLOW_ID, |
| 758 | FlowIDs) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 759 | // Clear resource map associated with (pon_intf_id, gemport_id) tuple. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 760 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 761 | // Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple. |
| 762 | for _, GEM := range GEMPortIDs { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 763 | _ = RsrcMgr.KVStore.Delete(fmt.Sprintf("%d,%d", intfID, GEM)) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 764 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 765 | } |
| 766 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 767 | // IsFlowCookieOnKVStore checks if the given flow cookie is present on the kv store |
| 768 | // Returns true if the flow cookie is found, otherwise it returns false |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 769 | func (RsrcMgr *OpenOltResourceMgr) IsFlowCookieOnKVStore(ponIntfID uint32, onuID int32, uniID int32, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 770 | flowStoreCookie uint64) bool { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 771 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 772 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 773 | FlowIDs := RsrcMgr.ResourceMgrs[ponIntfID].GetCurrentFlowIDsForOnu(FlowPath) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 774 | if FlowIDs != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 775 | log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "onuID": onuID, "uniID": uniID, "KVpath": FlowPath}) |
| 776 | for _, flowID := range FlowIDs { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 777 | FlowInfo := RsrcMgr.GetFlowIDInfo(ponIntfID, int32(onuID), int32(uniID), uint32(flowID)) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 778 | if FlowInfo != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 779 | log.Debugw("Found flows", log.Fields{"flows": *FlowInfo, "flowId": flowID}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 780 | for _, Info := range *FlowInfo { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 781 | if Info.FlowStoreCookie == flowStoreCookie { |
| 782 | 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] | 783 | return true |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | } |
| 789 | return false |
| 790 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 791 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 792 | // 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] | 793 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
| 794 | func (RsrcMgr *OpenOltResourceMgr) GetTechProfileIDForOnu(IntfID uint32, OnuID uint32, UniID uint32) []uint32 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 795 | Path := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 796 | var Data []uint32 |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 797 | Value, err := RsrcMgr.KVStore.Get(Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 798 | if err == nil { |
| 799 | if Value != nil { |
| 800 | Val, err := kvstore.ToByte(Value.Value) |
| 801 | if err != nil { |
| 802 | log.Errorw("Failed to convert into byte array", log.Fields{"error": err}) |
| 803 | return Data |
| 804 | } |
| 805 | if err = json.Unmarshal(Val, &Data); err != nil { |
| 806 | log.Error("Failed to unmarshal", log.Fields{"error": err}) |
| 807 | return Data |
| 808 | } |
| 809 | } |
| 810 | } else { |
| 811 | log.Errorf("Failed to get TP id from kvstore for path %s", Path) |
| 812 | } |
| 813 | log.Debugf("Getting TP id %d from path %s", Data, Path) |
| 814 | return Data |
| 815 | |
| 816 | } |
| 817 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 818 | // RemoveTechProfileIDsForOnu deletes all tech profile ids from the KV-Store for the given onu based on the path |
| 819 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
| 820 | func (RsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDsForOnu(IntfID uint32, OnuID uint32, UniID uint32) error { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 821 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
| 822 | if err := RsrcMgr.KVStore.Delete(IntfOnuUniID); err != nil { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 823 | 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] | 824 | return err |
| 825 | } |
| 826 | return nil |
| 827 | } |
| 828 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 829 | // RemoveTechProfileIDForOnu deletes a specific tech profile id from the KV-Store for the given onu based on the path |
| 830 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
| 831 | func (RsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDForOnu(IntfID uint32, OnuID uint32, UniID uint32, TpID uint32) error { |
| 832 | tpIDList := RsrcMgr.GetTechProfileIDForOnu(IntfID, OnuID, UniID) |
| 833 | for i, tpIDInList := range tpIDList { |
| 834 | if tpIDInList == TpID { |
| 835 | tpIDList = append(tpIDList[:i], tpIDList[i+1:]...) |
| 836 | } |
| 837 | } |
| 838 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
| 839 | Value, err := json.Marshal(tpIDList) |
| 840 | if err != nil { |
| 841 | log.Error("failed to Marshal") |
| 842 | return err |
| 843 | } |
| 844 | if err = RsrcMgr.KVStore.Put(IntfOnuUniID, Value); err != nil { |
| 845 | log.Errorf("Failed to update resource %s", IntfOnuUniID) |
| 846 | return err |
| 847 | } |
| 848 | return err |
| 849 | } |
| 850 | |
| 851 | // UpdateTechProfileIDForOnu updates (put) already present tech-profile-id for the given onu based on the path |
| 852 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 853 | func (RsrcMgr *OpenOltResourceMgr) UpdateTechProfileIDForOnu(IntfID uint32, OnuID uint32, |
| 854 | UniID uint32, TpID uint32) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 855 | var Value []byte |
| 856 | var err error |
| 857 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 858 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 859 | |
| 860 | tpIDList := RsrcMgr.GetTechProfileIDForOnu(IntfID, OnuID, UniID) |
| 861 | for _, value := range tpIDList { |
| 862 | if value == TpID { |
| 863 | log.Debugf("TpID %d is already in tpIdList for the path %s", TpID, IntfOnuUniID) |
| 864 | return err |
| 865 | } |
| 866 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 867 | log.Debugf("updating tp id %d on path %s", TpID, IntfOnuUniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 868 | tpIDList = append(tpIDList, TpID) |
| 869 | Value, err = json.Marshal(tpIDList) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 870 | if err != nil { |
| 871 | log.Error("failed to Marshal") |
| 872 | return err |
| 873 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 874 | if err = RsrcMgr.KVStore.Put(IntfOnuUniID, Value); err != nil { |
| 875 | log.Errorf("Failed to update resource %s", IntfOnuUniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 876 | return err |
| 877 | } |
| 878 | return err |
| 879 | } |
| 880 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 881 | // 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] | 882 | // 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] | 883 | func (RsrcMgr *OpenOltResourceMgr) UpdateMeterIDForOnu(Direction string, IntfID uint32, OnuID uint32, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 884 | UniID uint32, TpID uint32, MeterConfig *ofp.OfpMeterConfig) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 885 | var Value []byte |
| 886 | var err error |
| 887 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 888 | IntfOnuUniID := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 889 | Value, err = json.Marshal(*MeterConfig) |
| 890 | if err != nil { |
| 891 | log.Error("failed to Marshal meter config") |
| 892 | return err |
| 893 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 894 | if err = RsrcMgr.KVStore.Put(IntfOnuUniID, Value); err != nil { |
| 895 | log.Errorf("Failed to store meter into KV store %s", IntfOnuUniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 896 | return err |
| 897 | } |
| 898 | return err |
| 899 | } |
| 900 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 901 | // GetMeterIDForOnu fetches the meter id from the kv store for the given onu based on the path |
| 902 | // This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| 903 | func (RsrcMgr *OpenOltResourceMgr) GetMeterIDForOnu(Direction string, IntfID uint32, OnuID uint32, |
| 904 | UniID uint32, TpID uint32) (*ofp.OfpMeterConfig, error) { |
| 905 | Path := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 906 | var meterConfig ofp.OfpMeterConfig |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 907 | Value, err := RsrcMgr.KVStore.Get(Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 908 | if err == nil { |
| 909 | if Value != nil { |
| 910 | log.Debug("Found meter in KV store", log.Fields{"Direction": Direction}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 911 | Val, er := kvstore.ToByte(Value.Value) |
| 912 | if er != nil { |
| 913 | log.Errorw("Failed to convert into byte array", log.Fields{"error": er}) |
| 914 | return nil, er |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 915 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 916 | if er = json.Unmarshal(Val, &meterConfig); er != nil { |
| 917 | log.Error("Failed to unmarshal meterconfig", log.Fields{"error": er}) |
| 918 | return nil, er |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 919 | } |
| 920 | } else { |
| 921 | log.Debug("meter-does-not-exists-in-KVStore") |
| 922 | return nil, err |
| 923 | } |
| 924 | } else { |
| 925 | log.Errorf("Failed to get Meter config from kvstore for path %s", Path) |
| 926 | |
| 927 | } |
| 928 | return &meterConfig, err |
| 929 | } |
| 930 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 931 | // RemoveMeterIDForOnu deletes the meter id from the kV-Store for the given onu based on the path |
| 932 | // This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| 933 | func (RsrcMgr *OpenOltResourceMgr) RemoveMeterIDForOnu(Direction string, IntfID uint32, OnuID uint32, |
| 934 | UniID uint32, TpID uint32) error { |
| 935 | Path := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 936 | if err := RsrcMgr.KVStore.Delete(Path); err != nil { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 937 | log.Errorf("Failed to delete meter id %s from kvstore ", Path) |
| 938 | return err |
| 939 | } |
| 940 | return nil |
| 941 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 942 | |
| 943 | func getFlowIDFromFlowInfo(FlowInfo *[]FlowInfo, flowID, gemportID uint32, flowStoreCookie uint64, flowCategory string, vlanPcp ...uint32) error { |
| 944 | if FlowInfo != nil { |
| 945 | for _, Info := range *FlowInfo { |
| 946 | if int32(gemportID) == Info.Flow.GemportId && flowCategory != "" && Info.FlowCategory == flowCategory { |
| 947 | log.Debug("Found flow matching with flow category", log.Fields{"flowId": flowID, "FlowCategory": flowCategory}) |
| 948 | if Info.FlowCategory == "HSIA_FLOW" && Info.Flow.Classifier.OPbits == vlanPcp[0] { |
| 949 | log.Debug("Found matching vlan pcp ", log.Fields{"flowId": flowID, "Vlanpcp": vlanPcp[0]}) |
| 950 | return nil |
| 951 | } |
| 952 | } |
| 953 | if int32(gemportID) == Info.Flow.GemportId && flowStoreCookie != 0 && Info.FlowStoreCookie == flowStoreCookie { |
| 954 | if flowCategory != "" && Info.FlowCategory == flowCategory { |
| 955 | log.Debug("Found flow matching with flow category", log.Fields{"flowId": flowID, "FlowCategory": flowCategory}) |
| 956 | return nil |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 961 | 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] | 962 | return errors.New("invalid flow-info") |
| 963 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 964 | |
| 965 | //AddGemToOnuGemInfo adds gemport to onugem info kvstore |
| 966 | func (RsrcMgr *OpenOltResourceMgr) AddGemToOnuGemInfo(intfID uint32, onuID uint32, gemPort uint32) error { |
| 967 | var onuGemData []OnuGemInfo |
| 968 | var err error |
| 969 | |
| 970 | if err = RsrcMgr.ResourceMgrs[intfID].GetOnuGemInfo(intfID, &onuGemData); err != nil { |
| 971 | log.Errorf("failed to get onuifo for intfid %d", intfID) |
| 972 | return err |
| 973 | } |
| 974 | if len(onuGemData) == 0 { |
| 975 | log.Errorw("failed to ger Onuid info ", log.Fields{"intfid": intfID, "onuid": onuID}) |
| 976 | return err |
| 977 | } |
| 978 | |
| 979 | for idx, onugem := range onuGemData { |
| 980 | if onugem.OnuID == onuID { |
| 981 | for _, gem := range onuGemData[idx].GemPorts { |
| 982 | if gem == gemPort { |
| 983 | log.Debugw("Gem already present in onugem info, skpping addition", log.Fields{"gem": gem}) |
| 984 | return nil |
| 985 | } |
| 986 | } |
| 987 | log.Debugw("Added gem to onugem info", log.Fields{"gem": gemPort}) |
| 988 | onuGemData[idx].GemPorts = append(onuGemData[idx].GemPorts, gemPort) |
| 989 | break |
| 990 | } |
| 991 | } |
| 992 | err = RsrcMgr.ResourceMgrs[intfID].AddOnuGemInfo(intfID, onuGemData) |
| 993 | if err != nil { |
| 994 | log.Error("Failed to add onugem to kv store") |
| 995 | return err |
| 996 | } |
| 997 | return err |
| 998 | } |
| 999 | |
| 1000 | //GetOnuGemInfo gets onu gem info from the kvstore per interface |
| 1001 | func (RsrcMgr *OpenOltResourceMgr) GetOnuGemInfo(IntfID uint32) ([]OnuGemInfo, error) { |
| 1002 | var onuGemData []OnuGemInfo |
| 1003 | |
| 1004 | if err := RsrcMgr.ResourceMgrs[IntfID].GetOnuGemInfo(IntfID, &onuGemData); err != nil { |
| 1005 | log.Errorf("failed to get onuifo for intfid %d", IntfID) |
| 1006 | return nil, err |
| 1007 | } |
| 1008 | |
| 1009 | return onuGemData, nil |
| 1010 | } |
| 1011 | |
| 1012 | // AddOnuInfo adds onu info on to the kvstore per interface |
| 1013 | func (RsrcMgr *OpenOltResourceMgr) AddOnuInfo(IntfID uint32, onuGem OnuGemInfo) error { |
| 1014 | var onuGemData []OnuGemInfo |
| 1015 | var err error |
| 1016 | |
| 1017 | if err = RsrcMgr.ResourceMgrs[IntfID].GetOnuGemInfo(IntfID, &onuGemData); err != nil { |
| 1018 | log.Errorf("failed to get onuifo for intfid %d", IntfID) |
| 1019 | return err |
| 1020 | } |
| 1021 | onuGemData = append(onuGemData, onuGem) |
| 1022 | err = RsrcMgr.ResourceMgrs[IntfID].AddOnuGemInfo(IntfID, onuGemData) |
| 1023 | if err != nil { |
| 1024 | log.Error("Failed to add onugem to kv store") |
| 1025 | return err |
| 1026 | } |
| 1027 | |
| 1028 | log.Debugw("added onu to onugeminfo", log.Fields{"intf": IntfID, "onugem": onuGem}) |
| 1029 | return err |
| 1030 | } |
| 1031 | |
| 1032 | // UpdateOnuInfo updates Onuinfo on the kvstore per interface |
| 1033 | func (RsrcMgr *OpenOltResourceMgr) UpdateOnuInfo(IntfID uint32, onuGem []OnuGemInfo) error { |
| 1034 | var onuGemData []OnuGemInfo |
| 1035 | var err error |
| 1036 | |
| 1037 | err = RsrcMgr.ResourceMgrs[IntfID].AddOnuGemInfo(IntfID, onuGemData) |
| 1038 | if err != nil { |
| 1039 | log.Error("Failed to add onugem to kv store") |
| 1040 | return err |
| 1041 | } |
| 1042 | |
| 1043 | log.Debugw("updated onugeminfo", log.Fields{"intf": IntfID, "onugem": onuGem}) |
| 1044 | return err |
| 1045 | } |
| 1046 | |
| 1047 | // AddUniPortToOnuInfo adds uni port to the onuinfo kvstore. check if the uni is already present if not update the kv store. |
| 1048 | func (RsrcMgr *OpenOltResourceMgr) AddUniPortToOnuInfo(intfID uint32, onuID uint32, portNo uint32) { |
| 1049 | var onuGemData []OnuGemInfo |
| 1050 | var err error |
| 1051 | |
| 1052 | if err = RsrcMgr.ResourceMgrs[intfID].GetOnuGemInfo(intfID, &onuGemData); err != nil { |
| 1053 | log.Errorf("failed to get onuifo for intfid %d", intfID) |
| 1054 | return |
| 1055 | } |
| 1056 | for idx, onu := range onuGemData { |
| 1057 | if onu.OnuID == onuID { |
| 1058 | for _, uni := range onu.UniPorts { |
| 1059 | if uni == portNo { |
| 1060 | log.Debugw("uni already present in onugem info", log.Fields{"uni": portNo}) |
| 1061 | return |
| 1062 | } |
| 1063 | } |
| 1064 | onuGemData[idx].UniPorts = append(onuGemData[idx].UniPorts, portNo) |
| 1065 | break |
| 1066 | } |
| 1067 | } |
| 1068 | err = RsrcMgr.ResourceMgrs[intfID].AddOnuGemInfo(intfID, onuGemData) |
| 1069 | if err != nil { |
| 1070 | log.Errorw("Failed to add uin port in onugem to kv store", log.Fields{"uni": portNo}) |
| 1071 | return |
| 1072 | } |
| 1073 | return |
| 1074 | } |
| 1075 | |
| 1076 | //UpdateGemPortForPktIn updates gemport for pkt in path to kvstore, path being intfid, onuid, portno |
| 1077 | func (RsrcMgr *OpenOltResourceMgr) UpdateGemPortForPktIn(pktIn PacketInInfoKey, gemPort uint32) { |
| 1078 | |
| 1079 | path := fmt.Sprintf(OnuPacketINPath, pktIn.IntfID, pktIn.OnuID, pktIn.LogicalPort) |
| 1080 | Value, err := json.Marshal(gemPort) |
| 1081 | if err != nil { |
| 1082 | log.Error("Failed to marshal data") |
| 1083 | return |
| 1084 | } |
| 1085 | if err = RsrcMgr.KVStore.Put(path, Value); err != nil { |
| 1086 | log.Errorw("Failed to put to kvstore", log.Fields{"path": path, "value": gemPort}) |
| 1087 | return |
| 1088 | } |
| 1089 | log.Debugw("added gem packet in successfully", log.Fields{"path": path, "gem": gemPort}) |
| 1090 | |
| 1091 | return |
| 1092 | } |
| 1093 | |
| 1094 | // GetGemPortFromOnuPktIn gets the gem port from onu pkt in path, path being intfid, onuid, portno |
| 1095 | func (RsrcMgr *OpenOltResourceMgr) GetGemPortFromOnuPktIn(intfID uint32, onuID uint32, logicalPort uint32) (uint32, error) { |
| 1096 | |
| 1097 | var Val []byte |
| 1098 | var gemPort uint32 |
| 1099 | |
| 1100 | path := fmt.Sprintf(OnuPacketINPath, intfID, onuID, logicalPort) |
| 1101 | |
| 1102 | value, err := RsrcMgr.KVStore.Get(path) |
| 1103 | if err != nil { |
| 1104 | log.Errorw("Failed to get from kv store", log.Fields{"path": path}) |
| 1105 | return uint32(0), err |
| 1106 | } else if value == nil { |
| 1107 | log.Debugw("No pkt in gem found", log.Fields{"path": path}) |
| 1108 | return uint32(0), nil |
| 1109 | } |
| 1110 | |
| 1111 | if Val, err = kvstore.ToByte(value.Value); err != nil { |
| 1112 | log.Error("Failed to convert to byte array") |
| 1113 | return uint32(0), err |
| 1114 | } |
| 1115 | if err = json.Unmarshal(Val, &gemPort); err != nil { |
| 1116 | log.Error("Failed to unmarshall") |
| 1117 | return uint32(0), err |
| 1118 | } |
| 1119 | log.Debugw("found packein gemport from path", log.Fields{"path": path, "gem": gemPort}) |
| 1120 | |
| 1121 | return gemPort, nil |
| 1122 | } |
| 1123 | |
| 1124 | // DelGemPortPktIn deletes the gemport from the pkt in path |
| 1125 | func (RsrcMgr *OpenOltResourceMgr) DelGemPortPktIn(intfID uint32, onuID uint32, logicalPort uint32) error { |
| 1126 | |
| 1127 | path := fmt.Sprintf(OnuPacketINPath, intfID, onuID, logicalPort) |
| 1128 | if err := RsrcMgr.KVStore.Delete(path); err != nil { |
| 1129 | log.Errorf("Falied to remove resource %s", path) |
| 1130 | return err |
| 1131 | } |
| 1132 | return nil |
| 1133 | } |
| 1134 | |
| 1135 | // DelOnuGemInfoForIntf deletes the onugem info from kvstore per interface |
| 1136 | func (RsrcMgr *OpenOltResourceMgr) DelOnuGemInfoForIntf(intfID uint32) error { |
| 1137 | if err := RsrcMgr.ResourceMgrs[intfID].DelOnuGemInfoForIntf(intfID); err != nil { |
| 1138 | log.Errorw("failed to delete onu gem info for", log.Fields{"intfid": intfID}) |
| 1139 | return err |
| 1140 | } |
| 1141 | return nil |
| 1142 | } |
| 1143 | |
| 1144 | //GetNNIFromKVStore gets NNi intfids from kvstore. path being per device |
| 1145 | func (RsrcMgr *OpenOltResourceMgr) GetNNIFromKVStore() ([]uint32, error) { |
| 1146 | |
| 1147 | var nni []uint32 |
| 1148 | var Val []byte |
| 1149 | |
| 1150 | path := fmt.Sprintf(NnniIntfID) |
| 1151 | value, err := RsrcMgr.KVStore.Get(path) |
| 1152 | if err != nil { |
| 1153 | log.Error("failed to get data from kv store") |
| 1154 | return nil, err |
| 1155 | } |
| 1156 | if value != nil { |
| 1157 | if Val, err = kvstore.ToByte(value.Value); err != nil { |
| 1158 | log.Error("Failed to convert to byte array") |
| 1159 | return nil, err |
| 1160 | } |
| 1161 | if err = json.Unmarshal(Val, &nni); err != nil { |
| 1162 | log.Error("Failed to unmarshall") |
| 1163 | return nil, err |
| 1164 | } |
| 1165 | } |
| 1166 | return nni, err |
| 1167 | } |
| 1168 | |
| 1169 | // AddNNIToKVStore adds Nni interfaces to kvstore, path being per device. |
| 1170 | func (RsrcMgr *OpenOltResourceMgr) AddNNIToKVStore(nniIntf uint32) error { |
| 1171 | var Value []byte |
| 1172 | |
| 1173 | nni, err := RsrcMgr.GetNNIFromKVStore() |
| 1174 | if err != nil { |
| 1175 | log.Error("failed to fetch nni interfaces from kv store") |
| 1176 | return err |
| 1177 | } |
| 1178 | |
| 1179 | path := fmt.Sprintf(NnniIntfID) |
| 1180 | nni = append(nni, nniIntf) |
| 1181 | Value, err = json.Marshal(nni) |
| 1182 | if err != nil { |
| 1183 | log.Error("Failed to marshal data") |
| 1184 | } |
| 1185 | if err = RsrcMgr.KVStore.Put(path, Value); err != nil { |
| 1186 | log.Errorw("Failed to put to kvstore", log.Fields{"path": path, "value": Value}) |
| 1187 | return err |
| 1188 | } |
| 1189 | log.Debugw("added nni to kv successfully", log.Fields{"path": path, "nni": nniIntf}) |
| 1190 | return nil |
| 1191 | } |
| 1192 | |
| 1193 | // DelNNiFromKVStore deletes nni interface list from kv store. |
| 1194 | func (RsrcMgr *OpenOltResourceMgr) DelNNiFromKVStore() error { |
| 1195 | |
| 1196 | path := fmt.Sprintf(NnniIntfID) |
| 1197 | |
| 1198 | if err := RsrcMgr.KVStore.Delete(path); err != nil { |
| 1199 | log.Errorw("Failed to delete nni interfaces from kv store", log.Fields{"path": path}) |
| 1200 | return err |
| 1201 | } |
| 1202 | return nil |
| 1203 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1204 | |
| 1205 | //UpdateFlowIDsForGem updates flow id per gemport |
| 1206 | func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDsForGem(intf uint32, gem uint32, flowIDs []uint32) error { |
| 1207 | var val []byte |
| 1208 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1209 | |
| 1210 | flowsForGem, err := RsrcMgr.GetFlowIDsGemMapForInterface(intf) |
| 1211 | if err != nil { |
| 1212 | log.Error("Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf}) |
| 1213 | return err |
| 1214 | } |
| 1215 | if flowsForGem == nil { |
| 1216 | flowsForGem = make(map[uint32][]uint32) |
| 1217 | } |
| 1218 | flowsForGem[gem] = flowIDs |
| 1219 | val, err = json.Marshal(flowsForGem) |
| 1220 | if err != nil { |
| 1221 | log.Error("Failed to marshal data", log.Fields{"error": err}) |
| 1222 | return err |
| 1223 | } |
| 1224 | if err = RsrcMgr.KVStore.Put(path, val); err != nil { |
| 1225 | log.Errorw("Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val}) |
| 1226 | return err |
| 1227 | } |
| 1228 | log.Debugw("added flowid list for gem to kv successfully", log.Fields{"path": path, "flowidlist": flowsForGem[gem]}) |
| 1229 | return nil |
| 1230 | } |
| 1231 | |
| 1232 | //DeleteFlowIDsForGem deletes the flowID list entry per gem from kvstore. |
| 1233 | func (RsrcMgr *OpenOltResourceMgr) DeleteFlowIDsForGem(intf uint32, gem uint32) { |
| 1234 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1235 | var val []byte |
| 1236 | |
| 1237 | flowsForGem, err := RsrcMgr.GetFlowIDsGemMapForInterface(intf) |
| 1238 | if err != nil { |
| 1239 | log.Error("Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf}) |
| 1240 | return |
| 1241 | } |
| 1242 | if flowsForGem == nil { |
| 1243 | log.Error("No flowids found ", log.Fields{"intf": intf, "gemport": gem}) |
| 1244 | return |
| 1245 | } |
| 1246 | // once we get the flows per gem map from kv , just delete the gem entry from the map |
| 1247 | delete(flowsForGem, gem) |
| 1248 | // once gem entry is deleted update the kv store. |
| 1249 | val, err = json.Marshal(flowsForGem) |
| 1250 | if err != nil { |
| 1251 | log.Error("Failed to marshal data", log.Fields{"error": err}) |
| 1252 | return |
| 1253 | } |
| 1254 | if err = RsrcMgr.KVStore.Put(path, val); err != nil { |
| 1255 | log.Errorw("Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val}) |
| 1256 | return |
| 1257 | } |
| 1258 | return |
| 1259 | } |
| 1260 | |
| 1261 | //GetFlowIDsGemMapForInterface gets flowids per gemport and interface |
| 1262 | func (RsrcMgr *OpenOltResourceMgr) GetFlowIDsGemMapForInterface(intf uint32) (map[uint32][]uint32, error) { |
| 1263 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1264 | var flowsForGem map[uint32][]uint32 |
| 1265 | var val []byte |
| 1266 | |
| 1267 | value, err := RsrcMgr.KVStore.Get(path) |
| 1268 | if err != nil { |
| 1269 | log.Error("failed to get data from kv store") |
| 1270 | return nil, err |
| 1271 | } |
| 1272 | if value != nil { |
| 1273 | if val, err = kvstore.ToByte(value.Value); err != nil { |
| 1274 | log.Error("Failed to convert to byte array", log.Fields{"error": err}) |
| 1275 | return nil, err |
| 1276 | } |
| 1277 | if err = json.Unmarshal(val, &flowsForGem); err != nil { |
| 1278 | log.Error("Failed to unmarshall", log.Fields{"error": err}) |
| 1279 | return nil, err |
| 1280 | } |
| 1281 | } |
| 1282 | return flowsForGem, nil |
| 1283 | } |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame^] | 1284 | |
| 1285 | //DeleteIntfIDGempMapPath deletes the intf id path used to store flow ids per gem to kvstore. |
| 1286 | func (RsrcMgr *OpenOltResourceMgr) DeleteIntfIDGempMapPath(intf uint32) { |
| 1287 | |
| 1288 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1289 | if err := RsrcMgr.KVStore.Delete(path); err != nil { |
| 1290 | log.Errorw("Failed to delete nni interfaces from kv store", log.Fields{"path": path}) |
| 1291 | return |
| 1292 | } |
| 1293 | return |
| 1294 | } |
| 1295 | |
| 1296 | // RemoveResourceMap Clear resource map associated with (intfid, onuid, uniid) tuple. |
| 1297 | func (RsrcMgr *OpenOltResourceMgr) RemoveResourceMap(intfID uint32, onuID int32, uniID int32) { |
| 1298 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
| 1299 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(IntfOnuIDUniID) |
| 1300 | } |