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 | } |
| 173 | for IntfId := range TechRange.IntfIds { |
| 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 GlobalPoolID uint32 |
| 226 | var FirstIntfPoolID uint32 |
| 227 | var SharedPoolID uint32 |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 228 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 229 | for _, FirstIntfPoolID = range TechRange.IntfIds { |
| 230 | break |
| 231 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 232 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 233 | for _, RangePool := range TechRange.Pools { |
| 234 | if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
| 235 | SharedPoolID = GlobalPoolID |
| 236 | } else if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_SAME_TECH { |
| 237 | SharedPoolID = FirstIntfPoolID |
| 238 | } else { |
| 239 | SharedPoolID = 0 |
| 240 | } |
| 241 | if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID { |
| 242 | ONUIDStart = RangePool.Start |
| 243 | ONUIDEnd = RangePool.End |
| 244 | ONUIDShared = RangePool.Sharing |
| 245 | ONUIDSharedPoolID = SharedPoolID |
| 246 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID { |
| 247 | AllocIDStart = RangePool.Start |
| 248 | AllocIDEnd = RangePool.End |
| 249 | AllocIDShared = RangePool.Sharing |
| 250 | AllocIDSharedPoolID = SharedPoolID |
| 251 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID { |
| 252 | GEMPortIDStart = RangePool.Start |
| 253 | GEMPortIDEnd = RangePool.End |
| 254 | GEMPortIDShared = RangePool.Sharing |
| 255 | GEMPortIDSharedPoolID = SharedPoolID |
| 256 | } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID { |
| 257 | FlowIDStart = RangePool.Start |
| 258 | FlowIDEnd = RangePool.End |
| 259 | FlowIDShared = RangePool.Sharing |
| 260 | FlowIDSharedPoolID = SharedPoolID |
| 261 | } |
| 262 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 263 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 264 | log.Debugw("Device info init", log.Fields{"technology": TechRange.Technology, |
| 265 | "onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID, |
| 266 | "alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd, |
| 267 | "alloc_id_shared_pool_id": AllocIDSharedPoolID, |
| 268 | "gemport_id_start": GEMPortIDStart, "gemport_id_end": GEMPortIDEnd, |
| 269 | "gemport_id_shared_pool_id": GEMPortIDSharedPoolID, |
| 270 | "flow_id_start": FlowIDStart, |
| 271 | "flow_id_end_idx": FlowIDEnd, |
| 272 | "flow_id_shared_pool_id": FlowIDSharedPoolID, |
| 273 | "intf_ids": TechRange.IntfIds, |
| 274 | "uni_id_start": 0, |
| 275 | "uni_id_end_idx":/*MaxUNIIDperONU()*/ 1}) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 276 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 277 | PONRMgr.InitDefaultPONResourceRanges(ONUIDStart, ONUIDEnd, ONUIDSharedPoolID, |
| 278 | AllocIDStart, AllocIDEnd, AllocIDSharedPoolID, |
| 279 | GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID, |
| 280 | FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1, |
| 281 | DevInfo.PonPorts, TechRange.IntfIds) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 282 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 283 | // 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] | 284 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 285 | if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
| 286 | GlobalPONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd, |
| 287 | "", 0, nil) |
| 288 | PONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd, |
| 289 | "", 0, GlobalPONRMgr) |
| 290 | } |
| 291 | if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
| 292 | GlobalPONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd, |
| 293 | "", 0, nil) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 294 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 295 | PONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd, |
| 296 | "", 0, GlobalPONRMgr) |
| 297 | } |
| 298 | if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
| 299 | GlobalPONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd, |
| 300 | "", 0, nil) |
| 301 | PONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd, |
| 302 | "", 0, GlobalPONRMgr) |
| 303 | } |
| 304 | if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH { |
| 305 | GlobalPONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd, |
| 306 | "", 0, nil) |
| 307 | PONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd, |
| 308 | "", 0, GlobalPONRMgr) |
| 309 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 310 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 311 | // Make sure loaded range fits the platform bit encoding ranges |
| 312 | 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] | 313 | } |
| 314 | |
| 315 | /* TODO |
| 316 | def __del__(self): |
| 317 | self.log.info("clearing-device-resource-pool") |
| 318 | for key, resource_mgr in self.resource_mgrs.iteritems(): |
| 319 | resource_mgr.clear_device_resource_pool() |
| 320 | |
| 321 | def assert_pon_id_limit(self, pon_intf_id): |
| 322 | assert pon_intf_id in self.resource_mgrs |
| 323 | |
| 324 | def assert_onu_id_limit(self, pon_intf_id, onu_id): |
| 325 | self.assert_pon_id_limit(pon_intf_id) |
| 326 | self.resource_mgrs[pon_intf_id].assert_resource_limits(onu_id, PONResourceManager.ONU_ID) |
| 327 | |
| 328 | @property |
| 329 | def max_uni_id_per_onu(self): |
| 330 | return 0 #OpenOltPlatform.MAX_UNIS_PER_ONU-1, zero-based indexing Uncomment or override to make default multi-uni |
| 331 | |
| 332 | def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id): |
| 333 | self.assert_onu_id_limit(pon_intf_id, onu_id) |
| 334 | self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID) |
| 335 | */ |
| 336 | |
| 337 | func (RsrcMgr *OpenOltResourceMgr) GetONUID(PONIntfID uint32) (uint32, error) { |
| 338 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 339 | // Get ONU id for a provided pon interface ID. |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 340 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 341 | ONUID, err := RsrcMgr.ResourceMgrs[PONIntfID].GetResourceID(PONIntfID, |
| 342 | ponrmgr.ONU_ID, 1) |
| 343 | if err != nil { |
| 344 | log.Errorf("Failed to get resource for interface %d for type %s", |
| 345 | PONIntfID, ponrmgr.ONU_ID) |
| 346 | return ONUID[0], err |
| 347 | } |
| 348 | if ONUID != nil { |
| 349 | RsrcMgr.ResourceMgrs[PONIntfID].InitResourceMap(fmt.Sprintf("%d,%d", PONIntfID, ONUID)) |
| 350 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 351 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 352 | return ONUID[0], err |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 353 | } |
| 354 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 355 | func (RsrcMgr *OpenOltResourceMgr) GetFlowIDInfo(PONIntfID uint32, ONUID uint32, UNIID uint32, FlowID uint32) *[]FlowInfo { |
| 356 | |
| 357 | /* |
| 358 | Note: For flows which trap from the NNI and not really associated with any particular |
| 359 | ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
| 360 | */ |
| 361 | var flows []FlowInfo |
| 362 | |
| 363 | FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID) |
| 364 | if err := RsrcMgr.ResourceMgrs[PONIntfID].GetFlowIDInfo(FlowPath, FlowID, &flows); err != nil { |
| 365 | log.Errorw("Error while getting flows from KV store", log.Fields{"flowId": FlowID}) |
| 366 | return nil |
| 367 | } |
| 368 | if len(flows) == 0 { |
| 369 | log.Debugw("No flowInfo found in KV store", log.Fields{"flowPath": FlowPath}) |
| 370 | return nil |
| 371 | } |
| 372 | return &flows |
| 373 | } |
| 374 | |
| 375 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentFlowIDsForOnu(PONIntfID uint32, ONUID uint32, UNIID uint32) []uint32 { |
| 376 | /* |
| 377 | Note: For flows which trap from the NNI and not really associated with any particular |
| 378 | ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
| 379 | */ |
| 380 | FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID) |
| 381 | return RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath) |
| 382 | } |
| 383 | |
| 384 | func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDInfo(PONIntfID int32, ONUID int32, UNIID int32, |
| 385 | FlowID uint32, FlowData *[]FlowInfo) error { |
| 386 | |
| 387 | /* |
| 388 | Note: For flows which trap from the NNI and not really associated with any particular |
| 389 | ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
| 390 | */ |
| 391 | FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID) |
| 392 | return RsrcMgr.ResourceMgrs[uint32(PONIntfID)].UpdateFlowIDInfoForOnu(FlowPath, FlowID, *FlowData) |
| 393 | } |
| 394 | |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 395 | func (RsrcMgr *OpenOltResourceMgr) GetFlowID(PONIntfID uint32, ONUID uint32, UNIID uint32, |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 396 | FlowStoreCookie uint64, |
| 397 | FlowCategory string) (uint32, error) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 398 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 399 | // 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] | 400 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 401 | var err error |
| 402 | FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID) |
| 403 | FlowIDs := RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath) |
| 404 | if FlowIDs != nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 405 | log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": PONIntfID, "ONUID": ONUID, "UNIID": UNIID, "KVpath": FlowPath}) |
| 406 | for _, flowId := range FlowIDs { |
| 407 | FlowInfo := RsrcMgr.GetFlowIDInfo(PONIntfID, ONUID, UNIID, uint32(flowId)) |
| 408 | if FlowInfo != nil { |
| 409 | log.Debugw("Found flows", log.Fields{"flows": *FlowInfo, "flowId": flowId}) |
| 410 | for _, Info := range *FlowInfo { |
| 411 | if FlowCategory != "" && Info.FlowCategory == FlowCategory { |
| 412 | log.Debug("Found flow matching with flow catagory", log.Fields{"flowId": flowId, "FlowCategory": FlowCategory}) |
| 413 | return flowId, nil |
| 414 | } |
| 415 | if FlowStoreCookie != 0 && Info.FlowStoreCookie == FlowStoreCookie { |
| 416 | log.Debug("Found flow matching with flowStore cookie", log.Fields{"flowId": flowId, "FlowStoreCookie": FlowStoreCookie}) |
| 417 | return flowId, nil |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 422 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 423 | 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] | 424 | FlowIDs, err = RsrcMgr.ResourceMgrs[PONIntfID].GetResourceID(PONIntfID, |
| 425 | ponrmgr.FLOW_ID, 1) |
| 426 | if err != nil { |
| 427 | log.Errorf("Failed to get resource for interface %d for type %s", |
| 428 | PONIntfID, ponrmgr.FLOW_ID) |
| 429 | return FlowIDs[0], err |
| 430 | } |
| 431 | if FlowIDs != nil { |
| 432 | RsrcMgr.ResourceMgrs[PONIntfID].UpdateFlowIDForOnu(FlowPath, FlowIDs[0], true) |
| 433 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 434 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 435 | return FlowIDs[0], err |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 436 | } |
| 437 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 438 | func (RsrcMgr *OpenOltResourceMgr) GetAllocID(IntfID uint32, ONUID uint32, UNIID uint32) uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 439 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 440 | // Get alloc id for a given pon interface id and onu id. |
| 441 | var err error |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 442 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID) |
| 443 | AllocID := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 444 | if AllocID != nil { |
| 445 | // Since we support only one alloc_id for the ONU at the moment, |
| 446 | // return the first alloc_id in the list, if available, for that |
| 447 | // ONU. |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 448 | 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] | 449 | return AllocID[0] |
| 450 | } |
| 451 | AllocID, err = RsrcMgr.ResourceMgrs[IntfID].GetResourceID(IntfID, |
| 452 | ponrmgr.ALLOC_ID, 1) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 453 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 454 | if AllocID == nil || err != nil { |
| 455 | log.Error("Failed to allocate alloc id") |
| 456 | return 0 |
| 457 | } |
| 458 | // update the resource map on KV store with the list of alloc_id |
| 459 | // allocated for the pon_intf_onu_id tuple |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 460 | err = RsrcMgr.ResourceMgrs[IntfID].UpdateAllocIdsForOnu(IntfOnuIDUniID, AllocID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 461 | if err != nil { |
| 462 | log.Error("Failed to update Alloc ID") |
| 463 | return 0 |
| 464 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 465 | 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] | 466 | return AllocID[0] |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 467 | } |
| 468 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 469 | 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] | 470 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 471 | /* update alloc ids in kv store for a given pon interface id, |
| 472 | onu id and uni id. |
| 473 | */ |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 474 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID) |
| 475 | return RsrcMgr.ResourceMgrs[PONPort].UpdateAllocIdsForOnu(IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 476 | AllocID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 477 | } |
| 478 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentGEMPortIDsForOnu(IntfID uint32, ONUID uint32, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 479 | UNIID uint32) []uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 480 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 481 | /* 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] | 482 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 483 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID) |
| 484 | return RsrcMgr.ResourceMgrs[IntfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 485 | } |
| 486 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 487 | func (RsrcMgr *OpenOltResourceMgr) GetCurrentAllocIDForOnu(IntfID uint32, ONUID uint32, UNIID uint32) uint32 { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 488 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 489 | /* Get alloc ids for given pon interface and onu id. */ |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 490 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 491 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID) |
| 492 | AllocID := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 493 | if AllocID != nil { |
| 494 | // Since we support only one alloc_id for the ONU at the moment, |
| 495 | // return the first alloc_id in the list, if available, for that |
| 496 | // ONU. |
| 497 | return AllocID[0] |
| 498 | } |
| 499 | return 0 |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | func (RsrcMgr *OpenOltResourceMgr) UpdateGEMportsPonportToOnuMapOnKVStore(GEMPorts []uint32, PonPort uint32, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 503 | ONUID uint32, UNIID uint32) error { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 504 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 505 | /* Update onu and uni id associated with the gem port to the kv store. */ |
| 506 | var IntfGEMPortPath string |
| 507 | Data := fmt.Sprintf("%d %d", ONUID, UNIID) |
| 508 | for _, GEM := range GEMPorts { |
| 509 | IntfGEMPortPath = fmt.Sprintf("%d,%d", PonPort, GEM) |
| 510 | Val, err := json.Marshal(Data) |
| 511 | if err != nil { |
| 512 | log.Error("failed to Marshal") |
| 513 | return err |
| 514 | } |
| 515 | // This information is used when packet_indication is received and |
| 516 | // we need to derive the ONU Id for which the packet arrived based |
| 517 | // on the pon_intf and gemport available in the packet_indication |
| 518 | if err = RsrcMgr.KVStore.Put(IntfGEMPortPath, Val); err != nil { |
| 519 | log.Errorf("Failed to update resource %s", IntfGEMPortPath) |
| 520 | return err |
| 521 | } |
| 522 | } |
| 523 | return nil |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 524 | } |
| 525 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 526 | 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] | 527 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 528 | var ONUID uint32 |
| 529 | var UNIID uint32 |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 530 | var Data string |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 531 | |
| 532 | /* get the onu and uni id for a given gem port and pon port */ |
| 533 | IntfGEMPortPath := fmt.Sprintf("%d,%d", PONPort, GEMPort) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 534 | Value, err := RsrcMgr.KVStore.Get(IntfGEMPortPath) |
| 535 | if err == nil { |
| 536 | if Value != nil { |
| 537 | Val, _ := kvstore.ToByte(Value.Value) |
| 538 | if err = json.Unmarshal(Val, &Data); err != nil { |
| 539 | log.Error("Failed to unmarshal") |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 540 | return err, ONUID, UNIID |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 541 | } |
| 542 | IDs := strings.Split(Data, " ") |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 543 | for index, val := range IDs { |
| 544 | switch index { |
| 545 | case 0: |
| 546 | if intval, err := strconv.Atoi(val); err == nil { |
| 547 | ONUID = uint32(intval) |
| 548 | } |
| 549 | case 1: |
| 550 | if intval, err := strconv.Atoi(val); err == nil { |
| 551 | UNIID = uint32(intval) |
| 552 | } |
| 553 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 557 | return err, ONUID, UNIID |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | func (RsrcMgr *OpenOltResourceMgr) GetGEMPortID(PONPort uint32, ONUID uint32, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 561 | UNIID uint32, NumOfPorts uint32) ([]uint32, error) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 562 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 563 | /* Get gem port id for a particular pon port, onu id |
| 564 | and uni id. |
| 565 | */ |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 566 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 567 | var err error |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 568 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 569 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 570 | GEMPortList := RsrcMgr.ResourceMgrs[PONPort].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 571 | if GEMPortList != nil { |
| 572 | return GEMPortList, nil |
| 573 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 574 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 575 | GEMPortList, err = RsrcMgr.ResourceMgrs[PONPort].GetResourceID(PONPort, |
| 576 | ponrmgr.GEMPORT_ID, NumOfPorts) |
| 577 | if err != nil && GEMPortList == nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 578 | log.Errorf("Failed to get gem port id for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 579 | return nil, err |
| 580 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 581 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 582 | // update the resource map on KV store with the list of gemport_id |
| 583 | // allocated for the pon_intf_onu_id tuple |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 584 | err = RsrcMgr.ResourceMgrs[PONPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 585 | GEMPortList) |
| 586 | if err != nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 587 | 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] | 588 | return nil, err |
| 589 | } |
| 590 | RsrcMgr.UpdateGEMportsPonportToOnuMapOnKVStore(GEMPortList, PONPort, |
| 591 | ONUID, UNIID) |
| 592 | return GEMPortList, err |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | func (RsrcMgr *OpenOltResourceMgr) UpdateGEMPortIDsForOnu(PONPort uint32, ONUID uint32, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 596 | UNIID uint32, GEMPortList []uint32) error { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 597 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 598 | /* Update gemport ids on to kv store for a given pon port, |
| 599 | onu id and uni id. |
| 600 | */ |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 601 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID) |
| 602 | return RsrcMgr.ResourceMgrs[PONPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 603 | GEMPortList) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 604 | |
| 605 | } |
| 606 | func (RsrcMgr *OpenOltResourceMgr) FreeONUID(IntfID uint32, ONUID []uint32) { |
| 607 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 608 | /* Free onu id for a particular interface.*/ |
| 609 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.ONU_ID, ONUID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 610 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 611 | var IntfONUID string |
| 612 | for _, onu := range ONUID { |
| 613 | IntfONUID = fmt.Sprintf("%d,%d", IntfID, onu) |
| 614 | RsrcMgr.ResourceMgrs[IntfID].RemoveResourceMap(IntfONUID) |
| 615 | } |
| 616 | return |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | func (RsrcMgr *OpenOltResourceMgr) FreeFlowID(IntfID uint32, ONUID uint32, |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 620 | UNIID uint32, FlowID []uint32) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 621 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 622 | /* 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] | 623 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 624 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.FLOW_ID, FlowID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 625 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 626 | var IntfOnuIDUniID string |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 627 | var err error |
| 628 | for _, flow := range FlowID { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 629 | IntfOnuIDUniID = fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID) |
| 630 | err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(IntfOnuIDUniID, flow, false) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 631 | if err != nil { |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 632 | log.Error("Failed to Update flow id infor for %s", IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 633 | } |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 634 | RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(IntfOnuIDUniID, flow) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 635 | } |
| 636 | return |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 637 | } |
| 638 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 639 | func (RsrcMgr *OpenOltResourceMgr) FreePONResourcesForONU(IntfID uint32, ONUID uint32, UNIID uint32) { |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 640 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 641 | /* Free pon resources for a given pon interface and onu id. */ |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 642 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 643 | var ONUIDs []uint32 |
| 644 | ONUIDs = append(ONUIDs, ONUID) |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 645 | IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 646 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 647 | AllocIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 648 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 649 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, |
| 650 | ponrmgr.ALLOC_ID, |
| 651 | AllocIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 652 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 653 | GEMPortIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 654 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, |
| 655 | ponrmgr.GEMPORT_ID, |
| 656 | GEMPortIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 657 | |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 658 | FlowIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentFlowIDsForOnu(IntfOnuIDUniID) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 659 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, |
| 660 | ponrmgr.FLOW_ID, |
| 661 | FlowIDs) |
| 662 | RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, |
| 663 | ponrmgr.ONU_ID, |
| 664 | ONUIDs) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 665 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 666 | // Clear resource map associated with (pon_intf_id, gemport_id) tuple. |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 667 | RsrcMgr.ResourceMgrs[IntfID].RemoveResourceMap(IntfOnuIDUniID) |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 668 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 669 | // Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple. |
| 670 | for _, GEM := range GEMPortIDs { |
| 671 | RsrcMgr.KVStore.Delete(fmt.Sprintf("%d,%d", IntfID, GEM)) |
| 672 | } |
Abhilash S.L | 7f17e40 | 2019-03-15 17:40:41 +0530 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /* TODO once the flow id info structure is known |
| 676 | def is_flow_cookie_on_kv_store(self, intf_id, onu_id, uni_id, flow_store_cookie): |
| 677 | ''' |
| 678 | Note: For flows which trap from the NNI and not really associated with any particular |
| 679 | ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id. |
| 680 | ''' |
| 681 | intf_onu_id = (intf_id, onu_id, uni_id) |
| 682 | try: |
| 683 | flow_ids = self.resource_mgrs[intf_id]. \ |
| 684 | get_current_flow_ids_for_onu(intf_onu_id) |
| 685 | if flow_ids is not None: |
| 686 | for flow_id in flow_ids: |
| 687 | flows = self.get_flow_id_info(intf_id, onu_id, uni_id, flow_id) |
| 688 | assert (isinstance(flows, list)) |
| 689 | for flow in flows: |
| 690 | if flow['flow_store_cookie'] == flow_store_cookie: |
| 691 | return True |
| 692 | except Exception as e: |
| 693 | self.log.error("error-retrieving-flow-info", e=e) |
| 694 | |
| 695 | return False |
| 696 | */ |