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 ( |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 21 | "context" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 22 | "encoding/json" |
| 23 | "errors" |
| 24 | "fmt" |
| 25 | "strconv" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 26 | "strings" |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 27 | "sync" |
Neha Sharma | cc65696 | 2020-04-14 14:26:11 +0000 | [diff] [blame] | 28 | "time" |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 29 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 30 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
| 31 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v4/pkg/db" |
| 33 | "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore" |
| 34 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 35 | ponrmgr "github.com/opencord/voltha-lib-go/v4/pkg/ponresourcemanager" |
| 36 | ofp "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 37 | "github.com/opencord/voltha-protos/v4/go/openolt" |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 38 | ) |
| 39 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 40 | const ( |
| 41 | // KvstoreTimeout specifies the time out for KV Store Connection |
Neha Sharma | cc65696 | 2020-04-14 14:26:11 +0000 | [diff] [blame] | 42 | KvstoreTimeout = 5 * time.Second |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 43 | // BasePathKvStore - <pathPrefix>/openolt/<device_id> |
| 44 | BasePathKvStore = "%s/openolt/{%s}" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 45 | // TpIDPathSuffix - <(pon_id, onu_id, uni_id)>/tp_id |
| 46 | TpIDPathSuffix = "{%d,%d,%d}/tp_id" |
| 47 | //MeterIDPathSuffix - <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| 48 | MeterIDPathSuffix = "{%d,%d,%d}/{%d}/meter_id/{%s}" |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 49 | //NnniIntfID - nniintfids |
| 50 | NnniIntfID = "nniintfids" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 51 | // OnuPacketINPathPrefix - path prefix where ONU packet-in vlanID/PCP is stored |
| 52 | //format: onu_packetin/{<intfid>,<onuid>,<logicalport>} |
| 53 | OnuPacketINPathPrefix = "onu_packetin/{%d,%d,%d}" |
| 54 | // OnuPacketINPath path on the kvstore to store packetin gemport,which will be used for packetin, packetout |
| 55 | //format: onu_packetin/{<intfid>,<onuid>,<logicalport>}/{<vlanId>,<priority>} |
| 56 | OnuPacketINPath = OnuPacketINPathPrefix + "/{%d,%d}" |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 57 | //FlowIDsForGem flowids_per_gem/<intfid> |
| 58 | FlowIDsForGem = "flowids_per_gem/{%d}" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 59 | //McastQueuesForIntf multicast queues for pon interfaces |
| 60 | McastQueuesForIntf = "mcast_qs_for_int" |
| 61 | //FlowGroup flow_groups/<flow_group_id> |
| 62 | // A group is stored under this path on the KV store after it has been installed to the device. |
| 63 | // It should also be deleted after it has been removed from the device accordingly. |
| 64 | FlowGroup = "flow_groups/{%d}" |
| 65 | //FlowGroupCached flow_groups_cached/<flow_group_id> |
| 66 | // When a group add request received, we create the group without setting any members to it since we cannot |
| 67 | // set any members to a group until it is associated with a multicast flow. It is a BAL limitation. |
| 68 | // When the related multicast flow has been created we perform set members operation for the group. |
| 69 | // That is why we need to keep the members of a group until the multicast flow creation request comes. |
| 70 | // We preserve the groups under "FlowGroupsCached" directory in the KV store temporarily. Having set members, |
| 71 | // we remove the group from the cached group store. |
| 72 | FlowGroupCached = "flow_groups_cached/{%d}" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 73 | |
| 74 | //FlowIDPath - Path on the KV store for storing list of Flow IDs for a given subscriber |
| 75 | //Format: BasePathKvStore/<(pon_intf_id, onu_id, uni_id)>/flow_ids |
| 76 | FlowIDPath = "{%s}/flow_ids" |
| 77 | //FlowIDInfoPath - Used to store more metadata associated with the flow_id |
| 78 | //Format: BasePathKvStore/<(pon_intf_id, onu_id, uni_id)>/flow_id_info/<flow_id> |
| 79 | FlowIDInfoPath = "{%s}/flow_id_info/{%d}" |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 80 | ) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 81 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 82 | // FlowInfo holds the flow information |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 83 | type FlowInfo struct { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 84 | Flow *openolt.Flow |
| 85 | IsSymmtricFlow bool |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | // OnuGemInfo holds onu information along with gem port list and uni port list |
| 89 | type OnuGemInfo struct { |
| 90 | OnuID uint32 |
| 91 | SerialNumber string |
| 92 | IntfID uint32 |
| 93 | GemPorts []uint32 |
| 94 | UniPorts []uint32 |
| 95 | } |
| 96 | |
| 97 | // PacketInInfoKey is the key for packet in gemport |
| 98 | type PacketInInfoKey struct { |
| 99 | IntfID uint32 |
| 100 | OnuID uint32 |
| 101 | LogicalPort uint32 |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 102 | VlanID uint16 |
| 103 | Priority uint8 |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 104 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 105 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 106 | // GroupInfo holds group information |
| 107 | type GroupInfo struct { |
| 108 | GroupID uint32 |
| 109 | OutPorts []uint32 |
| 110 | } |
| 111 | |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 112 | // MeterInfo store meter information at path <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| 113 | type MeterInfo struct { |
| 114 | RefCnt uint8 // number of flow references for this meter. When RefCnt is 0, the MeterInfo should be deleted. |
| 115 | MeterConfig ofp.OfpMeterConfig |
| 116 | } |
| 117 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 118 | // OpenOltResourceMgr holds resource related information as provided below for each field |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 119 | type OpenOltResourceMgr struct { |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 120 | DeviceID string // OLT device id |
| 121 | Address string // Host and port of the kv store to connect to |
| 122 | Args string // args |
| 123 | KVStore *db.Backend // backend kv store connection handle |
| 124 | DeviceType string |
| 125 | DevInfo *openolt.DeviceInfo // device information |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 126 | // array of pon resource managers per interface technology |
| 127 | ResourceMgrs map[uint32]*ponrmgr.PONResourceManager |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 128 | |
| 129 | // This protects concurrent gemport_id allocate/delete calls on a per PON port basis |
| 130 | GemPortIDMgmtLock []sync.RWMutex |
| 131 | // This protects concurrent alloc_id allocate/delete calls on a per PON port basis |
| 132 | AllocIDMgmtLock []sync.RWMutex |
| 133 | // This protects concurrent onu_id allocate/delete calls on a per PON port basis |
| 134 | OnuIDMgmtLock []sync.RWMutex |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 135 | } |
| 136 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 137 | func newKVClient(ctx context.Context, storeType string, address string, timeout time.Duration) (kvstore.Client, error) { |
| 138 | logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 139 | switch storeType { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 140 | case "etcd": |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 141 | return kvstore.NewEtcdClient(ctx, address, timeout, log.FatalLevel) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 142 | } |
| 143 | return nil, errors.New("unsupported-kv-store") |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 144 | } |
| 145 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 146 | // SetKVClient sets the KV client and return a kv backend |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 147 | func SetKVClient(ctx context.Context, backend string, addr string, DeviceID string, basePathKvStore string) *db.Backend { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 148 | // TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some |
| 149 | // issue between kv store and backend , core is not calling NewBackend directly |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 150 | kvClient, err := newKVClient(ctx, backend, addr, KvstoreTimeout) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 151 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 152 | logger.Fatalw(ctx, "Failed to init KV client\n", log.Fields{"err": err}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 153 | return nil |
| 154 | } |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 155 | |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 156 | kvbackend := &db.Backend{ |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 157 | Client: kvClient, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 158 | StoreType: backend, |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 159 | Address: addr, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 160 | Timeout: KvstoreTimeout, |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 161 | PathPrefix: fmt.Sprintf(BasePathKvStore, basePathKvStore, DeviceID)} |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 162 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 163 | return kvbackend |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 164 | } |
| 165 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 166 | // 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] | 167 | // instances according to technology. Initializes the default resource ranges for all |
| 168 | // the resources. |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 169 | func NewResourceMgr(ctx context.Context, deviceID string, KVStoreAddress string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo, basePathKvStore string) *OpenOltResourceMgr { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 170 | var ResourceMgr OpenOltResourceMgr |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 171 | logger.Debugf(ctx, "Init new resource manager , address: %s, device-id: %s", KVStoreAddress, deviceID) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 172 | ResourceMgr.DeviceID = deviceID |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 173 | ResourceMgr.Address = KVStoreAddress |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 174 | ResourceMgr.DeviceType = deviceType |
| 175 | ResourceMgr.DevInfo = devInfo |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 176 | NumPONPorts := devInfo.GetPonPorts() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 177 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 178 | Backend := kvStoreType |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 179 | ResourceMgr.KVStore = SetKVClient(ctx, Backend, ResourceMgr.Address, deviceID, basePathKvStore) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 180 | if ResourceMgr.KVStore == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 181 | logger.Error(ctx, "Failed to setup KV store") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 182 | } |
| 183 | Ranges := make(map[string]*openolt.DeviceInfo_DeviceResourceRanges) |
| 184 | RsrcMgrsByTech := make(map[string]*ponrmgr.PONResourceManager) |
| 185 | ResourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 186 | |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 187 | ResourceMgr.AllocIDMgmtLock = make([]sync.RWMutex, NumPONPorts) |
| 188 | ResourceMgr.GemPortIDMgmtLock = make([]sync.RWMutex, NumPONPorts) |
| 189 | ResourceMgr.OnuIDMgmtLock = make([]sync.RWMutex, NumPONPorts) |
| 190 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 191 | // TODO self.args = registry('main').get_args() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 192 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 193 | /* |
| 194 | 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] | 195 | the legacy global per-device information. This, in theory, is temporary until |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 196 | the legacy drivers are upgrade to support pool ranges. |
| 197 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 198 | if devInfo.Ranges == nil { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 199 | var ranges openolt.DeviceInfo_DeviceResourceRanges |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 200 | ranges.Technology = devInfo.GetTechnology() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 201 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 202 | var index uint32 |
| 203 | for index = 0; index < NumPONPorts; index++ { |
| 204 | ranges.IntfIds = append(ranges.IntfIds, index) |
| 205 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 206 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 207 | var Pool openolt.DeviceInfo_DeviceResourceRanges_Pool |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 208 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 209 | Pool.Start = devInfo.OnuIdStart |
| 210 | Pool.End = devInfo.OnuIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 211 | Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 212 | onuPool := Pool |
| 213 | ranges.Pools = append(ranges.Pools, &onuPool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 214 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 215 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 216 | Pool.Start = devInfo.AllocIdStart |
| 217 | Pool.End = devInfo.AllocIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 218 | Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 219 | allocPool := Pool |
| 220 | ranges.Pools = append(ranges.Pools, &allocPool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 221 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 222 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 223 | Pool.Start = devInfo.GemportIdStart |
| 224 | Pool.End = devInfo.GemportIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 225 | Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 226 | gemPool := Pool |
| 227 | ranges.Pools = append(ranges.Pools, &gemPool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 228 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 229 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 230 | Pool.Start = devInfo.FlowIdStart |
| 231 | Pool.End = devInfo.FlowIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 232 | 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] | 233 | ranges.Pools = append(ranges.Pools, &Pool) |
| 234 | // Add to device info |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 235 | devInfo.Ranges = append(devInfo.Ranges, &ranges) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 236 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 237 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 238 | // Create a separate Resource Manager instance for each range. This assumes that |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 239 | // each technology is represented by only a single range |
| 240 | var GlobalPONRsrcMgr *ponrmgr.PONResourceManager |
| 241 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 242 | for _, TechRange := range devInfo.Ranges { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 243 | technology := TechRange.Technology |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 244 | logger.Debugf(ctx, "Device info technology %s", technology) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 245 | Ranges[technology] = TechRange |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 246 | |
| 247 | RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(ctx, technology, deviceType, deviceID, |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 248 | Backend, ResourceMgr.Address, basePathKvStore) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 249 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 250 | logger.Errorf(ctx, "Failed to create pon resource manager instance for technology %s", technology) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 251 | return nil |
| 252 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 253 | // resource_mgrs_by_tech[technology] = resource_mgr |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 254 | if GlobalPONRsrcMgr == nil { |
| 255 | GlobalPONRsrcMgr = RsrcMgrsByTech[technology] |
| 256 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 257 | for _, IntfID := range TechRange.IntfIds { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 258 | ResourceMgr.ResourceMgrs[IntfID] = RsrcMgrsByTech[technology] |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 259 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 260 | // self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 261 | InitializeDeviceResourceRangeAndPool(ctx, RsrcMgrsByTech[technology], GlobalPONRsrcMgr, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 262 | TechRange, devInfo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 263 | } |
| 264 | // After we have initialized resource ranges, initialize the |
| 265 | // resource pools accordingly. |
| 266 | for _, PONRMgr := range RsrcMgrsByTech { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 267 | _ = PONRMgr.InitDeviceResourcePool(ctx) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 268 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 269 | logger.Info(ctx, "Initialization of resource manager success!") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 270 | return &ResourceMgr |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 271 | } |
| 272 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 273 | // InitializeDeviceResourceRangeAndPool initializes the resource range pool according to the sharing type, then apply |
| 274 | // device specific information. If KV doesn't exist |
| 275 | // or is broader than the device, the device's information will |
| 276 | // dictate the range limits |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 277 | func InitializeDeviceResourceRangeAndPool(ctx context.Context, ponRMgr *ponrmgr.PONResourceManager, globalPONRMgr *ponrmgr.PONResourceManager, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 278 | techRange *openolt.DeviceInfo_DeviceResourceRanges, devInfo *openolt.DeviceInfo) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 279 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 280 | // init the resource range pool according to the sharing type |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 281 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 282 | logger.Debugf(ctx, "Resource range pool init for technology %s", ponRMgr.Technology) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 283 | // first load from KV profiles |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 284 | status := ponRMgr.InitResourceRangesFromKVStore(ctx) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 285 | if !status { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 286 | logger.Debugf(ctx, "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] | 287 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 288 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 289 | /* |
| 290 | Then apply device specific information. If KV doesn't exist |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 291 | or is broader than the device, the device's information will |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 292 | dictate the range limits |
| 293 | */ |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 294 | logger.Debugw(ctx, "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] | 295 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 296 | ONUIDStart := devInfo.OnuIdStart |
| 297 | ONUIDEnd := devInfo.OnuIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 298 | ONUIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF |
| 299 | ONUIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 300 | AllocIDStart := devInfo.AllocIdStart |
| 301 | AllocIDEnd := devInfo.AllocIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 302 | AllocIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 303 | AllocIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 304 | GEMPortIDStart := devInfo.GemportIdStart |
| 305 | GEMPortIDEnd := devInfo.GemportIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 306 | GEMPortIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 307 | GEMPortIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 308 | FlowIDStart := devInfo.FlowIdStart |
| 309 | FlowIDEnd := devInfo.FlowIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 310 | FlowIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 311 | FlowIDSharedPoolID := uint32(0) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 312 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 313 | var FirstIntfPoolID uint32 |
| 314 | var SharedPoolID uint32 |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 315 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 316 | /* |
| 317 | * 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] | 318 | * 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] | 319 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 320 | for _, FirstIntfPoolID = range techRange.IntfIds { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 321 | // skip the intf id 0 |
| 322 | if FirstIntfPoolID == 0 { |
| 323 | continue |
| 324 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 325 | break |
| 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 | for _, RangePool := range techRange.Pools { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 329 | 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] | 330 | SharedPoolID = FirstIntfPoolID |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 331 | } else if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_SAME_TECH { |
| 332 | SharedPoolID = FirstIntfPoolID |
| 333 | } else { |
| 334 | SharedPoolID = 0 |
| 335 | } |
| 336 | if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID { |
| 337 | ONUIDStart = RangePool.Start |
| 338 | ONUIDEnd = RangePool.End |
| 339 | ONUIDShared = RangePool.Sharing |
| 340 | ONUIDSharedPoolID = SharedPoolID |
| 341 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID { |
| 342 | AllocIDStart = RangePool.Start |
| 343 | AllocIDEnd = RangePool.End |
| 344 | AllocIDShared = RangePool.Sharing |
| 345 | AllocIDSharedPoolID = SharedPoolID |
| 346 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID { |
| 347 | GEMPortIDStart = RangePool.Start |
| 348 | GEMPortIDEnd = RangePool.End |
| 349 | GEMPortIDShared = RangePool.Sharing |
| 350 | GEMPortIDSharedPoolID = SharedPoolID |
| 351 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID { |
| 352 | FlowIDStart = RangePool.Start |
| 353 | FlowIDEnd = RangePool.End |
| 354 | FlowIDShared = RangePool.Sharing |
| 355 | FlowIDSharedPoolID = SharedPoolID |
| 356 | } |
| 357 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 358 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 359 | logger.Debugw(ctx, "Device info init", log.Fields{"technology": techRange.Technology, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 360 | "onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID, |
| 361 | "alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd, |
| 362 | "alloc_id_shared_pool_id": AllocIDSharedPoolID, |
| 363 | "gemport_id_start": GEMPortIDStart, "gemport_id_end": GEMPortIDEnd, |
| 364 | "gemport_id_shared_pool_id": GEMPortIDSharedPoolID, |
| 365 | "flow_id_start": FlowIDStart, |
| 366 | "flow_id_end_idx": FlowIDEnd, |
| 367 | "flow_id_shared_pool_id": FlowIDSharedPoolID, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 368 | "intf_ids": techRange.IntfIds, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 369 | "uni_id_start": 0, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 370 | "uni_id_end_idx": 1, /*MaxUNIIDperONU()*/ |
| 371 | }) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 372 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 373 | ponRMgr.InitDefaultPONResourceRanges(ctx, ONUIDStart, ONUIDEnd, ONUIDSharedPoolID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 374 | AllocIDStart, AllocIDEnd, AllocIDSharedPoolID, |
| 375 | GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID, |
| 376 | FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 377 | devInfo.PonPorts, techRange.IntfIds) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 378 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 379 | // 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] | 380 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 381 | if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 382 | globalPONRMgr.UpdateRanges(ctx, ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 383 | "", 0, nil) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 384 | ponRMgr.UpdateRanges(ctx, ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 385 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 386 | } |
| 387 | if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 388 | globalPONRMgr.UpdateRanges(ctx, ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 389 | "", 0, nil) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 390 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 391 | ponRMgr.UpdateRanges(ctx, ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 392 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 393 | } |
| 394 | if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 395 | globalPONRMgr.UpdateRanges(ctx, ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 396 | "", 0, nil) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 397 | ponRMgr.UpdateRanges(ctx, ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 398 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 399 | } |
| 400 | if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 401 | globalPONRMgr.UpdateRanges(ctx, ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 402 | "", 0, nil) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 403 | ponRMgr.UpdateRanges(ctx, ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 404 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 405 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 406 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 407 | // Make sure loaded range fits the platform bit encoding ranges |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 408 | ponRMgr.UpdateRanges(ctx, 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] | 409 | } |
| 410 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 411 | // Delete clears used resources for the particular olt device being deleted |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 412 | func (RsrcMgr *OpenOltResourceMgr) Delete(ctx context.Context) error { |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 413 | /* TODO |
| 414 | def __del__(self): |
| 415 | self.log.info("clearing-device-resource-pool") |
| 416 | for key, resource_mgr in self.resource_mgrs.iteritems(): |
| 417 | resource_mgr.clear_device_resource_pool() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 418 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 419 | def assert_pon_id_limit(self, pon_intf_id): |
| 420 | assert pon_intf_id in self.resource_mgrs |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 421 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 422 | def assert_onu_id_limit(self, pon_intf_id, onu_id): |
| 423 | self.assert_pon_id_limit(pon_intf_id) |
| 424 | 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] | 425 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 426 | @property |
| 427 | def max_uni_id_per_onu(self): |
| 428 | 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] | 429 | |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 430 | def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id): |
| 431 | self.assert_onu_id_limit(pon_intf_id, onu_id) |
| 432 | self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID) |
| 433 | */ |
| 434 | for _, rsrcMgr := range RsrcMgr.ResourceMgrs { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 435 | if err := rsrcMgr.ClearDeviceResourcePool(ctx); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 436 | logger.Debug(ctx, "Failed to clear device resource pool") |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 437 | return err |
| 438 | } |
| 439 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 440 | logger.Debug(ctx, "Cleared device resource pool") |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 441 | return nil |
| 442 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 443 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 444 | // GetONUID returns the available OnuID for the given pon-port |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 445 | func (RsrcMgr *OpenOltResourceMgr) GetONUID(ctx context.Context, ponIntfID uint32) (uint32, error) { |
salmansiddiqui | 352a45c | 2019-08-19 10:15:36 +0000 | [diff] [blame] | 446 | // Check if Pon Interface ID is present in Resource-manager-map |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 447 | RsrcMgr.OnuIDMgmtLock[ponIntfID].Lock() |
| 448 | defer RsrcMgr.OnuIDMgmtLock[ponIntfID].Unlock() |
| 449 | |
salmansiddiqui | 352a45c | 2019-08-19 10:15:36 +0000 | [diff] [blame] | 450 | if _, ok := RsrcMgr.ResourceMgrs[ponIntfID]; !ok { |
| 451 | err := errors.New("invalid-pon-interface-" + strconv.Itoa(int(ponIntfID))) |
| 452 | return 0, err |
| 453 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 454 | // Get ONU id for a provided pon interface ID. |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 455 | onuID, err := RsrcMgr.ResourceMgrs[ponIntfID].TechProfileMgr.GetResourceID(ctx, ponIntfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 456 | ponrmgr.ONU_ID, 1) |
| 457 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 458 | logger.Errorf(ctx, "Failed to get resource for interface %d for type %s", |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 459 | ponIntfID, ponrmgr.ONU_ID) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 460 | return 0, err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 461 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 462 | if onuID != nil { |
| 463 | RsrcMgr.ResourceMgrs[ponIntfID].InitResourceMap(ctx, fmt.Sprintf("%d,%d", ponIntfID, onuID[0])) |
| 464 | return onuID[0], err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 465 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 466 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 467 | return 0, err // return OnuID 0 on error |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 468 | } |
| 469 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 470 | // GetFlowIDInfo returns the slice of flow info of the given pon-port |
| 471 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 472 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 473 | func (RsrcMgr *OpenOltResourceMgr) GetFlowIDInfo(ctx context.Context, ponIntfID uint32, onuID int32, uniID int32, flowID uint64) *FlowInfo { |
| 474 | var flowInfo FlowInfo |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 475 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 476 | subs := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 477 | Path := fmt.Sprintf(FlowIDInfoPath, subs, flowID) |
| 478 | value, err := RsrcMgr.KVStore.Get(ctx, Path) |
| 479 | if err == nil { |
| 480 | if value != nil { |
| 481 | Val, err := toByte(value.Value) |
| 482 | if err != nil { |
| 483 | logger.Errorw(ctx, "Failed to convert flowinfo into byte array", log.Fields{"error": err, "subs": subs}) |
| 484 | return nil |
| 485 | } |
| 486 | if err = json.Unmarshal(Val, &flowInfo); err != nil { |
| 487 | logger.Errorw(ctx, "Failed to unmarshal", log.Fields{"error": err, "subs": subs}) |
| 488 | return nil |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | if flowInfo.Flow == nil { |
| 493 | logger.Debugw(ctx, "No flowInfo found in KV store", log.Fields{"subs": subs}) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 494 | return nil |
| 495 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 496 | return &flowInfo |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 497 | } |
| 498 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 499 | // GetCurrentFlowIDsForOnu fetches flow ID from the resource manager |
| 500 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 501 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 502 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentFlowIDsForOnu(ctx context.Context, ponIntfID uint32, onuID int32, uniID int32) ([]uint64, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 503 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 504 | subs := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 505 | path := fmt.Sprintf(FlowIDPath, subs) |
| 506 | |
| 507 | var data []uint64 |
| 508 | value, err := RsrcMgr.KVStore.Get(ctx, path) |
| 509 | if err == nil { |
| 510 | if value != nil { |
| 511 | Val, _ := toByte(value.Value) |
| 512 | if err = json.Unmarshal(Val, &data); err != nil { |
| 513 | logger.Error(ctx, "Failed to unmarshal") |
| 514 | return nil, err |
| 515 | } |
| 516 | } |
Serkant Uluderya | 89ff40c | 2019-10-17 16:02:25 -0700 | [diff] [blame] | 517 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 518 | return data, nil |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 519 | } |
| 520 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 521 | // UpdateFlowIDInfo updates flow info for the given pon interface, onu id, and uni id |
| 522 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 523 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 524 | func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDInfo(ctx context.Context, ponIntfID uint32, onuID int32, uniID int32, |
| 525 | flowID uint64, flowData FlowInfo) error { |
| 526 | |
| 527 | subs := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 528 | path := fmt.Sprintf(FlowIDInfoPath, subs, flowID) |
| 529 | |
| 530 | var value []byte |
| 531 | var err error |
| 532 | value, err = json.Marshal(flowData) |
| 533 | if err != nil { |
| 534 | logger.Errorf(ctx, "failed to Marshal, resource path %s", path) |
| 535 | return err |
| 536 | } |
| 537 | |
| 538 | if err = RsrcMgr.KVStore.Put(ctx, path, value); err != nil { |
| 539 | logger.Errorf(ctx, "Failed to update resource %s", path) |
| 540 | } |
| 541 | |
| 542 | // Update the flowID list for the ONU |
| 543 | if err = RsrcMgr.UpdateFlowIDForOnu(ctx, ponIntfID, onuID, uniID, flowID, true); err != nil { |
| 544 | // If the operation fails, try to remove FlowInfo from the KV store |
| 545 | _ = RsrcMgr.KVStore.Delete(ctx, path) |
| 546 | return err |
| 547 | } |
| 548 | return err |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 549 | } |
| 550 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 551 | // UpdateFlowIDForOnu updates the flow_id list of the ONU (add or remove flow_id from the list) |
| 552 | func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDForOnu(ctx context.Context, ponIntfID uint32, onuID int32, uniID int32, flowID uint64, add bool) error { |
| 553 | /* |
| 554 | Update the flow_id list of the ONU (add or remove flow_id from the list) |
| 555 | :param pon_intf_onu_id: reference of PON interface id and onu id |
| 556 | :param flow_id: flow ID |
| 557 | :param add: Boolean flag to indicate whether the flow_id should be |
| 558 | added or removed from the list. Defaults to adding the flow. |
| 559 | */ |
| 560 | var Value []byte |
| 561 | var err error |
| 562 | var retVal bool |
| 563 | var idx uint64 |
| 564 | subs := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 565 | path := fmt.Sprintf(FlowIDPath, subs) |
| 566 | flowIDs, err := RsrcMgr.GetCurrentFlowIDsForOnu(ctx, ponIntfID, onuID, uniID) |
| 567 | if err != nil { |
| 568 | // Error logged in the called function |
| 569 | return err |
| 570 | } |
| 571 | |
| 572 | if add { |
| 573 | if retVal, _ = checkForFlowIDInList(flowIDs, flowID); retVal { |
| 574 | return nil |
| 575 | } |
| 576 | flowIDs = append(flowIDs, flowID) |
| 577 | } else { |
| 578 | if retVal, idx = checkForFlowIDInList(flowIDs, flowID); !retVal { |
| 579 | return nil |
| 580 | } |
| 581 | // delete the index and shift |
| 582 | flowIDs = append(flowIDs[:idx], flowIDs[idx+1:]...) |
| 583 | } |
| 584 | Value, err = json.Marshal(flowIDs) |
| 585 | if err != nil { |
| 586 | logger.Error(ctx, "Failed to Marshal") |
| 587 | return err |
| 588 | } |
| 589 | |
| 590 | if err = RsrcMgr.KVStore.Put(ctx, path, Value); err != nil { |
| 591 | logger.Errorf(ctx, "Failed to update resource %s", path) |
| 592 | return err |
| 593 | } |
| 594 | return err |
| 595 | } |
| 596 | |
| 597 | // RemoveFlowIDInfo remove flow info for the given pon interface, onu id, and uni id |
| 598 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 599 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
| 600 | func (RsrcMgr *OpenOltResourceMgr) RemoveFlowIDInfo(ctx context.Context, ponIntfID uint32, onuID int32, uniID int32, |
| 601 | flowID uint64) error { |
| 602 | |
| 603 | subs := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 604 | path := fmt.Sprintf(FlowIDInfoPath, subs, flowID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 605 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 606 | var err error |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 607 | if err = RsrcMgr.KVStore.Delete(ctx, path); err != nil { |
| 608 | logger.Errorf(ctx, "Failed to delete resource %s", path) |
| 609 | return err |
| 610 | } |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 611 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 612 | // Update the flowID list for the ONU |
| 613 | err = RsrcMgr.UpdateFlowIDForOnu(ctx, ponIntfID, onuID, uniID, flowID, false) |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 614 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 615 | return err |
| 616 | } |
| 617 | |
| 618 | // RemoveAllFlowsForIntfOnuUniKey removes flow info for the given interface, onu id, and uni id |
| 619 | func (RsrcMgr *OpenOltResourceMgr) RemoveAllFlowsForIntfOnuUniKey(ctx context.Context, intf uint32, onuID int32, uniID int32) error { |
| 620 | flowIDs, err := RsrcMgr.GetCurrentFlowIDsForOnu(ctx, intf, onuID, uniID) |
| 621 | if err != nil { |
| 622 | // error logged in the called function |
| 623 | return err |
| 624 | } |
| 625 | for _, flID := range flowIDs { |
| 626 | if err := RsrcMgr.RemoveFlowIDInfo(ctx, intf, onuID, uniID, flID); err != nil { |
| 627 | logger.Errorw(ctx, "failed-to-delete-flow-id-info", log.Fields{"intf": intf, "onuID": onuID, "uniID": uniID, "flowID": flID}) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 628 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 629 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 630 | subs := fmt.Sprintf("%d,%d,%d", intf, onuID, uniID) |
| 631 | path := fmt.Sprintf(FlowIDPath, subs) |
| 632 | if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil { |
| 633 | logger.Errorf(ctx, "Failed to delete resource %s", path) |
| 634 | return err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 635 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 636 | return nil |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 637 | } |
| 638 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 639 | // GetAllocID return the first Alloc ID for a given pon interface id and onu id and then update the resource map on |
| 640 | // the KV store with the list of alloc_ids allocated for the pon_intf_onu_id tuple |
| 641 | // Currently of all the alloc_ids available, it returns the first alloc_id in the list for tha given ONU |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 642 | func (RsrcMgr *OpenOltResourceMgr) GetAllocID(ctx context.Context, intfID uint32, onuID uint32, uniID uint32) uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 643 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 644 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 645 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 646 | |
| 647 | RsrcMgr.AllocIDMgmtLock[intfID].Lock() |
| 648 | defer RsrcMgr.AllocIDMgmtLock[intfID].Unlock() |
| 649 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 650 | AllocID := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(ctx, IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 651 | if AllocID != nil { |
| 652 | // Since we support only one alloc_id for the ONU at the moment, |
| 653 | // return the first alloc_id in the list, if available, for that |
| 654 | // ONU. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 655 | logger.Debugw(ctx, "Retrieved alloc ID from pon resource mgr", log.Fields{"AllocID": AllocID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 656 | return AllocID[0] |
| 657 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 658 | AllocID, err = RsrcMgr.ResourceMgrs[intfID].GetResourceID(ctx, intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 659 | ponrmgr.ALLOC_ID, 1) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 660 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 661 | if AllocID == nil || err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 662 | logger.Error(ctx, "Failed to allocate alloc id") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 663 | return 0 |
| 664 | } |
| 665 | // update the resource map on KV store with the list of alloc_id |
| 666 | // allocated for the pon_intf_onu_id tuple |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 667 | err = RsrcMgr.ResourceMgrs[intfID].UpdateAllocIdsForOnu(ctx, IntfOnuIDUniID, AllocID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 668 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 669 | logger.Error(ctx, "Failed to update Alloc ID") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 670 | return 0 |
| 671 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 672 | logger.Debugw(ctx, "Allocated new Tcont from pon resource mgr", log.Fields{"AllocID": AllocID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 673 | return AllocID[0] |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 674 | } |
| 675 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 676 | // UpdateAllocIdsForOnu updates alloc ids in kv store for a given pon interface id, onu id and uni id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 677 | func (RsrcMgr *OpenOltResourceMgr) UpdateAllocIdsForOnu(ctx context.Context, ponPort uint32, onuID uint32, uniID uint32, allocID []uint32) error { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 678 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 679 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 680 | return RsrcMgr.ResourceMgrs[ponPort].UpdateAllocIdsForOnu(ctx, IntfOnuIDUniID, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 681 | allocID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 682 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 683 | |
| 684 | // GetCurrentGEMPortIDsForOnu returns gem ports for given pon interface , onu id and uni id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 685 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentGEMPortIDsForOnu(ctx context.Context, intfID uint32, onuID uint32, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 686 | uniID uint32) []uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 687 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 688 | /* 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] | 689 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 690 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 691 | return RsrcMgr.ResourceMgrs[intfID].GetCurrentGEMPortIDsForOnu(ctx, IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 692 | } |
| 693 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 694 | // GetCurrentAllocIDsForOnu returns alloc ids for given pon interface and onu id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 695 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentAllocIDsForOnu(ctx context.Context, intfID uint32, onuID uint32, uniID uint32) []uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 696 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 697 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 698 | AllocID := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(ctx, IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 699 | if AllocID != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 700 | return AllocID |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 701 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 702 | return []uint32{} |
| 703 | } |
| 704 | |
| 705 | // RemoveAllocIDForOnu removes the alloc id for given pon interface, onu id, uni id and alloc id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 706 | func (RsrcMgr *OpenOltResourceMgr) RemoveAllocIDForOnu(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID uint32) { |
| 707 | allocIDs := RsrcMgr.GetCurrentAllocIDsForOnu(ctx, intfID, onuID, uniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 708 | for i := 0; i < len(allocIDs); i++ { |
| 709 | if allocIDs[i] == allocID { |
| 710 | allocIDs = append(allocIDs[:i], allocIDs[i+1:]...) |
| 711 | break |
| 712 | } |
| 713 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 714 | err := RsrcMgr.UpdateAllocIdsForOnu(ctx, intfID, onuID, uniID, allocIDs) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 715 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 716 | logger.Errorf(ctx, "Failed to Remove Alloc Id For Onu. IntfID %d onuID %d uniID %d allocID %d", |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 717 | intfID, onuID, uniID, allocID) |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | // RemoveGemPortIDForOnu removes the gem port id for given pon interface, onu id, uni id and gem port id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 722 | func (RsrcMgr *OpenOltResourceMgr) RemoveGemPortIDForOnu(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, gemPortID uint32) { |
| 723 | gemPortIDs := RsrcMgr.GetCurrentGEMPortIDsForOnu(ctx, intfID, onuID, uniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 724 | for i := 0; i < len(gemPortIDs); i++ { |
| 725 | if gemPortIDs[i] == gemPortID { |
| 726 | gemPortIDs = append(gemPortIDs[:i], gemPortIDs[i+1:]...) |
| 727 | break |
| 728 | } |
| 729 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 730 | err := RsrcMgr.UpdateGEMPortIDsForOnu(ctx, intfID, onuID, uniID, gemPortIDs) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 731 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 732 | logger.Errorf(ctx, "Failed to Remove Gem Id For Onu. IntfID %d onuID %d uniID %d gemPortId %d", |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 733 | intfID, onuID, uniID, gemPortID) |
| 734 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 735 | } |
| 736 | |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 737 | //GetUniPortByPonPortGemPortFromKVStore retrieves onu and uni ID associated with the pon and gem ports. |
| 738 | func (RsrcMgr *OpenOltResourceMgr) GetUniPortByPonPortGemPortFromKVStore(ctx context.Context, PonPort uint32, GemPort uint32) (uint32, uint32, error) { |
| 739 | IntfGEMPortPath := fmt.Sprintf("%d,%d", PonPort, GemPort) |
| 740 | logger.Debugf(ctx, "Getting ONU and UNI IDs from the path %s", IntfGEMPortPath) |
| 741 | var Data []uint32 |
| 742 | Value, err := RsrcMgr.KVStore.Get(ctx, IntfGEMPortPath) |
| 743 | if err == nil { |
| 744 | if Value != nil { |
| 745 | Val, _ := ponrmgr.ToByte(Value.Value) |
| 746 | if err = json.Unmarshal(Val, &Data); err != nil { |
| 747 | logger.Errorw(ctx, "Failed to unmarshal", log.Fields{"error": err}) |
| 748 | return 0, 0, errors.New("failed to unmarshal the data retrieved") |
| 749 | } |
| 750 | } |
| 751 | } else { |
| 752 | logger.Errorf(ctx, "Failed to get data from kvstore for %s", IntfGEMPortPath, err) |
| 753 | return 0, 0, errors.New("could not get data") |
| 754 | } |
| 755 | if len(Data) < 2 { |
| 756 | return 0, 0, errors.New("invalid data format") |
| 757 | } |
| 758 | return Data[0], Data[1], nil |
| 759 | } |
| 760 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 761 | // UpdateGEMportsPonportToOnuMapOnKVStore updates onu and uni id associated with the gem port to the kv store |
| 762 | // This stored information is used when packet_indication is received and we need to derive the ONU Id for which |
| 763 | // the packet arrived based on the pon_intf and gemport available in the packet_indication |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 764 | func (RsrcMgr *OpenOltResourceMgr) UpdateGEMportsPonportToOnuMapOnKVStore(ctx context.Context, gemPorts []uint32, PonPort uint32, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 765 | onuID uint32, uniID uint32) error { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 766 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 767 | /* Update onu and uni id associated with the gem port to the kv store. */ |
| 768 | var IntfGEMPortPath string |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 769 | Data := []uint32{onuID, uniID} |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 770 | for _, GEM := range gemPorts { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 771 | IntfGEMPortPath = fmt.Sprintf("%d,%d", PonPort, GEM) |
| 772 | Val, err := json.Marshal(Data) |
| 773 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 774 | logger.Error(ctx, "failed to Marshal") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 775 | return err |
| 776 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 777 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 778 | if err = RsrcMgr.KVStore.Put(ctx, IntfGEMPortPath, Val); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 779 | logger.Errorf(ctx, "Failed to update resource %s", IntfGEMPortPath) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 780 | return err |
| 781 | } |
| 782 | } |
| 783 | return nil |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 784 | } |
| 785 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 786 | // RemoveGEMportPonportToOnuMapOnKVStore removes the relationship between the gem port and pon port |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 787 | func (RsrcMgr *OpenOltResourceMgr) RemoveGEMportPonportToOnuMapOnKVStore(ctx context.Context, GemPort uint32, PonPort uint32) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 788 | IntfGEMPortPath := fmt.Sprintf("%d,%d", PonPort, GemPort) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 789 | err := RsrcMgr.KVStore.Delete(ctx, IntfGEMPortPath) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 790 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 791 | logger.Errorf(ctx, "Failed to Remove Gem port-Pon port to onu map on kv store. Gem %d PonPort %d", GemPort, PonPort) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 792 | } |
| 793 | } |
| 794 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 795 | // GetGEMPortID gets gem port id for a particular pon port, onu id and uni id and then update the resource map on |
| 796 | // the KV store with the list of gemport_id allocated for the pon_intf_onu_id tuple |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 797 | func (RsrcMgr *OpenOltResourceMgr) GetGEMPortID(ctx context.Context, ponPort uint32, onuID uint32, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 798 | uniID uint32, NumOfPorts uint32) ([]uint32, error) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 799 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 800 | /* Get gem port id for a particular pon port, onu id |
| 801 | and uni id. |
| 802 | */ |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 803 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 804 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 805 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 806 | |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 807 | RsrcMgr.GemPortIDMgmtLock[ponPort].Lock() |
| 808 | defer RsrcMgr.GemPortIDMgmtLock[ponPort].Unlock() |
| 809 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 810 | GEMPortList := RsrcMgr.ResourceMgrs[ponPort].GetCurrentGEMPortIDsForOnu(ctx, IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 811 | if GEMPortList != nil { |
| 812 | return GEMPortList, nil |
| 813 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 814 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 815 | GEMPortList, err = RsrcMgr.ResourceMgrs[ponPort].GetResourceID(ctx, ponPort, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 816 | ponrmgr.GEMPORT_ID, NumOfPorts) |
| 817 | if err != nil && GEMPortList == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 818 | logger.Errorf(ctx, "Failed to get gem port id for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 819 | return nil, err |
| 820 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 821 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 822 | // update the resource map on KV store with the list of gemport_id |
| 823 | // allocated for the pon_intf_onu_id tuple |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 824 | err = RsrcMgr.ResourceMgrs[ponPort].UpdateGEMPortIDsForOnu(ctx, IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 825 | GEMPortList) |
| 826 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 827 | logger.Errorf(ctx, "Failed to update GEM ports to kv store for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 828 | return nil, err |
| 829 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 830 | _ = RsrcMgr.UpdateGEMportsPonportToOnuMapOnKVStore(ctx, GEMPortList, ponPort, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 831 | onuID, uniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 832 | return GEMPortList, err |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 833 | } |
| 834 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 835 | // UpdateGEMPortIDsForOnu updates gemport ids on to the kv store for a given pon port, onu id and uni id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 836 | func (RsrcMgr *OpenOltResourceMgr) UpdateGEMPortIDsForOnu(ctx context.Context, ponPort uint32, onuID uint32, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 837 | uniID uint32, GEMPortList []uint32) error { |
| 838 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 839 | return RsrcMgr.ResourceMgrs[ponPort].UpdateGEMPortIDsForOnu(ctx, IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 840 | GEMPortList) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 841 | |
| 842 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 843 | |
| 844 | // FreeonuID releases(make free) onu id for a particular pon-port |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 845 | func (RsrcMgr *OpenOltResourceMgr) FreeonuID(ctx context.Context, intfID uint32, onuID []uint32) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 846 | |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 847 | RsrcMgr.OnuIDMgmtLock[intfID].Lock() |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 848 | defer RsrcMgr.OnuIDMgmtLock[intfID].Unlock() |
| 849 | |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 850 | if err := RsrcMgr.ResourceMgrs[intfID].TechProfileMgr.FreeResourceID(ctx, intfID, ponrmgr.ONU_ID, onuID); err != nil { |
| 851 | logger.Errorw(ctx, "error-while-freeing-onu-id", log.Fields{ |
| 852 | "intf-id": intfID, |
| 853 | "onu-id": onuID, |
| 854 | "err": err.Error(), |
| 855 | }) |
| 856 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 857 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 858 | /* Free onu id for a particular interface.*/ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 859 | var IntfonuID string |
| 860 | for _, onu := range onuID { |
| 861 | IntfonuID = fmt.Sprintf("%d,%d", intfID, onu) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 862 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(ctx, IntfonuID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 863 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 864 | } |
| 865 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 866 | // FreeAllocID frees AllocID on the PON resource pool and also frees the allocID association |
| 867 | // for the given OLT device. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 868 | func (RsrcMgr *OpenOltResourceMgr) FreeAllocID(ctx context.Context, IntfID uint32, onuID uint32, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 869 | uniID uint32, allocID uint32) { |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 870 | RsrcMgr.AllocIDMgmtLock[IntfID].Lock() |
| 871 | defer RsrcMgr.AllocIDMgmtLock[IntfID].Unlock() |
| 872 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 873 | RsrcMgr.RemoveAllocIDForOnu(ctx, IntfID, onuID, uniID, allocID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 874 | allocIDs := make([]uint32, 0) |
| 875 | allocIDs = append(allocIDs, allocID) |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 876 | if err := RsrcMgr.ResourceMgrs[IntfID].TechProfileMgr.FreeResourceID(ctx, IntfID, ponrmgr.ALLOC_ID, allocIDs); err != nil { |
| 877 | logger.Errorw(ctx, "error-while-freeing-alloc-id", log.Fields{ |
| 878 | "intf-id": IntfID, |
| 879 | "onu-id": onuID, |
| 880 | "err": err.Error(), |
| 881 | }) |
| 882 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | // FreeGemPortID frees GemPortID on the PON resource pool and also frees the gemPortID association |
| 886 | // for the given OLT device. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 887 | func (RsrcMgr *OpenOltResourceMgr) FreeGemPortID(ctx context.Context, IntfID uint32, onuID uint32, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 888 | uniID uint32, gemPortID uint32) { |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 889 | RsrcMgr.GemPortIDMgmtLock[IntfID].Lock() |
| 890 | defer RsrcMgr.GemPortIDMgmtLock[IntfID].Unlock() |
| 891 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 892 | RsrcMgr.RemoveGemPortIDForOnu(ctx, IntfID, onuID, uniID, gemPortID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 893 | gemPortIDs := make([]uint32, 0) |
| 894 | gemPortIDs = append(gemPortIDs, gemPortID) |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 895 | if err := RsrcMgr.ResourceMgrs[IntfID].TechProfileMgr.FreeResourceID(ctx, IntfID, ponrmgr.GEMPORT_ID, gemPortIDs); err != nil { |
| 896 | logger.Errorw(ctx, "error-while-freeing-gem-port-id", log.Fields{ |
| 897 | "intf-id": IntfID, |
| 898 | "onu-id": onuID, |
| 899 | "err": err.Error(), |
| 900 | }) |
| 901 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 904 | // FreePONResourcesForONU make the pon resources free for a given pon interface and onu id, and the clears the |
| 905 | // resource map and the onuID associated with (pon_intf_id, gemport_id) tuple, |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 906 | func (RsrcMgr *OpenOltResourceMgr) FreePONResourcesForONU(ctx context.Context, intfID uint32, onuID uint32, uniID uint32) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 907 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 908 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 909 | |
Girish Gowdra | 0c595ba | 2020-04-09 15:04:27 -0700 | [diff] [blame] | 910 | RsrcMgr.AllocIDMgmtLock[intfID].Lock() |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 911 | AllocIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(ctx, IntfOnuIDUniID) |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 912 | |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 913 | if err := RsrcMgr.ResourceMgrs[intfID].TechProfileMgr.FreeResourceID(ctx, intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 914 | ponrmgr.ALLOC_ID, |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 915 | AllocIDs); err != nil { |
| 916 | logger.Errorw(ctx, "error-while-freeing-all-alloc-ids-for-onu", log.Fields{ |
| 917 | "intf-id": intfID, |
| 918 | "onu-id": onuID, |
| 919 | "err": err.Error(), |
| 920 | }) |
| 921 | } |
Girish Gowdra | 0c595ba | 2020-04-09 15:04:27 -0700 | [diff] [blame] | 922 | RsrcMgr.AllocIDMgmtLock[intfID].Unlock() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 923 | |
Girish Gowdra | 0c595ba | 2020-04-09 15:04:27 -0700 | [diff] [blame] | 924 | RsrcMgr.GemPortIDMgmtLock[intfID].Lock() |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 925 | GEMPortIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentGEMPortIDsForOnu(ctx, IntfOnuIDUniID) |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 926 | if err := RsrcMgr.ResourceMgrs[intfID].TechProfileMgr.FreeResourceID(ctx, intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 927 | ponrmgr.GEMPORT_ID, |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 928 | GEMPortIDs); err != nil { |
| 929 | logger.Errorw(ctx, "error-while-freeing-all-gem-port-ids-for-onu", log.Fields{ |
| 930 | "intf-id": intfID, |
| 931 | "onu-id": onuID, |
| 932 | "err": err.Error(), |
| 933 | }) |
| 934 | } |
Girish Gowdra | 0c595ba | 2020-04-09 15:04:27 -0700 | [diff] [blame] | 935 | RsrcMgr.GemPortIDMgmtLock[intfID].Unlock() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 936 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 937 | // Clear resource map associated with (pon_intf_id, gemport_id) tuple. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 938 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(ctx, IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 939 | // Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple. |
| 940 | for _, GEM := range GEMPortIDs { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 941 | _ = RsrcMgr.KVStore.Delete(ctx, fmt.Sprintf("%d,%d", intfID, GEM)) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 942 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 943 | } |
| 944 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 945 | // IsFlowOnKvStore checks if the given flowID is present on the kv store |
| 946 | // Returns true if the flowID is found, otherwise it returns false |
| 947 | func (RsrcMgr *OpenOltResourceMgr) IsFlowOnKvStore(ctx context.Context, ponIntfID uint32, onuID int32, uniID int32, |
| 948 | flowID uint64) bool { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 949 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 950 | FlowIDs, err := RsrcMgr.GetCurrentFlowIDsForOnu(ctx, ponIntfID, onuID, uniID) |
| 951 | if err != nil { |
| 952 | // error logged in the called function |
| 953 | return false |
| 954 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 955 | if FlowIDs != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 956 | logger.Debugw(ctx, "Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "onuID": onuID, "uniID": uniID}) |
| 957 | for _, id := range FlowIDs { |
| 958 | if flowID == id { |
| 959 | return true |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | } |
| 963 | return false |
| 964 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 965 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 966 | // 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] | 967 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 968 | func (RsrcMgr *OpenOltResourceMgr) GetTechProfileIDForOnu(ctx context.Context, IntfID uint32, OnuID uint32, UniID uint32) []uint32 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 969 | Path := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 970 | var Data []uint32 |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 971 | Value, err := RsrcMgr.KVStore.Get(ctx, Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 972 | if err == nil { |
| 973 | if Value != nil { |
| 974 | Val, err := kvstore.ToByte(Value.Value) |
| 975 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 976 | logger.Errorw(ctx, "Failed to convert into byte array", log.Fields{"error": err}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 977 | return Data |
| 978 | } |
| 979 | if err = json.Unmarshal(Val, &Data); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 980 | logger.Error(ctx, "Failed to unmarshal", log.Fields{"error": err}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 981 | return Data |
| 982 | } |
| 983 | } |
| 984 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 985 | logger.Errorf(ctx, "Failed to get TP id from kvstore for path %s", Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 986 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 987 | logger.Debugf(ctx, "Getting TP id %d from path %s", Data, Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 988 | return Data |
| 989 | |
| 990 | } |
| 991 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 992 | // RemoveTechProfileIDsForOnu deletes all tech profile ids from the KV-Store for the given onu based on the path |
| 993 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 994 | func (RsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDsForOnu(ctx context.Context, IntfID uint32, OnuID uint32, UniID uint32) error { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 995 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 996 | if err := RsrcMgr.KVStore.Delete(ctx, IntfOnuUniID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 997 | logger.Errorw(ctx, "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] | 998 | return err |
| 999 | } |
| 1000 | return nil |
| 1001 | } |
| 1002 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1003 | // RemoveTechProfileIDForOnu deletes a specific tech profile id from the KV-Store for the given onu based on the path |
| 1004 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1005 | func (RsrcMgr *OpenOltResourceMgr) RemoveTechProfileIDForOnu(ctx context.Context, IntfID uint32, OnuID uint32, UniID uint32, TpID uint32) error { |
| 1006 | tpIDList := RsrcMgr.GetTechProfileIDForOnu(ctx, IntfID, OnuID, UniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1007 | for i, tpIDInList := range tpIDList { |
| 1008 | if tpIDInList == TpID { |
| 1009 | tpIDList = append(tpIDList[:i], tpIDList[i+1:]...) |
| 1010 | } |
| 1011 | } |
| 1012 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
| 1013 | Value, err := json.Marshal(tpIDList) |
| 1014 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1015 | logger.Error(ctx, "failed to Marshal") |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1016 | return err |
| 1017 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1018 | if err = RsrcMgr.KVStore.Put(ctx, IntfOnuUniID, Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1019 | logger.Errorf(ctx, "Failed to update resource %s", IntfOnuUniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1020 | return err |
| 1021 | } |
| 1022 | return err |
| 1023 | } |
| 1024 | |
| 1025 | // UpdateTechProfileIDForOnu updates (put) already present tech-profile-id for the given onu based on the path |
| 1026 | // This path is formed as the following: {IntfID, OnuID, UniID}/tp_id |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1027 | func (RsrcMgr *OpenOltResourceMgr) UpdateTechProfileIDForOnu(ctx context.Context, IntfID uint32, OnuID uint32, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1028 | UniID uint32, TpID uint32) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1029 | var Value []byte |
| 1030 | var err error |
| 1031 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1032 | IntfOnuUniID := fmt.Sprintf(TpIDPathSuffix, IntfID, OnuID, UniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1033 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1034 | tpIDList := RsrcMgr.GetTechProfileIDForOnu(ctx, IntfID, OnuID, UniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1035 | for _, value := range tpIDList { |
| 1036 | if value == TpID { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1037 | logger.Debugf(ctx, "TpID %d is already in tpIdList for the path %s", TpID, IntfOnuUniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1038 | return err |
| 1039 | } |
| 1040 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1041 | logger.Debugf(ctx, "updating tp id %d on path %s", TpID, IntfOnuUniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1042 | tpIDList = append(tpIDList, TpID) |
| 1043 | Value, err = json.Marshal(tpIDList) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1044 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1045 | logger.Error(ctx, "failed to Marshal") |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1046 | return err |
| 1047 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1048 | if err = RsrcMgr.KVStore.Put(ctx, IntfOnuUniID, Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1049 | logger.Errorf(ctx, "Failed to update resource %s", IntfOnuUniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1050 | return err |
| 1051 | } |
| 1052 | return err |
| 1053 | } |
| 1054 | |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1055 | // StoreMeterInfoForOnu 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] | 1056 | // This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1057 | func (RsrcMgr *OpenOltResourceMgr) StoreMeterInfoForOnu(ctx context.Context, Direction string, IntfID uint32, OnuID uint32, |
| 1058 | UniID uint32, TpID uint32, meterInfo *MeterInfo) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1059 | var Value []byte |
| 1060 | var err error |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1061 | IntfOnuUniID := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1062 | Value, err = json.Marshal(*meterInfo) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1063 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1064 | logger.Error(ctx, "failed to Marshal meter config") |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1065 | return err |
| 1066 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1067 | if err = RsrcMgr.KVStore.Put(ctx, IntfOnuUniID, Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1068 | logger.Errorf(ctx, "Failed to store meter into KV store %s", IntfOnuUniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1069 | return err |
| 1070 | } |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1071 | logger.Debugw(ctx, "meter info updated successfully", log.Fields{"path": IntfOnuUniID, "meter-info": meterInfo}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1072 | return err |
| 1073 | } |
| 1074 | |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1075 | // GetMeterInfoForOnu fetches the meter 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] | 1076 | // This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1077 | func (RsrcMgr *OpenOltResourceMgr) GetMeterInfoForOnu(ctx context.Context, Direction string, IntfID uint32, OnuID uint32, |
| 1078 | UniID uint32, TpID uint32) (*MeterInfo, error) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1079 | Path := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1080 | var meterInfo MeterInfo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1081 | Value, err := RsrcMgr.KVStore.Get(ctx, Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1082 | if err == nil { |
| 1083 | if Value != nil { |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1084 | logger.Debug(ctx, "Found meter info in KV store", log.Fields{"Direction": Direction}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1085 | Val, er := kvstore.ToByte(Value.Value) |
| 1086 | if er != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1087 | logger.Errorw(ctx, "Failed to convert into byte array", log.Fields{"error": er}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1088 | return nil, er |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1089 | } |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1090 | if er = json.Unmarshal(Val, &meterInfo); er != nil { |
| 1091 | logger.Error(ctx, "Failed to unmarshal meter info", log.Fields{"error": er}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1092 | return nil, er |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1093 | } |
| 1094 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1095 | logger.Debug(ctx, "meter-does-not-exists-in-KVStore") |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1096 | return nil, err |
| 1097 | } |
| 1098 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1099 | logger.Errorf(ctx, "Failed to get Meter config from kvstore for path %s", Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1100 | |
| 1101 | } |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1102 | return &meterInfo, err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1105 | // HandleMeterInfoRefCntUpdate increments or decrements the reference counter for a given meter. |
| 1106 | // When reference count becomes 0, it clears the meter information from the kv store |
| 1107 | func (RsrcMgr *OpenOltResourceMgr) HandleMeterInfoRefCntUpdate(ctx context.Context, Direction string, |
| 1108 | IntfID uint32, OnuID uint32, UniID uint32, TpID uint32, increment bool) error { |
| 1109 | meterInfo, err := RsrcMgr.GetMeterInfoForOnu(ctx, Direction, IntfID, OnuID, UniID, TpID) |
Girish Gowdra | 01e8d97 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 1110 | if err != nil { |
| 1111 | return err |
| 1112 | } else if meterInfo == nil { |
| 1113 | // If we are increasing the reference count, we expect the meter information to be present on KV store. |
| 1114 | // But if decrementing the reference count, the meter is possibly already cleared from KV store. Just log warn but do not return error. |
| 1115 | if increment { |
| 1116 | logger.Errorf(ctx, "error-fetching-meter-info-for-intf-%d-onu-%d-uni-%d-tp-id-%d-direction-%s", IntfID, OnuID, UniID, TpID, Direction) |
| 1117 | return fmt.Errorf("error-fetching-meter-info-for-intf-%d-onu-%d-uni-%d-tp-id-%d-direction-%s", IntfID, OnuID, UniID, TpID, Direction) |
| 1118 | } |
| 1119 | logger.Warnw(ctx, "meter is already cleared", |
| 1120 | log.Fields{"intfID": IntfID, "onuID": OnuID, "uniID": UniID, "direction": Direction, "increment": increment}) |
| 1121 | return nil |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1122 | } |
Girish Gowdra | 01e8d97 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 1123 | |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1124 | if increment { |
| 1125 | meterInfo.RefCnt++ |
| 1126 | } else { |
| 1127 | meterInfo.RefCnt-- |
Girish Gowdra | 01e8d97 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 1128 | // If RefCnt become 0 clear the meter information from the DB. |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1129 | if meterInfo.RefCnt == 0 { |
| 1130 | if err := RsrcMgr.RemoveMeterInfoForOnu(ctx, Direction, IntfID, OnuID, UniID, TpID); err != nil { |
| 1131 | return err |
| 1132 | } |
| 1133 | return nil |
| 1134 | } |
| 1135 | } |
| 1136 | if err := RsrcMgr.StoreMeterInfoForOnu(ctx, Direction, IntfID, OnuID, UniID, TpID, meterInfo); err != nil { |
| 1137 | return err |
| 1138 | } |
| 1139 | return nil |
| 1140 | } |
| 1141 | |
| 1142 | // RemoveMeterInfoForOnu deletes the meter 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] | 1143 | // This path is formed as the following: <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
Girish Gowdra | 3fe4cc5 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1144 | func (RsrcMgr *OpenOltResourceMgr) RemoveMeterInfoForOnu(ctx context.Context, Direction string, IntfID uint32, OnuID uint32, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1145 | UniID uint32, TpID uint32) error { |
| 1146 | Path := fmt.Sprintf(MeterIDPathSuffix, IntfID, OnuID, UniID, TpID, Direction) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1147 | if err := RsrcMgr.KVStore.Delete(ctx, Path); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1148 | logger.Errorf(ctx, "Failed to delete meter id %s from kvstore ", Path) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1149 | return err |
| 1150 | } |
| 1151 | return nil |
| 1152 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1153 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1154 | //AddGemToOnuGemInfo adds gemport to onugem info kvstore |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1155 | func (RsrcMgr *OpenOltResourceMgr) AddGemToOnuGemInfo(ctx context.Context, intfID uint32, onuID uint32, gemPort uint32) error { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1156 | var onuGemData []OnuGemInfo |
| 1157 | var err error |
| 1158 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1159 | if err = RsrcMgr.ResourceMgrs[intfID].GetOnuGemInfo(ctx, intfID, &onuGemData); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1160 | logger.Errorf(ctx, "failed to get onuifo for intfid %d", intfID) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1161 | return err |
| 1162 | } |
| 1163 | if len(onuGemData) == 0 { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1164 | logger.Errorw(ctx, "failed to ger Onuid info ", log.Fields{"intfid": intfID, "onuid": onuID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1165 | return err |
| 1166 | } |
| 1167 | |
| 1168 | for idx, onugem := range onuGemData { |
| 1169 | if onugem.OnuID == onuID { |
| 1170 | for _, gem := range onuGemData[idx].GemPorts { |
| 1171 | if gem == gemPort { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1172 | logger.Debugw(ctx, "Gem already present in onugem info, skpping addition", log.Fields{"gem": gem}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1173 | return nil |
| 1174 | } |
| 1175 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1176 | logger.Debugw(ctx, "Added gem to onugem info", log.Fields{"gem": gemPort}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1177 | onuGemData[idx].GemPorts = append(onuGemData[idx].GemPorts, gemPort) |
| 1178 | break |
| 1179 | } |
| 1180 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1181 | err = RsrcMgr.ResourceMgrs[intfID].AddOnuGemInfo(ctx, intfID, onuGemData) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1182 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1183 | logger.Error(ctx, "Failed to add onugem to kv store") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1184 | return err |
| 1185 | } |
| 1186 | return err |
| 1187 | } |
| 1188 | |
| 1189 | //GetOnuGemInfo gets onu gem info from the kvstore per interface |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1190 | func (RsrcMgr *OpenOltResourceMgr) GetOnuGemInfo(ctx context.Context, IntfID uint32) ([]OnuGemInfo, error) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1191 | var onuGemData []OnuGemInfo |
| 1192 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1193 | if err := RsrcMgr.ResourceMgrs[IntfID].GetOnuGemInfo(ctx, IntfID, &onuGemData); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1194 | logger.Errorf(ctx, "failed to get onuifo for intfid %d", IntfID) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1195 | return nil, err |
| 1196 | } |
| 1197 | |
| 1198 | return onuGemData, nil |
| 1199 | } |
| 1200 | |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 1201 | // AddOnuGemInfo adds onu info on to the kvstore per interface |
| 1202 | func (RsrcMgr *OpenOltResourceMgr) AddOnuGemInfo(ctx context.Context, IntfID uint32, onuGem OnuGemInfo) error { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1203 | var onuGemData []OnuGemInfo |
| 1204 | var err error |
| 1205 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1206 | if err = RsrcMgr.ResourceMgrs[IntfID].GetOnuGemInfo(ctx, IntfID, &onuGemData); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1207 | logger.Errorf(ctx, "failed to get onuifo for intfid %d", IntfID) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1208 | return olterrors.NewErrPersistence("get", "OnuGemInfo", uint64(IntfID), |
Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 1209 | log.Fields{"onuGem": onuGem, "intfID": IntfID}, err) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1210 | } |
| 1211 | onuGemData = append(onuGemData, onuGem) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1212 | err = RsrcMgr.ResourceMgrs[IntfID].AddOnuGemInfo(ctx, IntfID, onuGemData) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1213 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1214 | logger.Error(ctx, "Failed to add onugem to kv store") |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1215 | return olterrors.NewErrPersistence("set", "OnuGemInfo", uint64(IntfID), |
Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 1216 | log.Fields{"onuGemData": onuGemData, "intfID": IntfID}, err) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1217 | } |
| 1218 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1219 | logger.Debugw(ctx, "added onu to onugeminfo", log.Fields{"intf": IntfID, "onugem": onuGem}) |
Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 1220 | return nil |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1221 | } |
| 1222 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1223 | // AddUniPortToOnuInfo adds uni port to the onuinfo kvstore. check if the uni is already present if not update the kv store. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1224 | func (RsrcMgr *OpenOltResourceMgr) AddUniPortToOnuInfo(ctx context.Context, intfID uint32, onuID uint32, portNo uint32) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1225 | var onuGemData []OnuGemInfo |
| 1226 | var err error |
| 1227 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1228 | if err = RsrcMgr.ResourceMgrs[intfID].GetOnuGemInfo(ctx, intfID, &onuGemData); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1229 | logger.Errorf(ctx, "failed to get onuifo for intfid %d", intfID) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1230 | return |
| 1231 | } |
| 1232 | for idx, onu := range onuGemData { |
| 1233 | if onu.OnuID == onuID { |
| 1234 | for _, uni := range onu.UniPorts { |
| 1235 | if uni == portNo { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1236 | logger.Debugw(ctx, "uni already present in onugem info", log.Fields{"uni": portNo}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1237 | return |
| 1238 | } |
| 1239 | } |
| 1240 | onuGemData[idx].UniPorts = append(onuGemData[idx].UniPorts, portNo) |
| 1241 | break |
| 1242 | } |
| 1243 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1244 | err = RsrcMgr.ResourceMgrs[intfID].AddOnuGemInfo(ctx, intfID, onuGemData) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1245 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1246 | logger.Errorw(ctx, "Failed to add uin port in onugem to kv store", log.Fields{"uni": portNo}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1247 | return |
| 1248 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1249 | } |
| 1250 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1251 | //UpdateGemPortForPktIn updates gemport for pkt in path to kvstore, path being intfid, onuid, portno, vlan id, priority bit |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1252 | func (RsrcMgr *OpenOltResourceMgr) UpdateGemPortForPktIn(ctx context.Context, pktIn PacketInInfoKey, gemPort uint32) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1253 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1254 | path := fmt.Sprintf(OnuPacketINPath, pktIn.IntfID, pktIn.OnuID, pktIn.LogicalPort, pktIn.VlanID, pktIn.Priority) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1255 | Value, err := json.Marshal(gemPort) |
| 1256 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1257 | logger.Error(ctx, "Failed to marshal data") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1258 | return |
| 1259 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1260 | if err = RsrcMgr.KVStore.Put(ctx, path, Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1261 | logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"path": path, "value": gemPort}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1262 | return |
| 1263 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1264 | logger.Debugw(ctx, "added gem packet in successfully", log.Fields{"path": path, "gem": gemPort}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1265 | } |
| 1266 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1267 | // GetGemPortFromOnuPktIn gets the gem port from onu pkt in path, path being intfid, onuid, portno, vlan id, priority bit |
| 1268 | func (RsrcMgr *OpenOltResourceMgr) GetGemPortFromOnuPktIn(ctx context.Context, packetInInfoKey PacketInInfoKey) (uint32, error) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1269 | |
| 1270 | var Val []byte |
| 1271 | var gemPort uint32 |
| 1272 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1273 | path := fmt.Sprintf(OnuPacketINPath, packetInInfoKey.IntfID, packetInInfoKey.OnuID, packetInInfoKey.LogicalPort, |
| 1274 | packetInInfoKey.VlanID, packetInInfoKey.Priority) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1275 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1276 | value, err := RsrcMgr.KVStore.Get(ctx, path) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1277 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1278 | logger.Errorw(ctx, "Failed to get from kv store", log.Fields{"path": path}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1279 | return uint32(0), err |
| 1280 | } else if value == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1281 | logger.Debugw(ctx, "No pkt in gem found", log.Fields{"path": path}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1282 | return uint32(0), nil |
| 1283 | } |
| 1284 | |
| 1285 | if Val, err = kvstore.ToByte(value.Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1286 | logger.Error(ctx, "Failed to convert to byte array") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1287 | return uint32(0), err |
| 1288 | } |
| 1289 | if err = json.Unmarshal(Val, &gemPort); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1290 | logger.Error(ctx, "Failed to unmarshall") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1291 | return uint32(0), err |
| 1292 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1293 | logger.Debugw(ctx, "found packein gemport from path", log.Fields{"path": path, "gem": gemPort}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1294 | |
| 1295 | return gemPort, nil |
| 1296 | } |
| 1297 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1298 | //DeletePacketInGemPortForOnu deletes the packet-in gemport for ONU |
| 1299 | func (RsrcMgr *OpenOltResourceMgr) DeletePacketInGemPortForOnu(ctx context.Context, intfID uint32, onuID uint32, logicalPort uint32) error { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1300 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1301 | path := fmt.Sprintf(OnuPacketINPathPrefix, intfID, onuID, logicalPort) |
| 1302 | value, err := RsrcMgr.KVStore.List(ctx, path) |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1303 | if err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1304 | logger.Errorf(ctx, "failed-to-read-value-from-path-%s", path) |
| 1305 | return errors.New("failed-to-read-value-from-path-" + path) |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1306 | } |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1307 | |
| 1308 | //remove them one by one |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1309 | for key := range value { |
| 1310 | // Formulate the right key path suffix ti be delete |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 1311 | stringToBeReplaced := fmt.Sprintf(BasePathKvStore, RsrcMgr.KVStore.PathPrefix, RsrcMgr.DeviceID) + "/" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1312 | replacedWith := "" |
| 1313 | key = strings.Replace(key, stringToBeReplaced, replacedWith, 1) |
| 1314 | |
| 1315 | logger.Debugf(ctx, "removing-key-%s", key) |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1316 | if err := RsrcMgr.KVStore.Delete(ctx, key); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1317 | logger.Errorf(ctx, "failed-to-remove-resource-%s", key) |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 1318 | return err |
| 1319 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1320 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1321 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1322 | return nil |
| 1323 | } |
| 1324 | |
| 1325 | // DelOnuGemInfoForIntf deletes the onugem info from kvstore per interface |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1326 | func (RsrcMgr *OpenOltResourceMgr) DelOnuGemInfoForIntf(ctx context.Context, intfID uint32) error { |
| 1327 | if err := RsrcMgr.ResourceMgrs[intfID].DelOnuGemInfoForIntf(ctx, intfID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1328 | logger.Errorw(ctx, "failed to delete onu gem info for", log.Fields{"intfid": intfID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1329 | return err |
| 1330 | } |
| 1331 | return nil |
| 1332 | } |
| 1333 | |
| 1334 | //GetNNIFromKVStore gets NNi intfids from kvstore. path being per device |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1335 | func (RsrcMgr *OpenOltResourceMgr) GetNNIFromKVStore(ctx context.Context) ([]uint32, error) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1336 | |
| 1337 | var nni []uint32 |
| 1338 | var Val []byte |
| 1339 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1340 | path := NnniIntfID |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1341 | value, err := RsrcMgr.KVStore.Get(ctx, path) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1342 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1343 | logger.Error(ctx, "failed to get data from kv store") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1344 | return nil, err |
| 1345 | } |
| 1346 | if value != nil { |
| 1347 | if Val, err = kvstore.ToByte(value.Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1348 | logger.Error(ctx, "Failed to convert to byte array") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1349 | return nil, err |
| 1350 | } |
| 1351 | if err = json.Unmarshal(Val, &nni); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1352 | logger.Error(ctx, "Failed to unmarshall") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1353 | return nil, err |
| 1354 | } |
| 1355 | } |
| 1356 | return nni, err |
| 1357 | } |
| 1358 | |
| 1359 | // AddNNIToKVStore adds Nni interfaces to kvstore, path being per device. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1360 | func (RsrcMgr *OpenOltResourceMgr) AddNNIToKVStore(ctx context.Context, nniIntf uint32) error { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1361 | var Value []byte |
| 1362 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1363 | nni, err := RsrcMgr.GetNNIFromKVStore(ctx) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1364 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1365 | logger.Error(ctx, "failed to fetch nni interfaces from kv store") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1366 | return err |
| 1367 | } |
| 1368 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1369 | path := NnniIntfID |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1370 | nni = append(nni, nniIntf) |
| 1371 | Value, err = json.Marshal(nni) |
| 1372 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1373 | logger.Error(ctx, "Failed to marshal data") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1374 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1375 | if err = RsrcMgr.KVStore.Put(ctx, path, Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1376 | logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"path": path, "value": Value}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1377 | return err |
| 1378 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1379 | logger.Debugw(ctx, "added nni to kv successfully", log.Fields{"path": path, "nni": nniIntf}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1380 | return nil |
| 1381 | } |
| 1382 | |
| 1383 | // DelNNiFromKVStore deletes nni interface list from kv store. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1384 | func (RsrcMgr *OpenOltResourceMgr) DelNNiFromKVStore(ctx context.Context) error { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1385 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1386 | path := NnniIntfID |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1387 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1388 | if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1389 | logger.Errorw(ctx, "Failed to delete nni interfaces from kv store", log.Fields{"path": path}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1390 | return err |
| 1391 | } |
| 1392 | return nil |
| 1393 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1394 | |
| 1395 | //UpdateFlowIDsForGem updates flow id per gemport |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1396 | func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDsForGem(ctx context.Context, intf uint32, gem uint32, flowIDs []uint64) error { |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1397 | var val []byte |
| 1398 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1399 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1400 | flowsForGem, err := RsrcMgr.GetFlowIDsGemMapForInterface(ctx, intf) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1401 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1402 | logger.Error(ctx, "Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1403 | return err |
| 1404 | } |
| 1405 | if flowsForGem == nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1406 | flowsForGem = make(map[uint32][]uint64) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1407 | } |
| 1408 | flowsForGem[gem] = flowIDs |
| 1409 | val, err = json.Marshal(flowsForGem) |
| 1410 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1411 | logger.Error(ctx, "Failed to marshal data", log.Fields{"error": err}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1412 | return err |
| 1413 | } |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 1414 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1415 | if err = RsrcMgr.KVStore.Put(ctx, path, val); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1416 | logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1417 | return err |
| 1418 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1419 | logger.Debugw(ctx, "added flowid list for gem to kv successfully", log.Fields{"path": path, "flowidlist": flowsForGem[gem]}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1420 | return nil |
| 1421 | } |
| 1422 | |
| 1423 | //DeleteFlowIDsForGem deletes the flowID list entry per gem from kvstore. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1424 | func (RsrcMgr *OpenOltResourceMgr) DeleteFlowIDsForGem(ctx context.Context, intf uint32, gem uint32) { |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1425 | path := fmt.Sprintf(FlowIDsForGem, intf) |
| 1426 | var val []byte |
| 1427 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1428 | flowsForGem, err := RsrcMgr.GetFlowIDsGemMapForInterface(ctx, intf) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1429 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1430 | logger.Error(ctx, "Failed to ger flowids for interface", log.Fields{"error": err, "intf": intf}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1431 | return |
| 1432 | } |
| 1433 | if flowsForGem == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1434 | logger.Error(ctx, "No flowids found ", log.Fields{"intf": intf, "gemport": gem}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1435 | return |
| 1436 | } |
| 1437 | // once we get the flows per gem map from kv , just delete the gem entry from the map |
| 1438 | delete(flowsForGem, gem) |
| 1439 | // once gem entry is deleted update the kv store. |
| 1440 | val, err = json.Marshal(flowsForGem) |
| 1441 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1442 | logger.Error(ctx, "Failed to marshal data", log.Fields{"error": err}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1443 | return |
| 1444 | } |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 1445 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1446 | if err = RsrcMgr.KVStore.Put(ctx, path, val); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1447 | logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1448 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | //GetFlowIDsGemMapForInterface gets flowids per gemport and interface |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1452 | func (RsrcMgr *OpenOltResourceMgr) GetFlowIDsGemMapForInterface(ctx context.Context, intf uint32) (map[uint32][]uint64, error) { |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1453 | path := fmt.Sprintf(FlowIDsForGem, intf) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1454 | var flowsForGem map[uint32][]uint64 |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1455 | var val []byte |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1456 | value, err := RsrcMgr.KVStore.Get(ctx, path) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1457 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1458 | logger.Error(ctx, "failed to get data from kv store") |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1459 | return nil, err |
| 1460 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1461 | if value != nil && value.Value != nil { |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1462 | if val, err = kvstore.ToByte(value.Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1463 | logger.Error(ctx, "Failed to convert to byte array ", log.Fields{"error": err}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1464 | return nil, err |
| 1465 | } |
| 1466 | if err = json.Unmarshal(val, &flowsForGem); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1467 | logger.Error(ctx, "Failed to unmarshall", log.Fields{"error": err}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1468 | return nil, err |
| 1469 | } |
| 1470 | } |
| 1471 | return flowsForGem, nil |
| 1472 | } |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1473 | |
| 1474 | //DeleteIntfIDGempMapPath deletes the intf id path used to store flow ids per gem to kvstore. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1475 | func (RsrcMgr *OpenOltResourceMgr) DeleteIntfIDGempMapPath(ctx context.Context, intf uint32) { |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1476 | path := fmt.Sprintf(FlowIDsForGem, intf) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1477 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1478 | if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1479 | logger.Errorw(ctx, "Failed to delete nni interfaces from kv store", log.Fields{"path": path}) |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1480 | } |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | // RemoveResourceMap Clear resource map associated with (intfid, onuid, uniid) tuple. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1484 | func (RsrcMgr *OpenOltResourceMgr) RemoveResourceMap(ctx context.Context, intfID uint32, onuID int32, uniID int32) { |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1485 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1486 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(ctx, IntfOnuIDUniID) |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1487 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1488 | |
| 1489 | //GetMcastQueuePerInterfaceMap gets multicast queue info per pon interface |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1490 | func (RsrcMgr *OpenOltResourceMgr) GetMcastQueuePerInterfaceMap(ctx context.Context) (map[uint32][]uint32, error) { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1491 | path := McastQueuesForIntf |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1492 | var mcastQueueToIntfMap map[uint32][]uint32 |
| 1493 | var val []byte |
| 1494 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1495 | kvPair, err := RsrcMgr.KVStore.Get(ctx, path) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1496 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1497 | logger.Error(ctx, "failed to get data from kv store") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1498 | return nil, err |
| 1499 | } |
| 1500 | if kvPair != nil && kvPair.Value != nil { |
| 1501 | if val, err = kvstore.ToByte(kvPair.Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1502 | logger.Error(ctx, "Failed to convert to byte array ", log.Fields{"error": err}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1503 | return nil, err |
| 1504 | } |
| 1505 | if err = json.Unmarshal(val, &mcastQueueToIntfMap); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1506 | logger.Error(ctx, "Failed to unmarshall ", log.Fields{"error": err}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1507 | return nil, err |
| 1508 | } |
| 1509 | } |
| 1510 | return mcastQueueToIntfMap, nil |
| 1511 | } |
| 1512 | |
| 1513 | //AddMcastQueueForIntf adds multicast queue for pon interface |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1514 | func (RsrcMgr *OpenOltResourceMgr) AddMcastQueueForIntf(ctx context.Context, intf uint32, gem uint32, servicePriority uint32) error { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1515 | var val []byte |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1516 | path := McastQueuesForIntf |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1517 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1518 | mcastQueues, err := RsrcMgr.GetMcastQueuePerInterfaceMap(ctx) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1519 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1520 | logger.Errorw(ctx, "Failed to get multicast queue info for interface", log.Fields{"error": err, "intf": intf}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1521 | return err |
| 1522 | } |
| 1523 | if mcastQueues == nil { |
| 1524 | mcastQueues = make(map[uint32][]uint32) |
| 1525 | } |
| 1526 | mcastQueues[intf] = []uint32{gem, servicePriority} |
| 1527 | if val, err = json.Marshal(mcastQueues); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1528 | logger.Errorw(ctx, "Failed to marshal data", log.Fields{"error": err}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1529 | return err |
| 1530 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1531 | if err = RsrcMgr.KVStore.Put(ctx, path, val); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1532 | logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1533 | return err |
| 1534 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1535 | logger.Debugw(ctx, "added multicast queue info to KV store successfully", log.Fields{"path": path, "mcastQueueInfo": mcastQueues[intf], "interfaceId": intf}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1536 | return nil |
| 1537 | } |
| 1538 | |
| 1539 | //AddFlowGroupToKVStore adds flow group into KV store |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1540 | func (RsrcMgr *OpenOltResourceMgr) AddFlowGroupToKVStore(ctx context.Context, groupEntry *ofp.OfpGroupEntry, cached bool) error { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1541 | var Value []byte |
| 1542 | var err error |
| 1543 | var path string |
| 1544 | if cached { |
| 1545 | path = fmt.Sprintf(FlowGroupCached, groupEntry.Desc.GroupId) |
| 1546 | } else { |
| 1547 | path = fmt.Sprintf(FlowGroup, groupEntry.Desc.GroupId) |
| 1548 | } |
| 1549 | //build group info object |
| 1550 | var outPorts []uint32 |
| 1551 | for _, ofBucket := range groupEntry.Desc.Buckets { |
| 1552 | for _, ofAction := range ofBucket.Actions { |
| 1553 | if ofAction.Type == ofp.OfpActionType_OFPAT_OUTPUT { |
| 1554 | outPorts = append(outPorts, ofAction.GetOutput().Port) |
| 1555 | } |
| 1556 | } |
| 1557 | } |
| 1558 | groupInfo := GroupInfo{ |
| 1559 | GroupID: groupEntry.Desc.GroupId, |
| 1560 | OutPorts: outPorts, |
| 1561 | } |
| 1562 | |
| 1563 | Value, err = json.Marshal(groupInfo) |
| 1564 | |
| 1565 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1566 | logger.Error(ctx, "failed to Marshal flow group object") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1567 | return err |
| 1568 | } |
| 1569 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1570 | if err = RsrcMgr.KVStore.Put(ctx, path, Value); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1571 | logger.Errorf(ctx, "Failed to update resource %s", path) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1572 | return err |
| 1573 | } |
| 1574 | return nil |
| 1575 | } |
| 1576 | |
| 1577 | //RemoveFlowGroupFromKVStore removes flow group from KV store |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1578 | func (RsrcMgr *OpenOltResourceMgr) RemoveFlowGroupFromKVStore(ctx context.Context, groupID uint32, cached bool) error { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1579 | var path string |
| 1580 | if cached { |
| 1581 | path = fmt.Sprintf(FlowGroupCached, groupID) |
| 1582 | } else { |
| 1583 | path = fmt.Sprintf(FlowGroup, groupID) |
| 1584 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1585 | if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1586 | logger.Errorf(ctx, "Failed to remove resource %s due to %s", path, err) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1587 | return err |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1588 | } |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1589 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | //GetFlowGroupFromKVStore fetches flow group from the KV store. Returns (false, {} error) if any problem occurs during |
| 1593 | //fetching the data. Returns (true, groupInfo, nil) if the group is fetched successfully. |
| 1594 | // Returns (false, {}, nil) if the group does not exists in the KV store. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1595 | func (RsrcMgr *OpenOltResourceMgr) GetFlowGroupFromKVStore(ctx context.Context, groupID uint32, cached bool) (bool, GroupInfo, error) { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1596 | var groupInfo GroupInfo |
| 1597 | var path string |
| 1598 | if cached { |
| 1599 | path = fmt.Sprintf(FlowGroupCached, groupID) |
| 1600 | } else { |
| 1601 | path = fmt.Sprintf(FlowGroup, groupID) |
| 1602 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1603 | kvPair, err := RsrcMgr.KVStore.Get(ctx, path) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1604 | if err != nil { |
| 1605 | return false, groupInfo, err |
| 1606 | } |
| 1607 | if kvPair != nil && kvPair.Value != nil { |
| 1608 | Val, err := kvstore.ToByte(kvPair.Value) |
| 1609 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1610 | logger.Errorw(ctx, "Failed to convert flow group into byte array", log.Fields{"error": err}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1611 | return false, groupInfo, err |
| 1612 | } |
| 1613 | if err = json.Unmarshal(Val, &groupInfo); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1614 | logger.Errorw(ctx, "Failed to unmarshal", log.Fields{"error": err}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1615 | return false, groupInfo, err |
| 1616 | } |
| 1617 | return true, groupInfo, nil |
| 1618 | } |
| 1619 | return false, groupInfo, nil |
| 1620 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1621 | |
| 1622 | // toByte converts an interface value to a []byte. The interface should either be of |
| 1623 | // a string type or []byte. Otherwise, an error is returned. |
| 1624 | func toByte(value interface{}) ([]byte, error) { |
| 1625 | switch t := value.(type) { |
| 1626 | case []byte: |
| 1627 | return value.([]byte), nil |
| 1628 | case string: |
| 1629 | return []byte(value.(string)), nil |
| 1630 | default: |
| 1631 | return nil, fmt.Errorf("unexpected-type-%T", t) |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | func checkForFlowIDInList(FlowIDList []uint64, FlowID uint64) (bool, uint64) { |
| 1636 | /* |
| 1637 | Check for a flow id in a given list of flow IDs. |
| 1638 | :param FLowIDList: List of Flow IDs |
| 1639 | :param FlowID: Flowd to check in the list |
| 1640 | : return true and the index if present false otherwise. |
| 1641 | */ |
| 1642 | |
| 1643 | for idx := range FlowIDList { |
| 1644 | if FlowID == FlowIDList[idx] { |
| 1645 | return true, uint64(idx) |
| 1646 | } |
| 1647 | } |
| 1648 | return false, 0 |
| 1649 | } |