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