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