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