Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 17 | //Package resourcemanager provides the utility for managing resources |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 18 | package resourcemanager |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 21 | "encoding/json" |
| 22 | "errors" |
| 23 | "fmt" |
| 24 | "strconv" |
| 25 | "strings" |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 26 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 27 | "github.com/opencord/voltha-go/common/log" |
| 28 | ponrmgr "github.com/opencord/voltha-go/common/ponresourcemanager" |
| 29 | "github.com/opencord/voltha-go/db/kvstore" |
| 30 | "github.com/opencord/voltha-go/db/model" |
| 31 | "github.com/opencord/voltha-protos/go/openolt" |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 32 | ) |
| 33 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 34 | // KvstoreTimeout specifies the time out for KV Store Connection |
| 35 | const KvstoreTimeout = 5 |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 36 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 37 | // BasePathKvStore - service/voltha/openolt/<device_id> |
| 38 | const BasePathKvStore = "service/voltha/openolt/{%s}" |
| 39 | |
| 40 | // FlowInfo holds the flow information |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 41 | type FlowInfo struct { |
| 42 | Flow *openolt.Flow |
| 43 | FlowStoreCookie uint64 |
| 44 | FlowCategory string |
| 45 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 46 | |
| 47 | // OpenOltResourceMgr holds resource related information as provided below for each field |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 48 | type OpenOltResourceMgr struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 49 | DeviceID string // OLT device id |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 50 | HostAndPort string // Host and port of the kv store to connect to |
| 51 | Args string // args |
| 52 | KVStore *model.Backend // backend kv store connection handle |
| 53 | DeviceType string |
| 54 | Host string // Host ip of the kv store |
| 55 | Port int // port of the kv store |
| 56 | DevInfo *openolt.DeviceInfo // device information |
| 57 | // array of pon resource managers per interface technology |
| 58 | ResourceMgrs map[uint32]*ponrmgr.PONResourceManager |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 59 | } |
| 60 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 61 | func newKVClient(storeType, address string, timeout uint32) (kvstore.Client, error) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 62 | log.Infow("kv-store-type", log.Fields{"store": storeType}) |
| 63 | switch storeType { |
| 64 | case "consul": |
| 65 | return kvstore.NewConsulClient(address, int(timeout)) |
| 66 | case "etcd": |
| 67 | return kvstore.NewEtcdClient(address, int(timeout)) |
| 68 | } |
| 69 | return nil, errors.New("unsupported-kv-store") |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 70 | } |
| 71 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 72 | // SetKVClient sets the KV client and return a kv backend |
| 73 | func SetKVClient(backend string, Host string, Port int, DeviceID string) *model.Backend { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 74 | addr := Host + ":" + strconv.Itoa(Port) |
| 75 | // TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some |
| 76 | // issue between kv store and backend , core is not calling NewBackend directly |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 77 | kvClient, err := newKVClient(backend, addr, KvstoreTimeout) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 78 | if err != nil { |
| 79 | log.Fatalw("Failed to init KV client\n", log.Fields{"err": err}) |
| 80 | return nil |
| 81 | } |
| 82 | kvbackend := &model.Backend{ |
| 83 | Client: kvClient, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 84 | StoreType: backend, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 85 | Host: Host, |
| 86 | Port: Port, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 87 | Timeout: KvstoreTimeout, |
| 88 | PathPrefix: fmt.Sprintf(BasePathKvStore, DeviceID)} |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 89 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 90 | return kvbackend |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 91 | } |
| 92 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 93 | // NewResourceMgr init a New resource maanger instance which in turn instantiates pon resource manager |
| 94 | // instances according to technology. Initializes the default resource ranges for all |
| 95 | // the resources. |
| 96 | func NewResourceMgr(deviceID string, KVStoreHostPort string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo) *OpenOltResourceMgr { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 97 | var ResourceMgr OpenOltResourceMgr |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 98 | log.Debugf("Init new resource manager , host_port: %s, deviceid: %s", KVStoreHostPort, deviceID) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 99 | ResourceMgr.HostAndPort = KVStoreHostPort |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 100 | ResourceMgr.DeviceType = deviceType |
| 101 | ResourceMgr.DevInfo = devInfo |
| 102 | IPPort := strings.Split(KVStoreHostPort, ":") |
| 103 | ResourceMgr.Host = IPPort[0] |
| 104 | ResourceMgr.Port, _ = strconv.Atoi(IPPort[1]) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 105 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 106 | Backend := kvStoreType |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 107 | ResourceMgr.KVStore = SetKVClient(Backend, ResourceMgr.Host, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 108 | ResourceMgr.Port, deviceID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 109 | if ResourceMgr.KVStore == nil { |
| 110 | log.Error("Failed to setup KV store") |
| 111 | } |
| 112 | Ranges := make(map[string]*openolt.DeviceInfo_DeviceResourceRanges) |
| 113 | RsrcMgrsByTech := make(map[string]*ponrmgr.PONResourceManager) |
| 114 | ResourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 115 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 116 | // TODO self.args = registry('main').get_args() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 117 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 118 | /* |
| 119 | If a legacy driver returns protobuf without any ranges,s synthesize one from |
| 120 | the legacy global per-device informaiton. This, in theory, is temporary until |
| 121 | the legacy drivers are upgrade to support pool ranges. |
| 122 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 123 | if devInfo.Ranges == nil { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 124 | var ranges openolt.DeviceInfo_DeviceResourceRanges |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 125 | ranges.Technology = devInfo.GetTechnology() |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 126 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 127 | NumPONPorts := devInfo.GetPonPorts() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 128 | var index uint32 |
| 129 | for index = 0; index < NumPONPorts; index++ { |
| 130 | ranges.IntfIds = append(ranges.IntfIds, index) |
| 131 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 132 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 133 | var Pool openolt.DeviceInfo_DeviceResourceRanges_Pool |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 134 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 135 | Pool.Start = devInfo.OnuIdStart |
| 136 | Pool.End = devInfo.OnuIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 137 | Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 138 | ranges.Pools = append(ranges.Pools, &Pool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 139 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 140 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 141 | Pool.Start = devInfo.AllocIdStart |
| 142 | Pool.End = devInfo.AllocIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 143 | 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] | 144 | ranges.Pools = append(ranges.Pools, &Pool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 145 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 146 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 147 | Pool.Start = devInfo.GemportIdStart |
| 148 | Pool.End = devInfo.GemportIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 149 | 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] | 150 | ranges.Pools = append(ranges.Pools, &Pool) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 151 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 152 | Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 153 | Pool.Start = devInfo.FlowIdStart |
| 154 | Pool.End = devInfo.FlowIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 155 | 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] | 156 | ranges.Pools = append(ranges.Pools, &Pool) |
| 157 | // Add to device info |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 158 | devInfo.Ranges = append(devInfo.Ranges, &ranges) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 159 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 160 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 161 | // Create a separate Resource Manager instance for each range. This assumes that |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 162 | // each technology is represented by only a single range |
| 163 | var GlobalPONRsrcMgr *ponrmgr.PONResourceManager |
| 164 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 165 | for _, TechRange := range devInfo.Ranges { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 166 | technology := TechRange.Technology |
| 167 | log.Debugf("Device info technology %s", technology) |
| 168 | Ranges[technology] = TechRange |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 169 | RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(technology, deviceType, deviceID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 170 | Backend, ResourceMgr.Host, ResourceMgr.Port) |
| 171 | if err != nil { |
| 172 | log.Errorf("Failed to create pon resource manager instacnce for technology %s", technology) |
| 173 | return nil |
| 174 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 175 | // resource_mgrs_by_tech[technology] = resource_mgr |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 176 | if GlobalPONRsrcMgr == nil { |
| 177 | GlobalPONRsrcMgr = RsrcMgrsByTech[technology] |
| 178 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 179 | for _, IntfID := range TechRange.IntfIds { |
| 180 | ResourceMgr.ResourceMgrs[uint32(IntfID)] = RsrcMgrsByTech[technology] |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 181 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 182 | // self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 183 | InitializeDeviceResourceRangeAndPool(RsrcMgrsByTech[technology], GlobalPONRsrcMgr, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 184 | TechRange, devInfo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 185 | } |
| 186 | // After we have initialized resource ranges, initialize the |
| 187 | // resource pools accordingly. |
| 188 | for _, PONRMgr := range RsrcMgrsByTech { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 189 | _ = PONRMgr.InitDeviceResourcePool() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 190 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 191 | log.Info("Initialization of resource manager success!") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 192 | return &ResourceMgr |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 193 | } |
| 194 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 195 | // InitializeDeviceResourceRangeAndPool initializes the resource range pool according to the sharing type, then apply |
| 196 | // device specific information. If KV doesn't exist |
| 197 | // or is broader than the device, the device's information will |
| 198 | // dictate the range limits |
| 199 | func InitializeDeviceResourceRangeAndPool(ponRMgr *ponrmgr.PONResourceManager, globalPONRMgr *ponrmgr.PONResourceManager, |
| 200 | techRange *openolt.DeviceInfo_DeviceResourceRanges, devInfo *openolt.DeviceInfo) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 201 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 202 | // init the resource range pool according to the sharing type |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 203 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 204 | log.Debugf("Resource range pool init for technology %s", ponRMgr.Technology) |
| 205 | // first load from KV profiles |
| 206 | status := ponRMgr.InitResourceRangesFromKVStore() |
| 207 | if !status { |
| 208 | log.Debugf("Failed to load resource ranges from KV store for tech %s", ponRMgr.Technology) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 209 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 210 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 211 | /* |
| 212 | Then apply device specific information. If KV doesn't exist |
| 213 | or is broader than the device, the device's informationw ill |
| 214 | dictate the range limits |
| 215 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 216 | log.Debugf("Using device info to init pon resource ranges for tech", ponRMgr.Technology) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 217 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 218 | ONUIDStart := devInfo.OnuIdStart |
| 219 | ONUIDEnd := devInfo.OnuIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 220 | ONUIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF |
| 221 | ONUIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 222 | AllocIDStart := devInfo.AllocIdStart |
| 223 | AllocIDEnd := devInfo.AllocIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 224 | AllocIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 225 | AllocIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 226 | GEMPortIDStart := devInfo.GemportIdStart |
| 227 | GEMPortIDEnd := devInfo.GemportIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 228 | GEMPortIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 229 | GEMPortIDSharedPoolID := uint32(0) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 230 | FlowIDStart := devInfo.FlowIdStart |
| 231 | FlowIDEnd := devInfo.FlowIdEnd |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 232 | FlowIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation |
| 233 | FlowIDSharedPoolID := uint32(0) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 234 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 235 | var FirstIntfPoolID uint32 |
| 236 | var SharedPoolID uint32 |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 237 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 238 | /* |
| 239 | * 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^] | 240 | * 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] | 241 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 242 | for _, FirstIntfPoolID = range techRange.IntfIds { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 243 | // skip the intf id 0 |
| 244 | if FirstIntfPoolID == 0 { |
| 245 | continue |
| 246 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 247 | break |
| 248 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 249 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 250 | for _, RangePool := range techRange.Pools { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 251 | 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] | 252 | SharedPoolID = FirstIntfPoolID |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 253 | } else if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_SAME_TECH { |
| 254 | SharedPoolID = FirstIntfPoolID |
| 255 | } else { |
| 256 | SharedPoolID = 0 |
| 257 | } |
| 258 | if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID { |
| 259 | ONUIDStart = RangePool.Start |
| 260 | ONUIDEnd = RangePool.End |
| 261 | ONUIDShared = RangePool.Sharing |
| 262 | ONUIDSharedPoolID = SharedPoolID |
| 263 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID { |
| 264 | AllocIDStart = RangePool.Start |
| 265 | AllocIDEnd = RangePool.End |
| 266 | AllocIDShared = RangePool.Sharing |
| 267 | AllocIDSharedPoolID = SharedPoolID |
| 268 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID { |
| 269 | GEMPortIDStart = RangePool.Start |
| 270 | GEMPortIDEnd = RangePool.End |
| 271 | GEMPortIDShared = RangePool.Sharing |
| 272 | GEMPortIDSharedPoolID = SharedPoolID |
| 273 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID { |
| 274 | FlowIDStart = RangePool.Start |
| 275 | FlowIDEnd = RangePool.End |
| 276 | FlowIDShared = RangePool.Sharing |
| 277 | FlowIDSharedPoolID = SharedPoolID |
| 278 | } |
| 279 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 280 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 281 | log.Debugw("Device info init", log.Fields{"technology": techRange.Technology, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 282 | "onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID, |
| 283 | "alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd, |
| 284 | "alloc_id_shared_pool_id": AllocIDSharedPoolID, |
| 285 | "gemport_id_start": GEMPortIDStart, "gemport_id_end": GEMPortIDEnd, |
| 286 | "gemport_id_shared_pool_id": GEMPortIDSharedPoolID, |
| 287 | "flow_id_start": FlowIDStart, |
| 288 | "flow_id_end_idx": FlowIDEnd, |
| 289 | "flow_id_shared_pool_id": FlowIDSharedPoolID, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 290 | "intf_ids": techRange.IntfIds, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 291 | "uni_id_start": 0, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 292 | "uni_id_end_idx": 1, /*MaxUNIIDperONU()*/ |
| 293 | }) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 294 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 295 | ponRMgr.InitDefaultPONResourceRanges(ONUIDStart, ONUIDEnd, ONUIDSharedPoolID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 296 | AllocIDStart, AllocIDEnd, AllocIDSharedPoolID, |
| 297 | GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID, |
| 298 | FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 299 | devInfo.PonPorts, techRange.IntfIds) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 300 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 301 | // 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] | 302 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 303 | if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 304 | 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] | 305 | "", 0, nil) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 306 | ponRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd, |
| 307 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 308 | } |
| 309 | if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 310 | 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] | 311 | "", 0, nil) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 312 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 313 | ponRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd, |
| 314 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 315 | } |
| 316 | if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 317 | 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] | 318 | "", 0, nil) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 319 | ponRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd, |
| 320 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 321 | } |
| 322 | if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 323 | 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] | 324 | "", 0, nil) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 325 | ponRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd, |
| 326 | "", 0, globalPONRMgr) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 327 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 328 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 329 | // Make sure loaded range fits the platform bit encoding ranges |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 330 | 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] | 331 | } |
| 332 | |
| 333 | /* TODO |
| 334 | def __del__(self): |
| 335 | self.log.info("clearing-device-resource-pool") |
| 336 | for key, resource_mgr in self.resource_mgrs.iteritems(): |
| 337 | resource_mgr.clear_device_resource_pool() |
| 338 | |
| 339 | def assert_pon_id_limit(self, pon_intf_id): |
| 340 | assert pon_intf_id in self.resource_mgrs |
| 341 | |
| 342 | def assert_onu_id_limit(self, pon_intf_id, onu_id): |
| 343 | self.assert_pon_id_limit(pon_intf_id) |
| 344 | self.resource_mgrs[pon_intf_id].assert_resource_limits(onu_id, PONResourceManager.ONU_ID) |
| 345 | |
| 346 | @property |
| 347 | def max_uni_id_per_onu(self): |
| 348 | return 0 #OpenOltPlatform.MAX_UNIS_PER_ONU-1, zero-based indexing Uncomment or override to make default multi-uni |
| 349 | |
| 350 | def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id): |
| 351 | self.assert_onu_id_limit(pon_intf_id, onu_id) |
| 352 | self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID) |
| 353 | */ |
| 354 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 355 | // GetONUID returns the available OnuID for the given pon-port |
| 356 | func (RsrcMgr *OpenOltResourceMgr) GetONUID(ponIntfID uint32) (uint32, error) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 357 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 358 | // Get ONU id for a provided pon interface ID. |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 359 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 360 | ONUID, err := RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(ponIntfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 361 | ponrmgr.ONU_ID, 1) |
| 362 | if err != nil { |
| 363 | log.Errorf("Failed to get resource for interface %d for type %s", |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 364 | ponIntfID, ponrmgr.ONU_ID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 365 | return ONUID[0], err |
| 366 | } |
| 367 | if ONUID != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 368 | RsrcMgr.ResourceMgrs[ponIntfID].InitResourceMap(fmt.Sprintf("%d,%d", ponIntfID, ONUID)) |
| 369 | return ONUID[0], err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 370 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 371 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 372 | return 0, err // return OnuID 0 on error |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 373 | } |
| 374 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 375 | // GetFlowIDInfo returns the slice of flow info of the given pon-port |
| 376 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 377 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
| 378 | func (RsrcMgr *OpenOltResourceMgr) GetFlowIDInfo(ponIntfID uint32, onuID uint32, uniID uint32, flowID uint32) *[]FlowInfo { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 379 | var flows []FlowInfo |
| 380 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 381 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 382 | if err := RsrcMgr.ResourceMgrs[ponIntfID].GetFlowIDInfo(FlowPath, flowID, &flows); err != nil { |
| 383 | log.Errorw("Error while getting flows from KV store", log.Fields{"flowId": flowID}) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 384 | return nil |
| 385 | } |
| 386 | if len(flows) == 0 { |
| 387 | log.Debugw("No flowInfo found in KV store", log.Fields{"flowPath": FlowPath}) |
| 388 | return nil |
| 389 | } |
| 390 | return &flows |
| 391 | } |
| 392 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 393 | // GetCurrentFlowIDsForOnu fetches flow ID from the resource manager |
| 394 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 395 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 396 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentFlowIDsForOnu(PONIntfID uint32, ONUID uint32, UNIID uint32) []uint32 { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 397 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 398 | FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID) |
| 399 | return RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath) |
| 400 | } |
| 401 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 402 | // UpdateFlowIDInfo updates flow info for the given pon interface, onu id, and uni id |
| 403 | // Note: For flows which trap from the NNI and not really associated with any particular |
| 404 | // ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
| 405 | func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDInfo(ponIntfID int32, onuID int32, uniID int32, |
| 406 | flowID uint32, flowData *[]FlowInfo) error { |
| 407 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 408 | return RsrcMgr.ResourceMgrs[uint32(ponIntfID)].UpdateFlowIDInfoForOnu(FlowPath, flowID, *flowData) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 409 | } |
| 410 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 411 | // GetFlowID return flow ID for a given pon interface id, onu id and uni id |
| 412 | func (RsrcMgr *OpenOltResourceMgr) GetFlowID(ponIntfID uint32, ONUID uint32, uniID uint32, |
| 413 | flowStoreCookie uint64, |
| 414 | flowCategory string) (uint32, error) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 415 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 416 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 417 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, ONUID, uniID) |
| 418 | FlowIDs := RsrcMgr.ResourceMgrs[ponIntfID].GetCurrentFlowIDsForOnu(FlowPath) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 419 | if FlowIDs != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 420 | log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "ONUID": ONUID, "uniID": uniID, "KVpath": FlowPath}) |
| 421 | for _, flowID := range FlowIDs { |
| 422 | FlowInfo := RsrcMgr.GetFlowIDInfo(ponIntfID, ONUID, uniID, uint32(flowID)) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 423 | if FlowInfo != nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 424 | for _, Info := range *FlowInfo { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 425 | if flowCategory != "" && Info.FlowCategory == flowCategory { |
| 426 | log.Debug("Found flow matching with flow category", log.Fields{"flowId": flowID, "flowCategory": flowCategory}) |
| 427 | return flowID, nil |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 428 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 429 | if flowStoreCookie != 0 && Info.FlowStoreCookie == flowStoreCookie { |
| 430 | log.Debug("Found flow matching with flowStore cookie", log.Fields{"flowId": flowID, "flowStoreCookie": flowStoreCookie}) |
| 431 | return flowID, nil |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | } |
| 435 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 436 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 437 | log.Debug("No matching flows with flow cookie or flow category, allocating new flowid") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 438 | FlowIDs, err = RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(ponIntfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 439 | ponrmgr.FLOW_ID, 1) |
| 440 | if err != nil { |
| 441 | log.Errorf("Failed to get resource for interface %d for type %s", |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 442 | ponIntfID, ponrmgr.FLOW_ID) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 443 | return uint32(0), err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 444 | } |
| 445 | if FlowIDs != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 446 | _ = RsrcMgr.ResourceMgrs[ponIntfID].UpdateFlowIDForOnu(FlowPath, FlowIDs[0], true) |
| 447 | return FlowIDs[0], err |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 448 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 449 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 450 | return 0, err |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 451 | } |
| 452 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 453 | // GetAllocID return the first Alloc ID for a given pon interface id and onu id and then update the resource map on |
| 454 | // the KV store with the list of alloc_ids allocated for the pon_intf_onu_id tuple |
| 455 | // Currently of all the alloc_ids available, it returns the first alloc_id in the list for tha given ONU |
| 456 | func (RsrcMgr *OpenOltResourceMgr) GetAllocID(intfID uint32, onuID uint32, uniID uint32) uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 457 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 458 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 459 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
| 460 | AllocID := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 461 | if AllocID != nil { |
| 462 | // Since we support only one alloc_id for the ONU at the moment, |
| 463 | // return the first alloc_id in the list, if available, for that |
| 464 | // ONU. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 465 | log.Debugw("Retrieved alloc ID from pon resource mgr", log.Fields{"AllocID": AllocID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 466 | return AllocID[0] |
| 467 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 468 | AllocID, err = RsrcMgr.ResourceMgrs[intfID].GetResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 469 | ponrmgr.ALLOC_ID, 1) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 470 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 471 | if AllocID == nil || err != nil { |
| 472 | log.Error("Failed to allocate alloc id") |
| 473 | return 0 |
| 474 | } |
| 475 | // update the resource map on KV store with the list of alloc_id |
| 476 | // allocated for the pon_intf_onu_id tuple |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 477 | err = RsrcMgr.ResourceMgrs[intfID].UpdateAllocIdsForOnu(IntfOnuIDUniID, AllocID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 478 | if err != nil { |
| 479 | log.Error("Failed to update Alloc ID") |
| 480 | return 0 |
| 481 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 482 | log.Debugw("Allocated new Tcont from pon resource mgr", log.Fields{"AllocID": AllocID}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 483 | return AllocID[0] |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 484 | } |
| 485 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 486 | // UpdateAllocIdsForOnu updates alloc ids in kv store for a given pon interface id, onu id and uni id |
| 487 | func (RsrcMgr *OpenOltResourceMgr) UpdateAllocIdsForOnu(ponPort uint32, onuID uint32, uniID uint32, allocID []uint32) error { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 488 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 489 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
| 490 | return RsrcMgr.ResourceMgrs[ponPort].UpdateAllocIdsForOnu(IntfOnuIDUniID, |
| 491 | allocID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 492 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 493 | |
| 494 | // GetCurrentGEMPortIDsForOnu returns gem ports for given pon interface , onu id and uni id |
| 495 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentGEMPortIDsForOnu(intfID uint32, onuID uint32, |
| 496 | uniID uint32) []uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 497 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 498 | /* 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] | 499 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 500 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
| 501 | return RsrcMgr.ResourceMgrs[intfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 502 | } |
| 503 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 504 | // GetCurrentAllocIDForOnu returns alloc ids for given pon interface and onu id |
| 505 | // Currently of all the alloc_ids available, it returns the first alloc_id in the list for tha given ONU |
| 506 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentAllocIDForOnu(intfID uint32, onuID uint32, uniID uint32) uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 507 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 508 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
| 509 | AllocID := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 510 | if AllocID != nil { |
| 511 | // Since we support only one alloc_id for the ONU at the moment, |
| 512 | // return the first alloc_id in the list, if available, for that |
| 513 | // ONU. |
| 514 | return AllocID[0] |
| 515 | } |
| 516 | return 0 |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 517 | } |
| 518 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 519 | // UpdateGEMportsPonportToOnuMapOnKVStore updates onu and uni id associated with the gem port to the kv store |
| 520 | // This stored information is used when packet_indication is received and we need to derive the ONU Id for which |
| 521 | // the packet arrived based on the pon_intf and gemport available in the packet_indication |
| 522 | func (RsrcMgr *OpenOltResourceMgr) UpdateGEMportsPonportToOnuMapOnKVStore(gemPorts []uint32, PonPort uint32, |
| 523 | onuID uint32, uniID uint32) error { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 524 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 525 | /* Update onu and uni id associated with the gem port to the kv store. */ |
| 526 | var IntfGEMPortPath string |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 527 | Data := fmt.Sprintf("%d %d", onuID, uniID) |
| 528 | for _, GEM := range gemPorts { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 529 | IntfGEMPortPath = fmt.Sprintf("%d,%d", PonPort, GEM) |
| 530 | Val, err := json.Marshal(Data) |
| 531 | if err != nil { |
| 532 | log.Error("failed to Marshal") |
| 533 | return err |
| 534 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 535 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 536 | if err = RsrcMgr.KVStore.Put(IntfGEMPortPath, Val); err != nil { |
| 537 | log.Errorf("Failed to update resource %s", IntfGEMPortPath) |
| 538 | return err |
| 539 | } |
| 540 | } |
| 541 | return nil |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 542 | } |
| 543 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 544 | // GetGEMPortID gets gem port id for a particular pon port, onu id and uni id and then update the resource map on |
| 545 | // the KV store with the list of gemport_id allocated for the pon_intf_onu_id tuple |
| 546 | func (RsrcMgr *OpenOltResourceMgr) GetGEMPortID(ponPort uint32, onuID uint32, |
| 547 | uniID uint32, NumOfPorts uint32) ([]uint32, error) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 548 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 549 | /* Get gem port id for a particular pon port, onu id |
| 550 | and uni id. |
| 551 | */ |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 552 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 553 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 554 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 555 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 556 | GEMPortList := RsrcMgr.ResourceMgrs[ponPort].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 557 | if GEMPortList != nil { |
| 558 | return GEMPortList, nil |
| 559 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 560 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 561 | GEMPortList, err = RsrcMgr.ResourceMgrs[ponPort].GetResourceID(ponPort, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 562 | ponrmgr.GEMPORT_ID, NumOfPorts) |
| 563 | if err != nil && GEMPortList == nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 564 | log.Errorf("Failed to get gem port id for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 565 | return nil, err |
| 566 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 567 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 568 | // update the resource map on KV store with the list of gemport_id |
| 569 | // allocated for the pon_intf_onu_id tuple |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 570 | err = RsrcMgr.ResourceMgrs[ponPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 571 | GEMPortList) |
| 572 | if err != nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 573 | log.Errorf("Failed to update GEM ports to kv store for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 574 | return nil, err |
| 575 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 576 | _ = RsrcMgr.UpdateGEMportsPonportToOnuMapOnKVStore(GEMPortList, ponPort, |
| 577 | onuID, uniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 578 | return GEMPortList, err |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 579 | } |
| 580 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 581 | // UpdateGEMPortIDsForOnu updates gemport ids on to the kv store for a given pon port, onu id and uni id |
| 582 | func (RsrcMgr *OpenOltResourceMgr) UpdateGEMPortIDsForOnu(ponPort uint32, onuID uint32, |
| 583 | uniID uint32, GEMPortList []uint32) error { |
| 584 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID) |
| 585 | return RsrcMgr.ResourceMgrs[ponPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 586 | GEMPortList) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 587 | |
| 588 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 589 | |
| 590 | // FreeonuID releases(make free) onu id for a particular pon-port |
| 591 | func (RsrcMgr *OpenOltResourceMgr) FreeonuID(intfID uint32, onuID []uint32) { |
| 592 | |
| 593 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, ponrmgr.ONU_ID, onuID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 594 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 595 | /* Free onu id for a particular interface.*/ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 596 | var IntfonuID string |
| 597 | for _, onu := range onuID { |
| 598 | IntfonuID = fmt.Sprintf("%d,%d", intfID, onu) |
| 599 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(IntfonuID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 600 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 601 | } |
| 602 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 603 | // FreeFlowID returns the free flow id for a given interface, onu id and uni id |
| 604 | func (RsrcMgr *OpenOltResourceMgr) FreeFlowID(IntfID uint32, onuID uint32, |
| 605 | uniID uint32, FlowID uint32) { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 606 | var IntfONUID string |
| 607 | var err error |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 608 | IntfONUID = fmt.Sprintf("%d,%d,%d", IntfID, onuID, uniID) |
| 609 | err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(IntfONUID, FlowID, false) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 610 | if err != nil { |
| 611 | log.Error("Failed to Update flow id infor for %s", IntfONUID) |
| 612 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 613 | RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(IntfONUID, FlowID) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 616 | // FreeFlowIDs releases the flow Ids |
| 617 | func (RsrcMgr *OpenOltResourceMgr) FreeFlowIDs(IntfID uint32, onuID uint32, |
| 618 | uniID uint32, FlowID []uint32) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 619 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 620 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.FLOW_ID, FlowID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 621 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 622 | var IntfOnuIDUniID string |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 623 | var err error |
| 624 | for _, flow := range FlowID { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 625 | IntfOnuIDUniID = fmt.Sprintf("%d,%d,%d", IntfID, onuID, uniID) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 626 | err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(IntfOnuIDUniID, flow, false) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 627 | if err != nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 628 | log.Error("Failed to Update flow id infor for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 629 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 630 | RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(IntfOnuIDUniID, flow) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 631 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 632 | } |
| 633 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 634 | // FreePONResourcesForONU make the pon resources free for a given pon interface and onu id, and the clears the |
| 635 | // resource map and the onuID associated with (pon_intf_id, gemport_id) tuple, |
| 636 | func (RsrcMgr *OpenOltResourceMgr) FreePONResourcesForONU(intfID uint32, onuID uint32, uniID uint32) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 637 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 638 | var onuIDs []uint32 |
| 639 | onuIDs = append(onuIDs, onuID) |
| 640 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 641 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 642 | AllocIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 643 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 644 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 645 | ponrmgr.ALLOC_ID, |
| 646 | AllocIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 647 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 648 | GEMPortIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
| 649 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 650 | ponrmgr.GEMPORT_ID, |
| 651 | GEMPortIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 652 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 653 | FlowIDs := RsrcMgr.ResourceMgrs[intfID].GetCurrentFlowIDsForOnu(IntfOnuIDUniID) |
| 654 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 655 | ponrmgr.FLOW_ID, |
| 656 | FlowIDs) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 657 | RsrcMgr.ResourceMgrs[intfID].FreeResourceID(intfID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 658 | ponrmgr.ONU_ID, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 659 | onuIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 660 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 661 | // Clear resource map associated with (pon_intf_id, gemport_id) tuple. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 662 | RsrcMgr.ResourceMgrs[intfID].RemoveResourceMap(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 663 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 664 | // Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple. |
| 665 | for _, GEM := range GEMPortIDs { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 666 | _ = RsrcMgr.KVStore.Delete(fmt.Sprintf("%d,%d", intfID, GEM)) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 667 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 668 | } |
| 669 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 670 | // IsFlowCookieOnKVStore checks if the given flow cookie is present on the kv store |
| 671 | // Returns true if the flow cookie is found, otherwise it returns false |
| 672 | func (RsrcMgr *OpenOltResourceMgr) IsFlowCookieOnKVStore(ponIntfID uint32, onuID uint32, uniID uint32, |
| 673 | flowStoreCookie uint64) bool { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 674 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 675 | FlowPath := fmt.Sprintf("%d,%d,%d", ponIntfID, onuID, uniID) |
| 676 | FlowIDs := RsrcMgr.ResourceMgrs[ponIntfID].GetCurrentFlowIDsForOnu(FlowPath) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 677 | if FlowIDs != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 678 | log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": ponIntfID, "onuID": onuID, "uniID": uniID, "KVpath": FlowPath}) |
| 679 | for _, flowID := range FlowIDs { |
| 680 | FlowInfo := RsrcMgr.GetFlowIDInfo(ponIntfID, onuID, uniID, uint32(flowID)) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 681 | if FlowInfo != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 682 | log.Debugw("Found flows", log.Fields{"flows": *FlowInfo, "flowId": flowID}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 683 | for _, Info := range *FlowInfo { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame^] | 684 | if Info.FlowStoreCookie == flowStoreCookie { |
| 685 | log.Debug("Found flow matching with flowStore cookie", log.Fields{"flowId": flowID, "flowStoreCookie": flowStoreCookie}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 686 | return true |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | return false |
| 693 | } |