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