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