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