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