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