manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "crypto/md5" |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 23 | "encoding/hex" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 24 | "encoding/json" |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 25 | "errors" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 26 | "fmt" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 27 | "math/big" |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 28 | "strings" |
William Kurkian | 740a09c | 2019-10-23 17:07:38 -0400 | [diff] [blame] | 29 | "sync" |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 30 | "time" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 31 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v3/pkg/flows" |
| 33 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 34 | tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 35 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v3/go/common" |
| 37 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 38 | ofp "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 39 | openoltpb2 "github.com/opencord/voltha-protos/v3/go/openolt" |
| 40 | tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile" |
| 41 | "github.com/opencord/voltha-protos/v3/go/voltha" |
Chaitrashree G S | 579fe73 | 2019-08-20 20:50:47 -0400 | [diff] [blame] | 42 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 43 | //deepcopy "github.com/getlantern/deepcopy" |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 44 | "github.com/EagleChen/mapmutex" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 45 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 46 | "google.golang.org/grpc/codes" |
| 47 | "google.golang.org/grpc/status" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 48 | ) |
| 49 | |
| 50 | const ( |
| 51 | // Flow categories |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 52 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 53 | //HsiaFlow flow category |
| 54 | HsiaFlow = "HSIA_FLOW" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 55 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 56 | //EapolFlow flow category |
| 57 | EapolFlow = "EAPOL_FLOW" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 58 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 59 | //DhcpFlow flow category |
| 60 | DhcpFlow = "DHCP_FLOW" |
| 61 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 62 | //MulticastFlow flow category |
| 63 | MulticastFlow = "MULTICAST_FLOW" |
| 64 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 65 | //IgmpFlow flow category |
| 66 | IgmpFlow = "IGMP_FLOW" |
| 67 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 68 | //IPProtoDhcp flow category |
| 69 | IPProtoDhcp = 17 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 70 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 71 | //IPProtoIgmp flow category |
| 72 | IPProtoIgmp = 2 |
| 73 | |
| 74 | //EapEthType eapethtype value |
| 75 | EapEthType = 0x888e |
| 76 | //LldpEthType lldp ethtype value |
| 77 | LldpEthType = 0x88cc |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 78 | //IPv4EthType IPv4 ethernet type value |
| 79 | IPv4EthType = 0x800 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 80 | |
| 81 | //IgmpProto proto value |
| 82 | IgmpProto = 2 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 83 | |
Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 84 | //ReservedVlan Transparent Vlan (Masked Vlan, VLAN_ANY in ONOS Flows) |
| 85 | ReservedVlan = 4096 |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 86 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 87 | //DefaultMgmtVlan default vlan value |
| 88 | DefaultMgmtVlan = 4091 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 89 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 90 | // Openolt Flow |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 91 | |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 92 | //Upstream constant |
| 93 | Upstream = "upstream" |
| 94 | //Downstream constant |
| 95 | Downstream = "downstream" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 96 | //Multicast constant |
| 97 | Multicast = "multicast" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 98 | //PacketTagType constant |
| 99 | PacketTagType = "pkt_tag_type" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 100 | //Untagged constant |
| 101 | Untagged = "untagged" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 102 | //SingleTag constant |
| 103 | SingleTag = "single_tag" |
| 104 | //DoubleTag constant |
| 105 | DoubleTag = "double_tag" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 106 | |
| 107 | // classifierInfo |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 108 | |
| 109 | //EthType constant |
| 110 | EthType = "eth_type" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 111 | //EthDst constant |
| 112 | EthDst = "eth_dst" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 113 | //TPID constant |
| 114 | TPID = "tpid" |
| 115 | //IPProto constant |
| 116 | IPProto = "ip_proto" |
| 117 | //InPort constant |
| 118 | InPort = "in_port" |
| 119 | //VlanVid constant |
| 120 | VlanVid = "vlan_vid" |
| 121 | //VlanPcp constant |
| 122 | VlanPcp = "vlan_pcp" |
| 123 | |
| 124 | //UDPDst constant |
| 125 | UDPDst = "udp_dst" |
| 126 | //UDPSrc constant |
| 127 | UDPSrc = "udp_src" |
| 128 | //Ipv4Dst constant |
| 129 | Ipv4Dst = "ipv4_dst" |
| 130 | //Ipv4Src constant |
| 131 | Ipv4Src = "ipv4_src" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 132 | //Metadata constant |
| 133 | Metadata = "metadata" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 134 | //TunnelID constant |
| 135 | TunnelID = "tunnel_id" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 136 | //Output constant |
| 137 | Output = "output" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 138 | //GroupID constant |
| 139 | GroupID = "group_id" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 140 | // Actions |
| 141 | |
| 142 | //PopVlan constant |
| 143 | PopVlan = "pop_vlan" |
| 144 | //PushVlan constant |
| 145 | PushVlan = "push_vlan" |
| 146 | //TrapToHost constant |
| 147 | TrapToHost = "trap_to_host" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 148 | //MaxMeterBand constant |
| 149 | MaxMeterBand = 2 |
| 150 | //VlanPCPMask contant |
| 151 | VlanPCPMask = 0xFF |
| 152 | //VlanvIDMask constant |
| 153 | VlanvIDMask = 0xFFF |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 154 | //IntfID constant |
| 155 | IntfID = "intfId" |
| 156 | //OnuID constant |
| 157 | OnuID = "onuId" |
| 158 | //UniID constant |
| 159 | UniID = "uniId" |
| 160 | //PortNo constant |
| 161 | PortNo = "portNo" |
| 162 | //AllocID constant |
| 163 | AllocID = "allocId" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 164 | |
| 165 | //NoneOnuID constant |
| 166 | NoneOnuID = -1 |
| 167 | //NoneUniID constant |
| 168 | NoneUniID = -1 |
| 169 | //NoneGemPortID constant |
| 170 | NoneGemPortID = -1 |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 171 | |
| 172 | // BinaryStringPrefix is binary string prefix |
| 173 | BinaryStringPrefix = "0b" |
| 174 | // BinaryBit1 is binary bit 1 expressed as a character |
| 175 | BinaryBit1 = '1' |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 176 | ) |
| 177 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 178 | type gemPortKey struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 179 | intfID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 180 | gemPort uint32 |
| 181 | } |
| 182 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 183 | type pendingFlowDeleteKey struct { |
| 184 | intfID uint32 |
| 185 | onuID uint32 |
| 186 | uniID uint32 |
| 187 | } |
| 188 | |
| 189 | type tpLockKey struct { |
| 190 | intfID uint32 |
| 191 | onuID uint32 |
| 192 | uniID uint32 |
| 193 | } |
| 194 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 195 | type schedQueue struct { |
| 196 | direction tp_pb.Direction |
| 197 | intfID uint32 |
| 198 | onuID uint32 |
| 199 | uniID uint32 |
| 200 | tpID uint32 |
| 201 | uniPort uint32 |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 202 | tpInst interface{} |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 203 | meterID uint32 |
| 204 | flowMetadata *voltha.FlowMetadata |
| 205 | } |
| 206 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 207 | type queueInfoBrief struct { |
| 208 | gemPortID uint32 |
| 209 | servicePriority uint32 |
| 210 | } |
| 211 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 212 | //OpenOltFlowMgr creates the Structure of OpenOltFlowMgr obj |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 213 | type OpenOltFlowMgr struct { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 214 | techprofile map[uint32]tp.TechProfileIf |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 215 | deviceHandler *DeviceHandler |
| 216 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 217 | onuIdsLock sync.RWMutex |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 218 | perGemPortLock *mapmutex.Mutex // lock to be used to access the flowsUsedByGemPort map |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 219 | flowsUsedByGemPort map[gemPortKey][]uint32 //gem port id to flow ids |
| 220 | packetInGemPort map[rsrcMgr.PacketInInfoKey]uint32 //packet in gem port local cache |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 221 | // TODO create a type rsrcMgr.OnuGemInfos to be used instead of []rsrcMgr.OnuGemInfo |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 222 | onuGemInfo map[uint32][]rsrcMgr.OnuGemInfo //onu, gem and uni info local cache, indexed by IntfId |
| 223 | // We need to have a global lock on the onuGemInfo map |
| 224 | onuGemInfoLock sync.RWMutex |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 225 | pendingFlowDelete sync.Map |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 226 | // The mapmutex.Mutex can be fine tuned to use mapmutex.NewCustomizedMapMutex |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 227 | perUserFlowHandleLock *mapmutex.Mutex |
| 228 | interfaceToMcastQueueMap map[uint32]*queueInfoBrief /*pon interface -> multicast queue map. Required to assign GEM to a bucket during group population*/ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 229 | } |
| 230 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 231 | //NewFlowManager creates OpenOltFlowMgr object and initializes the parameters |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 232 | func NewFlowManager(ctx context.Context, dh *DeviceHandler, rMgr *rsrcMgr.OpenOltResourceMgr) *OpenOltFlowMgr { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 233 | logger.Infow("initializing-flow-manager", log.Fields{"device-id": dh.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 234 | var flowMgr OpenOltFlowMgr |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 235 | var err error |
| 236 | var idx uint32 |
| 237 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 238 | flowMgr.deviceHandler = dh |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 239 | flowMgr.resourceMgr = rMgr |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 240 | flowMgr.techprofile = make(map[uint32]tp.TechProfileIf) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 241 | if err = flowMgr.populateTechProfilePerPonPort(); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 242 | logger.Errorw("error-while-populating-tech-profile-mgr", log.Fields{"error": err}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 243 | return nil |
| 244 | } |
William Kurkian | 740a09c | 2019-10-23 17:07:38 -0400 | [diff] [blame] | 245 | flowMgr.onuIdsLock = sync.RWMutex{} |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 246 | flowMgr.flowsUsedByGemPort = make(map[gemPortKey][]uint32) |
| 247 | flowMgr.packetInGemPort = make(map[rsrcMgr.PacketInInfoKey]uint32) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 248 | ponPorts := rMgr.DevInfo.GetPonPorts() |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 249 | flowMgr.onuGemInfo = make(map[uint32][]rsrcMgr.OnuGemInfo, ponPorts) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 250 | //Load the onugem info cache from kv store on flowmanager start |
| 251 | for idx = 0; idx < ponPorts; idx++ { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 252 | if flowMgr.onuGemInfo[idx], err = rMgr.GetOnuGemInfo(ctx, idx); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 253 | logger.Error("failed-to-load-onu-gem-info-cache") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 254 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 255 | //Load flowID list per gem map per interface from the kvstore. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 256 | flowMgr.loadFlowIDlistForGem(ctx, idx) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 257 | } |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 258 | flowMgr.onuGemInfoLock = sync.RWMutex{} |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 259 | flowMgr.pendingFlowDelete = sync.Map{} |
Girish Gowdra | b77ded9 | 2020-04-08 11:45:05 -0700 | [diff] [blame] | 260 | flowMgr.perUserFlowHandleLock = mapmutex.NewCustomizedMapMutex(300, 100000000, 10000000, 1.1, 0.2) |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 261 | flowMgr.perGemPortLock = mapmutex.NewCustomizedMapMutex(300, 100000000, 10000000, 1.1, 0.2) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 262 | flowMgr.interfaceToMcastQueueMap = make(map[uint32]*queueInfoBrief) |
| 263 | //load interface to multicast queue map from kv store |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 264 | flowMgr.loadInterfaceToMulticastQueueMap(ctx) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 265 | logger.Info("initialization-of-flow-manager-success") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 266 | return &flowMgr |
| 267 | } |
| 268 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 269 | func (f *OpenOltFlowMgr) generateStoredFlowID(flowID uint32, direction string) (uint64, error) { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 270 | if direction == Upstream { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 271 | logger.Debugw("upstream-flow-shifting-id", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 272 | return 0x1<<15 | uint64(flowID), nil |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 273 | } else if direction == Downstream { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 274 | logger.Debugw("downstream-flow-not-shifting-id", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 275 | return uint64(flowID), nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 276 | } else if direction == Multicast { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 277 | logger.Debugw("multicast-flow-shifting-id", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 278 | return 0x2<<15 | uint64(flowID), nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 279 | } else { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 280 | return 0, olterrors.NewErrInvalidValue(log.Fields{"direction": direction}, nil).Log() |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 284 | func (f *OpenOltFlowMgr) registerFlow(ctx context.Context, flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) { |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 285 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 286 | gemPK := gemPortKey{uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId)} |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 287 | if f.perGemPortLock.TryLock(gemPK) { |
| 288 | logger.Debugw("registering-flow-for-device", |
| 289 | log.Fields{ |
| 290 | "flow": flowFromCore, |
| 291 | "device-id": f.deviceHandler.device.Id}) |
| 292 | flowIDList, ok := f.flowsUsedByGemPort[gemPK] |
| 293 | if !ok { |
| 294 | flowIDList = []uint32{deviceFlow.FlowId} |
| 295 | } |
| 296 | flowIDList = appendUnique(flowIDList, deviceFlow.FlowId) |
| 297 | f.flowsUsedByGemPort[gemPK] = flowIDList |
| 298 | // update the flowids for a gem to the KVstore |
| 299 | f.resourceMgr.UpdateFlowIDsForGem(ctx, uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId), flowIDList) |
| 300 | f.perGemPortLock.Unlock(gemPK) |
| 301 | } else { |
| 302 | logger.Error("failed-to-acquire-per-gem-port-lock", |
| 303 | log.Fields{ |
| 304 | "flow": flowFromCore, |
| 305 | "device-id": f.deviceHandler.device.Id, |
| 306 | "key": gemPK, |
| 307 | }) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 308 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 309 | } |
| 310 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 311 | func (f *OpenOltFlowMgr) divideAndAddFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 312 | classifierInfo map[string]interface{}, actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpID uint32, |
| 313 | UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 314 | var allocID uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 315 | var gemPorts []uint32 |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 316 | var TpInst interface{} |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 317 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 318 | logger.Infow("dividing-flow", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 319 | "device-id": f.deviceHandler.device.Id, |
| 320 | "intf-id": intfID, |
| 321 | "onu-id": onuID, |
| 322 | "uni-id": uniID, |
| 323 | "port-no": portNo, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 324 | "classifier": classifierInfo, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 325 | "action": actionInfo, |
| 326 | "usmeter-iD": UsMeterID, |
| 327 | "dsmeter-iD": DsMeterID, |
| 328 | "tp-id": TpID}) |
Matt Jeanneret | 7719961 | 2019-07-26 18:08:35 -0400 | [diff] [blame] | 329 | // only create tcont/gemports if there is actually an onu id. otherwise BAL throws an error. Usually this |
| 330 | // is because the flow is an NNI flow and there would be no onu resources associated with it |
| 331 | // TODO: properly deal with NNI flows |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 332 | if onuID <= 0 { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 333 | logger.Errorw("no-onu-id-for-flow", |
| 334 | log.Fields{ |
| 335 | "port-no": portNo, |
| 336 | "classifer": classifierInfo, |
| 337 | "action": actionInfo, |
| 338 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 339 | return |
| 340 | } |
| 341 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 342 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 343 | logger.Debugw("uni-port-path", log.Fields{ |
| 344 | "uni": uni, |
| 345 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 346 | |
| 347 | tpLockMapKey := tpLockKey{intfID, onuID, uniID} |
| 348 | if f.perUserFlowHandleLock.TryLock(tpLockMapKey) { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 349 | logger.Debugw("dividing-flow-create-tcont-gem-ports", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 350 | "device-id": f.deviceHandler.device.Id, |
| 351 | "intf-id": intfID, |
| 352 | "onu-id": onuID, |
| 353 | "uni-id": uniID, |
| 354 | "port-no": portNo, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 355 | "classifier": classifierInfo, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 356 | "action": actionInfo, |
| 357 | "usmeter-id": UsMeterID, |
| 358 | "dsmeter-id": DsMeterID, |
| 359 | "tp-id": TpID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 360 | allocID, gemPorts, TpInst = f.createTcontGemports(ctx, intfID, onuID, uniID, uni, portNo, TpID, UsMeterID, DsMeterID, flowMetadata) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 361 | if allocID == 0 || gemPorts == nil || TpInst == nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 362 | logger.Error("alloc-id-gem-ports-tp-unavailable") |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 363 | f.perUserFlowHandleLock.Unlock(tpLockMapKey) |
| 364 | return |
| 365 | } |
| 366 | args := make(map[string]uint32) |
| 367 | args[IntfID] = intfID |
| 368 | args[OnuID] = onuID |
| 369 | args[UniID] = uniID |
| 370 | args[PortNo] = portNo |
| 371 | args[AllocID] = allocID |
| 372 | |
| 373 | /* Flows can be added specific to gemport if p-bits are received. |
| 374 | * If no pbit mentioned then adding flows for all gemports |
| 375 | */ |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 376 | f.checkAndAddFlow(ctx, args, classifierInfo, actionInfo, flow, TpInst, gemPorts, TpID, uni) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 377 | f.perUserFlowHandleLock.Unlock(tpLockMapKey) |
| 378 | } else { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 379 | logger.Errorw("failed-to-acquire-per-user-flow-handle-lock", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 380 | log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 381 | "intf-id": intfID, |
| 382 | "onu-id": onuID, |
| 383 | "uni-id": uniID, |
| 384 | "flow-id": flow.Id, |
| 385 | "flow-cookie": flow.Cookie, |
| 386 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 387 | return |
| 388 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 389 | } |
| 390 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 391 | // CreateSchedulerQueues creates traffic schedulers on the device with the given scheduler configuration and traffic shaping info |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 392 | func (f *OpenOltFlowMgr) CreateSchedulerQueues(ctx context.Context, sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 393 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 394 | logger.Debugw("CreateSchedulerQueues", |
| 395 | log.Fields{"dir": sq.direction, |
| 396 | "intf-id": sq.intfID, |
| 397 | "onu-id": sq.onuID, |
| 398 | "uni-id": sq.uniID, |
| 399 | "tp-id": sq.tpID, |
| 400 | "meter-id": sq.meterID, |
| 401 | "tp-inst": sq.tpInst, |
| 402 | "flowmetadata": sq.flowMetadata, |
| 403 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 404 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 405 | Direction, err := verifyMeterIDAndGetDirection(sq.meterID, sq.direction) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 406 | if err != nil { |
| 407 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* Lets make a simple assumption that if the meter-id is present on the KV store, |
| 411 | * then the scheduler and queues configuration is applied on the OLT device |
| 412 | * in the given direction. |
| 413 | */ |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 414 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 415 | var SchedCfg *tp_pb.SchedulerConfig |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 416 | KvStoreMeter, err := f.resourceMgr.GetMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 417 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 418 | return olterrors.NewErrNotFound("meter", |
| 419 | log.Fields{"intf-id": sq.intfID, |
| 420 | "onu-id": sq.onuID, |
| 421 | "uni-id": sq.uniID, |
| 422 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 423 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 424 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 425 | if KvStoreMeter != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 426 | if KvStoreMeter.MeterId == sq.meterID { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 427 | logger.Debugw("scheduler-already-created-for-upstream", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 428 | return nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 429 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 430 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 431 | "unsupported": "meter-id", |
| 432 | "kv-store-meter-id": KvStoreMeter.MeterId, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 433 | "meter-id-in-flow": sq.meterID, |
| 434 | "device-id": f.deviceHandler.device.Id}, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 435 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 436 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 437 | logger.Debugw("meter-does-not-exist-creating-new", |
| 438 | log.Fields{ |
| 439 | "meter-id": sq.meterID, |
| 440 | "direction": Direction, |
| 441 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 442 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 443 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 444 | SchedCfg, err = f.techprofile[sq.intfID].GetUsScheduler(sq.tpInst.(*tp.TechProfile)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 445 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 446 | SchedCfg, err = f.techprofile[sq.intfID].GetDsScheduler(sq.tpInst.(*tp.TechProfile)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 447 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 448 | |
| 449 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 450 | return olterrors.NewErrNotFound("scheduler-config", |
| 451 | log.Fields{ |
| 452 | "intf-id": sq.intfID, |
| 453 | "direction": sq.direction, |
| 454 | "tp-inst": sq.tpInst, |
| 455 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 458 | var meterConfig *ofp.OfpMeterConfig |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 459 | if sq.flowMetadata != nil { |
| 460 | for _, meter := range sq.flowMetadata.Meters { |
| 461 | if sq.meterID == meter.MeterId { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 462 | meterConfig = meter |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 463 | logger.Debugw("found-meter-config-from-flowmetadata", |
| 464 | log.Fields{"meterConfig": meterConfig, |
| 465 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 466 | break |
| 467 | } |
| 468 | } |
| 469 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 470 | logger.Errorw("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] | 471 | } |
| 472 | if meterConfig == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 473 | return olterrors.NewErrNotFound("meterbands", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 474 | "reason": "Could-not-get-meterbands-from-flowMetadata", |
| 475 | "flow-metadata": sq.flowMetadata, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 476 | "meter-id": sq.meterID, |
| 477 | "device-id": f.deviceHandler.device.Id}, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 478 | } else if len(meterConfig.Bands) < MaxMeterBand { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 479 | logger.Errorw("invalid-number-of-bands-in-meter", |
| 480 | log.Fields{"Bands": meterConfig.Bands, |
| 481 | "meter-id": sq.meterID, |
| 482 | "device-id": f.deviceHandler.device.Id}) |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 483 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 484 | "reason": "Invalid-number-of-bands-in-meter", |
| 485 | "meterband-count": len(meterConfig.Bands), |
| 486 | "metabands": meterConfig.Bands, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 487 | "meter-id": sq.meterID, |
| 488 | "device-id": f.deviceHandler.device.Id}, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 489 | } |
| 490 | cir := meterConfig.Bands[0].Rate |
| 491 | cbs := meterConfig.Bands[0].BurstSize |
| 492 | eir := meterConfig.Bands[1].Rate |
| 493 | ebs := meterConfig.Bands[1].BurstSize |
| 494 | pir := cir + eir |
| 495 | pbs := cbs + ebs |
| 496 | TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: cir, Cbs: cbs, Pir: pir, Pbs: pbs} |
| 497 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 498 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile[sq.intfID].GetTrafficScheduler(sq.tpInst.(*tp.TechProfile), SchedCfg, TrafficShaping)} |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 499 | TrafficSched[0].TechProfileId = sq.tpID |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 500 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 501 | if err := f.pushSchedulerQueuesToDevice(ctx, sq, TrafficShaping, TrafficSched); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 502 | return olterrors.NewErrAdapter("failure-pushing-traffic-scheduler-and-queues-to-device", |
| 503 | log.Fields{"intf-id": sq.intfID, |
| 504 | "direction": sq.direction, |
| 505 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 506 | } |
| 507 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 508 | /* After we successfully applied the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 509 | * store the meter id on the KV store, for further reference. |
| 510 | */ |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 511 | if err := f.resourceMgr.UpdateMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID, meterConfig); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 512 | return olterrors.NewErrAdapter("failed-updating-meter-id", |
| 513 | log.Fields{"onu-id": sq.onuID, |
| 514 | "meter-id": sq.meterID, |
| 515 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 516 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 517 | logger.Infow("updated-meter-info-into-kv-store-successfully", |
| 518 | log.Fields{"direction": Direction, |
| 519 | "Meter": meterConfig, |
| 520 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 521 | return nil |
| 522 | } |
| 523 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 524 | func (f *OpenOltFlowMgr) pushSchedulerQueuesToDevice(ctx context.Context, sq schedQueue, TrafficShaping *tp_pb.TrafficShapingInfo, TrafficSched []*tp_pb.TrafficScheduler) error { |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 525 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 526 | trafficQueues, err := f.techprofile[sq.intfID].GetTrafficQueues(sq.tpInst.(*tp.TechProfile), sq.direction) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 527 | |
| 528 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 529 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 530 | log.Fields{"intf-id": sq.intfID, |
| 531 | "direction": sq.direction, |
| 532 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 535 | logger.Debugw("sending-traffic-scheduler-create-to-device", |
| 536 | log.Fields{ |
| 537 | "direction": sq.direction, |
| 538 | "TrafficScheds": TrafficSched, |
| 539 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 540 | if _, err := f.deviceHandler.Client.CreateTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 541 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 542 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 543 | TrafficScheds: TrafficSched}); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 544 | return olterrors.NewErrAdapter("failed-to-create-traffic-schedulers-in-device", log.Fields{"TrafficScheds": TrafficSched}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 545 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 546 | logger.Infow("successfully-created-traffic-schedulers", log.Fields{ |
| 547 | "direction": sq.direction, |
| 548 | "traffic-queues": trafficQueues, |
| 549 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 550 | |
| 551 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 552 | // downstream queues. |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 553 | logger.Debugw("sending-traffic-queues-create-to-device", |
| 554 | log.Fields{"direction": sq.direction, |
| 555 | "traffic-queues": trafficQueues, |
| 556 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 557 | if _, err := f.deviceHandler.Client.CreateTrafficQueues(ctx, |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 558 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 559 | UniId: sq.uniID, PortNo: sq.uniPort, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 560 | TrafficQueues: trafficQueues, |
| 561 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 562 | 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] | 563 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 564 | logger.Infow("successfully-created-traffic-schedulers", log.Fields{ |
| 565 | "direction": sq.direction, |
| 566 | "traffic-queues": trafficQueues, |
| 567 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 568 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 569 | if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 570 | multicastTrafficQueues := f.techprofile[sq.intfID].GetMulticastTrafficQueues(sq.tpInst.(*tp.TechProfile)) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 571 | if len(multicastTrafficQueues) > 0 { |
| 572 | if _, present := f.interfaceToMcastQueueMap[sq.intfID]; !present { |
| 573 | //assumed that there is only one queue per PON for the multicast service |
| 574 | //the default queue with multicastQueuePerPonPort.Priority per a pon interface is used for multicast service |
| 575 | //just put it in interfaceToMcastQueueMap to use for building group members |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 576 | logger.Debugw("multicast-traffic-queues", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 577 | multicastQueuePerPonPort := multicastTrafficQueues[0] |
| 578 | f.interfaceToMcastQueueMap[sq.intfID] = &queueInfoBrief{ |
| 579 | gemPortID: multicastQueuePerPonPort.GemportId, |
| 580 | servicePriority: multicastQueuePerPonPort.Priority, |
| 581 | } |
| 582 | //also store the queue info in kv store |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 583 | f.resourceMgr.AddMcastQueueForIntf(ctx, sq.intfID, |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 584 | multicastQueuePerPonPort.GemportId, |
| 585 | multicastQueuePerPonPort.Priority) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 586 | |
| 587 | logger.Infow("multicast-queues-successfully-updated", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 591 | return nil |
| 592 | } |
| 593 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 594 | // 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] | 595 | func (f *OpenOltFlowMgr) RemoveSchedulerQueues(ctx context.Context, sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 596 | |
| 597 | var Direction string |
| 598 | var SchedCfg *tp_pb.SchedulerConfig |
| 599 | var err error |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 600 | logger.Infow("removing-schedulers-and-queues-in-olt", |
| 601 | log.Fields{ |
| 602 | "direction": sq.direction, |
| 603 | "intf-id": sq.intfID, |
| 604 | "onu-id": sq.onuID, |
| 605 | "uni-id": sq.uniID, |
| 606 | "uni-port": sq.uniPort, |
| 607 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 608 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 609 | SchedCfg, err = f.techprofile[sq.intfID].GetUsScheduler(sq.tpInst.(*tp.TechProfile)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 610 | Direction = "upstream" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 611 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 612 | SchedCfg, err = f.techprofile[sq.intfID].GetDsScheduler(sq.tpInst.(*tp.TechProfile)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 613 | Direction = "downstream" |
| 614 | } |
| 615 | |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 616 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 617 | return olterrors.NewErrNotFound("scheduler-config", |
| 618 | log.Fields{ |
| 619 | "int-id": sq.intfID, |
| 620 | "direction": sq.direction, |
| 621 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 622 | } |
| 623 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 624 | KVStoreMeter, err := f.resourceMgr.GetMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 625 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 626 | return olterrors.NewErrNotFound("meter", |
| 627 | log.Fields{ |
| 628 | "onu-id": sq.onuID, |
| 629 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 630 | } |
| 631 | if KVStoreMeter == nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 632 | logger.Warnw("no-meter-installed-yet", |
| 633 | log.Fields{ |
| 634 | "direction": Direction, |
| 635 | "intf-id": sq.intfID, |
| 636 | "onu-id": sq.onuID, |
| 637 | "uni-id": sq.uniID, |
| 638 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 639 | return nil |
| 640 | } |
| 641 | cir := KVStoreMeter.Bands[0].Rate |
| 642 | cbs := KVStoreMeter.Bands[0].BurstSize |
| 643 | eir := KVStoreMeter.Bands[1].Rate |
| 644 | ebs := KVStoreMeter.Bands[1].BurstSize |
| 645 | pir := cir + eir |
| 646 | pbs := cbs + ebs |
| 647 | |
| 648 | TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: cir, Cbs: cbs, Pir: pir, Pbs: pbs} |
| 649 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 650 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile[sq.intfID].GetTrafficScheduler(sq.tpInst.(*tp.TechProfile), SchedCfg, TrafficShaping)} |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 651 | TrafficSched[0].TechProfileId = sq.tpID |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 652 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 653 | TrafficQueues, err := f.techprofile[sq.intfID].GetTrafficQueues(sq.tpInst.(*tp.TechProfile), sq.direction) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 654 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 655 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 656 | log.Fields{ |
| 657 | "intf-id": sq.intfID, |
| 658 | "direction": sq.direction, |
| 659 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 660 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 661 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 662 | if _, err = f.deviceHandler.Client.RemoveTrafficQueues(ctx, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 663 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 664 | UniId: sq.uniID, PortNo: sq.uniPort, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 665 | TrafficQueues: TrafficQueues, |
| 666 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 667 | return olterrors.NewErrAdapter("unable-to-remove-traffic-queues-from-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 668 | log.Fields{ |
| 669 | "intf-id": sq.intfID, |
| 670 | "traffic-queues": TrafficQueues, |
| 671 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 672 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 673 | logger.Infow("removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 674 | if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 675 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 676 | UniId: sq.uniID, PortNo: sq.uniPort, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 677 | TrafficScheds: TrafficSched}); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 678 | return olterrors.NewErrAdapter("unable-to-remove-traffic-schedulers-from-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 679 | log.Fields{ |
| 680 | "intf-id": sq.intfID, |
| 681 | "traffic-schedulers": TrafficSched}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 682 | } |
| 683 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 684 | logger.Infow("removed-traffic-schedulers-successfully", log.Fields{"device-id": f.deviceHandler.device.Id}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 685 | |
| 686 | /* After we successfully remove the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 687 | * delete the meter id on the KV store. |
| 688 | */ |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 689 | err = f.resourceMgr.RemoveMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 690 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 691 | return olterrors.NewErrAdapter("unable-to-remove-meter", |
| 692 | log.Fields{ |
| 693 | "onu": sq.onuID, |
| 694 | "meter": KVStoreMeter.MeterId, |
| 695 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 696 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 697 | logger.Infow("removed-meter-from-KV-store-successfully", |
| 698 | log.Fields{ |
| 699 | "meter-id": KVStoreMeter.MeterId, |
| 700 | "dir": Direction, |
| 701 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 702 | return err |
| 703 | } |
| 704 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 705 | // This function allocates tconts and GEM ports for an ONU |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 706 | func (f *OpenOltFlowMgr) createTcontGemports(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uni string, uniPort uint32, TpID uint32, UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) (uint32, []uint32, interface{}) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 707 | var allocIDs []uint32 |
| 708 | var allgemPortIDs []uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 709 | var gemPortIDs []uint32 |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 710 | tpInstanceExists := false |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 711 | var err error |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 712 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 713 | allocIDs = f.resourceMgr.GetCurrentAllocIDsForOnu(ctx, intfID, onuID, uniID) |
| 714 | allgemPortIDs = f.resourceMgr.GetCurrentGEMPortIDsForOnu(ctx, intfID, onuID, uniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 715 | |
| 716 | tpPath := f.getTPpath(intfID, uni, TpID) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 717 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 718 | logger.Debugw("creating-new-tcont-and-gem", log.Fields{ |
| 719 | "intf-id": intfID, |
| 720 | "onu-id": onuID, |
| 721 | "uni-id": uniID, |
| 722 | "device-id": f.deviceHandler.device.Id, |
| 723 | "tp-id": TpID}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 724 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 725 | // Check tech profile instance already exists for derived port name |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 726 | techProfileInstance, _ := f.techprofile[intfID].GetTPInstanceFromKVStore(ctx, TpID, tpPath) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 727 | if techProfileInstance == nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 728 | logger.Infow("tp-instance-not-found--creating-new", |
| 729 | log.Fields{ |
| 730 | "path": tpPath, |
| 731 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 732 | techProfileInstance, err = f.techprofile[intfID].CreateTechProfInstance(ctx, TpID, uni, intfID) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 733 | if err != nil { |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 734 | // This should not happen, something wrong in KV backend transaction |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 735 | logger.Errorw("tp-instance-create-failed", |
| 736 | log.Fields{ |
| 737 | "error": err, |
| 738 | "tp-id": TpID, |
| 739 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 740 | return 0, nil, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 741 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 742 | f.resourceMgr.UpdateTechProfileIDForOnu(ctx, intfID, onuID, uniID, TpID) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 743 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 744 | logger.Debugw("tech-profile-instance-already-exist-for-given port-name", |
| 745 | log.Fields{ |
| 746 | "uni": uni, |
| 747 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 748 | tpInstanceExists = true |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 749 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 750 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 751 | switch tpInst := techProfileInstance.(type) { |
| 752 | case *tp.TechProfile: |
| 753 | if UsMeterID != 0 { |
| 754 | sq := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 755 | uniPort: uniPort, tpInst: techProfileInstance, meterID: UsMeterID, flowMetadata: flowMetadata} |
| 756 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
| 757 | logger.Errorw("CreateSchedulerQueues-failed-upstream", |
| 758 | log.Fields{ |
| 759 | "error": err, |
| 760 | "meter-id": UsMeterID, |
| 761 | "device-id": f.deviceHandler.device.Id}) |
| 762 | return 0, nil, nil |
| 763 | } |
| 764 | } |
| 765 | if DsMeterID != 0 { |
| 766 | sq := schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 767 | uniPort: uniPort, tpInst: techProfileInstance, meterID: DsMeterID, flowMetadata: flowMetadata} |
| 768 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
| 769 | logger.Errorw("CreateSchedulerQueues-failed-downstream", |
| 770 | log.Fields{ |
| 771 | "error": err, |
| 772 | "meter-id": DsMeterID, |
| 773 | "device-id": f.deviceHandler.device.Id}) |
| 774 | return 0, nil, nil |
| 775 | } |
| 776 | } |
| 777 | allocID := tpInst.UsScheduler.AllocID |
| 778 | for _, gem := range tpInst.UpstreamGemPortAttributeList { |
| 779 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 780 | } |
| 781 | allocIDs = appendUnique(allocIDs, allocID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 782 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 783 | if tpInstanceExists { |
| 784 | return allocID, gemPortIDs, techProfileInstance |
| 785 | } |
| 786 | |
| 787 | for _, gemPortID := range gemPortIDs { |
| 788 | allgemPortIDs = appendUnique(allgemPortIDs, gemPortID) |
| 789 | } |
| 790 | logger.Infow("allocated-tcont-and-gem-ports", |
| 791 | log.Fields{ |
| 792 | "alloc-ids": allocIDs, |
| 793 | "gemports": allgemPortIDs, |
| 794 | "device-id": f.deviceHandler.device.Id}) |
| 795 | // Send Tconts and GEM ports to KV store |
| 796 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 797 | return allocID, gemPortIDs, techProfileInstance |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 798 | case *tp.EponProfile: |
| 799 | // CreateSchedulerQueues for EPON needs to be implemented here |
| 800 | // when voltha-protos for EPON is completed. |
| 801 | allocID := tpInst.AllocID |
| 802 | for _, gem := range tpInst.UpstreamQueueAttributeList { |
| 803 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 804 | } |
| 805 | allocIDs = appendUnique(allocIDs, allocID) |
| 806 | |
| 807 | if tpInstanceExists { |
| 808 | return allocID, gemPortIDs, techProfileInstance |
| 809 | } |
| 810 | |
| 811 | for _, gemPortID := range gemPortIDs { |
| 812 | allgemPortIDs = appendUnique(allgemPortIDs, gemPortID) |
| 813 | } |
| 814 | logger.Infow("allocated-tcont-and-gem-ports", |
| 815 | log.Fields{ |
| 816 | "alloc-ids": allocIDs, |
| 817 | "gemports": allgemPortIDs, |
| 818 | "device-id": f.deviceHandler.device.Id}) |
| 819 | // Send Tconts and GEM ports to KV store |
| 820 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
| 821 | return allocID, gemPortIDs, techProfileInstance |
| 822 | default: |
| 823 | logger.Errorw("unknown-tech", |
| 824 | log.Fields{ |
| 825 | "tpInst": tpInst}) |
| 826 | return 0, nil, nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 827 | } |
| 828 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 829 | } |
| 830 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 831 | 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] | 832 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 833 | logger.Debugw("storing-allocated-tconts-and-gem-ports-into-KV-store", |
| 834 | log.Fields{ |
| 835 | "intf-id": intfID, |
| 836 | "onu-id": onuID, |
| 837 | "uni-id": uniID, |
| 838 | "alloc-id": allocID, |
| 839 | "gemport-ids": gemPortIDs, |
| 840 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 841 | /* 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] | 842 | if err := f.resourceMgr.UpdateAllocIdsForOnu(ctx, intfID, onuID, uniID, allocID); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 843 | logger.Errorw("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] | 844 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 845 | if err := f.resourceMgr.UpdateGEMPortIDsForOnu(ctx, intfID, onuID, uniID, gemPortIDs); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 846 | logger.Errorw("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] | 847 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 848 | if err := f.resourceMgr.UpdateGEMportsPonportToOnuMapOnKVStore(ctx, gemPortIDs, intfID, onuID, uniID); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 849 | logger.Error("error-while-uploading-gemtopon-map-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 850 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 851 | logger.Infow("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] | 852 | for _, gemPort := range gemPortIDs { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 853 | f.addGemPortToOnuInfoMap(ctx, intfID, onuID, gemPort) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 854 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | func (f *OpenOltFlowMgr) populateTechProfilePerPonPort() error { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 858 | var tpCount int |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 859 | for _, techRange := range f.resourceMgr.DevInfo.Ranges { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 860 | for _, intfID := range techRange.IntfIds { |
| 861 | f.techprofile[intfID] = f.resourceMgr.ResourceMgrs[uint32(intfID)].TechProfileMgr |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 862 | tpCount++ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 863 | logger.Debugw("init-tech-profile-done", |
| 864 | log.Fields{ |
| 865 | "intf-id": intfID, |
| 866 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | //Make sure we have as many tech_profiles as there are pon ports on the device |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 870 | if tpCount != int(f.resourceMgr.DevInfo.GetPonPorts()) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 871 | return olterrors.NewErrInvalidValue(log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 872 | "reason": "tP-count-does-not-match-number-of-pon-ports", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 873 | "tech-profile-count": tpCount, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 874 | "pon-port-count": f.resourceMgr.DevInfo.GetPonPorts(), |
| 875 | "device-id": f.deviceHandler.device.Id}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 876 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 877 | logger.Infow("populated-techprofile-for-ponports-successfully", |
| 878 | log.Fields{ |
| 879 | "numofTech": tpCount, |
| 880 | "numPonPorts": f.resourceMgr.DevInfo.GetPonPorts(), |
| 881 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 882 | return nil |
| 883 | } |
| 884 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 885 | func (f *OpenOltFlowMgr) addUpstreamDataFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 886 | portNo uint32, uplinkClassifier map[string]interface{}, |
| 887 | uplinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 888 | allocID uint32, gemportID uint32, tpID uint32) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 889 | uplinkClassifier[PacketTagType] = SingleTag |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 890 | logger.Debugw("adding-upstream-data-flow", |
| 891 | log.Fields{ |
| 892 | "uplinkClassifier": uplinkClassifier, |
| 893 | "uplinkAction": uplinkAction}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 894 | return f.addHSIAFlow(ctx, intfID, onuID, uniID, portNo, uplinkClassifier, uplinkAction, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 895 | Upstream, logicalFlow, allocID, gemportID, tpID) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 896 | /* TODO: Install Secondary EAP on the subscriber vlan */ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 897 | } |
| 898 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 899 | func (f *OpenOltFlowMgr) addDownstreamDataFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 900 | portNo uint32, downlinkClassifier map[string]interface{}, |
| 901 | downlinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 902 | allocID uint32, gemportID uint32, tpID uint32) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 903 | downlinkClassifier[PacketTagType] = DoubleTag |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 904 | logger.Debugw("adding-downstream-data-flow", |
| 905 | log.Fields{ |
| 906 | "downlinkClassifier": downlinkClassifier, |
| 907 | "downlinkAction": downlinkAction}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 908 | // Ignore Downlink trap flow given by core, cannot do anything with this flow */ |
| 909 | if vlan, exists := downlinkClassifier[VlanVid]; exists { |
| 910 | 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] | 911 | if metadata, exists := downlinkClassifier[Metadata]; exists { // inport is filled in metadata by core |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 912 | if uint32(metadata.(uint64)) == MkUniPortNum(intfID, onuID, uniID) { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 913 | logger.Infow("ignoring-dl-trap-device-flow-from-core", |
| 914 | log.Fields{ |
| 915 | "flow": logicalFlow, |
| 916 | "device-id": f.deviceHandler.device.Id, |
| 917 | "onu-id": onuID, |
| 918 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 919 | return nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 920 | } |
| 921 | } |
| 922 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 923 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 924 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 925 | /* Already this info available classifier? */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 926 | downlinkAction[PopVlan] = true |
Matt Jeanneret | ed16b7c | 2019-11-01 13:31:35 -0400 | [diff] [blame] | 927 | // vlan_vid is a uint32. must be type asserted as such or conversion fails |
| 928 | dlClVid, ok := downlinkClassifier[VlanVid].(uint32) |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 929 | if ok { |
| 930 | downlinkAction[VlanVid] = dlClVid & 0xfff |
| 931 | } else { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 932 | return olterrors.NewErrInvalidValue(log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 933 | "reason": "failed-to-convert-vlanid-classifier", |
| 934 | "vlan-id": VlanVid, |
| 935 | "device-id": f.deviceHandler.device.Id}, nil).Log() |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 936 | } |
| 937 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 938 | return f.addHSIAFlow(ctx, intfID, onuID, uniID, portNo, downlinkClassifier, downlinkAction, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 939 | Downstream, logicalFlow, allocID, gemportID, tpID) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 940 | } |
| 941 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 942 | func (f *OpenOltFlowMgr) addHSIAFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{}, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 943 | action map[string]interface{}, direction string, logicalFlow *ofp.OfpFlowStats, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 944 | allocID uint32, gemPortID uint32, tpID uint32) error { |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 945 | /* One of the OLT platform (Broadcom BAL) requires that symmetric |
| 946 | flows require the same flow_id to be used across UL and DL. |
| 947 | Since HSIA flow is the only symmetric flow currently, we need to |
| 948 | re-use the flow_id across both direction. The 'flow_category' |
| 949 | takes priority over flow_cookie to find any available HSIA_FLOW |
| 950 | id for the ONU. |
| 951 | */ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 952 | logger.Infow("adding-hsia-flow", |
| 953 | log.Fields{ |
| 954 | "intf-id": intfID, |
| 955 | "onu-id": onuID, |
| 956 | "uni-id": uniID, |
| 957 | "device-id": f.deviceHandler.device.Id, |
| 958 | "classifier": classifier, |
| 959 | "action": action, |
| 960 | "direction": direction, |
| 961 | "alloc-id": allocID, |
| 962 | "gemport-id": gemPortID, |
| 963 | "logicalflow": *logicalFlow}) |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 964 | var vlanPbit uint32 = 0xff // means no pbit |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 965 | var vlanVid uint32 |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 966 | if _, ok := classifier[VlanPcp]; ok { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 967 | vlanPbit = classifier[VlanPcp].(uint32) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 968 | logger.Debugw("found-pbit-in-flow", |
| 969 | log.Fields{ |
| 970 | "vlan-pbit": vlanPbit, |
| 971 | "intf-id": intfID, |
| 972 | "onu-id": onuID, |
| 973 | "device-id": f.deviceHandler.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 974 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 975 | logger.Debugw("pbit-not-found-in-flow", |
| 976 | log.Fields{ |
| 977 | "vlan-pcp": VlanPcp, |
| 978 | "intf-id": intfID, |
| 979 | "onu-id": onuID, |
| 980 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 981 | } |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 982 | if _, ok := classifier[VlanVid]; ok { |
| 983 | vlanVid = classifier[VlanVid].(uint32) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 984 | log.Debugw("found-vlan-in-the-flow", |
| 985 | log.Fields{ |
| 986 | "vlan-vid": vlanVid, |
| 987 | "intf-id": intfID, |
| 988 | "onu-id": onuID, |
| 989 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 990 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 991 | flowStoreCookie := getFlowStoreCookie(classifier, gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 992 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 993 | logger.Infow("flow-already-exists", |
| 994 | log.Fields{ |
| 995 | "device-id": f.deviceHandler.device.Id, |
| 996 | "intf-id": intfID, |
| 997 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 998 | return nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 999 | } |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1000 | flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, HsiaFlow, vlanVid, vlanPbit) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1001 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1002 | return olterrors.NewErrNotFound("hsia-flow-id", |
| 1003 | log.Fields{ |
| 1004 | "direction": direction, |
| 1005 | "device-id": f.deviceHandler.device.Id, |
| 1006 | "intf-id": intfID, |
| 1007 | "onu-id": onuID, |
| 1008 | }, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1009 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1010 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1011 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1012 | 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] | 1013 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1014 | logger.Debugw("created-classifier-proto", |
| 1015 | log.Fields{ |
| 1016 | "classifier": *classifierProto, |
| 1017 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1018 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1019 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1020 | 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] | 1021 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1022 | logger.Debugw("created-action-proto", |
| 1023 | log.Fields{ |
| 1024 | "action": *actionProto, |
| 1025 | "device-id": f.deviceHandler.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1026 | networkIntfID, err := getNniIntfID(classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1027 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1028 | return olterrors.NewErrNotFound("nni-interface-id", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1029 | log.Fields{ |
| 1030 | "classifier": classifier, |
| 1031 | "action": action, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1032 | "device-id": f.deviceHandler.device.Id, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1033 | }, err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1034 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1035 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
| 1036 | OnuId: int32(onuID), |
| 1037 | UniId: int32(uniID), |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1038 | FlowId: flowID, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1039 | FlowType: direction, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1040 | AllocId: int32(allocID), |
| 1041 | NetworkIntfId: int32(networkIntfID), |
| 1042 | GemportId: int32(gemPortID), |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1043 | Classifier: classifierProto, |
| 1044 | Action: actionProto, |
| 1045 | Priority: int32(logicalFlow.Priority), |
| 1046 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1047 | PortNo: portNo, |
| 1048 | TechProfileId: tpID, |
| 1049 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1050 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1051 | return olterrors.NewErrFlowOp("add", flowID, nil, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1052 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1053 | logger.Infow("hsia-flow-added-to-device-successfully", |
| 1054 | log.Fields{"direction": direction, |
| 1055 | "device-id": f.deviceHandler.device.Id, |
| 1056 | "flow": flow, |
| 1057 | "intf-id": intfID, |
| 1058 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1059 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &flow, flowStoreCookie, HsiaFlow, flowID, logicalFlow.Id) |
| 1060 | if err := f.updateFlowInfoToKVStore(ctx, flow.AccessIntfId, |
| 1061 | flow.OnuId, |
| 1062 | flow.UniId, |
| 1063 | flow.FlowId /*flowCategory,*/, flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1064 | return olterrors.NewErrPersistence("update", "flow", flowID, |
| 1065 | log.Fields{ |
| 1066 | "flow": flow, |
| 1067 | "device-id": f.deviceHandler.device.Id, |
| 1068 | "intf-id": intfID, |
| 1069 | "onu-id": onuID}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1070 | } |
| 1071 | return nil |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1072 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1073 | |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1074 | func (f *OpenOltFlowMgr) addDHCPTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
| 1075 | classifier map[string]interface{}, action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, |
| 1076 | gemPortID uint32, tpID uint32) error { |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1077 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1078 | networkIntfID, err := getNniIntfID(classifier, action) |
| 1079 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1080 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1081 | "classifier": classifier, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1082 | "action": action, |
| 1083 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1084 | err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1085 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1086 | |
| 1087 | // Clear the action map |
| 1088 | for k := range action { |
| 1089 | delete(action, k) |
| 1090 | } |
| 1091 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1092 | action[TrapToHost] = true |
| 1093 | classifier[UDPSrc] = uint32(68) |
| 1094 | classifier[UDPDst] = uint32(67) |
| 1095 | classifier[PacketTagType] = SingleTag |
| 1096 | delete(classifier, VlanVid) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1097 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1098 | flowStoreCookie := getFlowStoreCookie(classifier, gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1099 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1100 | logger.Infow("flow-exists--not-re-adding", |
| 1101 | log.Fields{ |
| 1102 | "device-id": f.deviceHandler.device.Id, |
| 1103 | "intf-id": intfID, |
| 1104 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1105 | return nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1106 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1107 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1108 | flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, DhcpFlow, 0 /*classifier[VLAN_PCP].(uint32)*/) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1109 | |
| 1110 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1111 | return olterrors.NewErrNotFound("flow", |
| 1112 | log.Fields{ |
| 1113 | "interface-id": intfID, |
| 1114 | "gem-port": gemPortID, |
| 1115 | "cookie": flowStoreCookie, |
| 1116 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1117 | err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1118 | } |
| 1119 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1120 | logger.Debugw("creating-ul-dhcp-flow", |
| 1121 | log.Fields{ |
| 1122 | "ul_classifier": classifier, |
| 1123 | "ul_action": action, |
| 1124 | "uplinkFlowId": flowID, |
| 1125 | "intf-id": intfID, |
| 1126 | "onu-id": onuID, |
| 1127 | "device-id": f.deviceHandler.device.Id}) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1128 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1129 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1130 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1131 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1132 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1133 | logger.Debugw("created-classifier-proto", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1134 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1135 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1136 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1137 | } |
| 1138 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1139 | dhcpFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1140 | OnuId: int32(onuID), |
| 1141 | UniId: int32(uniID), |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1142 | FlowId: flowID, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1143 | FlowType: Upstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1144 | AllocId: int32(allocID), |
| 1145 | NetworkIntfId: int32(networkIntfID), |
| 1146 | GemportId: int32(gemPortID), |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1147 | Classifier: classifierProto, |
| 1148 | Action: actionProto, |
| 1149 | Priority: int32(logicalFlow.Priority), |
| 1150 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1151 | PortNo: portNo, |
| 1152 | TechProfileId: tpID, |
| 1153 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1154 | if err := f.addFlowToDevice(ctx, logicalFlow, &dhcpFlow); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1155 | return olterrors.NewErrFlowOp("add", flowID, log.Fields{"dhcp-flow": dhcpFlow}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1156 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1157 | logger.Infow("dhcp-ul-flow-added-to-device-successfully", |
| 1158 | log.Fields{ |
| 1159 | "device-id": f.deviceHandler.device.Id, |
| 1160 | "flow-id": flowID, |
| 1161 | "intf-id": intfID, |
| 1162 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1163 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &dhcpFlow, flowStoreCookie, "DHCP", flowID, logicalFlow.Id) |
| 1164 | if err := f.updateFlowInfoToKVStore(ctx, dhcpFlow.AccessIntfId, |
| 1165 | dhcpFlow.OnuId, |
| 1166 | dhcpFlow.UniId, |
| 1167 | dhcpFlow.FlowId, flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1168 | return olterrors.NewErrPersistence("update", "flow", dhcpFlow.FlowId, |
| 1169 | log.Fields{ |
| 1170 | "flow": dhcpFlow, |
| 1171 | "device-id": f.deviceHandler.device.Id}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1172 | } |
| 1173 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1174 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1175 | } |
| 1176 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1177 | //addIGMPTrapFlow creates IGMP trap-to-host flow |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1178 | func (f *OpenOltFlowMgr) addIGMPTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{}, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1179 | action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, gemPortID uint32, tpID uint32) error { |
| 1180 | return f.addUpstreamTrapFlow(ctx, intfID, onuID, uniID, portNo, classifier, action, logicalFlow, allocID, gemPortID, IgmpFlow, tpID) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | //addUpstreamTrapFlow creates a trap-to-host flow |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1184 | func (f *OpenOltFlowMgr) addUpstreamTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{}, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1185 | action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, gemPortID uint32, flowType string, tpID uint32) error { |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1186 | |
| 1187 | networkIntfID, err := getNniIntfID(classifier, action) |
| 1188 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1189 | return olterrors.NewErrNotFound("nni-interface-id", |
| 1190 | log.Fields{ |
| 1191 | "classifier": classifier, |
| 1192 | "action": action, |
| 1193 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1194 | err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | // Clear the action map |
| 1198 | for k := range action { |
| 1199 | delete(action, k) |
| 1200 | } |
| 1201 | |
| 1202 | action[TrapToHost] = true |
| 1203 | classifier[PacketTagType] = SingleTag |
| 1204 | delete(classifier, VlanVid) |
| 1205 | |
| 1206 | flowStoreCookie := getFlowStoreCookie(classifier, gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1207 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkIntfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1208 | logger.Infow("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] | 1209 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1212 | flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, flowType, 0, 0 /*classifier[VLAN_PCP].(uint32)*/) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1213 | |
| 1214 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1215 | return olterrors.NewErrNotFound("flow-id", |
| 1216 | log.Fields{ |
| 1217 | "intf-id": intfID, |
| 1218 | "oni-id": onuID, |
| 1219 | "cookie": flowStoreCookie, |
| 1220 | "flow-type": flowType, |
| 1221 | "device-id": f.deviceHandler.device.Id, |
| 1222 | "onu-id": onuID}, |
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 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1226 | logger.Debugw("creating-upstream-trap-flow", |
| 1227 | log.Fields{ |
| 1228 | "ul_classifier": classifier, |
| 1229 | "ul_action": action, |
| 1230 | "uplinkFlowId": flowID, |
| 1231 | "flowType": flowType, |
| 1232 | "device-id": f.deviceHandler.device.Id, |
| 1233 | "intf-id": intfID, |
| 1234 | "onu-id": onuID}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1235 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1236 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1237 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1238 | 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] | 1239 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1240 | logger.Debugw("created-classifier-proto", |
| 1241 | log.Fields{ |
| 1242 | "classifier": *classifierProto, |
| 1243 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1244 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1245 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1246 | 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] | 1247 | } |
| 1248 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1249 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1250 | OnuId: int32(onuID), |
| 1251 | UniId: int32(uniID), |
| 1252 | FlowId: flowID, |
| 1253 | FlowType: Upstream, |
| 1254 | AllocId: int32(allocID), |
| 1255 | NetworkIntfId: int32(networkIntfID), |
| 1256 | GemportId: int32(gemPortID), |
| 1257 | Classifier: classifierProto, |
| 1258 | Action: actionProto, |
| 1259 | Priority: int32(logicalFlow.Priority), |
| 1260 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1261 | PortNo: portNo, |
| 1262 | TechProfileId: tpID, |
| 1263 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1264 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1265 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1266 | return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": flow, "device-id": f.deviceHandler.device.Id}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1267 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1268 | logger.Infof("%s ul-flow-added-to-device-successfully", flowType) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1269 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1270 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &flow, flowStoreCookie, flowType, flowID, logicalFlow.Id) |
| 1271 | if err := f.updateFlowInfoToKVStore(ctx, flow.AccessIntfId, |
| 1272 | flow.OnuId, |
| 1273 | flow.UniId, |
| 1274 | flow.FlowId, flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1275 | return olterrors.NewErrPersistence("update", "flow", flow.FlowId, log.Fields{"flow": flow, "device-id": f.deviceHandler.device.Id}, err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1278 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1281 | // Add EAPOL flow to device with mac, vlanId as classifier for upstream and downstream |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1282 | func (f *OpenOltFlowMgr) addEAPOLFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
| 1283 | classifier map[string]interface{}, action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, |
| 1284 | gemPortID uint32, vlanID uint32, tpID uint32) error { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1285 | logger.Infow("adding-eapol-to-device", |
| 1286 | log.Fields{ |
| 1287 | "intf-id": intfID, |
| 1288 | "onu-id": onuID, |
| 1289 | "port-no": portNo, |
| 1290 | "alloc-id": allocID, |
| 1291 | "gemport-id": gemPortID, |
| 1292 | "vlan-id": vlanID, |
| 1293 | "flow": logicalFlow}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1294 | |
| 1295 | uplinkClassifier := make(map[string]interface{}) |
| 1296 | uplinkAction := make(map[string]interface{}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1297 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1298 | // Fill Classfier |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1299 | uplinkClassifier[EthType] = uint32(EapEthType) |
| 1300 | uplinkClassifier[PacketTagType] = SingleTag |
| 1301 | uplinkClassifier[VlanVid] = vlanID |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1302 | uplinkClassifier[VlanPcp] = classifier[VlanPcp] |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1303 | // Fill action |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1304 | uplinkAction[TrapToHost] = true |
| 1305 | flowStoreCookie := getFlowStoreCookie(uplinkClassifier, gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1306 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1307 | logger.Infow("flow-exists-not-re-adding", log.Fields{ |
| 1308 | "device-id": f.deviceHandler.device.Id, |
| 1309 | "onu-id": onuID, |
| 1310 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1311 | return nil |
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 | //Add Uplink EAPOL Flow |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1314 | uplinkFlowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, "", 0, 0) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1315 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1316 | return olterrors.NewErrNotFound("flow-id", |
| 1317 | log.Fields{ |
| 1318 | "intf-id": intfID, |
| 1319 | "onu-id": onuID, |
| 1320 | "coookie": flowStoreCookie, |
| 1321 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1322 | err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1323 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1324 | logger.Debugw("creating-ul-eapol-flow", |
| 1325 | log.Fields{ |
| 1326 | "ul_classifier": uplinkClassifier, |
| 1327 | "ul_action": uplinkAction, |
| 1328 | "uplinkFlowId": uplinkFlowID, |
| 1329 | "device-id": f.deviceHandler.device.Id, |
| 1330 | "intf-id": intfID, |
| 1331 | "onu-id": onuID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1332 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1333 | classifierProto, err := makeOpenOltClassifierField(uplinkClassifier) |
| 1334 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1335 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 1336 | "classifier": uplinkClassifier, |
| 1337 | "device-id": f.deviceHandler.device.Id}, err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1338 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1339 | logger.Debugw("created-classifier-proto", |
| 1340 | log.Fields{ |
| 1341 | "classifier": *classifierProto, |
| 1342 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1343 | actionProto, err := makeOpenOltActionField(uplinkAction, uplinkClassifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1344 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1345 | 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] | 1346 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1347 | logger.Debugw("created-action-proto", |
| 1348 | log.Fields{ |
| 1349 | "action": *actionProto, |
| 1350 | "device-id": f.deviceHandler.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1351 | networkIntfID, err := getNniIntfID(classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1352 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1353 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1354 | "classifier": classifier, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1355 | "action": action, |
| 1356 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1357 | err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1358 | } |
| 1359 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1360 | upstreamFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1361 | OnuId: int32(onuID), |
| 1362 | UniId: int32(uniID), |
| 1363 | FlowId: uplinkFlowID, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1364 | FlowType: Upstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1365 | AllocId: int32(allocID), |
| 1366 | NetworkIntfId: int32(networkIntfID), |
| 1367 | GemportId: int32(gemPortID), |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1368 | Classifier: classifierProto, |
| 1369 | Action: actionProto, |
| 1370 | Priority: int32(logicalFlow.Priority), |
| 1371 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1372 | PortNo: portNo, |
| 1373 | TechProfileId: tpID, |
| 1374 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1375 | if err := f.addFlowToDevice(ctx, logicalFlow, &upstreamFlow); err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1376 | return olterrors.NewErrFlowOp("add", uplinkFlowID, log.Fields{"flow": upstreamFlow}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1377 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1378 | logger.Infow("eapol-ul-flow-added-to-device-successfully", |
| 1379 | log.Fields{ |
| 1380 | "device-id": f.deviceHandler.device.Id, |
| 1381 | "onu-id": onuID, |
| 1382 | "intf-id": intfID, |
| 1383 | }) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1384 | flowCategory := "EAPOL" |
| 1385 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &upstreamFlow, flowStoreCookie, flowCategory, uplinkFlowID, logicalFlow.Id) |
| 1386 | if err := f.updateFlowInfoToKVStore(ctx, upstreamFlow.AccessIntfId, |
| 1387 | upstreamFlow.OnuId, |
| 1388 | upstreamFlow.UniId, |
| 1389 | upstreamFlow.FlowId, |
| 1390 | /* lowCategory, */ |
| 1391 | flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1392 | return olterrors.NewErrPersistence("update", "flow", upstreamFlow.FlowId, |
| 1393 | log.Fields{ |
| 1394 | "flow": upstreamFlow, |
| 1395 | "device-id": f.deviceHandler.device.Id}, err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1396 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1397 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1398 | } |
| 1399 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1400 | func makeOpenOltClassifierField(classifierInfo map[string]interface{}) (*openoltpb2.Classifier, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1401 | var classifier openoltpb2.Classifier |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1402 | |
| 1403 | classifier.EthType, _ = classifierInfo[EthType].(uint32) |
| 1404 | classifier.IpProto, _ = classifierInfo[IPProto].(uint32) |
| 1405 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 1406 | if vlanID != ReservedVlan { |
| 1407 | vid := vlanID & VlanvIDMask |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1408 | classifier.OVid = vid |
| 1409 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1410 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1411 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 1412 | vid := uint32(metadata) |
| 1413 | if vid != ReservedVlan { |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1414 | classifier.IVid = vid |
| 1415 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1416 | } |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1417 | // 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] | 1418 | if vlanPcp, ok := classifierInfo[VlanPcp].(uint32); ok { |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1419 | classifier.OPbits = vlanPcp |
| 1420 | } else { |
| 1421 | classifier.OPbits = VlanPCPMask |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1422 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1423 | classifier.SrcPort, _ = classifierInfo[UDPSrc].(uint32) |
| 1424 | classifier.DstPort, _ = classifierInfo[UDPDst].(uint32) |
| 1425 | classifier.DstIp, _ = classifierInfo[Ipv4Dst].(uint32) |
| 1426 | classifier.SrcIp, _ = classifierInfo[Ipv4Src].(uint32) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1427 | classifier.DstMac, _ = classifierInfo[EthDst].([]uint8) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1428 | if pktTagType, ok := classifierInfo[PacketTagType].(string); ok { |
| 1429 | classifier.PktTagType = pktTagType |
| 1430 | |
| 1431 | switch pktTagType { |
| 1432 | case SingleTag: |
| 1433 | case DoubleTag: |
| 1434 | case Untagged: |
| 1435 | default: |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1436 | return nil, olterrors.NewErrInvalidValue(log.Fields{"packet-tag-type": pktTagType}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1437 | } |
| 1438 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1439 | return &classifier, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1440 | } |
| 1441 | |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1442 | 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] | 1443 | var actionCmd openoltpb2.ActionCmd |
| 1444 | var action openoltpb2.Action |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1445 | action.Cmd = &actionCmd |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1446 | if _, ok := actionInfo[PopVlan]; ok { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1447 | action.Cmd.RemoveOuterTag = true |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1448 | if _, ok := actionInfo[VlanPcp]; ok { |
| 1449 | action.Cmd.RemarkInnerPbits = true |
| 1450 | action.IPbits = actionInfo[VlanPcp].(uint32) |
| 1451 | if _, ok := actionInfo[VlanVid]; ok { |
| 1452 | action.Cmd.TranslateInnerTag = true |
| 1453 | action.IVid = actionInfo[VlanVid].(uint32) |
| 1454 | } |
| 1455 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1456 | } else if _, ok := actionInfo[PushVlan]; ok { |
| 1457 | action.OVid = actionInfo[VlanVid].(uint32) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1458 | action.Cmd.AddOuterTag = true |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1459 | if _, ok := actionInfo[VlanPcp]; ok { |
| 1460 | action.OPbits = actionInfo[VlanPcp].(uint32) |
| 1461 | action.Cmd.RemarkOuterPbits = true |
| 1462 | if _, ok := classifierInfo[VlanVid]; ok { |
| 1463 | action.IVid = classifierInfo[VlanVid].(uint32) |
| 1464 | action.Cmd.TranslateInnerTag = true |
| 1465 | } |
| 1466 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1467 | } else if _, ok := actionInfo[TrapToHost]; ok { |
| 1468 | action.Cmd.TrapToHost = actionInfo[TrapToHost].(bool) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1469 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1470 | return nil, olterrors.NewErrInvalidValue(log.Fields{"action-command": actionInfo}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1471 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1472 | return &action, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1473 | } |
| 1474 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1475 | // getTPpath return the ETCD path for a given UNI port |
| 1476 | func (f *OpenOltFlowMgr) getTPpath(intfID uint32, uniPath string, TpID uint32) string { |
| 1477 | return f.techprofile[intfID].GetTechProfileInstanceKVPath(TpID, uniPath) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1478 | } |
| 1479 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1480 | // DeleteTechProfileInstances removes the tech profile instances from persistent storage |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1481 | func (f *OpenOltFlowMgr) DeleteTechProfileInstances(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, sn string) error { |
| 1482 | tpIDList := f.resourceMgr.GetTechProfileIDForOnu(ctx, intfID, onuID, uniID) |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1483 | uniPortName := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| 1484 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1485 | for _, tpID := range tpIDList { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1486 | if err := f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1487 | olterrors.NewErrAdapter("delete-tech-profile-failed", log.Fields{"device-id": f.deviceHandler.device.Id}, err).Log() |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1488 | // return err |
| 1489 | // We should continue to delete tech-profile instances for other TP IDs |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1490 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1491 | log.Debugw("tech-profile-deleted", log.Fields{"device-id": f.deviceHandler.device.Id, "tp-id": tpID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1492 | } |
| 1493 | return nil |
| 1494 | } |
| 1495 | |
| 1496 | // DeleteTechProfileInstance removes the tech profile instance from persistent storage |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1497 | 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] | 1498 | if uniPortName == "" { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1499 | uniPortName = getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1500 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1501 | if err := f.techprofile[intfID].DeleteTechProfileInstance(ctx, tpID, uniPortName); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1502 | return olterrors.NewErrAdapter("failed-to-delete-tp-instance-from-kv-store", |
| 1503 | log.Fields{ |
| 1504 | "tp-id": tpID, |
| 1505 | "uni-port-name": uniPortName, |
| 1506 | "device-id": f.deviceHandler.device.Id}, err) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1507 | } |
| 1508 | return nil |
| 1509 | } |
| 1510 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1511 | func getFlowStoreCookie(classifier map[string]interface{}, gemPortID uint32) uint64 { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1512 | if len(classifier) == 0 { // should never happen |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1513 | logger.Error("invalid-classfier-object") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1514 | return 0 |
| 1515 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1516 | logger.Debugw("generating-flow-store-cookie", |
| 1517 | log.Fields{ |
| 1518 | "classifier": classifier, |
| 1519 | "gemport-id": gemPortID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1520 | var jsonData []byte |
| 1521 | var flowString string |
| 1522 | var err error |
| 1523 | // TODO: Do we need to marshall ?? |
| 1524 | if jsonData, err = json.Marshal(classifier); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1525 | logger.Error("failed-to-encode-classifier") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1526 | return 0 |
| 1527 | } |
| 1528 | flowString = string(jsonData) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1529 | if gemPortID != 0 { |
| 1530 | flowString = fmt.Sprintf("%s%s", string(jsonData), string(gemPortID)) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1531 | } |
| 1532 | h := md5.New() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1533 | _, _ = h.Write([]byte(flowString)) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1534 | hash := big.NewInt(0) |
| 1535 | hash.SetBytes(h.Sum(nil)) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1536 | generatedHash := hash.Uint64() |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1537 | logger.Debugw("hash-generated", log.Fields{"hash": generatedHash}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1538 | return generatedHash |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1539 | } |
| 1540 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1541 | func (f *OpenOltFlowMgr) getUpdatedFlowInfo(ctx context.Context, flow *openoltpb2.Flow, flowStoreCookie uint64, flowCategory string, deviceFlowID uint32, logicalFlowID uint64) *[]rsrcMgr.FlowInfo { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1542 | var flows = []rsrcMgr.FlowInfo{{Flow: flow, FlowCategory: flowCategory, FlowStoreCookie: flowStoreCookie, LogicalFlowID: logicalFlowID}} |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1543 | var intfID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1544 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1545 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1546 | */ |
| 1547 | if flow.AccessIntfId != -1 { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1548 | intfID = uint32(flow.AccessIntfId) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1549 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1550 | intfID = uint32(flow.NetworkIntfId) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1551 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1552 | // Get existing flows matching flowid for given subscriber from KV store |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1553 | existingFlows := f.resourceMgr.GetFlowIDInfo(ctx, intfID, flow.OnuId, flow.UniId, flow.FlowId) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1554 | if existingFlows != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1555 | logger.Debugw("flow-exists-for-given-flowID--appending-it-to-current-flow", |
| 1556 | log.Fields{ |
| 1557 | "flow-id": flow.FlowId, |
| 1558 | "device-id": f.deviceHandler.device.Id, |
| 1559 | "intf-id": intfID, |
| 1560 | "onu-id": flow.OnuId}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1561 | //for _, f := range *existingFlows { |
| 1562 | // flows = append(flows, f) |
| 1563 | //} |
| 1564 | flows = append(flows, *existingFlows...) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1565 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1566 | logger.Debugw("updated-flows-for-given-flowID-and-onuid", |
| 1567 | log.Fields{ |
| 1568 | "updatedflow": flows, |
| 1569 | "flow-id": flow.FlowId, |
| 1570 | "onu-id": flow.OnuId, |
| 1571 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1572 | return &flows |
| 1573 | } |
| 1574 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1575 | func (f *OpenOltFlowMgr) updateFlowInfoToKVStore(ctx context.Context, intfID int32, onuID int32, uniID int32, flowID uint32, flows *[]rsrcMgr.FlowInfo) error { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1576 | logger.Debugw("storing-flow(s)-into-kv-store", log.Fields{ |
| 1577 | "flow-id": flowID, |
| 1578 | "device-id": f.deviceHandler.device.Id, |
| 1579 | "intf-id": intfID, |
| 1580 | "onu-id": onuID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1581 | if err := f.resourceMgr.UpdateFlowIDInfo(ctx, intfID, onuID, uniID, flowID, flows); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1582 | logger.Warnw("error-while-storing-flow-into-kv-store", log.Fields{ |
| 1583 | "device-id": f.deviceHandler.device.Id, |
| 1584 | "onu-id": onuID, |
| 1585 | "intf-id": intfID, |
| 1586 | "flow-id": flowID}) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1587 | return err |
| 1588 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1589 | logger.Infow("stored-flow(s)-into-kv-store-successfully!", log.Fields{ |
| 1590 | "device-id": f.deviceHandler.device.Id, |
| 1591 | "onu-id": onuID, |
| 1592 | "intf-id": intfID, |
| 1593 | "flow-id": flowID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1594 | return nil |
| 1595 | } |
| 1596 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1597 | 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] | 1598 | |
| 1599 | var intfID uint32 |
| 1600 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1601 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1602 | */ |
| 1603 | if deviceFlow.AccessIntfId != -1 { |
| 1604 | intfID = uint32(deviceFlow.AccessIntfId) |
| 1605 | } else { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1606 | // REVIST : Why ponport is given as network port? |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1607 | intfID = uint32(deviceFlow.NetworkIntfId) |
| 1608 | } |
| 1609 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1610 | logger.Debugw("sending-flow-to-device-via-grpc", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1611 | "flow": *deviceFlow, |
| 1612 | "device-id": f.deviceHandler.device.Id, |
| 1613 | "intf-id": intfID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1614 | _, err := f.deviceHandler.Client.FlowAdd(context.Background(), deviceFlow) |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1615 | |
| 1616 | st, _ := status.FromError(err) |
| 1617 | if st.Code() == codes.AlreadyExists { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1618 | logger.Debug("flow-already-exists", log.Fields{ |
| 1619 | "err": err, |
| 1620 | "deviceFlow": deviceFlow, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1621 | "device-id": f.deviceHandler.device.Id, |
| 1622 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1623 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1624 | } |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1625 | |
| 1626 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1627 | logger.Errorw("failed-to-add-flow-to-device", |
| 1628 | log.Fields{"err": err, |
| 1629 | "device-flow": deviceFlow, |
| 1630 | "device-id": f.deviceHandler.device.Id, |
| 1631 | "intf-id": intfID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1632 | f.resourceMgr.FreeFlowID(ctx, intfID, deviceFlow.OnuId, deviceFlow.UniId, deviceFlow.FlowId) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1633 | return err |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1634 | } |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1635 | if deviceFlow.GemportId != -1 { |
| 1636 | // No need to register the flow if it is a trap on nni flow. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1637 | f.registerFlow(ctx, logicalFlow, deviceFlow) |
Abhilash Laxmeshwar | 6d1acb9 | 2020-01-17 15:43:03 +0530 | [diff] [blame] | 1638 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1639 | logger.Infow("flow-added-to-device-successfully ", |
| 1640 | log.Fields{ |
| 1641 | "flow": *deviceFlow, |
| 1642 | "device-id": f.deviceHandler.device.Id, |
| 1643 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1644 | return nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1645 | } |
| 1646 | |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1647 | func (f *OpenOltFlowMgr) removeFlowFromDevice(deviceFlow *openoltpb2.Flow, ofFlowID uint64) error { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1648 | logger.Debugw("sending-flow-to-device-via-grpc", |
| 1649 | log.Fields{ |
| 1650 | "flow": *deviceFlow, |
| 1651 | "device-id": f.deviceHandler.device.Id}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1652 | _, err := f.deviceHandler.Client.FlowRemove(context.Background(), deviceFlow) |
| 1653 | if err != nil { |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1654 | if f.deviceHandler.device.ConnectStatus == common.ConnectStatus_UNREACHABLE { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1655 | logger.Warnw("can-not-remove-flow-from-device--unreachable", |
| 1656 | log.Fields{ |
| 1657 | "err": err, |
| 1658 | "deviceFlow": deviceFlow, |
| 1659 | "device-id": f.deviceHandler.device.Id}) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1660 | //Assume the flow is removed |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1661 | return nil |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1662 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1663 | return olterrors.NewErrFlowOp("remove", deviceFlow.FlowId, log.Fields{"deviceFlow": deviceFlow}, err) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1664 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1665 | } |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1666 | logger.Infow("flow-removed-from-device-successfully", log.Fields{ |
| 1667 | "of-flow-id": ofFlowID, |
| 1668 | "flow": *deviceFlow, |
| 1669 | "device-id": f.deviceHandler.device.Id, |
| 1670 | }) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1671 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1672 | } |
| 1673 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1674 | 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] | 1675 | |
| 1676 | classifierInfo := make(map[string]interface{}) |
| 1677 | actionInfo := make(map[string]interface{}) |
| 1678 | |
| 1679 | classifierInfo[EthType] = uint32(LldpEthType) |
| 1680 | classifierInfo[PacketTagType] = Untagged |
| 1681 | actionInfo[TrapToHost] = true |
| 1682 | |
| 1683 | // LLDP flow is installed to trap LLDP packets on the NNI port. |
| 1684 | // We manage flow_id resource pool on per PON port basis. |
| 1685 | // Since this situation is tricky, as a hack, we pass the NNI port |
| 1686 | // index (network_intf_id) as PON port Index for the flow_id resource |
| 1687 | // pool. Also, there is no ONU Id available for trapping LLDP packets |
| 1688 | // on NNI port, use onu_id as -1 (invalid) |
| 1689 | // ****************** CAVEAT ******************* |
| 1690 | // This logic works if the NNI Port Id falls within the same valid |
| 1691 | // range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1692 | // we need to have a re-look at this. |
| 1693 | // ********************************************* |
| 1694 | |
| 1695 | var onuID = -1 |
| 1696 | var uniID = -1 |
| 1697 | var gemPortID = -1 |
| 1698 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1699 | networkInterfaceID, err := IntfIDFromNniPortNum(portNo) |
| 1700 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1701 | return olterrors.NewErrInvalidValue(log.Fields{"nni-port-number": portNo}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1702 | } |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1703 | var flowStoreCookie = getFlowStoreCookie(classifierInfo, uint32(0)) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1704 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1705 | logger.Infow("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] | 1706 | return nil |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1707 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1708 | flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1709 | |
| 1710 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1711 | return olterrors.NewErrNotFound("flow-id", |
| 1712 | log.Fields{ |
| 1713 | "interface-id": networkInterfaceID, |
| 1714 | "onu-id": onuID, |
| 1715 | "uni-id": uniID, |
| 1716 | "gem-port-id": gemPortID, |
| 1717 | "cookie": flowStoreCookie, |
| 1718 | "device-id": f.deviceHandler.device.Id}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1719 | err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1720 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1721 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 1722 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1723 | return olterrors.NewErrInvalidValue( |
| 1724 | log.Fields{ |
| 1725 | "classifier": classifierInfo, |
| 1726 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1727 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1728 | logger.Debugw("created-classifier-proto", |
| 1729 | log.Fields{ |
| 1730 | "classifier": *classifierProto, |
| 1731 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1732 | actionProto, err := makeOpenOltActionField(actionInfo, classifierInfo) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1733 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1734 | return olterrors.NewErrInvalidValue( |
| 1735 | log.Fields{ |
| 1736 | "action": actionInfo, |
| 1737 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1738 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1739 | logger.Debugw("created-action-proto", |
| 1740 | log.Fields{ |
| 1741 | "action": *actionProto, |
| 1742 | "device-id": f.deviceHandler.device.Id}) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1743 | |
| 1744 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 1745 | OnuId: int32(onuID), // OnuId not required |
| 1746 | UniId: int32(uniID), // UniId not used |
| 1747 | FlowId: flowID, |
| 1748 | FlowType: Downstream, |
| 1749 | NetworkIntfId: int32(networkInterfaceID), |
| 1750 | GemportId: int32(gemPortID), |
| 1751 | Classifier: classifierProto, |
| 1752 | Action: actionProto, |
| 1753 | Priority: int32(flow.Priority), |
| 1754 | Cookie: flow.Cookie, |
| 1755 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1756 | if err := f.addFlowToDevice(ctx, flow, &downstreamflow); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1757 | return olterrors.NewErrFlowOp("add", flowID, |
| 1758 | log.Fields{ |
| 1759 | "flow": downstreamflow, |
| 1760 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1761 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1762 | logger.Infow("lldp-trap-on-nni-flow-added-to-device-successfully", |
| 1763 | log.Fields{ |
| 1764 | "device-id": f.deviceHandler.device.Id, |
| 1765 | "onu-id": onuID, |
| 1766 | "flow-id": flowID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1767 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &downstreamflow, flowStoreCookie, "", flowID, flow.Id) |
| 1768 | if err := f.updateFlowInfoToKVStore(ctx, int32(networkInterfaceID), |
| 1769 | int32(onuID), |
| 1770 | int32(uniID), |
| 1771 | flowID, flowsToKVStore); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1772 | return olterrors.NewErrPersistence("update", "flow", flowID, |
| 1773 | log.Fields{ |
| 1774 | "flow": downstreamflow, |
| 1775 | "device-id": f.deviceHandler.device.Id}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1776 | } |
| 1777 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1778 | } |
| 1779 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1780 | func getUniPortPath(oltID string, intfID uint32, onuID int32, uniID int32) string { |
| 1781 | 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] | 1782 | } |
| 1783 | |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1784 | //getOnuDevice to fetch onu from cache or core. |
| 1785 | func (f *OpenOltFlowMgr) getOnuDevice(intfID uint32, onuID uint32) (*OnuDevice, error) { |
| 1786 | onuKey := f.deviceHandler.formOnuKey(intfID, onuID) |
| 1787 | onuDev, ok := f.deviceHandler.onus.Load(onuKey) |
| 1788 | if !ok { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1789 | logger.Debugw("couldnt-find-onu-in-cache", |
| 1790 | log.Fields{ |
| 1791 | "intf-id": intfID, |
| 1792 | "onu-id": onuID, |
| 1793 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1794 | onuDevice, err := f.getChildDevice(intfID, onuID) |
| 1795 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1796 | return nil, olterrors.NewErrNotFound("onu-child-device", |
| 1797 | log.Fields{ |
| 1798 | "onu-id": onuID, |
| 1799 | "intf-id": intfID, |
| 1800 | "device-id": f.deviceHandler.device.Id}, err) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1801 | } |
| 1802 | onuDev = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuDevice.ProxyAddress.OnuId, onuDevice.ProxyAddress.ChannelId, onuDevice.ProxyAddress.DeviceId, false) |
| 1803 | //better to ad the device to cache here. |
| 1804 | f.deviceHandler.StoreOnuDevice(onuDev.(*OnuDevice)) |
| 1805 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1806 | logger.Debugw("found-onu-in-cache", |
| 1807 | log.Fields{ |
| 1808 | "intf-id": intfID, |
| 1809 | "onu-id": onuID, |
| 1810 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | return onuDev.(*OnuDevice), nil |
| 1814 | } |
| 1815 | |
| 1816 | //getChildDevice to fetch onu |
| 1817 | func (f *OpenOltFlowMgr) getChildDevice(intfID uint32, onuID uint32) (*voltha.Device, error) { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1818 | logger.Infow("GetChildDevice", |
| 1819 | log.Fields{ |
| 1820 | "pon-port": intfID, |
| 1821 | "onu-id": onuID, |
| 1822 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1823 | parentPortNo := IntfIDToPortNo(intfID, voltha.Port_PON_OLT) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1824 | onuDevice, err := f.deviceHandler.GetChildDevice(parentPortNo, onuID) |
| 1825 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1826 | return nil, olterrors.NewErrNotFound("onu", |
| 1827 | log.Fields{ |
| 1828 | "interface-id": parentPortNo, |
| 1829 | "onu-id": onuID, |
| 1830 | "device-id": f.deviceHandler.device.Id}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1831 | err) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1832 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1833 | logger.Infow("successfully-received-child-device-from-core", |
| 1834 | log.Fields{ |
| 1835 | "device-id": f.deviceHandler.device.Id, |
| 1836 | "child_device_id": onuDevice.Id, |
| 1837 | "child_device_sn": onuDevice.SerialNumber}) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1838 | return onuDevice, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | func findNextFlow(flow *ofp.OfpFlowStats) *ofp.OfpFlowStats { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1842 | logger.Info("unimplemented-flow %v", flow) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1843 | return nil |
| 1844 | } |
| 1845 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1846 | func (f *OpenOltFlowMgr) clearFlowsAndSchedulerForLogicalPort(childDevice *voltha.Device, logicalPort *voltha.LogicalPort) { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1847 | logger.Info("unimplemented-device %v, logicalport %v", childDevice, logicalPort) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1848 | } |
| 1849 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1850 | func (f *OpenOltFlowMgr) decodeStoredID(id uint64) (uint64, string) { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1851 | if id>>15 == 0x1 { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1852 | return id & 0x7fff, Upstream |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1853 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1854 | return id, Downstream |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1855 | } |
| 1856 | |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1857 | func (f *OpenOltFlowMgr) sendDeleteGemPortToChild(intfID uint32, onuID uint32, uniID uint32, gemPortID uint32, tpPath string) error { |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1858 | onuDev, err := f.getOnuDevice(intfID, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1859 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1860 | logger.Debugw("couldnt-find-onu-child-device", |
| 1861 | log.Fields{ |
| 1862 | "intf-id": intfID, |
| 1863 | "onu-id": onuID, |
| 1864 | "uni-id": uniID, |
| 1865 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1866 | return err |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | delGemPortMsg := &ic.InterAdapterDeleteGemPortMessage{UniId: uniID, TpPath: tpPath, GemPortId: gemPortID} |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1870 | logger.Debugw("sending-gem-port-delete-to-openonu-adapter", |
| 1871 | log.Fields{ |
| 1872 | "msg": *delGemPortMsg, |
| 1873 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1874 | if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(context.Background(), |
| 1875 | delGemPortMsg, |
| 1876 | ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1877 | f.deviceHandler.device.Type, |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1878 | onuDev.deviceType, |
| 1879 | onuDev.deviceID, |
| 1880 | onuDev.proxyDeviceID, ""); sendErr != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1881 | return olterrors.NewErrCommunication("send-delete-gem-port-to-onu-adapter", |
| 1882 | log.Fields{ |
| 1883 | "from-adapter": f.deviceHandler.device.Type, |
| 1884 | "to-adapter": onuDev.deviceType, |
| 1885 | "onu-id": onuDev.deviceID, |
| 1886 | "proxyDeviceID": onuDev.proxyDeviceID, |
| 1887 | "device-id": f.deviceHandler.device.Id}, sendErr) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1888 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1889 | logger.Infow("success-sending-del-gem-port-to-onu-adapter", |
| 1890 | log.Fields{ |
| 1891 | "msg": delGemPortMsg, |
| 1892 | "from-adapter": f.deviceHandler.device.Type, |
| 1893 | "to-adapter": onuDev.deviceType, |
| 1894 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1895 | return nil |
| 1896 | } |
| 1897 | |
| 1898 | func (f *OpenOltFlowMgr) sendDeleteTcontToChild(intfID uint32, onuID uint32, uniID uint32, allocID uint32, tpPath string) error { |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1899 | onuDev, err := f.getOnuDevice(intfID, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1900 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1901 | logger.Warnw("couldnt-find-onu-child-device", |
| 1902 | log.Fields{ |
| 1903 | "intf-id": intfID, |
| 1904 | "onu-id": onuID, |
| 1905 | "uni-id": uniID, |
| 1906 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1907 | return err |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | delTcontMsg := &ic.InterAdapterDeleteTcontMessage{UniId: uniID, TpPath: tpPath, AllocId: allocID} |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1911 | logger.Debugw("sending-tcont-delete-to-openonu-adapter", |
| 1912 | log.Fields{ |
| 1913 | "msg": *delTcontMsg, |
| 1914 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1915 | if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(context.Background(), |
| 1916 | delTcontMsg, |
| 1917 | ic.InterAdapterMessageType_DELETE_TCONT_REQUEST, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 1918 | f.deviceHandler.device.Type, |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1919 | onuDev.deviceType, |
| 1920 | onuDev.deviceID, |
| 1921 | onuDev.proxyDeviceID, ""); sendErr != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1922 | return olterrors.NewErrCommunication("send-delete-tcont-to-onu-adapter", |
| 1923 | log.Fields{ |
| 1924 | "from-adapter": f.deviceHandler.device.Type, |
| 1925 | "to-adapter": onuDev.deviceType, "onu-id": onuDev.deviceID, |
| 1926 | "proxyDeviceID": onuDev.proxyDeviceID, |
| 1927 | "device-id": f.deviceHandler.device.Id}, sendErr) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1928 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1929 | logger.Infow("success-sending-del-tcont-to-onu-adapter", |
| 1930 | log.Fields{ |
| 1931 | "msg": delTcontMsg, |
| 1932 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1933 | return nil |
| 1934 | } |
| 1935 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1936 | func (f *OpenOltFlowMgr) deletePendingFlows(Intf uint32, onuID int32, uniID int32) { |
| 1937 | pnFlDelKey := pendingFlowDeleteKey{Intf, uint32(onuID), uint32(uniID)} |
| 1938 | if val, ok := f.pendingFlowDelete.Load(pnFlDelKey); ok { |
| 1939 | if val.(int) > 0 { |
| 1940 | pnFlDels := val.(int) - 1 |
| 1941 | if pnFlDels > 0 { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1942 | logger.Debugw("flow-delete-succeeded--more-pending", |
| 1943 | log.Fields{ |
| 1944 | "intf": Intf, |
| 1945 | "onu-id": onuID, |
| 1946 | "uni-id": uniID, |
| 1947 | "currpendingflowcnt": pnFlDels, |
| 1948 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1949 | f.pendingFlowDelete.Store(pnFlDelKey, pnFlDels) |
| 1950 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1951 | logger.Debugw("all-pending-flow-deletes-handled--removing-entry-from-map", |
| 1952 | log.Fields{ |
| 1953 | "intf": Intf, |
| 1954 | "onu-id": onuID, |
| 1955 | "uni-id": uniID, |
| 1956 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1957 | f.pendingFlowDelete.Delete(pnFlDelKey) |
| 1958 | } |
| 1959 | } |
| 1960 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1961 | logger.Debugw("no-pending-delete-flows-found", |
| 1962 | log.Fields{ |
| 1963 | "intf": Intf, |
| 1964 | "onu-id": onuID, |
| 1965 | "uni-id": uniID, |
| 1966 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1967 | |
| 1968 | } |
| 1969 | |
| 1970 | } |
| 1971 | |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 1972 | // Once the gemport is released for a given onu, it also has to be cleared from local cache |
| 1973 | // which was used for deriving the gemport->logicalPortNo during packet-in. |
| 1974 | // Otherwise stale info continues to exist after gemport is freed and wrong logicalPortNo |
| 1975 | // is conveyed to ONOS during packet-in OF message. |
| 1976 | func (f *OpenOltFlowMgr) deleteGemPortFromLocalCache(intfID uint32, onuID uint32, gemPortID uint32) { |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 1977 | |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 1978 | f.onuGemInfoLock.Lock() |
| 1979 | defer f.onuGemInfoLock.Unlock() |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 1980 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1981 | logger.Infow("deleting-gem-from-local-cache", |
| 1982 | log.Fields{ |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 1983 | "gem-port-id": gemPortID, |
| 1984 | "intf-id": intfID, |
| 1985 | "onu-id": onuID, |
| 1986 | "device-id": f.deviceHandler.device.Id, |
| 1987 | "onu-gem": f.onuGemInfo[intfID]}) |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 1988 | onugem := f.onuGemInfo[intfID] |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 1989 | deleteLoop: |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 1990 | for i, onu := range onugem { |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 1991 | if onu.OnuID == onuID { |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 1992 | for j, gem := range onu.GemPorts { |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 1993 | // If the gemport is found, delete it from local cache. |
| 1994 | if gem == gemPortID { |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 1995 | onu.GemPorts = append(onu.GemPorts[:j], onu.GemPorts[j+1:]...) |
| 1996 | onugem[i] = onu |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1997 | logger.Infow("removed-gemport-from-local-cache", |
| 1998 | log.Fields{ |
| 1999 | "intf-id": intfID, |
| 2000 | "onu-id": onuID, |
| 2001 | "deletedgemport-id": gemPortID, |
| 2002 | "gemports": onu.GemPorts, |
| 2003 | "device-id": f.deviceHandler.device.Id}) |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2004 | break deleteLoop |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 2005 | } |
| 2006 | } |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2007 | break deleteLoop |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 2008 | } |
| 2009 | } |
| 2010 | } |
| 2011 | |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2012 | //clearResources clears pon resources in kv store and the device |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2013 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2014 | func (f *OpenOltFlowMgr) clearResources(ctx context.Context, flow *ofp.OfpFlowStats, Intf uint32, onuID int32, uniID int32, |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2015 | gemPortID int32, flowID uint32, flowDirection string, |
| 2016 | portNum uint32, updatedFlows []rsrcMgr.FlowInfo) error { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2017 | |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2018 | tpID, err := getTpIDFromFlow(flow) |
| 2019 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2020 | return olterrors.NewErrNotFound("tp-id", |
| 2021 | log.Fields{ |
| 2022 | "flow": flow, |
| 2023 | "intf": Intf, |
| 2024 | "onu-id": onuID, |
| 2025 | "uni-id": uniID, |
| 2026 | "device-id": f.deviceHandler.device.Id}, err) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2027 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2028 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2029 | if len(updatedFlows) >= 0 { |
| 2030 | // There are still flows referencing the same flow_id. |
| 2031 | // So the flow should not be freed yet. |
| 2032 | // For ex: Case of HSIA where same flow is shared |
| 2033 | // between DS and US. |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2034 | if err := f.updateFlowInfoToKVStore(ctx, int32(Intf), int32(onuID), int32(uniID), flowID, &updatedFlows); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2035 | olterrors.NewErrPersistence("update", "flow", flowID, |
| 2036 | log.Fields{ |
| 2037 | "flow": updatedFlows, |
| 2038 | "device-id": f.deviceHandler.device.Id}, err).Log() |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2039 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2040 | if len(updatedFlows) == 0 { |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2041 | // Do this for subscriber flows only (not trap from NNI flows) |
| 2042 | if onuID != -1 && uniID != -1 { |
| 2043 | pnFlDelKey := pendingFlowDeleteKey{Intf, uint32(onuID), uint32(uniID)} |
| 2044 | if val, ok := f.pendingFlowDelete.Load(pnFlDelKey); !ok { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2045 | logger.Debugw("creating-entry-for-pending-flow-delete", |
| 2046 | log.Fields{ |
| 2047 | "flow-id": flowID, |
| 2048 | "intf": Intf, |
| 2049 | "onu-id": onuID, |
| 2050 | "uni-id": uniID, |
| 2051 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2052 | f.pendingFlowDelete.Store(pnFlDelKey, 1) |
| 2053 | } else { |
| 2054 | pnFlDels := val.(int) + 1 |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2055 | logger.Debugw("updating-flow-delete-entry", |
| 2056 | log.Fields{ |
| 2057 | "flow-id": flowID, |
| 2058 | "intf": Intf, |
| 2059 | "onu-id": onuID, |
| 2060 | "uni-id": uniID, |
| 2061 | "currPendingFlowCnt": pnFlDels, |
| 2062 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2063 | f.pendingFlowDelete.Store(pnFlDelKey, pnFlDels) |
| 2064 | } |
| 2065 | |
| 2066 | defer f.deletePendingFlows(Intf, onuID, uniID) |
| 2067 | } |
| 2068 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2069 | logger.Debugw("releasing-flow-id-to-resource-manager", |
| 2070 | log.Fields{ |
| 2071 | "Intf": Intf, |
| 2072 | "onu-id": onuID, |
| 2073 | "uni-id": uniID, |
| 2074 | "flow-id": flowID, |
| 2075 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2076 | f.resourceMgr.FreeFlowID(ctx, Intf, int32(onuID), int32(uniID), flowID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2077 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 2078 | uni := getUniPortPath(f.deviceHandler.device.Id, Intf, onuID, uniID) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2079 | tpPath := f.getTPpath(Intf, uni, tpID) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2080 | logger.Debugw("getting-techprofile-instance-for-subscriber", |
| 2081 | log.Fields{ |
| 2082 | "TP-PATH": tpPath, |
| 2083 | "device-id": f.deviceHandler.device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2084 | techprofileInst, err := f.techprofile[Intf].GetTPInstanceFromKVStore(ctx, tpID, tpPath) |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2085 | if err != nil || techprofileInst == nil { // This should not happen, something wrong in KV backend transaction |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2086 | return olterrors.NewErrNotFound("tech-profile-in-kv-store", |
| 2087 | log.Fields{ |
| 2088 | "tp-id": tpID, |
| 2089 | "path": tpPath}, err) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2092 | gemPK := gemPortKey{Intf, uint32(gemPortID)} |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 2093 | used, err := f.isGemPortUsedByAnotherFlow(gemPK) |
| 2094 | if err != nil { |
| 2095 | return err |
| 2096 | } |
| 2097 | if used { |
| 2098 | if f.perGemPortLock.TryLock(gemPK) { |
| 2099 | flowIDs := f.flowsUsedByGemPort[gemPK] |
| 2100 | for i, flowIDinMap := range flowIDs { |
| 2101 | if flowIDinMap == flowID { |
| 2102 | flowIDs = append(flowIDs[:i], flowIDs[i+1:]...) |
| 2103 | // everytime flowsUsedByGemPort cache is updated the same should be updated |
| 2104 | // in kv store by calling UpdateFlowIDsForGem |
| 2105 | f.flowsUsedByGemPort[gemPK] = flowIDs |
| 2106 | f.resourceMgr.UpdateFlowIDsForGem(ctx, Intf, uint32(gemPortID), flowIDs) |
| 2107 | break |
| 2108 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2109 | } |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 2110 | logger.Debugw("gem-port-id-is-still-used-by-other-flows", |
| 2111 | log.Fields{ |
| 2112 | "gemport-id": gemPortID, |
| 2113 | "usedByFlows": flowIDs, |
| 2114 | "device-id": f.deviceHandler.device.Id}) |
| 2115 | f.perGemPortLock.Unlock(gemPK) |
| 2116 | return nil |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2117 | } |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 2118 | logger.Error("failed-to-acquire-per-gem-port-lock", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2119 | log.Fields{ |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 2120 | "gemport-id": gemPortID, |
| 2121 | "device-id": f.deviceHandler.device.Id, |
| 2122 | "key": gemPK, |
| 2123 | }) |
| 2124 | return olterrors.NewErrAdapter("failed-to-acquire-per-gem-port-lock", log.Fields{ |
| 2125 | "gemport-id": gemPortID, |
| 2126 | "device-id": f.deviceHandler.device.Id, |
| 2127 | "key": gemPK, |
| 2128 | }, nil) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2129 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2130 | logger.Debugf("gem-port-id %d is-not-used-by-another-flow--releasing-the-gem-port", gemPortID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2131 | f.resourceMgr.RemoveGemPortIDForOnu(ctx, Intf, uint32(onuID), uint32(uniID), uint32(gemPortID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2132 | // TODO: The TrafficQueue corresponding to this gem-port also should be removed immediately. |
| 2133 | // But it is anyway eventually removed later when the TechProfile is freed, so not a big issue for now. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2134 | f.resourceMgr.RemoveGEMportPonportToOnuMapOnKVStore(ctx, uint32(gemPortID), Intf) |
Girish Gowdra | c303740 | 2020-01-22 20:29:53 +0530 | [diff] [blame] | 2135 | f.deleteGemPortFromLocalCache(Intf, uint32(onuID), uint32(gemPortID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2136 | f.onuIdsLock.Lock() |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 2137 | //everytime an entry is deleted from flowsUsedByGemPort cache, the same should be updated in kv as well |
| 2138 | // by calling DeleteFlowIDsForGem |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 2139 | if f.perGemPortLock.TryLock(gemPK) { |
| 2140 | delete(f.flowsUsedByGemPort, gemPK) |
| 2141 | f.perGemPortLock.Unlock(gemPK) |
| 2142 | } else { |
| 2143 | logger.Error("failed-to-acquire-per-gem-port-lock", |
| 2144 | log.Fields{ |
| 2145 | "device-id": f.deviceHandler.device.Id, |
| 2146 | "key": gemPK, |
| 2147 | }) |
| 2148 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2149 | f.resourceMgr.DeleteFlowIDsForGem(ctx, Intf, uint32(gemPortID)) |
| 2150 | f.resourceMgr.FreeGemPortID(ctx, Intf, uint32(onuID), uint32(uniID), uint32(gemPortID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2151 | f.onuIdsLock.Unlock() |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 2152 | // Delete the gem port on the ONU. |
| 2153 | if err := f.sendDeleteGemPortToChild(Intf, uint32(onuID), uint32(uniID), uint32(gemPortID), tpPath); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2154 | logger.Errorw("error-processing-delete-gem-port-towards-onu", |
| 2155 | log.Fields{ |
| 2156 | "err": err, |
| 2157 | "intf": Intf, |
| 2158 | "onu-id": onuID, |
| 2159 | "uni-id": uniID, |
| 2160 | "device-id": f.deviceHandler.device.Id, |
| 2161 | "gemport-id": gemPortID}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 2162 | } |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2163 | switch techprofileInst := techprofileInst.(type) { |
| 2164 | case *tp.TechProfile: |
| 2165 | ok, _ := f.isTechProfileUsedByAnotherGem(ctx, Intf, uint32(onuID), uint32(uniID), tpID, techprofileInst, uint32(gemPortID)) |
| 2166 | if !ok { |
| 2167 | f.resourceMgr.RemoveTechProfileIDForOnu(ctx, Intf, uint32(onuID), uint32(uniID), tpID) |
| 2168 | f.DeleteTechProfileInstance(ctx, Intf, uint32(onuID), uint32(uniID), "", tpID) |
| 2169 | f.RemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: Intf, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst}) |
| 2170 | f.RemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: Intf, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst}) |
| 2171 | f.resourceMgr.FreeAllocID(ctx, Intf, uint32(onuID), uint32(uniID), techprofileInst.UsScheduler.AllocID) |
| 2172 | // Delete the TCONT on the ONU. |
| 2173 | if err := f.sendDeleteTcontToChild(Intf, uint32(onuID), uint32(uniID), uint32(techprofileInst.UsScheduler.AllocID), tpPath); err != nil { |
| 2174 | logger.Errorw("error-processing-delete-tcont-towards-onu", |
| 2175 | log.Fields{ |
| 2176 | "intf": Intf, |
| 2177 | "onu-id": onuID, |
| 2178 | "uni-id": uniID, |
| 2179 | "device-id": f.deviceHandler.device.Id, |
| 2180 | "alloc-id": techprofileInst.UsScheduler.AllocID}) |
| 2181 | } |
| 2182 | } |
| 2183 | case *tp.EponProfile: |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2184 | f.resourceMgr.RemoveTechProfileIDForOnu(ctx, Intf, uint32(onuID), uint32(uniID), tpID) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2185 | f.DeleteTechProfileInstance(ctx, Intf, uint32(onuID), uint32(uniID), "", tpID) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2186 | f.resourceMgr.FreeAllocID(ctx, Intf, uint32(onuID), uint32(uniID), techprofileInst.AllocID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 2187 | // Delete the TCONT on the ONU. |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2188 | if err := f.sendDeleteTcontToChild(Intf, uint32(onuID), uint32(uniID), uint32(techprofileInst.AllocID), tpPath); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2189 | logger.Errorw("error-processing-delete-tcont-towards-onu", |
| 2190 | log.Fields{ |
| 2191 | "intf": Intf, |
| 2192 | "onu-id": onuID, |
| 2193 | "uni-id": uniID, |
| 2194 | "device-id": f.deviceHandler.device.Id, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2195 | "alloc-id": techprofileInst.AllocID}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 2196 | } |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2197 | default: |
| 2198 | logger.Errorw("error-unknown-tech", |
| 2199 | log.Fields{ |
| 2200 | "techprofileInst": techprofileInst}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2201 | } |
| 2202 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2203 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2204 | return nil |
| 2205 | } |
| 2206 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2207 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2208 | func (f *OpenOltFlowMgr) clearFlowFromResourceManager(ctx context.Context, flow *ofp.OfpFlowStats, flowDirection string) { |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2209 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2210 | logger.Infow("clear-flow-from-resource-manager", |
| 2211 | log.Fields{ |
| 2212 | "flowDirection": flowDirection, |
| 2213 | "flow": *flow, |
| 2214 | "device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2215 | |
| 2216 | if flowDirection == Multicast { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2217 | f.clearMulticastFlowFromResourceManager(ctx, flow) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2218 | return |
| 2219 | } |
| 2220 | |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2221 | var updatedFlows []rsrcMgr.FlowInfo |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2222 | classifierInfo := make(map[string]interface{}) |
| 2223 | |
| 2224 | portNum, Intf, onu, uni, inPort, ethType, err := FlowExtractInfo(flow, flowDirection) |
| 2225 | if err != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2226 | logger.Error(err) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2227 | return |
| 2228 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2229 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2230 | onuID := int32(onu) |
| 2231 | uniID := int32(uni) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2232 | |
| 2233 | for _, field := range flows.GetOfbFields(flow) { |
| 2234 | if field.Type == flows.IP_PROTO { |
| 2235 | classifierInfo[IPProto] = field.GetIpProto() |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2236 | logger.Debugw("field-type-ip-proto", log.Fields{"classifierInfo[IP_PROTO]": classifierInfo[IPProto].(uint32)}) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2237 | } |
| 2238 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2239 | logger.Infow("extracted-access-info-from-flow-to-be-deleted", |
| 2240 | log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2241 | "flow-id": flow.Id, |
| 2242 | "intf-id": Intf, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2243 | "onu-id": onuID, |
| 2244 | "uni-id": uniID}) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2245 | |
| 2246 | if ethType == LldpEthType || ((classifierInfo[IPProto] == IPProtoDhcp) && (flowDirection == "downstream")) { |
| 2247 | onuID = -1 |
| 2248 | uniID = -1 |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2249 | logger.Debug("trap-on-nni-flow-set-oni--uni-to- -1") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2250 | Intf, err = IntfIDFromNniPortNum(inPort) |
| 2251 | if err != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2252 | logger.Errorw("invalid-in-port-number", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2253 | log.Fields{ |
| 2254 | "port-number": inPort, |
| 2255 | "error": err}) |
| 2256 | return |
| 2257 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2258 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2259 | flowIds := f.resourceMgr.GetCurrentFlowIDsForOnu(ctx, Intf, onuID, uniID) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2260 | for _, flowID := range flowIds { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2261 | flowInfo := f.resourceMgr.GetFlowIDInfo(ctx, Intf, onuID, uniID, flowID) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2262 | if flowInfo == nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2263 | logger.Debugw("no-flowinfo-found-in-kv-store", |
| 2264 | log.Fields{ |
| 2265 | "intf": Intf, |
| 2266 | "onu-id": onuID, |
| 2267 | "uni-id": uniID, |
| 2268 | "flow-id": flowID}) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2269 | return |
| 2270 | } |
| 2271 | updatedFlows = nil |
| 2272 | for _, flow := range *flowInfo { |
| 2273 | updatedFlows = append(updatedFlows, flow) |
| 2274 | } |
| 2275 | |
| 2276 | for i, storedFlow := range updatedFlows { |
| 2277 | if flow.Id == storedFlow.LogicalFlowID { |
| 2278 | removeFlowMessage := openoltpb2.Flow{FlowId: storedFlow.Flow.FlowId, FlowType: storedFlow.Flow.FlowType} |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2279 | logger.Debugw("flow-to-be-deleted", log.Fields{"flow": storedFlow}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2280 | // DKB |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2281 | if err = f.removeFlowFromDevice(&removeFlowMessage, flow.Id); err != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2282 | logger.Errorw("failed-to-remove-flow", log.Fields{"error": err}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2283 | return |
| 2284 | } |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2285 | logger.Info("flow-removed-from-device-successfully", log.Fields{ |
| 2286 | "flow-id": flow.Id, |
| 2287 | "stored-flow": storedFlow, |
| 2288 | "device-id": f.deviceHandler.device.Id, |
| 2289 | "stored-flow-id": flowID, |
| 2290 | "onu-id": onuID, |
| 2291 | "intf": Intf, |
| 2292 | }) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2293 | //Remove the Flow from FlowInfo |
| 2294 | updatedFlows = append(updatedFlows[:i], updatedFlows[i+1:]...) |
| 2295 | if err = f.clearResources(ctx, flow, Intf, onuID, uniID, storedFlow.Flow.GemportId, |
| 2296 | flowID, flowDirection, portNum, updatedFlows); err != nil { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2297 | logger.Error("failed-to-clear-resources-for-flow", log.Fields{ |
| 2298 | "flow-id": flow.Id, |
| 2299 | "stored-flow": storedFlow, |
| 2300 | "device-id": f.deviceHandler.device.Id, |
| 2301 | "stored-flow-id": flowID, |
| 2302 | "onu-id": onuID, |
| 2303 | "intf": Intf, |
| 2304 | }) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2305 | return |
| 2306 | } |
| 2307 | } |
| 2308 | } |
| 2309 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2310 | } |
| 2311 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2312 | //clearMulticastFlowFromResourceManager removes a multicast flow from the KV store and |
| 2313 | // clears resources reserved for this multicast flow |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2314 | func (f *OpenOltFlowMgr) clearMulticastFlowFromResourceManager(ctx context.Context, flow *ofp.OfpFlowStats) { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2315 | classifierInfo := make(map[string]interface{}) |
| 2316 | formulateClassifierInfoFromFlow(classifierInfo, flow) |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2317 | networkInterfaceID, err := f.getNNIInterfaceIDOfMulticastFlow(ctx, classifierInfo) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2318 | |
| 2319 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2320 | logger.Warnw("no-inport-found--cannot-release-resources-of-the-multicast-flow", log.Fields{"flowId:": flow.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2321 | return |
| 2322 | } |
| 2323 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2324 | var onuID = int32(NoneOnuID) |
| 2325 | var uniID = int32(NoneUniID) |
| 2326 | var flowID uint32 |
| 2327 | var updatedFlows []rsrcMgr.FlowInfo |
| 2328 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2329 | flowIds := f.resourceMgr.GetCurrentFlowIDsForOnu(ctx, networkInterfaceID, onuID, uniID) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2330 | |
| 2331 | for _, flowID = range flowIds { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2332 | flowInfo := f.resourceMgr.GetFlowIDInfo(ctx, networkInterfaceID, onuID, uniID, flowID) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2333 | if flowInfo == nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2334 | logger.Debugw("no-multicast-flowinfo-found-in-the-kv-store", |
| 2335 | log.Fields{ |
| 2336 | "intf": networkInterfaceID, |
| 2337 | "onu-id": onuID, |
| 2338 | "uni-id": uniID, |
| 2339 | "flow-id": flowID}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2340 | continue |
| 2341 | } |
| 2342 | updatedFlows = nil |
| 2343 | for _, flow := range *flowInfo { |
| 2344 | updatedFlows = append(updatedFlows, flow) |
| 2345 | } |
| 2346 | for i, storedFlow := range updatedFlows { |
| 2347 | if flow.Id == storedFlow.LogicalFlowID { |
| 2348 | removeFlowMessage := openoltpb2.Flow{FlowId: storedFlow.Flow.FlowId, FlowType: storedFlow.Flow.FlowType} |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2349 | logger.Debugw("multicast-flow-to-be-deleted", |
| 2350 | log.Fields{ |
| 2351 | "flow": storedFlow, |
| 2352 | "flow-id": flow.Id, |
| 2353 | "device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2354 | //remove from device |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2355 | if err := f.removeFlowFromDevice(&removeFlowMessage, flow.Id); err != nil { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2356 | // DKB |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2357 | logger.Errorw("failed-to-remove-multicast-flow", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2358 | log.Fields{ |
| 2359 | "flow-id": flow.Id, |
| 2360 | "error": err}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2361 | return |
| 2362 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2363 | logger.Infow("multicast-flow-removed-from-device-successfully", log.Fields{"flow-id": flow.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2364 | //Remove the Flow from FlowInfo |
| 2365 | updatedFlows = append(updatedFlows[:i], updatedFlows[i+1:]...) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2366 | if err := f.updateFlowInfoToKVStore(ctx, int32(networkInterfaceID), NoneOnuID, NoneUniID, flowID, &updatedFlows); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2367 | logger.Errorw("failed-to-delete-multicast-flow-from-the-kv-store", |
| 2368 | log.Fields{"flow": storedFlow, |
| 2369 | "err": err}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2370 | return |
| 2371 | } |
| 2372 | //release flow id |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2373 | logger.Debugw("releasing-multicast-flow-id", |
| 2374 | log.Fields{"flow-id": flowID, |
| 2375 | "interfaceID": networkInterfaceID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2376 | f.resourceMgr.FreeFlowID(ctx, uint32(networkInterfaceID), NoneOnuID, NoneUniID, flowID) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2377 | } |
| 2378 | } |
| 2379 | } |
| 2380 | } |
| 2381 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2382 | //RemoveFlow removes the flow from the device |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2383 | func (f *OpenOltFlowMgr) RemoveFlow(ctx context.Context, flow *ofp.OfpFlowStats) error { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2384 | logger.Infow("removing-flow", log.Fields{"flow": *flow}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2385 | var direction string |
| 2386 | actionInfo := make(map[string]interface{}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2387 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2388 | for _, action := range flows.GetActions(flow) { |
| 2389 | if action.Type == flows.OUTPUT { |
| 2390 | if out := action.GetOutput(); out != nil { |
| 2391 | actionInfo[Output] = out.GetPort() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2392 | logger.Debugw("action-type-output", log.Fields{"out_port": actionInfo[Output].(uint32)}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2393 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2394 | logger.Error("invalid-output-port-in-action") |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2395 | return olterrors.NewErrInvalidValue(log.Fields{"invalid-out-port-action": 0}, nil) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2396 | } |
| 2397 | } |
| 2398 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2399 | |
| 2400 | if flows.HasGroup(flow) { |
| 2401 | direction = Multicast |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2402 | f.clearFlowFromResourceManager(ctx, flow, direction) |
| 2403 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2404 | } else if IsUpstream(actionInfo[Output].(uint32)) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2405 | direction = Upstream |
| 2406 | } else { |
| 2407 | direction = Downstream |
| 2408 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2409 | |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2410 | _, intfID, onuID, uniID, _, _, err := FlowExtractInfo(flow, direction) |
| 2411 | if err != nil { |
| 2412 | return err |
| 2413 | } |
| 2414 | |
| 2415 | userKey := tpLockKey{intfID, onuID, uniID} |
| 2416 | |
| 2417 | // Serialize flow removes on a per subscriber basis |
| 2418 | if f.perUserFlowHandleLock.TryLock(userKey) { |
| 2419 | f.clearFlowFromResourceManager(ctx, flow, direction) //TODO: Take care of the limitations |
| 2420 | f.perUserFlowHandleLock.Unlock(userKey) |
| 2421 | } else { |
| 2422 | // Ideally this should never happen |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2423 | logger.Errorw("failed-to-acquire-lock-to-remove-flow--remove-aborted", log.Fields{"flow": flow}) |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2424 | return errors.New("failed-to-acquire-per-user-lock") |
| 2425 | } |
| 2426 | |
| 2427 | return nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2428 | } |
| 2429 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2430 | func (f *OpenOltFlowMgr) waitForFlowDeletesToCompleteForOnu(ctx context.Context, intfID uint32, onuID uint32, |
| 2431 | uniID uint32, ch chan bool) { |
| 2432 | pnFlDelKey := pendingFlowDeleteKey{intfID, onuID, uniID} |
| 2433 | for { |
| 2434 | select { |
| 2435 | case <-time.After(20 * time.Millisecond): |
| 2436 | if flowDelRefCnt, ok := f.pendingFlowDelete.Load(pnFlDelKey); !ok || flowDelRefCnt == 0 { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2437 | logger.Debug("pending-flow-deletes-completed") |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2438 | ch <- true |
| 2439 | return |
| 2440 | } |
| 2441 | case <-ctx.Done(): |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2442 | logger.Error("flow-delete-wait-handler-routine-canceled") |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2443 | return |
| 2444 | } |
| 2445 | } |
| 2446 | } |
| 2447 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2448 | //isIgmpTrapDownstreamFlow return true if the flow is a downsteam IGMP trap-to-host flow; false otherwise |
| 2449 | func isIgmpTrapDownstreamFlow(classifierInfo map[string]interface{}) bool { |
| 2450 | if portType := IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_ETHERNET_NNI { |
| 2451 | if ethType, ok := classifierInfo[EthType]; ok { |
| 2452 | if ethType.(uint32) == IPv4EthType { |
| 2453 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2454 | if ipProto.(uint32) == IgmpProto { |
| 2455 | return true |
| 2456 | } |
| 2457 | } |
| 2458 | } |
| 2459 | } |
| 2460 | } |
| 2461 | return false |
| 2462 | } |
| 2463 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2464 | // AddFlow add flow to device |
Naga Manjunath | b8438aa | 2020-01-02 17:52:33 +0530 | [diff] [blame] | 2465 | // nolint: gocyclo |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2466 | func (f *OpenOltFlowMgr) AddFlow(ctx context.Context, flow *ofp.OfpFlowStats, flowMetadata *voltha.FlowMetadata) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2467 | classifierInfo := make(map[string]interface{}) |
| 2468 | actionInfo := make(map[string]interface{}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2469 | var UsMeterID uint32 |
| 2470 | var DsMeterID uint32 |
| 2471 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2472 | logger.Infow("adding-flow", |
| 2473 | log.Fields{ |
| 2474 | "flow": flow, |
| 2475 | "flowmetadata": flowMetadata}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2476 | formulateClassifierInfoFromFlow(classifierInfo, flow) |
| 2477 | |
| 2478 | err := formulateActionInfoFromFlow(actionInfo, classifierInfo, flow) |
| 2479 | if err != nil { |
| 2480 | // Error logging is already done in the called function |
| 2481 | // So just return in case of error |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2482 | return err |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2483 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2484 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2485 | if flows.HasGroup(flow) { |
| 2486 | // handle multicast flow |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2487 | return f.handleFlowWithGroup(ctx, actionInfo, classifierInfo, flow) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2490 | /* Controller bound trap flows */ |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2491 | err = formulateControllerBoundTrapFlowInfo(actionInfo, classifierInfo, flow) |
| 2492 | if err != nil { |
| 2493 | // error if any, already logged in the called function |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2494 | return err |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2495 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2496 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2497 | logger.Debugw("flow-ports", |
| 2498 | log.Fields{ |
| 2499 | "classifierinfo_inport": classifierInfo[InPort], |
| 2500 | "action_output": actionInfo[Output]}) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2501 | portNo, intfID, onuID, uniID := ExtractAccessFromFlow(classifierInfo[InPort].(uint32), actionInfo[Output].(uint32)) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2502 | |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2503 | if ethType, ok := classifierInfo[EthType]; ok { |
| 2504 | if ethType.(uint32) == LldpEthType { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2505 | logger.Info("adding-lldp-flow") |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2506 | return f.addLLDPFlow(ctx, flow, portNo) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2507 | } |
| 2508 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2509 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2510 | if ipProto.(uint32) == IPProtoDhcp { |
| 2511 | if udpSrc, ok := classifierInfo[UDPSrc]; ok { |
Naga Manjunath | b8438aa | 2020-01-02 17:52:33 +0530 | [diff] [blame] | 2512 | if udpSrc.(uint32) == uint32(67) || udpSrc.(uint32) == uint32(546) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2513 | logger.Debug("trap-dhcp-from-nni-flow") |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2514 | return f.addDHCPTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2515 | } |
| 2516 | } |
| 2517 | } |
| 2518 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2519 | if isIgmpTrapDownstreamFlow(classifierInfo) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2520 | logger.Debug("trap-igmp-from-nni-flow") |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2521 | return f.addIgmpTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2522 | } |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2523 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2524 | f.resourceMgr.AddUniPortToOnuInfo(ctx, intfID, onuID, portNo) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2525 | |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2526 | TpID, err := getTpIDFromFlow(flow) |
| 2527 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2528 | return olterrors.NewErrNotFound("tpid-for-flow", |
| 2529 | log.Fields{ |
| 2530 | "flow": flow, |
| 2531 | "intf-id": IntfID, |
| 2532 | "onu-id": onuID, |
| 2533 | "uni-id": uniID}, err) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2534 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2535 | logger.Debugw("tpid-for-this-subcriber", |
| 2536 | log.Fields{ |
| 2537 | "tp-id": TpID, |
| 2538 | "intf-id": intfID, |
| 2539 | "onu-id": onuID, |
| 2540 | "uni-id": uniID}) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2541 | if IsUpstream(actionInfo[Output].(uint32)) { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2542 | UsMeterID = flows.GetMeterIdFromFlow(flow) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2543 | logger.Debugw("upstream-flow-meter-id", log.Fields{"us-meter-id": UsMeterID}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2544 | } else { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2545 | DsMeterID = flows.GetMeterIdFromFlow(flow) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2546 | logger.Debugw("downstream-flow-meter-id", log.Fields{"ds-meter-id": DsMeterID}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2547 | |
| 2548 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2549 | |
| 2550 | pnFlDelKey := pendingFlowDeleteKey{intfID, onuID, uniID} |
| 2551 | if _, ok := f.pendingFlowDelete.Load(pnFlDelKey); !ok { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2552 | logger.Debugw("no-pending-flows-found--going-ahead-with-flow-install", |
| 2553 | log.Fields{ |
| 2554 | "intf-id": intfID, |
| 2555 | "onu-id": onuID, |
| 2556 | "uni-id": uniID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2557 | f.divideAndAddFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, uint32(TpID), UsMeterID, DsMeterID, flowMetadata) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2558 | } else { |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2559 | pendingFlowDelComplete := make(chan bool) |
| 2560 | go f.waitForFlowDeletesToCompleteForOnu(ctx, intfID, onuID, uniID, pendingFlowDelComplete) |
| 2561 | select { |
| 2562 | case <-pendingFlowDelComplete: |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2563 | logger.Debugw("all-pending-flow-deletes-completed", |
| 2564 | log.Fields{ |
| 2565 | "intf-id": intfID, |
| 2566 | "onu-id": onuID, |
| 2567 | "uni-id": uniID}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2568 | f.divideAndAddFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, uint32(TpID), UsMeterID, DsMeterID, flowMetadata) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2569 | |
| 2570 | case <-time.After(10 * time.Second): |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2571 | return olterrors.NewErrTimeout("pending-flow-deletes", |
| 2572 | log.Fields{ |
| 2573 | "intf-id": intfID, |
| 2574 | "onu-id": onuID, |
| 2575 | "uni-id": uniID}, nil) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2576 | } |
| 2577 | } |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2578 | return nil |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2581 | // handleFlowWithGroup adds multicast flow to the device. |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2582 | func (f *OpenOltFlowMgr) handleFlowWithGroup(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2583 | classifierInfo[PacketTagType] = DoubleTag |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2584 | logger.Debugw("add-multicast-flow", log.Fields{ |
| 2585 | "classifier-info": classifierInfo, |
| 2586 | "actionInfo": actionInfo}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2587 | |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2588 | networkInterfaceID, err := f.getNNIInterfaceIDOfMulticastFlow(ctx, classifierInfo) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2589 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2590 | return olterrors.NewErrNotFound("multicast-in-port", log.Fields{"classifier": classifierInfo}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2591 | } |
Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2592 | //this variable acts like a switch. When it is set, multicast flows are classified by eth_dst. |
| 2593 | //otherwise, classification is based on ipv4_dst by default. |
| 2594 | //the variable can be configurable in the future; it can be read from a configuration path in the kv store. |
| 2595 | mcastFlowClassificationByEthDst := false |
| 2596 | |
| 2597 | if mcastFlowClassificationByEthDst { |
| 2598 | //replace ipDst with ethDst |
| 2599 | if ipv4Dst, ok := classifierInfo[Ipv4Dst]; ok && |
| 2600 | flows.IsMulticastIp(ipv4Dst.(uint32)) { |
| 2601 | // replace ipv4_dst classifier with eth_dst |
| 2602 | multicastMac := flows.ConvertToMulticastMacBytes(ipv4Dst.(uint32)) |
| 2603 | delete(classifierInfo, Ipv4Dst) |
| 2604 | classifierInfo[EthDst] = multicastMac |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2605 | logger.Debugw("multicast-ip-to-mac-conversion-success", |
| 2606 | log.Fields{ |
| 2607 | "ip:": ipv4Dst.(uint32), |
| 2608 | "mac:": multicastMac}) |
Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2609 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2610 | } |
Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2611 | delete(classifierInfo, EthType) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2612 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2613 | onuID := NoneOnuID |
| 2614 | uniID := NoneUniID |
| 2615 | gemPortID := NoneGemPortID |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2616 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2617 | flowStoreCookie := getFlowStoreCookie(classifierInfo, uint32(0)) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2618 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2619 | logger.Infow("multicast-flow-exists-not-re-adding", log.Fields{"classifier-info": classifierInfo}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2620 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2621 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2622 | flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0, 0) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2623 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2624 | return olterrors.NewErrNotFound("multicast-flow-id", |
| 2625 | log.Fields{ |
| 2626 | "interface-id": networkInterfaceID, |
| 2627 | "onu-id": onuID, |
| 2628 | "uni-id": uniID, |
| 2629 | "gem-port-id": gemPortID, |
| 2630 | "cookie": flowStoreCookie}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2631 | err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2632 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2633 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 2634 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2635 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifierInfo}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2636 | } |
| 2637 | groupID := actionInfo[GroupID].(uint32) |
| 2638 | multicastFlow := openoltpb2.Flow{ |
| 2639 | FlowId: flowID, |
| 2640 | FlowType: Multicast, |
| 2641 | NetworkIntfId: int32(networkInterfaceID), |
| 2642 | GroupId: groupID, |
| 2643 | Classifier: classifierProto, |
| 2644 | Priority: int32(flow.Priority), |
| 2645 | Cookie: flow.Cookie} |
| 2646 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2647 | if err = f.addFlowToDevice(ctx, flow, &multicastFlow); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2648 | return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": multicastFlow}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2649 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2650 | logger.Info("multicast-flow-added-to-device-successfully") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2651 | //get cached group |
| 2652 | group, _, err := f.GetFlowGroupFromKVStore(ctx, groupID, true) |
| 2653 | if err == nil { |
| 2654 | //calling groupAdd to set group members after multicast flow creation |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2655 | if err = f.ModifyGroup(ctx, group); err == nil { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2656 | //cached group can be removed now |
| 2657 | f.resourceMgr.RemoveFlowGroupFromKVStore(ctx, groupID, true) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2658 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2659 | return olterrors.NewErrGroupOp("modify", groupID, log.Fields{"group": group}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2660 | } |
| 2661 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2662 | |
| 2663 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &multicastFlow, flowStoreCookie, MulticastFlow, flowID, flow.Id) |
| 2664 | if err = f.updateFlowInfoToKVStore(ctx, int32(networkInterfaceID), |
| 2665 | int32(onuID), |
| 2666 | int32(uniID), |
| 2667 | flowID, flowsToKVStore); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2668 | return olterrors.NewErrPersistence("update", "flow", flowID, log.Fields{"flow": multicastFlow}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2669 | } |
| 2670 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2673 | //getNNIInterfaceIDOfMulticastFlow returns associated NNI interface id of the inPort criterion if exists; returns the first NNI interface of the device otherwise |
| 2674 | func (f *OpenOltFlowMgr) getNNIInterfaceIDOfMulticastFlow(ctx context.Context, classifierInfo map[string]interface{}) (uint32, error) { |
| 2675 | if inPort, ok := classifierInfo[InPort]; ok { |
| 2676 | nniInterfaceID, err := IntfIDFromNniPortNum(inPort.(uint32)) |
| 2677 | if err != nil { |
| 2678 | return 0, olterrors.NewErrInvalidValue(log.Fields{"nni-in-port-number": inPort}, err) |
| 2679 | } |
| 2680 | return nniInterfaceID, nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2681 | } |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2682 | // find the first NNI interface id of the device |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2683 | nniPorts, e := f.resourceMgr.GetNNIFromKVStore(ctx) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2684 | if e == nil && len(nniPorts) > 0 { |
| 2685 | return nniPorts[0], nil |
| 2686 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2687 | return 0, olterrors.NewErrNotFound("nni-port", nil, e).Log() |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | // AddGroup add or update the group |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2691 | func (f *OpenOltFlowMgr) AddGroup(ctx context.Context, group *ofp.OfpGroupEntry) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2692 | logger.Infow("add-group", log.Fields{"group": group}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2693 | if group == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2694 | return olterrors.NewErrInvalidValue(log.Fields{"group": group}, nil) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | groupToOlt := openoltpb2.Group{ |
| 2698 | GroupId: group.Desc.GroupId, |
| 2699 | Command: openoltpb2.Group_SET_MEMBERS, |
| 2700 | Action: f.buildGroupAction(), |
| 2701 | } |
| 2702 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2703 | logger.Debugw("sending-group-to-device", log.Fields{"groupToOlt": groupToOlt}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2704 | _, err := f.deviceHandler.Client.PerformGroupOperation(ctx, &groupToOlt) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2705 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2706 | return olterrors.NewErrAdapter("add-group-operation-failed", log.Fields{"groupToOlt": groupToOlt}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2707 | } |
| 2708 | // group members not created yet. So let's store the group |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2709 | if err := f.resourceMgr.AddFlowGroupToKVStore(ctx, group, true); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2710 | return olterrors.NewErrPersistence("add", "flow-group", group.Desc.GroupId, log.Fields{"group": group}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2711 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2712 | logger.Infow("add-group-operation-performed-on-the-device-successfully ", log.Fields{"groupToOlt": groupToOlt}) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2713 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | //buildGroupAction creates and returns a group action |
| 2717 | func (f *OpenOltFlowMgr) buildGroupAction() *openoltpb2.Action { |
| 2718 | var actionCmd openoltpb2.ActionCmd |
| 2719 | var action openoltpb2.Action |
| 2720 | action.Cmd = &actionCmd |
| 2721 | //pop outer vlan |
| 2722 | action.Cmd.RemoveOuterTag = true |
| 2723 | return &action |
| 2724 | } |
| 2725 | |
| 2726 | // ModifyGroup updates the group |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2727 | func (f *OpenOltFlowMgr) ModifyGroup(ctx context.Context, group *ofp.OfpGroupEntry) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 2728 | logger.Infow("modify-group", log.Fields{"group": group}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2729 | if group == nil || group.Desc == nil { |
Jonathan Hart | c4b1911 | 2020-04-02 11:21:45 -0700 | [diff] [blame] | 2730 | return olterrors.NewErrInvalidValue(log.Fields{"group": group}, nil) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2733 | newGroup := f.buildGroup(group.Desc.GroupId, group.Desc.Buckets) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2734 | //get existing members of the group |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2735 | val, groupExists, err := f.GetFlowGroupFromKVStore(ctx, group.Desc.GroupId, false) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2736 | |
| 2737 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2738 | return olterrors.NewErrNotFound("flow-group-in-kv-store", log.Fields{"groupId": group.Desc.GroupId}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2741 | var current *openoltpb2.Group // represents the group on the device |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2742 | if groupExists { |
| 2743 | // group already exists |
| 2744 | current = f.buildGroup(group.Desc.GroupId, val.Desc.GetBuckets()) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2745 | logger.Debugw("modify-group--group exists", |
| 2746 | log.Fields{ |
| 2747 | "group on the device": val, |
| 2748 | "new": group}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2749 | } else { |
| 2750 | current = f.buildGroup(group.Desc.GroupId, nil) |
| 2751 | } |
| 2752 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2753 | logger.Debugw("modify-group--comparing-current-and-new", |
| 2754 | log.Fields{ |
| 2755 | "group on the device": current, |
| 2756 | "new": newGroup}) |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2757 | // get members to be added |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2758 | membersToBeAdded := f.findDiff(current, newGroup) |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2759 | // get members to be removed |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2760 | membersToBeRemoved := f.findDiff(newGroup, current) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2761 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2762 | logger.Infow("modify-group--differences found", log.Fields{ |
| 2763 | "membersToBeAdded": membersToBeAdded, |
| 2764 | "membersToBeRemoved": membersToBeRemoved, |
| 2765 | "groupId": group.Desc.GroupId}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2766 | |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2767 | groupToOlt := openoltpb2.Group{ |
| 2768 | GroupId: group.Desc.GroupId, |
| 2769 | } |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2770 | var errAdd, errRemoved error |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2771 | if membersToBeAdded != nil && len(membersToBeAdded) > 0 { |
| 2772 | groupToOlt.Command = openoltpb2.Group_ADD_MEMBERS |
| 2773 | groupToOlt.Members = membersToBeAdded |
| 2774 | //execute addMembers |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2775 | errAdd = f.callGroupAddRemove(&groupToOlt) |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2776 | } |
| 2777 | if membersToBeRemoved != nil && len(membersToBeRemoved) > 0 { |
| 2778 | groupToOlt.Command = openoltpb2.Group_REMOVE_MEMBERS |
| 2779 | groupToOlt.Members = membersToBeRemoved |
| 2780 | //execute removeMembers |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2781 | errRemoved = f.callGroupAddRemove(&groupToOlt) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2784 | //save the modified group |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2785 | if errAdd == nil && errRemoved == nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2786 | if err := f.resourceMgr.AddFlowGroupToKVStore(ctx, group, false); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2787 | return olterrors.NewErrPersistence("add", "flow-group", group.Desc.GroupId, log.Fields{"group": group}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2788 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2789 | logger.Infow("modify-group-was-success--storing-group", |
| 2790 | log.Fields{ |
| 2791 | "group": group, |
| 2792 | "existingGroup": current}) |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2793 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2794 | logger.Warnw("one-of-the-group-add/remove-operations-failed--cannot-save-group-modifications", |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2795 | log.Fields{"group": group}) |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2796 | if errAdd != nil { |
| 2797 | return errAdd |
| 2798 | } |
| 2799 | return errRemoved |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2800 | } |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2801 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2804 | //callGroupAddRemove performs add/remove buckets operation for the indicated group |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2805 | func (f *OpenOltFlowMgr) callGroupAddRemove(group *openoltpb2.Group) error { |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2806 | if err := f.performGroupOperation(group); err != nil { |
| 2807 | st, _ := status.FromError(err) |
| 2808 | //ignore already exists error code |
| 2809 | if st.Code() != codes.AlreadyExists { |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2810 | return olterrors.NewErrGroupOp("groupAddRemove", group.GroupId, log.Fields{"status": st}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2811 | } |
| 2812 | } |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2813 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | //findDiff compares group members and finds members which only exists in groups2 |
| 2817 | func (f *OpenOltFlowMgr) findDiff(group1 *openoltpb2.Group, group2 *openoltpb2.Group) []*openoltpb2.GroupMember { |
| 2818 | var members []*openoltpb2.GroupMember |
| 2819 | for _, bucket := range group2.Members { |
| 2820 | if !f.contains(group1.Members, bucket) { |
| 2821 | // bucket does not exist and must be added |
| 2822 | members = append(members, bucket) |
| 2823 | } |
| 2824 | } |
| 2825 | return members |
| 2826 | } |
| 2827 | |
| 2828 | //contains returns true if the members list contains the given member; false otherwise |
| 2829 | func (f *OpenOltFlowMgr) contains(members []*openoltpb2.GroupMember, member *openoltpb2.GroupMember) bool { |
| 2830 | for _, groupMember := range members { |
| 2831 | if groupMember.InterfaceId == member.InterfaceId { |
| 2832 | return true |
| 2833 | } |
| 2834 | } |
| 2835 | return false |
| 2836 | } |
| 2837 | |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 2838 | //performGroupOperation call performGroupOperation operation of openolt proto |
| 2839 | func (f *OpenOltFlowMgr) performGroupOperation(group *openoltpb2.Group) error { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2840 | logger.Debugw("sending-group-to-device", |
| 2841 | log.Fields{ |
| 2842 | "groupToOlt": group, |
| 2843 | "command": group.Command}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2844 | _, err := f.deviceHandler.Client.PerformGroupOperation(context.Background(), group) |
| 2845 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2846 | return olterrors.NewErrAdapter("group-operation-failed", log.Fields{"groupToOlt": group}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2847 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2848 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | //buildGroup build openoltpb2.Group from given group id and bucket list |
| 2852 | func (f *OpenOltFlowMgr) buildGroup(groupID uint32, buckets []*ofp.OfpBucket) *openoltpb2.Group { |
| 2853 | group := openoltpb2.Group{ |
| 2854 | GroupId: groupID} |
| 2855 | // create members of the group |
| 2856 | if buckets != nil { |
| 2857 | for _, ofBucket := range buckets { |
| 2858 | member := f.buildMember(ofBucket) |
| 2859 | if member != nil && !f.contains(group.Members, member) { |
| 2860 | group.Members = append(group.Members, member) |
| 2861 | } |
| 2862 | } |
| 2863 | } |
| 2864 | return &group |
| 2865 | } |
| 2866 | |
| 2867 | //buildMember builds openoltpb2.GroupMember from an OpenFlow bucket |
| 2868 | func (f *OpenOltFlowMgr) buildMember(ofBucket *ofp.OfpBucket) *openoltpb2.GroupMember { |
| 2869 | var outPort uint32 |
| 2870 | outPortFound := false |
| 2871 | for _, ofAction := range ofBucket.Actions { |
| 2872 | if ofAction.Type == ofp.OfpActionType_OFPAT_OUTPUT { |
| 2873 | outPort = ofAction.GetOutput().Port |
| 2874 | outPortFound = true |
| 2875 | } |
| 2876 | } |
| 2877 | |
| 2878 | if !outPortFound { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2879 | logger.Debugw("bucket-skipped-since-no-out-port-found-in-it", log.Fields{"ofBucket": ofBucket}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2880 | return nil |
| 2881 | } |
| 2882 | interfaceID := IntfIDFromUniPortNum(outPort) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2883 | logger.Debugw("got-associated-interface-id-of-the-port", |
| 2884 | log.Fields{ |
| 2885 | "portNumber:": outPort, |
| 2886 | "interfaceId:": interfaceID}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2887 | if groupInfo, ok := f.interfaceToMcastQueueMap[interfaceID]; ok { |
| 2888 | member := openoltpb2.GroupMember{ |
| 2889 | InterfaceId: interfaceID, |
| 2890 | InterfaceType: openoltpb2.GroupMember_PON, |
| 2891 | GemPortId: groupInfo.gemPortID, |
| 2892 | Priority: groupInfo.servicePriority, |
| 2893 | } |
| 2894 | //add member to the group |
| 2895 | return &member |
| 2896 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2897 | logger.Warnf("bucket-skipped-since-interface-2-gem-mapping-cannot-be-found", log.Fields{"ofBucket": ofBucket}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2898 | return nil |
| 2899 | } |
| 2900 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2901 | //sendTPDownloadMsgToChild send payload |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2902 | func (f *OpenOltFlowMgr) sendTPDownloadMsgToChild(intfID uint32, onuID uint32, uniID uint32, uni string, TpID uint32) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2903 | |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 2904 | onuDev, err := f.getOnuDevice(intfID, onuID) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 2905 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2906 | logger.Errorw("couldnt-find-onu-child-device", |
| 2907 | log.Fields{ |
| 2908 | "intf-id": intfID, |
| 2909 | "onu-id": onuID, |
| 2910 | "uni-id": uniID}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 2911 | return err |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2912 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2913 | logger.Debugw("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] | 2914 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2915 | tpPath := f.getTPpath(intfID, uni, TpID) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2916 | tpDownloadMsg := &ic.InterAdapterTechProfileDownloadMessage{UniId: uniID, Path: tpPath} |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2917 | logger.Debugw("sending-load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"tpDownloadMsg": *tpDownloadMsg}) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2918 | sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(context.Background(), |
| 2919 | tpDownloadMsg, |
| 2920 | ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST, |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 2921 | f.deviceHandler.device.Type, |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 2922 | onuDev.deviceType, |
| 2923 | onuDev.deviceID, |
| 2924 | onuDev.proxyDeviceID, "") |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2925 | if sendErr != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2926 | return olterrors.NewErrCommunication("send-techprofile-download-request", |
| 2927 | log.Fields{ |
| 2928 | "from-adapter": f.deviceHandler.device.Type, |
| 2929 | "to-adapter": onuDev.deviceType, |
| 2930 | "onu-id": onuDev.deviceID, |
| 2931 | "proxyDeviceID": onuDev.proxyDeviceID}, sendErr) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2932 | } |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2933 | logger.Infow("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] | 2934 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2935 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2936 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2937 | //UpdateOnuInfo function adds onu info to cache and kvstore |
Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 2938 | func (f *OpenOltFlowMgr) UpdateOnuInfo(ctx context.Context, intfID uint32, onuID uint32, serialNum string) error { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2939 | |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2940 | f.onuGemInfoLock.Lock() |
| 2941 | defer f.onuGemInfoLock.Unlock() |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 2942 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2943 | onu := rsrcMgr.OnuGemInfo{OnuID: onuID, SerialNumber: serialNum, IntfID: intfID} |
| 2944 | f.onuGemInfo[intfID] = append(f.onuGemInfo[intfID], onu) |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 2945 | if err := f.resourceMgr.AddOnuGemInfo(ctx, intfID, onu); err != nil { |
Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 2946 | return err |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2947 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2948 | logger.Infow("updated-onuinfo", |
| 2949 | log.Fields{ |
| 2950 | "intf-id": intfID, |
| 2951 | "onu-id": onuID, |
| 2952 | "serial-num": serialNum, |
| 2953 | "onu": onu, |
| 2954 | "device-id": f.deviceHandler.device.Id}) |
Andrea Campanella | b83b39d | 2020-03-30 11:41:16 +0200 | [diff] [blame] | 2955 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2956 | } |
| 2957 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2958 | //addGemPortToOnuInfoMap function adds GEMport to ONU map |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2959 | 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] | 2960 | |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2961 | f.onuGemInfoLock.Lock() |
| 2962 | defer f.onuGemInfoLock.Unlock() |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 2963 | |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2964 | logger.Infow("adding-gem-to-onu-info-map", |
| 2965 | log.Fields{ |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2966 | "gem-port-id": gemPort, |
| 2967 | "intf-id": intfID, |
| 2968 | "onu-id": onuID, |
| 2969 | "device-id": f.deviceHandler.device.Id, |
| 2970 | "onu-gem": f.onuGemInfo[intfID]}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2971 | onugem := f.onuGemInfo[intfID] |
| 2972 | // update the gem to the local cache as well as to kv strore |
| 2973 | for idx, onu := range onugem { |
| 2974 | if onu.OnuID == onuID { |
| 2975 | // check if gem already exists , else update the cache and kvstore |
| 2976 | for _, gem := range onu.GemPorts { |
| 2977 | if gem == gemPort { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 2978 | logger.Debugw("gem-already-in-cache-no-need-to-update-cache-and-kv-store", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2979 | log.Fields{ |
| 2980 | "gem": gemPort, |
| 2981 | "device-id": f.deviceHandler.device.Id}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2982 | return |
| 2983 | } |
| 2984 | } |
| 2985 | onugem[idx].GemPorts = append(onugem[idx].GemPorts, gemPort) |
| 2986 | f.onuGemInfo[intfID] = onugem |
| 2987 | } |
| 2988 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2989 | err := f.resourceMgr.AddGemToOnuGemInfo(ctx, intfID, onuID, gemPort) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2990 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2991 | logger.Errorw("failed-to-add-gem-to-onu", |
| 2992 | log.Fields{ |
| 2993 | "intf-id": intfID, |
| 2994 | "onu-id": onuID, |
| 2995 | "gemPort": gemPort, |
| 2996 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2997 | return |
| 2998 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2999 | logger.Infow("gem-added-to-onu-info-map", |
| 3000 | log.Fields{ |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3001 | "gem-port-id": gemPort, |
| 3002 | "intf-id": intfID, |
| 3003 | "onu-id": onuID, |
| 3004 | "device-id": f.deviceHandler.device.Id, |
| 3005 | "onu-gem": f.onuGemInfo[intfID]}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | // This function Lookup maps by serialNumber or (intfId, gemPort) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3009 | |
| 3010 | //getOnuIDfromGemPortMap Returns OnuID,nil if found or set 0,error if no onuId is found for serialNumber or (intfId, gemPort) |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 3011 | func (f *OpenOltFlowMgr) getOnuIDfromGemPortMap(intfID uint32, gemPortID uint32) (uint32, error) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3012 | |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3013 | f.onuGemInfoLock.RLock() |
| 3014 | defer f.onuGemInfoLock.RUnlock() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3015 | |
Matteo Scandolo | a4e4691 | 2020-08-05 15:23:45 -0700 | [diff] [blame^] | 3016 | logger.Debugw("getting-onu-id-from-gem-port-and-pon-port", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3017 | log.Fields{ |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 3018 | "device-id": f.deviceHandler.device.Id, |
| 3019 | "onu-geminfo": f.onuGemInfo[intfID], |
| 3020 | "intf-id": intfID, |
| 3021 | "gemport-id": gemPortID}) |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 3022 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3023 | // get onuid from the onugem info cache |
| 3024 | onugem := f.onuGemInfo[intfID] |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 3025 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3026 | for _, onu := range onugem { |
| 3027 | for _, gem := range onu.GemPorts { |
| 3028 | if gem == gemPortID { |
| 3029 | return onu.OnuID, nil |
| 3030 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3031 | } |
| 3032 | } |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3033 | logger.Errorw("onu-id-from-gem-port-not-found", log.Fields{ |
| 3034 | "gem-port-id": gemPortID, |
| 3035 | "interface-id": intfID, |
| 3036 | "all-gems-on-port": onu, |
| 3037 | }) |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3038 | return uint32(0), olterrors.NewErrNotFound("onu-id", log.Fields{ |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 3039 | "interface-id": intfID, |
| 3040 | "gem-port-id": gemPortID}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3041 | nil) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3042 | } |
| 3043 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3044 | //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] | 3045 | func (f *OpenOltFlowMgr) GetLogicalPortFromPacketIn(ctx context.Context, packetIn *openoltpb2.PacketIndication) (uint32, error) { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3046 | var logicalPortNum uint32 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3047 | var onuID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3048 | var err error |
| 3049 | |
| 3050 | if packetIn.IntfType == "pon" { |
| 3051 | // packet indication does not have serial number , so sending as nil |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 3052 | if onuID, err = f.getOnuIDfromGemPortMap(packetIn.IntfId, packetIn.GemportId); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3053 | // Called method is returning error with all data populated; just return the same |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3054 | return logicalPortNum, err |
| 3055 | } |
| 3056 | if packetIn.PortNo != 0 { |
| 3057 | logicalPortNum = packetIn.PortNo |
| 3058 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3059 | uniID := uint32(0) // FIXME - multi-uni support |
| 3060 | logicalPortNum = MkUniPortNum(packetIn.IntfId, onuID, uniID) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3061 | } |
| 3062 | // Store the gem port through which the packet_in came. Use the same gem port for packet_out |
Esin Karaman | 04166c8 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3063 | f.UpdateGemPortForPktIn(ctx, packetIn.IntfId, onuID, logicalPortNum, packetIn.GemportId, packetIn.Pkt) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3064 | } else if packetIn.IntfType == "nni" { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3065 | logicalPortNum = IntfIDToPortNo(packetIn.IntfId, voltha.Port_ETHERNET_NNI) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3066 | } |
Matteo Scandolo | a4e4691 | 2020-08-05 15:23:45 -0700 | [diff] [blame^] | 3067 | if logger.V(log.InfoLevel) { |
| 3068 | logger.Infow("retrieved-logicalport-from-packet-in", |
| 3069 | log.Fields{ |
| 3070 | "logical-port-num": logicalPortNum, |
| 3071 | "intf-type": packetIn.IntfType, |
| 3072 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 3073 | }) |
| 3074 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3075 | return logicalPortNum, nil |
| 3076 | } |
| 3077 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3078 | //GetPacketOutGemPortID returns gemPortId |
Esin Karaman | 04166c8 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3079 | 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] | 3080 | var gemPortID uint32 |
Esin Karaman | 04166c8 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3081 | |
| 3082 | ctag, priority, err := getCTagFromPacket(ctx, packet) |
| 3083 | if err != nil { |
| 3084 | return 0, err |
| 3085 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3086 | |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3087 | f.onuGemInfoLock.RLock() |
| 3088 | defer f.onuGemInfoLock.RUnlock() |
Esin Karaman | 04166c8 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3089 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: portNum, VlanID: ctag, Priority: priority} |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3090 | var ok bool |
| 3091 | gemPortID, ok = f.packetInGemPort[pktInkey] |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3092 | if ok { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3093 | logger.Debugw("found-gemport-for-pktin-key", |
| 3094 | log.Fields{ |
| 3095 | "pktinkey": pktInkey, |
| 3096 | "gem": gemPortID}) |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3097 | |
| 3098 | return gemPortID, nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3099 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3100 | //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 | 04166c8 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3101 | gemPortID, err = f.resourceMgr.GetGemPortFromOnuPktIn(ctx, pktInkey) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3102 | if err == nil { |
| 3103 | if gemPortID != 0 { |
| 3104 | f.packetInGemPort[pktInkey] = gemPortID |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3105 | logger.Infow("found-gem-port-from-kv-store-and-updating-cache-with-gemport", |
| 3106 | log.Fields{ |
| 3107 | "pktinkey": pktInkey, |
| 3108 | "gem": gemPortID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3109 | return gemPortID, nil |
| 3110 | } |
| 3111 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3112 | return uint32(0), olterrors.NewErrNotFound("gem-port", |
| 3113 | log.Fields{ |
| 3114 | "pktinkey": pktInkey, |
| 3115 | "gem": gemPortID}, err) |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3116 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3117 | } |
| 3118 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3119 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3120 | func installFlowOnAllGemports(ctx context.Context, |
| 3121 | f1 func(ctx context.Context, intfId uint32, onuId uint32, uniId uint32, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 3122 | portNo uint32, classifier map[string]interface{}, action map[string]interface{}, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3123 | logicalFlow *ofp.OfpFlowStats, allocId uint32, gemPortId uint32, tpID uint32) error, |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3124 | f2 func(ctx context.Context, intfId uint32, onuId uint32, uniId uint32, portNo uint32, |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 3125 | classifier map[string]interface{}, action map[string]interface{}, |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3126 | logicalFlow *ofp.OfpFlowStats, allocId uint32, gemPortId uint32, vlanId uint32, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3127 | tpID uint32) error, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 3128 | args map[string]uint32, |
| 3129 | classifier map[string]interface{}, action map[string]interface{}, |
| 3130 | logicalFlow *ofp.OfpFlowStats, |
| 3131 | gemPorts []uint32, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3132 | TpInst interface{}, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 3133 | FlowType string, |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3134 | direction string, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3135 | tpID uint32, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3136 | vlanID ...uint32) { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3137 | logger.Debugw("installing-flow-on-all-gem-ports", |
| 3138 | log.Fields{ |
| 3139 | "FlowType": FlowType, |
| 3140 | "gemPorts": gemPorts, |
| 3141 | "vlan": vlanID}) |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 3142 | |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3143 | // The bit mapping for a gemport is expressed in tech-profile as a binary string. For example, 0b00000001 |
| 3144 | // We need to trim prefix "0b", before further processing |
| 3145 | // Once the "0b" prefix is trimmed, we iterate each character in the string to identify which index |
| 3146 | // in the string is set to binary bit 1 (expressed as char '1' in the binary string). |
| 3147 | |
| 3148 | // If a particular character in the string is set to '1', identify the index of this character from |
| 3149 | // the LSB position which marks the PCP bit consumed by the given gem port. |
| 3150 | // This PCP bit now becomes a classifier in the flow. |
| 3151 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3152 | switch TpInst := TpInst.(type) { |
| 3153 | case *tp.TechProfile: |
| 3154 | attributes := TpInst.DownstreamGemPortAttributeList |
| 3155 | if direction == Upstream { |
| 3156 | attributes = TpInst.UpstreamGemPortAttributeList |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3157 | } |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3158 | |
| 3159 | for _, gemPortAttribute := range attributes { |
| 3160 | if direction == Downstream && strings.ToUpper(gemPortAttribute.IsMulticast) == "TRUE" { |
| 3161 | continue |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3162 | } |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3163 | gemPortID := gemPortAttribute.GemportID |
| 3164 | if allPbitsMarked(gemPortAttribute.PbitMap) { |
| 3165 | classifier[VlanPcp] = uint32(VlanPCPMask) |
| 3166 | if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow { |
| 3167 | f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID) |
| 3168 | } else if FlowType == EapolFlow { |
| 3169 | f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID) |
| 3170 | } |
| 3171 | } else { |
| 3172 | for pos, pbitSet := range strings.TrimPrefix(gemPortAttribute.PbitMap, BinaryStringPrefix) { |
| 3173 | if pbitSet == BinaryBit1 { |
| 3174 | classifier[VlanPcp] = uint32(len(strings.TrimPrefix(gemPortAttribute.PbitMap, BinaryStringPrefix))) - 1 - uint32(pos) |
| 3175 | if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow { |
| 3176 | f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID) |
| 3177 | } else if FlowType == EapolFlow { |
| 3178 | f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID) |
| 3179 | } |
| 3180 | } |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | case *tp.EponProfile: |
| 3185 | if direction == Upstream { |
| 3186 | attributes := TpInst.UpstreamQueueAttributeList |
| 3187 | for _, queueAttribute := range attributes { |
| 3188 | gemPortID := queueAttribute.GemportID |
| 3189 | if allPbitsMarked(queueAttribute.PbitMap) { |
| 3190 | classifier[VlanPcp] = uint32(VlanPCPMask) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3191 | if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow { |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3192 | f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3193 | } else if FlowType == EapolFlow { |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3194 | f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3195 | } |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3196 | } else { |
| 3197 | for pos, pbitSet := range strings.TrimPrefix(queueAttribute.PbitMap, BinaryStringPrefix) { |
| 3198 | if pbitSet == BinaryBit1 { |
| 3199 | classifier[VlanPcp] = uint32(len(strings.TrimPrefix(queueAttribute.PbitMap, BinaryStringPrefix))) - 1 - uint32(pos) |
| 3200 | if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow { |
| 3201 | f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID) |
| 3202 | } else if FlowType == EapolFlow { |
| 3203 | f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID) |
| 3204 | } |
| 3205 | } |
| 3206 | } |
| 3207 | } |
| 3208 | } |
| 3209 | } else { |
| 3210 | attributes := TpInst.DownstreamQueueAttributeList |
| 3211 | for _, queueAttribute := range attributes { |
| 3212 | gemPortID := queueAttribute.GemportID |
| 3213 | if allPbitsMarked(queueAttribute.PbitMap) { |
| 3214 | classifier[VlanPcp] = uint32(VlanPCPMask) |
| 3215 | if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow { |
| 3216 | f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID) |
| 3217 | } else if FlowType == EapolFlow { |
| 3218 | f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID) |
| 3219 | } |
| 3220 | } else { |
| 3221 | for pos, pbitSet := range strings.TrimPrefix(queueAttribute.PbitMap, BinaryStringPrefix) { |
| 3222 | if pbitSet == BinaryBit1 { |
| 3223 | classifier[VlanPcp] = uint32(len(strings.TrimPrefix(queueAttribute.PbitMap, BinaryStringPrefix))) - 1 - uint32(pos) |
| 3224 | if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow { |
| 3225 | f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID) |
| 3226 | } else if FlowType == EapolFlow { |
| 3227 | f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID) |
| 3228 | } |
| 3229 | } |
| 3230 | } |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 3231 | } |
| 3232 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 3233 | } |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3234 | default: |
| 3235 | logger.Errorw("unknown-tech", log.Fields{"tpInst": TpInst}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 3236 | } |
| 3237 | } |
| 3238 | |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3239 | func allPbitsMarked(pbitMap string) bool { |
| 3240 | for pos, pBit := range pbitMap { |
| 3241 | if pos >= 2 && pBit != BinaryBit1 { |
| 3242 | return false |
| 3243 | } |
| 3244 | } |
| 3245 | return true |
| 3246 | } |
| 3247 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3248 | func (f *OpenOltFlowMgr) addDHCPTrapFlowOnNNI(ctx context.Context, logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) error { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3249 | logger.Debug("adding-trap-dhcp-of-nni-flow") |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3250 | action := make(map[string]interface{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3251 | classifier[PacketTagType] = DoubleTag |
| 3252 | action[TrapToHost] = true |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3253 | /* We manage flowId resource pool on per PON port basis. |
| 3254 | Since this situation is tricky, as a hack, we pass the NNI port |
| 3255 | index (network_intf_id) as PON port Index for the flowId resource |
| 3256 | pool. Also, there is no ONU Id available for trapping DHCP packets |
| 3257 | on NNI port, use onu_id as -1 (invalid) |
| 3258 | ****************** CAVEAT ******************* |
| 3259 | This logic works if the NNI Port Id falls within the same valid |
| 3260 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 3261 | we need to have a re-look at this. |
| 3262 | ********************************************* |
| 3263 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3264 | onuID := -1 |
| 3265 | uniID := -1 |
| 3266 | gemPortID := -1 |
| 3267 | allocID := -1 |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3268 | networkInterfaceID, err := getNniIntfID(classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3269 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3270 | return olterrors.NewErrNotFound("nni-intreface-id", |
| 3271 | log.Fields{ |
| 3272 | "classifier": classifier, |
| 3273 | "action": action}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3274 | err) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3275 | } |
| 3276 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3277 | flowStoreCookie := getFlowStoreCookie(classifier, uint32(0)) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3278 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3279 | logger.Info("flow-exists-not-re-adding") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3280 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3281 | } |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3282 | flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0, 0) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3283 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3284 | return olterrors.NewErrNotFound("dhcp-trap-nni-flow-id", |
| 3285 | log.Fields{ |
| 3286 | "interface-id": networkInterfaceID, |
| 3287 | "onu-id": onuID, |
| 3288 | "uni-id": uniID, |
| 3289 | "gem-port-id": gemPortID, |
| 3290 | "cookie": flowStoreCookie}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3291 | err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3292 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3293 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 3294 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3295 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3296 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3297 | logger.Debugw("created-classifier-proto", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3298 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3299 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3300 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3301 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3302 | logger.Debugw("created-action-proto", log.Fields{"action": *actionProto}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3303 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 3304 | OnuId: int32(onuID), // OnuId not required |
| 3305 | UniId: int32(uniID), // UniId not used |
| 3306 | FlowId: flowID, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3307 | FlowType: Downstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 3308 | AllocId: int32(allocID), // AllocId not used |
| 3309 | NetworkIntfId: int32(networkInterfaceID), |
| 3310 | GemportId: int32(gemPortID), // GemportId not used |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3311 | Classifier: classifierProto, |
| 3312 | Action: actionProto, |
| 3313 | Priority: int32(logicalFlow.Priority), |
| 3314 | Cookie: logicalFlow.Cookie, |
| 3315 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3316 | if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3317 | return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": downstreamflow}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3318 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3319 | logger.Info("dhcp-trap-on-nni-flow-added–to-device-successfully") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3320 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &downstreamflow, flowStoreCookie, "", flowID, logicalFlow.Id) |
| 3321 | if err := f.updateFlowInfoToKVStore(ctx, int32(networkInterfaceID), |
| 3322 | int32(onuID), |
| 3323 | int32(uniID), |
| 3324 | flowID, flowsToKVStore); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3325 | return olterrors.NewErrPersistence("update", "flow", flowID, log.Fields{"flow": downstreamflow}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3326 | } |
| 3327 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 3328 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3329 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3330 | //getPacketTypeFromClassifiers finds and returns packet type of a flow by checking flow classifiers |
| 3331 | func getPacketTypeFromClassifiers(classifierInfo map[string]interface{}) string { |
| 3332 | var packetType string |
| 3333 | ovid, ivid := false, false |
| 3334 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
| 3335 | vid := vlanID & VlanvIDMask |
| 3336 | if vid != ReservedVlan { |
| 3337 | ovid = true |
| 3338 | } |
| 3339 | } |
| 3340 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 3341 | vid := uint32(metadata) |
| 3342 | if vid != ReservedVlan { |
| 3343 | ivid = true |
| 3344 | } |
| 3345 | } |
| 3346 | if ovid && ivid { |
| 3347 | packetType = DoubleTag |
| 3348 | } else if !ovid && !ivid { |
| 3349 | packetType = Untagged |
| 3350 | } else { |
| 3351 | packetType = SingleTag |
| 3352 | } |
| 3353 | return packetType |
| 3354 | } |
| 3355 | |
| 3356 | //addIgmpTrapFlowOnNNI adds a trap-to-host flow on NNI |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3357 | func (f *OpenOltFlowMgr) addIgmpTrapFlowOnNNI(ctx context.Context, logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) error { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3358 | logger.Infow("adding-igmp-trap-of-nni-flow", log.Fields{"classifier-info": classifier}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3359 | action := make(map[string]interface{}) |
| 3360 | classifier[PacketTagType] = getPacketTypeFromClassifiers(classifier) |
| 3361 | action[TrapToHost] = true |
| 3362 | /* We manage flowId resource pool on per PON port basis. |
| 3363 | Since this situation is tricky, as a hack, we pass the NNI port |
| 3364 | index (network_intf_id) as PON port Index for the flowId resource |
| 3365 | pool. Also, there is no ONU Id available for trapping packets |
| 3366 | on NNI port, use onu_id as -1 (invalid) |
| 3367 | ****************** CAVEAT ******************* |
| 3368 | This logic works if the NNI Port Id falls within the same valid |
| 3369 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 3370 | we need to have a re-look at this. |
| 3371 | ********************************************* |
| 3372 | */ |
| 3373 | onuID := -1 |
| 3374 | uniID := -1 |
| 3375 | gemPortID := -1 |
| 3376 | allocID := -1 |
| 3377 | networkInterfaceID, err := getNniIntfID(classifier, action) |
| 3378 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3379 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3380 | "classifier": classifier, |
| 3381 | "action": action}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3382 | err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3383 | } |
| 3384 | flowStoreCookie := getFlowStoreCookie(classifier, uint32(0)) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3385 | if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3386 | logger.Info("igmp-flow-exists-not-re-adding") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3387 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3388 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3389 | flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0, 0) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3390 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3391 | return olterrors.NewErrNotFound("igmp-flow-id", |
| 3392 | log.Fields{ |
| 3393 | "interface-id": networkInterfaceID, |
| 3394 | "onu-id": onuID, |
| 3395 | "uni-id": uniID, |
| 3396 | "gem-port-id": gemPortID, |
| 3397 | "cookie": flowStoreCookie}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3398 | err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3399 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3400 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 3401 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3402 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3403 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3404 | logger.Debugw("created-classifier-proto-for-the-igmp-flow", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3405 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3406 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3407 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3408 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3409 | logger.Debugw("created-action-proto-for-the-igmp-flow", log.Fields{"action": *actionProto}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3410 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 3411 | OnuId: int32(onuID), // OnuId not required |
| 3412 | UniId: int32(uniID), // UniId not used |
| 3413 | FlowId: flowID, |
| 3414 | FlowType: Downstream, |
| 3415 | AllocId: int32(allocID), // AllocId not used |
| 3416 | NetworkIntfId: int32(networkInterfaceID), |
| 3417 | GemportId: int32(gemPortID), // GemportId not used |
| 3418 | Classifier: classifierProto, |
| 3419 | Action: actionProto, |
| 3420 | Priority: int32(logicalFlow.Priority), |
| 3421 | Cookie: logicalFlow.Cookie, |
| 3422 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3423 | if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3424 | return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": downstreamflow}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3425 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3426 | logger.Info("igmp-trap-on-nni-flow-added-to-device-successfully") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3427 | flowsToKVStore := f.getUpdatedFlowInfo(ctx, &downstreamflow, flowStoreCookie, "", flowID, logicalFlow.Id) |
| 3428 | if err := f.updateFlowInfoToKVStore(ctx, int32(networkInterfaceID), |
| 3429 | int32(onuID), |
| 3430 | int32(uniID), |
| 3431 | flowID, flowsToKVStore); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3432 | return olterrors.NewErrPersistence("update", "flow", flowID, log.Fields{"flow": downstreamflow}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3433 | } |
| 3434 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3437 | func verifyMeterIDAndGetDirection(MeterID uint32, Dir tp_pb.Direction) (string, error) { |
| 3438 | if MeterID == 0 { // This should never happen |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 3439 | return "", olterrors.NewErrInvalidValue(log.Fields{"meter-id": MeterID}, nil).Log() |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3440 | } |
| 3441 | if Dir == tp_pb.Direction_UPSTREAM { |
| 3442 | return "upstream", nil |
| 3443 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 3444 | return "downstream", nil |
| 3445 | } |
| 3446 | return "", nil |
| 3447 | } |
| 3448 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3449 | 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] | 3450 | actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpInst interface{}, gemPorts []uint32, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3451 | tpID uint32, uni string) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3452 | var gemPort uint32 |
| 3453 | intfID := args[IntfID] |
| 3454 | onuID := args[OnuID] |
| 3455 | uniID := args[UniID] |
| 3456 | portNo := args[PortNo] |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3457 | allocID := args[AllocID] |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3458 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 3459 | if ipProto.(uint32) == IPProtoDhcp { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 3460 | logger.Infow("adding-dhcp-flow", log.Fields{ |
| 3461 | "tp-id": tpID, |
| 3462 | "alloc-id": allocID, |
| 3463 | "intf-id": intfID, |
| 3464 | "onu-id": onuID, |
| 3465 | "uni-id": uniID, |
| 3466 | }) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3467 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 3468 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
| 3469 | tp_pb.Direction_UPSTREAM, |
| 3470 | pcp.(uint32)) |
| 3471 | //Adding DHCP upstream flow |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 3472 | |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3473 | f.addDHCPTrapFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3474 | } else { |
| 3475 | //Adding DHCP upstream flow to all gemports |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3476 | installFlowOnAllGemports(ctx, f.addDHCPTrapFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, DhcpFlow, Upstream, tpID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3477 | } |
| 3478 | |
Girish Gowdra | 3262521 | 2020-04-29 11:26:35 -0700 | [diff] [blame] | 3479 | } else if ipProto.(uint32) == IgmpProto { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3480 | logger.Infow("adding-us-igmp-flow", |
| 3481 | log.Fields{ |
| 3482 | "intf-id": intfID, |
| 3483 | "onu-id": onuID, |
| 3484 | "uni-id": uniID, |
| 3485 | "classifier-info:": classifierInfo}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3486 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 3487 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
| 3488 | tp_pb.Direction_UPSTREAM, |
| 3489 | pcp.(uint32)) |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3490 | f.addIGMPTrapFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3491 | } else { |
| 3492 | //Adding IGMP upstream flow to all gem ports |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3493 | installFlowOnAllGemports(ctx, f.addIGMPTrapFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, IgmpFlow, Upstream, tpID) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 3494 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3495 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3496 | logger.Errorw("invalid-classifier-to-handle", log.Fields{"classifier": classifierInfo, "action": actionInfo}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3497 | return |
| 3498 | } |
| 3499 | } else if ethType, ok := classifierInfo[EthType]; ok { |
| 3500 | if ethType.(uint32) == EapEthType { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 3501 | logger.Infow("adding-eapol-flow", log.Fields{ |
| 3502 | "intf-id": intfID, |
| 3503 | "onu-id": onuID, |
| 3504 | "uni-id": uniID, |
| 3505 | }) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3506 | var vlanID uint32 |
| 3507 | if val, ok := classifierInfo[VlanVid]; ok { |
| 3508 | vlanID = (val.(uint32)) & VlanvIDMask |
| 3509 | } else { |
| 3510 | vlanID = DefaultMgmtVlan |
| 3511 | } |
| 3512 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 3513 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
| 3514 | tp_pb.Direction_UPSTREAM, |
| 3515 | pcp.(uint32)) |
| 3516 | |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3517 | f.addEAPOLFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, vlanID, tpID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3518 | } else { |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3519 | installFlowOnAllGemports(ctx, nil, f.addEAPOLFlow, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, EapolFlow, Upstream, tpID, vlanID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3520 | } |
| 3521 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3522 | } else if _, ok := actionInfo[PushVlan]; ok { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 3523 | logger.Infow("adding-upstream-data-rule", log.Fields{ |
| 3524 | "intf-id": intfID, |
| 3525 | "onu-id": onuID, |
| 3526 | "uni-id": uniID, |
| 3527 | }) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3528 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 3529 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
| 3530 | tp_pb.Direction_UPSTREAM, |
| 3531 | pcp.(uint32)) |
| 3532 | //Adding HSIA upstream flow |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3533 | f.addUpstreamDataFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3534 | } else { |
| 3535 | //Adding HSIA upstream flow to all gemports |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3536 | installFlowOnAllGemports(ctx, f.addUpstreamDataFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, HsiaFlow, Upstream, tpID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3537 | } |
| 3538 | } else if _, ok := actionInfo[PopVlan]; ok { |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 3539 | logger.Infow("adding-downstream-data-rule", log.Fields{ |
| 3540 | "intf-id": intfID, |
| 3541 | "onu-id": onuID, |
| 3542 | "uni-id": uniID, |
| 3543 | }) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3544 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 3545 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
aishwaryarana01 | d9f985f | 2019-09-03 15:41:40 -0500 | [diff] [blame] | 3546 | tp_pb.Direction_DOWNSTREAM, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3547 | pcp.(uint32)) |
| 3548 | //Adding HSIA downstream flow |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3549 | f.addDownstreamDataFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3550 | } else { |
| 3551 | //Adding HSIA downstream flow to all gemports |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3552 | installFlowOnAllGemports(ctx, f.addDownstreamDataFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, HsiaFlow, Downstream, tpID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3553 | } |
| 3554 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3555 | logger.Errorw("invalid-flow-type-to-handle", |
| 3556 | log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 3557 | "intf-id": intfID, |
| 3558 | "onu-id": onuID, |
| 3559 | "uni-id": uniID, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3560 | "classifier": classifierInfo, |
| 3561 | "action": actionInfo, |
| 3562 | "flow": flow}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3563 | return |
| 3564 | } |
| 3565 | // Send Techprofile download event to child device in go routine as it takes time |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 3566 | go f.sendTPDownloadMsgToChild(intfID, onuID, uniID, uni, tpID) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3567 | } |
| 3568 | |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 3569 | func (f *OpenOltFlowMgr) isGemPortUsedByAnotherFlow(gemPK gemPortKey) (bool, error) { |
| 3570 | if f.perGemPortLock.TryLock(gemPK) { |
| 3571 | flowIDList := f.flowsUsedByGemPort[gemPK] |
| 3572 | f.perGemPortLock.Unlock(gemPK) |
| 3573 | if len(flowIDList) > 1 { |
| 3574 | return true, nil |
| 3575 | } |
| 3576 | return false, nil |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3577 | } |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 3578 | logger.Error("failed-to-acquire-per-gem-port-lock", |
| 3579 | log.Fields{ |
| 3580 | "device-id": f.deviceHandler.device.Id, |
| 3581 | "key": gemPK, |
| 3582 | }) |
| 3583 | return false, olterrors.NewErrAdapter("failed-to-acquire-per-gem-port-lock", log.Fields{ |
| 3584 | "device-id": f.deviceHandler.device.Id, |
| 3585 | "key": gemPK, |
| 3586 | }, nil) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3587 | } |
| 3588 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3589 | func (f *OpenOltFlowMgr) isTechProfileUsedByAnotherGem(ctx context.Context, ponIntf uint32, onuID uint32, uniID uint32, tpID uint32, tpInst *tp.TechProfile, gemPortID uint32) (bool, uint32) { |
| 3590 | currentGemPorts := f.resourceMgr.GetCurrentGEMPortIDsForOnu(ctx, ponIntf, onuID, uniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3591 | tpGemPorts := tpInst.UpstreamGemPortAttributeList |
| 3592 | for _, currentGemPort := range currentGemPorts { |
| 3593 | for _, tpGemPort := range tpGemPorts { |
| 3594 | if (currentGemPort == tpGemPort.GemportID) && (currentGemPort != gemPortID) { |
| 3595 | return true, currentGemPort |
| 3596 | } |
| 3597 | } |
| 3598 | } |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3599 | if tpInst.InstanceCtrl.Onu == "single-instance" { |
| 3600 | // The TP information for the given TP ID, PON ID, ONU ID, UNI ID should be removed. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3601 | f.resourceMgr.RemoveTechProfileIDForOnu(ctx, ponIntf, uint32(onuID), uint32(uniID), tpID) |
| 3602 | f.DeleteTechProfileInstance(ctx, ponIntf, uint32(onuID), uint32(uniID), "", tpID) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3603 | |
| 3604 | // Although we cleaned up TP Instance for the given (PON ID, ONU ID, UNI ID), the TP might |
| 3605 | // still be used on other uni ports. |
| 3606 | // So, we need to check and make sure that no other gem port is referring to the given TP ID |
| 3607 | // on any other uni port. |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 3608 | tpInstances := f.techprofile[ponIntf].FindAllTpInstances(ctx, tpID, ponIntf, onuID).([]tp.TechProfile) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3609 | logger.Debugw("got-single-instance-tp-instances", log.Fields{"tp-instances": tpInstances}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3610 | for i := 0; i < len(tpInstances); i++ { |
| 3611 | tpI := tpInstances[i] |
| 3612 | tpGemPorts := tpI.UpstreamGemPortAttributeList |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 3613 | for _, tpGemPort := range tpGemPorts { |
| 3614 | if tpGemPort.GemportID != gemPortID { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3615 | logger.Debugw("single-instance-tp-is-in-use-by-gem", log.Fields{"gemPort": tpGemPort.GemportID}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 3616 | return true, tpGemPort.GemportID |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 3617 | } |
| 3618 | } |
| 3619 | } |
| 3620 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3621 | logger.Debug("tech-profile-is-not-in-use-by-any-gem") |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3622 | return false, 0 |
| 3623 | } |
| 3624 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3625 | func formulateClassifierInfoFromFlow(classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3626 | for _, field := range flows.GetOfbFields(flow) { |
| 3627 | if field.Type == flows.ETH_TYPE { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3628 | classifierInfo[EthType] = field.GetEthType() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3629 | logger.Debug("field-type-eth-type", log.Fields{"classifierInfo[ETH_TYPE]": classifierInfo[EthType].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3630 | } else if field.Type == flows.ETH_DST { |
| 3631 | classifierInfo[EthDst] = field.GetEthDst() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3632 | logger.Debug("field-type-eth-type", log.Fields{"classifierInfo[ETH_DST]": classifierInfo[EthDst].([]uint8)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3633 | } else if field.Type == flows.IP_PROTO { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3634 | classifierInfo[IPProto] = field.GetIpProto() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3635 | logger.Debug("field-type-ip-proto", log.Fields{"classifierInfo[IP_PROTO]": classifierInfo[IPProto].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3636 | } else if field.Type == flows.IN_PORT { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3637 | classifierInfo[InPort] = field.GetPort() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3638 | logger.Debug("field-type-in-port", log.Fields{"classifierInfo[IN_PORT]": classifierInfo[InPort].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3639 | } else if field.Type == flows.VLAN_VID { |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 3640 | classifierInfo[VlanVid] = field.GetVlanVid() & 0xfff |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3641 | logger.Debug("field-type-vlan-vid", log.Fields{"classifierInfo[VLAN_VID]": classifierInfo[VlanVid].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3642 | } else if field.Type == flows.VLAN_PCP { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3643 | classifierInfo[VlanPcp] = field.GetVlanPcp() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3644 | logger.Debug("field-type-vlan-pcp", log.Fields{"classifierInfo[VLAN_PCP]": classifierInfo[VlanPcp].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3645 | } else if field.Type == flows.UDP_DST { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3646 | classifierInfo[UDPDst] = field.GetUdpDst() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3647 | logger.Debug("field-type-udp-dst", log.Fields{"classifierInfo[UDP_DST]": classifierInfo[UDPDst].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3648 | } else if field.Type == flows.UDP_SRC { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3649 | classifierInfo[UDPSrc] = field.GetUdpSrc() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3650 | logger.Debug("field-type-udp-src", log.Fields{"classifierInfo[UDP_SRC]": classifierInfo[UDPSrc].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3651 | } else if field.Type == flows.IPV4_DST { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3652 | classifierInfo[Ipv4Dst] = field.GetIpv4Dst() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3653 | logger.Debug("field-type-ipv4-dst", log.Fields{"classifierInfo[IPV4_DST]": classifierInfo[Ipv4Dst].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3654 | } else if field.Type == flows.IPV4_SRC { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3655 | classifierInfo[Ipv4Src] = field.GetIpv4Src() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3656 | logger.Debug("field-type-ipv4-src", log.Fields{"classifierInfo[IPV4_SRC]": classifierInfo[Ipv4Src].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3657 | } else if field.Type == flows.METADATA { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3658 | classifierInfo[Metadata] = field.GetTableMetadata() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3659 | logger.Debug("field-type-metadata", log.Fields{"classifierInfo[Metadata]": classifierInfo[Metadata].(uint64)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3660 | } else if field.Type == flows.TUNNEL_ID { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3661 | classifierInfo[TunnelID] = field.GetTunnelId() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3662 | logger.Debug("field-type-tunnelId", log.Fields{"classifierInfo[TUNNEL_ID]": classifierInfo[TunnelID].(uint64)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3663 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3664 | logger.Errorw("un-supported-field-type", log.Fields{"type": field.Type}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3665 | return |
| 3666 | } |
| 3667 | } |
| 3668 | } |
| 3669 | |
| 3670 | func formulateActionInfoFromFlow(actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3671 | for _, action := range flows.GetActions(flow) { |
| 3672 | if action.Type == flows.OUTPUT { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3673 | if out := action.GetOutput(); out != nil { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3674 | actionInfo[Output] = out.GetPort() |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3675 | logger.Debugw("action-type-output", log.Fields{"out-port": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3676 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3677 | return olterrors.NewErrInvalidValue(log.Fields{"output-port": nil}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3678 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3679 | } else if action.Type == flows.POP_VLAN { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3680 | actionInfo[PopVlan] = true |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3681 | logger.Debugw("action-type-pop-vlan", log.Fields{"in_port": classifierInfo[InPort].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3682 | } else if action.Type == flows.PUSH_VLAN { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3683 | if out := action.GetPush(); out != nil { |
| 3684 | if tpid := out.GetEthertype(); tpid != 0x8100 { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3685 | logger.Errorw("invalid ethertype in push action", log.Fields{"ethertype": actionInfo[PushVlan].(int32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3686 | } else { |
| 3687 | actionInfo[PushVlan] = true |
| 3688 | actionInfo[TPID] = tpid |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3689 | logger.Debugw("action-type-push-vlan", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3690 | log.Fields{ |
| 3691 | "push-tpid": actionInfo[TPID].(uint32), |
| 3692 | "in-port": classifierInfo[InPort].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3693 | } |
| 3694 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3695 | } else if action.Type == flows.SET_FIELD { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3696 | if out := action.GetSetField(); out != nil { |
| 3697 | if field := out.GetField(); field != nil { |
| 3698 | if ofClass := field.GetOxmClass(); ofClass != ofp.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3699 | return olterrors.NewErrInvalidValue(log.Fields{"openflow-class": ofClass}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3700 | } |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3701 | /*logger.Debugw("action-type-set-field",log.Fields{"field": field, "in_port": classifierInfo[IN_PORT].(uint32)})*/ |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3702 | formulateSetFieldActionInfoFromFlow(field, actionInfo) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3703 | } |
| 3704 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3705 | } else if action.Type == flows.GROUP { |
| 3706 | formulateGroupActionInfoFromFlow(action, actionInfo) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3707 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3708 | return olterrors.NewErrInvalidValue(log.Fields{"action-type": action.Type}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | return nil |
| 3712 | } |
| 3713 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3714 | func formulateSetFieldActionInfoFromFlow(field *ofp.OfpOxmField, actionInfo map[string]interface{}) { |
| 3715 | if ofbField := field.GetOfbField(); ofbField != nil { |
Gamze Abaka | c43a66e | 2020-05-11 11:00:42 +0000 | [diff] [blame] | 3716 | fieldtype := ofbField.GetType() |
| 3717 | if fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3718 | if vlan := ofbField.GetVlanVid(); vlan != 0 { |
| 3719 | actionInfo[VlanVid] = vlan & 0xfff |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3720 | logger.Debugw("action-set-vlan-vid", log.Fields{"actionInfo[VLAN_VID]": actionInfo[VlanVid].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3721 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3722 | logger.Error("no-invalid-vlan-id-in-set-vlan-vid-action") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3723 | } |
Gamze Abaka | c43a66e | 2020-05-11 11:00:42 +0000 | [diff] [blame] | 3724 | } else if fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
| 3725 | pcp := ofbField.GetVlanPcp() |
| 3726 | actionInfo[VlanPcp] = pcp |
| 3727 | log.Debugw("action-set-vlan-pcp", log.Fields{"actionInfo[VLAN_PCP]": actionInfo[VlanPcp].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3728 | } else { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3729 | logger.Errorw("unsupported-action-set-field-type", log.Fields{"type": fieldtype}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3730 | } |
| 3731 | } |
| 3732 | } |
| 3733 | |
| 3734 | func formulateGroupActionInfoFromFlow(action *ofp.OfpAction, actionInfo map[string]interface{}) { |
| 3735 | if action.GetGroup() == nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3736 | logger.Warn("no-group-entry-found-in-the-group-action") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3737 | } else { |
| 3738 | actionInfo[GroupID] = action.GetGroup().GroupId |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3739 | logger.Debugw("action-group-id", log.Fields{"actionInfo[GroupID]": actionInfo[GroupID].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3743 | func formulateControllerBoundTrapFlowInfo(actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3744 | if isControllerFlow := IsControllerBoundFlow(actionInfo[Output].(uint32)); isControllerFlow { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3745 | logger.Debug("controller-bound-trap-flows--getting-inport-from-tunnelid") |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3746 | /* Get UNI port/ IN Port from tunnel ID field for upstream controller bound flows */ |
| 3747 | if portType := IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3748 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3749 | classifierInfo[InPort] = uniPort |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3750 | logger.Debugw("upstream-pon-to-controller-flow--inport-in-tunnelid", |
| 3751 | log.Fields{ |
| 3752 | "newinport": classifierInfo[InPort].(uint32), |
| 3753 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3754 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3755 | return olterrors.NewErrNotFound("child-in-port", |
| 3756 | log.Fields{ |
| 3757 | "reason": "upstream-pon-to-controller-flow--no-inport-in-tunnelid", |
| 3758 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3759 | } |
| 3760 | } |
| 3761 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3762 | logger.Debug("non-controller-flows--getting-uniport-from-tunnelid") |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3763 | // Downstream flow from NNI to PON port , Use tunnel ID as new OUT port / UNI port |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3764 | if portType := IntfIDToPortTypeName(actionInfo[Output].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3765 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3766 | actionInfo[Output] = uniPort |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3767 | logger.Debugw("downstream-nni-to-pon-port-flow, outport-in-tunnelid", |
| 3768 | log.Fields{ |
| 3769 | "newoutport": actionInfo[Output].(uint32), |
| 3770 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3771 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3772 | return olterrors.NewErrNotFound("out-port", |
| 3773 | log.Fields{ |
| 3774 | "reason": "downstream-nni-to-pon-port-flow--no-outport-in-tunnelid", |
| 3775 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3776 | } |
| 3777 | // Upstream flow from PON to NNI port , Use tunnel ID as new IN port / UNI port |
| 3778 | } else if portType := IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3779 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3780 | classifierInfo[InPort] = uniPort |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3781 | logger.Debugw("upstream-pon-to-nni-port-flow, inport-in-tunnelid", |
| 3782 | log.Fields{ |
| 3783 | "newinport": actionInfo[Output].(uint32), |
| 3784 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3785 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3786 | return olterrors.NewErrNotFound("nni-port", |
| 3787 | log.Fields{ |
| 3788 | "reason": "upstream-pon-to-nni-port-flow--no-inport-in-tunnelid", |
| 3789 | "in-port": classifierInfo[InPort].(uint32), |
| 3790 | "out-port": actionInfo[Output].(uint32), |
| 3791 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3792 | } |
| 3793 | } |
| 3794 | } |
| 3795 | return nil |
| 3796 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3797 | |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 3798 | func getTpIDFromFlow(flow *ofp.OfpFlowStats) (uint32, error) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3799 | /* Metadata 8 bytes: |
| 3800 | Most Significant 2 Bytes = Inner VLAN |
| 3801 | Next 2 Bytes = Tech Profile ID(TPID) |
| 3802 | Least Significant 4 Bytes = Port ID |
| 3803 | Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3804 | subscriber related flows. |
| 3805 | */ |
| 3806 | metadata := flows.GetMetadataFromWriteMetadataAction(flow) |
| 3807 | if metadata == 0 { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3808 | return 0, olterrors.NewErrNotFound("metadata", log.Fields{"flow": flow}, nil) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3809 | } |
| 3810 | TpID := flows.GetTechProfileIDFromWriteMetaData(metadata) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 3811 | return uint32(TpID), nil |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | func appendUnique(slice []uint32, item uint32) []uint32 { |
| 3815 | for _, sliceElement := range slice { |
| 3816 | if sliceElement == item { |
| 3817 | return slice |
| 3818 | } |
| 3819 | } |
| 3820 | return append(slice, item) |
| 3821 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3822 | |
| 3823 | // getNniIntfID gets nni intf id from the flow classifier/action |
| 3824 | func getNniIntfID(classifier map[string]interface{}, action map[string]interface{}) (uint32, error) { |
| 3825 | |
| 3826 | portType := IntfIDToPortTypeName(classifier[InPort].(uint32)) |
| 3827 | if portType == voltha.Port_PON_OLT { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3828 | intfID, err := IntfIDFromNniPortNum(action[Output].(uint32)) |
| 3829 | if err != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3830 | logger.Debugw("invalid-action-port-number", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3831 | log.Fields{ |
| 3832 | "port-number": action[Output].(uint32), |
| 3833 | "error": err}) |
| 3834 | return uint32(0), err |
| 3835 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3836 | logger.Infow("output-nni-intfId-is", log.Fields{"intf-id": intfID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3837 | return intfID, nil |
| 3838 | } else if portType == voltha.Port_ETHERNET_NNI { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3839 | intfID, err := IntfIDFromNniPortNum(classifier[InPort].(uint32)) |
| 3840 | if err != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 3841 | logger.Debugw("invalid-classifier-port-number", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3842 | log.Fields{ |
| 3843 | "port-number": action[Output].(uint32), |
| 3844 | "error": err}) |
| 3845 | return uint32(0), err |
| 3846 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3847 | logger.Infow("input-nni-intfId-is", log.Fields{"intf-id": intfID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3848 | return intfID, nil |
| 3849 | } |
| 3850 | return uint32(0), nil |
| 3851 | } |
| 3852 | |
| 3853 | // UpdateGemPortForPktIn updates gemport for packet-in in to the cache and to the kv store as well. |
Esin Karaman | 04166c8 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3854 | func (f *OpenOltFlowMgr) UpdateGemPortForPktIn(ctx context.Context, intfID uint32, onuID uint32, logicalPort uint32, gemPort uint32, pkt []byte) { |
| 3855 | cTag, priority, err := getCTagFromPacket(ctx, pkt) |
| 3856 | if err != nil { |
| 3857 | logger.Errorw("unable-to-update-gem-port-for-packet-in", |
| 3858 | log.Fields{"intfID": intfID, "onuID": onuID, "logicalPort": logicalPort, "gemPort": gemPort, "err": err}) |
| 3859 | return |
| 3860 | } |
| 3861 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: logicalPort, VlanID: cTag, Priority: priority} |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3862 | |
| 3863 | f.onuGemInfoLock.Lock() |
| 3864 | defer f.onuGemInfoLock.Unlock() |
| 3865 | |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3866 | lookupGemPort, ok := f.packetInGemPort[pktInkey] |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3867 | if ok { |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3868 | if lookupGemPort == gemPort { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3869 | logger.Infow("pktin-key/value-found-in-cache--no-need-to-update-kv--assume-both-in-sync", |
| 3870 | log.Fields{ |
| 3871 | "pktinkey": pktInkey, |
| 3872 | "gem": gemPort}) |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3873 | return |
| 3874 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3875 | } |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3876 | f.packetInGemPort[pktInkey] = gemPort |
| 3877 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3878 | f.resourceMgr.UpdateGemPortForPktIn(ctx, pktInkey, gemPort) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3879 | logger.Infow("pktin-key-not-found-in-local-cache-value-is-different--updating-cache-and-kv-store", |
| 3880 | log.Fields{ |
| 3881 | "pktinkey": pktInkey, |
| 3882 | "gem": gemPort}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3883 | return |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3884 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3885 | } |
| 3886 | |
Esin Karaman | 04166c8 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3887 | //getCTagFromPacket retrieves and returns c-tag and priority value from a packet. |
| 3888 | func getCTagFromPacket(ctx context.Context, packet []byte) (uint16, uint8, error) { |
| 3889 | if packet == nil || len(packet) < 18 { |
| 3890 | log.Error("unable-get-c-tag-from-the-packet--invalid-packet-length ") |
| 3891 | return 0, 0, errors.New("invalid packet length") |
| 3892 | } |
| 3893 | outerEthType := (uint16(packet[12]) << 8) | uint16(packet[13]) |
| 3894 | innerEthType := (uint16(packet[16]) << 8) | uint16(packet[17]) |
| 3895 | |
| 3896 | var index int8 |
| 3897 | if outerEthType == 0x8100 { |
| 3898 | if innerEthType == 0x8100 { |
| 3899 | // q-in-q 802.1ad or 802.1q double tagged packet. |
| 3900 | // get the inner vlanId |
| 3901 | index = 18 |
| 3902 | } else { |
| 3903 | index = 14 |
| 3904 | } |
| 3905 | priority := (packet[index] >> 5) & 0x7 |
| 3906 | //13 bits composes vlanId value |
| 3907 | vlan := ((uint16(packet[index]) << 8) & 0x0fff) | uint16(packet[index+1]) |
| 3908 | return vlan, priority, nil |
| 3909 | } |
| 3910 | logger.Debugf("No vlanId found in the packet. Returning zero as c-tag") |
| 3911 | return 0, 0, nil |
| 3912 | } |
| 3913 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3914 | // AddUniPortToOnuInfo adds uni port to the onugem info both in cache and kvstore. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3915 | func (f *OpenOltFlowMgr) AddUniPortToOnuInfo(ctx context.Context, intfID uint32, onuID uint32, portNum uint32) { |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 3916 | |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3917 | f.onuGemInfoLock.Lock() |
| 3918 | defer f.onuGemInfoLock.Unlock() |
Matteo Scandolo | 2c0d274 | 2020-06-10 11:28:42 -0700 | [diff] [blame] | 3919 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3920 | onugem := f.onuGemInfo[intfID] |
| 3921 | for idx, onu := range onugem { |
| 3922 | if onu.OnuID == onuID { |
| 3923 | for _, uni := range onu.UniPorts { |
| 3924 | if uni == portNum { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3925 | logger.Infow("uni-already-in-cache--no-need-to-update-cache-and-kv-store", log.Fields{"uni": portNum}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3926 | return |
| 3927 | } |
| 3928 | } |
| 3929 | onugem[idx].UniPorts = append(onugem[idx].UniPorts, portNum) |
| 3930 | f.onuGemInfo[intfID] = onugem |
| 3931 | } |
| 3932 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3933 | f.resourceMgr.AddUniPortToOnuInfo(ctx, intfID, onuID, portNum) |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3934 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3935 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 3936 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3937 | func (f *OpenOltFlowMgr) loadFlowIDlistForGem(ctx context.Context, intf uint32) { |
| 3938 | flowIDsList, err := f.resourceMgr.GetFlowIDsGemMapForInterface(ctx, intf) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 3939 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3940 | logger.Error("failed-to-get-flowid-list-per-gem", log.Fields{"intf": intf}) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 3941 | return |
| 3942 | } |
| 3943 | for gem, FlowIDs := range flowIDsList { |
| 3944 | gemPK := gemPortKey{intf, uint32(gem)} |
Matteo Scandolo | ac032b1 | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 3945 | if f.perGemPortLock.TryLock(gemPK) { |
| 3946 | f.flowsUsedByGemPort[gemPK] = FlowIDs |
| 3947 | f.perGemPortLock.Unlock(gemPK) |
| 3948 | } else { |
| 3949 | logger.Error("failed-to-acquire-per-gem-port-lock", |
| 3950 | log.Fields{ |
| 3951 | "intf-id": intf, |
| 3952 | "device-id": f.deviceHandler.device.Id, |
| 3953 | "key": gemPK, |
| 3954 | }) |
| 3955 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 3956 | } |
| 3957 | return |
| 3958 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3959 | |
| 3960 | //loadInterfaceToMulticastQueueMap reads multicast queues per interface from the KV store |
| 3961 | //and put them into interfaceToMcastQueueMap. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3962 | func (f *OpenOltFlowMgr) loadInterfaceToMulticastQueueMap(ctx context.Context) { |
| 3963 | storedMulticastQueueMap, err := f.resourceMgr.GetMcastQueuePerInterfaceMap(ctx) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3964 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3965 | logger.Error("failed-to-get-pon-interface-to-multicast-queue-map") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3966 | return |
| 3967 | } |
| 3968 | for intf, queueInfo := range storedMulticastQueueMap { |
| 3969 | q := queueInfoBrief{ |
| 3970 | gemPortID: queueInfo[0], |
| 3971 | servicePriority: queueInfo[1], |
| 3972 | } |
| 3973 | f.interfaceToMcastQueueMap[intf] = &q |
| 3974 | } |
| 3975 | } |
| 3976 | |
| 3977 | //GetFlowGroupFromKVStore fetches and returns flow group from the KV store. Returns (nil, false, error) if any problem occurs during |
| 3978 | //fetching the data. Returns (group, true, nil) if the group is fetched and returned successfully. |
| 3979 | //Returns (nil, false, nil) if the group does not exists in the KV store. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3980 | func (f *OpenOltFlowMgr) GetFlowGroupFromKVStore(ctx context.Context, groupID uint32, cached bool) (*ofp.OfpGroupEntry, bool, error) { |
| 3981 | exists, groupInfo, err := f.resourceMgr.GetFlowGroupFromKVStore(ctx, groupID, cached) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3982 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3983 | return nil, false, olterrors.NewErrNotFound("flow-group", log.Fields{"group-id": groupID}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3984 | } |
| 3985 | if exists { |
| 3986 | return newGroup(groupInfo.GroupID, groupInfo.OutPorts), exists, nil |
| 3987 | } |
| 3988 | return nil, exists, nil |
| 3989 | } |
| 3990 | |
| 3991 | func newGroup(groupID uint32, outPorts []uint32) *ofp.OfpGroupEntry { |
| 3992 | groupDesc := ofp.OfpGroupDesc{ |
| 3993 | Type: ofp.OfpGroupType_OFPGT_ALL, |
| 3994 | GroupId: groupID, |
| 3995 | } |
| 3996 | groupEntry := ofp.OfpGroupEntry{ |
| 3997 | Desc: &groupDesc, |
| 3998 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3999 | for i := 0; i < len(outPorts); i++ { |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 4000 | var acts []*ofp.OfpAction |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 4001 | acts = append(acts, flows.Output(outPorts[i])) |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 4002 | bucket := ofp.OfpBucket{ |
| 4003 | Actions: acts, |
| 4004 | } |
| 4005 | groupDesc.Buckets = append(groupDesc.Buckets, &bucket) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 4006 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 4007 | return &groupEntry |
| 4008 | } |