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