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