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