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" |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 22 | "encoding/hex" |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 23 | "errors" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 24 | "fmt" |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 25 | "strconv" |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 26 | "strings" |
| 27 | "sync" |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 28 | "time" |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 29 | |
Mahir Gunyel | 1d20eff | 2021-07-04 15:39:36 -0700 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v5/pkg/meters" |
| 31 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v5/pkg/flows" |
| 33 | "github.com/opencord/voltha-lib-go/v5/pkg/log" |
| 34 | tp "github.com/opencord/voltha-lib-go/v5/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" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v4/go/common" |
| 37 | ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 38 | ofp "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 39 | openoltpb2 "github.com/opencord/voltha-protos/v4/go/openolt" |
| 40 | tp_pb "github.com/opencord/voltha-protos/v4/go/tech_profile" |
| 41 | "github.com/opencord/voltha-protos/v4/go/voltha" |
Chaitrashree G S | 579fe73 | 2019-08-20 20:50:47 -0400 | [diff] [blame] | 42 | |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 43 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 44 | "google.golang.org/grpc/codes" |
| 45 | "google.golang.org/grpc/status" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 46 | ) |
| 47 | |
| 48 | const ( |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 49 | //IPProtoDhcp flow category |
| 50 | IPProtoDhcp = 17 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 51 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 52 | //IgmpProto proto value |
| 53 | IgmpProto = 2 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 54 | |
| 55 | //EapEthType eapethtype value |
| 56 | EapEthType = 0x888e |
| 57 | //LldpEthType lldp ethtype value |
| 58 | LldpEthType = 0x88cc |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 59 | //IPv4EthType IPv4 ethernet type value |
| 60 | IPv4EthType = 0x800 |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 61 | //PPPoEDEthType PPPoE discovery ethernet type value |
| 62 | PPPoEDEthType = 0x8863 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 63 | |
Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 64 | //ReservedVlan Transparent Vlan (Masked Vlan, VLAN_ANY in ONOS Flows) |
| 65 | ReservedVlan = 4096 |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 66 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 67 | //DefaultMgmtVlan default vlan value |
| 68 | DefaultMgmtVlan = 4091 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 69 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 70 | // Openolt Flow |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 71 | |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 72 | //Upstream constant |
| 73 | Upstream = "upstream" |
| 74 | //Downstream constant |
| 75 | Downstream = "downstream" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 76 | //Multicast constant |
| 77 | Multicast = "multicast" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 78 | //PacketTagType constant |
| 79 | PacketTagType = "pkt_tag_type" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 80 | //Untagged constant |
| 81 | Untagged = "untagged" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 82 | //SingleTag constant |
| 83 | SingleTag = "single_tag" |
| 84 | //DoubleTag constant |
| 85 | DoubleTag = "double_tag" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 86 | |
| 87 | // classifierInfo |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 88 | |
| 89 | //EthType constant |
| 90 | EthType = "eth_type" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 91 | //EthDst constant |
| 92 | EthDst = "eth_dst" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 93 | //TPID constant |
| 94 | TPID = "tpid" |
| 95 | //IPProto constant |
| 96 | IPProto = "ip_proto" |
| 97 | //InPort constant |
| 98 | InPort = "in_port" |
| 99 | //VlanVid constant |
| 100 | VlanVid = "vlan_vid" |
| 101 | //VlanPcp constant |
| 102 | VlanPcp = "vlan_pcp" |
| 103 | |
| 104 | //UDPDst constant |
| 105 | UDPDst = "udp_dst" |
| 106 | //UDPSrc constant |
| 107 | UDPSrc = "udp_src" |
| 108 | //Ipv4Dst constant |
| 109 | Ipv4Dst = "ipv4_dst" |
| 110 | //Ipv4Src constant |
| 111 | Ipv4Src = "ipv4_src" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 112 | //Metadata constant |
| 113 | Metadata = "metadata" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 114 | //TunnelID constant |
| 115 | TunnelID = "tunnel_id" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 116 | //Output constant |
| 117 | Output = "output" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 118 | //GroupID constant |
| 119 | GroupID = "group_id" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 120 | // Actions |
| 121 | |
| 122 | //PopVlan constant |
| 123 | PopVlan = "pop_vlan" |
| 124 | //PushVlan constant |
| 125 | PushVlan = "push_vlan" |
| 126 | //TrapToHost constant |
| 127 | TrapToHost = "trap_to_host" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 128 | //MaxMeterBand constant |
| 129 | MaxMeterBand = 2 |
| 130 | //VlanPCPMask contant |
| 131 | VlanPCPMask = 0xFF |
| 132 | //VlanvIDMask constant |
| 133 | VlanvIDMask = 0xFFF |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 134 | //IntfID constant |
| 135 | IntfID = "intfId" |
| 136 | //OnuID constant |
| 137 | OnuID = "onuId" |
| 138 | //UniID constant |
| 139 | UniID = "uniId" |
| 140 | //PortNo constant |
| 141 | PortNo = "portNo" |
| 142 | //AllocID constant |
| 143 | AllocID = "allocId" |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 144 | //GemID constant |
| 145 | GemID = "gemId" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 146 | |
| 147 | //NoneOnuID constant |
| 148 | NoneOnuID = -1 |
| 149 | //NoneUniID constant |
| 150 | NoneUniID = -1 |
Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 151 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 152 | // Max number of flows that can be queued per ONU |
| 153 | maxConcurrentFlowsPerOnu = 20 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 154 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 155 | bitMapPrefix = "0b" |
| 156 | pbit1 = '1' |
| 157 | ) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 158 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 159 | type schedQueue struct { |
| 160 | direction tp_pb.Direction |
| 161 | intfID uint32 |
| 162 | onuID uint32 |
| 163 | uniID uint32 |
| 164 | tpID uint32 |
| 165 | uniPort uint32 |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 166 | tpInst interface{} |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 167 | meterID uint32 |
| 168 | flowMetadata *voltha.FlowMetadata |
| 169 | } |
| 170 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 171 | type flowContext struct { |
| 172 | intfID uint32 |
| 173 | onuID uint32 |
| 174 | uniID uint32 |
| 175 | portNo uint32 |
| 176 | classifier map[string]interface{} |
| 177 | action map[string]interface{} |
| 178 | logicalFlow *ofp.OfpFlowStats |
| 179 | allocID uint32 |
| 180 | gemPortID uint32 |
| 181 | tpID uint32 |
| 182 | pbitToGem map[uint32]uint32 |
| 183 | gemToAes map[uint32]bool |
| 184 | } |
| 185 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 186 | // This control block is created per flow add/remove and pushed on the incomingFlows channel slice |
| 187 | // The flowControlBlock is then picked by the perOnuFlowHandlerRoutine for further processing. |
| 188 | // There is on perOnuFlowHandlerRoutine routine per ONU that constantly monitors for any incoming |
| 189 | // flow and processes it serially |
| 190 | type flowControlBlock struct { |
| 191 | ctx context.Context // Flow handler context |
| 192 | addFlow bool // if true flow to be added, else removed |
| 193 | flow *voltha.OfpFlowStats // Flow message |
| 194 | flowMetadata *voltha.FlowMetadata // FlowMetadata that contains flow meter information. This can be nil for Flow remove |
| 195 | errChan *chan error // channel to report the Flow handling error |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 198 | //OpenOltFlowMgr creates the Structure of OpenOltFlowMgr obj |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 199 | type OpenOltFlowMgr struct { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 200 | ponPortIdx uint32 // Pon Port this FlowManager is responsible for |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 201 | techprofile tp.TechProfileIf |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 202 | deviceHandler *DeviceHandler |
| 203 | grpMgr *OpenOltGroupMgr |
| 204 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 205 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 206 | gemToFlowIDs map[uint32][]uint64 // gem port id to flow ids |
| 207 | gemToFlowIDsKey sync.RWMutex // lock to be used to access the gemToFlowIDs map |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 208 | |
| 209 | packetInGemPort map[rsrcMgr.PacketInInfoKey]uint32 //packet in gem port local cache |
| 210 | packetInGemPortLock sync.RWMutex |
| 211 | |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 212 | // TODO create a type rsrcMgr.OnuGemInfos to be used instead of []rsrcMgr.OnuGemInfo |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 213 | onuGemInfoMap map[uint32]*rsrcMgr.OnuGemInfo //onu, gem and uni info local cache -> map of onuID to OnuGemInfo |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 214 | // We need to have a global lock on the onuGemInfo map |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 215 | onuGemInfoLock sync.RWMutex |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 216 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 217 | flowIDToGems map[uint64][]uint32 |
| 218 | flowIDToGemsLock sync.RWMutex |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 219 | |
| 220 | // Slice of channels. Each channel in slice, index by ONU ID, queues flows per ONU. |
| 221 | // A go routine per ONU, waits on the unique channel (indexed by ONU ID) for incoming flows (add/remove) |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 222 | incomingFlows []chan flowControlBlock |
| 223 | stopFlowHandlerRoutine []chan bool |
| 224 | flowHandlerRoutineActive []bool |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 225 | } |
| 226 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 227 | //NewFlowManager creates OpenOltFlowMgr object and initializes the parameters |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 228 | func NewFlowManager(ctx context.Context, dh *DeviceHandler, rMgr *rsrcMgr.OpenOltResourceMgr, grpMgr *OpenOltGroupMgr, ponPortIdx uint32) *OpenOltFlowMgr { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 229 | 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] | 230 | var flowMgr OpenOltFlowMgr |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 231 | var err error |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 232 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 233 | flowMgr.deviceHandler = dh |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 234 | flowMgr.ponPortIdx = ponPortIdx |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 235 | flowMgr.grpMgr = grpMgr |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 236 | flowMgr.resourceMgr = rMgr |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 237 | if err = flowMgr.populateTechProfilePerPonPort(ctx); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 238 | logger.Errorw(ctx, "error-while-populating-tech-profile-mgr", log.Fields{"err": err}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 239 | return nil |
| 240 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 241 | flowMgr.gemToFlowIDs = make(map[uint32][]uint64) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 242 | flowMgr.packetInGemPort = make(map[rsrcMgr.PacketInInfoKey]uint32) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 243 | flowMgr.flowIDToGems = make(map[uint64][]uint32) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 244 | |
| 245 | // Create a slice of buffered channels for handling concurrent flows per ONU. |
| 246 | // The additional entry (+1) is to handle the NNI trap flows on a separate channel from individual ONUs channel |
| 247 | flowMgr.incomingFlows = make([]chan flowControlBlock, MaxOnusPerPon+1) |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 248 | flowMgr.stopFlowHandlerRoutine = make([]chan bool, MaxOnusPerPon+1) |
| 249 | flowMgr.flowHandlerRoutineActive = make([]bool, MaxOnusPerPon+1) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 250 | for i := range flowMgr.incomingFlows { |
| 251 | flowMgr.incomingFlows[i] = make(chan flowControlBlock, maxConcurrentFlowsPerOnu) |
Girish Gowdra | 0c9ac29 | 2021-11-22 14:34:40 -0800 | [diff] [blame] | 252 | flowMgr.stopFlowHandlerRoutine[i] = make(chan bool) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 253 | // Spin up a go routine to handling incoming flows (add/remove). |
| 254 | // There will be on go routine per ONU. |
| 255 | // This routine will be blocked on the flowMgr.incomingFlows[onu-id] channel for incoming flows. |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 256 | flowMgr.flowHandlerRoutineActive[i] = true |
| 257 | go flowMgr.perOnuFlowHandlerRoutine(i, flowMgr.incomingFlows[i], flowMgr.stopFlowHandlerRoutine[i]) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 258 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 259 | flowMgr.onuGemInfoMap = make(map[uint32]*rsrcMgr.OnuGemInfo) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 260 | //Load the onugem info cache from kv store on flowmanager start |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 261 | onuIDStart := flowMgr.deviceHandler.deviceInfo.OnuIdStart |
| 262 | onuIDEnd := flowMgr.deviceHandler.deviceInfo.OnuIdEnd |
| 263 | for onuID := onuIDStart; onuID <= onuIDEnd; onuID++ { |
| 264 | // check for a valid serial number in onuGem as GetOnuGemInfo can return nil error in case of nothing found in the path. |
Gamze Abaka | 3e26851 | 2021-09-08 01:14:33 +0000 | [diff] [blame] | 265 | onugem, err := rMgr.GetOnuGemInfo(ctx, ponPortIdx, onuID) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 266 | if err == nil && onugem != nil && onugem.SerialNumber != "" { |
| 267 | flowMgr.onuGemInfoMap[onuID] = onugem |
| 268 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 269 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 270 | |
| 271 | //Load flowID list per gem map And gemIDs per flow per interface from the kvstore. |
| 272 | flowMgr.loadFlowIDsForGemAndGemIDsForFlow(ctx) |
| 273 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 274 | //load interface to multicast queue map from kv store |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 275 | flowMgr.grpMgr.LoadInterfaceToMulticastQueueMap(ctx) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 276 | logger.Info(ctx, "initialization-of-flow-manager-success") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 277 | return &flowMgr |
| 278 | } |
| 279 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 280 | func (f *OpenOltFlowMgr) registerFlow(ctx context.Context, flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 281 | if !deviceFlow.ReplicateFlow && deviceFlow.GemportId > 0 { |
| 282 | // Flow is not replicated in this case, we need to register the flow for a single gem-port |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 283 | return f.registerFlowIDForGemAndGemIDForFlow(ctx, uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId), flowFromCore) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 284 | } else if deviceFlow.ReplicateFlow && len(deviceFlow.PbitToGemport) > 0 { |
| 285 | // Flow is replicated in this case. We need to register the flow for all the gem-ports it is replicated to. |
| 286 | for _, gemPort := range deviceFlow.PbitToGemport { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 287 | if err := f.registerFlowIDForGemAndGemIDForFlow(ctx, uint32(deviceFlow.AccessIntfId), gemPort, flowFromCore); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 288 | return err |
| 289 | } |
Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 290 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 291 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 292 | return nil |
| 293 | } |
| 294 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 295 | func (f *OpenOltFlowMgr) registerFlowIDForGemAndGemIDForFlow(ctx context.Context, accessIntfID uint32, gemPortID uint32, flowFromCore *ofp.OfpFlowStats) error { |
| 296 | // update gem->flows map |
| 297 | f.gemToFlowIDsKey.Lock() |
| 298 | flowIDList, ok := f.gemToFlowIDs[gemPortID] |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 299 | if !ok { |
| 300 | flowIDList = []uint64{flowFromCore.Id} |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 301 | } else { |
| 302 | flowIDList = appendUnique64bit(flowIDList, flowFromCore.Id) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 303 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 304 | f.gemToFlowIDs[gemPortID] = flowIDList |
| 305 | f.gemToFlowIDsKey.Unlock() |
| 306 | |
| 307 | // update flow->gems map |
| 308 | f.flowIDToGemsLock.Lock() |
| 309 | if _, ok := f.flowIDToGems[flowFromCore.Id]; !ok { |
| 310 | f.flowIDToGems[flowFromCore.Id] = []uint32{gemPortID} |
| 311 | } else { |
| 312 | f.flowIDToGems[flowFromCore.Id] = appendUnique32bit(f.flowIDToGems[flowFromCore.Id], gemPortID) |
| 313 | } |
| 314 | f.flowIDToGemsLock.Unlock() |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 315 | |
| 316 | // update the flowids for a gem to the KVstore |
| 317 | return f.resourceMgr.UpdateFlowIDsForGem(ctx, accessIntfID, gemPortID, flowIDList) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 320 | func (f *OpenOltFlowMgr) processAddFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 321 | 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] | 322 | UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) error { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 323 | var allocID uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 324 | var gemPorts []uint32 |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 325 | var TpInst interface{} |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 326 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 327 | logger.Infow(ctx, "dividing-flow", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 328 | "device-id": f.deviceHandler.device.Id, |
| 329 | "intf-id": intfID, |
| 330 | "onu-id": onuID, |
| 331 | "uni-id": uniID, |
| 332 | "port-no": portNo, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 333 | "classifier": classifierInfo, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 334 | "action": actionInfo, |
| 335 | "usmeter-iD": UsMeterID, |
| 336 | "dsmeter-iD": DsMeterID, |
| 337 | "tp-id": TpID}) |
Matt Jeanneret | 7719961 | 2019-07-26 18:08:35 -0400 | [diff] [blame] | 338 | // only create tcont/gemports if there is actually an onu id. otherwise BAL throws an error. Usually this |
| 339 | // is because the flow is an NNI flow and there would be no onu resources associated with it |
| 340 | // TODO: properly deal with NNI flows |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 341 | if onuID == 0 { |
Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 342 | cause := "no-onu-id-for-flow" |
| 343 | fields := log.Fields{ |
| 344 | "onu": onuID, |
| 345 | "port-no": portNo, |
| 346 | "classifer": classifierInfo, |
| 347 | "action": actionInfo, |
| 348 | "device-id": f.deviceHandler.device.Id} |
| 349 | logger.Errorw(ctx, cause, fields) |
| 350 | return olterrors.NewErrNotFound(cause, fields, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 351 | } |
| 352 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 353 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 354 | logger.Debugw(ctx, "uni-port-path", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 355 | "uni": uni, |
| 356 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 357 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 358 | logger.Debugw(ctx, "dividing-flow-create-tcont-gem-ports", log.Fields{ |
| 359 | "device-id": f.deviceHandler.device.Id, |
| 360 | "intf-id": intfID, |
| 361 | "onu-id": onuID, |
| 362 | "uni-id": uniID, |
| 363 | "port-no": portNo, |
| 364 | "classifier": classifierInfo, |
| 365 | "action": actionInfo, |
| 366 | "usmeter-id": UsMeterID, |
| 367 | "dsmeter-id": DsMeterID, |
| 368 | "tp-id": TpID}) |
| 369 | allocID, gemPorts, TpInst = f.createTcontGemports(ctx, intfID, onuID, uniID, uni, portNo, TpID, UsMeterID, DsMeterID, flowMetadata) |
| 370 | if allocID == 0 || gemPorts == nil || TpInst == nil { |
| 371 | logger.Error(ctx, "alloc-id-gem-ports-tp-unavailable") |
| 372 | return olterrors.NewErrNotFound( |
| 373 | "alloc-id-gem-ports-tp-unavailable", |
| 374 | nil, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 375 | } |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 376 | args := make(map[string]uint32) |
| 377 | args[IntfID] = intfID |
| 378 | args[OnuID] = onuID |
| 379 | args[UniID] = uniID |
| 380 | args[PortNo] = portNo |
| 381 | args[AllocID] = allocID |
| 382 | |
| 383 | /* Flows can be added specific to gemport if p-bits are received. |
| 384 | * If no pbit mentioned then adding flows for all gemports |
| 385 | */ |
| 386 | f.checkAndAddFlow(ctx, args, classifierInfo, actionInfo, flow, TpInst, gemPorts, TpID, uni) |
| 387 | |
Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 388 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 389 | } |
| 390 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 391 | // 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] | 392 | func (f *OpenOltFlowMgr) CreateSchedulerQueues(ctx context.Context, sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 393 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 394 | logger.Debugw(ctx, "CreateSchedulerQueues", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 395 | log.Fields{"dir": sq.direction, |
| 396 | "intf-id": sq.intfID, |
| 397 | "onu-id": sq.onuID, |
| 398 | "uni-id": sq.uniID, |
| 399 | "tp-id": sq.tpID, |
| 400 | "meter-id": sq.meterID, |
| 401 | "tp-inst": sq.tpInst, |
| 402 | "flowmetadata": sq.flowMetadata, |
| 403 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 404 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 405 | Direction, err := verifyMeterIDAndGetDirection(sq.meterID, sq.direction) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 406 | if err != nil { |
| 407 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* Lets make a simple assumption that if the meter-id is present on the KV store, |
| 411 | * then the scheduler and queues configuration is applied on the OLT device |
| 412 | * in the given direction. |
| 413 | */ |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 414 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 415 | var SchedCfg *tp_pb.SchedulerConfig |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 416 | meterInfo, err := f.resourceMgr.GetMeterInfoForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 417 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 418 | return olterrors.NewErrNotFound("meter", |
| 419 | log.Fields{"intf-id": sq.intfID, |
| 420 | "onu-id": sq.onuID, |
| 421 | "uni-id": sq.uniID, |
| 422 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 423 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 424 | |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 425 | if meterInfo != nil { |
| 426 | logger.Debugw(ctx, "scheduler-already-created-for-upstream", log.Fields{"device-id": f.deviceHandler.device.Id, "meter-id": sq.meterID}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 427 | if meterInfo.MeterID == sq.meterID { |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 428 | if err := f.resourceMgr.HandleMeterInfoRefCntUpdate(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID, true); err != nil { |
| 429 | return err |
| 430 | } |
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", |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 435 | "kv-store-meter-id": meterInfo.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 { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 447 | SchedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 448 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 449 | SchedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 452 | found := false |
| 453 | meterInfo = &rsrcMgr.MeterInfo{} |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 454 | if sq.flowMetadata != nil { |
| 455 | for _, meter := range sq.flowMetadata.Meters { |
| 456 | if sq.meterID == meter.MeterId { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 457 | meterInfo.MeterID = meter.MeterId |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 458 | meterInfo.RefCnt = 1 // initialize it to 1, since this is the first flow that referenced the meter id. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 459 | logger.Debugw(ctx, "found-meter-config-from-flowmetadata", |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 460 | log.Fields{"meter": meter, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 461 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 462 | found = true |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 463 | break |
| 464 | } |
| 465 | } |
| 466 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 467 | 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] | 468 | } |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 469 | if !found { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 470 | return olterrors.NewErrNotFound("meterbands", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 471 | "reason": "Could-not-get-meterbands-from-flowMetadata", |
| 472 | "flow-metadata": sq.flowMetadata, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 473 | "meter-id": sq.meterID, |
| 474 | "device-id": f.deviceHandler.device.Id}, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 475 | } |
Gamze Abaka | 0117442 | 2021-03-10 06:55:27 +0000 | [diff] [blame] | 476 | |
| 477 | var TrafficShaping *tp_pb.TrafficShapingInfo |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 478 | if TrafficShaping, err = meters.GetTrafficShapingInfo(ctx, sq.flowMetadata.Meters[0]); err != nil { |
Gamze Abaka | 0117442 | 2021-03-10 06:55:27 +0000 | [diff] [blame] | 479 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 480 | "reason": "invalid-meter-config", |
| 481 | "meter-id": sq.meterID, |
| 482 | "device-id": f.deviceHandler.device.Id}, nil) |
| 483 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 484 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 485 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), SchedCfg, TrafficShaping)} |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 486 | TrafficSched[0].TechProfileId = sq.tpID |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 487 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 488 | if err := f.pushSchedulerQueuesToDevice(ctx, sq, TrafficSched); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 489 | return olterrors.NewErrAdapter("failure-pushing-traffic-scheduler-and-queues-to-device", |
| 490 | log.Fields{"intf-id": sq.intfID, |
| 491 | "direction": sq.direction, |
| 492 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 493 | } |
| 494 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 495 | /* After we successfully applied the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 496 | * store the meter id on the KV store, for further reference. |
| 497 | */ |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 498 | if err := f.resourceMgr.StoreMeterInfoForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID, meterInfo); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 499 | return olterrors.NewErrAdapter("failed-updating-meter-id", |
| 500 | log.Fields{"onu-id": sq.onuID, |
| 501 | "meter-id": sq.meterID, |
| 502 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 503 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 504 | logger.Infow(ctx, "updated-meter-info-into-kv-store-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 505 | log.Fields{"direction": Direction, |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 506 | "meter-info": meterInfo, |
| 507 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 508 | return nil |
| 509 | } |
| 510 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 511 | func (f *OpenOltFlowMgr) pushSchedulerQueuesToDevice(ctx context.Context, sq schedQueue, TrafficSched []*tp_pb.TrafficScheduler) error { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 512 | trafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 513 | |
| 514 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 515 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 516 | log.Fields{"intf-id": sq.intfID, |
| 517 | "direction": sq.direction, |
| 518 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 521 | if allocExists := f.isAllocUsedByAnotherUNI(ctx, sq); !allocExists { |
| 522 | logger.Debugw(ctx, "sending-traffic-scheduler-create-to-device", |
| 523 | log.Fields{ |
| 524 | "direction": sq.direction, |
| 525 | "TrafficScheds": TrafficSched, |
| 526 | "device-id": f.deviceHandler.device.Id, |
| 527 | "intfID": sq.intfID, |
| 528 | "onuID": sq.onuID, |
| 529 | "uniID": sq.uniID}) |
| 530 | if _, err := f.deviceHandler.Client.CreateTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
| 531 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 532 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 533 | TrafficScheds: TrafficSched}); err != nil { |
| 534 | return olterrors.NewErrAdapter("failed-to-create-traffic-schedulers-in-device", log.Fields{"TrafficScheds": TrafficSched}, err) |
| 535 | } |
| 536 | logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{ |
| 537 | "direction": sq.direction, |
| 538 | "traffic-queues": trafficQueues, |
| 539 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 543 | // downstream queues. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 544 | logger.Debugw(ctx, "sending-traffic-queues-create-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 545 | log.Fields{"direction": sq.direction, |
| 546 | "traffic-queues": trafficQueues, |
| 547 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 548 | if _, err := f.deviceHandler.Client.CreateTrafficQueues(ctx, |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 549 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 550 | UniId: sq.uniID, PortNo: sq.uniPort, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 551 | TrafficQueues: trafficQueues, |
| 552 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 553 | 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] | 554 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 555 | logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 556 | "direction": sq.direction, |
| 557 | "traffic-queues": trafficQueues, |
| 558 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 559 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 560 | if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 561 | multicastTrafficQueues := f.techprofile.GetMulticastTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance)) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 562 | if len(multicastTrafficQueues) > 0 { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 563 | if _, present := f.grpMgr.GetInterfaceToMcastQueueMap(sq.intfID); !present { //assumed that there is only one queue per PON for the multicast service |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 564 | //the default queue with multicastQueuePerPonPort.Priority per a pon interface is used for multicast service |
| 565 | //just put it in interfaceToMcastQueueMap to use for building group members |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 566 | 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] | 567 | multicastQueuePerPonPort := multicastTrafficQueues[0] |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 568 | val := &QueueInfoBrief{ |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 569 | gemPortID: multicastQueuePerPonPort.GemportId, |
| 570 | servicePriority: multicastQueuePerPonPort.Priority, |
| 571 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 572 | f.grpMgr.UpdateInterfaceToMcastQueueMap(sq.intfID, val) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 573 | //also store the queue info in kv store |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 574 | if err := f.resourceMgr.AddMcastQueueForIntf(ctx, sq.intfID, multicastQueuePerPonPort.GemportId, multicastQueuePerPonPort.Priority); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 575 | logger.Errorw(ctx, "failed-to-add-mcast-queue", log.Fields{"err": err}) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 576 | return err |
| 577 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 578 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 579 | 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] | 580 | } |
| 581 | } |
| 582 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 583 | return nil |
| 584 | } |
| 585 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 586 | // 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] | 587 | func (f *OpenOltFlowMgr) RemoveSchedulerQueues(ctx context.Context, sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 588 | |
| 589 | var Direction string |
| 590 | var SchedCfg *tp_pb.SchedulerConfig |
| 591 | var err error |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 592 | logger.Infow(ctx, "removing-schedulers-and-queues-in-olt", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 593 | log.Fields{ |
| 594 | "direction": sq.direction, |
| 595 | "intf-id": sq.intfID, |
| 596 | "onu-id": sq.onuID, |
| 597 | "uni-id": sq.uniID, |
| 598 | "uni-port": sq.uniPort, |
| 599 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 600 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 601 | SchedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 602 | Direction = "upstream" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 603 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 604 | SchedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 605 | Direction = "downstream" |
| 606 | } |
| 607 | |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 608 | TrafficShaping := &tp_pb.TrafficShapingInfo{} // this info is not really useful for the agent during flow removal. Just use default values. |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 609 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 610 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), SchedCfg, TrafficShaping)} |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 611 | TrafficSched[0].TechProfileId = sq.tpID |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 612 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 613 | TrafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 614 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 615 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 616 | log.Fields{ |
| 617 | "intf-id": sq.intfID, |
| 618 | "direction": sq.direction, |
| 619 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 620 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 621 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 622 | if _, err = f.deviceHandler.Client.RemoveTrafficQueues(ctx, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 623 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 624 | UniId: sq.uniID, PortNo: sq.uniPort, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 625 | TrafficQueues: TrafficQueues, |
| 626 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 627 | return olterrors.NewErrAdapter("unable-to-remove-traffic-queues-from-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 628 | log.Fields{ |
| 629 | "intf-id": sq.intfID, |
| 630 | "traffic-queues": TrafficQueues, |
| 631 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 632 | } |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 633 | logger.Infow(ctx, "removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, "trafficQueues": TrafficQueues}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 634 | |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 635 | if allocExists := f.isAllocUsedByAnotherUNI(ctx, sq); !allocExists { |
| 636 | if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
| 637 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 638 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 639 | TrafficScheds: TrafficSched}); err != nil { |
| 640 | return olterrors.NewErrAdapter("unable-to-remove-traffic-schedulers-from-device", |
| 641 | log.Fields{ |
| 642 | "intf-id": sq.intfID, |
| 643 | "traffic-schedulers": TrafficSched, |
| 644 | "onu-id": sq.onuID, |
| 645 | "uni-id": sq.uniID, |
| 646 | "uni-port": sq.uniPort}, err) |
| 647 | } |
| 648 | |
| 649 | logger.Infow(ctx, "removed-traffic-schedulers-successfully", |
| 650 | log.Fields{"device-id": f.deviceHandler.device.Id, |
| 651 | "intf-id": sq.intfID, |
| 652 | "onu-id": sq.onuID, |
| 653 | "uni-id": sq.uniID, |
| 654 | "uni-port": sq.uniPort}) |
| 655 | |
| 656 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 657 | allocID := sq.tpInst.(*tp_pb.TechProfileInstance).UsScheduler.AllocId |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 658 | f.resourceMgr.FreeAllocID(ctx, sq.intfID, sq.onuID, sq.uniID, allocID) |
| 659 | // Delete the TCONT on the ONU. |
| 660 | uni := getUniPortPath(f.deviceHandler.device.Id, sq.intfID, int32(sq.onuID), int32(sq.uniID)) |
| 661 | tpPath := f.getTPpath(ctx, sq.intfID, uni, sq.tpID) |
| 662 | if err := f.sendDeleteTcontToChild(ctx, sq.intfID, sq.onuID, sq.uniID, allocID, tpPath); err != nil { |
| 663 | logger.Errorw(ctx, "error-processing-delete-tcont-towards-onu", |
| 664 | log.Fields{ |
| 665 | "intf": sq.intfID, |
| 666 | "onu-id": sq.onuID, |
| 667 | "uni-id": sq.uniID, |
| 668 | "device-id": f.deviceHandler.device.Id, |
| 669 | "alloc-id": allocID}) |
| 670 | } |
| 671 | } |
| 672 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 673 | |
| 674 | /* After we successfully remove the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 675 | * delete the meter id on the KV store. |
| 676 | */ |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 677 | err = f.resourceMgr.RemoveMeterInfoForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 678 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 679 | return olterrors.NewErrAdapter("unable-to-remove-meter", |
| 680 | log.Fields{ |
| 681 | "onu": sq.onuID, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 682 | "device-id": f.deviceHandler.device.Id, |
| 683 | "intf-id": sq.intfID, |
| 684 | "onu-id": sq.onuID, |
| 685 | "uni-id": sq.uniID, |
| 686 | "uni-port": sq.uniPort}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 687 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 688 | logger.Infow(ctx, "removed-meter-from-KV-store-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 689 | log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 690 | "dir": Direction, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 691 | "device-id": f.deviceHandler.device.Id, |
| 692 | "intf-id": sq.intfID, |
| 693 | "onu-id": sq.onuID, |
| 694 | "uni-id": sq.uniID, |
| 695 | "uni-port": sq.uniPort}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 696 | return err |
| 697 | } |
| 698 | |
Girish Gowdra | 37f13fa | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 699 | // We are trying to force remove the schedulers and queues here if one exists for the given key. |
| 700 | // We ignore any errors encountered in the process. The errors most likely are encountered when |
| 701 | // the schedulers and queues are already cleared for the given key. |
| 702 | func (f *OpenOltFlowMgr) forceRemoveSchedulerQueues(ctx context.Context, sq schedQueue) { |
| 703 | |
| 704 | var schedCfg *tp_pb.SchedulerConfig |
| 705 | var err error |
| 706 | logger.Infow(ctx, "removing-schedulers-and-queues-in-olt", |
| 707 | log.Fields{ |
| 708 | "direction": sq.direction, |
| 709 | "intf-id": sq.intfID, |
| 710 | "onu-id": sq.onuID, |
| 711 | "uni-id": sq.uniID, |
| 712 | "uni-port": sq.uniPort, |
| 713 | "tp-id": sq.tpID, |
| 714 | "device-id": f.deviceHandler.device.Id}) |
| 715 | if sq.direction == tp_pb.Direction_UPSTREAM { |
| 716 | schedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| 717 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
| 718 | schedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| 719 | } |
| 720 | |
| 721 | TrafficShaping := &tp_pb.TrafficShapingInfo{} // this info is not really useful for the agent during flow removal. Just use default values. |
| 722 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), schedCfg, TrafficShaping)} |
| 723 | TrafficSched[0].TechProfileId = sq.tpID |
| 724 | |
| 725 | // Remove traffic queues. Ignore any errors, just log them. |
| 726 | if TrafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction); err != nil { |
| 727 | logger.Errorw(ctx, "error retrieving traffic queue", log.Fields{ |
| 728 | "direction": sq.direction, |
| 729 | "intf-id": sq.intfID, |
| 730 | "onu-id": sq.onuID, |
| 731 | "uni-id": sq.uniID, |
| 732 | "uni-port": sq.uniPort, |
| 733 | "tp-id": sq.tpID, |
| 734 | "device-id": f.deviceHandler.device.Id, |
| 735 | "err": err}) |
| 736 | } else { |
| 737 | if _, err = f.deviceHandler.Client.RemoveTrafficQueues(ctx, |
| 738 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 739 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 740 | TrafficQueues: TrafficQueues, |
| 741 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
| 742 | logger.Warnw(ctx, "error removing traffic queue", log.Fields{ |
| 743 | "direction": sq.direction, |
| 744 | "intf-id": sq.intfID, |
| 745 | "onu-id": sq.onuID, |
| 746 | "uni-id": sq.uniID, |
| 747 | "uni-port": sq.uniPort, |
| 748 | "tp-id": sq.tpID, |
| 749 | "device-id": f.deviceHandler.device.Id, |
| 750 | "err": err}) |
| 751 | |
| 752 | } else { |
| 753 | logger.Infow(ctx, "removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, |
| 754 | "direction": sq.direction, |
| 755 | "intf-id": sq.intfID, |
| 756 | "onu-id": sq.onuID, |
| 757 | "uni-id": sq.uniID, |
| 758 | "uni-port": sq.uniPort, |
| 759 | "tp-id": sq.tpID}) |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | // Remove traffic schedulers. Ignore any errors, just log them. |
| 764 | if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
| 765 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 766 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 767 | TrafficScheds: TrafficSched}); err != nil { |
| 768 | logger.Warnw(ctx, "error removing traffic scheduler", log.Fields{ |
| 769 | "direction": sq.direction, |
| 770 | "intf-id": sq.intfID, |
| 771 | "onu-id": sq.onuID, |
| 772 | "uni-id": sq.uniID, |
| 773 | "uni-port": sq.uniPort, |
| 774 | "tp-id": sq.tpID, |
| 775 | "device-id": f.deviceHandler.device.Id, |
| 776 | "err": err}) |
| 777 | } else { |
| 778 | logger.Infow(ctx, "removed-traffic-schedulers-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, |
| 779 | "direction": sq.direction, |
| 780 | "intf-id": sq.intfID, |
| 781 | "onu-id": sq.onuID, |
| 782 | "uni-id": sq.uniID, |
| 783 | "uni-port": sq.uniPort, |
| 784 | "tp-id": sq.tpID}) |
| 785 | } |
| 786 | } |
| 787 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 788 | // This function allocates tconts and GEM ports for an ONU |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 789 | 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] | 790 | var allocIDs []uint32 |
| 791 | var allgemPortIDs []uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 792 | var gemPortIDs []uint32 |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 793 | tpInstanceExists := false |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 794 | var err error |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 795 | allocIDs = f.resourceMgr.GetCurrentAllocIDsForOnu(ctx, intfID, onuID, uniID) |
| 796 | allgemPortIDs = f.resourceMgr.GetCurrentGEMPortIDsForOnu(ctx, intfID, onuID, uniID) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 797 | tpPath := f.getTPpath(ctx, intfID, uni, TpID) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 798 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 799 | logger.Debugw(ctx, "creating-new-tcont-and-gem", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 800 | "intf-id": intfID, |
| 801 | "onu-id": onuID, |
| 802 | "uni-id": uniID, |
| 803 | "device-id": f.deviceHandler.device.Id, |
| 804 | "tp-id": TpID}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 805 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 806 | // Check tech profile instance already exists for derived port name |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 807 | techProfileInstance, _ := f.techprofile.GetTPInstance(ctx, tpPath) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 808 | if techProfileInstance == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 809 | logger.Infow(ctx, "tp-instance-not-found--creating-new", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 810 | log.Fields{ |
| 811 | "path": tpPath, |
| 812 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 813 | techProfileInstance, err = f.techprofile.CreateTechProfileInstance(ctx, TpID, uni, intfID) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 814 | if err != nil { |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 815 | // This should not happen, something wrong in KV backend transaction |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 816 | logger.Errorw(ctx, "tp-instance-create-failed", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 817 | log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 818 | "err": err, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 819 | "tp-id": TpID, |
| 820 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 821 | return 0, nil, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 822 | } |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 823 | if err := f.resourceMgr.UpdateTechProfileIDForOnu(ctx, intfID, onuID, uniID, TpID); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 824 | logger.Warnw(ctx, "failed-to-update-tech-profile-id", log.Fields{"err": err}) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 825 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 826 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 827 | logger.Debugw(ctx, "tech-profile-instance-already-exist-for-given port-name", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 828 | log.Fields{ |
| 829 | "uni": uni, |
| 830 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 831 | tpInstanceExists = true |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 832 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 833 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 834 | switch tpInst := techProfileInstance.(type) { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 835 | case *tp_pb.TechProfileInstance: |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 836 | if UsMeterID != 0 { |
| 837 | sq := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 838 | uniPort: uniPort, tpInst: techProfileInstance, meterID: UsMeterID, flowMetadata: flowMetadata} |
| 839 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 840 | logger.Errorw(ctx, "CreateSchedulerQueues-failed-upstream", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 841 | log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 842 | "err": err, |
Matteo Scandolo | 2f6b5bc | 2020-09-17 13:58:10 -0700 | [diff] [blame] | 843 | "onu-id": onuID, |
| 844 | "uni-id": uniID, |
| 845 | "intf-id": intfID, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 846 | "meter-id": UsMeterID, |
| 847 | "device-id": f.deviceHandler.device.Id}) |
| 848 | return 0, nil, nil |
| 849 | } |
| 850 | } |
| 851 | if DsMeterID != 0 { |
| 852 | sq := schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 853 | uniPort: uniPort, tpInst: techProfileInstance, meterID: DsMeterID, flowMetadata: flowMetadata} |
| 854 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 855 | logger.Errorw(ctx, "CreateSchedulerQueues-failed-downstream", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 856 | log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 857 | "err": err, |
Matteo Scandolo | 2f6b5bc | 2020-09-17 13:58:10 -0700 | [diff] [blame] | 858 | "onu-id": onuID, |
| 859 | "uni-id": uniID, |
| 860 | "intf-id": intfID, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 861 | "meter-id": DsMeterID, |
| 862 | "device-id": f.deviceHandler.device.Id}) |
| 863 | return 0, nil, nil |
| 864 | } |
| 865 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 866 | allocID := tpInst.UsScheduler.AllocId |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 867 | for _, gem := range tpInst.UpstreamGemPortAttributeList { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 868 | gemPortIDs = append(gemPortIDs, gem.GemportId) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 869 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 870 | allocIDs = appendUnique32bit(allocIDs, allocID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 871 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 872 | if tpInstanceExists { |
| 873 | return allocID, gemPortIDs, techProfileInstance |
| 874 | } |
| 875 | |
| 876 | for _, gemPortID := range gemPortIDs { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 877 | allgemPortIDs = appendUnique32bit(allgemPortIDs, gemPortID) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 878 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 879 | logger.Infow(ctx, "allocated-tcont-and-gem-ports", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 880 | log.Fields{ |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 881 | "intf-id": intfID, |
| 882 | "onu-id": onuID, |
| 883 | "uni-id": uniID, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 884 | "alloc-ids": allocIDs, |
| 885 | "gemports": allgemPortIDs, |
| 886 | "device-id": f.deviceHandler.device.Id}) |
| 887 | // Send Tconts and GEM ports to KV store |
| 888 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 889 | return allocID, gemPortIDs, techProfileInstance |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 890 | case *openoltpb2.EponTechProfileInstance: |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 891 | // CreateSchedulerQueues for EPON needs to be implemented here |
| 892 | // when voltha-protos for EPON is completed. |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 893 | allocID := tpInst.AllocId |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 894 | for _, gem := range tpInst.UpstreamQueueAttributeList { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 895 | gemPortIDs = append(gemPortIDs, gem.GemportId) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 896 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 897 | allocIDs = appendUnique32bit(allocIDs, allocID) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 898 | |
| 899 | if tpInstanceExists { |
| 900 | return allocID, gemPortIDs, techProfileInstance |
| 901 | } |
| 902 | |
| 903 | for _, gemPortID := range gemPortIDs { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 904 | allgemPortIDs = appendUnique32bit(allgemPortIDs, gemPortID) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 905 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 906 | logger.Infow(ctx, "allocated-tcont-and-gem-ports", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 907 | log.Fields{ |
| 908 | "alloc-ids": allocIDs, |
| 909 | "gemports": allgemPortIDs, |
| 910 | "device-id": f.deviceHandler.device.Id}) |
| 911 | // Send Tconts and GEM ports to KV store |
| 912 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
| 913 | return allocID, gemPortIDs, techProfileInstance |
| 914 | default: |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 915 | logger.Errorw(ctx, "unknown-tech", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 916 | log.Fields{ |
| 917 | "tpInst": tpInst}) |
| 918 | return 0, nil, nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 919 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 920 | } |
| 921 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 922 | 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] | 923 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 924 | logger.Debugw(ctx, "storing-allocated-tconts-and-gem-ports-into-KV-store", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 925 | log.Fields{ |
| 926 | "intf-id": intfID, |
| 927 | "onu-id": onuID, |
| 928 | "uni-id": uniID, |
| 929 | "alloc-id": allocID, |
| 930 | "gemport-ids": gemPortIDs, |
| 931 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 932 | /* 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] | 933 | if err := f.resourceMgr.UpdateAllocIdsForOnu(ctx, intfID, onuID, uniID, allocID); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 934 | 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] | 935 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 936 | if err := f.resourceMgr.UpdateGEMPortIDsForOnu(ctx, intfID, onuID, uniID, gemPortIDs); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 937 | 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] | 938 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 939 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 940 | 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] | 941 | for _, gemPort := range gemPortIDs { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 942 | f.addGemPortToOnuInfoMap(ctx, intfID, onuID, gemPort) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 943 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 944 | } |
| 945 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 946 | func (f *OpenOltFlowMgr) populateTechProfilePerPonPort(ctx context.Context) error { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 947 | var tpCount int |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 948 | for _, techRange := range f.resourceMgr.DevInfo.Ranges { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 949 | for _, intfID := range techRange.IntfIds { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 950 | f.techprofile = f.resourceMgr.PonRsrMgr.TechProfileMgr |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 951 | tpCount++ |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 952 | logger.Debugw(ctx, "init-tech-profile-done", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 953 | log.Fields{ |
| 954 | "intf-id": intfID, |
| 955 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | //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] | 959 | if tpCount != int(f.resourceMgr.DevInfo.GetPonPorts()) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 960 | return olterrors.NewErrInvalidValue(log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 961 | "reason": "tP-count-does-not-match-number-of-pon-ports", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 962 | "tech-profile-count": tpCount, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 963 | "pon-port-count": f.resourceMgr.DevInfo.GetPonPorts(), |
| 964 | "device-id": f.deviceHandler.device.Id}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 965 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 966 | logger.Infow(ctx, "populated-techprofile-for-ponports-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 967 | log.Fields{ |
| 968 | "numofTech": tpCount, |
| 969 | "numPonPorts": f.resourceMgr.DevInfo.GetPonPorts(), |
| 970 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 971 | return nil |
| 972 | } |
| 973 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 974 | func (f *OpenOltFlowMgr) addUpstreamDataPathFlow(ctx context.Context, flowContext *flowContext) error { |
Andrea Campanella | 8f64556 | 2021-10-28 11:50:56 +0530 | [diff] [blame^] | 975 | flowContext.classifier[PacketTagType] = SingleTag // FIXME: This hardcoding needs to be removed. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 976 | logger.Debugw(ctx, "adding-upstream-data-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 977 | log.Fields{ |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 978 | "uplinkClassifier": flowContext.classifier, |
| 979 | "uplinkAction": flowContext.action}) |
| 980 | return f.addSymmetricDataPathFlow(ctx, flowContext, Upstream) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 981 | /* TODO: Install Secondary EAP on the subscriber vlan */ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 982 | } |
| 983 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 984 | func (f *OpenOltFlowMgr) addDownstreamDataPathFlow(ctx context.Context, flowContext *flowContext) error { |
| 985 | downlinkClassifier := flowContext.classifier |
| 986 | downlinkAction := flowContext.action |
| 987 | |
Andrea Campanella | 8f64556 | 2021-10-28 11:50:56 +0530 | [diff] [blame^] | 988 | // TODO: For now mark the PacketTagType as SingleTag when OLT is transparent to VLAN |
| 989 | // Per some deployment models, it is also possible that ONU operates on double tagged packets, |
| 990 | // so this hardcoding of SingeTag packet-tag-type may be problem for such deployment models. |
| 991 | // Need a better way for detection of packet tag type from OpenFlow message. |
| 992 | if _, ok := downlinkClassifier[VlanVid]; !ok { |
| 993 | downlinkClassifier[PacketTagType] = SingleTag |
| 994 | } else { |
| 995 | downlinkClassifier[PacketTagType] = DoubleTag |
| 996 | downlinkAction[PopVlan] = true |
| 997 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 998 | logger.Debugw(ctx, "adding-downstream-data-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 999 | log.Fields{ |
| 1000 | "downlinkClassifier": downlinkClassifier, |
| 1001 | "downlinkAction": downlinkAction}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1002 | // Ignore Downlink trap flow given by core, cannot do anything with this flow */ |
| 1003 | if vlan, exists := downlinkClassifier[VlanVid]; exists { |
| 1004 | 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] | 1005 | if metadata, exists := downlinkClassifier[Metadata]; exists { // inport is filled in metadata by core |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1006 | if uint32(metadata.(uint64)) == MkUniPortNum(ctx, flowContext.intfID, flowContext.onuID, flowContext.uniID) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1007 | logger.Infow(ctx, "ignoring-dl-trap-device-flow-from-core", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1008 | log.Fields{ |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1009 | "flow": flowContext.logicalFlow, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1010 | "device-id": f.deviceHandler.device.Id, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1011 | "onu-id": flowContext.onuID, |
| 1012 | "intf-id": flowContext.intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1013 | return nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1017 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1018 | |
Matt Jeanneret | ed16b7c | 2019-11-01 13:31:35 -0400 | [diff] [blame] | 1019 | // vlan_vid is a uint32. must be type asserted as such or conversion fails |
| 1020 | dlClVid, ok := downlinkClassifier[VlanVid].(uint32) |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 1021 | if ok { |
| 1022 | downlinkAction[VlanVid] = dlClVid & 0xfff |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 1023 | } |
| 1024 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1025 | return f.addSymmetricDataPathFlow(ctx, flowContext, Downstream) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1026 | } |
| 1027 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1028 | func (f *OpenOltFlowMgr) addSymmetricDataPathFlow(ctx context.Context, flowContext *flowContext, direction string) error { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1029 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1030 | intfID := flowContext.intfID |
| 1031 | onuID := flowContext.onuID |
| 1032 | uniID := flowContext.uniID |
| 1033 | classifier := flowContext.classifier |
| 1034 | action := flowContext.action |
| 1035 | allocID := flowContext.allocID |
| 1036 | gemPortID := flowContext.gemPortID |
| 1037 | tpID := flowContext.tpID |
| 1038 | logicalFlow := flowContext.logicalFlow |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1039 | logger.Infow(ctx, "adding-hsia-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1040 | log.Fields{ |
| 1041 | "intf-id": intfID, |
| 1042 | "onu-id": onuID, |
| 1043 | "uni-id": uniID, |
| 1044 | "device-id": f.deviceHandler.device.Id, |
| 1045 | "classifier": classifier, |
| 1046 | "action": action, |
| 1047 | "direction": direction, |
| 1048 | "alloc-id": allocID, |
| 1049 | "gemport-id": gemPortID, |
| 1050 | "logicalflow": *logicalFlow}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1051 | |
| 1052 | if present := f.resourceMgr.IsFlowOnKvStore(ctx, intfID, int32(onuID), int32(uniID), logicalFlow.Id); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1053 | logger.Infow(ctx, "flow-already-exists", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1054 | log.Fields{ |
| 1055 | "device-id": f.deviceHandler.device.Id, |
| 1056 | "intf-id": intfID, |
| 1057 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1058 | return nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1059 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1060 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1061 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1062 | 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] | 1063 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1064 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1065 | log.Fields{ |
| 1066 | "classifier": *classifierProto, |
| 1067 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1068 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1069 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1070 | 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] | 1071 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1072 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1073 | log.Fields{ |
| 1074 | "action": *actionProto, |
| 1075 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1076 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1077 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1078 | return olterrors.NewErrNotFound("nni-interface-id", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1079 | log.Fields{ |
| 1080 | "classifier": classifier, |
| 1081 | "action": action, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1082 | "device-id": f.deviceHandler.device.Id, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1083 | }, err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1084 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1085 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1086 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1087 | OnuId: int32(onuID), |
| 1088 | UniId: int32(uniID), |
| 1089 | FlowId: logicalFlow.Id, |
| 1090 | FlowType: direction, |
| 1091 | AllocId: int32(allocID), |
| 1092 | NetworkIntfId: int32(networkIntfID), |
| 1093 | GemportId: int32(gemPortID), |
| 1094 | Classifier: classifierProto, |
| 1095 | Action: actionProto, |
| 1096 | Priority: int32(logicalFlow.Priority), |
| 1097 | Cookie: logicalFlow.Cookie, |
| 1098 | PortNo: flowContext.portNo, |
| 1099 | TechProfileId: tpID, |
| 1100 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1101 | PbitToGemport: flowContext.pbitToGem, |
| 1102 | GemportToAes: flowContext.gemToAes, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1103 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1104 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1105 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, nil, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1106 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1107 | logger.Infow(ctx, "hsia-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1108 | log.Fields{"direction": direction, |
| 1109 | "device-id": f.deviceHandler.device.Id, |
| 1110 | "flow": flow, |
| 1111 | "intf-id": intfID, |
| 1112 | "onu-id": onuID}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1113 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1114 | return nil |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1115 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1116 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1117 | func (f *OpenOltFlowMgr) addDHCPTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| 1118 | |
| 1119 | intfID := flowContext.intfID |
| 1120 | onuID := flowContext.onuID |
| 1121 | uniID := flowContext.uniID |
| 1122 | logicalFlow := flowContext.logicalFlow |
| 1123 | classifier := flowContext.classifier |
| 1124 | action := flowContext.action |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1125 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1126 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1127 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1128 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1129 | "classifier": classifier, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1130 | "action": action, |
| 1131 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1132 | err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1133 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1134 | |
| 1135 | // Clear the action map |
| 1136 | for k := range action { |
| 1137 | delete(action, k) |
| 1138 | } |
| 1139 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1140 | action[TrapToHost] = true |
| 1141 | classifier[UDPSrc] = uint32(68) |
| 1142 | classifier[UDPDst] = uint32(67) |
| 1143 | classifier[PacketTagType] = SingleTag |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1144 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1145 | if present := f.resourceMgr.IsFlowOnKvStore(ctx, intfID, int32(onuID), int32(uniID), logicalFlow.Id); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1146 | logger.Infow(ctx, "flow-exists--not-re-adding", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1147 | log.Fields{ |
| 1148 | "device-id": f.deviceHandler.device.Id, |
| 1149 | "intf-id": intfID, |
| 1150 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1151 | return nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1152 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1153 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1154 | logger.Debugw(ctx, "creating-ul-dhcp-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1155 | log.Fields{ |
| 1156 | "ul_classifier": classifier, |
| 1157 | "ul_action": action, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1158 | "uplinkFlowId": logicalFlow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1159 | "intf-id": intfID, |
| 1160 | "onu-id": onuID, |
| 1161 | "device-id": f.deviceHandler.device.Id}) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1162 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1163 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1164 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1165 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1166 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1167 | logger.Debugw(ctx, "created-classifier-proto", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1168 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1169 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1170 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1171 | } |
| 1172 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1173 | dhcpFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1174 | OnuId: int32(onuID), |
| 1175 | UniId: int32(uniID), |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1176 | FlowId: logicalFlow.Id, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1177 | FlowType: Upstream, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1178 | AllocId: int32(flowContext.allocID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1179 | NetworkIntfId: int32(networkIntfID), |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1180 | GemportId: int32(flowContext.gemPortID), |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1181 | Classifier: classifierProto, |
| 1182 | Action: actionProto, |
| 1183 | Priority: int32(logicalFlow.Priority), |
| 1184 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1185 | PortNo: flowContext.portNo, |
| 1186 | TechProfileId: flowContext.tpID, |
| 1187 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1188 | PbitToGemport: flowContext.pbitToGem, |
| 1189 | GemportToAes: flowContext.gemToAes, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1190 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1191 | if err := f.addFlowToDevice(ctx, logicalFlow, &dhcpFlow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1192 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"dhcp-flow": dhcpFlow}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1193 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1194 | logger.Infow(ctx, "dhcp-ul-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1195 | log.Fields{ |
| 1196 | "device-id": f.deviceHandler.device.Id, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1197 | "flow-id": logicalFlow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1198 | "intf-id": intfID, |
| 1199 | "onu-id": onuID}) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1200 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1201 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1202 | } |
| 1203 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1204 | //addIGMPTrapFlow creates IGMP trap-to-host flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1205 | func (f *OpenOltFlowMgr) addIGMPTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| 1206 | delete(flowContext.classifier, VlanVid) |
| 1207 | return f.addUpstreamTrapFlow(ctx, flowContext) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | //addUpstreamTrapFlow creates a trap-to-host flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1211 | func (f *OpenOltFlowMgr) addUpstreamTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| 1212 | |
| 1213 | intfID := flowContext.intfID |
| 1214 | onuID := flowContext.onuID |
| 1215 | uniID := flowContext.uniID |
| 1216 | logicalFlow := flowContext.logicalFlow |
| 1217 | classifier := flowContext.classifier |
| 1218 | action := flowContext.action |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1219 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1220 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1221 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1222 | return olterrors.NewErrNotFound("nni-interface-id", |
| 1223 | log.Fields{ |
| 1224 | "classifier": classifier, |
| 1225 | "action": action, |
| 1226 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1227 | err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | // Clear the action map |
| 1231 | for k := range action { |
| 1232 | delete(action, k) |
| 1233 | } |
| 1234 | |
| 1235 | action[TrapToHost] = true |
| 1236 | classifier[PacketTagType] = SingleTag |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1237 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1238 | if present := f.resourceMgr.IsFlowOnKvStore(ctx, networkIntfID, int32(onuID), int32(uniID), logicalFlow.Id); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1239 | 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] | 1240 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1243 | logger.Debugw(ctx, "creating-upstream-trap-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1244 | log.Fields{ |
| 1245 | "ul_classifier": classifier, |
| 1246 | "ul_action": action, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1247 | "uplinkFlowId": logicalFlow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1248 | "device-id": f.deviceHandler.device.Id, |
| 1249 | "intf-id": intfID, |
| 1250 | "onu-id": onuID}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1251 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1252 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1253 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1254 | 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] | 1255 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1256 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1257 | log.Fields{ |
| 1258 | "classifier": *classifierProto, |
| 1259 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1260 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1261 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1262 | 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] | 1263 | } |
| 1264 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1265 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1266 | OnuId: int32(onuID), |
| 1267 | UniId: int32(uniID), |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1268 | FlowId: logicalFlow.Id, |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1269 | FlowType: Upstream, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1270 | AllocId: int32(flowContext.allocID), |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1271 | NetworkIntfId: int32(networkIntfID), |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1272 | GemportId: int32(flowContext.gemPortID), |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1273 | Classifier: classifierProto, |
| 1274 | Action: actionProto, |
| 1275 | Priority: int32(logicalFlow.Priority), |
| 1276 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1277 | PortNo: flowContext.portNo, |
| 1278 | TechProfileId: flowContext.tpID, |
| 1279 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1280 | PbitToGemport: flowContext.pbitToGem, |
| 1281 | GemportToAes: flowContext.gemToAes, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1282 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1283 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1284 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1285 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, 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] | 1286 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1287 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1288 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1291 | // Add EthType flow to device with mac, vlanId as classifier for upstream and downstream |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1292 | func (f *OpenOltFlowMgr) addEthTypeBasedFlow(ctx context.Context, flowContext *flowContext, vlanID uint32, ethType uint32) error { |
| 1293 | intfID := flowContext.intfID |
| 1294 | onuID := flowContext.onuID |
| 1295 | uniID := flowContext.uniID |
| 1296 | portNo := flowContext.portNo |
| 1297 | allocID := flowContext.allocID |
| 1298 | gemPortID := flowContext.gemPortID |
| 1299 | logicalFlow := flowContext.logicalFlow |
| 1300 | classifier := flowContext.classifier |
| 1301 | action := flowContext.action |
| 1302 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1303 | logger.Infow(ctx, "adding-ethType-flow-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1304 | log.Fields{ |
| 1305 | "intf-id": intfID, |
| 1306 | "onu-id": onuID, |
| 1307 | "port-no": portNo, |
| 1308 | "alloc-id": allocID, |
| 1309 | "gemport-id": gemPortID, |
| 1310 | "vlan-id": vlanID, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1311 | "flow": logicalFlow, |
| 1312 | "ethType": ethType}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1313 | |
| 1314 | uplinkClassifier := make(map[string]interface{}) |
| 1315 | uplinkAction := make(map[string]interface{}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1316 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1317 | // Fill Classfier |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1318 | uplinkClassifier[EthType] = ethType |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1319 | uplinkClassifier[PacketTagType] = SingleTag |
| 1320 | uplinkClassifier[VlanVid] = vlanID |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1321 | uplinkClassifier[VlanPcp] = classifier[VlanPcp] |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1322 | // Fill action |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1323 | uplinkAction[TrapToHost] = true |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1324 | if present := f.resourceMgr.IsFlowOnKvStore(ctx, intfID, int32(onuID), int32(uniID), logicalFlow.Id); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1325 | logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1326 | "device-id": f.deviceHandler.device.Id, |
| 1327 | "onu-id": onuID, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1328 | "intf-id": intfID, |
| 1329 | "ethType": ethType}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1330 | return nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1331 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1332 | //Add Uplink EthType Flow |
| 1333 | logger.Debugw(ctx, "creating-ul-ethType-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1334 | log.Fields{ |
| 1335 | "ul_classifier": uplinkClassifier, |
| 1336 | "ul_action": uplinkAction, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1337 | "uplinkFlowId": logicalFlow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1338 | "device-id": f.deviceHandler.device.Id, |
| 1339 | "intf-id": intfID, |
| 1340 | "onu-id": onuID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1341 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1342 | classifierProto, err := makeOpenOltClassifierField(uplinkClassifier) |
| 1343 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1344 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 1345 | "classifier": uplinkClassifier, |
| 1346 | "device-id": f.deviceHandler.device.Id}, err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1347 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1348 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1349 | log.Fields{ |
| 1350 | "classifier": *classifierProto, |
| 1351 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1352 | actionProto, err := makeOpenOltActionField(uplinkAction, uplinkClassifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1353 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1354 | 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] | 1355 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1356 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1357 | log.Fields{ |
| 1358 | "action": *actionProto, |
| 1359 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1360 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1361 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1362 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1363 | "classifier": classifier, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1364 | "action": action, |
| 1365 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1366 | err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1367 | } |
| 1368 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1369 | upstreamFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1370 | OnuId: int32(onuID), |
| 1371 | UniId: int32(uniID), |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1372 | FlowId: logicalFlow.Id, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1373 | FlowType: Upstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1374 | AllocId: int32(allocID), |
| 1375 | NetworkIntfId: int32(networkIntfID), |
| 1376 | GemportId: int32(gemPortID), |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1377 | Classifier: classifierProto, |
| 1378 | Action: actionProto, |
| 1379 | Priority: int32(logicalFlow.Priority), |
| 1380 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1381 | PortNo: portNo, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1382 | TechProfileId: flowContext.tpID, |
| 1383 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1384 | PbitToGemport: flowContext.pbitToGem, |
| 1385 | GemportToAes: flowContext.gemToAes, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1386 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1387 | if err := f.addFlowToDevice(ctx, logicalFlow, &upstreamFlow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1388 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow": upstreamFlow}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1389 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1390 | logger.Infow(ctx, "ethType-ul-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1391 | log.Fields{ |
| 1392 | "device-id": f.deviceHandler.device.Id, |
| 1393 | "onu-id": onuID, |
| 1394 | "intf-id": intfID, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1395 | "ethType": ethType, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1396 | }) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1397 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1398 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1399 | } |
| 1400 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1401 | func makeOpenOltClassifierField(classifierInfo map[string]interface{}) (*openoltpb2.Classifier, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1402 | var classifier openoltpb2.Classifier |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1403 | |
| 1404 | classifier.EthType, _ = classifierInfo[EthType].(uint32) |
| 1405 | classifier.IpProto, _ = classifierInfo[IPProto].(uint32) |
| 1406 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 1407 | if vlanID != ReservedVlan { |
| 1408 | vid := vlanID & VlanvIDMask |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1409 | classifier.OVid = vid |
| 1410 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1411 | } |
Andrea Campanella | 8f64556 | 2021-10-28 11:50:56 +0530 | [diff] [blame^] | 1412 | // The classifierInfo[Metadata] carries the vlan that the OLT see when it receives packet from the ONU |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1413 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 1414 | vid := uint32(metadata) |
Andrea Campanella | 8f64556 | 2021-10-28 11:50:56 +0530 | [diff] [blame^] | 1415 | // Set the OVid or IVid classifier based on the whether OLT is using a transparent tag or not |
| 1416 | // If OLT is using transparent tag mechanism, then it classifies whatever tag it sees to/from ONU which |
| 1417 | //is OVid from the perspective of the OLT. When OLT also places or pops the outer tag, then classifierInfo[Metadata] |
| 1418 | // becomes the IVid. |
| 1419 | if classifier.OVid != 0 && classifier.OVid != ReservedVlan { // This is case when classifier.OVid is not set |
| 1420 | if vid != ReservedVlan { |
| 1421 | classifier.IVid = vid |
| 1422 | } |
| 1423 | } else { |
| 1424 | if vid != ReservedVlan { |
| 1425 | classifier.OVid = vid |
| 1426 | } |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1427 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1428 | } |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1429 | // 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] | 1430 | if vlanPcp, ok := classifierInfo[VlanPcp].(uint32); ok { |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1431 | classifier.OPbits = vlanPcp |
| 1432 | } else { |
| 1433 | classifier.OPbits = VlanPCPMask |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1434 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1435 | classifier.SrcPort, _ = classifierInfo[UDPSrc].(uint32) |
| 1436 | classifier.DstPort, _ = classifierInfo[UDPDst].(uint32) |
| 1437 | classifier.DstIp, _ = classifierInfo[Ipv4Dst].(uint32) |
| 1438 | classifier.SrcIp, _ = classifierInfo[Ipv4Src].(uint32) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1439 | classifier.DstMac, _ = classifierInfo[EthDst].([]uint8) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1440 | if pktTagType, ok := classifierInfo[PacketTagType].(string); ok { |
| 1441 | classifier.PktTagType = pktTagType |
| 1442 | |
| 1443 | switch pktTagType { |
| 1444 | case SingleTag: |
| 1445 | case DoubleTag: |
| 1446 | case Untagged: |
| 1447 | default: |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1448 | return nil, olterrors.NewErrInvalidValue(log.Fields{"packet-tag-type": pktTagType}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1449 | } |
| 1450 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1451 | return &classifier, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1452 | } |
| 1453 | |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1454 | 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] | 1455 | var actionCmd openoltpb2.ActionCmd |
| 1456 | var action openoltpb2.Action |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1457 | action.Cmd = &actionCmd |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1458 | if _, ok := actionInfo[PopVlan]; ok { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1459 | action.Cmd.RemoveOuterTag = true |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1460 | if _, ok := actionInfo[VlanPcp]; ok { |
| 1461 | action.Cmd.RemarkInnerPbits = true |
| 1462 | action.IPbits = actionInfo[VlanPcp].(uint32) |
| 1463 | if _, ok := actionInfo[VlanVid]; ok { |
| 1464 | action.Cmd.TranslateInnerTag = true |
| 1465 | action.IVid = actionInfo[VlanVid].(uint32) |
| 1466 | } |
| 1467 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1468 | } else if _, ok := actionInfo[PushVlan]; ok { |
| 1469 | action.OVid = actionInfo[VlanVid].(uint32) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1470 | action.Cmd.AddOuterTag = true |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1471 | if _, ok := actionInfo[VlanPcp]; ok { |
| 1472 | action.OPbits = actionInfo[VlanPcp].(uint32) |
| 1473 | action.Cmd.RemarkOuterPbits = true |
| 1474 | if _, ok := classifierInfo[VlanVid]; ok { |
| 1475 | action.IVid = classifierInfo[VlanVid].(uint32) |
| 1476 | action.Cmd.TranslateInnerTag = true |
| 1477 | } |
| 1478 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1479 | } else if _, ok := actionInfo[TrapToHost]; ok { |
| 1480 | action.Cmd.TrapToHost = actionInfo[TrapToHost].(bool) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1481 | } |
Andrea Campanella | 8f64556 | 2021-10-28 11:50:56 +0530 | [diff] [blame^] | 1482 | // When OLT is transparent to vlans no-action is valid. |
| 1483 | /* |
| 1484 | else { |
| 1485 | return nil, olterrors.NewErrInvalidValue(log.Fields{"action-command": actionInfo}, nil) |
| 1486 | } |
| 1487 | */ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1488 | return &action, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1489 | } |
| 1490 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1491 | // getTPpath return the ETCD path for a given UNI port |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1492 | func (f *OpenOltFlowMgr) getTPpath(ctx context.Context, intfID uint32, uniPath string, TpID uint32) string { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1493 | return f.techprofile.GetTechProfileInstanceKey(ctx, TpID, uniPath) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1494 | } |
| 1495 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1496 | // DeleteTechProfileInstances removes the tech profile instances from persistent storage |
Girish Gowdra | 37f13fa | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1497 | // We also force release scheduler and queues associated with the tp instance. Theoretically there could be |
| 1498 | // an issue if the upstream scheduler (DBA) is shared across multiple UNI and we force release it, given that |
| 1499 | // this function is only meant to clean up TP instances of a given UNI. But in practicality this routine |
| 1500 | // is only meant to be called when the clean up of resource for the whole ONU is taking place. |
| 1501 | // The reason for introducing the force cleanup of scheduler and queues (on the OLT) was introduced here |
| 1502 | // because it was observed that if the ONU device was deleted too soon after the flows were |
| 1503 | // unprovisioned on that ONU, the scheduler and queue removal pertinent to that ONU would remain |
| 1504 | // uncleaned on the OLT. So we force clean up here and ignore any error that OLT returns during the |
| 1505 | // force cleanup (possible if the OLT has already cleared those resources). |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1506 | func (f *OpenOltFlowMgr) DeleteTechProfileInstances(ctx context.Context, intfID uint32, onuID uint32, uniID uint32) error { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1507 | tpIDList := f.resourceMgr.GetTechProfileIDForOnu(ctx, intfID, onuID, uniID) |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1508 | uniPortName := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| 1509 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1510 | for _, tpID := range tpIDList { |
Girish Gowdra | 37f13fa | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1511 | |
| 1512 | // Force cleanup scheduler/queues -- start |
| 1513 | uniPortNum := MkUniPortNum(ctx, intfID, onuID, uniID) |
| 1514 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| 1515 | tpPath := f.getTPpath(ctx, intfID, uni, tpID) |
| 1516 | tpInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
| 1517 | if err != nil || tpInst == nil { // This should not happen, something wrong in KV backend transaction |
| 1518 | logger.Warnw(ctx, "tech-profile-not-in-kv-store", |
| 1519 | log.Fields{ |
| 1520 | "tp-id": tpID, |
| 1521 | "path": tpPath}) |
| 1522 | } |
| 1523 | switch tpInstance := tpInst.(type) { |
| 1524 | case *tp_pb.TechProfileInstance: |
| 1525 | f.forceRemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: tpID, uniPort: uniPortNum, tpInst: tpInstance}) |
| 1526 | f.forceRemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: tpID, uniPort: uniPortNum, tpInst: tpInstance}) |
| 1527 | } |
| 1528 | // Force cleanup scheduler/queues -- end |
| 1529 | |
| 1530 | // Now remove the tp instance |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1531 | if err := f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1532 | logger.Errorw(ctx, "delete-tech-profile-failed", log.Fields{"err": err, "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1533 | // return err |
| 1534 | // We should continue to delete tech-profile instances for other TP IDs |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1535 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1536 | logger.Debugw(ctx, "tech-profile-instance-deleted", log.Fields{"device-id": f.deviceHandler.device.Id, "uniPortName": uniPortName, "tp-id": tpID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1537 | } |
| 1538 | return nil |
| 1539 | } |
| 1540 | |
| 1541 | // DeleteTechProfileInstance removes the tech profile instance from persistent storage |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1542 | 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] | 1543 | if uniPortName == "" { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1544 | uniPortName = getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1545 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1546 | if err := f.techprofile.DeleteTechProfileInstance(ctx, tpID, uniPortName); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1547 | return olterrors.NewErrAdapter("failed-to-delete-tp-instance-from-kv-store", |
| 1548 | log.Fields{ |
| 1549 | "tp-id": tpID, |
| 1550 | "uni-port-name": uniPortName, |
| 1551 | "device-id": f.deviceHandler.device.Id}, err) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1552 | } |
| 1553 | return nil |
| 1554 | } |
| 1555 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1556 | 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] | 1557 | |
| 1558 | var intfID uint32 |
| 1559 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1560 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1561 | */ |
| 1562 | if deviceFlow.AccessIntfId != -1 { |
| 1563 | intfID = uint32(deviceFlow.AccessIntfId) |
| 1564 | } else { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1565 | // We need to log the valid interface ID. |
| 1566 | // For trap-on-nni flows, the access_intf_id is invalid (-1), so choose the network_intf_id. |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1567 | intfID = uint32(deviceFlow.NetworkIntfId) |
| 1568 | } |
| 1569 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1570 | logger.Debugw(ctx, "sending-flow-to-device-via-grpc", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1571 | "flow": *deviceFlow, |
| 1572 | "device-id": f.deviceHandler.device.Id, |
| 1573 | "intf-id": intfID}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1574 | _, err := f.deviceHandler.Client.FlowAdd(log.WithSpanFromContext(context.Background(), ctx), deviceFlow) |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1575 | |
| 1576 | st, _ := status.FromError(err) |
| 1577 | if st.Code() == codes.AlreadyExists { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1578 | logger.Debug(ctx, "flow-already-exists", log.Fields{ |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1579 | "err": err, |
| 1580 | "deviceFlow": deviceFlow, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1581 | "device-id": f.deviceHandler.device.Id, |
| 1582 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1583 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1584 | } |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1585 | |
| 1586 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1587 | logger.Errorw(ctx, "failed-to-add-flow-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1588 | log.Fields{"err": err, |
| 1589 | "device-flow": deviceFlow, |
| 1590 | "device-id": f.deviceHandler.device.Id, |
| 1591 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1592 | return err |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1593 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1594 | logger.Infow(ctx, "flow-added-to-device-successfully ", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1595 | log.Fields{ |
| 1596 | "flow": *deviceFlow, |
| 1597 | "device-id": f.deviceHandler.device.Id, |
| 1598 | "intf-id": intfID}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1599 | |
| 1600 | // Case of trap-on-nni flow when deviceFlow.AccessIntfId is invalid (-1) |
| 1601 | if deviceFlow.AccessIntfId != -1 { |
| 1602 | // No need to register the flow if it is a trap on nni flow. |
| 1603 | if err := f.registerFlow(ctx, logicalFlow, deviceFlow); err != nil { |
| 1604 | logger.Errorw(ctx, "failed-to-register-flow", log.Fields{"err": err}) |
| 1605 | return err |
| 1606 | } |
| 1607 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1608 | return nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1609 | } |
| 1610 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1611 | func (f *OpenOltFlowMgr) removeFlowFromDevice(ctx context.Context, deviceFlow *openoltpb2.Flow, ofFlowID uint64) error { |
| 1612 | logger.Debugw(ctx, "sending-flow-to-device-via-grpc", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1613 | log.Fields{ |
| 1614 | "flow": *deviceFlow, |
| 1615 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1616 | _, err := f.deviceHandler.Client.FlowRemove(log.WithSpanFromContext(context.Background(), ctx), deviceFlow) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1617 | if err != nil { |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1618 | if f.deviceHandler.device.ConnectStatus == common.ConnectStatus_UNREACHABLE { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1619 | logger.Warnw(ctx, "can-not-remove-flow-from-device--unreachable", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1620 | log.Fields{ |
| 1621 | "err": err, |
| 1622 | "deviceFlow": deviceFlow, |
| 1623 | "device-id": f.deviceHandler.device.Id}) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1624 | //Assume the flow is removed |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1625 | return nil |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1626 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1627 | return olterrors.NewErrFlowOp("remove", deviceFlow.FlowId, log.Fields{"deviceFlow": deviceFlow}, err) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1628 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1629 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1630 | logger.Infow(ctx, "flow-removed-from-device-successfully", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1631 | "of-flow-id": ofFlowID, |
| 1632 | "flow": *deviceFlow, |
| 1633 | "device-id": f.deviceHandler.device.Id, |
| 1634 | }) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1635 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1636 | } |
| 1637 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1638 | 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] | 1639 | |
| 1640 | classifierInfo := make(map[string]interface{}) |
| 1641 | actionInfo := make(map[string]interface{}) |
| 1642 | |
| 1643 | classifierInfo[EthType] = uint32(LldpEthType) |
| 1644 | classifierInfo[PacketTagType] = Untagged |
| 1645 | actionInfo[TrapToHost] = true |
| 1646 | |
| 1647 | // LLDP flow is installed to trap LLDP packets on the NNI port. |
| 1648 | // We manage flow_id resource pool on per PON port basis. |
| 1649 | // Since this situation is tricky, as a hack, we pass the NNI port |
| 1650 | // index (network_intf_id) as PON port Index for the flow_id resource |
| 1651 | // pool. Also, there is no ONU Id available for trapping LLDP packets |
| 1652 | // on NNI port, use onu_id as -1 (invalid) |
| 1653 | // ****************** CAVEAT ******************* |
| 1654 | // This logic works if the NNI Port Id falls within the same valid |
| 1655 | // range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1656 | // we need to have a re-look at this. |
| 1657 | // ********************************************* |
| 1658 | |
| 1659 | var onuID = -1 |
| 1660 | var uniID = -1 |
| 1661 | var gemPortID = -1 |
| 1662 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1663 | networkInterfaceID, err := IntfIDFromNniPortNum(ctx, portNo) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1664 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1665 | return olterrors.NewErrInvalidValue(log.Fields{"nni-port-number": portNo}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1666 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1667 | if present := f.resourceMgr.IsFlowOnKvStore(ctx, networkInterfaceID, int32(onuID), int32(uniID), flow.Id); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1668 | 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] | 1669 | return nil |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1670 | } |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1671 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1672 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 1673 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1674 | return olterrors.NewErrInvalidValue( |
| 1675 | log.Fields{ |
| 1676 | "classifier": classifierInfo, |
| 1677 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1678 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1679 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1680 | log.Fields{ |
| 1681 | "classifier": *classifierProto, |
| 1682 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1683 | actionProto, err := makeOpenOltActionField(actionInfo, classifierInfo) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1684 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1685 | return olterrors.NewErrInvalidValue( |
| 1686 | log.Fields{ |
| 1687 | "action": actionInfo, |
| 1688 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1689 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1690 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1691 | log.Fields{ |
| 1692 | "action": *actionProto, |
| 1693 | "device-id": f.deviceHandler.device.Id}) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1694 | |
| 1695 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 1696 | OnuId: int32(onuID), // OnuId not required |
| 1697 | UniId: int32(uniID), // UniId not used |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1698 | FlowId: flow.Id, |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1699 | FlowType: Downstream, |
| 1700 | NetworkIntfId: int32(networkInterfaceID), |
| 1701 | GemportId: int32(gemPortID), |
| 1702 | Classifier: classifierProto, |
| 1703 | Action: actionProto, |
| 1704 | Priority: int32(flow.Priority), |
| 1705 | Cookie: flow.Cookie, |
| 1706 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1707 | if err := f.addFlowToDevice(ctx, flow, &downstreamflow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1708 | return olterrors.NewErrFlowOp("add", flow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1709 | log.Fields{ |
| 1710 | "flow": downstreamflow, |
| 1711 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1712 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1713 | logger.Infow(ctx, "lldp-trap-on-nni-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1714 | log.Fields{ |
| 1715 | "device-id": f.deviceHandler.device.Id, |
| 1716 | "onu-id": onuID, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1717 | "flow-id": flow.Id}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1718 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1719 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1720 | } |
| 1721 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1722 | func getUniPortPath(oltID string, intfID uint32, onuID int32, uniID int32) string { |
| 1723 | 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] | 1724 | } |
| 1725 | |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1726 | //getOnuDevice to fetch onu from cache or core. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1727 | 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] | 1728 | onuKey := f.deviceHandler.formOnuKey(intfID, onuID) |
| 1729 | onuDev, ok := f.deviceHandler.onus.Load(onuKey) |
| 1730 | if !ok { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1731 | logger.Debugw(ctx, "couldnt-find-onu-in-cache", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1732 | log.Fields{ |
| 1733 | "intf-id": intfID, |
| 1734 | "onu-id": onuID, |
| 1735 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1736 | onuDevice, err := f.getChildDevice(ctx, intfID, onuID) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1737 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1738 | return nil, olterrors.NewErrNotFound("onu-child-device", |
| 1739 | log.Fields{ |
| 1740 | "onu-id": onuID, |
| 1741 | "intf-id": intfID, |
| 1742 | "device-id": f.deviceHandler.device.Id}, err) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1743 | } |
| 1744 | onuDev = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuDevice.ProxyAddress.OnuId, onuDevice.ProxyAddress.ChannelId, onuDevice.ProxyAddress.DeviceId, false) |
| 1745 | //better to ad the device to cache here. |
| 1746 | f.deviceHandler.StoreOnuDevice(onuDev.(*OnuDevice)) |
| 1747 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1748 | logger.Debugw(ctx, "found-onu-in-cache", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1749 | log.Fields{ |
| 1750 | "intf-id": intfID, |
| 1751 | "onu-id": onuID, |
| 1752 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | return onuDev.(*OnuDevice), nil |
| 1756 | } |
| 1757 | |
| 1758 | //getChildDevice to fetch onu |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1759 | func (f *OpenOltFlowMgr) getChildDevice(ctx context.Context, intfID uint32, onuID uint32) (*voltha.Device, error) { |
| 1760 | logger.Infow(ctx, "GetChildDevice", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1761 | log.Fields{ |
| 1762 | "pon-port": intfID, |
| 1763 | "onu-id": onuID, |
| 1764 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1765 | parentPortNo := IntfIDToPortNo(intfID, voltha.Port_PON_OLT) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1766 | onuDevice, err := f.deviceHandler.GetChildDevice(ctx, parentPortNo, onuID) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1767 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1768 | return nil, olterrors.NewErrNotFound("onu", |
| 1769 | log.Fields{ |
| 1770 | "interface-id": parentPortNo, |
| 1771 | "onu-id": onuID, |
| 1772 | "device-id": f.deviceHandler.device.Id}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1773 | err) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1774 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1775 | logger.Infow(ctx, "successfully-received-child-device-from-core", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1776 | log.Fields{ |
| 1777 | "device-id": f.deviceHandler.device.Id, |
| 1778 | "child_device_id": onuDevice.Id, |
| 1779 | "child_device_sn": onuDevice.SerialNumber}) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1780 | return onuDevice, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1781 | } |
| 1782 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1783 | func (f *OpenOltFlowMgr) sendDeleteGemPortToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, gemPortID uint32, tpPath string) error { |
| 1784 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1785 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1786 | logger.Debugw(ctx, "couldnt-find-onu-child-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1787 | log.Fields{ |
| 1788 | "intf-id": intfID, |
| 1789 | "onu-id": onuID, |
| 1790 | "uni-id": uniID, |
| 1791 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1792 | return err |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1793 | } |
| 1794 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1795 | delGemPortMsg := &ic.InterAdapterDeleteGemPortMessage{UniId: uniID, TpInstancePath: tpPath, GemPortId: gemPortID} |
| 1796 | logger.Infow(ctx, "sending-gem-port-delete-to-openonu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1797 | log.Fields{ |
| 1798 | "msg": *delGemPortMsg, |
| 1799 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1800 | if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(log.WithSpanFromContext(context.Background(), ctx), |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1801 | delGemPortMsg, |
| 1802 | ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST, |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 1803 | f.deviceHandler.openOLT.config.Topic, |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1804 | onuDev.deviceType, |
| 1805 | onuDev.deviceID, |
| 1806 | onuDev.proxyDeviceID, ""); sendErr != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1807 | return olterrors.NewErrCommunication("send-delete-gem-port-to-onu-adapter", |
| 1808 | log.Fields{ |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 1809 | "from-adapter": f.deviceHandler.openOLT.config.Topic, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1810 | "to-adapter": onuDev.deviceType, |
| 1811 | "onu-id": onuDev.deviceID, |
| 1812 | "proxyDeviceID": onuDev.proxyDeviceID, |
| 1813 | "device-id": f.deviceHandler.device.Id}, sendErr) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1814 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1815 | logger.Infow(ctx, "success-sending-del-gem-port-to-onu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1816 | log.Fields{ |
| 1817 | "msg": delGemPortMsg, |
| 1818 | "from-adapter": f.deviceHandler.device.Type, |
| 1819 | "to-adapter": onuDev.deviceType, |
| 1820 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1821 | return nil |
| 1822 | } |
| 1823 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1824 | func (f *OpenOltFlowMgr) sendDeleteTcontToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID uint32, tpPath string) error { |
| 1825 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1826 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1827 | logger.Warnw(ctx, "couldnt-find-onu-child-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1828 | log.Fields{ |
| 1829 | "intf-id": intfID, |
| 1830 | "onu-id": onuID, |
| 1831 | "uni-id": uniID, |
| 1832 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1833 | return err |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1834 | } |
| 1835 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1836 | delTcontMsg := &ic.InterAdapterDeleteTcontMessage{UniId: uniID, TpInstancePath: tpPath, AllocId: allocID} |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1837 | logger.Debugw(ctx, "sending-tcont-delete-to-openonu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1838 | log.Fields{ |
| 1839 | "msg": *delTcontMsg, |
| 1840 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1841 | if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(log.WithSpanFromContext(context.Background(), ctx), |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1842 | delTcontMsg, |
| 1843 | ic.InterAdapterMessageType_DELETE_TCONT_REQUEST, |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 1844 | f.deviceHandler.openOLT.config.Topic, |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1845 | onuDev.deviceType, |
| 1846 | onuDev.deviceID, |
| 1847 | onuDev.proxyDeviceID, ""); sendErr != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1848 | return olterrors.NewErrCommunication("send-delete-tcont-to-onu-adapter", |
| 1849 | log.Fields{ |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 1850 | "from-adapter": f.deviceHandler.openOLT.config.Topic, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1851 | "to-adapter": onuDev.deviceType, "onu-id": onuDev.deviceID, |
| 1852 | "proxyDeviceID": onuDev.proxyDeviceID, |
| 1853 | "device-id": f.deviceHandler.device.Id}, sendErr) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1854 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1855 | logger.Infow(ctx, "success-sending-del-tcont-to-onu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1856 | log.Fields{ |
| 1857 | "msg": delTcontMsg, |
| 1858 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1859 | return nil |
| 1860 | } |
| 1861 | |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 1862 | // Once the gemport is released for a given onu, it also has to be cleared from local cache |
| 1863 | // which was used for deriving the gemport->logicalPortNo during packet-in. |
| 1864 | // Otherwise stale info continues to exist after gemport is freed and wrong logicalPortNo |
| 1865 | // is conveyed to ONOS during packet-in OF message. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1866 | func (f *OpenOltFlowMgr) deleteGemPortFromLocalCache(ctx context.Context, intfID uint32, onuID uint32, gemPortID uint32) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1867 | logger.Infow(ctx, "deleting-gem-from-local-cache", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1868 | log.Fields{ |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 1869 | "gem-port-id": gemPortID, |
| 1870 | "intf-id": intfID, |
| 1871 | "onu-id": onuID, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1872 | "device-id": f.deviceHandler.device.Id}) |
| 1873 | f.onuGemInfoLock.RLock() |
| 1874 | onugem, ok := f.onuGemInfoMap[onuID] |
| 1875 | f.onuGemInfoLock.RUnlock() |
| 1876 | if !ok { |
| 1877 | logger.Warnw(ctx, "onu gem info already cleared from cache", log.Fields{ |
| 1878 | "gem-port-id": gemPortID, |
| 1879 | "intf-id": intfID, |
| 1880 | "onu-id": onuID, |
| 1881 | "device-id": f.deviceHandler.device.Id}) |
| 1882 | return |
| 1883 | } |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 1884 | deleteLoop: |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1885 | for j, gem := range onugem.GemPorts { |
| 1886 | // If the gemport is found, delete it from local cache. |
| 1887 | if gem == gemPortID { |
| 1888 | onugem.GemPorts = append(onugem.GemPorts[:j], onugem.GemPorts[j+1:]...) |
| 1889 | f.onuGemInfoLock.Lock() |
| 1890 | f.onuGemInfoMap[onuID] = onugem |
| 1891 | f.onuGemInfoLock.Unlock() |
| 1892 | logger.Infow(ctx, "removed-gemport-from-local-cache", |
| 1893 | log.Fields{ |
| 1894 | "intf-id": intfID, |
| 1895 | "onu-id": onuID, |
| 1896 | "deletedgemport-id": gemPortID, |
| 1897 | "gemports": onugem.GemPorts, |
| 1898 | "device-id": f.deviceHandler.device.Id}) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 1899 | break deleteLoop |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 1904 | //clearResources clears pon resources in kv store and the device |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 1905 | // nolint: gocyclo |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1906 | func (f *OpenOltFlowMgr) clearResources(ctx context.Context, intfID uint32, onuID int32, uniID int32, |
Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 1907 | gemPortID int32, flowID uint64, portNum uint32, tpID uint32) error { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1908 | |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1909 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, onuID, uniID) |
| 1910 | tpPath := f.getTPpath(ctx, intfID, uni, tpID) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1911 | logger.Debugw(ctx, "getting-techprofile-instance-for-subscriber", |
| 1912 | log.Fields{ |
| 1913 | "tpPath": tpPath, |
| 1914 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1915 | |
| 1916 | used := f.isGemPortUsedByAnotherFlow(uint32(gemPortID)) |
| 1917 | |
| 1918 | if used { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1919 | f.gemToFlowIDsKey.RLock() |
| 1920 | flowIDs := f.gemToFlowIDs[uint32(gemPortID)] |
| 1921 | f.gemToFlowIDsKey.RUnlock() |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1922 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1923 | for i, flowIDinMap := range flowIDs { |
| 1924 | if flowIDinMap == flowID { |
| 1925 | flowIDs = append(flowIDs[:i], flowIDs[i+1:]...) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1926 | f.gemToFlowIDsKey.Lock() |
| 1927 | f.gemToFlowIDs[uint32(gemPortID)] = flowIDs |
| 1928 | f.gemToFlowIDsKey.Unlock() |
| 1929 | // everytime gemToFlowIDs cache is updated the same should be updated |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1930 | // in kv store by calling UpdateFlowIDsForGem |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1931 | if err := f.resourceMgr.UpdateFlowIDsForGem(ctx, intfID, uint32(gemPortID), flowIDs); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1932 | return err |
| 1933 | } |
| 1934 | break |
| 1935 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1936 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1937 | logger.Debugw(ctx, "gem-port-id-is-still-used-by-other-flows", |
| 1938 | log.Fields{ |
| 1939 | "gemport-id": gemPortID, |
| 1940 | "usedByFlows": flowIDs, |
| 1941 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1942 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1943 | return nil |
| 1944 | } |
| 1945 | logger.Debugf(ctx, "gem-port-id %d is-not-used-by-another-flow--releasing-the-gem-port", gemPortID) |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1946 | f.deleteGemPortFromLocalCache(ctx, intfID, uint32(onuID), uint32(gemPortID)) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1947 | _ = f.resourceMgr.RemoveGemFromOnuGemInfo(ctx, intfID, uint32(onuID), uint32(gemPortID)) // ignore error and proceed. |
| 1948 | //everytime an entry is deleted from gemToFlowIDs cache, the same should be updated in kv as well |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1949 | // by calling DeleteFlowIDsForGem |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1950 | f.gemToFlowIDsKey.Lock() |
| 1951 | delete(f.gemToFlowIDs, uint32(gemPortID)) |
| 1952 | f.gemToFlowIDsKey.Unlock() |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1953 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1954 | f.resourceMgr.DeleteFlowIDsForGem(ctx, intfID, uint32(gemPortID)) |
| 1955 | |
| 1956 | f.resourceMgr.FreeGemPortID(ctx, intfID, uint32(onuID), uint32(uniID), uint32(gemPortID)) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1957 | |
Mahir Gunyel | 1d20eff | 2021-07-04 15:39:36 -0700 | [diff] [blame] | 1958 | //First remove TCONT from child if needed. Then remove the GEM. |
| 1959 | //It is expected from child to clean ani side conf if all GEMs of TP are deleted. |
| 1960 | //Before this, ensure that the related TCONT deletions are informed to child. |
| 1961 | //Refer to VOL-4215. |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1962 | techprofileInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
| 1963 | if err != nil || techprofileInst == nil { // This should not happen, something wrong in KV backend transaction |
| 1964 | return olterrors.NewErrNotFound("tech-profile-in-kv-store", |
| 1965 | log.Fields{ |
| 1966 | "tp-id": tpID, |
| 1967 | "path": tpPath}, err) |
| 1968 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1969 | switch techprofileInst := techprofileInst.(type) { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1970 | case *tp_pb.TechProfileInstance: |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 1971 | ok, _ := f.isTechProfileUsedByAnotherGem(ctx, intfID, uint32(onuID), uint32(uniID), techprofileInst, uint32(gemPortID)) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1972 | if !ok { |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1973 | if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, intfID, uint32(onuID), uint32(uniID), tpID); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1974 | logger.Warn(ctx, err) |
| 1975 | } |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1976 | if err := f.DeleteTechProfileInstance(ctx, intfID, uint32(onuID), uint32(uniID), "", tpID); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1977 | logger.Warn(ctx, err) |
| 1978 | } |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1979 | if err := f.RemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst}); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1980 | logger.Warn(ctx, err) |
| 1981 | } |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1982 | if err := f.RemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst}); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1983 | logger.Warn(ctx, err) |
| 1984 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1985 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1986 | case *tp_pb.EponTechProfileInstance: |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1987 | if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, intfID, uint32(onuID), uint32(uniID), tpID); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1988 | logger.Warn(ctx, err) |
| 1989 | } |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1990 | if err := f.DeleteTechProfileInstance(ctx, intfID, uint32(onuID), uint32(uniID), "", tpID); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1991 | logger.Warn(ctx, err) |
| 1992 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1993 | f.resourceMgr.FreeAllocID(ctx, intfID, uint32(onuID), uint32(uniID), techprofileInst.AllocId) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1994 | // Delete the TCONT on the ONU. |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1995 | if err := f.sendDeleteTcontToChild(ctx, intfID, uint32(onuID), uint32(uniID), techprofileInst.AllocId, tpPath); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1996 | logger.Errorw(ctx, "error-processing-delete-tcont-towards-onu", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1997 | log.Fields{ |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1998 | "intf": intfID, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1999 | "onu-id": onuID, |
| 2000 | "uni-id": uniID, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2001 | "device-id": f.deviceHandler.device.Id, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2002 | "alloc-id": techprofileInst.AllocId}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2003 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2004 | default: |
| 2005 | logger.Errorw(ctx, "error-unknown-tech", |
| 2006 | log.Fields{ |
| 2007 | "techprofileInst": techprofileInst}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2008 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2009 | |
Mahir Gunyel | 1d20eff | 2021-07-04 15:39:36 -0700 | [diff] [blame] | 2010 | // Delete the gem port on the ONU. Send Gem Removal After TCONT removal. |
| 2011 | if err := f.sendDeleteGemPortToChild(ctx, intfID, uint32(onuID), uint32(uniID), uint32(gemPortID), tpPath); err != nil { |
| 2012 | logger.Errorw(ctx, "error-processing-delete-gem-port-towards-onu", |
| 2013 | log.Fields{ |
| 2014 | "err": err, |
| 2015 | "intfID": intfID, |
| 2016 | "onu-id": onuID, |
| 2017 | "uni-id": uniID, |
| 2018 | "device-id": f.deviceHandler.device.Id, |
| 2019 | "gemport-id": gemPortID}) |
| 2020 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2021 | return nil |
| 2022 | } |
| 2023 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2024 | // nolint: gocyclo |
Girish Gowdra | e8f473b | 2020-10-16 11:07:21 -0700 | [diff] [blame] | 2025 | func (f *OpenOltFlowMgr) clearFlowFromDeviceAndResourceManager(ctx context.Context, flow *ofp.OfpFlowStats, flowDirection string) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2026 | logger.Infow(ctx, "clear-flow-from-resource-manager", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2027 | log.Fields{ |
| 2028 | "flowDirection": flowDirection, |
| 2029 | "flow": *flow, |
| 2030 | "device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2031 | |
| 2032 | if flowDirection == Multicast { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2033 | return f.clearMulticastFlowFromResourceManager(ctx, flow) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2036 | classifierInfo := make(map[string]interface{}) |
| 2037 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2038 | portNum, Intf, onu, uni, inPort, ethType, err := FlowExtractInfo(ctx, flow, flowDirection) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2039 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2040 | logger.Error(ctx, err) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2041 | return err |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2042 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2043 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2044 | onuID := int32(onu) |
| 2045 | uniID := int32(uni) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2046 | tpID, err := getTpIDFromFlow(ctx, flow) |
| 2047 | if err != nil { |
| 2048 | return olterrors.NewErrNotFound("tp-id", |
| 2049 | log.Fields{ |
| 2050 | "flow": flow, |
| 2051 | "intf-id": Intf, |
| 2052 | "onu-id": onuID, |
| 2053 | "uni-id": uniID, |
| 2054 | "device-id": f.deviceHandler.device.Id}, err) |
| 2055 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2056 | |
| 2057 | for _, field := range flows.GetOfbFields(flow) { |
| 2058 | if field.Type == flows.IP_PROTO { |
| 2059 | classifierInfo[IPProto] = field.GetIpProto() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2060 | logger.Debugw(ctx, "field-type-ip-proto", log.Fields{"classifierInfo[IP_PROTO]": classifierInfo[IPProto].(uint32)}) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2061 | } |
| 2062 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2063 | logger.Infow(ctx, "extracted-access-info-from-flow-to-be-deleted", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2064 | log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2065 | "flow-id": flow.Id, |
| 2066 | "intf-id": Intf, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2067 | "onu-id": onuID, |
| 2068 | "uni-id": uniID}) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2069 | |
| 2070 | if ethType == LldpEthType || ((classifierInfo[IPProto] == IPProtoDhcp) && (flowDirection == "downstream")) { |
| 2071 | onuID = -1 |
| 2072 | uniID = -1 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2073 | logger.Debug(ctx, "trap-on-nni-flow-set-oni--uni-to- -1") |
| 2074 | Intf, err = IntfIDFromNniPortNum(ctx, inPort) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2075 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2076 | logger.Errorw(ctx, "invalid-in-port-number", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2077 | log.Fields{ |
| 2078 | "port-number": inPort, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2079 | "err": err}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2080 | return err |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2081 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2082 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2083 | |
| 2084 | removeFlowMessage := openoltpb2.Flow{FlowId: flow.Id, AccessIntfId: int32(Intf), OnuId: onuID, UniId: uniID, TechProfileId: tpID, FlowType: flowDirection} |
| 2085 | logger.Debugw(ctx, "flow-to-be-deleted", log.Fields{"flow": flow}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2086 | if err = f.removeFlowFromDevice(ctx, &removeFlowMessage, flow.Id); err != nil { |
| 2087 | return err |
| 2088 | } |
Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 2089 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2090 | f.flowIDToGemsLock.Lock() |
| 2091 | gems, ok := f.flowIDToGems[flow.Id] |
| 2092 | if !ok { |
| 2093 | logger.Errorw(ctx, "flow-id-to-gem-map-not-found", log.Fields{"flowID": flow.Id}) |
| 2094 | f.flowIDToGemsLock.Unlock() |
| 2095 | return olterrors.NewErrNotFound("flow-id-to-gem-map-not-found", log.Fields{"flowID": flow.Id}, nil) |
| 2096 | } |
| 2097 | copyOfGems := make([]uint32, len(gems)) |
| 2098 | _ = copy(copyOfGems, gems) |
| 2099 | // Delete the flow-id to gemport list entry from the map now the flow is deleted. |
| 2100 | delete(f.flowIDToGems, flow.Id) |
| 2101 | f.flowIDToGemsLock.Unlock() |
| 2102 | |
| 2103 | logger.Debugw(ctx, "gems-to-be-cleared", log.Fields{"gems": copyOfGems}) |
| 2104 | for _, gem := range copyOfGems { |
| 2105 | if err = f.clearResources(ctx, Intf, onuID, uniID, int32(gem), flow.Id, portNum, tpID); err != nil { |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 2106 | logger.Errorw(ctx, "failed-to-clear-resources-for-flow", log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2107 | "flow-id": flow.Id, |
| 2108 | "device-id": f.deviceHandler.device.Id, |
| 2109 | "onu-id": onuID, |
| 2110 | "intf": Intf, |
| 2111 | "gem": gem, |
| 2112 | "err": err, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2113 | }) |
| 2114 | return err |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2115 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2116 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2117 | |
Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 2118 | // Decrement reference count for the meter associated with the given <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
| 2119 | if err := f.resourceMgr.HandleMeterInfoRefCntUpdate(ctx, flowDirection, Intf, uint32(onuID), uint32(uniID), tpID, false); err != nil { |
| 2120 | return err |
| 2121 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2122 | return nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2123 | } |
| 2124 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2125 | //RemoveFlow removes the flow from the device |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2126 | func (f *OpenOltFlowMgr) RemoveFlow(ctx context.Context, flow *ofp.OfpFlowStats) error { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2127 | |
Matteo Scandolo | f16389e | 2021-05-18 00:47:08 +0000 | [diff] [blame] | 2128 | logger.Infow(ctx, "removing-flow", log.Fields{"flow": *flow}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2129 | var direction string |
| 2130 | actionInfo := make(map[string]interface{}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2131 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2132 | for _, action := range flows.GetActions(flow) { |
| 2133 | if action.Type == flows.OUTPUT { |
| 2134 | if out := action.GetOutput(); out != nil { |
| 2135 | actionInfo[Output] = out.GetPort() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2136 | logger.Debugw(ctx, "action-type-output", log.Fields{"out_port": actionInfo[Output].(uint32)}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2137 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2138 | logger.Error(ctx, "invalid-output-port-in-action") |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2139 | return olterrors.NewErrInvalidValue(log.Fields{"invalid-out-port-action": 0}, nil) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2140 | } |
| 2141 | } |
| 2142 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2143 | |
| 2144 | if flows.HasGroup(flow) { |
| 2145 | direction = Multicast |
Girish Gowdra | e8f473b | 2020-10-16 11:07:21 -0700 | [diff] [blame] | 2146 | return f.clearFlowFromDeviceAndResourceManager(ctx, flow, direction) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2147 | } else if IsUpstream(actionInfo[Output].(uint32)) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2148 | direction = Upstream |
| 2149 | } else { |
| 2150 | direction = Downstream |
| 2151 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2152 | |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2153 | // Serialize flow removes on a per subscriber basis |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2154 | err := f.clearFlowFromDeviceAndResourceManager(ctx, flow, direction) |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2155 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2156 | return err |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2157 | } |
| 2158 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2159 | //isIgmpTrapDownstreamFlow return true if the flow is a downsteam IGMP trap-to-host flow; false otherwise |
| 2160 | func isIgmpTrapDownstreamFlow(classifierInfo map[string]interface{}) bool { |
| 2161 | if portType := IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_ETHERNET_NNI { |
| 2162 | if ethType, ok := classifierInfo[EthType]; ok { |
| 2163 | if ethType.(uint32) == IPv4EthType { |
| 2164 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2165 | if ipProto.(uint32) == IgmpProto { |
| 2166 | return true |
| 2167 | } |
| 2168 | } |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | return false |
| 2173 | } |
| 2174 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2175 | // RouteFlowToOnuChannel routes incoming flow to ONU specific channel |
| 2176 | func (f *OpenOltFlowMgr) RouteFlowToOnuChannel(ctx context.Context, flow *voltha.OfpFlowStats, addFlow bool, flowMetadata *voltha.FlowMetadata) error { |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 2177 | if f.deviceHandler.getDeviceDeletionInProgressFlag() { |
| 2178 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2179 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| 2180 | return nil |
| 2181 | } |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2182 | // Step1 : Fill flowControlBlock |
| 2183 | // Step2 : Push the flowControlBlock to ONU channel |
| 2184 | // Step3 : Wait on response channel for response |
| 2185 | // Step4 : Return error value |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2186 | startTime := time.Now() |
| 2187 | logger.Infow(ctx, "process-flow", log.Fields{"flow": flow, "addFlow": addFlow}) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2188 | errChan := make(chan error) |
| 2189 | flowCb := flowControlBlock{ |
| 2190 | ctx: ctx, |
| 2191 | addFlow: addFlow, |
| 2192 | flow: flow, |
| 2193 | flowMetadata: flowMetadata, |
| 2194 | errChan: &errChan, |
| 2195 | } |
| 2196 | inPort, outPort := getPorts(flow) |
| 2197 | var onuID uint32 |
| 2198 | if inPort != InvalidPort && outPort != InvalidPort { |
| 2199 | _, _, onuID, _ = ExtractAccessFromFlow(inPort, outPort) |
| 2200 | } |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 2201 | if f.flowHandlerRoutineActive[onuID] { |
| 2202 | // inPort or outPort is InvalidPort for trap-from-nni flows. |
| 2203 | // In the that case onuID is 0 which is the reserved index for trap-from-nni flows in the f.incomingFlows slice |
| 2204 | // Send the flowCb on the ONU flow channel |
| 2205 | f.incomingFlows[onuID] <- flowCb |
| 2206 | // Wait on the channel for flow handlers return value |
| 2207 | err := <-errChan |
| 2208 | logger.Infow(ctx, "process-flow-received-resp", log.Fields{"err": err, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
| 2209 | return err |
| 2210 | } |
| 2211 | logger.Errorw(ctx, "flow handler routine not active for onu", log.Fields{"onuID": onuID, "ponPortIdx": f.ponPortIdx}) |
| 2212 | return fmt.Errorf("flow-handler-routine-not-active-for-onu-%v-pon-%d", onuID, f.ponPortIdx) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | // This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows |
| 2216 | // Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 2217 | func (f *OpenOltFlowMgr) perOnuFlowHandlerRoutine(handlerRoutineIndex int, subscriberFlowChannel chan flowControlBlock, stopHandler chan bool) { |
| 2218 | var flowCb flowControlBlock |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2219 | for { |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 2220 | select { |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2221 | // block on the channel to receive an incoming flow |
| 2222 | // process the flow completely before proceeding to handle the next flow |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 2223 | case flowCb = <-subscriberFlowChannel: |
| 2224 | if flowCb.addFlow { |
| 2225 | logger.Info(flowCb.ctx, "adding-flow-start") |
| 2226 | startTime := time.Now() |
| 2227 | err := f.AddFlow(flowCb.ctx, flowCb.flow, flowCb.flowMetadata) |
| 2228 | logger.Infow(flowCb.ctx, "adding-flow-complete", log.Fields{"processTimeSecs": time.Since(startTime).Seconds()}) |
| 2229 | // Pass the return value over the return channel |
| 2230 | *flowCb.errChan <- err |
| 2231 | } else { |
| 2232 | logger.Info(flowCb.ctx, "removing-flow-start") |
| 2233 | startTime := time.Now() |
| 2234 | err := f.RemoveFlow(flowCb.ctx, flowCb.flow) |
| 2235 | logger.Infow(flowCb.ctx, "removing-flow-complete", log.Fields{"processTimeSecs": time.Since(startTime).Seconds()}) |
| 2236 | // Pass the return value over the return channel |
| 2237 | *flowCb.errChan <- err |
| 2238 | } |
| 2239 | case <-stopHandler: |
| 2240 | f.flowHandlerRoutineActive[handlerRoutineIndex] = false |
| 2241 | return |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2242 | } |
| 2243 | } |
| 2244 | } |
| 2245 | |
Girish Gowdra | da69ec1 | 2021-11-16 15:04:58 -0800 | [diff] [blame] | 2246 | // StopAllFlowHandlerRoutines stops all flow handler routines. Call this when device is being rebooted or deleted |
| 2247 | func (f *OpenOltFlowMgr) StopAllFlowHandlerRoutines(ctx context.Context, wg *sync.WaitGroup) { |
| 2248 | for i, v := range f.stopFlowHandlerRoutine { |
| 2249 | if f.flowHandlerRoutineActive[i] { |
| 2250 | select { |
| 2251 | case v <- true: |
| 2252 | case <-time.After(time.Second * 5): |
| 2253 | logger.Warnw(ctx, "timeout stopping flow handler routine", log.Fields{"onuID": i, "deviceID": f.deviceHandler.device.Id}) |
| 2254 | } |
| 2255 | } |
| 2256 | } |
| 2257 | wg.Done() |
| 2258 | logger.Debugw(ctx, "stopped all flow handler routines", log.Fields{"ponPortIdx": f.ponPortIdx}) |
| 2259 | } |
| 2260 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2261 | // AddFlow add flow to device |
Naga Manjunath | b8438aa | 2020-01-02 17:52:33 +0530 | [diff] [blame] | 2262 | // nolint: gocyclo |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2263 | func (f *OpenOltFlowMgr) AddFlow(ctx context.Context, flow *ofp.OfpFlowStats, flowMetadata *voltha.FlowMetadata) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2264 | classifierInfo := make(map[string]interface{}) |
| 2265 | actionInfo := make(map[string]interface{}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2266 | var UsMeterID uint32 |
| 2267 | var DsMeterID uint32 |
| 2268 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2269 | logger.Infow(ctx, "adding-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2270 | log.Fields{ |
| 2271 | "flow": flow, |
Matteo Scandolo | f16389e | 2021-05-18 00:47:08 +0000 | [diff] [blame] | 2272 | "flowmetadata": flowMetadata}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2273 | formulateClassifierInfoFromFlow(ctx, classifierInfo, flow) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2274 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2275 | err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2276 | if err != nil { |
| 2277 | // Error logging is already done in the called function |
| 2278 | // So just return in case of error |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2279 | return err |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2280 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2281 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2282 | if flows.HasGroup(flow) { |
| 2283 | // handle multicast flow |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2284 | return f.handleFlowWithGroup(ctx, actionInfo, classifierInfo, flow) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2285 | } |
| 2286 | |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2287 | /* Controller bound trap flows */ |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2288 | err = formulateControllerBoundTrapFlowInfo(ctx, actionInfo, classifierInfo, flow) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2289 | if err != nil { |
| 2290 | // error if any, already logged in the called function |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2291 | return err |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2292 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2293 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2294 | logger.Debugw(ctx, "flow-ports", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2295 | log.Fields{ |
| 2296 | "classifierinfo_inport": classifierInfo[InPort], |
| 2297 | "action_output": actionInfo[Output]}) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2298 | portNo, intfID, onuID, uniID := ExtractAccessFromFlow(classifierInfo[InPort].(uint32), actionInfo[Output].(uint32)) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2299 | |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2300 | if ethType, ok := classifierInfo[EthType]; ok { |
| 2301 | if ethType.(uint32) == LldpEthType { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2302 | logger.Info(ctx, "adding-lldp-flow") |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2303 | return f.addLLDPFlow(ctx, flow, portNo) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2304 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2305 | if ethType.(uint32) == PPPoEDEthType { |
| 2306 | if voltha.Port_ETHERNET_NNI == IntfIDToPortTypeName(classifierInfo[InPort].(uint32)) { |
| 2307 | logger.Debug(ctx, "trap-pppoed-from-nni-flow") |
| 2308 | return f.addTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
| 2309 | } |
| 2310 | } |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2311 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2312 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2313 | if ipProto.(uint32) == IPProtoDhcp { |
| 2314 | if udpSrc, ok := classifierInfo[UDPSrc]; ok { |
Naga Manjunath | b8438aa | 2020-01-02 17:52:33 +0530 | [diff] [blame] | 2315 | if udpSrc.(uint32) == uint32(67) || udpSrc.(uint32) == uint32(546) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2316 | logger.Debug(ctx, "trap-dhcp-from-nni-flow") |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2317 | return f.addTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2322 | if isIgmpTrapDownstreamFlow(classifierInfo) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2323 | logger.Debug(ctx, "trap-igmp-from-nni-flow") |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2324 | return f.addIgmpTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2325 | } |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2326 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2327 | f.resourceMgr.AddUniPortToOnuInfo(ctx, intfID, onuID, portNo) |
Girish Gowdra | bcf98af | 2021-07-01 08:24:42 -0700 | [diff] [blame] | 2328 | // also update flowmgr cache |
| 2329 | f.onuGemInfoLock.Lock() |
| 2330 | onugem, ok := f.onuGemInfoMap[onuID] |
| 2331 | if ok { |
| 2332 | found := false |
| 2333 | for _, uni := range onugem.UniPorts { |
| 2334 | if uni == portNo { |
| 2335 | found = true |
| 2336 | break |
| 2337 | } |
| 2338 | } |
| 2339 | if !found { |
| 2340 | onugem.UniPorts = append(onugem.UniPorts, portNo) |
| 2341 | f.onuGemInfoMap[onuID] = onugem |
| 2342 | logger.Infow(ctx, "added uni port to onugem cache", log.Fields{"uni": portNo}) |
| 2343 | } |
| 2344 | } |
| 2345 | f.onuGemInfoLock.Unlock() |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2346 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2347 | TpID, err := getTpIDFromFlow(ctx, flow) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2348 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2349 | return olterrors.NewErrNotFound("tpid-for-flow", |
| 2350 | log.Fields{ |
| 2351 | "flow": flow, |
| 2352 | "intf-id": IntfID, |
| 2353 | "onu-id": onuID, |
| 2354 | "uni-id": uniID}, err) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2355 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2356 | logger.Debugw(ctx, "tpid-for-this-subcriber", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2357 | log.Fields{ |
| 2358 | "tp-id": TpID, |
| 2359 | "intf-id": intfID, |
| 2360 | "onu-id": onuID, |
| 2361 | "uni-id": uniID}) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2362 | if IsUpstream(actionInfo[Output].(uint32)) { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2363 | UsMeterID = flows.GetMeterIdFromFlow(flow) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2364 | logger.Debugw(ctx, "upstream-flow-meter-id", log.Fields{"us-meter-id": UsMeterID}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2365 | } else { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2366 | DsMeterID = flows.GetMeterIdFromFlow(flow) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2367 | logger.Debugw(ctx, "downstream-flow-meter-id", log.Fields{"ds-meter-id": DsMeterID}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2368 | |
| 2369 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2370 | return f.processAddFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, TpID, UsMeterID, DsMeterID, flowMetadata) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2371 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2372 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2373 | // handleFlowWithGroup adds multicast flow to the device. |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2374 | func (f *OpenOltFlowMgr) handleFlowWithGroup(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
Andrea Campanella | 8f64556 | 2021-10-28 11:50:56 +0530 | [diff] [blame^] | 2375 | classifierInfo[PacketTagType] = getPacketTypeFromClassifiers(classifierInfo) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2376 | logger.Debugw(ctx, "add-multicast-flow", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2377 | "classifier-info": classifierInfo, |
| 2378 | "actionInfo": actionInfo}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2379 | |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2380 | networkInterfaceID, err := f.getNNIInterfaceIDOfMulticastFlow(ctx, classifierInfo) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2381 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2382 | return olterrors.NewErrNotFound("multicast-in-port", log.Fields{"classifier": classifierInfo}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2383 | } |
Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2384 | |
Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2385 | delete(classifierInfo, EthType) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2386 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2387 | onuID := NoneOnuID |
| 2388 | uniID := NoneUniID |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2389 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2390 | if present := f.resourceMgr.IsFlowOnKvStore(ctx, networkInterfaceID, int32(onuID), int32(uniID), flow.Id); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2391 | logger.Infow(ctx, "multicast-flow-exists-not-re-adding", log.Fields{"classifier-info": classifierInfo}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2392 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2393 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2394 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 2395 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2396 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifierInfo}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2397 | } |
| 2398 | groupID := actionInfo[GroupID].(uint32) |
| 2399 | multicastFlow := openoltpb2.Flow{ |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2400 | FlowId: flow.Id, |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2401 | FlowType: Multicast, |
| 2402 | NetworkIntfId: int32(networkInterfaceID), |
| 2403 | GroupId: groupID, |
| 2404 | Classifier: classifierProto, |
| 2405 | Priority: int32(flow.Priority), |
| 2406 | Cookie: flow.Cookie} |
| 2407 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2408 | if err := f.addFlowToDevice(ctx, flow, &multicastFlow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2409 | return olterrors.NewErrFlowOp("add", flow.Id, log.Fields{"flow": multicastFlow}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2410 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2411 | logger.Info(ctx, "multicast-flow-added-to-device-successfully") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2412 | //get cached group |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2413 | if group, _, err := f.grpMgr.getFlowGroupFromKVStore(ctx, groupID, true); err == nil { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2414 | //calling groupAdd to set group members after multicast flow creation |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2415 | if err := f.grpMgr.ModifyGroup(ctx, group); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2416 | return olterrors.NewErrGroupOp("modify", groupID, log.Fields{"group": group}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2417 | } |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2418 | //cached group can be removed now |
| 2419 | if err := f.resourceMgr.RemoveFlowGroupFromKVStore(ctx, groupID, true); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2420 | logger.Warnw(ctx, "failed-to-remove-flow-group", log.Fields{"group-id": groupID, "err": err}) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2421 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2422 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2423 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2424 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2427 | //getNNIInterfaceIDOfMulticastFlow returns associated NNI interface id of the inPort criterion if exists; returns the first NNI interface of the device otherwise |
| 2428 | func (f *OpenOltFlowMgr) getNNIInterfaceIDOfMulticastFlow(ctx context.Context, classifierInfo map[string]interface{}) (uint32, error) { |
| 2429 | if inPort, ok := classifierInfo[InPort]; ok { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2430 | nniInterfaceID, err := IntfIDFromNniPortNum(ctx, inPort.(uint32)) |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2431 | if err != nil { |
| 2432 | return 0, olterrors.NewErrInvalidValue(log.Fields{"nni-in-port-number": inPort}, err) |
| 2433 | } |
| 2434 | return nniInterfaceID, nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2435 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2436 | |
| 2437 | // TODO: For now we support only one NNI port in VOLTHA. We shall use only the first NNI port, i.e., interface-id 0. |
| 2438 | return 0, nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2441 | //sendTPDownloadMsgToChild send payload |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2442 | func (f *OpenOltFlowMgr) sendTPDownloadMsgToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uni string, TpID uint32, tpInst tp_pb.TechProfileInstance) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2443 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2444 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 2445 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2446 | logger.Errorw(ctx, "couldnt-find-onu-child-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2447 | log.Fields{ |
| 2448 | "intf-id": intfID, |
| 2449 | "onu-id": onuID, |
| 2450 | "uni-id": uniID}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 2451 | return err |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2452 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2453 | logger.Debugw(ctx, "got-child-device-from-olt-device-handler", log.Fields{"onu-id": onuDev.deviceID}) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2454 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2455 | tpPath := f.getTPpath(ctx, intfID, uni, TpID) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2456 | tpDownloadMsg := &ic.InterAdapterTechProfileDownloadMessage{ |
| 2457 | UniId: uniID, |
| 2458 | TpInstancePath: tpPath, |
| 2459 | TechTpInstance: &ic.InterAdapterTechProfileDownloadMessage_TpInstance{TpInstance: &tpInst}, |
| 2460 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2461 | logger.Debugw(ctx, "sending-load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"tpDownloadMsg": *tpDownloadMsg}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 2462 | sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(log.WithSpanFromContext(context.Background(), ctx), |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2463 | tpDownloadMsg, |
| 2464 | ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST, |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 2465 | f.deviceHandler.openOLT.config.Topic, |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 2466 | onuDev.deviceType, |
| 2467 | onuDev.deviceID, |
| 2468 | onuDev.proxyDeviceID, "") |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2469 | if sendErr != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2470 | return olterrors.NewErrCommunication("send-techprofile-download-request", |
| 2471 | log.Fields{ |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 2472 | "from-adapter": f.deviceHandler.openOLT.config.Topic, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2473 | "to-adapter": onuDev.deviceType, |
| 2474 | "onu-id": onuDev.deviceID, |
| 2475 | "proxyDeviceID": onuDev.proxyDeviceID}, sendErr) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2476 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2477 | logger.Infow(ctx, "success-sending-load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"tpDownloadMsg": *tpDownloadMsg}) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 2478 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2479 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2480 | |
Girish Gowdra | 37f13fa | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 2481 | //AddOnuInfoToFlowMgrCacheAndKvStore function adds onu info to cache and kvstore |
| 2482 | func (f *OpenOltFlowMgr) AddOnuInfoToFlowMgrCacheAndKvStore(ctx context.Context, intfID uint32, onuID uint32, serialNum string) error { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2483 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2484 | f.onuGemInfoLock.RLock() |
| 2485 | _, ok := f.onuGemInfoMap[onuID] |
| 2486 | f.onuGemInfoLock.RUnlock() |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2487 | // If the ONU already exists in onuGemInfo list, nothing to do |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2488 | if ok { |
| 2489 | logger.Debugw(ctx, "onu-id-already-exists-in-cache", |
| 2490 | log.Fields{"onuID": onuID, |
| 2491 | "serialNum": serialNum}) |
| 2492 | return nil |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2493 | } |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 2494 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2495 | onuGemInfo := rsrcMgr.OnuGemInfo{OnuID: onuID, SerialNumber: serialNum, IntfID: intfID} |
| 2496 | f.onuGemInfoLock.Lock() |
| 2497 | f.onuGemInfoMap[onuID] = &onuGemInfo |
| 2498 | f.onuGemInfoLock.Unlock() |
| 2499 | if err := f.resourceMgr.AddOnuGemInfo(ctx, intfID, onuID, onuGemInfo); err != nil { |
Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 2500 | return err |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2501 | } |
Girish Gowdra | 37f13fa | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 2502 | logger.Infow(ctx, "added-onuinfo", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2503 | log.Fields{ |
| 2504 | "intf-id": intfID, |
| 2505 | "onu-id": onuID, |
| 2506 | "serial-num": serialNum, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2507 | "onu": onuGemInfo, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2508 | "device-id": f.deviceHandler.device.Id}) |
Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 2509 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2510 | } |
| 2511 | |
Girish Gowdra | 37f13fa | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 2512 | //RemoveOnuInfoFromFlowMgrCacheAndKvStore function adds onu info to cache and kvstore |
| 2513 | func (f *OpenOltFlowMgr) RemoveOnuInfoFromFlowMgrCacheAndKvStore(ctx context.Context, intfID uint32, onuID uint32) error { |
| 2514 | |
| 2515 | f.onuGemInfoLock.Lock() |
| 2516 | delete(f.onuGemInfoMap, onuID) |
| 2517 | f.onuGemInfoLock.Unlock() |
| 2518 | |
| 2519 | if err := f.resourceMgr.DelOnuGemInfo(ctx, intfID, onuID); err != nil { |
| 2520 | return err |
| 2521 | } |
| 2522 | logger.Infow(ctx, "deleted-onuinfo", |
| 2523 | log.Fields{ |
| 2524 | "intf-id": intfID, |
| 2525 | "onu-id": onuID, |
| 2526 | "device-id": f.deviceHandler.device.Id}) |
| 2527 | return nil |
| 2528 | } |
| 2529 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2530 | //addGemPortToOnuInfoMap function adds GEMport to ONU map |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2531 | func (f *OpenOltFlowMgr) addGemPortToOnuInfoMap(ctx context.Context, intfID uint32, onuID uint32, gemPort uint32) { |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 2532 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2533 | logger.Infow(ctx, "adding-gem-to-onu-info-map", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2534 | log.Fields{ |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2535 | "gem-port-id": gemPort, |
| 2536 | "intf-id": intfID, |
| 2537 | "onu-id": onuID, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2538 | "device-id": f.deviceHandler.device.Id}) |
| 2539 | f.onuGemInfoLock.RLock() |
| 2540 | onugem, ok := f.onuGemInfoMap[onuID] |
| 2541 | f.onuGemInfoLock.RUnlock() |
| 2542 | if !ok { |
| 2543 | logger.Warnw(ctx, "onu gem info is missing", log.Fields{ |
| 2544 | "gem-port-id": gemPort, |
| 2545 | "intf-id": intfID, |
| 2546 | "onu-id": onuID, |
| 2547 | "device-id": f.deviceHandler.device.Id}) |
| 2548 | return |
| 2549 | } |
| 2550 | |
| 2551 | if onugem.OnuID == onuID { |
| 2552 | // check if gem already exists , else update the cache and kvstore |
| 2553 | for _, gem := range onugem.GemPorts { |
| 2554 | if gem == gemPort { |
| 2555 | logger.Debugw(ctx, "gem-already-in-cache-no-need-to-update-cache-and-kv-store", |
| 2556 | log.Fields{ |
| 2557 | "gem": gemPort, |
| 2558 | "device-id": f.deviceHandler.device.Id}) |
| 2559 | return |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2560 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2561 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2562 | onugem.GemPorts = append(onugem.GemPorts, gemPort) |
| 2563 | f.onuGemInfoLock.Lock() |
| 2564 | f.onuGemInfoMap[onuID] = onugem |
| 2565 | f.onuGemInfoLock.Unlock() |
Girish Gowdra | bcf98af | 2021-07-01 08:24:42 -0700 | [diff] [blame] | 2566 | logger.Debugw(ctx, "updated onu gem info from cache", log.Fields{"onugem": onugem}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2567 | } else { |
| 2568 | logger.Warnw(ctx, "mismatched onu id", log.Fields{ |
| 2569 | "gem-port-id": gemPort, |
| 2570 | "intf-id": intfID, |
| 2571 | "onu-id": onuID, |
| 2572 | "device-id": f.deviceHandler.device.Id}) |
| 2573 | return |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2574 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2575 | err := f.resourceMgr.AddGemToOnuGemInfo(ctx, intfID, onuID, gemPort) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2576 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2577 | logger.Errorw(ctx, "failed-to-add-gem-to-onu", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2578 | log.Fields{ |
| 2579 | "intf-id": intfID, |
| 2580 | "onu-id": onuID, |
| 2581 | "gemPort": gemPort, |
| 2582 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2583 | return |
| 2584 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2585 | logger.Infow(ctx, "gem-added-to-onu-info-map", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2586 | log.Fields{ |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2587 | "gem-port-id": gemPort, |
| 2588 | "intf-id": intfID, |
| 2589 | "onu-id": onuID, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2590 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2591 | } |
| 2592 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2593 | //GetLogicalPortFromPacketIn function computes logical port UNI/NNI port from packet-in indication and returns the same |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2594 | func (f *OpenOltFlowMgr) GetLogicalPortFromPacketIn(ctx context.Context, packetIn *openoltpb2.PacketIndication) (uint32, error) { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2595 | var logicalPortNum uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2596 | |
| 2597 | if packetIn.IntfType == "pon" { |
| 2598 | // packet indication does not have serial number , so sending as nil |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 2599 | // get onu and uni ids associated with the given pon and gem ports |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2600 | onuID, uniID := packetIn.OnuId, packetIn.UniId |
| 2601 | logger.Debugf(ctx, "retrieved ONU and UNI IDs [%d, %d] by interface:%d, gem:%d", packetIn.OnuId, packetIn.UniId, packetIn.GemportId) |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 2602 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2603 | if packetIn.PortNo != 0 { |
| 2604 | logicalPortNum = packetIn.PortNo |
| 2605 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2606 | logicalPortNum = MkUniPortNum(ctx, packetIn.IntfId, onuID, uniID) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2607 | } |
| 2608 | // Store the gem port through which the packet_in came. Use the same gem port for packet_out |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2609 | f.UpdateGemPortForPktIn(ctx, packetIn.IntfId, onuID, logicalPortNum, packetIn.GemportId, packetIn.Pkt) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2610 | } else if packetIn.IntfType == "nni" { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2611 | logicalPortNum = IntfIDToPortNo(packetIn.IntfId, voltha.Port_ETHERNET_NNI) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2612 | } |
Girish Gowdra | eb45029 | 2020-10-26 10:03:39 -0700 | [diff] [blame] | 2613 | |
| 2614 | if logger.V(log.DebugLevel) { |
| 2615 | logger.Debugw(ctx, "retrieved-logicalport-from-packet-in", |
| 2616 | log.Fields{ |
| 2617 | "logical-port-num": logicalPortNum, |
| 2618 | "intf-type": packetIn.IntfType, |
| 2619 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2620 | }) |
| 2621 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2622 | return logicalPortNum, nil |
| 2623 | } |
| 2624 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2625 | //GetPacketOutGemPortID returns gemPortId |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2626 | func (f *OpenOltFlowMgr) GetPacketOutGemPortID(ctx context.Context, intfID uint32, onuID uint32, portNum uint32, packet []byte) (uint32, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2627 | var gemPortID uint32 |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2628 | |
| 2629 | ctag, priority, err := getCTagFromPacket(ctx, packet) |
| 2630 | if err != nil { |
| 2631 | return 0, err |
| 2632 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2633 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2634 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: portNum, VlanID: ctag, Priority: priority} |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2635 | var ok bool |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2636 | f.packetInGemPortLock.RLock() |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2637 | gemPortID, ok = f.packetInGemPort[pktInkey] |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2638 | f.packetInGemPortLock.RUnlock() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2639 | if ok { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2640 | logger.Debugw(ctx, "found-gemport-for-pktin-key", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2641 | log.Fields{ |
| 2642 | "pktinkey": pktInkey, |
| 2643 | "gem": gemPortID}) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2644 | |
| 2645 | return gemPortID, nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2646 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2647 | //If gem is not found in cache try to get it from kv store, if found in kv store, update the cache and return. |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2648 | gemPortID, err = f.resourceMgr.GetGemPortFromOnuPktIn(ctx, pktInkey) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2649 | if err == nil { |
| 2650 | if gemPortID != 0 { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2651 | f.packetInGemPortLock.Lock() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2652 | f.packetInGemPort[pktInkey] = gemPortID |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2653 | f.packetInGemPortLock.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2654 | logger.Infow(ctx, "found-gem-port-from-kv-store-and-updating-cache-with-gemport", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2655 | log.Fields{ |
| 2656 | "pktinkey": pktInkey, |
| 2657 | "gem": gemPortID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2658 | return gemPortID, nil |
| 2659 | } |
| 2660 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2661 | return uint32(0), olterrors.NewErrNotFound("gem-port", |
| 2662 | log.Fields{ |
| 2663 | "pktinkey": pktInkey, |
| 2664 | "gem": gemPortID}, err) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2665 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2666 | } |
| 2667 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2668 | func (f *OpenOltFlowMgr) addTrapFlowOnNNI(ctx context.Context, logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) error { |
| 2669 | logger.Debug(ctx, "adding-trap-of-nni-flow") |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2670 | action := make(map[string]interface{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2671 | classifier[PacketTagType] = DoubleTag |
| 2672 | action[TrapToHost] = true |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2673 | /* We manage flowId resource pool on per PON port basis. |
| 2674 | Since this situation is tricky, as a hack, we pass the NNI port |
| 2675 | index (network_intf_id) as PON port Index for the flowId resource |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2676 | pool. Also, there is no ONU Id available for trapping packets |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2677 | on NNI port, use onu_id as -1 (invalid) |
| 2678 | ****************** CAVEAT ******************* |
| 2679 | This logic works if the NNI Port Id falls within the same valid |
| 2680 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 2681 | we need to have a re-look at this. |
| 2682 | ********************************************* |
| 2683 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2684 | onuID := -1 |
| 2685 | uniID := -1 |
| 2686 | gemPortID := -1 |
| 2687 | allocID := -1 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2688 | networkInterfaceID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2689 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2690 | return olterrors.NewErrNotFound("nni-intreface-id", |
| 2691 | log.Fields{ |
| 2692 | "classifier": classifier, |
| 2693 | "action": action}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2694 | err) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2695 | } |
| 2696 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2697 | if present := f.resourceMgr.IsFlowOnKvStore(ctx, networkInterfaceID, int32(onuID), int32(uniID), logicalFlow.Id); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2698 | logger.Info(ctx, "flow-exists-not-re-adding") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2699 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2700 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2701 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2702 | logger.Debugw(ctx, "creating-trap-of-nni-flow", |
| 2703 | log.Fields{ |
| 2704 | "classifier": classifier, |
| 2705 | "action": action, |
| 2706 | "flowId": logicalFlow.Id, |
| 2707 | "intf-id": networkInterfaceID}) |
| 2708 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2709 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 2710 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2711 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2712 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2713 | logger.Debugw(ctx, "created-classifier-proto", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 2714 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2715 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2716 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2717 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2718 | logger.Debugw(ctx, "created-action-proto", log.Fields{"action": *actionProto}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2719 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 2720 | OnuId: int32(onuID), // OnuId not required |
| 2721 | UniId: int32(uniID), // UniId not used |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2722 | FlowId: logicalFlow.Id, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2723 | FlowType: Downstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2724 | AllocId: int32(allocID), // AllocId not used |
| 2725 | NetworkIntfId: int32(networkInterfaceID), |
| 2726 | GemportId: int32(gemPortID), // GemportId not used |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2727 | Classifier: classifierProto, |
| 2728 | Action: actionProto, |
| 2729 | Priority: int32(logicalFlow.Priority), |
| 2730 | Cookie: logicalFlow.Cookie, |
| 2731 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2732 | if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2733 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow": downstreamflow}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2734 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2735 | logger.Info(ctx, "trap-on-nni-flow-added–to-device-successfully") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2736 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2737 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2738 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2739 | //getPacketTypeFromClassifiers finds and returns packet type of a flow by checking flow classifiers |
| 2740 | func getPacketTypeFromClassifiers(classifierInfo map[string]interface{}) string { |
| 2741 | var packetType string |
| 2742 | ovid, ivid := false, false |
| 2743 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
| 2744 | vid := vlanID & VlanvIDMask |
| 2745 | if vid != ReservedVlan { |
| 2746 | ovid = true |
| 2747 | } |
| 2748 | } |
| 2749 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 2750 | vid := uint32(metadata) |
| 2751 | if vid != ReservedVlan { |
| 2752 | ivid = true |
| 2753 | } |
| 2754 | } |
| 2755 | if ovid && ivid { |
| 2756 | packetType = DoubleTag |
| 2757 | } else if !ovid && !ivid { |
| 2758 | packetType = Untagged |
| 2759 | } else { |
| 2760 | packetType = SingleTag |
| 2761 | } |
| 2762 | return packetType |
| 2763 | } |
| 2764 | |
| 2765 | //addIgmpTrapFlowOnNNI adds a trap-to-host flow on NNI |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2766 | func (f *OpenOltFlowMgr) addIgmpTrapFlowOnNNI(ctx context.Context, logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2767 | logger.Infow(ctx, "adding-igmp-trap-of-nni-flow", log.Fields{"classifier-info": classifier}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2768 | action := make(map[string]interface{}) |
| 2769 | classifier[PacketTagType] = getPacketTypeFromClassifiers(classifier) |
| 2770 | action[TrapToHost] = true |
| 2771 | /* We manage flowId resource pool on per PON port basis. |
| 2772 | Since this situation is tricky, as a hack, we pass the NNI port |
| 2773 | index (network_intf_id) as PON port Index for the flowId resource |
| 2774 | pool. Also, there is no ONU Id available for trapping packets |
| 2775 | on NNI port, use onu_id as -1 (invalid) |
| 2776 | ****************** CAVEAT ******************* |
| 2777 | This logic works if the NNI Port Id falls within the same valid |
| 2778 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 2779 | we need to have a re-look at this. |
| 2780 | ********************************************* |
| 2781 | */ |
| 2782 | onuID := -1 |
| 2783 | uniID := -1 |
| 2784 | gemPortID := -1 |
| 2785 | allocID := -1 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2786 | networkInterfaceID, err := getNniIntfID(ctx, classifier, action) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2787 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2788 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2789 | "classifier": classifier, |
| 2790 | "action": action}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2791 | err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2792 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2793 | if present := f.resourceMgr.IsFlowOnKvStore(ctx, networkInterfaceID, int32(onuID), int32(uniID), logicalFlow.Id); present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2794 | logger.Info(ctx, "igmp-flow-exists-not-re-adding") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2795 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2796 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2797 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2798 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 2799 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2800 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2801 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2802 | logger.Debugw(ctx, "created-classifier-proto-for-the-igmp-flow", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 2803 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2804 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2805 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2806 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2807 | logger.Debugw(ctx, "created-action-proto-for-the-igmp-flow", log.Fields{"action": *actionProto}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2808 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 2809 | OnuId: int32(onuID), // OnuId not required |
| 2810 | UniId: int32(uniID), // UniId not used |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2811 | FlowId: logicalFlow.Id, |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2812 | FlowType: Downstream, |
| 2813 | AllocId: int32(allocID), // AllocId not used |
| 2814 | NetworkIntfId: int32(networkInterfaceID), |
| 2815 | GemportId: int32(gemPortID), // GemportId not used |
| 2816 | Classifier: classifierProto, |
| 2817 | Action: actionProto, |
| 2818 | Priority: int32(logicalFlow.Priority), |
| 2819 | Cookie: logicalFlow.Cookie, |
| 2820 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2821 | if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2822 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow": downstreamflow}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2823 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2824 | logger.Info(ctx, "igmp-trap-on-nni-flow-added-to-device-successfully") |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2825 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2826 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2829 | func verifyMeterIDAndGetDirection(MeterID uint32, Dir tp_pb.Direction) (string, error) { |
| 2830 | if MeterID == 0 { // This should never happen |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2831 | return "", olterrors.NewErrInvalidValue(log.Fields{"meter-id": MeterID}, nil).Log() |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2832 | } |
| 2833 | if Dir == tp_pb.Direction_UPSTREAM { |
| 2834 | return "upstream", nil |
| 2835 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 2836 | return "downstream", nil |
| 2837 | } |
| 2838 | return "", nil |
| 2839 | } |
| 2840 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2841 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2842 | func (f *OpenOltFlowMgr) checkAndAddFlow(ctx context.Context, args map[string]uint32, classifierInfo map[string]interface{}, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2843 | actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpInst interface{}, gemPorts []uint32, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 2844 | tpID uint32, uni string) { |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2845 | var gemPortID uint32 |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2846 | intfID := args[IntfID] |
| 2847 | onuID := args[OnuID] |
| 2848 | uniID := args[UniID] |
| 2849 | portNo := args[PortNo] |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2850 | allocID := args[AllocID] |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2851 | pbitToGem := make(map[uint32]uint32) |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2852 | gemToAes := make(map[uint32]bool) |
| 2853 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2854 | var attributes []*tp_pb.GemPortAttributes |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2855 | var direction = tp_pb.Direction_UPSTREAM |
| 2856 | switch TpInst := TpInst.(type) { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2857 | case *tp_pb.TechProfileInstance: |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2858 | if IsUpstream(actionInfo[Output].(uint32)) { |
| 2859 | attributes = TpInst.UpstreamGemPortAttributeList |
| 2860 | } else { |
| 2861 | attributes = TpInst.DownstreamGemPortAttributeList |
| 2862 | direction = tp_pb.Direction_DOWNSTREAM |
| 2863 | } |
| 2864 | default: |
| 2865 | logger.Errorw(ctx, "unsupported-tech", log.Fields{"tpInst": TpInst}) |
| 2866 | return |
| 2867 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2868 | |
| 2869 | if len(gemPorts) == 1 { |
| 2870 | // If there is only single gemport use that and do not populate pbitToGem map |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2871 | gemPortID = gemPorts[0] |
| 2872 | gemToAes[gemPortID], _ = strconv.ParseBool(attributes[0].AesEncryption) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2873 | } else if pcp, ok := classifierInfo[VlanPcp]; !ok { |
| 2874 | for idx, gemID := range gemPorts { |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2875 | pBitMap := attributes[idx].PbitMap |
| 2876 | // Trim the bitMapPrefix form the binary string and then iterate each character in the binary string. |
| 2877 | // If the character is set to pbit1, extract the pcp value from the position of this character in the string. |
| 2878 | // Update the pbitToGem map with key being the pcp bit and the value being the gemPortID that consumes |
| 2879 | // this pcp bit traffic. |
| 2880 | for pos, pbitSet := range strings.TrimPrefix(pBitMap, bitMapPrefix) { |
| 2881 | if pbitSet == pbit1 { |
| 2882 | pcp := uint32(len(strings.TrimPrefix(pBitMap, bitMapPrefix))) - 1 - uint32(pos) |
| 2883 | pbitToGem[pcp] = gemID |
| 2884 | gemToAes[gemID], _ = strconv.ParseBool(attributes[idx].AesEncryption) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2885 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2886 | } |
| 2887 | } |
| 2888 | } else { // Extract the exact gemport which maps to the PCP classifier in the flow |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2889 | if gem := f.techprofile.GetGemportForPbit(ctx, TpInst, direction, pcp.(uint32)); gem != nil { |
| 2890 | gemPortID = gem.(*tp_pb.GemPortAttributes).GemportId |
| 2891 | gemToAes[gemPortID], _ = strconv.ParseBool(gem.(*tp_pb.GemPortAttributes).AesEncryption) |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2892 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2895 | flowContext := &flowContext{intfID, onuID, uniID, portNo, classifierInfo, actionInfo, |
| 2896 | flow, allocID, gemPortID, tpID, pbitToGem, gemToAes} |
| 2897 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2898 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2899 | if ipProto.(uint32) == IPProtoDhcp { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2900 | logger.Infow(ctx, "adding-dhcp-flow", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2901 | "tp-id": tpID, |
| 2902 | "alloc-id": allocID, |
| 2903 | "intf-id": intfID, |
| 2904 | "onu-id": onuID, |
| 2905 | "uni-id": uniID, |
| 2906 | }) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2907 | //Adding DHCP upstream flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2908 | if err := f.addDHCPTrapFlow(ctx, flowContext); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2909 | logger.Warn(ctx, err) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
Girish Gowdra | 3262521 | 2020-04-29 11:26:35 -0700 | [diff] [blame] | 2912 | } else if ipProto.(uint32) == IgmpProto { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2913 | logger.Infow(ctx, "adding-us-igmp-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2914 | log.Fields{ |
| 2915 | "intf-id": intfID, |
| 2916 | "onu-id": onuID, |
| 2917 | "uni-id": uniID, |
| 2918 | "classifier-info:": classifierInfo}) |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2919 | if err := f.addIGMPTrapFlow(ctx, flowContext); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2920 | logger.Warn(ctx, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2921 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2922 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2923 | logger.Errorw(ctx, "invalid-classifier-to-handle", log.Fields{"classifier": classifierInfo, "action": actionInfo}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2924 | return |
| 2925 | } |
| 2926 | } else if ethType, ok := classifierInfo[EthType]; ok { |
Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2927 | if ethType.(uint32) == EapEthType { |
| 2928 | logger.Infow(ctx, "adding-eapol-flow", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2929 | "intf-id": intfID, |
| 2930 | "onu-id": onuID, |
| 2931 | "uni-id": uniID, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2932 | "ethType": ethType, |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2933 | }) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2934 | var vlanID uint32 |
| 2935 | if val, ok := classifierInfo[VlanVid]; ok { |
| 2936 | vlanID = (val.(uint32)) & VlanvIDMask |
| 2937 | } else { |
| 2938 | vlanID = DefaultMgmtVlan |
| 2939 | } |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2940 | if err := f.addEthTypeBasedFlow(ctx, flowContext, vlanID, ethType.(uint32)); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2941 | logger.Warn(ctx, err) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2942 | } |
Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2943 | } else if ethType.(uint32) == PPPoEDEthType { |
| 2944 | logger.Infow(ctx, "adding-pppoed-flow", log.Fields{ |
| 2945 | "tp-id": tpID, |
| 2946 | "alloc-id": allocID, |
| 2947 | "intf-id": intfID, |
| 2948 | "onu-id": onuID, |
| 2949 | "uni-id": uniID, |
| 2950 | }) |
| 2951 | //Adding PPPOED upstream flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2952 | if err := f.addUpstreamTrapFlow(ctx, flowContext); err != nil { |
Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2953 | logger.Warn(ctx, err) |
| 2954 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2955 | } |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2956 | } else if direction == tp_pb.Direction_UPSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2957 | logger.Infow(ctx, "adding-upstream-data-rule", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2958 | "intf-id": intfID, |
| 2959 | "onu-id": onuID, |
| 2960 | "uni-id": uniID, |
| 2961 | }) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2962 | //Adding HSIA upstream flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2963 | if err := f.addUpstreamDataPathFlow(ctx, flowContext); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2964 | logger.Warn(ctx, err) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2965 | } |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2966 | } else if direction == tp_pb.Direction_DOWNSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2967 | logger.Infow(ctx, "adding-downstream-data-rule", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2968 | "intf-id": intfID, |
| 2969 | "onu-id": onuID, |
| 2970 | "uni-id": uniID, |
| 2971 | }) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2972 | //Adding HSIA downstream flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2973 | if err := f.addDownstreamDataPathFlow(ctx, flowContext); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2974 | logger.Warn(ctx, err) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2975 | } |
| 2976 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2977 | logger.Errorw(ctx, "invalid-flow-type-to-handle", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2978 | log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2979 | "intf-id": intfID, |
| 2980 | "onu-id": onuID, |
| 2981 | "uni-id": uniID, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2982 | "classifier": classifierInfo, |
| 2983 | "action": actionInfo, |
| 2984 | "flow": flow}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2985 | return |
| 2986 | } |
| 2987 | // Send Techprofile download event to child device in go routine as it takes time |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2988 | go func() { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2989 | if err := f.sendTPDownloadMsgToChild(ctx, intfID, onuID, uniID, uni, tpID, *(TpInst.(*tp_pb.TechProfileInstance))); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2990 | logger.Warn(ctx, err) |
| 2991 | } |
| 2992 | }() |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2995 | func (f *OpenOltFlowMgr) isGemPortUsedByAnotherFlow(gemPortID uint32) bool { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2996 | f.gemToFlowIDsKey.RLock() |
| 2997 | flowIDList := f.gemToFlowIDs[gemPortID] |
| 2998 | f.gemToFlowIDsKey.RUnlock() |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2999 | return len(flowIDList) > 1 |
| 3000 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3001 | } |
| 3002 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3003 | func (f *OpenOltFlowMgr) isTechProfileUsedByAnotherGem(ctx context.Context, ponIntf uint32, onuID uint32, uniID uint32, tpInst *tp_pb.TechProfileInstance, gemPortID uint32) (bool, uint32) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3004 | currentGemPorts := f.resourceMgr.GetCurrentGEMPortIDsForOnu(ctx, ponIntf, onuID, uniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3005 | tpGemPorts := tpInst.UpstreamGemPortAttributeList |
| 3006 | for _, currentGemPort := range currentGemPorts { |
| 3007 | for _, tpGemPort := range tpGemPorts { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3008 | if (currentGemPort == tpGemPort.GemportId) && (currentGemPort != gemPortID) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3009 | return true, currentGemPort |
| 3010 | } |
| 3011 | } |
| 3012 | } |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3013 | logger.Debug(ctx, "tech-profile-is-not-in-use-by-any-gem") |
| 3014 | return false, 0 |
| 3015 | } |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3016 | |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3017 | func (f *OpenOltFlowMgr) isAllocUsedByAnotherUNI(ctx context.Context, sq schedQueue) bool { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3018 | tpInst := sq.tpInst.(*tp_pb.TechProfileInstance) |
| 3019 | if tpInst.InstanceControl.Onu == "single-instance" && sq.direction == tp_pb.Direction_UPSTREAM { |
| 3020 | tpInstances := f.techprofile.FindAllTpInstances(ctx, f.deviceHandler.device.Id, sq.tpID, sq.intfID, sq.onuID).([]tp_pb.TechProfileInstance) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3021 | logger.Debugw(ctx, "got-single-instance-tp-instances", log.Fields{"tp-instances": tpInstances}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3022 | for i := 0; i < len(tpInstances); i++ { |
| 3023 | tpI := tpInstances[i] |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3024 | if tpI.SubscriberIdentifier != tpInst.SubscriberIdentifier && |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3025 | tpI.UsScheduler.AllocId == tpInst.UsScheduler.AllocId { |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3026 | logger.Debugw(ctx, "alloc-is-in-use", |
| 3027 | log.Fields{ |
| 3028 | "device-id": f.deviceHandler.device.Id, |
| 3029 | "intfID": sq.intfID, |
| 3030 | "onuID": sq.onuID, |
| 3031 | "uniID": sq.uniID, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3032 | "allocID": tpI.UsScheduler.AllocId, |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3033 | }) |
| 3034 | return true |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | } |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 3038 | return false |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3039 | } |
| 3040 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3041 | func formulateClassifierInfoFromFlow(ctx context.Context, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3042 | for _, field := range flows.GetOfbFields(flow) { |
| 3043 | if field.Type == flows.ETH_TYPE { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3044 | classifierInfo[EthType] = field.GetEthType() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3045 | logger.Debug(ctx, "field-type-eth-type", log.Fields{"classifierInfo[ETH_TYPE]": classifierInfo[EthType].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3046 | } else if field.Type == flows.ETH_DST { |
| 3047 | classifierInfo[EthDst] = field.GetEthDst() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3048 | logger.Debug(ctx, "field-type-eth-type", log.Fields{"classifierInfo[ETH_DST]": classifierInfo[EthDst].([]uint8)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3049 | } else if field.Type == flows.IP_PROTO { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3050 | classifierInfo[IPProto] = field.GetIpProto() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3051 | logger.Debug(ctx, "field-type-ip-proto", log.Fields{"classifierInfo[IP_PROTO]": classifierInfo[IPProto].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3052 | } else if field.Type == flows.IN_PORT { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3053 | classifierInfo[InPort] = field.GetPort() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3054 | logger.Debug(ctx, "field-type-in-port", log.Fields{"classifierInfo[IN_PORT]": classifierInfo[InPort].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3055 | } else if field.Type == flows.VLAN_VID { |
Andrea Campanella | 8f64556 | 2021-10-28 11:50:56 +0530 | [diff] [blame^] | 3056 | // The ReservedVlan is used to signify transparent vlan. Do not do any classification when we see ReservedVlan |
| 3057 | if field.GetVlanVid() != ReservedVlan { |
| 3058 | classifierInfo[VlanVid] = field.GetVlanVid() & 0xfff |
| 3059 | logger.Debug(ctx, "field-type-vlan-vid", log.Fields{"classifierInfo[VLAN_VID]": classifierInfo[VlanVid].(uint32)}) |
| 3060 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3061 | } else if field.Type == flows.VLAN_PCP { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3062 | classifierInfo[VlanPcp] = field.GetVlanPcp() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3063 | logger.Debug(ctx, "field-type-vlan-pcp", log.Fields{"classifierInfo[VLAN_PCP]": classifierInfo[VlanPcp].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3064 | } else if field.Type == flows.UDP_DST { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3065 | classifierInfo[UDPDst] = field.GetUdpDst() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3066 | logger.Debug(ctx, "field-type-udp-dst", log.Fields{"classifierInfo[UDP_DST]": classifierInfo[UDPDst].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3067 | } else if field.Type == flows.UDP_SRC { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3068 | classifierInfo[UDPSrc] = field.GetUdpSrc() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3069 | logger.Debug(ctx, "field-type-udp-src", log.Fields{"classifierInfo[UDP_SRC]": classifierInfo[UDPSrc].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3070 | } else if field.Type == flows.IPV4_DST { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3071 | classifierInfo[Ipv4Dst] = field.GetIpv4Dst() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3072 | logger.Debug(ctx, "field-type-ipv4-dst", log.Fields{"classifierInfo[IPV4_DST]": classifierInfo[Ipv4Dst].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3073 | } else if field.Type == flows.IPV4_SRC { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3074 | classifierInfo[Ipv4Src] = field.GetIpv4Src() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3075 | logger.Debug(ctx, "field-type-ipv4-src", log.Fields{"classifierInfo[IPV4_SRC]": classifierInfo[Ipv4Src].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3076 | } else if field.Type == flows.METADATA { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3077 | classifierInfo[Metadata] = field.GetTableMetadata() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3078 | logger.Debug(ctx, "field-type-metadata", log.Fields{"classifierInfo[Metadata]": classifierInfo[Metadata].(uint64)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3079 | } else if field.Type == flows.TUNNEL_ID { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3080 | classifierInfo[TunnelID] = field.GetTunnelId() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3081 | logger.Debug(ctx, "field-type-tunnelId", log.Fields{"classifierInfo[TUNNEL_ID]": classifierInfo[TunnelID].(uint64)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3082 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3083 | logger.Errorw(ctx, "un-supported-field-type", log.Fields{"type": field.Type}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3084 | return |
| 3085 | } |
| 3086 | } |
| 3087 | } |
| 3088 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3089 | func formulateActionInfoFromFlow(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3090 | for _, action := range flows.GetActions(flow) { |
| 3091 | if action.Type == flows.OUTPUT { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3092 | if out := action.GetOutput(); out != nil { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3093 | actionInfo[Output] = out.GetPort() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3094 | logger.Debugw(ctx, "action-type-output", log.Fields{"out-port": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3095 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3096 | return olterrors.NewErrInvalidValue(log.Fields{"output-port": nil}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3097 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3098 | } else if action.Type == flows.POP_VLAN { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3099 | actionInfo[PopVlan] = true |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3100 | logger.Debugw(ctx, "action-type-pop-vlan", log.Fields{"in_port": classifierInfo[InPort].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3101 | } else if action.Type == flows.PUSH_VLAN { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3102 | if out := action.GetPush(); out != nil { |
| 3103 | if tpid := out.GetEthertype(); tpid != 0x8100 { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3104 | logger.Errorw(ctx, "invalid ethertype in push action", log.Fields{"ethertype": actionInfo[PushVlan].(int32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3105 | } else { |
| 3106 | actionInfo[PushVlan] = true |
| 3107 | actionInfo[TPID] = tpid |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3108 | logger.Debugw(ctx, "action-type-push-vlan", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3109 | log.Fields{ |
| 3110 | "push-tpid": actionInfo[TPID].(uint32), |
| 3111 | "in-port": classifierInfo[InPort].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3112 | } |
| 3113 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3114 | } else if action.Type == flows.SET_FIELD { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3115 | if out := action.GetSetField(); out != nil { |
| 3116 | if field := out.GetField(); field != nil { |
| 3117 | if ofClass := field.GetOxmClass(); ofClass != ofp.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3118 | return olterrors.NewErrInvalidValue(log.Fields{"openflow-class": ofClass}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3119 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3120 | /*logger.Debugw(ctx, "action-type-set-field",log.Fields{"field": field, "in_port": classifierInfo[IN_PORT].(uint32)})*/ |
| 3121 | formulateSetFieldActionInfoFromFlow(ctx, field, actionInfo) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3122 | } |
| 3123 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3124 | } else if action.Type == flows.GROUP { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3125 | formulateGroupActionInfoFromFlow(ctx, action, actionInfo) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3126 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3127 | return olterrors.NewErrInvalidValue(log.Fields{"action-type": action.Type}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | return nil |
| 3131 | } |
| 3132 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3133 | func formulateSetFieldActionInfoFromFlow(ctx context.Context, field *ofp.OfpOxmField, actionInfo map[string]interface{}) { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3134 | if ofbField := field.GetOfbField(); ofbField != nil { |
Gamze Abaka | c43a66e | 2020-05-11 11:00:42 +0000 | [diff] [blame] | 3135 | fieldtype := ofbField.GetType() |
| 3136 | if fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3137 | if vlan := ofbField.GetVlanVid(); vlan != 0 { |
| 3138 | actionInfo[VlanVid] = vlan & 0xfff |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3139 | logger.Debugw(ctx, "action-set-vlan-vid", log.Fields{"actionInfo[VLAN_VID]": actionInfo[VlanVid].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3140 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3141 | logger.Error(ctx, "no-invalid-vlan-id-in-set-vlan-vid-action") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3142 | } |
Gamze Abaka | c43a66e | 2020-05-11 11:00:42 +0000 | [diff] [blame] | 3143 | } else if fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
| 3144 | pcp := ofbField.GetVlanPcp() |
| 3145 | actionInfo[VlanPcp] = pcp |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3146 | logger.Debugw(ctx, "action-set-vlan-pcp", log.Fields{"actionInfo[VLAN_PCP]": actionInfo[VlanPcp].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3147 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3148 | logger.Errorw(ctx, "unsupported-action-set-field-type", log.Fields{"type": fieldtype}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3149 | } |
| 3150 | } |
| 3151 | } |
| 3152 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3153 | func formulateGroupActionInfoFromFlow(ctx context.Context, action *ofp.OfpAction, actionInfo map[string]interface{}) { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3154 | if action.GetGroup() == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3155 | logger.Warn(ctx, "no-group-entry-found-in-the-group-action") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3156 | } else { |
| 3157 | actionInfo[GroupID] = action.GetGroup().GroupId |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3158 | logger.Debugw(ctx, "action-group-id", log.Fields{"actionInfo[GroupID]": actionInfo[GroupID].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3162 | func formulateControllerBoundTrapFlowInfo(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3163 | if isControllerFlow := IsControllerBoundFlow(actionInfo[Output].(uint32)); isControllerFlow { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3164 | logger.Debug(ctx, "controller-bound-trap-flows--getting-inport-from-tunnelid") |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3165 | /* Get UNI port/ IN Port from tunnel ID field for upstream controller bound flows */ |
| 3166 | if portType := IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3167 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3168 | classifierInfo[InPort] = uniPort |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3169 | logger.Debugw(ctx, "upstream-pon-to-controller-flow--inport-in-tunnelid", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3170 | log.Fields{ |
| 3171 | "newinport": classifierInfo[InPort].(uint32), |
| 3172 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3173 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3174 | return olterrors.NewErrNotFound("child-in-port", |
| 3175 | log.Fields{ |
| 3176 | "reason": "upstream-pon-to-controller-flow--no-inport-in-tunnelid", |
| 3177 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3178 | } |
| 3179 | } |
| 3180 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3181 | logger.Debug(ctx, "non-controller-flows--getting-uniport-from-tunnelid") |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3182 | // Downstream flow from NNI to PON port , Use tunnel ID as new OUT port / UNI port |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3183 | if portType := IntfIDToPortTypeName(actionInfo[Output].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3184 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3185 | actionInfo[Output] = uniPort |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3186 | logger.Debugw(ctx, "downstream-nni-to-pon-port-flow, outport-in-tunnelid", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3187 | log.Fields{ |
| 3188 | "newoutport": actionInfo[Output].(uint32), |
| 3189 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3190 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3191 | return olterrors.NewErrNotFound("out-port", |
| 3192 | log.Fields{ |
| 3193 | "reason": "downstream-nni-to-pon-port-flow--no-outport-in-tunnelid", |
| 3194 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3195 | } |
| 3196 | // Upstream flow from PON to NNI port , Use tunnel ID as new IN port / UNI port |
| 3197 | } else if portType := IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3198 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3199 | classifierInfo[InPort] = uniPort |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3200 | logger.Debugw(ctx, "upstream-pon-to-nni-port-flow, inport-in-tunnelid", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3201 | log.Fields{ |
| 3202 | "newinport": actionInfo[Output].(uint32), |
| 3203 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3204 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3205 | return olterrors.NewErrNotFound("nni-port", |
| 3206 | log.Fields{ |
| 3207 | "reason": "upstream-pon-to-nni-port-flow--no-inport-in-tunnelid", |
| 3208 | "in-port": classifierInfo[InPort].(uint32), |
| 3209 | "out-port": actionInfo[Output].(uint32), |
| 3210 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3211 | } |
| 3212 | } |
| 3213 | } |
| 3214 | return nil |
| 3215 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3216 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3217 | func getTpIDFromFlow(ctx context.Context, flow *ofp.OfpFlowStats) (uint32, error) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3218 | /* Metadata 8 bytes: |
| 3219 | Most Significant 2 Bytes = Inner VLAN |
| 3220 | Next 2 Bytes = Tech Profile ID(TPID) |
| 3221 | Least Significant 4 Bytes = Port ID |
| 3222 | Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3223 | subscriber related flows. |
| 3224 | */ |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3225 | metadata := flows.GetMetadataFromWriteMetadataAction(ctx, flow) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3226 | if metadata == 0 { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3227 | return 0, olterrors.NewErrNotFound("metadata", log.Fields{"flow": flow}, nil) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3228 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3229 | TpID := flows.GetTechProfileIDFromWriteMetaData(ctx, metadata) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 3230 | return uint32(TpID), nil |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3231 | } |
| 3232 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3233 | func appendUnique64bit(slice []uint64, item uint64) []uint64 { |
| 3234 | for _, sliceElement := range slice { |
| 3235 | if sliceElement == item { |
| 3236 | return slice |
| 3237 | } |
| 3238 | } |
| 3239 | return append(slice, item) |
| 3240 | } |
| 3241 | |
| 3242 | func appendUnique32bit(slice []uint32, item uint32) []uint32 { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3243 | for _, sliceElement := range slice { |
| 3244 | if sliceElement == item { |
| 3245 | return slice |
| 3246 | } |
| 3247 | } |
| 3248 | return append(slice, item) |
| 3249 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3250 | |
| 3251 | // getNniIntfID gets nni intf id from the flow classifier/action |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3252 | func getNniIntfID(ctx context.Context, classifier map[string]interface{}, action map[string]interface{}) (uint32, error) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3253 | |
| 3254 | portType := IntfIDToPortTypeName(classifier[InPort].(uint32)) |
| 3255 | if portType == voltha.Port_PON_OLT { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3256 | intfID, err := IntfIDFromNniPortNum(ctx, action[Output].(uint32)) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3257 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3258 | logger.Debugw(ctx, "invalid-action-port-number", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3259 | log.Fields{ |
| 3260 | "port-number": action[Output].(uint32), |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3261 | "err": err}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3262 | return uint32(0), err |
| 3263 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3264 | logger.Infow(ctx, "output-nni-intfId-is", log.Fields{"intf-id": intfID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3265 | return intfID, nil |
| 3266 | } else if portType == voltha.Port_ETHERNET_NNI { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3267 | intfID, err := IntfIDFromNniPortNum(ctx, classifier[InPort].(uint32)) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3268 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3269 | logger.Debugw(ctx, "invalid-classifier-port-number", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3270 | log.Fields{ |
| 3271 | "port-number": action[Output].(uint32), |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3272 | "err": err}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3273 | return uint32(0), err |
| 3274 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3275 | logger.Infow(ctx, "input-nni-intfId-is", log.Fields{"intf-id": intfID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3276 | return intfID, nil |
| 3277 | } |
| 3278 | return uint32(0), nil |
| 3279 | } |
| 3280 | |
| 3281 | // UpdateGemPortForPktIn updates gemport for packet-in in to the cache and to the kv store as well. |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3282 | func (f *OpenOltFlowMgr) UpdateGemPortForPktIn(ctx context.Context, intfID uint32, onuID uint32, logicalPort uint32, gemPort uint32, pkt []byte) { |
| 3283 | cTag, priority, err := getCTagFromPacket(ctx, pkt) |
| 3284 | if err != nil { |
| 3285 | logger.Errorw(ctx, "unable-to-update-gem-port-for-packet-in", |
| 3286 | log.Fields{"intfID": intfID, "onuID": onuID, "logicalPort": logicalPort, "gemPort": gemPort, "err": err}) |
| 3287 | return |
| 3288 | } |
| 3289 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: logicalPort, VlanID: cTag, Priority: priority} |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3290 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3291 | f.packetInGemPortLock.RLock() |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3292 | lookupGemPort, ok := f.packetInGemPort[pktInkey] |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3293 | f.packetInGemPortLock.RUnlock() |
| 3294 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3295 | if ok { |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3296 | if lookupGemPort == gemPort { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3297 | logger.Infow(ctx, "pktin-key/value-found-in-cache--no-need-to-update-kv--assume-both-in-sync", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3298 | log.Fields{ |
| 3299 | "pktinkey": pktInkey, |
| 3300 | "gem": gemPort}) |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3301 | return |
| 3302 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3303 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3304 | f.packetInGemPortLock.Lock() |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3305 | f.packetInGemPort[pktInkey] = gemPort |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3306 | f.packetInGemPortLock.Unlock() |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3307 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3308 | f.resourceMgr.UpdateGemPortForPktIn(ctx, pktInkey, gemPort) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3309 | logger.Infow(ctx, "pktin-key-not-found-in-local-cache-value-is-different--updating-cache-and-kv-store", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3310 | log.Fields{ |
| 3311 | "pktinkey": pktInkey, |
| 3312 | "gem": gemPort}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3313 | } |
| 3314 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3315 | //getCTagFromPacket retrieves and returns c-tag and priority value from a packet. |
| 3316 | func getCTagFromPacket(ctx context.Context, packet []byte) (uint16, uint8, error) { |
| 3317 | if packet == nil || len(packet) < 18 { |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3318 | logger.Error(ctx, "unable-get-c-tag-from-the-packet--invalid-packet-length ") |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3319 | return 0, 0, errors.New("invalid packet length") |
| 3320 | } |
| 3321 | outerEthType := (uint16(packet[12]) << 8) | uint16(packet[13]) |
| 3322 | innerEthType := (uint16(packet[16]) << 8) | uint16(packet[17]) |
| 3323 | |
| 3324 | var index int8 |
| 3325 | if outerEthType == 0x8100 { |
| 3326 | if innerEthType == 0x8100 { |
| 3327 | // q-in-q 802.1ad or 802.1q double tagged packet. |
| 3328 | // get the inner vlanId |
| 3329 | index = 18 |
| 3330 | } else { |
| 3331 | index = 14 |
| 3332 | } |
| 3333 | priority := (packet[index] >> 5) & 0x7 |
| 3334 | //13 bits composes vlanId value |
| 3335 | vlan := ((uint16(packet[index]) << 8) & 0x0fff) | uint16(packet[index+1]) |
| 3336 | return vlan, priority, nil |
| 3337 | } |
| 3338 | logger.Debugf(ctx, "No vlanId found in the packet. Returning zero as c-tag") |
| 3339 | return 0, 0, nil |
| 3340 | } |
| 3341 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3342 | func (f *OpenOltFlowMgr) loadFlowIDsForGemAndGemIDsForFlow(ctx context.Context) { |
| 3343 | logger.Debug(ctx, "loadFlowIDsForGemAndGemIDsForFlow - start") |
| 3344 | f.onuGemInfoLock.RLock() |
| 3345 | f.gemToFlowIDsKey.Lock() |
| 3346 | f.flowIDToGemsLock.Lock() |
| 3347 | for _, og := range f.onuGemInfoMap { |
| 3348 | for _, gem := range og.GemPorts { |
| 3349 | flowIDs, err := f.resourceMgr.GetFlowIDsForGem(ctx, f.ponPortIdx, gem) |
Gamze Abaka | 3e26851 | 2021-09-08 01:14:33 +0000 | [diff] [blame] | 3350 | if err == nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3351 | f.gemToFlowIDs[gem] = flowIDs |
| 3352 | for _, flowID := range flowIDs { |
| 3353 | if _, ok := f.flowIDToGems[flowID]; !ok { |
| 3354 | f.flowIDToGems[flowID] = []uint32{gem} |
| 3355 | } else { |
| 3356 | f.flowIDToGems[flowID] = appendUnique32bit(f.flowIDToGems[flowID], gem) |
| 3357 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3358 | } |
| 3359 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3360 | } |
| 3361 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3362 | f.flowIDToGemsLock.Unlock() |
| 3363 | f.gemToFlowIDsKey.Unlock() |
| 3364 | f.onuGemInfoLock.RUnlock() |
| 3365 | logger.Debug(ctx, "loadFlowIDsForGemAndGemIDsForFlow - end") |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 3366 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3367 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3368 | //clearMulticastFlowFromResourceManager removes a multicast flow from the KV store and |
| 3369 | // clears resources reserved for this multicast flow |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3370 | func (f *OpenOltFlowMgr) clearMulticastFlowFromResourceManager(ctx context.Context, flow *ofp.OfpFlowStats) error { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3371 | removeFlowMessage := openoltpb2.Flow{FlowId: flow.Id, FlowType: Multicast} |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3372 | logger.Debugw(ctx, "multicast-flow-to-be-deleted", |
| 3373 | log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3374 | "flow": flow, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3375 | "flow-id": flow.Id, |
| 3376 | "device-id": f.deviceHandler.device.Id}) |
| 3377 | // Remove from device |
| 3378 | if err := f.removeFlowFromDevice(ctx, &removeFlowMessage, flow.Id); err != nil { |
| 3379 | // DKB |
| 3380 | logger.Errorw(ctx, "failed-to-remove-multicast-flow", |
| 3381 | log.Fields{ |
| 3382 | "flow-id": flow.Id, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3383 | "err": err}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3384 | return err |
| 3385 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3386 | |
| 3387 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3390 | func (f *OpenOltFlowMgr) getTechProfileDownloadMessage(ctx context.Context, tpPath string, ponID uint32, onuID uint32, uniID uint32) *ic.InterAdapterTechProfileDownloadMessage { |
| 3391 | tpInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3392 | if err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3393 | logger.Errorw(ctx, "error-fetching-tp-instance", log.Fields{"tpPath": tpPath}) |
| 3394 | return nil |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3397 | switch tpInst := tpInst.(type) { |
| 3398 | case *tp_pb.TechProfileInstance: |
| 3399 | logger.Debugw(ctx, "fetched-tp-instance-successfully--formulating-tp-download-msg", log.Fields{"tpPath": tpPath}) |
| 3400 | return &ic.InterAdapterTechProfileDownloadMessage{UniId: uniID, |
| 3401 | TpInstancePath: tpPath, |
| 3402 | TechTpInstance: &ic.InterAdapterTechProfileDownloadMessage_TpInstance{TpInstance: tpInst}, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3403 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3404 | case *openoltpb2.EponTechProfileInstance: |
| 3405 | return &ic.InterAdapterTechProfileDownloadMessage{UniId: uniID, |
| 3406 | TpInstancePath: tpPath, |
| 3407 | TechTpInstance: &ic.InterAdapterTechProfileDownloadMessage_EponTpInstance{EponTpInstance: tpInst}, |
| 3408 | } |
| 3409 | default: |
| 3410 | logger.Errorw(ctx, "unknown-tech", log.Fields{"tpPath": tpPath}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3411 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3412 | return nil |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
Girish Gowdra | bcf98af | 2021-07-01 08:24:42 -0700 | [diff] [blame] | 3415 | func (f *OpenOltFlowMgr) getOnuGemInfoList(ctx context.Context) []rsrcMgr.OnuGemInfo { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3416 | var onuGemInfoLst []rsrcMgr.OnuGemInfo |
| 3417 | f.onuGemInfoLock.RLock() |
| 3418 | defer f.onuGemInfoLock.RUnlock() |
| 3419 | for _, v := range f.onuGemInfoMap { |
| 3420 | onuGemInfoLst = append(onuGemInfoLst, *v) |
| 3421 | } |
| 3422 | return onuGemInfoLst |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3423 | } |