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