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