manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "crypto/md5" |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 23 | "encoding/hex" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 24 | "encoding/json" |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 25 | "errors" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 26 | "fmt" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 27 | "math/big" |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 28 | "strings" |
William Kurkian | 740a09c | 2019-10-23 17:07:38 -0400 | [diff] [blame] | 29 | "sync" |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 30 | "time" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 31 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v3/pkg/flows" |
| 33 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 34 | tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 35 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v3/go/common" |
| 37 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 38 | ofp "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 39 | openoltpb2 "github.com/opencord/voltha-protos/v3/go/openolt" |
| 40 | tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile" |
| 41 | "github.com/opencord/voltha-protos/v3/go/voltha" |
Chaitrashree G S | 579fe73 | 2019-08-20 20:50:47 -0400 | [diff] [blame] | 42 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 43 | //deepcopy "github.com/getlantern/deepcopy" |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 44 | "github.com/EagleChen/mapmutex" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 45 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 46 | "google.golang.org/grpc/codes" |
| 47 | "google.golang.org/grpc/status" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 48 | ) |
| 49 | |
| 50 | const ( |
| 51 | // Flow categories |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 52 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 53 | //HsiaFlow flow category |
| 54 | HsiaFlow = "HSIA_FLOW" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 55 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 56 | //EapolFlow flow category |
| 57 | EapolFlow = "EAPOL_FLOW" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 58 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 59 | //DhcpFlow flow category |
| 60 | DhcpFlow = "DHCP_FLOW" |
| 61 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 62 | //MulticastFlow flow category |
| 63 | MulticastFlow = "MULTICAST_FLOW" |
| 64 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 65 | //IgmpFlow flow category |
| 66 | IgmpFlow = "IGMP_FLOW" |
| 67 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 68 | //IPProtoDhcp flow category |
| 69 | IPProtoDhcp = 17 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 70 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 71 | //IPProtoIgmp flow category |
| 72 | IPProtoIgmp = 2 |
| 73 | |
| 74 | //EapEthType eapethtype value |
| 75 | EapEthType = 0x888e |
| 76 | //LldpEthType lldp ethtype value |
| 77 | LldpEthType = 0x88cc |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 78 | //IPv4EthType IPv4 ethernet type value |
| 79 | IPv4EthType = 0x800 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 80 | |
| 81 | //IgmpProto proto value |
| 82 | IgmpProto = 2 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 83 | |
Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 84 | //ReservedVlan Transparent Vlan (Masked Vlan, VLAN_ANY in ONOS Flows) |
| 85 | ReservedVlan = 4096 |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 86 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 87 | //DefaultMgmtVlan default vlan value |
| 88 | DefaultMgmtVlan = 4091 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 89 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 90 | // Openolt Flow |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 91 | |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 92 | //Upstream constant |
| 93 | Upstream = "upstream" |
| 94 | //Downstream constant |
| 95 | Downstream = "downstream" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 96 | //Multicast constant |
| 97 | Multicast = "multicast" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 98 | //PacketTagType constant |
| 99 | PacketTagType = "pkt_tag_type" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 100 | //Untagged constant |
| 101 | Untagged = "untagged" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 102 | //SingleTag constant |
| 103 | SingleTag = "single_tag" |
| 104 | //DoubleTag constant |
| 105 | DoubleTag = "double_tag" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 106 | |
| 107 | // classifierInfo |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 108 | |
| 109 | //EthType constant |
| 110 | EthType = "eth_type" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 111 | //EthDst constant |
| 112 | EthDst = "eth_dst" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 113 | //TPID constant |
| 114 | TPID = "tpid" |
| 115 | //IPProto constant |
| 116 | IPProto = "ip_proto" |
| 117 | //InPort constant |
| 118 | InPort = "in_port" |
| 119 | //VlanVid constant |
| 120 | VlanVid = "vlan_vid" |
| 121 | //VlanPcp constant |
| 122 | VlanPcp = "vlan_pcp" |
| 123 | |
| 124 | //UDPDst constant |
| 125 | UDPDst = "udp_dst" |
| 126 | //UDPSrc constant |
| 127 | UDPSrc = "udp_src" |
| 128 | //Ipv4Dst constant |
| 129 | Ipv4Dst = "ipv4_dst" |
| 130 | //Ipv4Src constant |
| 131 | Ipv4Src = "ipv4_src" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 132 | //Metadata constant |
| 133 | Metadata = "metadata" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 134 | //TunnelID constant |
| 135 | TunnelID = "tunnel_id" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 136 | //Output constant |
| 137 | Output = "output" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 138 | //GroupID constant |
| 139 | GroupID = "group_id" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 140 | // Actions |
| 141 | |
| 142 | //PopVlan constant |
| 143 | PopVlan = "pop_vlan" |
| 144 | //PushVlan constant |
| 145 | PushVlan = "push_vlan" |
| 146 | //TrapToHost constant |
| 147 | TrapToHost = "trap_to_host" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 148 | //MaxMeterBand constant |
| 149 | MaxMeterBand = 2 |
| 150 | //VlanPCPMask contant |
| 151 | VlanPCPMask = 0xFF |
| 152 | //VlanvIDMask constant |
| 153 | VlanvIDMask = 0xFFF |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 154 | //IntfID constant |
| 155 | IntfID = "intfId" |
| 156 | //OnuID constant |
| 157 | OnuID = "onuId" |
| 158 | //UniID constant |
| 159 | UniID = "uniId" |
| 160 | //PortNo constant |
| 161 | PortNo = "portNo" |
| 162 | //AllocID constant |
| 163 | AllocID = "allocId" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 164 | |
| 165 | //NoneOnuID constant |
| 166 | NoneOnuID = -1 |
| 167 | //NoneUniID constant |
| 168 | NoneUniID = -1 |
| 169 | //NoneGemPortID constant |
| 170 | NoneGemPortID = -1 |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 171 | |
| 172 | // BinaryStringPrefix is binary string prefix |
| 173 | BinaryStringPrefix = "0b" |
| 174 | // BinaryBit1 is binary bit 1 expressed as a character |
| 175 | BinaryBit1 = '1' |
Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 176 | |
| 177 | // MapMutex |
| 178 | maxRetry = 300 |
| 179 | maxDelay = 100000000 |
| 180 | baseDelay = 10000000 |
| 181 | factor = 1.1 |
| 182 | jitter = 0.2 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 183 | ) |
| 184 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 185 | type gemPortKey struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 186 | intfID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 187 | gemPort uint32 |
| 188 | } |
| 189 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 190 | type pendingFlowDeleteKey struct { |
| 191 | intfID uint32 |
| 192 | onuID uint32 |
| 193 | uniID uint32 |
| 194 | } |
| 195 | |
| 196 | type tpLockKey struct { |
| 197 | intfID uint32 |
| 198 | onuID uint32 |
| 199 | uniID uint32 |
| 200 | } |
| 201 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 202 | type schedQueue struct { |
| 203 | direction tp_pb.Direction |
| 204 | intfID uint32 |
| 205 | onuID uint32 |
| 206 | uniID uint32 |
| 207 | tpID uint32 |
| 208 | uniPort uint32 |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 209 | tpInst interface{} |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 210 | meterID uint32 |
| 211 | flowMetadata *voltha.FlowMetadata |
| 212 | } |
| 213 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 214 | type queueInfoBrief struct { |
| 215 | gemPortID uint32 |
| 216 | servicePriority uint32 |
| 217 | } |
| 218 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 219 | //OpenOltFlowMgr creates the Structure of OpenOltFlowMgr obj |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 220 | type OpenOltFlowMgr struct { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 221 | techprofile map[uint32]tp.TechProfileIf |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 222 | deviceHandler *DeviceHandler |
| 223 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 224 | onuIdsLock sync.RWMutex |
Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 225 | perGemPortLock *mapmutex.Mutex // lock to be used to access the flowsUsedByGemPort map |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 226 | flowsUsedByGemPort map[gemPortKey][]uint32 //gem port id to flow ids |
| 227 | packetInGemPort map[rsrcMgr.PacketInInfoKey]uint32 //packet in gem port local cache |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 228 | // TODO create a type rsrcMgr.OnuGemInfos to be used instead of []rsrcMgr.OnuGemInfo |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 229 | onuGemInfo map[uint32][]rsrcMgr.OnuGemInfo //onu, gem and uni info local cache, indexed by IntfId |
| 230 | // We need to have a global lock on the onuGemInfo map |
| 231 | onuGemInfoLock sync.RWMutex |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 232 | pendingFlowDelete sync.Map |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 233 | // The mapmutex.Mutex can be fine tuned to use mapmutex.NewCustomizedMapMutex |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 234 | perUserFlowHandleLock *mapmutex.Mutex |
| 235 | interfaceToMcastQueueMap map[uint32]*queueInfoBrief /*pon interface -> multicast queue map. Required to assign GEM to a bucket during group population*/ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 236 | } |
| 237 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 238 | //NewFlowManager creates OpenOltFlowMgr object and initializes the parameters |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 239 | func NewFlowManager(ctx context.Context, dh *DeviceHandler, rMgr *rsrcMgr.OpenOltResourceMgr) *OpenOltFlowMgr { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 240 | logger.Infow(ctx, "initializing-flow-manager", log.Fields{"device-id": dh.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 241 | var flowMgr OpenOltFlowMgr |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 242 | var err error |
| 243 | var idx uint32 |
| 244 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 245 | flowMgr.deviceHandler = dh |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 246 | flowMgr.resourceMgr = rMgr |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 247 | flowMgr.techprofile = make(map[uint32]tp.TechProfileIf) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 248 | if err = flowMgr.populateTechProfilePerPonPort(ctx); err != nil { |
| 249 | logger.Errorw(ctx, "error-while-populating-tech-profile-mgr", log.Fields{"error": err}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 250 | return nil |
| 251 | } |
William Kurkian | 740a09c | 2019-10-23 17:07:38 -0400 | [diff] [blame] | 252 | flowMgr.onuIdsLock = sync.RWMutex{} |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 253 | flowMgr.flowsUsedByGemPort = make(map[gemPortKey][]uint32) |
| 254 | flowMgr.packetInGemPort = make(map[rsrcMgr.PacketInInfoKey]uint32) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 255 | ponPorts := rMgr.DevInfo.GetPonPorts() |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 256 | flowMgr.onuGemInfo = make(map[uint32][]rsrcMgr.OnuGemInfo, ponPorts) |
Girish Gowdra | 1183b4d | 2020-08-25 16:12:01 -0700 | [diff] [blame] | 257 | flowMgr.onuGemInfoLock = sync.RWMutex{} |
| 258 | flowMgr.pendingFlowDelete = sync.Map{} |
| 259 | flowMgr.perUserFlowHandleLock = mapmutex.NewCustomizedMapMutex(maxRetry, maxDelay, baseDelay, factor, jitter) |
| 260 | flowMgr.perGemPortLock = mapmutex.NewCustomizedMapMutex(maxRetry, maxDelay, baseDelay, factor, jitter) |
| 261 | flowMgr.interfaceToMcastQueueMap = make(map[uint32]*queueInfoBrief) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 262 | //Load the onugem info cache from kv store on flowmanager start |
| 263 | for idx = 0; idx < ponPorts; idx++ { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 264 | if flowMgr.onuGemInfo[idx], err = rMgr.GetOnuGemInfo(ctx, idx); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 265 | logger.Error(ctx, "failed-to-load-onu-gem-info-cache") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 266 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 267 | //Load flowID list per gem map per interface from the kvstore. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 268 | flowMgr.loadFlowIDlistForGem(ctx, idx) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 269 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 270 | //load interface to multicast queue map from kv store |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 271 | flowMgr.loadInterfaceToMulticastQueueMap(ctx) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 272 | logger.Info(ctx, "initialization-of-flow-manager-success") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 273 | return &flowMgr |
| 274 | } |
| 275 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 276 | func (f *OpenOltFlowMgr) registerFlow(ctx context.Context, flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 277 | gemPK := gemPortKey{uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId)} |
Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 278 | if f.perGemPortLock.TryLock(gemPK) { |
| 279 | logger.Debugw(ctx, "registering-flow-for-device ", |
| 280 | log.Fields{ |
| 281 | "flow": flowFromCore, |
| 282 | "device-id": f.deviceHandler.device.Id}) |
| 283 | flowIDList, ok := f.flowsUsedByGemPort[gemPK] |
| 284 | if !ok { |
| 285 | flowIDList = []uint32{deviceFlow.FlowId} |
| 286 | } |
| 287 | flowIDList = appendUnique(flowIDList, deviceFlow.FlowId) |
| 288 | f.flowsUsedByGemPort[gemPK] = flowIDList |
| 289 | |
| 290 | f.perGemPortLock.Unlock(gemPK) |
| 291 | |
| 292 | // update the flowids for a gem to the KVstore |
| 293 | return f.resourceMgr.UpdateFlowIDsForGem(ctx, uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId), flowIDList) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 294 | } |
Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 295 | logger.Error(ctx, "failed-to-acquire-per-gem-port-lock", |
| 296 | log.Fields{ |
| 297 | "flow-from-core": flowFromCore, |
| 298 | "device-id": f.deviceHandler.device.Id, |
| 299 | "key": gemPK, |
| 300 | }) |
| 301 | return olterrors.NewErrAdapter("failed-to-acquire-per-gem-port-lock", log.Fields{ |
| 302 | "flow-from-core": flowFromCore, |
| 303 | "device-id": f.deviceHandler.device.Id, |
| 304 | "key": gemPK, |
| 305 | }, nil) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 306 | } |
| 307 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 308 | func (f *OpenOltFlowMgr) divideAndAddFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 309 | classifierInfo map[string]interface{}, actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpID uint32, |
Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 310 | UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) error { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 311 | var allocID uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 312 | var gemPorts []uint32 |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 313 | var TpInst interface{} |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 314 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 315 | logger.Infow(ctx, "dividing-flow", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 316 | "device-id": f.deviceHandler.device.Id, |
| 317 | "intf-id": intfID, |
| 318 | "onu-id": onuID, |
| 319 | "uni-id": uniID, |
| 320 | "port-no": portNo, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 321 | "classifier": classifierInfo, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 322 | "action": actionInfo, |
| 323 | "usmeter-iD": UsMeterID, |
| 324 | "dsmeter-iD": DsMeterID, |
| 325 | "tp-id": TpID}) |
Matt Jeanneret | 7719961 | 2019-07-26 18:08:35 -0400 | [diff] [blame] | 326 | // only create tcont/gemports if there is actually an onu id. otherwise BAL throws an error. Usually this |
| 327 | // is because the flow is an NNI flow and there would be no onu resources associated with it |
| 328 | // TODO: properly deal with NNI flows |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 329 | if onuID == 0 { |
Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 330 | cause := "no-onu-id-for-flow" |
| 331 | fields := log.Fields{ |
| 332 | "onu": onuID, |
| 333 | "port-no": portNo, |
| 334 | "classifer": classifierInfo, |
| 335 | "action": actionInfo, |
| 336 | "device-id": f.deviceHandler.device.Id} |
| 337 | logger.Errorw(ctx, cause, fields) |
| 338 | return olterrors.NewErrNotFound(cause, fields, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 339 | } |
| 340 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 341 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 342 | logger.Debugw(ctx, "uni-port-path", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 343 | "uni": uni, |
| 344 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 345 | |
| 346 | tpLockMapKey := tpLockKey{intfID, onuID, uniID} |
| 347 | if f.perUserFlowHandleLock.TryLock(tpLockMapKey) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 348 | logger.Debugw(ctx, "dividing-flow-create-tcont-gem-ports", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 349 | "device-id": f.deviceHandler.device.Id, |
| 350 | "intf-id": intfID, |
| 351 | "onu-id": onuID, |
| 352 | "uni-id": uniID, |
| 353 | "port-no": portNo, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 354 | "classifier": classifierInfo, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 355 | "action": actionInfo, |
| 356 | "usmeter-id": UsMeterID, |
| 357 | "dsmeter-id": DsMeterID, |
| 358 | "tp-id": TpID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 359 | allocID, gemPorts, TpInst = f.createTcontGemports(ctx, intfID, onuID, uniID, uni, portNo, TpID, UsMeterID, DsMeterID, flowMetadata) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 360 | if allocID == 0 || gemPorts == nil || TpInst == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 361 | logger.Error(ctx, "alloc-id-gem-ports-tp-unavailable") |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 362 | f.perUserFlowHandleLock.Unlock(tpLockMapKey) |
Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 363 | return olterrors.NewErrNotFound( |
| 364 | "alloc-id-gem-ports-tp-unavailable", |
| 365 | nil, nil) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 366 | } |
| 367 | args := make(map[string]uint32) |
| 368 | args[IntfID] = intfID |
| 369 | args[OnuID] = onuID |
| 370 | args[UniID] = uniID |
| 371 | args[PortNo] = portNo |
| 372 | args[AllocID] = allocID |
| 373 | |
| 374 | /* Flows can be added specific to gemport if p-bits are received. |
| 375 | * If no pbit mentioned then adding flows for all gemports |
| 376 | */ |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 377 | f.checkAndAddFlow(ctx, args, classifierInfo, actionInfo, flow, TpInst, gemPorts, TpID, uni) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 378 | f.perUserFlowHandleLock.Unlock(tpLockMapKey) |
| 379 | } else { |
Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 380 | cause := "failed-to-acquire-per-user-flow-handle-lock" |
| 381 | fields := log.Fields{ |
| 382 | "intf-id": intfID, |
| 383 | "onu-id": onuID, |
| 384 | "uni-id": uniID, |
| 385 | "flow-id": flow.Id, |
| 386 | "flow-cookie": flow.Cookie, |
| 387 | "device-id": f.deviceHandler.device.Id} |
| 388 | logger.Errorw(ctx, cause, fields) |
| 389 | return olterrors.NewErrAdapter(cause, fields, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 390 | } |
Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 391 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 392 | } |
| 393 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 394 | // CreateSchedulerQueues creates traffic schedulers on the device with the given scheduler configuration and traffic shaping info |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 395 | func (f *OpenOltFlowMgr) CreateSchedulerQueues(ctx context.Context, sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 396 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 397 | logger.Debugw(ctx, "CreateSchedulerQueues", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 398 | log.Fields{"dir": sq.direction, |
| 399 | "intf-id": sq.intfID, |
| 400 | "onu-id": sq.onuID, |
| 401 | "uni-id": sq.uniID, |
| 402 | "tp-id": sq.tpID, |
| 403 | "meter-id": sq.meterID, |
| 404 | "tp-inst": sq.tpInst, |
| 405 | "flowmetadata": sq.flowMetadata, |
| 406 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 407 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 408 | Direction, err := verifyMeterIDAndGetDirection(sq.meterID, sq.direction) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 409 | if err != nil { |
| 410 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* Lets make a simple assumption that if the meter-id is present on the KV store, |
| 414 | * then the scheduler and queues configuration is applied on the OLT device |
| 415 | * in the given direction. |
| 416 | */ |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 417 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 418 | var SchedCfg *tp_pb.SchedulerConfig |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 419 | KvStoreMeter, err := f.resourceMgr.GetMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 420 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 421 | return olterrors.NewErrNotFound("meter", |
| 422 | log.Fields{"intf-id": sq.intfID, |
| 423 | "onu-id": sq.onuID, |
| 424 | "uni-id": sq.uniID, |
| 425 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 426 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 427 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 428 | if KvStoreMeter != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 429 | if KvStoreMeter.MeterId == sq.meterID { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 430 | logger.Debugw(ctx, "scheduler-already-created-for-upstream", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 431 | return nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 432 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 433 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 434 | "unsupported": "meter-id", |
| 435 | "kv-store-meter-id": KvStoreMeter.MeterId, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 436 | "meter-id-in-flow": sq.meterID, |
| 437 | "device-id": f.deviceHandler.device.Id}, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 438 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 439 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 440 | logger.Debugw(ctx, "meter-does-not-exist-creating-new", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 441 | log.Fields{ |
| 442 | "meter-id": sq.meterID, |
| 443 | "direction": Direction, |
| 444 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 445 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 446 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 447 | SchedCfg, err = f.techprofile[sq.intfID].GetUsScheduler(ctx, sq.tpInst.(*tp.TechProfile)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 448 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 449 | SchedCfg, err = f.techprofile[sq.intfID].GetDsScheduler(ctx, sq.tpInst.(*tp.TechProfile)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 450 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 451 | |
| 452 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 453 | return olterrors.NewErrNotFound("scheduler-config", |
| 454 | log.Fields{ |
| 455 | "intf-id": sq.intfID, |
| 456 | "direction": sq.direction, |
| 457 | "tp-inst": sq.tpInst, |
| 458 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 461 | var meterConfig *ofp.OfpMeterConfig |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 462 | if sq.flowMetadata != nil { |
| 463 | for _, meter := range sq.flowMetadata.Meters { |
| 464 | if sq.meterID == meter.MeterId { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 465 | meterConfig = meter |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 466 | logger.Debugw(ctx, "found-meter-config-from-flowmetadata", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 467 | log.Fields{"meterConfig": meterConfig, |
| 468 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 469 | break |
| 470 | } |
| 471 | } |
| 472 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 473 | logger.Errorw(ctx, "flow-metadata-not-present-in-flow", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 474 | } |
| 475 | if meterConfig == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 476 | return olterrors.NewErrNotFound("meterbands", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 477 | "reason": "Could-not-get-meterbands-from-flowMetadata", |
| 478 | "flow-metadata": sq.flowMetadata, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 479 | "meter-id": sq.meterID, |
| 480 | "device-id": f.deviceHandler.device.Id}, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 481 | } else if len(meterConfig.Bands) < MaxMeterBand { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 482 | logger.Errorw(ctx, "invalid-number-of-bands-in-meter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 483 | log.Fields{"Bands": meterConfig.Bands, |
| 484 | "meter-id": sq.meterID, |
| 485 | "device-id": f.deviceHandler.device.Id}) |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 486 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 487 | "reason": "Invalid-number-of-bands-in-meter", |
| 488 | "meterband-count": len(meterConfig.Bands), |
| 489 | "metabands": meterConfig.Bands, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 490 | "meter-id": sq.meterID, |
| 491 | "device-id": f.deviceHandler.device.Id}, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 492 | } |
| 493 | cir := meterConfig.Bands[0].Rate |
| 494 | cbs := meterConfig.Bands[0].BurstSize |
| 495 | eir := meterConfig.Bands[1].Rate |
| 496 | ebs := meterConfig.Bands[1].BurstSize |
| 497 | pir := cir + eir |
| 498 | pbs := cbs + ebs |
| 499 | TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: cir, Cbs: cbs, Pir: pir, Pbs: pbs} |
| 500 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 501 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile[sq.intfID].GetTrafficScheduler(sq.tpInst.(*tp.TechProfile), SchedCfg, TrafficShaping)} |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 502 | TrafficSched[0].TechProfileId = sq.tpID |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 503 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 504 | if err := f.pushSchedulerQueuesToDevice(ctx, sq, TrafficShaping, TrafficSched); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 505 | return olterrors.NewErrAdapter("failure-pushing-traffic-scheduler-and-queues-to-device", |
| 506 | log.Fields{"intf-id": sq.intfID, |
| 507 | "direction": sq.direction, |
| 508 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 509 | } |
| 510 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 511 | /* After we successfully applied the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 512 | * store the meter id on the KV store, for further reference. |
| 513 | */ |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 514 | if err := f.resourceMgr.UpdateMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID, meterConfig); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 515 | return olterrors.NewErrAdapter("failed-updating-meter-id", |
| 516 | log.Fields{"onu-id": sq.onuID, |
| 517 | "meter-id": sq.meterID, |
| 518 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 519 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 520 | logger.Infow(ctx, "updated-meter-info-into-kv-store-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 521 | log.Fields{"direction": Direction, |
| 522 | "Meter": meterConfig, |
| 523 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 524 | return nil |
| 525 | } |
| 526 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 527 | func (f *OpenOltFlowMgr) pushSchedulerQueuesToDevice(ctx context.Context, sq schedQueue, TrafficShaping *tp_pb.TrafficShapingInfo, TrafficSched []*tp_pb.TrafficScheduler) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 528 | trafficQueues, err := f.techprofile[sq.intfID].GetTrafficQueues(ctx, sq.tpInst.(*tp.TechProfile), sq.direction) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 529 | |
| 530 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 531 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 532 | log.Fields{"intf-id": sq.intfID, |
| 533 | "direction": sq.direction, |
| 534 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 537 | logger.Debugw(ctx, "sending-traffic-scheduler-create-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 538 | log.Fields{ |
| 539 | "direction": sq.direction, |
| 540 | "TrafficScheds": TrafficSched, |
| 541 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 542 | if _, err := f.deviceHandler.Client.CreateTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 543 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 544 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 545 | TrafficScheds: TrafficSched}); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 546 | return olterrors.NewErrAdapter("failed-to-create-traffic-schedulers-in-device", log.Fields{"TrafficScheds": TrafficSched}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 547 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 548 | logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 549 | "direction": sq.direction, |
| 550 | "traffic-queues": trafficQueues, |
| 551 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 552 | |
| 553 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 554 | // downstream queues. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 555 | logger.Debugw(ctx, "sending-traffic-queues-create-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 556 | log.Fields{"direction": sq.direction, |
| 557 | "traffic-queues": trafficQueues, |
| 558 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 559 | if _, err := f.deviceHandler.Client.CreateTrafficQueues(ctx, |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 560 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 561 | UniId: sq.uniID, PortNo: sq.uniPort, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 562 | TrafficQueues: trafficQueues, |
| 563 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 564 | return olterrors.NewErrAdapter("failed-to-create-traffic-queues-in-device", log.Fields{"traffic-queues": trafficQueues}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 565 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 566 | logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 567 | "direction": sq.direction, |
| 568 | "traffic-queues": trafficQueues, |
| 569 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 570 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 571 | if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 572 | multicastTrafficQueues := f.techprofile[sq.intfID].GetMulticastTrafficQueues(ctx, sq.tpInst.(*tp.TechProfile)) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 573 | if len(multicastTrafficQueues) > 0 { |
| 574 | if _, present := f.interfaceToMcastQueueMap[sq.intfID]; !present { |
| 575 | //assumed that there is only one queue per PON for the multicast service |
| 576 | //the default queue with multicastQueuePerPonPort.Priority per a pon interface is used for multicast service |
| 577 | //just put it in interfaceToMcastQueueMap to use for building group members |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 578 | logger.Debugw(ctx, "multicast-traffic-queues", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 579 | multicastQueuePerPonPort := multicastTrafficQueues[0] |
| 580 | f.interfaceToMcastQueueMap[sq.intfID] = &queueInfoBrief{ |
| 581 | gemPortID: multicastQueuePerPonPort.GemportId, |
| 582 | servicePriority: multicastQueuePerPonPort.Priority, |
| 583 | } |
| 584 | //also store the queue info in kv store |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 585 | if err := f.resourceMgr.AddMcastQueueForIntf(ctx, sq.intfID, multicastQueuePerPonPort.GemportId, multicastQueuePerPonPort.Priority); err != nil { |
| 586 | logger.Errorw(ctx, "failed-to-add-mcast-queue", log.Fields{"error": err}) |
| 587 | return err |
| 588 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 589 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 590 | logger.Infow(ctx, "multicast-queues-successfully-updated", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 594 | return nil |
| 595 | } |
| 596 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 597 | // RemoveSchedulerQueues removes the traffic schedulers from the device based on the given scheduler configuration and traffic shaping info |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 598 | func (f *OpenOltFlowMgr) RemoveSchedulerQueues(ctx context.Context, sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 599 | |
| 600 | var Direction string |
| 601 | var SchedCfg *tp_pb.SchedulerConfig |
| 602 | var err error |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 603 | logger.Infow(ctx, "removing-schedulers-and-queues-in-olt", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 604 | log.Fields{ |
| 605 | "direction": sq.direction, |
| 606 | "intf-id": sq.intfID, |
| 607 | "onu-id": sq.onuID, |
| 608 | "uni-id": sq.uniID, |
| 609 | "uni-port": sq.uniPort, |
| 610 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 611 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 612 | SchedCfg, err = f.techprofile[sq.intfID].GetUsScheduler(ctx, sq.tpInst.(*tp.TechProfile)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 613 | Direction = "upstream" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 614 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 615 | SchedCfg, err = f.techprofile[sq.intfID].GetDsScheduler(ctx, sq.tpInst.(*tp.TechProfile)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 616 | Direction = "downstream" |
| 617 | } |
| 618 | |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 619 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 620 | return olterrors.NewErrNotFound("scheduler-config", |
| 621 | log.Fields{ |
| 622 | "int-id": sq.intfID, |
| 623 | "direction": sq.direction, |
| 624 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 625 | } |
| 626 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 627 | KVStoreMeter, err := f.resourceMgr.GetMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 628 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 629 | return olterrors.NewErrNotFound("meter", |
| 630 | log.Fields{ |
| 631 | "onu-id": sq.onuID, |
| 632 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 633 | } |
| 634 | if KVStoreMeter == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 635 | logger.Warnw(ctx, "no-meter-installed-yet", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 636 | log.Fields{ |
| 637 | "direction": Direction, |
| 638 | "intf-id": sq.intfID, |
| 639 | "onu-id": sq.onuID, |
| 640 | "uni-id": sq.uniID, |
| 641 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 642 | return nil |
| 643 | } |
| 644 | cir := KVStoreMeter.Bands[0].Rate |
| 645 | cbs := KVStoreMeter.Bands[0].BurstSize |
| 646 | eir := KVStoreMeter.Bands[1].Rate |
| 647 | ebs := KVStoreMeter.Bands[1].BurstSize |
| 648 | pir := cir + eir |
| 649 | pbs := cbs + ebs |
| 650 | |
| 651 | TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: cir, Cbs: cbs, Pir: pir, Pbs: pbs} |
| 652 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 653 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile[sq.intfID].GetTrafficScheduler(sq.tpInst.(*tp.TechProfile), SchedCfg, TrafficShaping)} |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 654 | TrafficSched[0].TechProfileId = sq.tpID |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 655 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 656 | TrafficQueues, err := f.techprofile[sq.intfID].GetTrafficQueues(ctx, sq.tpInst.(*tp.TechProfile), sq.direction) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 657 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 658 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 659 | log.Fields{ |
| 660 | "intf-id": sq.intfID, |
| 661 | "direction": sq.direction, |
| 662 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 663 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 664 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 665 | if _, err = f.deviceHandler.Client.RemoveTrafficQueues(ctx, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 666 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 667 | UniId: sq.uniID, PortNo: sq.uniPort, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 668 | TrafficQueues: TrafficQueues, |
| 669 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 670 | return olterrors.NewErrAdapter("unable-to-remove-traffic-queues-from-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 671 | log.Fields{ |
| 672 | "intf-id": sq.intfID, |
| 673 | "traffic-queues": TrafficQueues, |
| 674 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 675 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 676 | logger.Infow(ctx, "removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 677 | if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 678 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 679 | UniId: sq.uniID, PortNo: sq.uniPort, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 680 | TrafficScheds: TrafficSched}); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 681 | return olterrors.NewErrAdapter("unable-to-remove-traffic-schedulers-from-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 682 | log.Fields{ |
| 683 | "intf-id": sq.intfID, |
| 684 | "traffic-schedulers": TrafficSched}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 685 | } |
| 686 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 687 | logger.Infow(ctx, "removed-traffic-schedulers-successfully", log.Fields{"device-id": f.deviceHandler.device.Id}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 688 | |
| 689 | /* After we successfully remove the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 690 | * delete the meter id on the KV store. |
| 691 | */ |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 692 | err = f.resourceMgr.RemoveMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 693 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 694 | return olterrors.NewErrAdapter("unable-to-remove-meter", |
| 695 | log.Fields{ |
| 696 | "onu": sq.onuID, |
| 697 | "meter": KVStoreMeter.MeterId, |
| 698 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 699 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 700 | logger.Infow(ctx, "removed-meter-from-KV-store-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 701 | log.Fields{ |
| 702 | "meter-id": KVStoreMeter.MeterId, |
| 703 | "dir": Direction, |
| 704 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 705 | return err |
| 706 | } |
| 707 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 708 | // This function allocates tconts and GEM ports for an ONU |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 709 | func (f *OpenOltFlowMgr) createTcontGemports(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uni string, uniPort uint32, TpID uint32, UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) (uint32, []uint32, interface{}) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 710 | var allocIDs []uint32 |
| 711 | var allgemPortIDs []uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 712 | var gemPortIDs []uint32 |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 713 | tpInstanceExists := false |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 714 | var err error |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 715 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 716 | allocIDs = f.resourceMgr.GetCurrentAllocIDsForOnu(ctx, intfID, onuID, uniID) |
| 717 | allgemPortIDs = f.resourceMgr.GetCurrentGEMPortIDsForOnu(ctx, intfID, onuID, uniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 718 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 719 | tpPath := f.getTPpath(ctx, intfID, uni, TpID) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 720 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 721 | logger.Debugw(ctx, "creating-new-tcont-and-gem", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 722 | "intf-id": intfID, |
| 723 | "onu-id": onuID, |
| 724 | "uni-id": uniID, |
| 725 | "device-id": f.deviceHandler.device.Id, |
| 726 | "tp-id": TpID}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 727 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 728 | // Check tech profile instance already exists for derived port name |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 729 | techProfileInstance, _ := f.techprofile[intfID].GetTPInstanceFromKVStore(ctx, TpID, tpPath) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 730 | if techProfileInstance == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 731 | logger.Infow(ctx, "tp-instance-not-found--creating-new", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 732 | log.Fields{ |
| 733 | "path": tpPath, |
| 734 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 735 | techProfileInstance, err = f.techprofile[intfID].CreateTechProfInstance(ctx, TpID, uni, intfID) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 736 | if err != nil { |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 737 | // This should not happen, something wrong in KV backend transaction |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 738 | logger.Errorw(ctx, "tp-instance-create-failed", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 739 | log.Fields{ |
| 740 | "error": err, |
| 741 | "tp-id": TpID, |
| 742 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 743 | return 0, nil, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 744 | } |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 745 | if err := f.resourceMgr.UpdateTechProfileIDForOnu(ctx, intfID, onuID, uniID, TpID); err != nil { |
| 746 | logger.Warnw(ctx, "failed-to-update-tech-profile-id", log.Fields{"error": err}) |
| 747 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 748 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 749 | logger.Debugw(ctx, "tech-profile-instance-already-exist-for-given port-name", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 750 | log.Fields{ |
| 751 | "uni": uni, |
| 752 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 753 | tpInstanceExists = true |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 754 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 755 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 756 | switch tpInst := techProfileInstance.(type) { |
| 757 | case *tp.TechProfile: |
| 758 | if UsMeterID != 0 { |
| 759 | sq := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 760 | uniPort: uniPort, tpInst: techProfileInstance, meterID: UsMeterID, flowMetadata: flowMetadata} |
| 761 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 762 | logger.Errorw(ctx, "CreateSchedulerQueues-failed-upstream", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 763 | log.Fields{ |
| 764 | "error": err, |
| 765 | "meter-id": UsMeterID, |
| 766 | "device-id": f.deviceHandler.device.Id}) |
| 767 | return 0, nil, nil |
| 768 | } |
| 769 | } |
| 770 | if DsMeterID != 0 { |
| 771 | sq := schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 772 | uniPort: uniPort, tpInst: techProfileInstance, meterID: DsMeterID, flowMetadata: flowMetadata} |
| 773 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 774 | logger.Errorw(ctx, "CreateSchedulerQueues-failed-downstream", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 775 | log.Fields{ |
| 776 | "error": err, |
| 777 | "meter-id": DsMeterID, |
| 778 | "device-id": f.deviceHandler.device.Id}) |
| 779 | return 0, nil, nil |
| 780 | } |
| 781 | } |
| 782 | allocID := tpInst.UsScheduler.AllocID |
| 783 | for _, gem := range tpInst.UpstreamGemPortAttributeList { |
| 784 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 785 | } |
| 786 | allocIDs = appendUnique(allocIDs, allocID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 787 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 788 | if tpInstanceExists { |
| 789 | return allocID, gemPortIDs, techProfileInstance |
| 790 | } |
| 791 | |
| 792 | for _, gemPortID := range gemPortIDs { |
| 793 | allgemPortIDs = appendUnique(allgemPortIDs, gemPortID) |
| 794 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 795 | logger.Infow(ctx, "allocated-tcont-and-gem-ports", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 796 | log.Fields{ |
| 797 | "alloc-ids": allocIDs, |
| 798 | "gemports": allgemPortIDs, |
| 799 | "device-id": f.deviceHandler.device.Id}) |
| 800 | // Send Tconts and GEM ports to KV store |
| 801 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 802 | return allocID, gemPortIDs, techProfileInstance |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 803 | case *tp.EponProfile: |
| 804 | // CreateSchedulerQueues for EPON needs to be implemented here |
| 805 | // when voltha-protos for EPON is completed. |
| 806 | allocID := tpInst.AllocID |
| 807 | for _, gem := range tpInst.UpstreamQueueAttributeList { |
| 808 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 809 | } |
| 810 | allocIDs = appendUnique(allocIDs, allocID) |
| 811 | |
| 812 | if tpInstanceExists { |
| 813 | return allocID, gemPortIDs, techProfileInstance |
| 814 | } |
| 815 | |
| 816 | for _, gemPortID := range gemPortIDs { |
| 817 | allgemPortIDs = appendUnique(allgemPortIDs, gemPortID) |
| 818 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 819 | logger.Infow(ctx, "allocated-tcont-and-gem-ports", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 820 | log.Fields{ |
| 821 | "alloc-ids": allocIDs, |
| 822 | "gemports": allgemPortIDs, |
| 823 | "device-id": f.deviceHandler.device.Id}) |
| 824 | // Send Tconts and GEM ports to KV store |
| 825 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
| 826 | return allocID, gemPortIDs, techProfileInstance |
| 827 | default: |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 828 | logger.Errorw(ctx, "unknown-tech", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 829 | log.Fields{ |
| 830 | "tpInst": tpInst}) |
| 831 | return 0, nil, nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 832 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 833 | } |
| 834 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 835 | func (f *OpenOltFlowMgr) storeTcontsGEMPortsIntoKVStore(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID []uint32, gemPortIDs []uint32) { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 836 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 837 | logger.Debugw(ctx, "storing-allocated-tconts-and-gem-ports-into-KV-store", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 838 | log.Fields{ |
| 839 | "intf-id": intfID, |
| 840 | "onu-id": onuID, |
| 841 | "uni-id": uniID, |
| 842 | "alloc-id": allocID, |
| 843 | "gemport-ids": gemPortIDs, |
| 844 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 845 | /* Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store */ |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 846 | if err := f.resourceMgr.UpdateAllocIdsForOnu(ctx, intfID, onuID, uniID, allocID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 847 | logger.Errorw(ctx, "error-while-uploading-allocid-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 848 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 849 | if err := f.resourceMgr.UpdateGEMPortIDsForOnu(ctx, intfID, onuID, uniID, gemPortIDs); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 850 | logger.Errorw(ctx, "error-while-uploading-gemports-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 851 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 852 | if err := f.resourceMgr.UpdateGEMportsPonportToOnuMapOnKVStore(ctx, gemPortIDs, intfID, onuID, uniID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 853 | logger.Error(ctx, "error-while-uploading-gemtopon-map-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 854 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 855 | logger.Infow(ctx, "stored-tconts-and-gem-into-kv-store-successfully", log.Fields{"device-id": f.deviceHandler.device.Id}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 856 | for _, gemPort := range gemPortIDs { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 857 | f.addGemPortToOnuInfoMap(ctx, intfID, onuID, gemPort) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 858 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 859 | } |
| 860 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 861 | func (f *OpenOltFlowMgr) populateTechProfilePerPonPort(ctx context.Context) error { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 862 | var tpCount int |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 863 | for _, techRange := range f.resourceMgr.DevInfo.Ranges { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 864 | for _, intfID := range techRange.IntfIds { |
| 865 | f.techprofile[intfID] = f.resourceMgr.ResourceMgrs[uint32(intfID)].TechProfileMgr |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 866 | tpCount++ |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 867 | logger.Debugw(ctx, "init-tech-profile-done", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 868 | log.Fields{ |
| 869 | "intf-id": intfID, |
| 870 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | //Make sure we have as many tech_profiles as there are pon ports on the device |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 874 | if tpCount != int(f.resourceMgr.DevInfo.GetPonPorts()) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 875 | return olterrors.NewErrInvalidValue(log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 876 | "reason": "tP-count-does-not-match-number-of-pon-ports", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 877 | "tech-profile-count": tpCount, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 878 | "pon-port-count": f.resourceMgr.DevInfo.GetPonPorts(), |
| 879 | "device-id": f.deviceHandler.device.Id}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 880 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 881 | logger.Infow(ctx, "populated-techprofile-for-ponports-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 882 | log.Fields{ |
| 883 | "numofTech": tpCount, |
| 884 | "numPonPorts": f.resourceMgr.DevInfo.GetPonPorts(), |
| 885 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 886 | return nil |
| 887 | } |
| 888 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 889 | func (f *OpenOltFlowMgr) addUpstreamDataFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 890 | portNo uint32, uplinkClassifier map[string]interface{}, |
| 891 | uplinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 892 | allocID uint32, gemportID uint32, tpID uint32) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 893 | uplinkClassifier[PacketTagType] = SingleTag |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 894 | logger.Debugw(ctx, "adding-upstream-data-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 895 | log.Fields{ |
| 896 | "uplinkClassifier": uplinkClassifier, |
| 897 | "uplinkAction": uplinkAction}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 898 | return f.addHSIAFlow(ctx, intfID, onuID, uniID, portNo, uplinkClassifier, uplinkAction, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 899 | Upstream, logicalFlow, allocID, gemportID, tpID) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 900 | /* TODO: Install Secondary EAP on the subscriber vlan */ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 901 | } |
| 902 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 903 | func (f *OpenOltFlowMgr) addDownstreamDataFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 904 | portNo uint32, downlinkClassifier map[string]interface{}, |
| 905 | downlinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 906 | allocID uint32, gemportID uint32, tpID uint32) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 907 | downlinkClassifier[PacketTagType] = DoubleTag |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 908 | logger.Debugw(ctx, "adding-downstream-data-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 909 | log.Fields{ |
| 910 | "downlinkClassifier": downlinkClassifier, |
| 911 | "downlinkAction": downlinkAction}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 912 | // Ignore Downlink trap flow given by core, cannot do anything with this flow */ |
| 913 | if vlan, exists := downlinkClassifier[VlanVid]; exists { |
| 914 | if vlan.(uint32) == (uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000) { //private VLAN given by core |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 915 | if metadata, exists := downlinkClassifier[Metadata]; exists { // inport is filled in metadata by core |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 916 | if uint32(metadata.(uint64)) == MkUniPortNum(ctx, intfID, onuID, uniID) { |
| 917 | logger.Infow(ctx, "ignoring-dl-trap-device-flow-from-core", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 918 | log.Fields{ |
| 919 | "flow": logicalFlow, |
| 920 | "device-id": f.deviceHandler.device.Id, |
| 921 | "onu-id": onuID, |
| 922 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 923 | return nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 924 | } |
| 925 | } |
| 926 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 927 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 928 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 929 | /* Already this info available classifier? */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 930 | downlinkAction[PopVlan] = true |
Matt Jeanneret | ed16b7c | 2019-11-01 13:31:35 -0400 | [diff] [blame] | 931 | // vlan_vid is a uint32. must be type asserted as such or conversion fails |
| 932 | dlClVid, ok := downlinkClassifier[VlanVid].(uint32) |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 933 | if ok { |
| 934 | downlinkAction[VlanVid] = dlClVid & 0xfff |
| 935 | } else { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 936 | return olterrors.NewErrInvalidValue(log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 937 | "reason": "failed-to-convert-vlanid-classifier", |
| 938 | "vlan-id": VlanVid, |
| 939 | "device-id": f.deviceHandler.device.Id}, nil).Log() |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 940 | } |
| 941 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 942 | return f.addHSIAFlow(ctx, intfID, onuID, uniID, portNo, downlinkClassifier, downlinkAction, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 943 | Downstream, logicalFlow, allocID, gemportID, tpID) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 944 | } |
| 945 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 946 | func (f *OpenOltFlowMgr) addHSIAFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{}, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 947 | action map[string]interface{}, direction string, logicalFlow *ofp.OfpFlowStats, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 948 | allocID uint32, gemPortID uint32, tpID uint32) error { |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 949 | /* One of the OLT platform (Broadcom BAL) requires that symmetric |
| 950 | flows require the same flow_id to be used across UL and DL. |
| 951 | Since HSIA flow is the only symmetric flow currently, we need to |
| 952 | re-use the flow_id across both direction. The 'flow_category' |
| 953 | takes priority over flow_cookie to find any available HSIA_FLOW |
| 954 | id for the ONU. |
| 955 | */ |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 956 | logger.Infow(ctx, "adding-hsia-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 957 | log.Fields{ |
| 958 | "intf-id": intfID, |
| 959 | "onu-id": onuID, |
| 960 | "uni-id": uniID, |
| 961 | "device-id": f.deviceHandler.device.Id, |
| 962 | "classifier": classifier, |
| 963 | "action": action, |
| 964 | "direction": direction, |
| 965 | "alloc-id": allocID, |
| 966 | "gemport-id": gemPortID, |
| 967 | "logicalflow": *logicalFlow}) |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 968 | var vlanPbit uint32 = 0xff // means no pbit |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 969 | var vlanVid uint32 |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 970 | if _, ok := classifier[VlanPcp]; ok { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 971 | vlanPbit = classifier[VlanPcp].(uint32) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 972 | logger.Debugw(ctx, "found-pbit-in-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 973 | log.Fields{ |
| 974 | "vlan-pbit": vlanPbit, |
| 975 | "intf-id": intfID, |
| 976 | "onu-id": onuID, |
| 977 | "device-id": f.deviceHandler.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 978 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 979 | logger.Debugw(ctx, "pbit-not-found-in-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 980 | log.Fields{ |
| 981 | "vlan-pcp": VlanPcp, |
| 982 | "intf-id": intfID, |
| 983 | "onu-id": onuID, |
| 984 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 985 | } |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 986 | if _, ok := classifier[VlanVid]; ok { |
| 987 | vlanVid = classifier[VlanVid].(uint32) |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 988 | logger.Debugw(ctx, "found-vlan-in-the-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 989 | log.Fields{ |
| 990 | "vlan-vid": vlanVid, |
| 991 | "intf-id": intfID, |
| 992 | "onu-id": onuID, |
| 993 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 994 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 995 | flowStoreCookie := getFlowStoreCookie(ctx, classifier, gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 996 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 997 | logger.Infow(ctx, "flow-already-exists", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 998 | log.Fields{ |
| 999 | "device-id": f.deviceHandler.device.Id, |
| 1000 | "intf-id": intfID, |
| 1001 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1002 | return nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1003 | } |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1004 | flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, HsiaFlow, vlanVid, vlanPbit) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1005 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1006 | return olterrors.NewErrNotFound("hsia-flow-id", |
| 1007 | log.Fields{ |
| 1008 | "direction": direction, |
| 1009 | "device-id": f.deviceHandler.device.Id, |
| 1010 | "intf-id": intfID, |
| 1011 | "onu-id": onuID, |
| 1012 | }, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1013 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1014 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1015 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1016 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier, "device-id": f.deviceHandler.device.Id}, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1017 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1018 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1019 | log.Fields{ |
| 1020 | "classifier": *classifierProto, |
| 1021 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1022 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1023 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1024 | return olterrors.NewErrInvalidValue(log.Fields{"action": action, "device-id": f.deviceHandler.device.Id}, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1025 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1026 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1027 | log.Fields{ |
| 1028 | "action": *actionProto, |
| 1029 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1030 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1031 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1032 | return olterrors.NewErrNotFound("nni-interface-id", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1033 | log.Fields{ |
| 1034 | "classifier": classifier, |
| 1035 | "action": action, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1036 | "device-id": f.deviceHandler.device.Id, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1037 | }, err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1038 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1039 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
| 1040 | OnuId: int32(onuID), |
| 1041 | UniId: int32(uniID), |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1042 | FlowId: flowID, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1043 | FlowType: direction, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1044 | AllocId: int32(allocID), |
| 1045 | NetworkIntfId: int32(networkIntfID), |
| 1046 | GemportId: int32(gemPortID), |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1047 | Classifier: classifierProto, |
| 1048 | Action: actionProto, |
| 1049 | Priority: int32(logicalFlow.Priority), |
| 1050 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1051 | PortNo: portNo, |
| 1052 | TechProfileId: tpID, |
| 1053 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1054 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1055 | return olterrors.NewErrFlowOp("add", flowID, nil, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1056 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1057 | logger.Infow(ctx, "hsia-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1058 | log.Fields{"direction": direction, |
| 1059 | "device-id": f.deviceHandler.device.Id, |
| 1060 | "flow": flow, |
| 1061 | "intf-id": intfID, |
| 1062 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1063 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &flow, flowStoreCookie, HsiaFlow, flowID, logicalFlow.Id) |
| 1064 | if err := f.updateFlowInfoToKVStore(ctx, flow.AccessIntfId, |
| 1065 | flow.OnuId, |
| 1066 | flow.UniId, |
| 1067 | flow.FlowId /*flowCategory,*/, flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1068 | return olterrors.NewErrPersistence("update", "flow", flowID, |
| 1069 | log.Fields{ |
| 1070 | "flow": flow, |
| 1071 | "device-id": f.deviceHandler.device.Id, |
| 1072 | "intf-id": intfID, |
| 1073 | "onu-id": onuID}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1074 | } |
| 1075 | return nil |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1076 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1077 | |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1078 | func (f *OpenOltFlowMgr) addDHCPTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
| 1079 | classifier map[string]interface{}, action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, |
| 1080 | gemPortID uint32, tpID uint32) error { |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1081 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1082 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1083 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1084 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1085 | "classifier": classifier, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1086 | "action": action, |
| 1087 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1088 | err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1089 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1090 | |
| 1091 | // Clear the action map |
| 1092 | for k := range action { |
| 1093 | delete(action, k) |
| 1094 | } |
| 1095 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1096 | action[TrapToHost] = true |
| 1097 | classifier[UDPSrc] = uint32(68) |
| 1098 | classifier[UDPDst] = uint32(67) |
| 1099 | classifier[PacketTagType] = SingleTag |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1100 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1101 | flowStoreCookie := getFlowStoreCookie(ctx, classifier, gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1102 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1103 | logger.Infow(ctx, "flow-exists--not-re-adding", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1104 | log.Fields{ |
| 1105 | "device-id": f.deviceHandler.device.Id, |
| 1106 | "intf-id": intfID, |
| 1107 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1108 | return nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1109 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1110 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1111 | flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, DhcpFlow, 0 /*classifier[VLAN_PCP].(uint32)*/) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1112 | |
| 1113 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1114 | return olterrors.NewErrNotFound("flow", |
| 1115 | log.Fields{ |
| 1116 | "interface-id": intfID, |
| 1117 | "gem-port": gemPortID, |
| 1118 | "cookie": flowStoreCookie, |
| 1119 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1120 | err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1121 | } |
| 1122 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1123 | logger.Debugw(ctx, "creating-ul-dhcp-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1124 | log.Fields{ |
| 1125 | "ul_classifier": classifier, |
| 1126 | "ul_action": action, |
| 1127 | "uplinkFlowId": flowID, |
| 1128 | "intf-id": intfID, |
| 1129 | "onu-id": onuID, |
| 1130 | "device-id": f.deviceHandler.device.Id}) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1131 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1132 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1133 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1134 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1135 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1136 | logger.Debugw(ctx, "created-classifier-proto", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1137 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1138 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1139 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1140 | } |
| 1141 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1142 | dhcpFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1143 | OnuId: int32(onuID), |
| 1144 | UniId: int32(uniID), |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1145 | FlowId: flowID, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1146 | FlowType: Upstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1147 | AllocId: int32(allocID), |
| 1148 | NetworkIntfId: int32(networkIntfID), |
| 1149 | GemportId: int32(gemPortID), |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1150 | Classifier: classifierProto, |
| 1151 | Action: actionProto, |
| 1152 | Priority: int32(logicalFlow.Priority), |
| 1153 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1154 | PortNo: portNo, |
| 1155 | TechProfileId: tpID, |
| 1156 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1157 | if err := f.addFlowToDevice(ctx, logicalFlow, &dhcpFlow); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1158 | return olterrors.NewErrFlowOp("add", flowID, log.Fields{"dhcp-flow": dhcpFlow}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1159 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1160 | logger.Infow(ctx, "dhcp-ul-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1161 | log.Fields{ |
| 1162 | "device-id": f.deviceHandler.device.Id, |
| 1163 | "flow-id": flowID, |
| 1164 | "intf-id": intfID, |
| 1165 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1166 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &dhcpFlow, flowStoreCookie, "DHCP", flowID, logicalFlow.Id) |
| 1167 | if err := f.updateFlowInfoToKVStore(ctx, dhcpFlow.AccessIntfId, |
| 1168 | dhcpFlow.OnuId, |
| 1169 | dhcpFlow.UniId, |
| 1170 | dhcpFlow.FlowId, flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1171 | return olterrors.NewErrPersistence("update", "flow", dhcpFlow.FlowId, |
| 1172 | log.Fields{ |
| 1173 | "flow": dhcpFlow, |
| 1174 | "device-id": f.deviceHandler.device.Id}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1175 | } |
| 1176 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1177 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1178 | } |
| 1179 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1180 | //addIGMPTrapFlow creates IGMP trap-to-host flow |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1181 | func (f *OpenOltFlowMgr) addIGMPTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{}, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1182 | action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, gemPortID uint32, tpID uint32) error { |
| 1183 | return f.addUpstreamTrapFlow(ctx, intfID, onuID, uniID, portNo, classifier, action, logicalFlow, allocID, gemPortID, IgmpFlow, tpID) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | //addUpstreamTrapFlow creates a trap-to-host flow |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1187 | func (f *OpenOltFlowMgr) addUpstreamTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{}, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1188 | action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, gemPortID uint32, flowType string, tpID uint32) error { |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1189 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1190 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1191 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1192 | return olterrors.NewErrNotFound("nni-interface-id", |
| 1193 | log.Fields{ |
| 1194 | "classifier": classifier, |
| 1195 | "action": action, |
| 1196 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1197 | err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | // Clear the action map |
| 1201 | for k := range action { |
| 1202 | delete(action, k) |
| 1203 | } |
| 1204 | |
| 1205 | action[TrapToHost] = true |
| 1206 | classifier[PacketTagType] = SingleTag |
| 1207 | delete(classifier, VlanVid) |
| 1208 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1209 | flowStoreCookie := getFlowStoreCookie(ctx, classifier, gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1210 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkIntfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1211 | logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{"device-id": f.deviceHandler.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1212 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1215 | flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, flowType, 0, 0 /*classifier[VLAN_PCP].(uint32)*/) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1216 | |
| 1217 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1218 | return olterrors.NewErrNotFound("flow-id", |
| 1219 | log.Fields{ |
| 1220 | "intf-id": intfID, |
| 1221 | "oni-id": onuID, |
| 1222 | "cookie": flowStoreCookie, |
| 1223 | "flow-type": flowType, |
| 1224 | "device-id": f.deviceHandler.device.Id, |
| 1225 | "onu-id": onuID}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1226 | err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1229 | logger.Debugw(ctx, "creating-upstream-trap-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1230 | log.Fields{ |
| 1231 | "ul_classifier": classifier, |
| 1232 | "ul_action": action, |
| 1233 | "uplinkFlowId": flowID, |
| 1234 | "flowType": flowType, |
| 1235 | "device-id": f.deviceHandler.device.Id, |
| 1236 | "intf-id": intfID, |
| 1237 | "onu-id": onuID}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1238 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1239 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1240 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1241 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier, "device-id": f.deviceHandler.device.Id}, err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1242 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1243 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1244 | log.Fields{ |
| 1245 | "classifier": *classifierProto, |
| 1246 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1247 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1248 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1249 | return olterrors.NewErrInvalidValue(log.Fields{"action": action, "device-id": f.deviceHandler.device.Id}, err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1252 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1253 | OnuId: int32(onuID), |
| 1254 | UniId: int32(uniID), |
| 1255 | FlowId: flowID, |
| 1256 | FlowType: Upstream, |
| 1257 | AllocId: int32(allocID), |
| 1258 | NetworkIntfId: int32(networkIntfID), |
| 1259 | GemportId: int32(gemPortID), |
| 1260 | Classifier: classifierProto, |
| 1261 | Action: actionProto, |
| 1262 | Priority: int32(logicalFlow.Priority), |
| 1263 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1264 | PortNo: portNo, |
| 1265 | TechProfileId: tpID, |
| 1266 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1267 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1268 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1269 | return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": flow, "device-id": f.deviceHandler.device.Id}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1270 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1271 | logger.Infof(ctx, "%s ul-flow-added-to-device-successfully", flowType) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1272 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1273 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &flow, flowStoreCookie, flowType, flowID, logicalFlow.Id) |
| 1274 | if err := f.updateFlowInfoToKVStore(ctx, flow.AccessIntfId, |
| 1275 | flow.OnuId, |
| 1276 | flow.UniId, |
| 1277 | flow.FlowId, flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1278 | return olterrors.NewErrPersistence("update", "flow", flow.FlowId, log.Fields{"flow": flow, "device-id": f.deviceHandler.device.Id}, err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1281 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1284 | // Add EAPOL flow to device with mac, vlanId as classifier for upstream and downstream |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1285 | func (f *OpenOltFlowMgr) addEAPOLFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
| 1286 | classifier map[string]interface{}, action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, |
| 1287 | gemPortID uint32, vlanID uint32, tpID uint32) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1288 | logger.Infow(ctx, "adding-eapol-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1289 | log.Fields{ |
| 1290 | "intf-id": intfID, |
| 1291 | "onu-id": onuID, |
| 1292 | "port-no": portNo, |
| 1293 | "alloc-id": allocID, |
| 1294 | "gemport-id": gemPortID, |
| 1295 | "vlan-id": vlanID, |
| 1296 | "flow": logicalFlow}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1297 | |
| 1298 | uplinkClassifier := make(map[string]interface{}) |
| 1299 | uplinkAction := make(map[string]interface{}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1300 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1301 | // Fill Classfier |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1302 | uplinkClassifier[EthType] = uint32(EapEthType) |
| 1303 | uplinkClassifier[PacketTagType] = SingleTag |
| 1304 | uplinkClassifier[VlanVid] = vlanID |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1305 | uplinkClassifier[VlanPcp] = classifier[VlanPcp] |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1306 | // Fill action |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1307 | uplinkAction[TrapToHost] = true |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1308 | flowStoreCookie := getFlowStoreCookie(ctx, uplinkClassifier, gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1309 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1310 | logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1311 | "device-id": f.deviceHandler.device.Id, |
| 1312 | "onu-id": onuID, |
| 1313 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1314 | return nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1315 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1316 | //Add Uplink EAPOL Flow |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1317 | uplinkFlowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, "", 0, 0) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1318 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1319 | return olterrors.NewErrNotFound("flow-id", |
| 1320 | log.Fields{ |
| 1321 | "intf-id": intfID, |
| 1322 | "onu-id": onuID, |
| 1323 | "coookie": flowStoreCookie, |
| 1324 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1325 | err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1326 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1327 | logger.Debugw(ctx, "creating-ul-eapol-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1328 | log.Fields{ |
| 1329 | "ul_classifier": uplinkClassifier, |
| 1330 | "ul_action": uplinkAction, |
| 1331 | "uplinkFlowId": uplinkFlowID, |
| 1332 | "device-id": f.deviceHandler.device.Id, |
| 1333 | "intf-id": intfID, |
| 1334 | "onu-id": onuID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1335 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1336 | classifierProto, err := makeOpenOltClassifierField(uplinkClassifier) |
| 1337 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1338 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 1339 | "classifier": uplinkClassifier, |
| 1340 | "device-id": f.deviceHandler.device.Id}, err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1341 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1342 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1343 | log.Fields{ |
| 1344 | "classifier": *classifierProto, |
| 1345 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1346 | actionProto, err := makeOpenOltActionField(uplinkAction, uplinkClassifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1347 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1348 | return olterrors.NewErrInvalidValue(log.Fields{"action": uplinkAction, "device-id": f.deviceHandler.device.Id}, err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1349 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1350 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1351 | log.Fields{ |
| 1352 | "action": *actionProto, |
| 1353 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1354 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1355 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1356 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1357 | "classifier": classifier, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1358 | "action": action, |
| 1359 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1360 | err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1361 | } |
| 1362 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1363 | upstreamFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1364 | OnuId: int32(onuID), |
| 1365 | UniId: int32(uniID), |
| 1366 | FlowId: uplinkFlowID, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1367 | FlowType: Upstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1368 | AllocId: int32(allocID), |
| 1369 | NetworkIntfId: int32(networkIntfID), |
| 1370 | GemportId: int32(gemPortID), |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1371 | Classifier: classifierProto, |
| 1372 | Action: actionProto, |
| 1373 | Priority: int32(logicalFlow.Priority), |
| 1374 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1375 | PortNo: portNo, |
| 1376 | TechProfileId: tpID, |
| 1377 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1378 | if err := f.addFlowToDevice(ctx, logicalFlow, &upstreamFlow); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1379 | return olterrors.NewErrFlowOp("add", uplinkFlowID, log.Fields{"flow": upstreamFlow}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1380 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1381 | logger.Infow(ctx, "eapol-ul-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1382 | log.Fields{ |
| 1383 | "device-id": f.deviceHandler.device.Id, |
| 1384 | "onu-id": onuID, |
| 1385 | "intf-id": intfID, |
| 1386 | }) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1387 | flowCategory := "EAPOL" |
| 1388 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &upstreamFlow, flowStoreCookie, flowCategory, uplinkFlowID, logicalFlow.Id) |
| 1389 | if err := f.updateFlowInfoToKVStore(ctx, upstreamFlow.AccessIntfId, |
| 1390 | upstreamFlow.OnuId, |
| 1391 | upstreamFlow.UniId, |
| 1392 | upstreamFlow.FlowId, |
| 1393 | /* lowCategory, */ |
| 1394 | flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1395 | return olterrors.NewErrPersistence("update", "flow", upstreamFlow.FlowId, |
| 1396 | log.Fields{ |
| 1397 | "flow": upstreamFlow, |
| 1398 | "device-id": f.deviceHandler.device.Id}, err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1399 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1400 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1401 | } |
| 1402 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1403 | func makeOpenOltClassifierField(classifierInfo map[string]interface{}) (*openoltpb2.Classifier, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1404 | var classifier openoltpb2.Classifier |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1405 | |
| 1406 | classifier.EthType, _ = classifierInfo[EthType].(uint32) |
| 1407 | classifier.IpProto, _ = classifierInfo[IPProto].(uint32) |
| 1408 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 1409 | if vlanID != ReservedVlan { |
| 1410 | vid := vlanID & VlanvIDMask |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1411 | classifier.OVid = vid |
| 1412 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1413 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1414 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 1415 | vid := uint32(metadata) |
| 1416 | if vid != ReservedVlan { |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1417 | classifier.IVid = vid |
| 1418 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1419 | } |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1420 | // Use VlanPCPMask (0xff) to signify NO PCP. Else use valid PCP (0 to 7) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1421 | if vlanPcp, ok := classifierInfo[VlanPcp].(uint32); ok { |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1422 | classifier.OPbits = vlanPcp |
| 1423 | } else { |
| 1424 | classifier.OPbits = VlanPCPMask |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1425 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1426 | classifier.SrcPort, _ = classifierInfo[UDPSrc].(uint32) |
| 1427 | classifier.DstPort, _ = classifierInfo[UDPDst].(uint32) |
| 1428 | classifier.DstIp, _ = classifierInfo[Ipv4Dst].(uint32) |
| 1429 | classifier.SrcIp, _ = classifierInfo[Ipv4Src].(uint32) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1430 | classifier.DstMac, _ = classifierInfo[EthDst].([]uint8) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1431 | if pktTagType, ok := classifierInfo[PacketTagType].(string); ok { |
| 1432 | classifier.PktTagType = pktTagType |
| 1433 | |
| 1434 | switch pktTagType { |
| 1435 | case SingleTag: |
| 1436 | case DoubleTag: |
| 1437 | case Untagged: |
| 1438 | default: |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1439 | return nil, olterrors.NewErrInvalidValue(log.Fields{"packet-tag-type": pktTagType}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1440 | } |
| 1441 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1442 | return &classifier, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1443 | } |
| 1444 | |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1445 | func makeOpenOltActionField(actionInfo map[string]interface{}, classifierInfo map[string]interface{}) (*openoltpb2.Action, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1446 | var actionCmd openoltpb2.ActionCmd |
| 1447 | var action openoltpb2.Action |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1448 | action.Cmd = &actionCmd |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1449 | if _, ok := actionInfo[PopVlan]; ok { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1450 | action.Cmd.RemoveOuterTag = true |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1451 | if _, ok := actionInfo[VlanPcp]; ok { |
| 1452 | action.Cmd.RemarkInnerPbits = true |
| 1453 | action.IPbits = actionInfo[VlanPcp].(uint32) |
| 1454 | if _, ok := actionInfo[VlanVid]; ok { |
| 1455 | action.Cmd.TranslateInnerTag = true |
| 1456 | action.IVid = actionInfo[VlanVid].(uint32) |
| 1457 | } |
| 1458 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1459 | } else if _, ok := actionInfo[PushVlan]; ok { |
| 1460 | action.OVid = actionInfo[VlanVid].(uint32) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1461 | action.Cmd.AddOuterTag = true |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1462 | if _, ok := actionInfo[VlanPcp]; ok { |
| 1463 | action.OPbits = actionInfo[VlanPcp].(uint32) |
| 1464 | action.Cmd.RemarkOuterPbits = true |
| 1465 | if _, ok := classifierInfo[VlanVid]; ok { |
| 1466 | action.IVid = classifierInfo[VlanVid].(uint32) |
| 1467 | action.Cmd.TranslateInnerTag = true |
| 1468 | } |
| 1469 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1470 | } else if _, ok := actionInfo[TrapToHost]; ok { |
| 1471 | action.Cmd.TrapToHost = actionInfo[TrapToHost].(bool) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1472 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1473 | return nil, olterrors.NewErrInvalidValue(log.Fields{"action-command": actionInfo}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1474 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1475 | return &action, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1476 | } |
| 1477 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1478 | // getTPpath return the ETCD path for a given UNI port |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1479 | func (f *OpenOltFlowMgr) getTPpath(ctx context.Context, intfID uint32, uniPath string, TpID uint32) string { |
| 1480 | return f.techprofile[intfID].GetTechProfileInstanceKVPath(ctx, TpID, uniPath) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1481 | } |
| 1482 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1483 | // DeleteTechProfileInstances removes the tech profile instances from persistent storage |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1484 | func (f *OpenOltFlowMgr) DeleteTechProfileInstances(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, sn string) error { |
| 1485 | tpIDList := f.resourceMgr.GetTechProfileIDForOnu(ctx, intfID, onuID, uniID) |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1486 | uniPortName := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| 1487 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1488 | for _, tpID := range tpIDList { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1489 | if err := f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1490 | _ = olterrors.NewErrAdapter("delete-tech-profile-failed", log.Fields{"device-id": f.deviceHandler.device.Id}, err).Log() |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1491 | // return err |
| 1492 | // We should continue to delete tech-profile instances for other TP IDs |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1493 | } |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 1494 | logger.Debugw(ctx, "tech-profile-deleted", log.Fields{"device-id": f.deviceHandler.device.Id, "tp-id": tpID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1495 | } |
| 1496 | return nil |
| 1497 | } |
| 1498 | |
| 1499 | // DeleteTechProfileInstance removes the tech profile instance from persistent storage |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1500 | func (f *OpenOltFlowMgr) DeleteTechProfileInstance(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uniPortName string, tpID uint32) error { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1501 | if uniPortName == "" { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1502 | uniPortName = getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1503 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1504 | if err := f.techprofile[intfID].DeleteTechProfileInstance(ctx, tpID, uniPortName); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1505 | return olterrors.NewErrAdapter("failed-to-delete-tp-instance-from-kv-store", |
| 1506 | log.Fields{ |
| 1507 | "tp-id": tpID, |
| 1508 | "uni-port-name": uniPortName, |
| 1509 | "device-id": f.deviceHandler.device.Id}, err) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1510 | } |
| 1511 | return nil |
| 1512 | } |
| 1513 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1514 | func getFlowStoreCookie(ctx context.Context, classifier map[string]interface{}, gemPortID uint32) uint64 { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1515 | if len(classifier) == 0 { // should never happen |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1516 | logger.Error(ctx, "invalid-classfier-object") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1517 | return 0 |
| 1518 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1519 | logger.Debugw(ctx, "generating-flow-store-cookie", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1520 | log.Fields{ |
| 1521 | "classifier": classifier, |
| 1522 | "gemport-id": gemPortID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1523 | var jsonData []byte |
| 1524 | var flowString string |
| 1525 | var err error |
| 1526 | // TODO: Do we need to marshall ?? |
| 1527 | if jsonData, err = json.Marshal(classifier); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1528 | logger.Error(ctx, "failed-to-encode-classifier") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1529 | return 0 |
| 1530 | } |
| 1531 | flowString = string(jsonData) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1532 | if gemPortID != 0 { |
| 1533 | flowString = fmt.Sprintf("%s%s", string(jsonData), string(gemPortID)) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1534 | } |
| 1535 | h := md5.New() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1536 | _, _ = h.Write([]byte(flowString)) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1537 | hash := big.NewInt(0) |
| 1538 | hash.SetBytes(h.Sum(nil)) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1539 | generatedHash := hash.Uint64() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1540 | logger.Debugw(ctx, "hash-generated", log.Fields{"hash": generatedHash}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1541 | return generatedHash |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1542 | } |
| 1543 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1544 | func (f *OpenOltFlowMgr) getUpdatedFlowInfo(ctx context.Context, flow *openoltpb2.Flow, flowStoreCookie uint64, flowCategory string, deviceFlowID uint32, logicalFlowID uint64) *[]rsrcMgr.FlowInfo { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1545 | var flows = []rsrcMgr.FlowInfo{{Flow: flow, FlowCategory: flowCategory, FlowStoreCookie: flowStoreCookie, LogicalFlowID: logicalFlowID}} |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1546 | var intfID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1547 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1548 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1549 | */ |
| 1550 | if flow.AccessIntfId != -1 { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1551 | intfID = uint32(flow.AccessIntfId) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1552 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1553 | intfID = uint32(flow.NetworkIntfId) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1554 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1555 | // Get existing flows matching flowid for given subscriber from KV store |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1556 | existingFlows := f.resourceMgr.GetFlowIDInfo(ctx, intfID, flow.OnuId, flow.UniId, flow.FlowId) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1557 | if existingFlows != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1558 | logger.Debugw(ctx, "flow-exists-for-given-flowID--appending-it-to-current-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1559 | log.Fields{ |
| 1560 | "flow-id": flow.FlowId, |
| 1561 | "device-id": f.deviceHandler.device.Id, |
| 1562 | "intf-id": intfID, |
| 1563 | "onu-id": flow.OnuId}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1564 | //for _, f := range *existingFlows { |
| 1565 | // flows = append(flows, f) |
| 1566 | //} |
| 1567 | flows = append(flows, *existingFlows...) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1568 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1569 | logger.Debugw(ctx, "updated-flows-for-given-flowID-and-onuid", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1570 | log.Fields{ |
| 1571 | "updatedflow": flows, |
| 1572 | "flow-id": flow.FlowId, |
| 1573 | "onu-id": flow.OnuId, |
| 1574 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1575 | return &flows |
| 1576 | } |
| 1577 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1578 | func (f *OpenOltFlowMgr) updateFlowInfoToKVStore(ctx context.Context, intfID int32, onuID int32, uniID int32, flowID uint32, flows *[]rsrcMgr.FlowInfo) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1579 | logger.Debugw(ctx, "storing-flow(s)-into-kv-store", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1580 | "flow-id": flowID, |
| 1581 | "device-id": f.deviceHandler.device.Id, |
| 1582 | "intf-id": intfID, |
| 1583 | "onu-id": onuID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1584 | if err := f.resourceMgr.UpdateFlowIDInfo(ctx, intfID, onuID, uniID, flowID, flows); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1585 | logger.Warnw(ctx, "error-while-storing-flow-into-kv-store", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1586 | "device-id": f.deviceHandler.device.Id, |
| 1587 | "onu-id": onuID, |
| 1588 | "intf-id": intfID, |
| 1589 | "flow-id": flowID}) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1590 | return err |
| 1591 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1592 | logger.Infow(ctx, "stored-flow(s)-into-kv-store-successfully!", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1593 | "device-id": f.deviceHandler.device.Id, |
| 1594 | "onu-id": onuID, |
| 1595 | "intf-id": intfID, |
| 1596 | "flow-id": flowID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1597 | return nil |
| 1598 | } |
| 1599 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1600 | func (f *OpenOltFlowMgr) addFlowToDevice(ctx context.Context, logicalFlow *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error { |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1601 | |
| 1602 | var intfID uint32 |
| 1603 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1604 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1605 | */ |
| 1606 | if deviceFlow.AccessIntfId != -1 { |
| 1607 | intfID = uint32(deviceFlow.AccessIntfId) |
| 1608 | } else { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1609 | // REVIST : Why ponport is given as network port? |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1610 | intfID = uint32(deviceFlow.NetworkIntfId) |
| 1611 | } |
| 1612 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1613 | logger.Debugw(ctx, "sending-flow-to-device-via-grpc", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1614 | "flow": *deviceFlow, |
| 1615 | "device-id": f.deviceHandler.device.Id, |
| 1616 | "intf-id": intfID}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1617 | _, err := f.deviceHandler.Client.FlowAdd(log.WithSpanFromContext(context.Background(), ctx), deviceFlow) |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1618 | |
| 1619 | st, _ := status.FromError(err) |
| 1620 | if st.Code() == codes.AlreadyExists { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1621 | logger.Debug(ctx, "flow-already-exists", log.Fields{ |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1622 | "err": err, |
| 1623 | "deviceFlow": deviceFlow, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1624 | "device-id": f.deviceHandler.device.Id, |
| 1625 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1626 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1627 | } |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1628 | |
| 1629 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1630 | logger.Errorw(ctx, "failed-to-add-flow-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1631 | log.Fields{"err": err, |
| 1632 | "device-flow": deviceFlow, |
| 1633 | "device-id": f.deviceHandler.device.Id, |
| 1634 | "intf-id": intfID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1635 | f.resourceMgr.FreeFlowID(ctx, intfID, deviceFlow.OnuId, deviceFlow.UniId, deviceFlow.FlowId) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1636 | return err |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1637 | } |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1638 | if deviceFlow.GemportId != -1 { |
| 1639 | // No need to register the flow if it is a trap on nni flow. |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1640 | if err := f.registerFlow(ctx, logicalFlow, deviceFlow); err != nil { |
| 1641 | logger.Errorw(ctx, "failed-to-register-flow", log.Fields{"err": err}) |
| 1642 | return err |
| 1643 | } |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1644 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1645 | logger.Infow(ctx, "flow-added-to-device-successfully ", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1646 | log.Fields{ |
| 1647 | "flow": *deviceFlow, |
| 1648 | "device-id": f.deviceHandler.device.Id, |
| 1649 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1650 | return nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1651 | } |
| 1652 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1653 | func (f *OpenOltFlowMgr) removeFlowFromDevice(ctx context.Context, deviceFlow *openoltpb2.Flow, ofFlowID uint64) error { |
| 1654 | logger.Debugw(ctx, "sending-flow-to-device-via-grpc", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1655 | log.Fields{ |
| 1656 | "flow": *deviceFlow, |
| 1657 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1658 | _, err := f.deviceHandler.Client.FlowRemove(log.WithSpanFromContext(context.Background(), ctx), deviceFlow) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1659 | if err != nil { |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1660 | if f.deviceHandler.device.ConnectStatus == common.ConnectStatus_UNREACHABLE { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1661 | logger.Warnw(ctx, "can-not-remove-flow-from-device--unreachable", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1662 | log.Fields{ |
| 1663 | "err": err, |
| 1664 | "deviceFlow": deviceFlow, |
| 1665 | "device-id": f.deviceHandler.device.Id}) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1666 | //Assume the flow is removed |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1667 | return nil |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1668 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1669 | return olterrors.NewErrFlowOp("remove", deviceFlow.FlowId, log.Fields{"deviceFlow": deviceFlow}, err) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1670 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1671 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1672 | logger.Infow(ctx, "flow-removed-from-device-successfully", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1673 | "of-flow-id": ofFlowID, |
| 1674 | "flow": *deviceFlow, |
| 1675 | "device-id": f.deviceHandler.device.Id, |
| 1676 | }) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1677 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1678 | } |
| 1679 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1680 | func (f *OpenOltFlowMgr) addLLDPFlow(ctx context.Context, flow *ofp.OfpFlowStats, portNo uint32) error { |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1681 | |
| 1682 | classifierInfo := make(map[string]interface{}) |
| 1683 | actionInfo := make(map[string]interface{}) |
| 1684 | |
| 1685 | classifierInfo[EthType] = uint32(LldpEthType) |
| 1686 | classifierInfo[PacketTagType] = Untagged |
| 1687 | actionInfo[TrapToHost] = true |
| 1688 | |
| 1689 | // LLDP flow is installed to trap LLDP packets on the NNI port. |
| 1690 | // We manage flow_id resource pool on per PON port basis. |
| 1691 | // Since this situation is tricky, as a hack, we pass the NNI port |
| 1692 | // index (network_intf_id) as PON port Index for the flow_id resource |
| 1693 | // pool. Also, there is no ONU Id available for trapping LLDP packets |
| 1694 | // on NNI port, use onu_id as -1 (invalid) |
| 1695 | // ****************** CAVEAT ******************* |
| 1696 | // This logic works if the NNI Port Id falls within the same valid |
| 1697 | // range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1698 | // we need to have a re-look at this. |
| 1699 | // ********************************************* |
| 1700 | |
| 1701 | var onuID = -1 |
| 1702 | var uniID = -1 |
| 1703 | var gemPortID = -1 |
| 1704 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1705 | networkInterfaceID, err := IntfIDFromNniPortNum(ctx, portNo) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1706 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1707 | return olterrors.NewErrInvalidValue(log.Fields{"nni-port-number": portNo}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1708 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1709 | var flowStoreCookie = getFlowStoreCookie(ctx, classifierInfo, uint32(0)) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1710 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1711 | logger.Infow(ctx, "flow-exists--not-re-adding", log.Fields{"device-id": f.deviceHandler.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1712 | return nil |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1713 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1714 | flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1715 | |
| 1716 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1717 | return olterrors.NewErrNotFound("flow-id", |
| 1718 | log.Fields{ |
| 1719 | "interface-id": networkInterfaceID, |
| 1720 | "onu-id": onuID, |
| 1721 | "uni-id": uniID, |
| 1722 | "gem-port-id": gemPortID, |
| 1723 | "cookie": flowStoreCookie, |
| 1724 | "device-id": f.deviceHandler.device.Id}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1725 | err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1726 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1727 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 1728 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1729 | return olterrors.NewErrInvalidValue( |
| 1730 | log.Fields{ |
| 1731 | "classifier": classifierInfo, |
| 1732 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1733 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1734 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1735 | log.Fields{ |
| 1736 | "classifier": *classifierProto, |
| 1737 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1738 | actionProto, err := makeOpenOltActionField(actionInfo, classifierInfo) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1739 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1740 | return olterrors.NewErrInvalidValue( |
| 1741 | log.Fields{ |
| 1742 | "action": actionInfo, |
| 1743 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1744 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1745 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1746 | log.Fields{ |
| 1747 | "action": *actionProto, |
| 1748 | "device-id": f.deviceHandler.device.Id}) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1749 | |
| 1750 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 1751 | OnuId: int32(onuID), // OnuId not required |
| 1752 | UniId: int32(uniID), // UniId not used |
| 1753 | FlowId: flowID, |
| 1754 | FlowType: Downstream, |
| 1755 | NetworkIntfId: int32(networkInterfaceID), |
| 1756 | GemportId: int32(gemPortID), |
| 1757 | Classifier: classifierProto, |
| 1758 | Action: actionProto, |
| 1759 | Priority: int32(flow.Priority), |
| 1760 | Cookie: flow.Cookie, |
| 1761 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1762 | if err := f.addFlowToDevice(ctx, flow, &downstreamflow); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1763 | return olterrors.NewErrFlowOp("add", flowID, |
| 1764 | log.Fields{ |
| 1765 | "flow": downstreamflow, |
| 1766 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1767 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1768 | logger.Infow(ctx, "lldp-trap-on-nni-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1769 | log.Fields{ |
| 1770 | "device-id": f.deviceHandler.device.Id, |
| 1771 | "onu-id": onuID, |
| 1772 | "flow-id": flowID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1773 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &downstreamflow, flowStoreCookie, "", flowID, flow.Id) |
| 1774 | if err := f.updateFlowInfoToKVStore(ctx, int32(networkInterfaceID), |
| 1775 | int32(onuID), |
| 1776 | int32(uniID), |
| 1777 | flowID, flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1778 | return olterrors.NewErrPersistence("update", "flow", flowID, |
| 1779 | log.Fields{ |
| 1780 | "flow": downstreamflow, |
| 1781 | "device-id": f.deviceHandler.device.Id}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1782 | } |
| 1783 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1784 | } |
| 1785 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1786 | func getUniPortPath(oltID string, intfID uint32, onuID int32, uniID int32) string { |
| 1787 | return fmt.Sprintf("olt-{%s}/pon-{%d}/onu-{%d}/uni-{%d}", oltID, intfID, onuID, uniID) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1790 | //getOnuDevice to fetch onu from cache or core. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1791 | func (f *OpenOltFlowMgr) getOnuDevice(ctx context.Context, intfID uint32, onuID uint32) (*OnuDevice, error) { |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1792 | onuKey := f.deviceHandler.formOnuKey(intfID, onuID) |
| 1793 | onuDev, ok := f.deviceHandler.onus.Load(onuKey) |
| 1794 | if !ok { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1795 | logger.Debugw(ctx, "couldnt-find-onu-in-cache", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1796 | log.Fields{ |
| 1797 | "intf-id": intfID, |
| 1798 | "onu-id": onuID, |
| 1799 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1800 | onuDevice, err := f.getChildDevice(ctx, intfID, onuID) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1801 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1802 | return nil, olterrors.NewErrNotFound("onu-child-device", |
| 1803 | log.Fields{ |
| 1804 | "onu-id": onuID, |
| 1805 | "intf-id": intfID, |
| 1806 | "device-id": f.deviceHandler.device.Id}, err) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1807 | } |
| 1808 | onuDev = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuDevice.ProxyAddress.OnuId, onuDevice.ProxyAddress.ChannelId, onuDevice.ProxyAddress.DeviceId, false) |
| 1809 | //better to ad the device to cache here. |
| 1810 | f.deviceHandler.StoreOnuDevice(onuDev.(*OnuDevice)) |
| 1811 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1812 | logger.Debugw(ctx, "found-onu-in-cache", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1813 | log.Fields{ |
| 1814 | "intf-id": intfID, |
| 1815 | "onu-id": onuID, |
| 1816 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | return onuDev.(*OnuDevice), nil |
| 1820 | } |
| 1821 | |
| 1822 | //getChildDevice to fetch onu |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1823 | func (f *OpenOltFlowMgr) getChildDevice(ctx context.Context, intfID uint32, onuID uint32) (*voltha.Device, error) { |
| 1824 | logger.Infow(ctx, "GetChildDevice", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1825 | log.Fields{ |
| 1826 | "pon-port": intfID, |
| 1827 | "onu-id": onuID, |
| 1828 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1829 | parentPortNo := IntfIDToPortNo(intfID, voltha.Port_PON_OLT) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1830 | onuDevice, err := f.deviceHandler.GetChildDevice(ctx, parentPortNo, onuID) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1831 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1832 | return nil, olterrors.NewErrNotFound("onu", |
| 1833 | log.Fields{ |
| 1834 | "interface-id": parentPortNo, |
| 1835 | "onu-id": onuID, |
| 1836 | "device-id": f.deviceHandler.device.Id}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1837 | err) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1838 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1839 | logger.Infow(ctx, "successfully-received-child-device-from-core", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1840 | log.Fields{ |
| 1841 | "device-id": f.deviceHandler.device.Id, |
| 1842 | "child_device_id": onuDevice.Id, |
| 1843 | "child_device_sn": onuDevice.SerialNumber}) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1844 | return onuDevice, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1845 | } |
| 1846 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1847 | func (f *OpenOltFlowMgr) sendDeleteGemPortToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, gemPortID uint32, tpPath string) error { |
| 1848 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1849 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1850 | logger.Debugw(ctx, "couldnt-find-onu-child-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1851 | log.Fields{ |
| 1852 | "intf-id": intfID, |
| 1853 | "onu-id": onuID, |
| 1854 | "uni-id": uniID, |
| 1855 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1856 | return err |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | delGemPortMsg := &ic.InterAdapterDeleteGemPortMessage{UniId: uniID, TpPath: tpPath, GemPortId: gemPortID} |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1860 | logger.Debugw(ctx, "sending-gem-port-delete-to-openonu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1861 | log.Fields{ |
| 1862 | "msg": *delGemPortMsg, |
| 1863 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1864 | if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(log.WithSpanFromContext(context.Background(), ctx), |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1865 | delGemPortMsg, |
| 1866 | ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1867 | f.deviceHandler.device.Type, |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1868 | onuDev.deviceType, |
| 1869 | onuDev.deviceID, |
| 1870 | onuDev.proxyDeviceID, ""); sendErr != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1871 | return olterrors.NewErrCommunication("send-delete-gem-port-to-onu-adapter", |
| 1872 | log.Fields{ |
| 1873 | "from-adapter": f.deviceHandler.device.Type, |
| 1874 | "to-adapter": onuDev.deviceType, |
| 1875 | "onu-id": onuDev.deviceID, |
| 1876 | "proxyDeviceID": onuDev.proxyDeviceID, |
| 1877 | "device-id": f.deviceHandler.device.Id}, sendErr) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1878 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1879 | logger.Infow(ctx, "success-sending-del-gem-port-to-onu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1880 | log.Fields{ |
| 1881 | "msg": delGemPortMsg, |
| 1882 | "from-adapter": f.deviceHandler.device.Type, |
| 1883 | "to-adapter": onuDev.deviceType, |
| 1884 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1885 | return nil |
| 1886 | } |
| 1887 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1888 | func (f *OpenOltFlowMgr) sendDeleteTcontToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID uint32, tpPath string) error { |
| 1889 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1890 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1891 | logger.Warnw(ctx, "couldnt-find-onu-child-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1892 | log.Fields{ |
| 1893 | "intf-id": intfID, |
| 1894 | "onu-id": onuID, |
| 1895 | "uni-id": uniID, |
| 1896 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1897 | return err |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | delTcontMsg := &ic.InterAdapterDeleteTcontMessage{UniId: uniID, TpPath: tpPath, AllocId: allocID} |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1901 | logger.Debugw(ctx, "sending-tcont-delete-to-openonu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1902 | log.Fields{ |
| 1903 | "msg": *delTcontMsg, |
| 1904 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1905 | if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(log.WithSpanFromContext(context.Background(), ctx), |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1906 | delTcontMsg, |
| 1907 | ic.InterAdapterMessageType_DELETE_TCONT_REQUEST, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1908 | f.deviceHandler.device.Type, |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1909 | onuDev.deviceType, |
| 1910 | onuDev.deviceID, |
| 1911 | onuDev.proxyDeviceID, ""); sendErr != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1912 | return olterrors.NewErrCommunication("send-delete-tcont-to-onu-adapter", |
| 1913 | log.Fields{ |
| 1914 | "from-adapter": f.deviceHandler.device.Type, |
| 1915 | "to-adapter": onuDev.deviceType, "onu-id": onuDev.deviceID, |
| 1916 | "proxyDeviceID": onuDev.proxyDeviceID, |
| 1917 | "device-id": f.deviceHandler.device.Id}, sendErr) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1918 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1919 | logger.Infow(ctx, "success-sending-del-tcont-to-onu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1920 | log.Fields{ |
| 1921 | "msg": delTcontMsg, |
| 1922 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1923 | return nil |
| 1924 | } |
| 1925 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1926 | func (f *OpenOltFlowMgr) deletePendingFlows(ctx context.Context, Intf uint32, onuID int32, uniID int32) { |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1927 | pnFlDelKey := pendingFlowDeleteKey{Intf, uint32(onuID), uint32(uniID)} |
| 1928 | if val, ok := f.pendingFlowDelete.Load(pnFlDelKey); ok { |
| 1929 | if val.(int) > 0 { |
| 1930 | pnFlDels := val.(int) - 1 |
| 1931 | if pnFlDels > 0 { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [ |